5,604,122 Members 49,973 Now Online
XDA Developers Android and Mobile Development Forum

[Guide] Add toggle settings to hide clock/AM/PM

Tip us?
 
jeboo
Old
(Last edited by jeboo; 18th August 2012 at 08:47 PM.)
#1  
jeboo's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 3756
Posts: 716
Join Date: Apr 2010

 
DONATE TO ME
Default [Guide] Add toggle settings to hide clock/AM/PM




****** 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/SHOstock...c58eb8cce03248
https://github.com/shoman94/SHOstock...8372ab6a199cc2


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:
Code:
<public type="string" name="disable_ampm" id="0x7f0b0923" />
<public type="string" name="disable_ampm_text" id="0x7f0b0924" />
<public type="string" name="disable_time" id="0x7f0b0925" />
<public type="string" name="disable_time_text" id="0x7f0b0926" />
strings.xml, add:
Code:
<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:
Code:
<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:
Code:
.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:
Code:
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:
Code:
.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:
Code:
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:
Code:
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':
Code:
: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!):
Code:
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, 0x7f0e0027

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:
Code:
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:
Code:
.locals 3
Find:
if-eqz p1, :cond_1

const/4 v0, 0x0

and insert this code after it:
Code:
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 =)
The Binary Won. Thank you to all the donors!
Check out HomerBall, my free app: https://play.google.com/store/apps/d...ag87.homerball
The Following 29 Users Say Thank You to jeboo For This Useful Post: [ Click to Expand ]
 
shoman94
Old
#2  
shoman94's Avatar
Recognized Contributor
Thanks Meter 11761
Posts: 8,332
Join Date: Mar 2009
Location: Maine

 
DONATE TO ME
Excellent.... built into my rom. Thanks !
<a href=http://forum.xda-developers.com/signaturepics/sigpic1670609_1.gif target=_blank rel=nofollow >http://forum.xda-developers.com/sign...c1670609_1.gif</a>
IRC: freenode|#shostock


Asus Transformer Prime[32gb]
Stock-JellyBean

Asus Transformer[16gb]
ICS RevolutionHD
 
sorg
Old
#3  
Senior Member
Thanks Meter 506
Posts: 634
Join Date: Sep 2006
Location: 台灣
...or just use 24h format which is shorter and more natural
Samsung Galaxy S4 SHV-E330S: Optimus ROM (i9506 TW 4.3) & Kernel. CPU OC 2.7GHz, GPU OC 645MHz, non-KNOX bootloader, UHD/360 Camera.
Samsung Galaxy S4 GT-I9500: Optimus ROM (TW 4.3), Perseus Kernel. CPU No-OC, GPU OC 700MHz, non-KNOX bootloader.
Past models: Samsung Galaxy SIII SHV-E210K & GT-I9300, Samsung Galaxy SII GT-I9100.
 
shoman94
Old
#4  
shoman94's Avatar
Recognized Contributor
Thanks Meter 11761
Posts: 8,332
Join Date: Mar 2009
Location: Maine

 
DONATE TO ME
Quote:
Originally Posted by sorg View Post
...or just use 24h format which is shorter and more natural
Ummm You can use this to remove the clock completely....
<a href=http://forum.xda-developers.com/signaturepics/sigpic1670609_1.gif target=_blank rel=nofollow >http://forum.xda-developers.com/sign...c1670609_1.gif</a>
IRC: freenode|#shostock


Asus Transformer Prime[32gb]
Stock-JellyBean

Asus Transformer[16gb]
ICS RevolutionHD
 
jeboo
Old
#5  
jeboo's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 3756
Posts: 716
Join Date: Apr 2010

 
DONATE TO ME
I just updated to OP to include Step 4. I didn't realize the lock screen was interfering with the feature since I don't use one..Fixed now.
The Binary Won. Thank you to all the donors!
Check out HomerBall, my free app: https://play.google.com/store/apps/d...ag87.homerball
The Following User Says Thank You to jeboo For This Useful Post: [ Click to Expand ]
 
LiLChris06
Old
(Last edited by LiLChris06; 16th April 2012 at 06:59 AM.)
#6  
LiLChris06's Avatar
Senior Member
Thanks Meter 1280
Posts: 2,381
Join Date: Nov 2011
Location: XDA
Building into mine as well, tonight if I don't fall asleep.



And a few moments of disagreeing with smali, got it going...thanks a bunch Jeboo!
 
Mirko ddd
Old
#7  
Mirko ddd's Avatar
Recognized Contributor / Recognized Developer
Thanks Meter 4687
Posts: 1,441
Join Date: Nov 2010
Location: Piazza Armerina

 
DONATE TO ME
nice, welldone!
but it s better to leave public.xml, add only the others xml and recompile once.
then decompile again to get the public xml
it s safer, and then match the smali changes with the new public values.
Anyway great guide
NICOLA SAVED ME!

If I helped you and/or you like my rom consider a small donation and/or join Disaster Family on Facebook
I DON'T ANSWER ON PM ABOUT ROM/MODDING STUFFS

The Following User Says Thank You to Mirko ddd For This Useful Post: [ Click to Expand ]
 
vlara
Old
#8  
vlara's Avatar
Senior Member
Thanks Meter 183
Posts: 148
Join Date: Jan 2011

 
DONATE TO ME
if your decompiling with smali/baksmali directly make sure to use the -l flag (thats a L) so you have local varibles instead of registers, learned this the hard way lol

SGS3 i747: Ultimatum 1.2
SGS2 i777: Ultimatum 2.2
HTC Flyer: HoneyPot 1.2
Dell Streak: DSC
BB Playbook: BB OS 2.0
Iphone 4: 5.0.1 <---
The Following User Says Thank You to vlara For This Useful Post: [ Click to Expand ]
 
yoderk
Old
#9  
yoderk's Avatar
Senior Member
Thanks Meter 268
Posts: 415
Join Date: Sep 2010
Location: Henderson

 
DONATE TO ME
This mod is amazing, thank you very much my friend works fabulously
Phone: Nexus 4 16gb
Kernel: franco.kernel
Rom: Xylon 016 B1 Build

If my post has in any way helped or humored you, please hit the thanks button

Always have your stuff when you need it with Dropbox
Dropbox 2gb free!
 
jeboo
Old
(Last edited by jeboo; 29th April 2012 at 11:17 PM.)
#10  
jeboo's Avatar
Recognized Contributor / Recognized Developer - OP
Thanks Meter 3756
Posts: 716
Join Date: Apr 2010

 
DONATE TO ME
Default Add a toggle for CRT Animation

Building upon the same theme from the OP, we can now add another toggle under display settings for CRT animation. This feature is controlled by the boolean animateScreenLights in framework-res.apk (thanks to whomever the original author was!).

Since adding the setting is pretty much identical to the procedure in the OP, I will just discuss the relevant code needed to access the new setting (I leave adding the setting up to you!). The only requirement is you name your setting 'crt_animation'.

Our patch point will be inside services.jar, specifically PowerManagerService$BrightnessState.smali (this is based on LP7):

Code:
iget-object v6, p0, Lcom/android/server/PowerManagerService$BrightnessState;->this$0:Lcom/android/server/PowerManagerService;

iget-boolean v6, v6, Lcom/android/server/PowerManagerService;->mAnimateScreenLights:Z

if-nez v6, :cond_19
NOTE: cond_19 may differ depending on your decompiler.

So we need to delete the 3 lines above. In its place, add our new code:

Code:
iget-object v0, p0, Lcom/android/server/PowerManagerService$BrightnessState;->this$0:Lcom/android/server/PowerManagerService;

invoke-static {v0}, Lcom/android/server/PowerManagerService;->access$4300(Lcom/android/server/PowerManagerService;)Landroid/content/Context;
    
move-result-object v0
	
invoke-virtual {v0}, Landroid/content/Context;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v0

const-string v1, "crt_animation"

const/4 v4, 0x0

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

move-result v6

if-eqz v6, :cond_19
NOTE: Again, if cond_19 is different, fix the last line above!

Recompile settings.apk & services.jar, u/l and reboot!
The Binary Won. Thank you to all the donors!
Check out HomerBall, my free app: https://play.google.com/store/apps/d...ag87.homerball

The Following 6 Users Say Thank You to jeboo For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes