From 1ac8758ce7ce13b2f0990a285514aed7a5e43ed9 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Fri, 15 Sep 2023 16:06:56 +0600 Subject: [PATCH] Bring back fixed status icons for A13+ --- .../iconify/ui/activities/XposedOthers.java | 16 +- .../iconify/xposed/mods/BackgroundChip.java | 144 ++++++++++-------- .../iconify/xposed/mods/Miscellaneous.java | 9 +- 3 files changed, 96 insertions(+), 73 deletions(-) diff --git a/app/src/main/java/com/drdisagree/iconify/ui/activities/XposedOthers.java b/app/src/main/java/com/drdisagree/iconify/ui/activities/XposedOthers.java index 628b39ec9..5cd33d52b 100644 --- a/app/src/main/java/com/drdisagree/iconify/ui/activities/XposedOthers.java +++ b/app/src/main/java/com/drdisagree/iconify/ui/activities/XposedOthers.java @@ -90,13 +90,14 @@ protected void onCreate(Bundle savedInstanceState) { // Fixed status icons if (Build.VERSION.SDK_INT >= 33) { - binding.enableFixedStatusIconsContainer.setVisibility(View.GONE); ((View) binding.statusIconsSideMarginSeekbar.getParent()).setVisibility(View.GONE); - RPrefs.putBoolean(FIXED_STATUS_ICONS_SWITCH, false); } binding.enableFixedStatusIcons.setChecked(RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)); binding.enableFixedStatusIcons.setOnCheckedChangeListener((buttonView, isChecked) -> { + binding.statusIconsSideMarginSeekbar.setEnabled(isChecked); + binding.statusIconsTopMarginSeekbar.setEnabled(isChecked); + RPrefs.putBoolean(FIXED_STATUS_ICONS_SWITCH, isChecked); if (!isChecked) FabricatedUtil.disableOverlay("quickQsOffsetHeight"); else if (RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) > 32) @@ -115,7 +116,11 @@ else if (RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) > 32) // Status icons top margin binding.statusIconsTopMarginOutput.setText(getResources().getString(R.string.opt_selected) + ' ' + RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8) + "dp"); binding.statusIconsTopMarginSeekbar.setValue(RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8)); - binding.statusIconsTopMarginSeekbar.setEnabled(Build.VERSION.SDK_INT >= 33 ? RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) : RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)); + binding.statusIconsTopMarginSeekbar.setEnabled( + Build.VERSION.SDK_INT >= 33 ? + RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) || RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) : + RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) + ); if (Build.VERSION.SDK_INT >= 33) binding.statusIconsTopMarginSeekbar.setValueTo(200); final int[] topMarginStatusIcons = {RPrefs.getInt(FIXED_STATUS_ICONS_TOPMARGIN, 8)}; binding.statusIconsTopMarginSeekbar.addOnSliderTouchListener(new Slider.OnSliderTouchListener() { @@ -128,7 +133,10 @@ public void onStopTrackingTouch(@NonNull Slider slider) { topMarginStatusIcons[0] = (int) slider.getValue(); binding.statusIconsTopMarginOutput.setText(getResources().getString(R.string.opt_selected) + ' ' + topMarginStatusIcons[0] + "dp"); RPrefs.putInt(FIXED_STATUS_ICONS_TOPMARGIN, topMarginStatusIcons[0]); - if (Build.VERSION.SDK_INT >= 33 ? RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) : RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false)) { + if (Build.VERSION.SDK_INT >= 33 ? + RPrefs.getBoolean(QSPANEL_STATUSICONSBG_SWITCH, false) || RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) : + RPrefs.getBoolean(FIXED_STATUS_ICONS_SWITCH, false) + ) { if (Build.VERSION.SDK_INT < 33) { FabricatedUtil.buildAndEnableOverlay(FRAMEWORK_PACKAGE, "quickQsOffsetHeight", "dimen", "quick_qs_offset_height", (40 + topMarginStatusIcons[0]) + "dp"); } diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/BackgroundChip.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/BackgroundChip.java index 52249678f..9543722cf 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/BackgroundChip.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/BackgroundChip.java @@ -49,6 +49,7 @@ import com.drdisagree.iconify.R; import com.drdisagree.iconify.xposed.ModPack; +import java.lang.reflect.Field; import java.util.Objects; import de.robv.android.xposed.IXposedHookLoadPackage; @@ -203,14 +204,20 @@ protected void afterHookedMethod(MethodHookParam param) { if (Build.VERSION.SDK_INT >= 33) { Class QuickStatusBarHeader = findClass(SYSTEMUI_PACKAGE + ".qs.QuickStatusBarHeader", lpparam.classLoader); - Class ShadeHeaderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".shade.ShadeHeaderController", lpparam.classLoader); - try { - getObjectField(QuickStatusBarHeader, "mIconContainer"); + boolean correctClass = false; + Field[] fs = QuickStatusBarHeader.getDeclaredFields(); + for (Field f : fs) { + if (f.getName().equals("mIconContainer")) { + correctClass = true; + } + } + + if (correctClass) { hookAllMethods(QuickStatusBarHeader, "onFinishInflate", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) { - if (!mShowQSStatusIconsBg || hideStatusIcons) return; + if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return; FrameLayout mQuickStatusBarHeader = (FrameLayout) param.thisObject; LinearLayout mIconContainer = (LinearLayout) getObjectField(param.thisObject, "mIconContainer"); @@ -251,17 +258,20 @@ protected void afterHookedMethod(MethodHookParam param) { hookAllMethods(QuickStatusBarHeader, "updateResources", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) { + if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return; + updateStatusIcons(); } }); - } catch (Throwable ignored) { + } else { + Class ShadeHeaderControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".shade.ShadeHeaderController", lpparam.classLoader); if (ShadeHeaderControllerClass == null) ShadeHeaderControllerClass = findClass(SYSTEMUI_PACKAGE + ".shade.LargeScreenShadeHeaderController", lpparam.classLoader); hookAllMethods(ShadeHeaderControllerClass, "onInit", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) { - if (!mShowQSStatusIconsBg || hideStatusIcons) return; + if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return; LinearLayout iconContainer = (LinearLayout) getObjectField(param.thisObject, "iconContainer"); LinearLayout batteryIcon = (LinearLayout) getObjectField(param.thisObject, "batteryIcon"); @@ -305,7 +315,7 @@ protected void afterHookedMethod(MethodHookParam param) { hookAllMethods(ShadeHeaderControllerClass, "updateResources", new XC_MethodHook() { @Override protected void afterHookedMethod(MethodHookParam param) { - if (!mShowQSStatusIconsBg || hideStatusIcons) return; + if ((!mShowQSStatusIconsBg && !fixedStatusIcons) || hideStatusIcons) return; updateStatusIcons(); } @@ -329,44 +339,49 @@ private void updateStatusBarClock() { } private void updateStatusIcons() { - if (!mShowQSStatusIconsBg || mQsStatusIconsContainer.getChildCount() == 0) return; + if (mQsStatusIconsContainer.getChildCount() == 0) + return; int paddingTopBottom = dp2px(mContext, 4); int paddingStartEnd = dp2px(mContext, 12); - setStatusIconsBackgroundChip(mQsStatusIconsContainer); - mQsStatusIconsContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); - try { + if (mShowQSStatusIconsBg) { + setStatusIconsBackgroundChip(mQsStatusIconsContainer); + mQsStatusIconsContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); + } + + if (mQsStatusIconsContainer.getLayoutParams() instanceof FrameLayout.LayoutParams) { ((FrameLayout.LayoutParams) mQsStatusIconsContainer.getLayoutParams()).setMargins(0, dp2px(mContext, topMarginStatusIcons), 0, 0); - } catch (Throwable ignored) { - if (mLoadPackageParam != null && header != null && constraintLayoutId != -1) { - try { - Class ConstraintSetClass = findClass("androidx.constraintlayout.widget.ConstraintSet", mLoadPackageParam.classLoader); - Object mConstraintSet = ConstraintSetClass.newInstance(); - - callMethod(mConstraintSet, "clone", header); - callMethod(mConstraintSet, - "connect", - constraintLayoutId, - ConstraintSet.TOP, - ConstraintSet.PARENT_ID, - ConstraintSet.TOP, - 0); - callMethod(mConstraintSet, - "connect", - constraintLayoutId, - ConstraintSet.END, - ConstraintSet.PARENT_ID, - ConstraintSet.END, - 0); - callMethod(mConstraintSet, "applyTo", header); - - callMethod(callMethod(mQsStatusIconsContainer, "getLayoutParams"), "setMargins", 0, dp2px(mContext, topMarginStatusIcons), 0, 0); - } catch (Throwable throwable) { - log(TAG + throwable); - } + } else if (mQsStatusIconsContainer.getLayoutParams() instanceof LinearLayout.LayoutParams) { + ((LinearLayout.LayoutParams) mQsStatusIconsContainer.getLayoutParams()).setMargins(0, dp2px(mContext, topMarginStatusIcons), 0, 0); + } else if (mLoadPackageParam != null && header != null && constraintLayoutId != -1) { + try { + Class ConstraintSetClass = findClass("androidx.constraintlayout.widget.ConstraintSet", mLoadPackageParam.classLoader); + Object mConstraintSet = ConstraintSetClass.newInstance(); + + callMethod(mConstraintSet, "clone", header); + callMethod(mConstraintSet, + "connect", + constraintLayoutId, + ConstraintSet.TOP, + ConstraintSet.PARENT_ID, + ConstraintSet.TOP, + 0); + callMethod(mConstraintSet, + "connect", + constraintLayoutId, + ConstraintSet.END, + ConstraintSet.PARENT_ID, + ConstraintSet.END, + 0); + callMethod(mConstraintSet, "applyTo", header); + + callMethod(callMethod(mQsStatusIconsContainer, "getLayoutParams"), "setMargins", 0, dp2px(mContext, topMarginStatusIcons), 0, 0); + } catch (Throwable throwable) { + log(TAG + throwable); } } + mQsStatusIconsContainer.requestLayout(); Configuration config = mContext.getResources().getConfiguration(); @@ -375,6 +390,7 @@ private void updateStatusIcons() { } else { mQsStatusIconsContainer.setVisibility(View.VISIBLE); } + } private void setSBClockBackgroundChip(View view) { @@ -487,25 +503,23 @@ private void setQSStatusIconsBgA12() { ourResparam.res.hookLayout(SYSTEMUI_PACKAGE, "layout", "quick_qs_status_icons", new XC_LayoutInflated() { @Override public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam) { - if (!mShowQSStatusIconsBg || hideStatusIcons) return; + if (!mShowQSStatusIconsBg || hideStatusIcons || fixedStatusIcons) return; - if (!fixedStatusIcons) { - try { - @SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName())); - LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent(); + try { + @SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName())); + LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent(); - ((FrameLayout.LayoutParams) statusIconContainer.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END; - statusIconContainer.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, mContext.getResources().getDisplayMetrics()); - statusIconContainer.requestLayout(); + ((FrameLayout.LayoutParams) statusIconContainer.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END; + statusIconContainer.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, mContext.getResources().getDisplayMetrics()); + statusIconContainer.requestLayout(); - int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics()); - int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics()); - statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); + int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics()); + int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics()); + statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); - setStatusIconsBackgroundChip(statusIconContainer); - } catch (Throwable throwable) { - log(TAG + throwable); - } + setStatusIconsBackgroundChip(statusIconContainer); + } catch (Throwable throwable) { + log(TAG + throwable); } } }); @@ -513,23 +527,21 @@ public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam) ourResparam.res.hookLayout(SYSTEMUI_PACKAGE, "layout", "quick_status_bar_header_date_privacy", new XC_LayoutInflated() { @Override public void handleLayoutInflated(LayoutInflatedParam liparam) { - if (!mShowQSStatusIconsBg || hideStatusIcons) return; + if (!mShowQSStatusIconsBg || hideStatusIcons || !fixedStatusIcons) return; - if (fixedStatusIcons) { - try { - @SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName())); - if (statusIcons != null) { - LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent(); + try { + @SuppressLint("DiscouragedApi") LinearLayout statusIcons = liparam.view.findViewById(liparam.res.getIdentifier("statusIcons", "id", mContext.getPackageName())); + if (statusIcons != null) { + LinearLayout statusIconContainer = (LinearLayout) statusIcons.getParent(); - int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics()); - int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics()); - statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); + int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, mContext.getResources().getDisplayMetrics()); + int paddingStartEnd = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, mContext.getResources().getDisplayMetrics()); + statusIconContainer.setPadding(paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); - setStatusIconsBackgroundChip(statusIconContainer); - } - } catch (Throwable throwable) { - log(TAG + throwable); + setStatusIconsBackgroundChip(statusIconContainer); } + } catch (Throwable throwable) { + log(TAG + throwable); } } }); diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java index c454faa28..a61a3192a 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/Miscellaneous.java @@ -20,6 +20,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.os.Build; import android.util.TypedValue; import android.view.Gravity; import android.view.View; @@ -76,7 +77,7 @@ public void updatePrefs(String... Key) { if (Objects.equals(Key[0], HIDE_STATUS_ICONS_SWITCH)) hideStatusIcons(); if (Objects.equals(Key[0], FIXED_STATUS_ICONS_SWITCH) || Objects.equals(Key[0], HIDE_STATUS_ICONS_SWITCH) || Objects.equals(Key[0], FIXED_STATUS_ICONS_TOPMARGIN) || Objects.equals(Key[0], FIXED_STATUS_ICONS_SIDEMARGIN)) - fixedStatusIcons(); + fixedStatusIconsA12(); if (Objects.equals(Key[0], HIDE_LOCKSCREEN_CARRIER) || Objects.equals(Key[0], HIDE_LOCKSCREEN_STATUSBAR)) hideLockscreenCarrierOrStatusbar(); @@ -176,7 +177,7 @@ protected void afterHookedMethod(MethodHookParam param) { hideQSCarrierGroup(); hideStatusIcons(); - fixedStatusIcons(); + fixedStatusIconsA12(); hideLockscreenCarrierOrStatusbar(); Class MobileSignalController = findClass(SYSTEMUI_PACKAGE + ".statusbar.connectivity.MobileSignalController", lpparam.classLoader); @@ -355,7 +356,9 @@ public void handleLayoutInflated(XC_LayoutInflated.LayoutInflatedParam liparam) } } - private void fixedStatusIcons() { + private void fixedStatusIconsA12() { + if (Build.VERSION.SDK_INT >= 33) return; + XC_InitPackageResources.InitPackageResourcesParam ourResparam = resparams.get(SYSTEMUI_PACKAGE); if (ourResparam == null) return;