Skip to content

Commit e2535d4

Browse files
committed
Bring back battery percent text into label views list
Fixes battery percent text derp
1 parent 3e70edf commit e2535d4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/com/ceco/gm2/gravitybox/ModBatteryStyle.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package com.ceco.gm2.gravitybox;
1717

18+
import java.util.ArrayList;
19+
1820
import android.content.BroadcastReceiver;
1921
import android.content.Intent;
2022
import android.content.Context;
@@ -33,10 +35,12 @@
3335
import de.robv.android.xposed.XposedHelpers;
3436
import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
3537
import de.robv.android.xposed.callbacks.XC_LayoutInflated;
38+
import de.robv.android.xposed.callbacks.XCallback;
3639

3740
public class ModBatteryStyle {
3841
private static final String TAG = "GB:ModBatteryStyle";
3942
public static final String PACKAGE_NAME = "com.android.systemui";
43+
public static final String CLASS_PHONE_STATUSBAR = "com.android.systemui.statusbar.phone.PhoneStatusBar";
4044
public static final String CLASS_BATTERY_CONTROLLER =
4145
"com.android.systemui.statusbar.policy.BatteryController";
4246
private static final boolean DEBUG = false;
@@ -152,8 +156,35 @@ public static void init(final XSharedPreferences prefs, ClassLoader classLoader)
152156
if (DEBUG) log("init");
153157

154158
try {
159+
Class<?> phoneStatusBarClass = XposedHelpers.findClass(CLASS_PHONE_STATUSBAR, classLoader);
155160
Class<?> batteryControllerClass = XposedHelpers.findClass(CLASS_BATTERY_CONTROLLER, classLoader);
156161

162+
XposedHelpers.findAndHookMethod(phoneStatusBarClass, "makeStatusBarView",
163+
new XC_MethodHook(XCallback.PRIORITY_HIGHEST) {
164+
@Override
165+
protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
166+
final Object batteryController =
167+
XposedHelpers.getObjectField(param.thisObject, "mBatteryController");
168+
if (mPercentText != null && batteryController != null) {
169+
// add percent text only in case there is no label with "percentage" tag present
170+
@SuppressWarnings("unchecked")
171+
ArrayList<TextView> mLabelViews =
172+
(ArrayList<TextView>) XposedHelpers.getObjectField(batteryController, "mLabelViews");
173+
boolean percentTextExists = false;
174+
for (TextView tv : mLabelViews) {
175+
if ("percentage".equals(tv.getTag())) {
176+
percentTextExists = true;
177+
break;
178+
}
179+
}
180+
if (!percentTextExists) {
181+
XposedHelpers.callMethod(batteryController, "addLabelView", mPercentText);
182+
if (DEBUG) log("BatteryController.addLabelView(percText)");
183+
}
184+
}
185+
}
186+
});
187+
157188
XposedBridge.hookAllConstructors(batteryControllerClass, new XC_MethodHook() {
158189

159190
@Override
@@ -184,6 +215,14 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
184215
if (DEBUG) log("BatteryController constructed");
185216
}
186217
});
218+
219+
XposedHelpers.findAndHookMethod(batteryControllerClass, "onReceive",
220+
Context.class, Intent.class, new XC_MethodHook() {
221+
@Override
222+
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
223+
updateBatteryStyle();
224+
}
225+
});
187226
}
188227
catch (Throwable t) {
189228
XposedBridge.log(t);

0 commit comments

Comments
 (0)