From a524d78d134cca23a4acf7e338778309fab17665 Mon Sep 17 00:00:00 2001 From: SmartJQ <35246436+SmartJQ@users.noreply.github.com> Date: Sat, 14 Dec 2024 02:26:55 +0000 Subject: [PATCH] feat: fix bastardized custom action buttons in media control panel --- .../systemui/controlcenter/MediaButton.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/MediaButton.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/MediaButton.java index 866059a8f9..1807466e4a 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/MediaButton.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/controlcenter/MediaButton.java @@ -18,6 +18,7 @@ */ package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter; +import android.widget.ImageButton; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; @@ -40,6 +41,35 @@ public class MediaButton extends BaseHook { @Override public void init() throws NoSuchMethodException { + + Class DrawableUtils = findClassIfExists("com.miui.utils.DrawableUtils", lpparam.classLoader); + hookAllMethods("com.android.systemui.media.controls.ui.controller.MediaControlPanel", + "bindButtonCommon", new MethodHook() { + @Override + protected void before(MethodHookParam param) throws Throwable { + Object mediaAction = param.args[0]; + String desc = (String) XposedHelpers.getObjectField(mediaAction, "contentDescription"); + if ((typeCustom != 140) && + !desc.contains("Play") && !desc.contains("Pause") && + !desc.contains("Previous track") && !desc.contains("Next track")) { + ImageButton button = (ImageButton) param.args[0]; + Drawable loadDrawable = (Drawable) XposedHelpers.getObjectField(mediaAction, "icon"); + Method method = DrawableUtils.getDeclaredMethod("drawable2Bitmap", Drawable.class); + Bitmap bitmap = (Bitmap) method.invoke(null, loadDrawable); + Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, typeCustom, typeCustom, true); + XposedHelpers.setObjectField(mediaAction, "icon", new BitmapDrawable(button.getContext().getResources(), scaledBitmap)); + } else if (type != 140) { + ImageButton button = (ImageButton) param.args[0]; + Drawable loadDrawable = (Drawable) XposedHelpers.getObjectField(mediaAction, "icon"); + Method method = DrawableUtils.getDeclaredMethod("drawable2Bitmap", Drawable.class); + Bitmap bitmap = (Bitmap) method.invoke(null, loadDrawable); + Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, type, type, true); + XposedHelpers.setObjectField(mediaAction, "icon", new BitmapDrawable(button.getContext().getResources(), scaledBitmap)); + } + } + }); + + /* HyperOS 1.0 findAndHookMethod("com.android.systemui.media.controls.pipeline.MediaDataManager", "createActionsFromState", String.class, MediaController.class, UserHandle.class, new MethodHook() { @@ -91,6 +121,7 @@ protected void after(MethodHookParam param) throws Throwable { } } } - ); + ); + */ } }