[Sony Cross-Device Development Themes and Apps] venkat kamesh:
Post 2

Look at these 2 xml code which give same result with variation of view

<SwitchPreference android:title="Brightness Slider" android:key="[COLOR="red"]key_brightness_slider_show[/COLOR]" android:summaryOn="Brightness Slider Shown" android:summaryOff="Brightness Slider Hidden" />

or

<CheckBoxPreference android:title="Brightness Slider" android:key="[COLOR="red"]key_brightness_slider_show[/COLOR]" android:summaryOn="Brightness Slider Shown" android:summaryOff="Brightness Slider Hidden" />

You MUST provide defaultValue for ANY switch preference you create

It writes boolean (true or false) into the shared preferences

We copy it as integer (1 or 0) into the Settings.System database

It mush have a unique key, none of existent in databse.

It must be the same key as you use in your mod for that function. key_brightness_slider_show.

So thea Slider can be either visible or invisible.

Also will checkbox preference. In your mod when you retrieve and integer using ContentResolver you specify the default value (if the key is not found).

You have to specify the same default value here. If in smali it was 0x1,. then in the app it must be android:defaultValue = "true".

android:summaryOn="Brightness Slider Shown" android:summaryOff="Brightness Slider Hidden"

These will show the below summary when value is 1 you will get summaryOn else off

This is not much mandatory.. its your wish or you can leave it or you can just only define summary

You can also make Dependence of the switch example

Network mod- this contain turn on/off, color, auto hide and more

When you add the dependency code so that when you only get bool 1 you can control other next string

Look below code of strings

<ListPreference android:persistent="false" android:entries="@array/show_network_traffic_state_entries" android:title="@string/show_network_traffic_state" android:key="[COLOR="red"]network_traffic_state[/COLOR]" android:entryValues="@array/show_network_traffic_state_values" />
<net.margaritov.preference.colorpicker.ColorPickerPreference android:title="@string/network_traffic_color_style" android:key="network_traffic_color" [COLOR="Orange"]android:dependency="[COLOR="Red"]network_traffic_state[/COLOR]" [/COLOR]android:defaultValue="0xffffffff" />

in the above code you can see the dependency

mean, when you turn on the first string

only then next string works

Now its time to go for smali

First create your own xml code

Example look this empty code

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="New"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">

</PreferenceScreen>

save this in any name of your xml (settings.apk/res/xml)

now i like to control Brightness slider

so i will add this to the xml and will look like

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="New"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<SwitchPreference android:title="Brightness Slider" android:key="key_brightness_slider_show" android:defaultValue="0" android:summaryOn="Brightness Slider Shown" android:summaryOff="Brightness Slider Hidden"
</PreferenceScreen>

Look here the main part is Key android:key="key_brightness_slider_show" (where i had defined brightness_slider_show in above code )

I think you are clear till now

So time to create a boolean

Lets start with new empty code

This is an Empty code Which or where you can create new Switch or Checkbox preference

The path of the file is Settings.apk/smali/com/android/settings/rz/

and File name was Statusmod.smali

.class public Lcom/android/settings/rz/Statusmod;
.super Lcom/android/settings/SettingsPreferenceFragment;
.source "Statusmod.java"

# instance fields

# direct methods
.method public constructor <init>()V
.locals 0

.prologue
.line 28
invoke-direct {p0}, Lcom/android/settings/SettingsPreferenceFragment;-><init>()V

return-void
.end method

# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
.locals 5
.param p1, "savedInstanceState" # Landroid/os/Bundle;

.prologue
const/4 v3, 0x0

const/4 v2, 0x1

.line 42
invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

.line 43
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v1

invoke-virtual {v1}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

.line 44
.local v0, "resolver":Landroid/content/ContentResolver;
const v1, 0x7f060092 #Xml preference

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->addPreferencesFromResource(I)V

.end method

.method public onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z
.locals 5
.param p1, "preferenceScreen" # Landroid/preference/PreferenceScreen;
.param p2, "preference" # Landroid/preference/Preference;

.prologue
const/4 v1, 0x0

const/4 v2, 0x1

.end method

Here i had added a part of Switch settings

.class public Lcom/android/settings/rz/Statusmod;
.super Lcom/android/settings/SettingsPreferenceFragment;
.source "Statusmod.java"

# instance fields
.field private mENABLE_SLIDER:Landroid/preference/[COLOR="SeaGreen"]SwitchPreference[/COLOR];

# direct methods
.method public constructor <init>()V
.locals 0

.prologue
.line 28
invoke-direct {p0}, Lcom/android/settings/SettingsPreferenceFragment;-><init>()V

return-void
.end method

# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
.locals 5
.param p1, "savedInstanceState" # Landroid/os/Bundle;

.prologue
const/4 v3, 0x0

const/4 v2, 0x1

.line 42
invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

.line 43
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v1

invoke-virtual {v1}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

.line 44
.local v0, "resolver":Landroid/content/ContentResolver;
const v1, 0x7f060092 # xml public key

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->addPreferencesFromResource(I)V

.line 46
const-string v1, "key_brightness_slider_show"

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v1

check-cast v1, Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];

iput-object v1, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];

.line 47
iget-object v4, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];

const-string v1, "brightness_slider_show"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

if-ne v1, v2, :cond_0

move v1, v2

:goto_0
invoke-virtual {v4, v1}, Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];->setChecked(Z)V

.line 57
return-void

:cond_0
move v1, v3

.line 47
goto :goto_0
.end method

.method public onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z
.locals 5
.param p1, "preferenceScreen" # Landroid/preference/PreferenceScreen;
.param p2, "preference" # Landroid/preference/Preference;

.prologue
const/4 v1, 0x0

const/4 v2, 0x1

.line 61
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];

if-ne p2, v3, :cond_1

.line 62
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];

invoke-virtual {v3}, Landroid/preference/[COLOR="seagreen"]SwitchPreference[/COLOR];->isChecked()Z

move-result v0

.line 63
.local v0, "value":Z
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v3

invoke-virtual {v3}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "brightness_slider_show"

if-eqz v0, :cond_0

move v1, v2

:cond_0
invoke-static {v3, v4, v1}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

.line 78
.end local v0 # "value":Z
:goto_0
return v2

.line 65
:cond_1
invoke-super {p0, p1, p2}, Lcom/android/settings/SettingsPreferenceFragment;->onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z

move-result v2

goto :goto_0
.end method

Now you had done with the code

in this you should look for public id

Where you need to match with xml you created above

This is Switch box preference

If you like to change it to Check Box preference then change all Switch to Checkbox ( also in Xml)

As like below Code ( Look for green part of changes)

.class public Lcom/android/settings/rz/Statusmod;
.super Lcom/android/settings/SettingsPreferenceFragment;
.source "Statusmod.java"

# instance fields
.field private mENABLE_SLIDER:Landroid/preference/CheckBoxPreference;

# direct methods
.method public constructor <init>()V
.locals 0

.prologue
.line 28
invoke-direct {p0}, Lcom/android/settings/SettingsPreferenceFragment;-><init>()V

return-void
.end method

# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
.locals 5
.param p1, "savedInstanceState" # Landroid/os/Bundle;

.prologue
const/4 v3, 0x0

const/4 v2, 0x1

.line 42
invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

.line 43
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v1

invoke-virtual {v1}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

.line 44
.local v0, "resolver":Landroid/content/ContentResolver;
const v1, 0x7f060092

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->addPreferencesFromResource(I)V

.line 46
const-string v1, "key_brightness_slider_show"

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v1

check-cast v1, Landroid/preference/CheckBoxPreference;

iput-object v1, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/CheckBoxPreference;

.line 47
iget-object v4, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/CheckBoxPreference;

const-string v1, "brightness_slider_show"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

if-ne v1, v2, :cond_0

move v1, v2

:goto_0
invoke-virtual {v4, v1}, Landroid/preference/CheckBoxPreference;->setChecked(Z)V

.line 57
return-void

:cond_0
move v1, v3

.line 47
goto :goto_0
.end method

.method public onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z
.locals 5
.param p1, "preferenceScreen" # Landroid/preference/PreferenceScreen;
.param p2, "preference" # Landroid/preference/Preference;

.prologue
const/4 v1, 0x0

const/4 v2, 0x1

.line 61
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/CheckBoxPreference;

if-ne p2, v3, :cond_1

.line 62
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/CheckBoxPreference;

invoke-virtual {v3}, Landroid/preference/CheckBoxPreference;->isChecked()Z

move-result v0

.line 63
.local v0, "value":Z
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v3

invoke-virtual {v3}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "brightness_slider_show"

if-eqz v0, :cond_0

move v1, v2

:cond_0
invoke-static {v3, v4, v1}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

.line 78
.end local v0 # "value":Z
:goto_0
return v2

.line 65
:cond_1
invoke-super {p0, p1, p2}, Lcom/android/settings/SettingsPreferenceFragment;->onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z

move-result v2

goto :goto_0
.end method

If you like to add more in this

Example if you had added new Switch or checkbox

<PreferenceScreen android:title="New"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings">
<SwitchPreference android:title="Brightness Slider" android:key="brightness_slider_show" android:defaultValue="0" android:summaryOn="Brightness Slider Shown" android:summaryOff="Brightness Slider Hidden"
<CheckBoxPreference android:title="Nothing Bomb" android:key="key_bomb_show" />
</PreferenceScreen>

first define in xml then i code

i will explain in simple

Look for the above code

Look at this boolean ( from above code)

.field private mENABLE_SLIDER:Landroid/preference/SwitchPreference;

above/Below Add this line

.field private mENABLE_BOMB:Landroid/preference/CheckBoxPreference; #define boolean

In this method

.method public onCreate(Landroid/os/Bundle;)V

After :goto_0

You need to add this code

invoke-virtual {v4, v1}, Landroid/preference/CheckBoxPreference;->setChecked(Z)V

const-string v1, "key_bomb_show"

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v1

check-cast v1, Landroid/preference/CheckBoxPreference;

iput-object v1, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/CheckBoxPreference;

.line 50
iget-object v4, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/CheckBoxPreference;

const-string v1, "bomb_show"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

if-ne v1, v2, :cond_1

move v1, v2

:goto_1

After goto :goto_0

Add this Code

:cond_1
move v1, v3

.line 50
goto :goto_1

In this code when you add more first look cond_? and goto_?

Now look for this method

.method public onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z

in that after

.line 65

:cond_1

Add this code

iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/SwitchPreference;

if-ne p2, v3, :cond_2

.line 62
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/SwitchPreference;

invoke-virtual {v3}, Landroid/preference/SwitchPreference;->isChecked()Z

move-result v0

.line 63
.local v0, "value":Z
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v3

invoke-virtual {v3}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "bomb_show"

if-eqz v0, :cond_1

move v1, v2

:cond_1
invoke-static {v3, v4, v1}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

.line 78
.end local v0 # "value":Z
:goto_1
return v2

.line 65
:cond_2

and save finally it looks like this

.class public Lcom/android/settings/rz/Statusmod;
.super Lcom/android/settings/SettingsPreferenceFragment;
.source "Statusmod.java"

# instance fields
.field private mENABLE_SLIDER:Landroid/preference/SwitchPreference;
.field private mENABLE_BOMB:Landroid/preference/CheckBoxPreference;

# direct methods
.method public constructor <init>()V
.locals 0

.prologue
.line 28
invoke-direct {p0}, Lcom/android/settings/SettingsPreferenceFragment;-><init>()V

return-void
.end method

# virtual methods
.method public onCreate(Landroid/os/Bundle;)V
.locals 5
.param p1, "savedInstanceState" # Landroid/os/Bundle;

.prologue
const/4 v3, 0x0

const/4 v2, 0x1

.line 42
invoke-super {p0, p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

.line 43
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v1

invoke-virtual {v1}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

.line 44
.local v0, "resolver":Landroid/content/ContentResolver;
const v1, 0x7f060092

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->addPreferencesFromResource(I)V

.line 46
const-string v1, "key_brightness_slider_show"

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v1

check-cast v1, Landroid/preference/SwitchPreference;

iput-object v1, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/SwitchPreference;

.line 47
iget-object v4, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/SwitchPreference;

const-string v1, "brightness_slider_show"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

if-ne v1, v2, :cond_0

move v1, v2

:goto_0
invoke-virtual {v4, v1}, Landroid/preference/CheckBoxPreference;->setChecked(Z)V

const-string v1, "key_bomb_show"

invoke-virtual {p0, v1}, Lcom/android/settings/rz/Statusmod;->findPreference(Ljava/lang/CharSequence;)Landroid/preference/Preference;

move-result-object v1

check-cast v1, Landroid/preference/CheckBoxPreference;

iput-object v1, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/CheckBoxPreference;

.line 50
iget-object v4, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/CheckBoxPreference;

const-string v1, "bomb_show"

invoke-static {v0, v1, v2}, Landroid/provider/Settings$System;->getInt(Landroid/content/ContentResolver;Ljava/lang/String;I)I

move-result v1

if-ne v1, v2, :cond_1

move v1, v2

:goto_1
invoke-virtual {v4, v1}, Landroid/preference/SwitchPreference;->setChecked(Z)V

.line 57
return-void

:cond_0
move v1, v3

.line 47
goto :goto_0

:cond_1
move v1, v3

.line 50
goto :goto_1
.end method

.method public onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z
.locals 5
.param p1, "preferenceScreen" # Landroid/preference/PreferenceScreen;
.param p2, "preference" # Landroid/preference/Preference;

.prologue
const/4 v1, 0x0

const/4 v2, 0x1

.line 61
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/SwitchPreference;

if-ne p2, v3, :cond_1

.line 62
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_SLIDER:Landroid/preference/SwitchPreference;

invoke-virtual {v3}, Landroid/preference/SwitchPreference;->isChecked()Z

move-result v0

.line 63
.local v0, "value":Z
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v3

invoke-virtual {v3}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "brightness_slider_show"

if-eqz v0, :cond_0

move v1, v2

:cond_0
invoke-static {v3, v4, v1}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

.line 78
.end local v0 # "value":Z
:goto_0
return v2

.line 65
:cond_1

iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/SwitchPreference;

if-ne p2, v3, :cond_2

.line 62
iget-object v3, p0, Lcom/android/settings/rz/Statusmod;->mENABLE_BOMB:Landroid/preference/SwitchPreference;

invoke-virtual {v3}, Landroid/preference/SwitchPreference;->isChecked()Z

move-result v0

.line 63
.local v0, "value":Z
invoke-virtual {p0}, Lcom/android/settings/rz/Statusmod;->getActivity()Landroid/app/Activity;

move-result-object v3

invoke-virtual {v3}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "bomb_show"

if-eqz v0, :cond_1

move v1, v2

:cond_1
invoke-static {v3, v4, v1}, Landroid/provider/Settings$System;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

.line 78
.end local v0 # "value":Z
:goto_1
return v2

.line 65
:cond_2
invoke-super {p0, p1, p2}, Lcom/android/settings/SettingsPreferenceFragment;->onPreferenceTreeClick(Landroid/preference/PreferenceScreen;Landroid/preference/Preference;)Z

move-result v2

goto :goto_0
.end method

and save it compile and done with your settings preferences

This is how to add preferences

If you add more with different smlai name then change the code path and definition

If you got confused look for my guides ;) that will surely help you