[Android Software Development] serajr:
New mods...

Here I'm gonna try to show you other mods you can try!!

Change Battery Icons Guide

1. First you need to put new battery resources within your decompiled SystemUI.apk

2. Go to \res\drawable folder and look for:

stat_sys_battery.xml
stat_sys_battery_charge.xml

3. Found, these two xml files are where all respective png's are mapped!

Let's name them as our "default" preference value (gonna be 0), so we do nothing with them

4. While at \res\drawable folder, create (CTRL+C and CTRL+V) two new files based on above ones, you will get (in red):

stat_sys_battery.xml
[COLOR="Red"]stat_sys_battery_1.xml[/COLOR]
stat_sys_battery_charge.xml
[COLOR="red"]stat_sys_battery_charge_1.xml[/COLOR]

New red files gonna be our value 1 preference

5. By editing new red files above, you will get something like this:

<?xml version="1.0" encoding="utf-8"?>
<level-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/stat_sys_battery_0" android:maxLevel="4" />
<item android:drawable="@drawable/stat_sys_battery_15" android:maxLevel="15" />
<item android:drawable="@drawable/stat_sys_battery_28" android:maxLevel="35" />
<item android:drawable="@drawable/stat_sys_battery_43" android:maxLevel="49" />
<item android:drawable="@drawable/stat_sys_battery_57" android:maxLevel="60" />
<item android:drawable="@drawable/stat_sys_battery_71" android:maxLevel="75" />
<item android:drawable="@drawable/stat_sys_battery_85" android:maxLevel="90" />
<item android:drawable="@drawable/stat_sys_battery_100" android:maxLevel="100" />
</level-list>

6. Here you need to change the drawables mapping to your new battery png's you put within your \res\drawable\YOUR_DENSITY folder:

E.g.: New png's have _1 suffix!!

<?xml version="1.0" encoding="utf-8"?>
<level-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/stat_sys_battery_0[COLOR="red"]_1[/COLOR]" android:maxLevel="4" />
<item android:drawable="@drawable/stat_sys_battery_15[COLOR="red"]_1[/COLOR]" android:maxLevel="15" />
<item android:drawable="@drawable/stat_sys_battery_28[COLOR="red"]_1[/COLOR]" android:maxLevel="35" />
<item android:drawable="@drawable/stat_sys_battery_43[COLOR="red"]_1[/COLOR]" android:maxLevel="49" />
<item android:drawable="@drawable/stat_sys_battery_57[COLOR="red"]_1[/COLOR]" android:maxLevel="60" />
<item android:drawable="@drawable/stat_sys_battery_71[COLOR="red"]_1[/COLOR]" android:maxLevel="75" />
<item android:drawable="@drawable/stat_sys_battery_85[COLOR="red"]_1[/COLOR]" android:maxLevel="90" />
<item android:drawable="@drawable/stat_sys_battery_100[COLOR="red"]_1[/COLOR]" android:maxLevel="100" />
</level-list>

7. Done with new resources!!!

Remember you can put as much as new ones you want, just change their suffix to next integer value!!!

Java

- New "clone" com.android.systemui.statusbar.policy package

- New "clone" BatteryController.java class with two new methods and all related comments there too

- Added into "clone" PhoneStatusBar.java the new handleStatusBarChangeBatteryIcons method and its "calls", take a look at:

Get new Eclipse Project from attachments!!

Smali

1. Get the newly built ExternalPreferences.apk from Eclipse project ( \bin folder )

2. Decompile it

3. Go to ExternalPreferences.apk decompiled folder: ...\smali\com\android\systemui\statusbar\phone\

4. Open PhoneStatusBar.smali

Now let's copy our new method from ExternalPreferences.apk (PhoneStatusBar.smali) file to SystemUI.apk (PhoneStatusBar.smali file)

By copying it you will get (in red):

Under # direct methods

# direct methods
[COLOR="red"].method private handleStatusBarChangeBatteryIcons()V
.locals 9

.prologue
const/4 v8, 0x0

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

const/4 v5, 0x0

new-instance v6, Landroid/content/IntentFilter;

const-string v7, "android.intent.action.BATTERY_CHANGED"

invoke-direct {v6, v7}, Landroid/content/IntentFilter;-><init>(Ljava/lang/String;)V

invoke-virtual {v4, v5, v6}, Landroid/content/Context;->registerReceiver(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;

move-result-object v0

.line 126
.local v0, getIntent:Landroid/content/Intent;
const-string v4, "level"

invoke-virtual {v0, v4, v8}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

move-result v2

.line 127
.local v2, level:I
const-string v4, "plugged"

invoke-virtual {v0, v4, v8}, Landroid/content/Intent;->getIntExtra(Ljava/lang/String;I)I

move-result v3

.line 131
.local v3, plugged:I
new-instance v1, Landroid/content/Intent;

const-string v4, "android.intent.action.BATTERY_CHANGED"

invoke-direct {v1, v4}, Landroid/content/Intent;-><init>(Ljava/lang/String;)V

.line 132
.local v1, intent:Landroid/content/Intent;
const-string v4, "level"

invoke-virtual {v1, v4, v2}, Landroid/content/Intent;->putExtra(Ljava/lang/String;I)Landroid/content/Intent;

.line 133
const-string v4, "plugged"

invoke-virtual {v1, v4, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;I)Landroid/content/Intent;

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

invoke-virtual {v4, v1}, Landroid/content/Context;->sendBroadcast(Landroid/content/Intent;)V

.line 136
return-void
.end method[/COLOR]

5. Also replace setupExternalSettingsObserver and externalPreferencesObserverCallback whole methods by the new ones

6. While on SystemUI.apk look for our last implemented method (from original guide, but now in blue) inside makeStatusBarView method, and add red lines

.line 1005
const-string v0, "com.sonymobile.notes.NEW_SKETCH"

invoke-direct {p0, v0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->isAppInstalled(Ljava/lang/String;)Z

move-result v0

iput-boolean v0, p0, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->mRightVisible:Z

[COLOR="Blue"].line 34
invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->setupExternalSettingsObserver()V

.line 37
invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->handleStatusBarChangeClockToRed()V[/COLOR]

[COLOR="Red"].line 40
invoke-direct {p0}, Lcom/android/systemui/statusbar/phone/PhoneStatusBar;->handleStatusBarChangeBatteryIcons()V[/COLOR]

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

return-object v0

:cond_14
move v1, v2

.line 825
goto/16 :goto_7

7. Go to ExternalPreferences.apk decompiled folder: ...\smali\com\android\systemui\statusbar\policy\

8. Open BatteryController.smali

Now let's copy our new methods from ExternalPreferences.apk (BatteryController.smali) file to SystemUI.apk (BatteryController.smali file)

By copying them you will get (in red):

Under # direct methods

# direct methods
[COLOR="Red"].method private getStatSysBatteryChargeResId()I
.locals 6

.prologue
.line 62
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v2

const-string v3, "stat_sys_battery_charge"

const-string v4, "drawable"

iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

move-result-object v5

invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v0

.line 65
.local v0, resId:I
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

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

move-result-object v2

const-string v3, "status_bar_change_battery_icons"

const/4 v4, 0x0

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

move-result v1

.line 66
.local v1, value:I
packed-switch v1, :pswitch_data_0

.line 77
:goto_0
return v0

.line 71
:pswitch_0
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v2

const-string v3, "stat_sys_battery_charge_1"

const-string v4, "drawable"

iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

move-result-object v5

invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v0

goto :goto_0

.line 66
:pswitch_data_0
.packed-switch 0x1
:pswitch_0
.end packed-switch
.end method

.method private getStatSysBatteryResId()I
.locals 6

.prologue
.line 36
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v2

const-string v3, "stat_sys_battery"

const-string v4, "drawable"

iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

move-result-object v5

invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v0

.line 39
.local v0, resId:I
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

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

move-result-object v2

const-string v3, "status_bar_change_battery_icons"

const/4 v4, 0x0

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

move-result v1

.line 40
.local v1, value:I
packed-switch v1, :pswitch_data_0

.line 51
:goto_0
return v0

.line 45
:pswitch_0
iget-object v2, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v2}, Landroid/content/Context;->getResources()Landroid/content/res/Resources;

move-result-object v2

const-string v3, "stat_sys_battery_1"

const-string v4, "drawable"

iget-object v5, p0, Lcom/android/systemui/statusbar/policy/BatteryController;->mContext:Landroid/content/Context;

invoke-virtual {v5}, Landroid/content/Context;->getPackageName()Ljava/lang/String;

move-result-object v5

invoke-virtual {v2, v3, v4, v5}, Landroid/content/res/Resources;->getIdentifier(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I

move-result v0

goto :goto_0

.line 40
:pswitch_data_0
.packed-switch 0x1
:pswitch_0
.end packed-switch
.end method[/COLOR]

9. While on SystemUI.apk BatteryController.smali file look for this method:

.method public onReceive(Landroid/content/Context;Landroid/content/Intent;)V

9. Found, now let's implement "calls" to our new "get" methods (in red)

Pay attention on v6 (in green), method must return as v6 (or the v? from your decompiled code)

.
.
.
.line 117
.end local v8 #plugType:I
:cond_1
:goto_1
if-eqz v9, :cond_3

const [COLOR="SeaGreen"]v6[/COLOR], 0x7f020130

[COLOR="red"]invoke-direct {p0}, Lcom/android/systemui/statusbar/policy/BatteryController;->getStatSysBatteryChargeResId()I

move-result [COLOR="SeaGreen"]v6[/COLOR][/COLOR]

.line 120
.local [COLOR="SeaGreen"]v6[/COLOR], icon:I
:goto_2
move-object/from16 v0, p0

iget-object v13, v0, Lcom/android/systemui/statusbar/policy/BatteryController;->mIconViews:Ljava/util/ArrayList;

invoke-virtual {v13}, Ljava/util/ArrayList;->size()I

move-result v1
.
.
.

.
.
.
.line 117
.end local v8 #plugType:I
:cond_3
const [COLOR="green"]v6[/COLOR], 0x7f020127

[COLOR="Red"]invoke-direct {p0}, Lcom/android/systemui/statusbar/policy/BatteryController;->getStatSysBatteryResId()I

move-result [COLOR="SeaGreen"]v6[/COLOR][/COLOR]

goto :goto_2

.line 128
.restart local v1 #N:I
.restart local v4 #i:I
.restart local v6 #icon:I
.
.
.

0x7f020130 is the hex value from original stat_sys_battery_charge resource (under SystemUI.apk public.xml)

0x7f020127 is the hex value from original stat_sys_battery resource (under SystemUI.apk public.xml)

Your values may differ!!!

10. Double check your changes, save everything, compile your modified SystemUI.apk and... done!!

Others soon...

.

.