From 7fae0246566ee27bf983f18b230c106784f8054d Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Thu, 25 Apr 2024 16:57:29 +0200 Subject: [PATCH] Misc fixes for OOS13 --- .../hooks/systemui/statusbar/HeaderClock.java | 93 ++++++++++++------- .../systemui/statusbar/StatusbarClock.java | 28 ++++-- .../statusbar/StatusbarNotification.java | 7 +- 3 files changed, 86 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/HeaderClock.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/HeaderClock.java index 6a3159718..0e5263c7a 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/HeaderClock.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/HeaderClock.java @@ -131,8 +131,8 @@ public class HeaderClock extends XposedMods { private int stockClockDateBackgroundChipStyle; private int mAccent; - private GradientDrawable mClockChipDrawale = new GradientDrawable(); - private GradientDrawable mDateChipDrawale = new GradientDrawable(); + private GradientDrawable mClockChipDrawale; + private GradientDrawable mDateChipDrawale; private Typeface mStockClockTypeface, mStockDateTypeface; private Object OQC = null; private Object mActivityStarter = null; @@ -217,7 +217,7 @@ public void updatePrefs(String... Key) { } for (String k : QS_HEADER_CHIP_PREFS) { if (Key[0].equals(k)) { - updateChips(); + setupChips(); } } } @@ -271,21 +271,32 @@ protected void afterHookedMethod(MethodHookParam param) { try { mOplusDate = (TextView) getObjectField(param.thisObject, "mQsDateView"); mStockDateTypeface = mOplusDate.getTypeface(); - } catch (Throwable ignored) { + } catch (Throwable t) { + try { + mOplusDate = (TextView) mQuickStatusBarHeader.findViewById(mContext.getResources().getIdentifier("oplus_date", "id", listenPackage)); + } catch (Throwable ignored) {} } try { mOplusClock = (TextView) getObjectField(param.thisObject, "mClockView"); mStockClockTypeface = mOplusClock.getTypeface(); - } catch (Throwable ignored) { + } catch (Throwable t) { + try { + mOplusClock = (TextView) mQuickStatusBarHeader.findViewById(mContext.getResources().getIdentifier("qs_footer_clock", "id", listenPackage)); + } catch (Throwable ignored) {} } try { mOplusCarrier = (TextView) getObjectField(param.thisObject, "mOplusQSCarrier"); - } catch (Throwable ignored) { + } catch (Throwable t) { + try { + mOplusCarrier = (TextView) mQuickStatusBarHeader.findViewById(mContext.getResources().getIdentifier("qs_footer_carrier_text", "id", listenPackage)); + } catch (Throwable ignored) {} } updateStockPrefs(); + setupChips(); + updateChips(); updateClockView(); } }); @@ -360,6 +371,7 @@ protected void beforeHookedMethod(MethodHookParam param) { @Override protected void afterHookedMethod(MethodHookParam param) { updateClockView(); + updateChips(); } }); @@ -431,7 +443,12 @@ public boolean listensTo(String packageName) { return listenPackage.equals(packageName); } - private void updateChips() { + private void setupChips() { + + mClockChipDrawale = new GradientDrawable(); + mDateChipDrawale = new GradientDrawable(); + + log(TAG + "updateChips: " + stockClockTimeBackgroundChip + " " + stockClockDateBackgroundChip); mAccent = getPrimaryColor(mContext); mClockChipDrawale.setShape(GradientDrawable.RECTANGLE); @@ -496,6 +513,20 @@ else if (stockClockDateChipGradient) mDateChipDrawale.setStroke(stockDateStrokeWidth, stockClockDateUseAccent ? mAccent : stockClockDateChipGradient1); } mDateChipDrawale.invalidateSelf(); + + } + + private void updateChips() { + if (stockClockTimeBackgroundChip) { + applyChip(mOplusClock); + } else { + removeChip(mOplusClock); + } + if (!stockClockHideDate && stockClockDateBackgroundChip) { + applyChip(mOplusDate); + } else { + removeChip(mOplusDate); + } } private void hideView(TextView textView) { @@ -504,7 +535,8 @@ private void hideView(TextView textView) { if (textView.getVisibility() != View.VISIBLE) return; textView.setVisibility(View.INVISIBLE); textView.setTextColor(Color.TRANSPARENT); - } catch (Throwable ignored) { + } catch (Throwable t) { + log(TAG + "hideView: " + t.getMessage()); } } @@ -546,13 +578,13 @@ private void updateStockPrefs() { } // Stock clock hide date - if (stockClockHideDate) { + if (showHeaderClock || stockClockHideDate) { hideView(mOplusDate); } else { showView(mOplusDate); } - if (stockClockHideCarrier || showHeaderClock) { + if (showHeaderClock || stockClockHideCarrier) { hideView(mOplusCarrier); } else { showView(mOplusCarrier); @@ -563,30 +595,23 @@ private void updateStockPrefs() { } private void setupStockColors() { - if (stockClockTimeBackgroundChip) { - mOplusClock.setBackground(mClockChipDrawale); - } else { - removeChip(mOplusClock); - } - if (!stockClockHideDate && stockClockDateBackgroundChip) { - mOplusDate.setBackground(mDateChipDrawale); - } else { - removeChip(mOplusDate); - } + boolean nightMode = mContext.getResources().getConfiguration().isNightModeActive(); + int textColor = nightMode ? Color.WHITE : Color.BLACK; if (stockClockTimeColorSwitch) { mOplusClock.setTextColor(stockClockTimeColor); } else { - mOplusClock.setTextColor(Color.WHITE); + mOplusClock.setTextColor(textColor); } if (!stockClockHideDate && stockClockDateColorSwitch) { mOplusDate.setTextColor(stockClockDateColor); - } else if (!stockClockHideDate && !stockClockDateColorSwitch) { - mOplusDate.setTextColor(Color.WHITE); + } else if (!stockClockHideDate) { + mOplusDate.setTextColor(textColor); } } private void removeChip(TextView textView) { + if (textView == null || textView.getVisibility() != View.VISIBLE) return; try { textView.setBackground(null); } catch (Throwable t) { @@ -594,6 +619,15 @@ private void removeChip(TextView textView) { } } + private void applyChip(TextView textView) { + if (textView == null || textView.getVisibility() != View.VISIBLE) return; + try { + textView.setBackground(textView == mOplusClock ? mClockChipDrawale : mDateChipDrawale); + } catch (Throwable t) { + log(TAG + "applyChip: " + t.getMessage()); + } + } + private void updateClockView() { if (mQsClockContainer == null) return; @@ -667,11 +701,8 @@ private void modifyClockView(View clockView) { String customFont = Environment.getExternalStorageDirectory() + "/.oxygencustomizer_files/headerclock_font.ttf"; int mAccent = getPrimaryColor(mContext); boolean customColor = Xprefs.getBoolean(QS_HEADER_CLOCK_CUSTOM_COLOR_SWITCH, false); - int textColor = Color.BLACK; - try { - textColor = mContext.getColor(mContext.getResources().getIdentifier("status_bar_qs_footer_clock", "color", listenPackage)); - } catch (Throwable ignored) { - } + boolean nightMode = mContext.getResources().getConfiguration().isNightModeActive(); + int textColor = nightMode ? Color.WHITE : Color.BLACK; int accent1 = Xprefs.getInt( QS_HEADER_CLOCK_COLOR_CODE_ACCENT1, @@ -695,20 +726,15 @@ private void modifyClockView(View clockView) { ); Typeface typeface = null; - log(TAG + "modifyClockView" + " customFont: " + customFont + " customFontEnabled: " + customFontEnabled); if (customFontEnabled && (new File(customFont).exists())) typeface = Typeface.createFromFile(new File(customFont)); - log(TAG + "modifyClockView" + " typeface: " + typeface + " clockScale: " + clockScale + " sideMargin: " + sideMargin + " topMargin: " + topMargin); - if (TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL) { ViewHelper.setMargins(clockView, mContext, 0, topMargin, sideMargin, 0); } else { ViewHelper.setMargins(clockView, mContext, sideMargin, topMargin, 0, 0); } - log(TAG + "setColors"); - ViewHelper.findViewWithTagAndChangeColor(clockView, "accent1", customColor ? accent1 : mAccent); ViewHelper.findViewWithTagAndChangeColor(clockView, "accent2", customColor ? accent2 : mAccent); ViewHelper.findViewWithTagAndChangeColor(clockView, "accent3", customColor ? accent3 : mAccent); @@ -717,7 +743,6 @@ private void modifyClockView(View clockView) { ViewHelper.findViewWithTagAndChangeColor(clockView, "backgroundAccent", customColor ? accent1 : mAccent); if (typeface != null) { - log(TAG + "modifyClockView" + " applyFont"); ViewHelper.applyFontRecursively((ViewGroup) clockView, typeface); } diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarClock.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarClock.java index 8fb4e65e8..eead1b9a6 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarClock.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarClock.java @@ -30,6 +30,7 @@ import android.content.pm.ResolveInfo; import android.graphics.Color; import android.graphics.drawable.GradientDrawable; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.text.Spannable; @@ -123,7 +124,7 @@ public class StatusbarClock extends XposedMods { private int chipTopSxRound, chipTopDxRound, chipBottomSxRound,chipBottomDxRound; private int mAccent; private final GradientDrawable mClockChipDrawale = new GradientDrawable(); - private int mClockSize = 14; + private int mClockSize = 12; public StatusbarClock(Context context) { @@ -234,6 +235,21 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } }); + if (Build.VERSION.SDK_INT == 33) { + try { + Class PhoneStatusBarView = findClass("com.android.systemui.statusbar.phone.PhoneStatusBarView", lpparam.classLoader); + hookAllMethods(PhoneStatusBarView, "onFinishInflate", new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + FrameLayout mStatusBar = (FrameLayout) param.thisObject; + mStatusbarStartSide = mStatusBar.findViewById(mContext.getResources().getIdentifier("status_bar_left_side", "id", mContext.getPackageName())); + } + }); + } catch (Throwable ignored) {} + } else { + mStatusbarStartSide = null; + } + findAndHookMethod(CollapsedStatusBarFragmentClass, "onViewCreated", View.class, Bundle.class, new XC_MethodHook() { @SuppressLint("DiscouragedApi") @@ -246,11 +262,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } ViewGroup mStatusBar = (ViewGroup) getObjectField(mCollapsedStatusBarFragment, "mStatusBar"); - try { - mStatusbarStartSide = mStatusBar.findViewById(mContext.getResources().getIdentifier("status_bar_start_side_except_heads_up", "id", mContext.getPackageName())); - } catch (Throwable t) { - mStatusbarStartSide = mStatusBar.findViewById(mContext.getResources().getIdentifier("status_bar_left_side", "id", mContext.getPackageName())); // OOS 13 - } + if (mStatusbarStartSide == null) mStatusbarStartSide = mStatusBar.findViewById(mContext.getResources().getIdentifier("status_bar_start_side_except_heads_up", "id", mContext.getPackageName())); try { mSystemIconArea = mStatusBar.findViewById(mContext.getResources().getIdentifier("statusIcons", "id", mContext.getPackageName())); @@ -278,6 +290,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } }); + + hookAllMethods(ClockClass, "updateClockVisibility", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { @@ -540,7 +554,7 @@ else if (chipUseGradient) private void setupChip() { if (clockChip) { - mClockView.setPadding(dp2px(mContext, 4), 0, dp2px(mContext, 4), 0); + mClockView.setPadding(dp2px(mContext, 2), 0, dp2px(mContext, 2), 0); mClockView.setBackground(mClockChipDrawale); } else { mClockView.setPadding(0, 0, 0, 0); diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarNotification.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarNotification.java index e2baa3d45..80787037b 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarNotification.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/StatusbarNotification.java @@ -103,7 +103,12 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { } }); - Class SystemPromptController = findClass("com.oplus.systemui.statusbar.controller.SystemPromptController", lpparam.classLoader); + Class SystemPromptController; + try { + SystemPromptController = findClass("com.oplus.systemui.statusbar.controller.SystemPromptController", lpparam.classLoader); + } catch (Throwable t) { + SystemPromptController = findClass("com.oplusos.systemui.controller.SystemPromptController", lpparam.classLoader); // OOS 13 + } findAndHookMethod(SystemPromptController, "updateDeveloperMode", new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable {