Skip to content

Commit

Permalink
CHANGELOG: Added Notification Expansion behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed May 9, 2024
1 parent 9615037 commit 52eaeac
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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"));


}

Expand Down Expand Up @@ -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<Object> entries;
//noinspection unchecked
entries = (Collection<Object>) 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
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@
<!-- <item>@string/status_bar_date_format_custom</item> -->
</string-array>

<string-array name="notif_default_expansion_entries">
<item>@string/default_value</item>
<item>@string/notif_always_expand</item>
<item>@string/notif_always_collapse</item>
</string-array>

<string-array name="notif_default_expansion_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

<!-- Lockscreen Stock Red One -->
<string-array name="lockscreen_stock_clock_red_one_entries" translatable="false">
<item>@string/default_value</item>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<string name="remove_dev_mode_notification">Remove dev mode notification</string>
<string name="remove_flashlight_notification">Remove flashlight notification</string>
<string name="remove_low_battery_notification">Remove low battery notification</string>
<string name="notif_default_expansion_title">Notification default expansion</string>
<string name="notif_always_expand">Always expand</string>
<string name="notif_always_collapse">Always collapse</string>

<!-- Statusbar Clock Strings -->
<!-- Status bar - Clock -->
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/statusbar_notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
android:summaryOn="@string/general_on"
android:summaryOff="@string/general_off" />

<ListPreference
android:defaultValue="0"
android:entries="@array/notif_default_expansion_entries"
android:entryValues="@array/notif_default_expansion_values"
android:key="notificationDefaultExpansion"
android:summary="%s"
android:title="@string/notif_default_expansion_title"
app:iconSpaceReserved="false" />

</PreferenceCategory>

Expand Down

0 comments on commit 52eaeac

Please sign in to comment.