Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP jeboo

14th April 2012, 09:08 PM   |  #1  
jeboo's Avatar
OP Recognized Contributor / Recognized Developer
Thanks Meter: 3,970
 
761 posts
Join Date:Joined: Apr 2010
Donate to Me
More



****** 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 =)
Last edited by jeboo; 18th August 2012 at 09:47 PM.
The Following 29 Users Say Thank You to jeboo For This Useful Post: [ View ]
14th April 2012, 09:37 PM   |  #2  
shoman94's Avatar
Recognized Contributor
Flag Maine
Thanks Meter: 12,255
 
8,478 posts
Join Date:Joined: Mar 2009
Donate to Me
More
Excellent.... built into my rom. Thanks !
15th April 2012, 06:43 AM   |  #3  
Senior Member
Flag 台灣
Thanks Meter: 756
 
797 posts
Join Date:Joined: Sep 2006
More
...or just use 24h format which is shorter and more natural
15th April 2012, 07:06 AM   |  #4  
shoman94's Avatar
Recognized Contributor
Flag Maine
Thanks Meter: 12,255
 
8,478 posts
Join Date:Joined: Mar 2009
Donate to Me
More
Quote:
Originally Posted by sorg

...or just use 24h format which is shorter and more natural

Ummm You can use this to remove the clock completely....
15th April 2012, 07:11 AM   |  #5  
jeboo's Avatar
OP Recognized Contributor / Recognized Developer
Thanks Meter: 3,970
 
761 posts
Join Date:Joined: Apr 2010
Donate to Me
More
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 Following User Says Thank You to jeboo For This Useful Post: [ View ]
16th April 2012, 05:42 AM   |  #6  
LiLChris06's Avatar
Senior Member
Flag XDA
Thanks Meter: 1,281
 
2,381 posts
Join Date:Joined: Nov 2011
More
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!
Last edited by LiLChris06; 16th April 2012 at 07:59 AM.
16th April 2012, 10:36 AM   |  #7  
Mirko ddd's Avatar
Recognized Contributor / Recognized Developer
Flag Piazza Armerina
Thanks Meter: 4,730
 
1,453 posts
Join Date:Joined: Nov 2010
Donate to Me
More
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
The Following User Says Thank You to Mirko ddd For This Useful Post: [ View ]
17th April 2012, 02:49 AM   |  #8  
vlara's Avatar
Senior Member
Thanks Meter: 183
 
148 posts
Join Date:Joined: Jan 2011
Donate to Me
More
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
The Following User Says Thank You to vlara For This Useful Post: [ View ]
17th April 2012, 09:36 PM   |  #9  
yoderk's Avatar
Senior Member
Flag Reno
Thanks Meter: 270
 
417 posts
Join Date:Joined: Sep 2010
Donate to Me
More
This mod is amazing, thank you very much my friend works fabulously
29th April 2012, 11:40 PM   |  #10  
jeboo's Avatar
OP Recognized Contributor / Recognized Developer
Thanks Meter: 3,970
 
761 posts
Join Date:Joined: Apr 2010
Donate to Me
More
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!
Last edited by jeboo; 30th April 2012 at 12:17 AM.

The Following 6 Users Say Thank You to jeboo For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes