[Galaxy S II Themes and Apps] jeboo:
****** For ICS 4.0.4, the code has changed a bit. Instead of changing the original tutorial, I'm providing a known working patch I did for an i9100 XWLPT build ******

(there's also a 2nd patch below to ignore regular swipe actions while using AOSP lockscreen)

https://github.com/shoman94/SHOstock2-XWLPT/commit/523075aac1730883a14e365e29c58eb8cce03248

https://github.com/shoman94/SHOstock2-XWLPT/commit/a55fb9b42a5f3f0c0c840c72e68372ab6a199cc2

This tutorial will be a bit involved, you've been warned! It was more of a learning experience, so here are the things you will see:

1. Add toggle settings via xml

2. Add global settings that are retained

3. Add code support for your toggles

4. Have your toggles be smart, and enable/disable other related toggles

5. Add a debug message using Slog, this is invaluable for any project!

Based on 4.0.3 LP3 base..Adjust resource IDs (bolded) for your base!!

--------------------------------------------------------------------------

Step 1. Adding the toggles to Settings/Date & Time (the easy part)

Decompile Settings.apk, modify the following:

public.xml, add:

<public type="string" name="disable_ampm" id="[b]0x7f0b0923[/b]" />
<public type="string" name="disable_ampm_text" id="[b]0x7f0b0924[/b]" />
<public type="string" name="disable_time" id="[b]0x7f0b0925[/b]" />
<public type="string" name="disable_time_text" id="[b]0x7f0b0926[/b]" />

strings.xml, add:

<string name="disable_time">Hide Time</string>
<string name="disable_time_text">Remove time from status bar</string>
<string name="disable_ampm">Hide AM/PM</string>
<string name="disable_ampm_text">Remove AM/PM from time in status bar</string>

xml/date_time_prefs.xml, add:

<CheckBoxPreference android:title="@string/disable_time" android:key="hide_time" android:summary="@string/disable_time_text" />
<CheckBoxPreference android:title="@string/disable_ampm" android:key="hide_ampm" android:summary="@string/disable_ampm_text" />

Compile settings.apk, u/l and reboot. Make sure the toggles are added!

Step 2. Adding code for the settings (the not so easy part). This code gets a bit involved since we have to handle the new settings, and also add 'toggle logic' for different combinations to enable/disable them.

Still in settings.apk, DateTimeSettings.smali:

At top, add:

.field private mHideTime:Landroid/preference/Preference;
.field private mHideAmPm:Landroid/preference/Preference;

Then in the '.method private initUI()V', find 'return-void' and add this code above it:

const-string v6, "hide_time"

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

move-result-object v6

check-cast v6, Landroid/preference/Preference;

iput-object v6, p0, Lcom/android/settings/DateTimeSettings;->mHideTime:Landroid/preference/Preference;

const-string v6, "hide_ampm"

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

move-result-object v6

check-cast v6, Landroid/preference/Preference;

iput-object v6, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mHideTime:Landroid/preference/Preference;

check-cast v0, Landroid/preference/CheckBoxPreference;

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

move-result v0

if-eqz v0, :no_disablebtns

const/4 v0, 0x0

iget-object v6, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

invoke-virtual {v6, v0}, Landroid/preference/Preference;->setEnabled(Z)V

iget-object v6, p0, Lcom/android/settings/DateTimeSettings;->mTime24Pref:Landroid/preference/Preference;

invoke-virtual {v6, v0}, Landroid/preference/Preference;->setEnabled(Z)V

:no_disablebtns
iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mTime24Pref:Landroid/preference/Preference;

check-cast v0, Landroid/preference/CheckBoxPreference;

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

move-result v0

if-eqz v0, :no_disableampm

const/4 v0, 0x0

iget-object v6, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

invoke-virtual {v6, v0}, Landroid/preference/Preference;->setEnabled(Z)V

:no_disableampm

Now search for '.method public onPreferenceTreeClick' and on the line below, change .locals 2 to:

.locals 6

Now search for:

:cond_2

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mTime24Pref:Landroid/preference/Preference;

if-ne p2, v0, :cond_0

change the last line to:

if-ne p2, v0, :cond_new

About 10 lines below that, you will see 'invoke-direct {p0, v0}, Lcom/android/settings/DateTimeSettings;->set24Hour(Z)V', add this below that line:

iget-object v1, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

if-nez v0, :cond_hideampm

const/4 v0, 0x1

goto :set_ampm

:cond_hideampm

const/4 v0, 0x0

:set_ampm
invoke-virtual {v1, v0}, Landroid/preference/Preference;->setEnabled(Z)V

:cond_updatetime

Then search for 'goto :goto_0' about 10 lines below and add this before '.end method':

:cond_new
const-string v3, "hide_ampm"

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

if-ne p2, v0, :cond_new2

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

check-cast v0, Landroid/preference/CheckBoxPreference;

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

move-result v2

:save_ampm
invoke-virtual {p0}, Lcom/android/settings/DateTimeSettings;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "hide_ampm"

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

goto :cond_updatetime

:cond_new2
const-string v3, "hide_time"

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mHideTime:Landroid/preference/Preference;

if-ne p2, v0, :goto_0

iget-object v0, p0, Lcom/android/settings/DateTimeSettings;->mHideTime:Landroid/preference/Preference;

check-cast v0, Landroid/preference/CheckBoxPreference;

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

move-result v2

:save_time

invoke-virtual {p0}, Lcom/android/settings/DateTimeSettings;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v3

const-string v4, "hide_time"

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

if-nez v2, :cond_hidebtns

const/4 v2, 0x1

goto :cond_setbtns

:cond_hidebtns

const/4 v2, 0x0

:cond_setbtns

iget-object v1, p0, Lcom/android/settings/DateTimeSettings;->mHideAmPm:Landroid/preference/Preference;

invoke-virtual {v1, v2}, Landroid/preference/Preference;->setEnabled(Z)V

iget-object v1, p0, Lcom/android/settings/DateTimeSettings;->mTime24Pref:Landroid/preference/Preference;

invoke-virtual {v1, v2}, Landroid/preference/Preference;->setEnabled(Z)V

goto :cond_updatetime

And that's it for Settings! Recompile and upload and check everything looks right in Settings/Date and Time and the toggles work.

Step 3. Modifying the clock code to handle new changes (kinda easy =)

Decompile SystemUI and open Clock.smali.

Search for the following in func getSmallTime:

.local v3, context:Landroid/content/Context;

invoke-static {v3}, Landroid/text/format/DateFormat;->is24HourFormat(Landroid/content/Context;)Z

Then add this code BEFORE the invoke-static .. line above (NOTE: there's a constant below that refers to the clock resource in public.xml [<public type="id" name="clock" id="0x7f0e0027" />], be sure it matches!):

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

move-result-object v2

const-string v7, "hide_time"

const/4 v0, 0x0

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

move-result v7

const/4 v0, 0x0

if-eqz v7, :cond_nohide

const/16 v0, 0x8

:cond_nohide
const v1, [b]0x7f0e0027[/b]

invoke-virtual {p0, v1}, Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;->findViewById(I)Landroid/view/View;

move-result-object v1

invoke-virtual {v1, v0}, Landroid/view/View;->setVisibility(I)V

About 20 lines below that, you will see:

.local v1, MAGIC2:C

invoke-virtual {v3, v5}, Landroid/content/Context;->getString(I)Ljava/lang/String;

move-result-object v4

Add this directly after:

if-nez v2, :cond_continue

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

move-result-object v2

const-string v3, "hide_ampm"

const/4 v0, 0x0

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

move-result v7

########### Start of debug msg, can be removed #######
const-string v0, "ampm"

new-instance v1, Ljava/lang/StringBuilder;

invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

const-string v2, "getint returned="

invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v1

invoke-virtual {v1, v7}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

move-result-object v1

invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v1

invoke-static {v0, v1}, Landroid/util/Slog;->i(Ljava/lang/String;Ljava/lang/String;)I
########### End of debug msg ###########

move v2, v7

if-eqz v2, :cond_continue

const-string v4, "h:mm"

:cond_continue

That's it for Clock.smali.

Step 4. Almost there, now we just have to make one more change to SystemUI in PhoneStatusBar.smali.

Find '.method public showClock' and change .locals 2 to:

.locals 3

Find:

if-eqz p1, :cond_1

const/4 v0, 0x0

and insert this code after it:

iget-object v2, p0, Lcom/android/systemui/SystemUI;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v2

const-string v3, "hide_time"

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

move-result v2

if-eqz v2, :goto_0

const/16 v0, 0x8

Recompile SystemUI and reboot. Now try out the new feature =)