From 52eaeaca7d20142a8b210b449636fb5772febfdb Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Thu, 9 May 2024 23:14:15 +0200 Subject: [PATCH] CHANGELOG: Added Notification Expansion behaviour --- .../statusbar/StatusbarNotification.java | 75 +++++++++++++++++++ app/src/main/res/values/arrays.xml | 12 +++ app/src/main/res/values/strings.xml | 3 + .../main/res/xml/statusbar_notifications.xml | 8 ++ 4 files changed, 98 insertions(+) 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 680baf0af..d70350fdb 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 @@ -1,7 +1,9 @@ package it.dhd.oxygencustomizer.xposed.hooks.systemui.statusbar; import static de.robv.android.xposed.XposedBridge.hookAllConstructors; +import static de.robv.android.xposed.XposedBridge.hookAllMethods; import static de.robv.android.xposed.XposedBridge.log; +import static de.robv.android.xposed.XposedHelpers.callMethod; import static de.robv.android.xposed.XposedHelpers.findAndHookMethod; import static de.robv.android.xposed.XposedHelpers.findClass; import static de.robv.android.xposed.XposedHelpers.findClassIfExists; @@ -13,6 +15,8 @@ import android.os.Bundle; import android.view.View; +import java.util.Collection; + import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.callbacks.XC_LoadPackage; import it.dhd.oxygencustomizer.utils.Constants; @@ -26,6 +30,16 @@ public class StatusbarNotification extends XposedMods { private View mStatusBar; private boolean removeChargingCompleteNotification, removeDevMode, removeFlashlightNotification, removeLowBattery; + // Notification Expander + private static final int DEFAULT = 0; + private static final int EXPAND_ALWAYS = 1; + /** @noinspection unused*/ + private static final int COLLAPSE_ALWAYS = 2; + private static int notificationDefaultExpansion = DEFAULT; + private Object Scroller; + private Object NotifCollection = null; + + public StatusbarNotification(Context context) { super(context); } @@ -36,6 +50,8 @@ public void updatePrefs(String... Key) { removeDevMode = Xprefs.getBoolean("remove_dev_mode", false); removeFlashlightNotification = Xprefs.getBoolean("remove_flashlight_notification", false); removeLowBattery = Xprefs.getBoolean("remove_low_battery_notification", false); + notificationDefaultExpansion = Integer.parseInt(Xprefs.getString("notificationDefaultExpansion", "0")); + } @@ -116,6 +132,65 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { } }); + Class NotificationStackScrollLayoutClass = findClass("com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout", lpparam.classLoader); + Class NotifCollectionClass = findClassIfExists("com.android.systemui.statusbar.notification.collection.NotifCollection", lpparam.classLoader); + Class NotificationPanelViewControllerClass = findClass("com.android.systemui.shade.NotificationPanelViewController", lpparam.classLoader); + + //region default notification state + hookAllMethods(NotificationPanelViewControllerClass, "notifyExpandingStarted", new XC_MethodHook() { + @Override + protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable { + if(notificationDefaultExpansion != DEFAULT) + expandAll(notificationDefaultExpansion == EXPAND_ALWAYS); + } + }); + //endregion + + //grab notification container manager + if (NotifCollectionClass != null) { + hookAllConstructors(NotifCollectionClass, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + NotifCollection = param.thisObject; + } + }); + } + + //grab notification scroll page + hookAllConstructors(NotificationStackScrollLayoutClass, new XC_MethodHook() { + @Override + protected void afterHookedMethod(MethodHookParam param) throws Throwable { + Scroller = param.thisObject; + } + }); + + } + + public void expandAll(boolean expand) { + if (NotifCollection == null) return; + + if (!expand) { + callMethod( + Scroller, + "setOwnScrollY", + /* pisition */0, + /* animate */ true); + } + + Collection entries; + //noinspection unchecked + entries = (Collection) getObjectField(NotifCollection, "mReadOnlyNotificationSet"); + for (Object entry : entries.toArray()) { + Object row = getObjectField(entry, "row"); + if (row != null) { + setRowExpansion(row, expand); + } + } + + } + + private void setRowExpansion(Object row, boolean expand) { + callMethod(row, "setUserExpanded", expand, true); } @Override diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 790456cb3..45d0fce15 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -221,6 +221,18 @@ + + @string/default_value + @string/notif_always_expand + @string/notif_always_collapse + + + + 0 + 1 + 2 + + @string/default_value diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3434411b1..b86907582 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -97,6 +97,9 @@ Remove dev mode notification Remove flashlight notification Remove low battery notification + Notification default expansion + Always expand + Always collapse diff --git a/app/src/main/res/xml/statusbar_notifications.xml b/app/src/main/res/xml/statusbar_notifications.xml index fdd8fa01d..684b589e2 100644 --- a/app/src/main/res/xml/statusbar_notifications.xml +++ b/app/src/main/res/xml/statusbar_notifications.xml @@ -61,6 +61,14 @@ android:summaryOn="@string/general_on" android:summaryOff="@string/general_off" /> +