Skip to content

Commit

Permalink
fix: volume dialog blur
Browse files Browse the repository at this point in the history
  • Loading branch information
MonwF committed Jan 1, 2023
1 parent 1455a66 commit a304c4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public void handleLoadPackage(final LoadPackageParam lpparam) {

if (mPrefs.getInt("system_qsgridcolumns", 2) > 2 || mPrefs.getInt("system_qsgridrows", 1) > 1) System.QSGridRes();
if (mPrefs.getInt("system_qqsgridcolumns", 2) > 2) System.QQSGridRes();
if (mPrefs.getInt("system_volumeblur_collapsed", 0) > 0 || mPrefs.getInt("system_volumeblur_expanded", 0) > 0) System.BlurVolumeDialogBackgroundRes();
if (mPrefs.getBoolean("system_notifrowmenu")) System.NotificationRowMenuRes();
if (mPrefs.getBoolean("system_volumetimer")) System.VolumeTimerValuesRes(lpparam);
if (mPrefs.getBoolean("system_snoozedmanager")) System.MoreSnoozeOptionsRes();
Expand Down
47 changes: 20 additions & 27 deletions app/src/main/java/name/mikanoshi/customiuizer/mods/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -5719,45 +5719,43 @@ protected void after(MethodHookParam param) throws Throwable {
}
}

private static Dialog mDialog = null;
private static float blurCollapsed = 0.0f;
private static float blurExpanded = 0.0f;

@SuppressWarnings("deprecation")
private static void updateBlurRatio(Object thisObject) {
if (mDialog == null || mDialog.getWindow() == null) return;
View rootView = mDialog.getWindow().getDecorView();
if (rootView.isAttachedToWindow() && rootView.getLayoutParams() instanceof WindowManager.LayoutParams) {
WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams)rootView.getLayoutParams();
layoutParams.flags |= WindowManager.LayoutParams.FLAG_BLUR_BEHIND;
boolean isExpanded = (boolean)XposedHelpers.callMethod(thisObject, "isExpanded");
XposedHelpers.setFloatField(layoutParams, "blurRatio", isExpanded ? blurExpanded : blurCollapsed);
mDialog.getWindow().getWindowManager().updateViewLayout(rootView, layoutParams);
}
}

public static void BlurVolumeDialogBackgroundHook(ClassLoader classLoader) {
Helpers.hookAllMethods("com.android.systemui.miui.volume.MiuiVolumeDialogView", classLoader, "onAttachedToWindow", new MethodHook() {
MainModule.resHooks.setObjectReplacement("miui.systemui.plugin", "fraction", "miui_volume_dim_behind_collapsed", 0f);
MainModule.resHooks.setObjectReplacement("miui.systemui.plugin", "fraction", "miui_volume_dim_behind_expanded", 0f);

Helpers.findAndHookMethod("com.android.systemui.miui.volume.MiuiVolumeDialogImpl", classLoader, "updateDialogWindowH", boolean.class, new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
updateBlurRatio(param.thisObject);
boolean mExpanded = XposedHelpers.getBooleanField(param.thisObject, "mExpanded");
float blurRatio = blurCollapsed;
boolean isVisible = (boolean) param.args[0];
if (mExpanded && !isVisible) {
blurRatio = blurExpanded;
}
if (!mExpanded) {
Window mWindow = (Window) XposedHelpers.getObjectField(param.thisObject, "mWindow");
mWindow.clearFlags(8);
}
XposedHelpers.callMethod(param.thisObject, "startBlurAnim", 0f, blurRatio, 0);
}
});

Helpers.hookAllMethods("com.android.systemui.miui.volume.MiuiVolumeDialogView", classLoader, "onExpandStateUpdated", new MethodHook() {
Helpers.findAndHookMethod("com.android.systemui.miui.volume.MiuiVolumeDialogImpl", classLoader, "showH", int.class, new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
updateBlurRatio(param.thisObject);
Window mWindow = (Window) XposedHelpers.getObjectField(param.thisObject, "mWindow");
mWindow.clearFlags(8);
XposedHelpers.callMethod(param.thisObject, "startBlurAnim", 0f, blurCollapsed, 0);
}
});

Helpers.hookAllMethods("com.android.systemui.miui.volume.MiuiVolumeDialogImpl", classLoader, "initDialog", new MethodHook() {
@Override
protected void after(MethodHookParam param) throws Throwable {
protected void before(MethodHookParam param) throws Throwable {
Context mContext = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
Handler mHandler = new Handler(mContext.getMainLooper());

mDialog = (Dialog)XposedHelpers.getObjectField(param.thisObject, "mDialog");
blurCollapsed = MainModule.mPrefs.getInt("system_volumeblur_collapsed", 0) / 100f;
blurExpanded = MainModule.mPrefs.getInt("system_volumeblur_expanded", 0) / 100f;
new Helpers.SharedPrefObserver(mContext, mHandler) {
Expand All @@ -5776,11 +5774,6 @@ public void onChange(Uri uri) {
});
}

public static void BlurVolumeDialogBackgroundRes() {
MainModule.resHooks.setObjectReplacement("miui.systemui.plugin", "fraction", "miui_volume_dim_behind_collapsed", 0.0f);
MainModule.resHooks.setObjectReplacement("miui.systemui.plugin", "fraction", "miui_volume_dim_behind_expanded", 0.0f);
}

public static void RemoveSecureHook(LoadPackageParam lpparam) {
Helpers.findAndHookMethod("com.android.server.wm.WindowState", lpparam.classLoader, "isSecureLocked", XC_MethodReplacement.returnConstant(false));
}
Expand Down

0 comments on commit a304c4b

Please sign in to comment.