Skip to content

Commit

Permalink
Apply UiStyle Theme after SystemUI Restart
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed Jun 16, 2024
1 parent b0a037d commit 604d1a8
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ interface IRootProviderProxy {
*/
String[] runCommand(String command);
void extractSubject(in Bitmap input, String resultPath);
void applyTheme(in String theme);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.dhd.oxygencustomizer.ui.fragments.uistyle;

import static it.dhd.oxygencustomizer.utils.Dynamic.TOTAL_ANDROID_THEMES;
import static it.dhd.oxygencustomizer.utils.PreferenceHelper.getModulePrefs;
import static it.dhd.oxygencustomizer.utils.overlay.OverlayUtil.getStringFromOverlay;

import android.os.Bundle;
Expand All @@ -18,6 +19,8 @@
import it.dhd.oxygencustomizer.ui.adapters.ThemeAdapter;
import it.dhd.oxygencustomizer.ui.base.BaseFragment;
import it.dhd.oxygencustomizer.ui.dialogs.LoadingDialog;
import it.dhd.oxygencustomizer.utils.PrefManager;
import it.dhd.oxygencustomizer.utils.Prefs;

public class UiStyle extends BaseFragment {

Expand Down Expand Up @@ -45,6 +48,9 @@ private ThemeAdapter initThemesItems() {
for (int i = 0; i<TOTAL_ANDROID_THEMES; i++) {
mThemeNames.add(getStringFromOverlay(requireContext(), "OxygenCustomizerComponentTH" + (i+1) + ".overlay", "android_theme_name"));
}
if (getModulePrefs() != null) {
getModulePrefs().edit().putInt("UiStylesThemes", TOTAL_ANDROID_THEMES).apply();
}
return new ThemeAdapter(requireContext(), mThemeNames, loadingDialog, "TH");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package it.dhd.oxygencustomizer.utils.overlay;

import static it.dhd.oxygencustomizer.utils.Dynamic.TOTAL_ANDROID_THEMES;
import static it.dhd.oxygencustomizer.utils.PreferenceHelper.getModulePrefs;

import android.content.Context;
import android.content.om.OverlayInfo;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -51,6 +54,9 @@ static boolean isOverlayInstalled(List<String> enabledOverlays, String pkgName)

public static void enableOverlay(String pkgName) {
Prefs.putBoolean(pkgName, true);
if (getModulePrefs() != null) {
getModulePrefs().edit().putBoolean(pkgName, true).apply();
}
Shell.cmd("cmd overlay enable --user current " + pkgName, "cmd overlay set-priority " + pkgName + " highest").submit();
}

Expand Down Expand Up @@ -83,6 +89,9 @@ public static void enableOverlaysExclusiveInCategory(String... pkgNames) {

public static void disableOverlay(String pkgName) {
Prefs.putBoolean(pkgName, false);
if (getModulePrefs() != null) {
getModulePrefs().edit().putBoolean(pkgName, false).apply();
}
Shell.cmd("cmd overlay disable --user current " + pkgName).submit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import it.dhd.oxygencustomizer.xposed.hooks.systemui.OpUtils;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.PulseViewHook;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.SettingsLibUtilsProvider;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.ThemeEnabler;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.VolumePanel;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.aod.AodClock;
import it.dhd.oxygencustomizer.xposed.hooks.systemui.lockscreen.DepthWallpaper;
Expand Down Expand Up @@ -54,6 +55,9 @@ public static ArrayList<Class<? extends XposedMods>> getMods(String packageName)
}
case SYSTEM_UI -> {
if (!XPLauncher.isChildProcess) {
// Theme Enabler
modPacks.add(ThemeEnabler.class);

// Battery Data Provider
modPacks.add(BatteryDataProvider.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package it.dhd.oxygencustomizer.xposed.hooks.systemui;

import static de.robv.android.xposed.XposedBridge.hookAllMethods;
import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static it.dhd.oxygencustomizer.utils.Constants.Packages.SYSTEM_UI;
import static it.dhd.oxygencustomizer.utils.Dynamic.TOTAL_ANDROID_THEMES;
import static it.dhd.oxygencustomizer.xposed.XPrefs.Xprefs;

import android.content.Context;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import it.dhd.oxygencustomizer.xposed.XPLauncher;
import it.dhd.oxygencustomizer.xposed.XposedMods;

public class ThemeEnabler extends XposedMods {

private static final String listenPackage = SYSTEM_UI;
private int themeNum;

public ThemeEnabler(Context context) {
super(context);
}

@Override
public void updatePrefs(String... Key) {
if (Xprefs == null) return;
log("ThemeEnabler Updating Prefs " + Xprefs.getInt("UiStylesThemes", 0));
for (int i = 0; i<Xprefs.getInt("UiStylesThemes", 0); i++) {
if (Xprefs.getBoolean("OxygenCustomizerComponentTH" + (i+1) + ".overlay", false)) {
themeNum = (i+1);
}
}
}

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
// System UI Got Restarted, Re-Apply Theme
enableTheme();

// Get monet change so we can apply theme
Class<?> ScrimController = findClass("com.android.systemui.statusbar.phone.ScrimController", lpparam.classLoader);
hookAllMethods(ScrimController, "updateThemeColors", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
log("ThemeEnabler ScrimController updateThemeColors");
enableTheme();
}
});

}

private void enableTheme() {
log("ThemeEnabler Enabling Themes " + themeNum);
XPLauncher.enqueueProxyCommand(proxy -> proxy.applyTheme("OxygenCustomizerComponentTH" + themeNum + ".overlay"));
}

@Override
public boolean listensTo(String packageName) {
return listenPackage.equals(packageName);
}
}

0 comments on commit 604d1a8

Please sign in to comment.