Skip to content

Commit

Permalink
Fluid Theme: Fix white-ish brightness bar color
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 6, 2023
1 parent ad25d4b commit 8f4e4a3
Showing 1 changed file with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static com.drdisagree.iconify.config.XPrefs.Xprefs;
import static com.drdisagree.iconify.xposed.HookRes.modRes;
import static com.drdisagree.iconify.xposed.HookRes.resparams;
import static com.drdisagree.iconify.xposed.utils.SettingsLibUtils.getColorAttr;
import static com.drdisagree.iconify.xposed.utils.ViewHelper.setAlphaForBackgroundDrawables;
import static de.robv.android.xposed.XposedBridge.hookAllConstructors;
import static de.robv.android.xposed.XposedBridge.hookAllMethods;
Expand All @@ -21,6 +20,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XResources;
import android.graphics.Color;
import android.graphics.PorterDuff;
Expand All @@ -41,6 +41,7 @@
import android.widget.ImageView;
import android.widget.SeekBar;

import androidx.annotation.ColorInt;
import androidx.core.content.res.ResourcesCompat;

import com.drdisagree.iconify.R;
Expand Down Expand Up @@ -134,6 +135,13 @@ protected void afterHookedMethod(MethodHookParam param) {
});

// QS tile color
hookAllConstructors(QSTileViewImplClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
colorInactiveAlpha[0] = changeAlpha((Integer) getObjectField(param.thisObject, "colorInactive"), INACTIVE_ALPHA);
}
});

hookAllMethods(QSTileViewImplClass, "getBackgroundColorForState", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
Expand Down Expand Up @@ -224,10 +232,17 @@ protected void afterHookedMethod(MethodHookParam param) {

setAlphaForBackgroundDrawables(view, INACTIVE_ALPHA);

ViewGroup pm_button_container = view.findViewById(res.getIdentifier("pm_lite", "id", mContext.getPackageName()));
pm_button_container.getBackground().setAlpha((int) (ACTIVE_ALPHA * 255));
pm_button_container.getBackground().setTint(colorAccent[0]);
((ImageView) pm_button_container.getChildAt(0)).setColorFilter(colorAccent[0], PorterDuff.Mode.SRC_IN);
try {
ViewGroup pm_button_container = view.findViewById(res.getIdentifier("pm_lite", "id", mContext.getPackageName()));
pm_button_container.getBackground().setAlpha((int) (ACTIVE_ALPHA * 255));
pm_button_container.getBackground().setTint(colorAccent[0]);
((ImageView) pm_button_container.getChildAt(0)).setColorFilter(colorAccent[0], PorterDuff.Mode.SRC_IN);
} catch (Throwable ignored) {
ImageView pm_button = view.findViewById(res.getIdentifier("pm_lite", "id", mContext.getPackageName()));
pm_button.getBackground().setAlpha((int) (ACTIVE_ALPHA * 255));
pm_button.getBackground().setTint(colorAccent[0]);
pm_button.setImageTintList(ColorStateList.valueOf(colorAccent[0]));
}
} catch (Throwable throwable) {
log(TAG + throwable);
}
Expand Down Expand Up @@ -288,8 +303,7 @@ protected void afterHookedMethod(MethodHookParam param) {
try {
((ImageView) getObjectField(param.thisObject, "mIconView")).setImageTintList(ColorStateList.valueOf(colorAccent[0]));
((ImageView) getObjectField(param.thisObject, "mIconView")).setBackgroundTintList(ColorStateList.valueOf(colorActiveAlpha[0]));
} catch (Throwable throwable1) {
log(TAG + throwable1);
} catch (Throwable ignored) {
}
}
}
Expand Down Expand Up @@ -466,7 +480,7 @@ private void initColors() {
if (QSTileViewImplParam != null) {
colorInactiveAlpha[0] = changeAlpha((Integer) getObjectField(QSTileViewImplParam.thisObject, "colorInactive"), INACTIVE_ALPHA);
} else {
colorInactiveAlpha[0] = colorInactiveAlpha[0] == null ? (wasDark ? Color.parseColor("#0FFFFFFF") : Color.parseColor("#59FFFFFF")) : colorInactiveAlpha[0];
colorInactiveAlpha[0] = colorInactiveAlpha[0] == null ? (wasDark ? Color.parseColor("#03D3D3DF") : Color.parseColor("#593D3D3D")) : colorInactiveAlpha[0];
}
}

Expand Down Expand Up @@ -587,12 +601,8 @@ private LayerDrawable createBrightnessBackgroundDrawable(Context context) {
ShapeDrawable backgroundShape = new ShapeDrawable(new RoundRectShape(radiusF, null, null));
backgroundShape.setIntrinsicHeight(height);

@SuppressLint("DiscouragedApi") ColorStateList states = getColorAttr(res.getIdentifier("attr/offStateColor", "attr", context.getPackageName()), context);
if (states != null) {
backgroundShape.getPaint().setColor(changeAlpha(states.getDefaultColor(), INACTIVE_ALPHA));
} else {
backgroundShape.getPaint().setColor(colorInactiveAlpha[0]);
}
@SuppressLint("DiscouragedApi") int colorInactive = getColorAttrDefaultColor(context, res.getIdentifier("offStateColor", "attr", context.getPackageName()), colorInactiveAlpha[0]);
backgroundShape.getPaint().setColor(changeAlpha(colorInactive, INACTIVE_ALPHA));

// Create the progress drawable
RoundedCornerProgressDrawable progressDrawable = null;
Expand All @@ -601,6 +611,7 @@ private LayerDrawable createBrightnessBackgroundDrawable(Context context) {
progressDrawable.setAlpha((int) (ACTIVE_ALPHA * 255));
progressDrawable.setTint(colorAccent[0]);
} catch (Throwable ignored) {
// it shoudln't happen anyway
}

// Create the start and end drawables
Expand All @@ -623,4 +634,11 @@ private LayerDrawable createBrightnessBackgroundDrawable(Context context) {

return layerDrawable;
}

private static int getColorAttrDefaultColor(Context context, int attr, @ColorInt int defValue) {
TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
@ColorInt int color = ta.getColor(0, defValue);
ta.recycle();
return color;
}
}

0 comments on commit 8f4e4a3

Please sign in to comment.