[MOD][TUT]How To Add Seconds To The Statusbar Clock

Did you find this tutorial useful?

  • Yes

    Votes: 35 87.5%
  • No

    Votes: 5 12.5%

  • Total voters
    40

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
This is a TICKLEFISH TUTORIAL!


If you've been following these tutorials, you'll know by now how to center the clock in the statusbar and how to change its colour to whatever you like. So far, so good.

Now, let's do something you won't see anywhere else. Let's make it display seconds!

You haven't been following my threads?
Well, click here to find out how to change the clock's colour and here to find out how to center it.

So..let's get started.

We will need to edit status_bar.xml in SystemUI.apk. To do this, we'll need to pull and decompile the apk file from the phone.

What's the best way to do this? Why, with Tickle My Android, of course! :D

This is the stock code in Timescape ICS:

Code:
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.phone.PhoneStatusBarView android:orientation="vertical" android:background="@drawable/status_bar_background" android:focusable="true" android:descendantFocusability="afterDescendants"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui">
  <LinearLayout android:orientation="horizontal" android:id="@id/icons" android:paddingLeft="6.0dip" android:paddingRight="6.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:orientation="horizontal" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0">
      <com.android.systemui.statusbar.StatusBarIconView android:id="@id/moreIcon" android:layout_width="@dimen/status_bar_icon_size" android:layout_height="fill_parent" android:visibility="gone" android:src="@drawable/stat_notify_more" />
      <com.android.systemui.statusbar.phone.IconMerger android:orientation="horizontal" android:id="@id/notificationIcons" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentLeft="true" />
    </LinearLayout>
    <LinearLayout android:orientation="horizontal" android:id="@id/statusIcons" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" />
    <ImageView android:id="@id/stat_no_sim" android:paddingLeft="4.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:layout_gravity="center_vertical" />
    <LinearLayout android:orientation="horizontal" android:id="@id/signal_battery_cluster" android:paddingLeft="2.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center">
      <include android:id="@id/signal_cluster" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/signal_cluster_view" />
      <ImageView android:id="@id/battery" android:paddingLeft="8.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>
    <com.android.systemui.statusbar.policy.Clock android:id="@id/clock" android:paddingLeft="6.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="left|center" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:singleLine="true" />
  </LinearLayout>
  <LinearLayout android:orientation="horizontal" android:id="@id/ticker" android:paddingLeft="6.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:animationCache="false">
    <ImageSwitcher android:id="@id/tickerIcon" android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:layout_marginRight="4.0dip">
      <com.android.systemui.statusbar.AnimatedImageView android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:scaleType="center" />
      <com.android.systemui.statusbar.AnimatedImageView android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:scaleType="center" />
    </ImageSwitcher>
    <com.android.systemui.statusbar.phone.TickerView android:id="@id/tickerText" android:paddingRight="10.0dip" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:paddingTop="2.0dip">
      <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.StatusBar.PhoneTicker" android:singleLine="true" />
      <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.StatusBar.PhoneTicker" android:singleLine="true" />
    </com.android.systemui.statusbar.phone.TickerView>
  </LinearLayout>
</com.android.systemui.statusbar.phone.PhoneStatusBarView>
We'll need to edit the line containing the clock:

Code:
    <com.android.systemui.statusbar.policy.Clock android:id="@id/clock" android:paddingLeft="6.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="left|center" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:singleLine="true" />
Now, how do we add seconds to this? XML tags? Smali edits?

Nah..

We'll cheat!

There's a little bit of widget code that's been in Android for ages called 'DigitalClock'. This provides..can you guess..a digital clock! And we're going to use it like this:

Code:
    <DigitalClock android:id="@id/clock" android:paddingLeft="6.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="left|center" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:singleLine="true" />
This will change the xml to:

Code:
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.phone.PhoneStatusBarView android:orientation="vertical" android:background="@drawable/status_bar_background" android:focusable="true" android:descendantFocusability="afterDescendants"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui">
  <LinearLayout android:orientation="horizontal" android:id="@id/icons" android:paddingLeft="6.0dip" android:paddingRight="6.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:orientation="horizontal" android:layout_width="0.0dip" android:layout_height="fill_parent" android:layout_weight="1.0">
      <com.android.systemui.statusbar.StatusBarIconView android:id="@id/moreIcon" android:layout_width="@dimen/status_bar_icon_size" android:layout_height="fill_parent" android:visibility="gone" android:src="@drawable/stat_notify_more" />
      <com.android.systemui.statusbar.phone.IconMerger android:orientation="horizontal" android:id="@id/notificationIcons" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" android:layout_alignParentLeft="true" />
    </LinearLayout>
    <LinearLayout android:orientation="horizontal" android:id="@id/statusIcons" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center_vertical" />
    <ImageView android:id="@id/stat_no_sim" android:paddingLeft="4.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" android:layout_gravity="center_vertical" />
    <LinearLayout android:orientation="horizontal" android:id="@id/signal_battery_cluster" android:paddingLeft="2.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="center">
      <include android:id="@id/signal_cluster" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="@layout/signal_cluster_view" />
      <ImageView android:id="@id/battery" android:paddingLeft="8.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>
    <DigitalClock android:id="@id/clock" android:paddingLeft="6.0dip" android:layout_width="wrap_content" android:layout_height="fill_parent" android:gravity="left|center" android:textAppearance="@style/TextAppearance.StatusBar.Clock" android:singleLine="true" />
  </LinearLayout>
  <LinearLayout android:orientation="horizontal" android:id="@id/ticker" android:paddingLeft="6.0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:animationCache="false">
    <ImageSwitcher android:id="@id/tickerIcon" android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:layout_marginRight="4.0dip">
      <com.android.systemui.statusbar.AnimatedImageView android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:scaleType="center" />
      <com.android.systemui.statusbar.AnimatedImageView android:layout_width="@dimen/status_bar_icon_size" android:layout_height="@dimen/status_bar_icon_size" android:scaleType="center" />
    </ImageSwitcher>
    <com.android.systemui.statusbar.phone.TickerView android:id="@id/tickerText" android:paddingRight="10.0dip" android:layout_width="0.0dip" android:layout_height="wrap_content" android:layout_weight="1.0" android:paddingTop="2.0dip">
      <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.StatusBar.PhoneTicker" android:singleLine="true" />
      <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="@style/TextAppearance.StatusBar.PhoneTicker" android:singleLine="true" />
    </com.android.systemui.statusbar.phone.TickerView>
  </LinearLayout>
</com.android.systemui.statusbar.phone.PhoneStatusBarView>
Save, recompile, blah-blah-blah.

And here it is:



It's worth noting that DigitalClock doesn't have any leading zeros. Which means, at one o'clock in the morning, the clock shows 1:00:00, not 01:00:00.

There's also another widget code you might be interested in, which is AnalogClock. This gives you...well, I'm sure you can guess.
This doesn't work well on the statusbar as the clock won't be big enough. But it can be used in other places.
Here's my personal setup on my Mini Pro:


Have fun!
 

coolkwc

Member
Dec 21, 2012
15
2
0
Bro, i can't recompile the file. it said "error, "systemUI.apk" has not been fully decompiled". In fact i already modified the code inside the status_bar.xml

Tickle My Android version 4.3,
Mini Pro ICS .587 stock ROM, rooted.

Thanks.
 

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
Bro, i can't recompile the file. it said "error, "systemUI.apk" has not been fully decompiled". In fact i already modified the code inside the status_bar.xml

Tickle My Android version 4.3,
Mini Pro ICS .587 stock ROM, rooted.

Thanks.
Yes, but the apk is still missing information. If you're using the stock rom, chances are you didn't install framework-res.apk before you started decompiling.

Oh, and Tickle My Android is on Version 5.0 now..

Sent from my SK17i using xda premium
 
  • Like
Reactions: kssood and luki2411

coolkwc

Member
Dec 21, 2012
15
2
0
Yes, but the apk is still missing information. If you're using the stock rom, chances are you didn't install framework-res.apk before you started decompiling.

Oh, and Tickle My Android is on Version 5.0 now..

Sent from my SK17i using xda premium
Bro, i'm using v5 now. Can recompile...after that what shall i do? option 14 to prepare system apps for pushing? or option 15 to sign? after that how to push back the device? create flashable zip? i try create zip, but error... Sorry bro, i read the TMA tutorial, but it is confusing, especially after the step of recompile.

Thanks in advance.

---------- Post added at 06:58 PM ---------- Previous post was at 06:49 PM ----------

Bro, i'm using v5 now. Can recompile...after that what shall i do? option 14 to prepare system apps for pushing? or option 15 to sign? after that how to push back the device? create flashable zip? i try create zip, but error... Sorry bro, i read the TMA tutorial, but it is confusing, especially after the step of recompile.

Thanks in advance.
Bro, i adi figure out how to create zip, previously i din set destination folder for zip.:p
 

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
Bro, i'm using v5 now. Can recompile...after that what shall i do? option 14 to prepare system apps for pushing? or option 15 to sign? after that how to push back the device? create flashable zip? i try create zip, but error... Sorry bro, i read the TMA tutorial, but it is confusing, especially after the step of recompile.

Thanks in advance.

---------- Post added at 06:58 PM ---------- Previous post was at 06:49 PM ----------



Bro, i adi figure out how to create zip, previously i din set destination folder for zip.:p
Once you've successfully recompiled, you need to prepare the files then make a flashable zip. Preparing signs the new apk in the same way as the old, which you need to do to make the phone accept it.

Sent from my SK17i using xda premium
 
  • Like
Reactions: kssood and luki2411

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
Whalesplaho, the xda app is misbehaving again and I can't view your post to quote it.
But basically, the code is AnalogClock and you just need to set the width and height. If you examine the full tag for DigitalClock as I wrote in the op, that should give you enough to start with.
The analogue clock is really meant for app developers to use, because it doesn't work well when it's small, but it works well on the tracking part of the drop-down notification screen.
Have a play and experiment with it. It's the best way of learning!

Sent from my SK17i using xda premium
 

sandy7

Inactive Recognized Developer
May 28, 2012
6,215
6,842
0
31
bangalore
really like it tackelfish...definitly going to try this..

Just one question..don't I need the png's for clock in notification area.?

Sent from my SK17i using XDA Premium HD app
 

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
really like it tackelfish...definitly going to try this..

Just one question..don't I need the png's for clock in notification area.?

Sent from my SK17i using XDA Premium HD app
Nope. You can actually use PNG's for the different parts of the clock if you want but what you see in the screenshots is how it looks by default. All you need is code.

Sent from my SK17i using xda premium
 

coolkwc

Member
Dec 21, 2012
15
2
0
Once you've successfully recompiled, you need to prepare the files then make a flashable zip. Preparing signs the new apk in the same way as the old, which you need to do to make the phone accept it.

Sent from my SK17i using xda premium
Bro, i really dun know what's wrong with my step, please kindly review.

1. Pull framework-res.apk, decompiled and install in PC.
2. Pull systemUI.apk, decompiled.
3. Edit status_bar.xml as stated, then save.
4. recompile systemUI.apk
5. prepare system apps for pushing.
6. sign app.
7. create flashable zip

Here's the problem, i dun understand the purpose of step 5 and 6, am i doing wrongly??
I flash using CMW, boot into recovery and install zip from sdcard.
the result is as follow:

<<FLASHING MOD>>

ADDING XTRA FILES>>
[!] Nothing to do in XTRAS

WORPHING >>
[!] Nothing to morph

{ Nothing has changed }

CLEANING CACHE, TEMPORAL FILES & EXIT >>

Install from sdcard complete.

i reboot and nothing has changed. I tried pull the modified systemUI.apk from phone, and noticed that the status_bar.xml still remained same as original, which doesn't changed as i edit.

Really no idea what's wrong with that.

Thanks in advance.
 
  • Like
Reactions: Ticklefish

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
Bro, i really dun know what's wrong with my step, please kindly review.

1. Pull framework-res.apk, decompiled and install in PC.
2. Pull systemUI.apk, decompiled.
3. Edit status_bar.xml as stated, then save.
4. recompile systemUI.apk
5. prepare system apps for pushing.
6. sign app.
7. create flashable zip

Here's the problem, i dun understand the purpose of step 5 and 6, am i doing wrongly??
I flash using CMW, boot into recovery and install zip from sdcard.
the result is as follow:

<<FLASHING MOD>>

ADDING XTRA FILES>>
[!] Nothing to do in XTRAS

WORPHING >>
[!] Nothing to morph

{ Nothing has changed }

CLEANING CACHE, TEMPORAL FILES & EXIT >>

Install from sdcard complete.

i reboot and nothing has changed. I tried pull the modified systemUI.apk from phone, and noticed that the status_bar.xml still remained same as original, which doesn't changed as i edit.

Really no idea what's wrong with that.

Thanks in advance.
Don't sign the apk. That's what preparing it is all about.

And it looks like you're creating the zip file without putting any files in it. Once you've recompiled and prepared SystemUI.apk, you need to add it to system/app in the zip menu. Then you can make the zip.

Sent from my SK17i using xda premium
 

Ticklefish

Recognized Themer
Oct 27, 2011
6,743
8,534
263
Hampshire, UK
edited some xml but cant recompile... apktool aint working on windows 8, i get error apktool is not recognised while trying to recompile!

ticklefish should i upload my edited file & help me recompile please?
I'm happy to, if I have the time. I might even be able to in a hour or two. In the meantime, what are you using for your de/recompiling?

Sent from my SK17i using xda premium