|
15 | 15 |
|
16 | 16 | package com.ceco.gm2.gravitybox;
|
17 | 17 |
|
| 18 | +import java.util.ArrayList; |
| 19 | + |
18 | 20 | import android.content.BroadcastReceiver;
|
19 | 21 | import android.content.Intent;
|
20 | 22 | import android.content.Context;
|
|
33 | 35 | import de.robv.android.xposed.XposedHelpers;
|
34 | 36 | import de.robv.android.xposed.callbacks.XC_InitPackageResources.InitPackageResourcesParam;
|
35 | 37 | import de.robv.android.xposed.callbacks.XC_LayoutInflated;
|
| 38 | +import de.robv.android.xposed.callbacks.XCallback; |
36 | 39 |
|
37 | 40 | public class ModBatteryStyle {
|
38 | 41 | private static final String TAG = "GB:ModBatteryStyle";
|
39 | 42 | public static final String PACKAGE_NAME = "com.android.systemui";
|
| 43 | + public static final String CLASS_PHONE_STATUSBAR = "com.android.systemui.statusbar.phone.PhoneStatusBar"; |
40 | 44 | public static final String CLASS_BATTERY_CONTROLLER =
|
41 | 45 | "com.android.systemui.statusbar.policy.BatteryController";
|
42 | 46 | private static final boolean DEBUG = false;
|
@@ -152,8 +156,35 @@ public static void init(final XSharedPreferences prefs, ClassLoader classLoader)
|
152 | 156 | if (DEBUG) log("init");
|
153 | 157 |
|
154 | 158 | try {
|
| 159 | + Class<?> phoneStatusBarClass = XposedHelpers.findClass(CLASS_PHONE_STATUSBAR, classLoader); |
155 | 160 | Class<?> batteryControllerClass = XposedHelpers.findClass(CLASS_BATTERY_CONTROLLER, classLoader);
|
156 | 161 |
|
| 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 | + |
157 | 188 | XposedBridge.hookAllConstructors(batteryControllerClass, new XC_MethodHook() {
|
158 | 189 |
|
159 | 190 | @Override
|
@@ -184,6 +215,14 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
|
184 | 215 | if (DEBUG) log("BatteryController constructed");
|
185 | 216 | }
|
186 | 217 | });
|
| 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 | + }); |
187 | 226 | }
|
188 | 227 | catch (Throwable t) {
|
189 | 228 | XposedBridge.log(t);
|
|
0 commit comments