Skip to content

Commit

Permalink
新增: 已启用磁贴颜色自定义支持大磁贴
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed May 7, 2024
1 parent 1548bfa commit 86013e5
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void handleLoadPackage() {

// 控制中心
// initHook(new SmartHome(), false);
initHook(new QSColor(), mPrefsMap.getBoolean("system_ui_control_center_qs_open_color"));
initHook(new QSColor(), mPrefsMap.getBoolean("system_ui_control_center_qs_open_color") || mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color"));
initHook(new UnimportantNotification(), mPrefsMap.getBoolean("system_ui_control_center_unimportant_notification"));
initHook(new BlurEnable(), mPrefsMap.getBoolean("system_ui_control_center_statusbar_blur"));
initHook(new ExpandNotification(), !mPrefsMap.getStringSet("system_ui_control_center_expand_notification").isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package com.sevtinge.hyperceiler.module.hook.systemui.controlcenter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.base.BaseXposedInit;
Expand All @@ -28,47 +31,132 @@
import de.robv.android.xposed.XposedHelpers;

public class QSColor extends BaseHook {
private static boolean small = false;
private static int bgColor = -1;
private static int color = -1;
private static boolean big = false;

private static int bigBgColor = -1;
private static int bigColor = -1;

@Override
public void init() throws NoSuchMethodException {
bgColor = mPrefsMap.getInt("system_ui_control_center_qs_bg_color", -1);
color = mPrefsMap.getInt("system_ui_control_center_qs_color", -1);
findAndHookConstructor("com.android.systemui.qs.tileimpl.MiuiQSIconViewImpl",
Context.class, new MethodHook() {
@Override
protected void after(MethodHookParam param) {
XposedHelpers.setObjectField(param.thisObject, "mIconColorEnabled", color);
mResHook.setObjectReplacement("com.android.systemui", "color", "qs_tile_icon_enabled_color", color);
load();
if (small) {
findAndHookConstructor("com.android.systemui.qs.tileimpl.MiuiQSIconViewImpl",
Context.class, new MethodHook() {
@Override
protected void after(MethodHookParam param) {
XposedHelpers.setObjectField(param.thisObject, "mIconColorEnabled", color);
mResHook.setObjectReplacement("com.android.systemui", "color", "qs_tile_icon_enabled_color", color);
}
}
}
);
);
}
}

public static void pluginHook(ClassLoader classLoader) {
public static int id = -1;

public static void load() {
small = mPrefsMap.getBoolean("system_ui_control_center_qs_open_color");
big = mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color");
bgColor = mPrefsMap.getInt("system_ui_control_center_qs_bg_color", -1);
color = mPrefsMap.getInt("system_ui_control_center_qs_color", -1);
XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView",
classLoader, "updateIcon",
"com.android.systemui.plugins.qs.QSTile$State", boolean.class, boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
XposedHelpers.setObjectField(param.thisObject, "iconColor", color);
BaseXposedInit.mResHook.setObjectReplacement("miui.systemui.plugin", "color", "qs_icon_enabled_color", color);
bigBgColor = mPrefsMap.getInt("system_ui_control_center_qs_big_bg_color", -1);
bigColor = mPrefsMap.getInt("system_ui_control_center_qs_big_color", -1);
}

public static void pluginHook(ClassLoader classLoader) {
String TAG = "QSColor";
load();
if (small) {
XposedHelpers.findAndHookConstructor("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader,
Context.class, Context.class, AttributeSet.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
BaseXposedInit.mResHook.setObjectReplacement("miui.systemui.plugin", "color", "qs_icon_enabled_color", color);
}
}
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView",
classLoader, "updateIcon",
"com.android.systemui.plugins.qs.QSTile$State", boolean.class, boolean.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
XposedHelpers.setObjectField(param.thisObject, "iconColor", color);
}
}
}
);
XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader,
"getActiveBackgroundDrawable", "com.android.systemui.plugins.qs.QSTile$State",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
GradientDrawable drawable = (GradientDrawable) param.getResult();
drawable.setColor(bgColor);
param.setResult(drawable);
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSTileItemIconView", classLoader,
"getActiveBackgroundDrawable", "com.android.systemui.plugins.qs.QSTile$State",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
GradientDrawable drawable = (GradientDrawable) param.getResult();
drawable.setColor(bgColor);
param.setResult(drawable);
}
}
);
}

if (big) {
XposedHelpers.findAndHookConstructor("miui.systemui.controlcenter.qs.tileview.QSCardItemIconView", classLoader,
Context.class, Context.class, AttributeSet.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
BaseXposedInit.mResHook.setObjectReplacement("miui.systemui.plugin", "color", "qs_icon_enabled_color", bigColor);
}
}
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSCardItemIconView", classLoader,
"setIcon", "com.android.systemui.plugins.qs.QSTile$State", boolean.class,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
XposedHelpers.setObjectField(param.thisObject, "iconColor", bigColor);
}
}
);

XposedHelpers.findAndHookConstructor("miui.systemui.controlcenter.qs.tileview.QSCardItemView", classLoader,
Context.class, AttributeSet.class,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
id = ((LinearLayout) param.thisObject).getContext().getResources().getIdentifier("qs_card_cell_background_enabled",
"drawable", "miui.systemui.plugin");
}
}
);

XposedHelpers.findAndHookMethod("miui.systemui.controlcenter.qs.tileview.QSCardItemView", classLoader,
"updateBackground",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
Object state = XposedHelpers.getObjectField(param.thisObject, "state");
String spec = (String) XposedHelpers.getObjectField(state, "spec");
int i = XposedHelpers.getIntField(state, "state");
LinearLayout linearLayout = (LinearLayout) param.thisObject;
if (i == 2) {
if (id == -1) {
logE(TAG, "id is -1!!");
return;
}
Drawable drawable = linearLayout.getContext().getTheme().getResources().getDrawable(id, linearLayout.getContext().getTheme());
drawable.setTint(bigBgColor);
linearLayout.setBackground(drawable);
}
}
}
}
);
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public void setClassLoader(ClassLoader classLoader) {
mPrefsMap.getBoolean("system_control_center_qs_tile_label")) && !isMoreHyperOSVersion(1f)) {
CCGrid.loadCCGrid(classLoader);
}
if (mPrefsMap.getBoolean("system_ui_control_center_qs_open_color"))
if (mPrefsMap.getBoolean("system_ui_control_center_qs_open_color") ||
mPrefsMap.getBoolean("system_ui_control_center_qs_big_open_color"))
QSColor.pluginHook(classLoader);
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@
<string name="system_ui_control_center_media_control_seekbar_thumb_color">滑块颜色</string>
<string name="system_ui_control_center_qs_bg_color">背景颜色</string>
<string name="system_ui_control_center_qs_color">图标颜色</string>
<string name="system_ui_control_center_qs_open_color">已启用磁贴颜色自定义</string>
<string name="system_ui_control_center_qs_open_color">已启用小磁贴颜色自定义</string>
<string name="system_ui_control_center_qs_big_open_color">已启用大磁贴颜色自定义</string>
<string name="system_ui_control_center_media_control_panel_background_mix">优化音乐面板背景混色效果</string>
<string name="system_ui_control_center_media_control_media_button_custom">自定义动作按钮大小</string>
<string name="system_ui_control_center_media_control_media_button">固有动作按钮大小</string>
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,8 @@
<string name="system_ui_control_auto_close">Magnetic tiles automatically retract</string>
<string name="system_ui_control_center_qs_bg_color">Background color</string>
<string name="system_ui_control_center_qs_color">Icon color</string>
<string name="system_ui_control_center_qs_open_color">Tile color customization is enabled</string>
<string name="system_ui_control_center_qs_open_color">Small tile color customization is enabled</string>
<string name="system_ui_control_center_qs_big_open_color">Large tile color customization is enabled</string>
<string name="system_ui_control_auto_close_more">After opening, clicking on the status bar tile will automatically retract the status bar</string>
<string name="system_control_center_qs_tile_label">Remove title</string>
<string name="system_control_center_qs_rows">Rows</string>
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/xml/system_ui_control_center.xml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,25 @@
android:title="@string/system_ui_control_center_qs_color"
app:showAlphaSlider="true" />

<SwitchPreference
android:defaultValue="false"
android:key="prefs_key_system_ui_control_center_qs_big_open_color"
android:title="@string/system_ui_control_center_qs_big_open_color" />

<moralnorm.preference.ColorPickerPreference
android:defaultValue="-1"
android:dependency="prefs_key_system_ui_control_center_qs_big_open_color"
android:key="prefs_key_system_ui_control_center_qs_big_bg_color"
android:title="@string/system_ui_control_center_qs_bg_color"
app:showAlphaSlider="true" />

<moralnorm.preference.ColorPickerPreference
android:defaultValue="-1"
android:dependency="prefs_key_system_ui_control_center_qs_big_open_color"
android:key="prefs_key_system_ui_control_center_qs_big_color"
android:title="@string/system_ui_control_center_qs_color"
app:showAlphaSlider="true" />

<SwitchPreference
android:defaultValue="false"
android:key="prefs_key_system_ui_control_auto_close"
Expand Down

0 comments on commit 86013e5

Please sign in to comment.