From c63f56735129e12e2415669ddb87996e44694f76 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Sun, 24 Sep 2023 01:25:55 +0600 Subject: [PATCH] Extract view tags for better understanding --- .../iconify/common/Preferences.java | 5 ++ .../iconify/xposed/mods/DepthWallpaper.java | 19 ++++++-- .../iconify/xposed/mods/HeaderClock.java | 8 ++-- .../iconify/xposed/mods/LockscreenClock.java | 46 +++++++++++-------- 4 files changed, 51 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/drdisagree/iconify/common/Preferences.java b/app/src/main/java/com/drdisagree/iconify/common/Preferences.java index d88e3af8a..39e5f91a6 100644 --- a/app/src/main/java/com/drdisagree/iconify/common/Preferences.java +++ b/app/src/main/java/com/drdisagree/iconify/common/Preferences.java @@ -62,6 +62,11 @@ public class Preferences { public static final String HIDE_DATA_DISABLED_ICON = "xposed_hideDataDisabledIcon"; public static final String DEPTH_WALLPAPER_SWITCH = "xposed_depthwallpaper"; + // Xposed view tags + public static final String ICONIFY_HEADER_CLOCK_TAG = "iconify_header_clock"; + public static final String ICONIFY_LOCKSCREEN_CLOCK_TAG = "iconify_lockscreen_clock"; + public static final String ICONIFY_DEPTH_WALLPAPER_TAG = "iconify_depth_wallpaper"; + // Battery styles public static final int BATTERY_STYLE_DEFAULT = 0; public static final int BATTERY_STYLE_DEFAULT_RLANDSCAPE = 1; diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java index 89c71c9d5..0166f6b7b 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java @@ -2,6 +2,7 @@ import static com.drdisagree.iconify.common.Const.SYSTEMUI_PACKAGE; import static com.drdisagree.iconify.common.Preferences.DEPTH_WALLPAPER_SWITCH; +import static com.drdisagree.iconify.common.Preferences.ICONIFY_DEPTH_WALLPAPER_TAG; import static com.drdisagree.iconify.config.XPrefs.Xprefs; import static de.robv.android.xposed.XposedBridge.hookAllMethods; import static de.robv.android.xposed.XposedHelpers.findClass; @@ -89,8 +90,19 @@ protected void afterHookedMethod(MethodHookParam param) { TextView mTopIndicationView = mIndicationArea.findViewById(mContext.getResources().getIdentifier("keyguard_indication_text", "id", mContext.getPackageName())); TextView mLockScreenIndicationView = mIndicationArea.findViewById(mContext.getResources().getIdentifier("keyguard_indication_text_bottom", "id", mContext.getPackageName())); + /* + We added a blank view to the top of the layout to push the indication text views to the bottom + The reason we did this is because gravity is not working properly on the indication text views + */ + View blankView = new View(mContext); + blankView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f)); + + // Remove the existing indication text views from the indication area ((ViewGroup) mTopIndicationView.getParent()).removeView(mTopIndicationView); ((ViewGroup) mLockScreenIndicationView.getParent()).removeView(mLockScreenIndicationView); + + // Add the indication text views to the new layout + mIndicationTextView.addView(blankView); mIndicationTextView.addView(mTopIndicationView); mIndicationTextView.addView(mLockScreenIndicationView); @@ -100,14 +112,13 @@ protected void afterHookedMethod(MethodHookParam param) { mIndicationArea.addView(mIndicationAreaDupe); // Get the depth wallpaper layout - String depth_wall_tag = "iconify_depth_wallpaper"; - mDepthWallpaperLayout = mIndicationArea.findViewWithTag(depth_wall_tag); + mDepthWallpaperLayout = mIndicationArea.findViewWithTag(ICONIFY_DEPTH_WALLPAPER_TAG); // Create the depth wallpaper layout if it doesn't exist if (mDepthWallpaperLayout == null) { mDepthWallpaperLayout = new FrameLayout(mContext); mDepthWallpaperLayout.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - mDepthWallpaperLayout.setTag(depth_wall_tag); + mDepthWallpaperLayout.setTag(ICONIFY_DEPTH_WALLPAPER_TAG); mIndicationAreaDupe.addView(mDepthWallpaperLayout, 0); } @@ -118,7 +129,7 @@ protected void afterHookedMethod(MethodHookParam param) { mDepthWallpaperForeground.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mDepthWallpaperLayout.addView(mDepthWallpaperBackground, 0); - mDepthWallpaperLayout.addView(mDepthWallpaperForeground); + mDepthWallpaperLayout.addView(mDepthWallpaperForeground, -1); // Fix the bottom shortcuts pushing the wallpaper ImageView startButton = view.findViewById(mContext.getResources().getIdentifier("start_button", "id", mContext.getPackageName())); diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java index d3ed9cc25..806f99b84 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java @@ -12,6 +12,7 @@ import static com.drdisagree.iconify.common.Preferences.HEADER_CLOCK_SWITCH; import static com.drdisagree.iconify.common.Preferences.HEADER_CLOCK_TEXT_WHITE; import static com.drdisagree.iconify.common.Preferences.HEADER_CLOCK_TOPMARGIN; +import static com.drdisagree.iconify.common.Preferences.ICONIFY_HEADER_CLOCK_TAG; import static com.drdisagree.iconify.config.XPrefs.Xprefs; import static com.drdisagree.iconify.xposed.HookRes.resparams; import static de.robv.android.xposed.XposedBridge.hookAllMethods; @@ -272,9 +273,8 @@ private void updateClockView() { } ViewGroup clockView = HeaderClockStyles.getClock(mContext); - String clock_tag = "iconify_header_clock"; - if (mQsClockContainer.findViewWithTag(clock_tag) != null) { - mQsClockContainer.removeView(mQsClockContainer.findViewWithTag(clock_tag)); + if (mQsClockContainer.findViewWithTag(ICONIFY_HEADER_CLOCK_TAG) != null) { + mQsClockContainer.removeView(mQsClockContainer.findViewWithTag(ICONIFY_HEADER_CLOCK_TAG)); } if (clockView != null) { if (centeredClockView) { @@ -282,7 +282,7 @@ private void updateClockView() { } else { mQsClockContainer.setGravity(Gravity.START); } - clockView.setTag(clock_tag); + clockView.setTag(ICONIFY_HEADER_CLOCK_TAG); mQsClockContainer.addView(clockView); mQsClockContainer.requestLayout(); } diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java index d746562e5..ff0fa3197 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java @@ -2,6 +2,8 @@ import static com.drdisagree.iconify.common.Const.SYSTEMUI_PACKAGE; import static com.drdisagree.iconify.common.Preferences.DEPTH_WALLPAPER_SWITCH; +import static com.drdisagree.iconify.common.Preferences.ICONIFY_DEPTH_WALLPAPER_TAG; +import static com.drdisagree.iconify.common.Preferences.ICONIFY_LOCKSCREEN_CLOCK_TAG; import static com.drdisagree.iconify.common.Preferences.LSCLOCK_BOTTOMMARGIN; import static com.drdisagree.iconify.common.Preferences.LSCLOCK_COLOR_CODE; import static com.drdisagree.iconify.common.Preferences.LSCLOCK_COLOR_SWITCH; @@ -146,8 +148,19 @@ protected void afterHookedMethod(MethodHookParam param) { TextView mTopIndicationView = mIndicationArea.findViewById(mContext.getResources().getIdentifier("keyguard_indication_text", "id", mContext.getPackageName())); TextView mLockScreenIndicationView = mIndicationArea.findViewById(mContext.getResources().getIdentifier("keyguard_indication_text_bottom", "id", mContext.getPackageName())); + /* + We added a blank view to the top of the layout to push the indication text views to the bottom + The reason we did this is because gravity is not working properly on the indication text views + */ + View blankView = new View(mContext); + blankView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f)); + + // Remove the existing indication text views from the indication area ((ViewGroup) mTopIndicationView.getParent()).removeView(mTopIndicationView); ((ViewGroup) mLockScreenIndicationView.getParent()).removeView(mLockScreenIndicationView); + + // Add the indication text views to the new layout + mIndicationTextView.addView(blankView); mIndicationTextView.addView(mTopIndicationView); mIndicationTextView.addView(mLockScreenIndicationView); @@ -157,14 +170,13 @@ protected void afterHookedMethod(MethodHookParam param) { mIndicationArea.addView(mIndicationAreaDupe); // Get the depth wallpaper layout - String depth_wall_tag = "iconify_depth_wallpaper"; - mClockViewContainer = mIndicationArea.findViewWithTag(depth_wall_tag); + mClockViewContainer = mIndicationArea.findViewWithTag(ICONIFY_DEPTH_WALLPAPER_TAG); // Create the depth wallpaper layout if it doesn't exist if (mClockViewContainer == null) { mClockViewContainer = new FrameLayout(mContext); mClockViewContainer.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - mClockViewContainer.setTag(depth_wall_tag); + mClockViewContainer.setTag(ICONIFY_DEPTH_WALLPAPER_TAG); mIndicationAreaDupe.addView(mClockViewContainer, 0); } @@ -214,30 +226,28 @@ public void onReceive(Context context, Intent intent) { private void updateClockView() { if (mClockViewContainer == null) return; - ViewGroup clockView = LockscreenClockStyles.getClock(mContext); - String clock_tag = "iconify_lockscreen_clock"; + View clockView = LockscreenClockStyles.getClock(mContext); // Remove existing clock view - if (mClockViewContainer.findViewWithTag(clock_tag) != null) { - mClockViewContainer.removeView(mClockViewContainer.findViewWithTag(clock_tag)); + if (mClockViewContainer.findViewWithTag(ICONIFY_LOCKSCREEN_CLOCK_TAG) != null) { + mClockViewContainer.removeView(mClockViewContainer.findViewWithTag(ICONIFY_LOCKSCREEN_CLOCK_TAG)); } if (clockView != null) { - clockView.setTag(clock_tag); + clockView.setTag(ICONIFY_LOCKSCREEN_CLOCK_TAG); int idx = 0; - String depth_wall_tag = "iconify_depth_wallpaper"; - if (mClockViewContainer.getTag() == depth_wall_tag) { + if (mClockViewContainer.getTag() == ICONIFY_DEPTH_WALLPAPER_TAG) { /* If the clock view container is the depth wallpaper container, we need to add the clock view to the middle of foreground and background images */ - if (mClockViewContainer.getChildCount() == 2) { + if (mClockViewContainer.getChildCount() > 0) { idx = 1; } - // Add a dummy layout to the status view container so that we can move notifications + // Add a dummy layout to the status view container so that we can still move notifications if (mStatusViewContainer != null) { String dummy_tag = "dummy_layout"; LinearLayout dummyLayout = mStatusViewContainer.findViewWithTag(dummy_tag); @@ -250,14 +260,13 @@ private void updateClockView() { } dummyLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300)); - ViewGroup.MarginLayoutParams clockParams = (ViewGroup.MarginLayoutParams) clockView.getLayoutParams(); ((LinearLayout.LayoutParams) clockView.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL; - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) dummyLayout.getLayoutParams(); - params.topMargin = clockParams.topMargin; - params.bottomMargin = clockParams.bottomMargin; - dummyLayout.setLayoutParams(params); - mStatusViewContainer.requestLayout(); + ViewGroup.MarginLayoutParams dummyParams = (ViewGroup.MarginLayoutParams) dummyLayout.getLayoutParams(); + ViewGroup.MarginLayoutParams clockParams = (ViewGroup.MarginLayoutParams) clockView.getLayoutParams(); + dummyParams.topMargin = clockParams.topMargin; + dummyParams.bottomMargin = clockParams.bottomMargin; + dummyLayout.setLayoutParams(dummyParams); } } @@ -265,7 +274,6 @@ private void updateClockView() { ((ViewGroup) clockView.getParent()).removeView(clockView); } mClockViewContainer.addView(clockView, idx); - mClockViewContainer.requestLayout(); } } } \ No newline at end of file