FORUMS
Remove All Ads from XDA

[GUIDE][4.2+] Replace your statusbar clock with a styled TextClock

6,171 posts
Thanks Meter: 15,239
 
By Spannaa, Recognized Contributor / Themer on 11th April 2014, 04:03 PM
Post Reply Email Thread
This guide assumes that you can decompile & recompile apks.

Whilst theming my statusbar clock and running into a couple of smali problems, @Ticklefish suggested I look at TextClock - an extension to TextView that was introduced in Android 4.2

TextClock can display the current time and/or date as a formatted string using both 12-hour and 24-hour modes and makes a great drop-in replacement for the normal statusbar clock.

The statusbar clock code is contained in the com.android.systemui.statusbar.policy.Clock code block in SystemUI.apk\res\layout\status_bar.xml and we can replace this with a TextClock code block:
Code:
<TextClock android:format12Hour="EEE h:mm a" android:format24Hour="EEE HH:mm" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:id="@id/clock" android:paddingLeft="3.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:singleLine="true" />
The important bits here are the format strings:
Code:
android:format12Hour="EEE h:mm a"
which shows as Fri 8:26 PM

Code:
android:format24Hour="EEE HH:mm"
which shows as Fri 20:26

You can use a combination of the options below to create your preferred format:

Quote:

d.............Day Of Month (single digit) 7
dd.......... Day Of Month (double digit) Zero, 07
EEEE......Day Of Week (Full) Monday
EEE........Week Day (Short) Mon
MMMM....Month (Full) AUGUST
MMM.......Month (Short) AUG
MM..........Month (double digit) 08
M............Month (Single digit) 8
yyyy........Year (Full) 2013
yy............Year (Short) 13
h..............Hour (12 hour, single digit) 8
hh............Hour (12 hour, double digit) 08
H.............Hour (24 hour, single digit) 8 20
HH...........Hour (24 hour, double digit) 08 20 (Note: some roms use kk instead)
m.............Minute (single digit) 9
MM..........Minute (double digit) 09
s..............Second (single digit) 9
ss............Second (double digit) 09
a..............Marker AM/PM

One advantage of using TextClock is that if you move the android:format strings into string resources, you can embed simple HTML into the strings to enhance the result

So replace:
Code:
android:format12Hour="EEE h:mm a" android:format24Hour="EEE HH:mm"
with:
Code:
android:format12Hour="@string/status_bar_clock_12hr_format" android:format24Hour="@string/status_bar_clock_24hr_format"
and add two strings to the bottom of SystemUI.apk\res\values\strings.xml,
Code:
	<string name="status_bar_clock_12hr_format">EEE h:mm a</string>
	<string name="status_bar_clock_24hr_format">EEE HH:mm</string>
these can then be styled using HTML

Quote:

<b>...</b> ..................................makes the the enclosed text bold
<i>...</i> ...................................makes the the enclosed text italic
<font size ="X">...</font> ............sets the font size of the enclosed text to X.0dip
<font fgcolor ="#ffffffff">...</> ........sets the foreground colour of the enclosed text
<font bgcolor ="#ff000000">...</> .sets the background colour of the enclosed text

Example:
Code:
<string name="status_bar_clock_12hr_format"><font size="12">EEE </font>h:mm<font size="12"> a</font></string>
which shows as as the base font size was 18.0dip

Code:
<string name="status_bar_clock_24hr_format"><font size="12">EEE </font>HH:mm</string>
which shows as as the base font size was 18.0dip

Other styling is handled normally, either in-line or in an external style resource in SystemUI.apk\res\values\styles.xml
Code:
android:textAppearance="@style/TextAppearance.StatusBar.Clock"
Embedding HTML in string resources will also work in a normal TextView and there are a few additional tags you can use. REFERENCE

Note: Setting android:textAllCaps="true" inline or <item name="android:textAllCaps">true</item> in your external style resource will break the HTML embedded in the XML strings as this HAS to be in lowercase for it to be parsed.
The Following 45 Users Say Thank You to Spannaa For This Useful Post: [ View ] Gift Spannaa Ad-Free
 
 
12th April 2014, 10:28 AM |#2  
_Sale_'s Avatar
Recognized Developer / Recognized Contributor
Thanks Meter: 53,734
 
Donate to Me
More
Nice work Spannaa :thumbup:

Sent from my GT-I9100 using Tapatalk 2
The Following 5 Users Say Thank You to _Sale_ For This Useful Post: [ View ]
12th April 2014, 11:41 AM |#3  
avirk's Avatar
Recognized Contributor
Thanks Meter: 5,372
 
More
Great guide mate. Just missed the 4.1+ version.
The Following 3 Users Say Thank You to avirk For This Useful Post: [ View ] Gift avirk Ad-Free
13th April 2014, 07:49 AM |#4  
ICS_XD's Avatar
Senior Member
Flag Hidden Leaf Village
Thanks Meter: 13,268
 
Donate to Me
More
Nice Guide Bro :thumbup::thumbup::thumbup::thumbup::thumbup:

Sent from my GT-I9500 using Tapatalk 2
The Following 2 Users Say Thank You to ICS_XD For This Useful Post: [ View ] Gift ICS_XD Ad-Free
15th April 2014, 02:37 PM |#5  
Spannaa's Avatar
OP Recognized Contributor / Themer
Flag Cardiff
Thanks Meter: 15,239
 
Donate to Me
More
Quote:
Originally Posted by _Sale_

Nice work Spannaa :thumbup:

Quote:
Originally Posted by ICS_XD

Nice Guide Bro :thumbup::thumbup::thumbup::thumbup::thumbup:

Quote:
Originally Posted by avirk

Great guide mate. Just missed the 4.1+ version.

Thanks.

Unfortunately, it won't work on 4.1.2 NeatROM for the S2 as Google only introduced the code in v4.2
The Following 2 Users Say Thank You to Spannaa For This Useful Post: [ View ] Gift Spannaa Ad-Free
28th April 2014, 11:44 AM |#6  
glfsd's Avatar
Senior Member
Thanks Meter: 1,250
 
Donate to Me
More
thanks Spannaa, great guide

please a helping hand. where am I doing wrong?


this is my clock line
Code:
<com.android.systemui.statusbar.policy.Clock android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="center" android:id="@id/clock" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:shadowColor="#ff000000" android:shadowDy="2.0" android:shadowRadius="2.0" />
and I replaced it with
Code:
<TextClock android:format24Hour="@string/status_bar_clock_24hr_format" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="bottom" android:id="@id/clock" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:shadowColor="#ff000000" android:shadowDy="2.0" android:shadowRadius="2.0" />
and in strings.xml I added
Code:
	<string name="status_bar_clock_24hr_format">EEE HH:mm</string>
I'd like it to be like your example


and I wish it was Lun and no lun

ps. sorry for my poor english
28th April 2014, 12:05 PM |#7  
Spannaa's Avatar
OP Recognized Contributor / Themer
Flag Cardiff
Thanks Meter: 15,239
 
Donate to Me
More
Quote:
Originally Posted by glfsd

thanks Spannaa, great guide

please a helping hand. where am I doing wrong?



this is my clock line
Code:
<com.android.systemui.statusbar.policy.Clock android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="center" android:id="@id/clock" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:shadowColor="#ff000000" android:shadowDy="2.0" android:shadowRadius="2.0" />
and I replaced it with
Code:
<TextClock android:format24Hour="@string/status_bar_clock_24hr_format" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:gravity="bottom" android:id="@id/clock" android:layout_width="wrap_content" android:layout_height="fill_parent" android:singleLine="true" android:shadowColor="#ff000000" android:shadowDy="2.0" android:shadowRadius="2.0" />
and in strings.xml I added
Code:
	<string name="status_bar_clock_24hr_format">EEE HH:mm</string>
I'd like it to be like your example


and I wish it was Lun and no lun

ps. sorry for my poor english

To display the correct hour, try changing the HH to kk (something to do with SimpleDateFormat)

I'm pretty sure that the capitalisation of the day is controlled by your timezone and locale settings so I don't think that's changeable.
The Following 2 Users Say Thank You to Spannaa For This Useful Post: [ View ] Gift Spannaa Ad-Free
28th April 2014, 01:09 PM |#8  
glfsd's Avatar
Senior Member
Thanks Meter: 1,250
 
Donate to Me
More
Quote:
Originally Posted by Spannaa

To display the correct hour, try changing the HH to kk (something to do with SimpleDateFormat)

THANK YOU VERY MUCH! with "kk"


Quote:
Originally Posted by Spannaa

I'm pretty sure that the capitalisation of the day is controlled by your timezone and locale settings so I don't think that's changeable.

28th April 2014, 03:15 PM |#9  
Spannaa's Avatar
OP Recognized Contributor / Themer
Flag Cardiff
Thanks Meter: 15,239
 
Donate to Me
More
Quote:
Originally Posted by glfsd

THANK YOU VERY MUCH! with "kk"




Since you're not using HTML tags in your string, you could set android:textAllCaps="true" inline or <item name="android:textAllCaps">true</item> in your external style resource to change lun to LUN
The Following 3 Users Say Thank You to Spannaa For This Useful Post: [ View ] Gift Spannaa Ad-Free
28th April 2014, 03:36 PM |#10  
glfsd's Avatar
Senior Member
Thanks Meter: 1,250
 
Donate to Me
More
Quote:
Originally Posted by Spannaa

Since you're not using HTML tags in your string, you could set android:textAllCaps="true" inline or <item name="android:textAllCaps">true</item> in your external style resource to change lun to LUN

i had understood this, i would have wanted to try "Lun"


anyway, thanks again!
29th April 2014, 11:19 AM |#11  
glfsd's Avatar
Senior Member
Thanks Meter: 1,250
 
Donate to Me
More
sorry Spannaa, one last thing.
I can not change the font size of the "LUN"


I put it in strings.xml, this
Code:
    <string name="status_bar_clock_24hr_format"><font size="8">EEE </font>kk:mm</string>
is that right? but does not change

this is my styles.xml
Code:
    <style name="TextAppearance.StatusBar.Clock" parent="@*android:style/TextAppearance.StatusBar.Icon">
        <item name="android:textSize">16.0dip</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textColor">#ffffffff</item>
    </style>
Post Reply Subscribe to Thread

Tags
android 4.2+, statusbar clock, statusbar expanded clock, textclock, theming

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes