From 1f9754995e7ae0c3bcb8c4bc035f5d0944924189 Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Fri, 26 Apr 2024 14:51:47 +0200 Subject: [PATCH] CHANGELOG: Battery Style improvement --- .github/workflows/makeBetaRelease.yml | 14 ++- .../statusbar/BatteryStyleManager.java | 109 +++++++++++++++++- 2 files changed, 118 insertions(+), 5 deletions(-) diff --git a/.github/workflows/makeBetaRelease.yml b/.github/workflows/makeBetaRelease.yml index 74cb9c814..47d7c6104 100644 --- a/.github/workflows/makeBetaRelease.yml +++ b/.github/workflows/makeBetaRelease.yml @@ -87,6 +87,18 @@ jobs: message: ${{ env.TMessage }} format: markdown + - name: Telegram Channel Post + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.OC_CHANNEL2 }} + token: ${{ secrets.TELEGRAM_TOKEN }} + message: ${{ env.TMessage }} + format: markdown + + - name: Telegram File Attachment + run: | + curl -v "https://api.telegram.org/bot${{ secrets.TELEGRAM_TK }}/sendMediaGroup?chat_id=${{ secrets.OC_CHANNEL }}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FXposed%22%7D%5D" -F Xposed="@app/build/outputs/apk/release/OxygenCustomizer.apk" + - name: Telegram File Attachment run: | - curl -v "https://api.telegram.org/bot${{ secrets.TELEGRAM_TK }}/sendMediaGroup?chat_id=${{ secrets.OC_CHANNEL }}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FXposed%22%7D%5D" -F Xposed="@app/build/outputs/apk/release/OxygenCustomizer.apk" \ No newline at end of file + curl -v "https://api.telegram.org/bot${{ secrets.TELEGRAM_TK }}/sendMediaGroup?chat_id=${{ secrets.OC_CHANNEL2 }}&media=%5B%7B%22type%22%3A%22document%22%2C%20%22media%22%3A%22attach%3A%2F%2FXposed%22%7D%5D" -F Xposed="@app/build/outputs/apk/release/OxygenCustomizer.apk" diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java index 63c5393a9..5aaf06e0c 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java @@ -5,7 +5,9 @@ import static de.robv.android.xposed.XposedBridge.log; import static de.robv.android.xposed.XposedHelpers.callMethod; import static de.robv.android.xposed.XposedHelpers.findAndHookConstructor; +import static de.robv.android.xposed.XposedHelpers.findAndHookMethod; import static de.robv.android.xposed.XposedHelpers.findClass; +import static de.robv.android.xposed.XposedHelpers.getObjectField; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BATTERY_STYLE_CIRCLE; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BATTERY_STYLE_CUSTOM_LANDSCAPE; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BATTERY_STYLE_CUSTOM_RLANDSCAPE; @@ -85,6 +87,7 @@ import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.TypedValue; import android.view.Gravity; import android.view.View; @@ -291,7 +294,15 @@ public void updatePrefs(String... Key) { public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable { if (!listensTo(lpparam.packageName)) return; - //Class StatBatteryMeterView = findClass("com.oplus.systemui.statusbar.pipeline.battery.ui.view.StatBatteryMeterView", lpparam.classLoader); + if (Build.VERSION.SDK_INT >= 34) { + hookBattery(lpparam); // OOS 14 + } else { + hookBattery13(lpparam); // OOS 13 + } + + } + + private void hookBattery(XC_LoadPackage.LoadPackageParam lpparam) { Class BatteryIconColor = findClass("com.oplus.systemui.statusbar.pipeline.battery.ui.model.BatteryIconColor", lpparam.classLoader); findAndHookConstructor(BatteryIconColor, @@ -434,10 +445,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { progress.setProgress(0); progress.setVisibility(View.GONE); } else { - batteryPercentInView.setVisibility(View.VISIBLE); if (customizePercSize) { - batteryPercentOutView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mBatteryPercSize); - } + if (batteryPercentOutView != null && batteryPercentOutView.getVisibility() == View.VISIBLE) + batteryPercentOutView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mBatteryPercSize); } } @@ -463,6 +473,97 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { }); } + private void hookBattery13(XC_LoadPackage.LoadPackageParam lpparam) { + + Class TwoBatteryMeterDrawable = findClass("com.oplusos.systemui.statusbar.widget.TwoBatteryMeterDrawable", lpparam.classLoader); + findAndHookMethod(TwoBatteryMeterDrawable, "setColors", + int.class, + int.class, + int.class, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + /* + this.mOutlineColor = i3; + setColors(i, i2); + public void setColors(int i, int i2) { + int argb = Color.argb((int) (Color.alpha(i) * 0.85f), Color.red(i), Color.green(i), Color.blue(i)); + int argb2 = Color.argb((int) (Color.alpha(i2) * 0.85f), Color.red(i2), Color.green(i2), Color.blue(i2)); + this.mCircleBackPaint.setColor(argb2); + this.mCircleFrontPaint.setColor(argb); + this.mCircleChargingPaint.setColor(argb); + super.setColors(argb, argb2); + } + public void setColors(int i, int i2) { + this.mIconTint = i; + this.mFramePaint.setColor(i2); + this.mBoltPaint.setColor(i); + this.mChargeColor = i; + invalidateSelf(); + } + + */ + backgroundColor = (int) param.args[0]; + frameColor = (int) param.args[1]; + singleToneColor = (int) param.args[1]; + + } + }); + + + Class StatBatteryMeterView = findClass("com.oplusos.systemui.statusbar.widget.StatBatteryMeterView", lpparam.classLoader); + findAndHookMethod(StatBatteryMeterView, "initViews", Context.class, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + mBatteryIcon = (ImageView) getObjectField(param.thisObject, "mBatteryIconView"); + batteryPercentOutView = (TextView) getObjectField(param.thisObject, "batteryPercentText"); + + if (CustomBatteryEnabled && mBatteryIcon != null) { + if (mHidePercentage) + batteryPercentOutView.setVisibility(View.GONE); + else { + batteryPercentOutView.setVisibility(View.VISIBLE); + } + BatteryDrawable mBatteryDrawable = getNewBatteryDrawable(mContext); + if (mBatteryDrawable == null) return; + if (mBatteryDrawable != null) { + mBatteryDrawable.setBatteryLevel(getCurrentLevel()); + mBatteryDrawable.setChargingEnabled(mIsCharging, isFastCharging()); + mBatteryDrawable.setPowerSavingEnabled(isPowerSaving()); + mBatteryDrawable.setShowPercentEnabled(mShowPercentInside); + mBatteryDrawable.setAlpha(Math.round(BatteryIconOpacity * 2.55f)); + mBatteryDrawable.setColors(frameColor, backgroundColor, singleToneColor); + mBatteryDrawable.customizeBatteryDrawable( + mBatteryLayoutReverse, + mScaledPerimeterAlpha, + mScaledFillAlpha, + mCustomBlendColor, + mRainbowFillColor, + mCustomFillColor, + mCustomFillGradColor, + mCustomBlendColor ? mCustomChargingColor : getChargingColor(mCustomChargingColor), + mCustomBlendColor ? mCustomFastChargingColor : getChargingColor(mCustomFastChargingColor), + mCustomPowerSaveColor, + mCustomPowerSaveFillColor, + mChargingIconSwitch + ); + mBatteryIcon.setImageDrawable(mBatteryDrawable); + + } + + scaleBatteryMeterViews(mBatteryIcon); + updateBatteryRotation(mBatteryIcon); + updateFlipper(mBatteryIcon.getParent()); + } else { + if (customizePercSize) { + if (batteryPercentOutView != null && batteryPercentOutView.getVisibility() == View.VISIBLE) + batteryPercentOutView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mBatteryPercSize); + } + } + + } + }); + } + private BatteryDrawable getNewBatteryDrawable(Context context) { BatteryDrawable mBatteryDrawable = switch (BatteryStyle) { case BATTERY_STYLE_CUSTOM_RLANDSCAPE -> new RLandscapeBattery(context, frameColor, true);