[Android Themes] 05Gurpreet:
In this guide , I will tell "How to add Battery Bar" option in Settings. :)

Tested this option on Android 4.2 and 4.4​

REQUIREMENTS :

1. Brain

2. Apktool

3. Notepad ++

4. Knowledge on How to Decompile/Recompile the apk

Lets start ,

NOTE : Those are not having the "colorpicker" folder in Settings/smali/net/margaritov/preference and having any other colorpicker in different location then open the "battery_bar_prefs" and edit this line by changing the path of colorpicker in this line.

<net.margaritov.preference.colorpicker.ColorPickerPreference android:title="@string/battery_bar_color" android:key="battery_bar_color" android:defaultValue="\#ffffff" alphaSlider="true" />

Those who are not having any color picker , first add that using guide whose link is given below.

http://xdaforums.com/android/themes/guide-add-coloricker-settings-t3176597/post62282065#post62282065

Settings.apk Modding

1. First Decompile your Settings.apk and merge the files (given below).

2. Now add this line in display_settings.xml or any other xml present in Settings.apk/res/xml.

<PreferenceScreen android:title="@string/battery_bar_title" android:key="battery_bar" android:summary="@string/battery_bar_summary" android:fragment="com.android.settings.gurpreet.batterybar.BatteryBarStyle" />

3. Now open strings.xml and add these lines above </resources>.

<string name="battery_bar_title">Battery Bar</string>
<string name="battery_bar_summary">Enable the battery bar option in statusbar</string>
<string name="battery_bar">Battery bar location</string>
<string name="battery_bar_color">Battery bar color</string>
<string name="battery_bar_cat">Battery bar style</string>
<string name="battery_bar_style_title">Battery bar alignment</string>
<string name="battery_bar_thickness_title">Battery bar thickness</string>
<string name="battery_bar_animate_title">Charging animation</string>
<string name="battery_bar_animate_summary">The charging animation may result in a poor user experience. Enable at your own discretion.</string>

4. Now open array.xml and add these lines above </resources>.

<string-array name="battery_bar_entries">
<item>Hide</item>
<item>Statusbar</item>
<item>Top of navbar</item>
<item>Bottom of navbar</item>
</string-array>
<string-array name="battery_bar_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="battery_bar_style_entries">
<item>Regular</item>
<item>Center-mirrored</item>
</string-array>
<string-array name="battery_bar_style_values">
<item>0</item>
<item>1</item>
</string-array>
<string-array name="battery_bar_thickness_entries">
<item>1 dp</item>
<item>2 dp</item>
<item>3 dp</item>
<item>4 dp</item>
</string-array>
<string-array name="battery_bar_thickness_values">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

5. Now Recompile your Settings.apk , Sign it and again Decompile it.

6. Now open BatteryBarStyle.smali and replace the ids with the ids present in public.xml of your Settings.apk

0x7f06005e

<public type="xml" name="battery_bar_prefs"

0x7f020103

<public type="drawable" name="ic_settings_batterybar"

SystemUI.apk Modding

1. First Decompile your SystemUI.apk and merge the files inside it (given below).

2. Now go to SystemUI.apk\res\layout\gemini_status_bar.xml and open it. Now Find these lines ,

</com.android.systemui.statusbar.phone.TickerView>
</LinearLayout>
</com.android.systemui.statusbar.phone.PhoneStatusBarView>

Now add this line between the above lines like this ,

<com.android.systemui.statusbar.policy.BatteryBarController android:layout_width="fill_parent" android:layout_height="1.0dip" systemui:viewLocation="1" />

The final will look like this ,

</com.android.systemui.statusbar.phone.TickerView>
</LinearLayout>
<com.android.systemui.statusbar.policy.BatteryBarController android:layout_width="fill_parent" android:layout_height="1.0dip" systemui:viewLocation="1" />
</com.android.systemui.statusbar.phone.PhoneStatusBarView>

3. Now go to SystemUI.apk\res\layout\navigation_bar.xml and open it. Find this line ,

<FrameLayout android:id="@id/rot0" android:layout_width="fill_parent" android:layout_height="fill_parent">

Now add these lines below the above line ,

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.BatteryBarController android:visibility="gone" android:layout_width="fill_parent" android:layout_height="1.0dip" android:layout_alignParentTop="true" systemui:viewLocation="2" />
<com.android.systemui.statusbar.policy.BatteryBarController android:visibility="gone" android:layout_width="fill_parent" android:layout_height="1.0dip" android:layout_alignParentBottom="true" systemui:viewLocation="3" />
</RelativeLayout>

The final will look like this ,

<FrameLayout android:id="@id/rot0" android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.BatteryBarController android:visibility="gone" android:layout_width="fill_parent" android:layout_height="1.0dip" android:layout_alignParentTop="true" systemui:viewLocation="2" />
<com.android.systemui.statusbar.policy.BatteryBarController android:visibility="gone" android:layout_width="fill_parent" android:layout_height="1.0dip" android:layout_alignParentBottom="true" systemui:viewLocation="3" />
</RelativeLayout>

Now again find this line ,

<FrameLayout android:id="@id/rot90" android:paddingTop="0.0dip" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent">

Now add these lines below the above line ,

<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.BatteryBarController android:orientation="vertical" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:rotation="180.0" systemui:viewLocation="2" />
<com.android.systemui.statusbar.policy.BatteryBarController android:orientation="vertical" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:rotation="180.0" systemui:viewLocation="3" />
</RelativeLayout>

The final will look like this ,

<FrameLayout android:id="@id/rot90" android:paddingTop="0.0dip" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.BatteryBarController android:orientation="vertical" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:rotation="180.0" systemui:viewLocation="2" />
<com.android.systemui.statusbar.policy.BatteryBarController android:orientation="vertical" android:visibility="gone" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentRight="true" android:rotation="180.0" systemui:viewLocation="3" />
</RelativeLayout>

Do this same with all navigation_bar.xml present in other layout folders.

4. Now go to SystemUI.apk\res\values\attrs.xml and open it. Now add this above </resources>.

<attr name="viewLocation" format="integer" />

5. Now go to smali\com\android\systemui\statusbar\policy\Prefs.smali and open that. Then find this method ,

.method public static edit(Landroid/content/Context;)Landroid/content/SharedPreferences$Editor;

Now add this method below the above method ,

.method public static getLastBatteryLevel(Landroid/content/Context;)I
.locals 3
.param p0, "context" # Landroid/content/Context;

.prologue
.line 48
invoke-static {p0}, Lcom/android/systemui/statusbar/policy/Prefs;->read(Landroid/content/Context;)Landroid/content/SharedPreferences;

move-result-object v0

const-string v1, "last_battery_level"

const/16 v2, 0x32

invoke-interface {v0, v1, v2}, Landroid/content/SharedPreferences;->getInt(Ljava/lang/String;I)I

move-result v0

return v0
.end method

Now again find this method ,

.method public static read(Landroid/content/Context;)Landroid/content/SharedPreferences;

Now add this method below the above method ,

.method public static setLastBatteryLevel(Landroid/content/Context;I)V
.locals 2
.param p0, "context" # Landroid/content/Context;
.param p1, "level" # I

.prologue
.line 44
invoke-static {p0}, Lcom/android/systemui/statusbar/policy/Prefs;->edit(Landroid/content/Context;)Landroid/content/SharedPreferences$Editor;

move-result-object v0

const-string v1, "last_battery_level"

invoke-interface {v0, v1, p1}, Landroid/content/SharedPreferences$Editor;->putInt(Ljava/lang/String;I)Landroid/content/SharedPreferences$Editor;

move-result-object v0

invoke-interface {v0}, Landroid/content/SharedPreferences$Editor;->commit()Z

.line 45
return-void
.end method

6. Now go to smali\com\android\systemui\R$styleable.smali and open that. Then find this line ,

# static fields

Now add this line below the above line ,

.field public static final BatteryBarController:[I

Now again find these lines ,

.method static constructor <clinit>()V
.locals 4

.prologue
const/4 v3, 0x1

const/4 v2, 0x0

Now add these lines below this "const/4 v2, 0x0" line ,

new-array v0, v3, [I

const v1, 0x7f01000c

aput v1, v0, v2

sput-object v0, Lcom/android/systemui/R$styleable;->BatteryBarController:[I

The final will look like this ,

.method static constructor <clinit>()V
.locals 4

.prologue
const/4 v3, 0x1

const/4 v2, 0x0

new-array v0, v3, [I

const v1, 0x7f01000c

aput v1, v0, v2

sput-object v0, Lcom/android/systemui/R$styleable;->BatteryBarController:[I

7. Now Recompile your SystemUI.apk , sign it and again Decompile it.

8. Now open R$styleable.smali and replace the id with the id present in public.xml of your SystemUI.apk

0x7f01000c

<public type="attr" name="viewLocation"

Special Thanks To :

1. DU_Flo ROM (Extracted from this ROM)

2. MAAaD

3. XDA