[Android Themes] 05Gurpreet:
In this guide , I will tell "How to add Clock" option in Settings. :)

Will work only on 4.4​

REQUIREMENTS :

1. Brain

2. Apktool (2.0.0)

3. Notepad ++

4. Knowledge on How to Decompile/Recompile the apk

Lets start ,

NOTE : Those are not having the "colorpicker" folder in Settings/smali/net/margaritov/preference and having any other colorpicker in different location then open the "status_bar_clock_style" and edit this line by changing the path of colorpicker in this line.

<net.margaritov.preference.colorpicker.ColorPickerPreference android:title="@string/battery_bar_color" android:key="battery_bar_color" android:defaultValue="\#ffffff" alphaSlider="true" />

Those who are not having any color picker , first add that using guide whose link is given below.

http://xdaforums.com/android/themes/guide-add-coloricker-settings-t3176597/post62282065#post62282065

Settings.apk Modding

1. First Decompile your Settings.apk and merge the files (given below).

2. Now add this line in display_settings.xml or any other xml present in Settings.apk/res/xml.

<PreferenceScreen android:title="@string/statusbar_clock" android:key="statusbar_clock" android:summary="@string/statusbar_clock_summary" android:fragment="com.android.settings.gurpreet.statusbarclock.StatusBarClockStyle" />

3. Now open strings.xml and add these lines above </resources>.

<string name="statusbar_clock">Clock and Date</string>
<string name="statusbar_clock_summary">Change the clock and date style</string>
<string name="clock_title_enable">Alignment</string>
<string name="clock_enabled">Enabled</string>
<string name="clock_disabled">Disabled</string>
<string name="clock_color_title">Color</string>
<string name="status_bar_clock_style_reset">Reset color</string>
<string name="status_bar_show_clock_title">Show clock and date</string>
<string name="status_bar_am_pm_title">AM/PM</string>
<string name="status_bar_am_pm_info">24-hour clock is enabled</string>
<string name="enable_clock_weekday">Day of the week</string>
<string name="enable_clock_weekday_summary">Abbreviated day of the week before the time</string>
<string name="right_clock">Right clock</string>
<string name="center_clock">Center clock</string>
<string name="left_clock">Left clock</string>
<string name="dont_show">"Don't show"</string>
<string name="clock_date_display">Date</string>
<string name="clock_date_display_summary">Display custom date before the clock</string>
<string name="clock_date_style">Date style</string>
<string name="clock_date_format">Date format</string>
<string name="clock_date_string_edittext_title">Must be in DateFormat eg. MM/dd/yy</string>
<string name="clock_date_string_edittext_summary">Enter string</string>
<string name="am_pm_clock_normal">Normal font size</string>
<string name="am_pm_clock_small">Small font size</string>
<string name="am_pm_clock_none">"Don't show"</string>
<string name="clock_date_display_none">"Don't show"</string>
<string name="clock_date_display_small">Small font size</string>
<string name="clock_date_display_normal">Normal font size</string>
<string name="clock_date_style_normal">Normal</string>
<string name="clock_date_style_lowercase">Lowercase</string>
<string name="clock_date_style_uppercase">Uppercase</string>
<string name="clock_date_format_custom">Custom java format</string>
<string name="status_bar_clock_style_reset_message">Reset clock color?</string>
<string name="clock_font_style_title">Font styles</string>
<string name="clock_font_bold">Bold</string>
<string name="clock_font_condensed">Condensed</string>
<string name="clock_font_light">Light</string>
<string name="clock_font_light_italic">Light italic</string>
<string name="clock_font_normal">Normal</string>
<string name="color_default">Default</string>
<string name="clock_use_second">Enable Seconds</string>
<string name="clock_use_second_summary">Shows the seconds next to the clock</string>

4. Now open array.xml and add these lines above </resources>.

<string-array name="clock_style_entries">
<item>@string/right_clock</item>
<item>@string/center_clock</item>
<item>@string/left_clock</item>
</string-array>
<string-array name="clock_style_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="entries_status_bar_am_pm">
<item>@string/am_pm_clock_none</item>
<item>@string/am_pm_clock_small</item>
<item>@string/am_pm_clock_normal</item>
</string-array>
<string-array name="values_status_bar_am_pm">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="clock_date_display_entries">
<item>@string/clock_date_display_none</item>
<item>@string/clock_date_display_small</item>
<item>@string/clock_date_display_normal</item>
</string-array>
<string-array name="clock_date_display_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="clock_date_style_entries">
<item>@string/clock_date_style_normal</item>
<item>@string/clock_date_style_lowercase</item>
<item>@string/clock_date_style_uppercase</item>
</string-array>
<string-array name="clock_date_style_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="clock_date_format_entries_values">
<item>dd/MM/yy</item>
<item>MM/dd/yy</item>
<item>yyyy-MM-dd</item>
<item>yyyy-dd-MM</item>
<item>dd-MM-yyyy</item>
<item>MM-dd-yyyy</item>
<item>MMM dd</item>
<item>MMM dd, yyyy</item>
<item>MMMM dd, yyyy</item>
<item>EEE</item>
<item>EEE dd</item>
<item>EEE dd/MM</item>
<item>EEE MM/dd</item>
<item>EEE dd MMM</item>
<item>EEE MMM dd</item>
<item>EEE MMMM dd</item>
<item>EEEE dd/MM</item>
<item>EEEE MM/dd</item>
<item>@string/clock_date_format_custom</item>
</string-array>
<string-array name="clock_font_style_entries">
<item>@string/clock_font_bold</item>
<item>@string/clock_font_condensed</item>
<item>@string/clock_font_light</item>
<item>@string/clock_font_light_italic</item>
<item>@string/clock_font_normal</item>
</string-array>
<string-array name="clock_font_style_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

5. Now Recompile your Settings.apk , Sign it and again Decompile it.

6. Now open StatusBarClockStyle.smali and replace the ids with the ids present in public.xml of your Settings.apk

0x7f050077

<public type="xml" name="status_bar_clock_style"

0x7f0200cd

<public type="drawable" name="ic_settings_clock"

0x7f0800a4

<public type="string" name="color_default"

0x7f0800cd

<public type="string" name="status_bar_am_pm_info"

0x7f0a0078

<public type="array" name="clock_date_format_entries_values"

0x7f08007c

<public type="string" name="reset"

Do this with other same id.

0x7f0800e3

<public type="string" name="status_bar_clock_style_reset_message"

0x7f08007b

<public type="string" name="ok"

0x7f08066e

<public type="string" name="cancel"

0x7f0200c4

<public type="drawable" name="ic_settings_backup"

0x7f0800d7

<public type="string" name="clock_date_string_edittext_title"

0x7f0800d8

<public type="string" name="clock_date_string_edittext_summary"

0x7f080bcb

<public type="string" name="menu_save"

0x7f080bcc

<public type="string" name="menu_cancel"

SystemUI.apk Modding

1. First Decompile your SystemUI.apk and merge the files inside it (given below).

2. Now go to SystemUI.apk\res\layout\gemini_status_bar.xml and open it.

Add these lines in the xml. Compare with the "gemini_status_bar.xml" given in the guide.

<com.android.systemui.statusbar.policy.ClockLeft android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="left|center" android:id="@id/left_clock" android:paddingLeft="6.0dip" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" />

<com.android.systemui.statusbar.policy.ClockCenter android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="center" android:id="@id/center_clock" android:paddingLeft="6.0dip" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" />

<LinearLayout android:gravity="center" android:orientation="horizontal" android:id="@id/center_clock_layout" android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.ClockCenter android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="center" android:id="@id/center_clock" android:paddingLeft="6.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" />
</LinearLayout>

NOTE: To solve the issue of overlapping of other things with clock in statusbar , follow this.

• Find this line ,

<LinearLayout android:orientation="horizontal" android:id="@id/notification_icon_area" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0">

• Replace with this line ,

<LinearLayout android:gravity="left" android:orientation="horizontal" android:id="@id/notification_icon_area" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0">

• Now again find this line ,

<LinearLayout android:orientation="horizontal" android:id="@id/system_icon_area" android:layout_width="wrap_content" android:layout_height="fill_parent">

• Replace with this line ,

<LinearLayout android:gravity="right" android:orientation="horizontal" android:id="@id/system_icon_area" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0">

3. Now go to SystemUI.apk\res\values\ids.xml and open it. Now add these above </resources>.

<item type="id" name="left_clock">false</item>
<item type="id" name="clock_stock">false</item>
<item type="id" name="center_clock_layout">false</item>
<item type="id" name="center_clock">false</item>

4. Now go to SystemUI.apk\res\values\colors.xml and open it. Now add this above </resources>.

<color name="status_bar_clock_color">#ffffffff</color>

5. Now Recompile your SystemUI.apk , Sign it and then again Decompile it.

6. Now go to SystemUI.apk\smali\com\android\systemui\statusbar\phone\PhoneStatusBar.smali

• Add this line ,

.field mCenterClockLayout:Landroid/widget/LinearLayout;

Like this ,

.field private mCarrierLabelVisible:Z

.field mCenterClockLayout:Landroid/widget/LinearLayout;

.field private final mCheckBarModes:Ljava/lang/Runnable;

• Now again , Add this line

.field private mShowClock:Z

Like this ,

.field private mShowCarrierInPanel:Z

.field private mShowClock:Z

.field private mShowSearchHoldoff:I

7. Now find this method ,

.method protected makeStatusBarView()Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

• Now find these lines in this method ,

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

move-object/from16 v0, p0

• Now copy these lines and paste it below the lines that you have copied , like this

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

move-object/from16 v0, p0

• Now replace the second last line of pasted lines with this ,

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mCenterClockLayout:Landroid/widget/LinearLayout;

• The final will look like this ,

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f0?????

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mCenterClockLayout:Landroid/widget/LinearLayout;

move-object/from16 v0, p0

8. Now replace this id in "PhoneStatusBar.smali" with the id present in public.xml of your SystemUI.apk

0x7f0?????

<public type="id" name="center_clock_layout"

9. Now find this method ,

.method public showClock(Z)V

• Now delete whole lines between these ,

.method public showClock(Z)V
-
-
-
.end method

• Now copy these lines between these ,

.locals 10

.prologue
const/4 v9, -0x2

const/4 v1, 0x1

const/4 v2, 0x0

const/16 v4, 0x8

.line 3874
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

if-nez v0, :cond_1

.line 3894
:cond_0
:goto_0
return-void

.line 3875
:cond_1
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mContext:Landroid/content/Context;

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

move-result-object v3

.line 3876
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v5, 0x7f07005d

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

move-result-object v5

.line 3877
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v6, 0x7f0700db

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

move-result-object v6

.line 3878
iget-object v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v7, 0x7f0700d8

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

move-result-object v7

.line 3879
const-string v0, "status_bar_clock"

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

move-result v0

if-ne v0, v1, :cond_5

move v0, v1

.line 3882
:goto_1
const-string v8, "statusbar_clock_style"

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

move-result v8

.line 3885
if-nez v8, :cond_2

if-eqz v5, :cond_2

.line 3886
if-eqz p1, :cond_7

if-eqz v0, :cond_6

move v3, v2

:goto_2
invoke-virtual {v5, v3}, Landroid/view/View;->setVisibility(I)V

.line 3888
:cond_2
if-ne v8, v1, :cond_3

if-eqz v6, :cond_3

.line 3889
if-eqz p1, :cond_9

if-eqz v0, :cond_8

move v1, v2

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

.line 3891
:cond_3
const/4 v1, 0x2

if-ne v8, v1, :cond_0

if-eqz v7, :cond_0

.line 3892
if-eqz p1, :cond_4

if-eqz v0, :cond_4

move v4, v2

:cond_4
invoke-virtual {v7, v4}, Landroid/view/View;->setVisibility(I)V

goto :goto_0

:cond_5
move v0, v2

.line 3879
goto :goto_1

:cond_6
move v3, v4

.line 3886
goto :goto_2

:cond_7
move v3, v4

goto :goto_2

:cond_8
move v1, v4

.line 3889
goto :goto_3

:cond_9
move v1, v4

goto :goto_3

10. Now replace these ids in the above method with the ids present in public.xml of your SystemUI.apk

0x7f07005d

<public type="id" name="clock"

0x7f0700db

<public type="id" name="center_clock"

0x7f0700d8

<public type="id" name="left_clock"

11. Now go to SystemUI.apk\smali\com\android\systemui\statusbar\policy\Clock.smali and open it. Now replace the id with the id present in public.xml of your SystemUI.apk

0x7f080009

<public type="color" name="status_bar_clock_color"

12. Done , now Recompile your SystemUI.apk and Sign it.

Important Information :

• In step no. 7 , if in these lines

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

.line 523 <--------- Like This ----------->
move-object/from16 v0, p0

• The line above line "move-object/from16 v0, p0" is having line like this (may be any no.) , then after the copying and replacing (as mentioned in step 7) , it will look like this.

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

.line 523 <--------- 1 ----------->
move-object/from16 v0, p0

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f0????? (<public type="id" name="center_clock_layout")

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mCenterClockLayout:Landroid/widget/LinearLayout;

.line 523 <--------- 2 ----------->
move-object/from16 v0, p0

• Then in 2nd case , change the line number by adding 1. In this case add 1 to 523 and it will become 524. (If line 524 is already there in smali , then add 2 means 523+2 and so on). the final will look like this ,

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f070052

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarContents:Landroid/widget/LinearLayout;

.line 523 <--------- 1 ----------->
move-object/from16 v0, p0

iget-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mStatusBarView:Lcom/android/systemui/statusbar/phone/PhoneStatusBarView;

const v2, 0x7f0????? (<public type="id" name="center_clock_layout")

invoke-virtual {v1, v2}, Landroid/view/View;->findViewById(I)Landroid/view/View;

move-result-object v1

check-cast v1, Landroid/widget/LinearLayout;

move-object/from16 v0, p0

iput-object v1, v0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mCenterClockLayout:Landroid/widget/LinearLayout;

.line 524 <--------- 2 (Changed here)----------->
move-object/from16 v0, p0

• Now follow the above remaining steps given in guide.

Special Thanks To :

1. DU_Flo ROM (Extracted from this ROM)

2. Vanya Melnechenko

3. MAAaD

4. XDA

5. Raj Shekhar (For testing the guide & screenshots)