Skip to content

Commit

Permalink
Improve xposed QS label color changer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Jan 28, 2024
1 parent b22d770 commit 617a797
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -97,17 +98,11 @@ public void onStopTrackingTouch(@NonNull Slider slider) {

// QS text always white
binding.labelWhite.setSwitchChecked(RPrefs.getBoolean(QS_TEXT_ALWAYS_WHITE, false));
binding.labelWhite.setSwitchChangeListener((buttonView, isChecked) -> {
RPrefs.putBoolean(QS_TEXT_ALWAYS_WHITE, isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
});
binding.labelWhite.setSwitchChangeListener(qsTextWhiteListener);

// QS text follow accent
binding.labelAccent.setSwitchChecked(RPrefs.getBoolean(QS_TEXT_FOLLOW_ACCENT, false));
binding.labelAccent.setSwitchChangeListener((buttonView, isChecked) -> {
RPrefs.putBoolean(QS_TEXT_FOLLOW_ACCENT, isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
});
binding.labelAccent.setSwitchChangeListener(qsTextAccentListener);

// Hide silent text
binding.hideSilentText.setSwitchChecked(RPrefs.getBoolean(HIDE_QS_SILENT_TEXT, false));
Expand All @@ -119,4 +114,33 @@ public void onStopTrackingTouch(@NonNull Slider slider) {

return view;
}

CompoundButton.OnCheckedChangeListener qsTextWhiteListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
RPrefs.putBoolean(QS_TEXT_FOLLOW_ACCENT, false);
binding.labelAccent.setSwitchChangeListener(null);
binding.labelAccent.setSwitchChecked(false);
binding.labelAccent.setSwitchChangeListener(qsTextAccentListener);
}

RPrefs.putBoolean(QS_TEXT_ALWAYS_WHITE, isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
}
};

CompoundButton.OnCheckedChangeListener qsTextAccentListener = (buttonView, isChecked) -> {
if (isChecked) {
RPrefs.putBoolean(QS_TEXT_ALWAYS_WHITE, false);
binding.labelWhite.setSwitchChangeListener(null);
binding.labelWhite.setSwitchChecked(false);
binding.labelWhite.setSwitchChangeListener(qsTextWhiteListener);
}

RPrefs.putBoolean(QS_TEXT_FOLLOW_ACCENT, isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
};


}
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
@SuppressLint("DiscouragedApi")
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!blackQSHeaderEnabled) return;
if (qsTextAlwaysWhite || qsTextFollowAccent) return;

try {
setObjectField(param.thisObject, "colorLabelActive", colorText);
setObjectField(param.thisObject, "colorSecondaryLabelActive", colorTextAlpha);
if (!qsTextAlwaysWhite && !qsTextFollowAccent) {
setObjectField(param.thisObject, "colorLabelActive", colorText);
setObjectField(param.thisObject, "colorSecondaryLabelActive", colorTextAlpha);
}
setObjectField(param.thisObject, "colorLabelInactive", Color.WHITE);
setObjectField(param.thisObject, "colorSecondaryLabelInactive", 0x80FFFFFF);

Expand All @@ -368,8 +369,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
hookAllMethods(QSIconViewImplClass, "getIconColorForState", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (qsTextAlwaysWhite || qsTextFollowAccent) return;

boolean isActiveState = false;
boolean isDisabledState;

Expand Down Expand Up @@ -397,9 +396,9 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (blackQSHeaderEnabled) {
if (isDisabledState) {
param.setResult(0x80FFFFFF);
} else if (isActiveState) {
} else if (isActiveState && !qsTextAlwaysWhite && !qsTextFollowAccent) {
param.setResult(colorText);
} else {
} else if (!isActiveState) {
param.setResult(Color.WHITE);
}
}
Expand Down Expand Up @@ -440,9 +439,9 @@ protected void afterHookedMethod(MethodHookParam param) {
ImageView mIcon = (ImageView) param.args[0];
if (isDisabledState) {
mIcon.setImageTintList(ColorStateList.valueOf(0x80FFFFFF));
} else if (isActiveState) {
} else if (isActiveState && !qsTextAlwaysWhite && !qsTextFollowAccent) {
mIcon.setImageTintList(ColorStateList.valueOf(colorText));
} else {
} else if (!isActiveState) {
mIcon.setImageTintList(ColorStateList.valueOf(Color.WHITE));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!lightQSHeaderEnabled || isDark) return;
if (qsTextAlwaysWhite || qsTextFollowAccent) return;

try {
setObjectField(param.thisObject, "colorLabelActive", Color.WHITE);
setObjectField(param.thisObject, "colorSecondaryLabelActive", 0x80FFFFFF);
if (!qsTextAlwaysWhite && !qsTextFollowAccent) {
setObjectField(param.thisObject, "colorLabelActive", Color.WHITE);
setObjectField(param.thisObject, "colorSecondaryLabelActive", 0x80FFFFFF);
}
setObjectField(param.thisObject, "colorLabelInactive", Color.BLACK);
setObjectField(param.thisObject, "colorSecondaryLabelInactive", 0x80000000);
} catch (Throwable throwable) {
Expand All @@ -356,8 +357,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
hookAllMethods(QSIconViewImplClass, "getIconColorForState", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (qsTextAlwaysWhite || qsTextFollowAccent) return;

boolean isActiveState = false;
boolean isDisabledState;

Expand Down Expand Up @@ -386,7 +385,11 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (isDisabledState) {
param.setResult(0x80000000);
} else {
param.setResult(isActiveState ? Color.WHITE : Color.BLACK);
if (isActiveState && !qsTextAlwaysWhite && !qsTextFollowAccent) {
param.setResult(Color.WHITE);
} else if (!isActiveState) {
param.setResult(Color.BLACK);
}
}
}
}
Expand All @@ -396,8 +399,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
hookAllMethods(QSIconViewImplClass, "updateIcon", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if (qsTextAlwaysWhite || qsTextFollowAccent) return;

boolean isActiveState = false;
boolean isDisabledState;

Expand Down Expand Up @@ -427,7 +428,11 @@ protected void afterHookedMethod(MethodHookParam param) {
if (isDisabledState) {
param.setResult(0x80000000);
} else {
mIcon.setImageTintList(ColorStateList.valueOf(isActiveState ? Color.WHITE : Color.BLACK));
if (isActiveState && !qsTextAlwaysWhite && !qsTextFollowAccent) {
mIcon.setImageTintList(ColorStateList.valueOf(Color.WHITE));
} else if (!isActiveState) {
mIcon.setImageTintList(ColorStateList.valueOf(Color.BLACK));
}
}
}
}
Expand Down

0 comments on commit 617a797

Please sign in to comment.