Skip to content

Commit

Permalink
re-add a brightness pct for hyperos 1.0-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Dec 14, 2024
1 parent 6c64c45 commit 182cb3f
Show file tree
Hide file tree
Showing 13 changed files with 232 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeather;
Expand Down Expand Up @@ -101,8 +102,6 @@
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.HideNavigationBar;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.NavigationCustom;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.RotationButton;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.FocusNotifLyricPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelperKt;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.BlurEnable;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.DoubleTapToSleep;
Expand Down Expand Up @@ -349,6 +348,7 @@ public void handleLoadPackage() {
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(new VolumeTimerValuesHook(), mPrefsMap.getBoolean("system_ui_volume_timer"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewFlashLight;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
Expand Down Expand Up @@ -97,8 +98,6 @@
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.HideNavigationBar;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.NavigationCustom;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.RotationButton;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.FocusNotifLyricPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelperKt;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.BlurEnable;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.DoubleTapToSleep;
Expand Down Expand Up @@ -269,6 +268,7 @@ public void handleLoadPackage() {
initHook(DisableInfinitymodeGesture.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_infinitymode_gesture"));
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationWeather;
Expand Down Expand Up @@ -101,8 +102,6 @@
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.HideNavigationBar;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.NavigationCustom;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.RotationButton;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.FocusNotifLyricPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelperKt;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.BlurEnable;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.DoubleTapToSleep;
Expand Down Expand Up @@ -349,6 +348,7 @@ public void handleLoadPackage() {
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(new VolumeTimerValuesHook(), mPrefsMap.getBoolean("system_ui_volume_timer"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaControlPanelTimeViewTextSize;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MediaSeekBarColor;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.MuteVisibleNotifications;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewBrightnessPct;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NewFlashLight;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationImportanceHyperOSFix;
import com.sevtinge.hyperceiler.module.hook.systemui.controlcenter.NotificationRowMenu;
Expand Down Expand Up @@ -97,8 +98,6 @@
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.HideNavigationBar;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.NavigationCustom;
import com.sevtinge.hyperceiler.module.hook.systemui.navigation.RotationButton;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.FocusNotifLyricPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelper;
import com.sevtinge.hyperceiler.module.hook.systemui.plugin.NewPluginHelperKt;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.BlurEnable;
import com.sevtinge.hyperceiler.module.hook.systemui.statusbar.DoubleTapToSleep;
Expand Down Expand Up @@ -285,6 +284,7 @@ public void handleLoadPackage() {
initHook(DisableInfinitymodeGesture.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_infinitymode_gesture"));
initHook(DisableBottomBar.INSTANCE, mPrefsMap.getBoolean("system_ui_disable_bottombar"));
initHook(UnlockClipboard.INSTANCE, mPrefsMap.getBoolean("system_ui_unlock_clipboard"));
initHook(NewBrightnessPct.INSTANCE, mPrefsMap.getBoolean("system_showpct_title"));

// 锁屏
initHook(new ScramblePIN(), mPrefsMap.getBoolean("system_ui_lock_screen_scramble_pin"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.sevtinge.hyperceiler.utils.devicesdk.DeviceSDKKt.isDarkMode;
import static com.sevtinge.hyperceiler.utils.log.XposedLogUtils.logE;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -53,19 +54,10 @@ public class OtherTool {
// 获取 Android 系统
public static final int FlAG_ONLY_ANDROID = ContextUtils.FlAG_ONLY_ANDROID;

// public static TextView mPct = null;
public static WeakReference<TextView> mPct;
public static TextView mPct = null;

// public Context mModuleContext = null;

public static void setTextView(TextView textView) {
mPct = new WeakReference<>(textView);
}

public static TextView getTextView() {
return mPct != null ? mPct.get() : null;
}

public static Resources getModuleRes(Context context)
throws PackageManager.NameNotFoundException {
return ResourcesTool.loadModuleRes(context);
Expand Down Expand Up @@ -155,25 +147,25 @@ public static int getPackageVersionCode(XC_LoadPackage.LoadPackageParam lpparam)
}
}

public static void initPct(ViewGroup container, int source, Context context) {
Resources res = context.getResources();
if (getTextView() == null) {
setTextView(new TextView(container.getContext()));
getTextView().setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
getTextView().setGravity(Gravity.CENTER);
public static void initPct(ViewGroup container, int source) {
Resources res = container.getContext().getResources();
if (mPct == null) {
mPct = new TextView(container.getContext());
mPct.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
mPct.setGravity(Gravity.CENTER);
float density = res.getDisplayMetrics().density;
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
lp.topMargin = Math.round(mPrefsMap.getInt("system_ui_others_showpct_top", 54) * density);
// lp.topMargin = Math.round(54 * density);
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
getTextView().setPadding(Math.round(20 * density), Math.round(10 * density), Math.round(18 * density), Math.round(12 * density));
getTextView().setLayoutParams(lp);
mPct.setPadding(Math.round(20 * density), Math.round(10 * density), Math.round(18 * density), Math.round(12 * density));
mPct.setLayoutParams(lp);
try {
Resources modRes = getModuleRes(context);
getTextView().setTextColor(ColorStateList.valueOf(Color.parseColor("#FFFFFFFF")));
getTextView().setBackground(modRes.getDrawable(R.drawable.input_background, context.getTheme()));
Resources modRes = getModuleRes(container.getContext());
mPct.setTextColor(ColorStateList.valueOf(Color.parseColor("#FFFFFFFF")));
mPct.setBackground(modRes.getDrawable(R.drawable.input_background, container.getContext().getTheme()));
} catch (Throwable err) {
logE("ShowVolumePct", err);
logE("ShowPct", err);
}
if (mPrefsMap.getBoolean("system_showpct_use_blur")) {
try {
Expand All @@ -183,18 +175,18 @@ public static void initPct(ViewGroup container, int source, Context context) {
int a;
if (isDarkMode()) a = 120;
else a = 140;
MiBlurUtils.setContainerPassBlur(getTextView(), i, true);
MiBlurUtils.setMiViewBlurMode(getTextView(), 1);
MiBlurUtils.clearMiBackgroundBlendColor(getTextView());
MiBlurUtils.addMiBackgroundBlendColor(getTextView(), Color.argb(a, 0, 0, 0), 101);
MiBlurUtils.setContainerPassBlur(mPct, i, true);
MiBlurUtils.setMiViewBlurMode(mPct, 1);
MiBlurUtils.clearMiBackgroundBlendColor(mPct);
MiBlurUtils.addMiBackgroundBlendColor(mPct, Color.argb(a, 0, 0, 0), 101);
} catch (Throwable e) {
logE("ShowVolumePct", e);
logE("ShowPct", e);
}
}
container.addView(getTextView());
container.addView(mPct);
}
getTextView().setTag(source);
getTextView().setVisibility(View.GONE);
mPct.setTag(source);
mPct.setVisibility(View.GONE);
}

public static void removePct(TextView mPctText) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*/
package com.sevtinge.hyperceiler.module.hook.systemui;

import static com.sevtinge.hyperceiler.module.base.tool.OtherTool.getTextView;
import static com.sevtinge.hyperceiler.module.base.tool.OtherTool.initPct;
import static com.sevtinge.hyperceiler.module.base.tool.OtherTool.mPct;
import static com.sevtinge.hyperceiler.module.base.tool.OtherTool.removePct;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

Expand All @@ -34,8 +33,6 @@
import de.robv.android.xposed.XposedHelpers;

public class BrightnessPct extends BaseHook {
public boolean isHooked = false;

@Override
@SuppressLint("SetTextI18n")
public void init() throws NoSuchMethodException {
Expand All @@ -48,15 +45,15 @@ protected void after(MethodHookParam param) {
logE(TAG, lpparam.packageName, "mStatusBarWindow is null");
return;
}
initPct(mStatusBarWindow, 1, mStatusBarWindow.getContext());
getTextView().setVisibility(View.VISIBLE);
initPct(mStatusBarWindow, 1);
mPct.setVisibility(View.VISIBLE);
}
});

findAndHookMethod("com.android.systemui.statusbar.policy.BrightnessMirrorController", "hideMirror", new MethodHook() {
@Override
protected void after(MethodHookParam param) {
removePct(getTextView());
removePct(mPct);
}
}
);
Expand All @@ -65,21 +62,20 @@ protected void after(MethodHookParam param) {
hookAllMethods("com.android.systemui.controlcenter.policy.MiuiBrightnessController", "onStart", new MethodHook() {
@Override
protected void before(MethodHookParam param) {
Context mContext = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
Object windowView = getObject(param);
if (windowView == null) {
logE(TAG, lpparam.packageName, "mControlPanelContentView is null");
return;
}
initPct((ViewGroup) windowView, 2, mContext);
getTextView().setVisibility(View.VISIBLE);
initPct((ViewGroup) windowView, 2);
mPct.setVisibility(View.VISIBLE);
}
});

hookAllMethods("com.android.systemui.controlcenter.policy.MiuiBrightnessController", "onStop", new MethodHook() {
@Override
protected void after(MethodHookParam param) {
removePct(getTextView());
removePct(mPct);
}
});

Expand All @@ -88,14 +84,14 @@ protected void after(MethodHookParam param) {
@Override
protected void after(MethodHookParam param) {
int pctTag = 0;
if (getTextView() != null && getTextView().getTag() != null) {
pctTag = (int) getTextView().getTag();
if (mPct != null && mPct.getTag() != null) {
pctTag = (int) mPct.getTag();
}
if (pctTag == 0 || getTextView() == null) return;
if (pctTag == 0 || mPct == null) return;
int currentLevel = (int) param.args[3];
if (brightnessUtils != null) {
int maxLevel = (int) XposedHelpers.getStaticObjectField(brightnessUtils, "GAMMA_SPACE_MAX");
getTextView().setText(((currentLevel * 100) / maxLevel) + "%");
mPct.setText(((currentLevel * 100) / maxLevel) + "%");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter

import android.annotation.*
import android.view.*
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClass
import com.github.kyuubiran.ezxhelper.ClassUtils.loadClassOrNull
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createBeforeHook
import com.github.kyuubiran.ezxhelper.finders.MethodFinder.`-Static`.methodFinder
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.tool.*
import com.sevtinge.hyperceiler.utils.*
import de.robv.android.xposed.*

object NewBrightnessPct : BaseHook() {
private val MiuiBrightnessController by lazy {
loadClass("com.android.systemui.controlcenter.policy.MiuiBrightnessController")
}
private val brightnessUtils by lazy {
loadClassOrNull("com.android.systemui.controlcenter.policy.BrightnessUtils")
}

fun initLoaderHook(classLoader: ClassLoader) {
loadClass("miui.systemui.controlcenter.panel.main.brightness.BrightnessSliderController\$seekBarListener\$1", classLoader)
.methodFinder().filterByName("onStartTrackingTouch")
.first().createBeforeHook {
startPct(it)
}

loadClass("miui.systemui.controlcenter.panel.main.brightness.BrightnessPanelSliderController\$seekBarListener\$1")
.methodFinder().filterByName("onStartTrackingTouch")
.first().createBeforeHook {
startPct(it)
}
}

private fun startPct(it: XC_MethodHook.MethodHookParam) {
val windowView = getView("miui.systemui.dagger.PluginComponentFactory", it.thisObject.javaClass.classLoader)
if (windowView == null) {
logE(TAG, lpparam.packageName, "ControlCenterWindowViewImpl is null")
return
}
OtherTool.initPct(windowView as ViewGroup, 2)
OtherTool.mPct.visibility = View.VISIBLE
}

@SuppressLint("SetTextI18n")
override fun init() {
hookAllMethods(
MiuiBrightnessController, "onStop",
object : MethodHook() {
override fun after(param: MethodHookParam) {
OtherTool.removePct(OtherTool.mPct)
}
})

hookAllMethods(
MiuiBrightnessController, "onChanged",
object : MethodHook() {
override fun after(param: MethodHookParam) {
var pctTag = 0
if (OtherTool.mPct != null && OtherTool.mPct.tag != null) {
pctTag = OtherTool.mPct.tag as Int
}
if (pctTag == 0 || OtherTool.mPct == null) return
val currentLevel = param.args[3] as Int
if (brightnessUtils != null) {
val maxLevel =
brightnessUtils!!.getStaticObjectField("GAMMA_SPACE_MAX") as Int
OtherTool.mPct.text =
((currentLevel * 100) / maxLevel).toString() + "%"
}
}
})
}

private fun getView(str: String, cl: ClassLoader?): Any? {
val cl2 = loadClass(str, cl)
val controlCenterWindowView = cl2.callStaticMethod("getInstance")!!
.callMethod("getPluginComponent")!!
.getObjectField("controlCenterWindowViewCreatorProvider")!!
.callMethod("get")!!
.getObjectField("windowView")
return controlCenterWindowView
}
}
Loading

0 comments on commit 182cb3f

Please sign in to comment.