Skip to content

Commit

Permalink
Depth Wallpaper: Fix issues for A12L
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 26, 2023
1 parent 951aa03 commit 12ff445
Showing 1 changed file with 69 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static com.drdisagree.iconify.config.XPrefs.Xprefs;
import static de.robv.android.xposed.XposedBridge.hookAllMethods;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findClassIfExists;
import static de.robv.android.xposed.XposedHelpers.getObjectField;

import android.annotation.SuppressLint;
Expand All @@ -16,6 +17,8 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -91,10 +94,8 @@ 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
*/
// 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));

Expand Down Expand Up @@ -133,13 +134,16 @@ protected void afterHookedMethod(MethodHookParam param) {
mDepthWallpaperLayout.addView(mDepthWallpaperForeground, -1);

// Fix the bottom shortcuts pushing the wallpaper
ImageView startButton = view.findViewById(mContext.getResources().getIdentifier("start_button", "id", mContext.getPackageName()));
ImageView endButton = view.findViewById(mContext.getResources().getIdentifier("end_button", "id", mContext.getPackageName()));
int offset = mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("keyguard_affordance_fixed_height", "dimen", mContext.getPackageName()))
+ mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("keyguard_affordance_horizontal_offset", "dimen", mContext.getPackageName()));

startButton.getViewTreeObserver().addOnGlobalLayoutListener(() -> ((ViewGroup.MarginLayoutParams) mIndicationTextView.getLayoutParams()).setMarginStart(startButton.getVisibility() == View.VISIBLE ? offset : 0));
endButton.getViewTreeObserver().addOnGlobalLayoutListener(() -> ((ViewGroup.MarginLayoutParams) mIndicationTextView.getLayoutParams()).setMarginEnd(endButton.getVisibility() == View.VISIBLE ? offset : 0));
try {
ImageView startButton = view.findViewById(mContext.getResources().getIdentifier("start_button", "id", mContext.getPackageName()));
ImageView endButton = view.findViewById(mContext.getResources().getIdentifier("end_button", "id", mContext.getPackageName()));
int offset = mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("keyguard_affordance_fixed_height", "dimen", mContext.getPackageName()))
+ mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("keyguard_affordance_horizontal_offset", "dimen", mContext.getPackageName()));

startButton.getViewTreeObserver().addOnGlobalLayoutListener(() -> ((ViewGroup.MarginLayoutParams) mIndicationTextView.getLayoutParams()).setMarginStart(startButton.getVisibility() == View.VISIBLE ? offset : 0));
endButton.getViewTreeObserver().addOnGlobalLayoutListener(() -> ((ViewGroup.MarginLayoutParams) mIndicationTextView.getLayoutParams()).setMarginEnd(endButton.getVisibility() == View.VISIBLE ? offset : 0));
} catch (Throwable ignored) {
}

updateWallpaper();
}
Expand All @@ -152,7 +156,9 @@ protected void afterHookedMethod(MethodHookParam param) {
}
});

Class<?> NotificationPanelViewControllerClass = findClass(SYSTEMUI_PACKAGE + ".shade.NotificationPanelViewController", lpparam.classLoader);
Class<?> NotificationPanelViewControllerClass = findClassIfExists(SYSTEMUI_PACKAGE + ".shade.NotificationPanelViewController", lpparam.classLoader);
if (NotificationPanelViewControllerClass == null)
NotificationPanelViewControllerClass = findClass(SYSTEMUI_PACKAGE + ".statusbar.phone.NotificationPanelViewController", lpparam.classLoader);

hookAllMethods(NotificationPanelViewControllerClass, "onFinishInflate", new XC_MethodHook() {
@Override
Expand All @@ -170,33 +176,39 @@ protected void afterHookedMethod(MethodHookParam param) {
XC_MethodHook noKeyguardIndicationPadding = new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
int resId = mContext.getResources().getIdentifier("keyguard_indication_area_padding", "dimen", mContext.getPackageName());
if (showDepthWallpaper) {
if (Build.VERSION.SDK_INT >= 33) {
try {
int resId = mContext.getResources().getIdentifier("keyguard_indication_area_padding", "dimen", mContext.getPackageName());
if (param.args[0].equals(resId)) {
param.setResult(0);
}
} catch (Throwable ignored) {
}
} else {
// These resources are only available on Android 12L and below
try {
int resId = mContext.getResources().getIdentifier("keyguard_indication_margin_bottom", "dimen", mContext.getPackageName());
if (param.args[0].equals(resId)) {
param.setResult(0);
}
} catch (Throwable ignored) {
}

if (showDepthWallpaper && param.args[0].equals(resId)) {
param.setResult(0);
try {
int resId = mContext.getResources().getIdentifier("keyguard_indication_margin_bottom_fingerprint_in_display", "dimen", mContext.getPackageName());
if (param.args[0].equals(resId)) {
param.setResult(0);
}
} catch (Throwable ignored) {
}
}
}
}
};

hookAllMethods(Resources.class, "getDimensionPixelOffset", noKeyguardIndicationPadding);
hookAllMethods(Resources.class, "getDimensionPixelSize", noKeyguardIndicationPadding);

if (Build.VERSION.SDK_INT <= 32) {
// This method is only available on Android 12L and below
hookAllMethods(KeyguardBottomAreaViewClass, "updateIndicationAreaPadding", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) {
if (!showDepthWallpaper) return;

View view = (View) param.thisObject;
ViewGroup mIndicationArea = view.findViewById(mContext.getResources().getIdentifier("keyguard_indication_area", "id", mContext.getPackageName()));

ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) mIndicationArea.getLayoutParams();
mlp.bottomMargin = 0;
mIndicationArea.setLayoutParams(mlp);
}
});
}
}

private void updateWallpaper() {
Expand All @@ -213,36 +225,38 @@ private void updateWallpaper() {
File Android = new File(Environment.getExternalStorageDirectory() + "/Android");

if (Android.isDirectory()) {
try {
ImageDecoder.Source backgroundImg = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/depth_wallpaper_bg.png"));
ImageDecoder.Source foregroundImg = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/depth_wallpaper_fg.png"));
new Handler(Looper.getMainLooper()).post(() -> {
try {
ImageDecoder.Source backgroundImg = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/depth_wallpaper_bg.png"));
ImageDecoder.Source foregroundImg = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/depth_wallpaper_fg.png"));

Drawable backgroundDrawable = ImageDecoder.decodeDrawable(backgroundImg);
Drawable foregroundDrawable = ImageDecoder.decodeDrawable(foregroundImg);
Drawable backgroundDrawable = ImageDecoder.decodeDrawable(backgroundImg);
Drawable foregroundDrawable = ImageDecoder.decodeDrawable(foregroundImg);

mDepthWallpaperBackground.setImageDrawable(backgroundDrawable);
mDepthWallpaperBackground.setClipToOutline(true);
mDepthWallpaperBackground.setScaleType(ImageView.ScaleType.CENTER_CROP);
mDepthWallpaperBackground.setImageDrawable(backgroundDrawable);
mDepthWallpaperBackground.setClipToOutline(true);
mDepthWallpaperBackground.setScaleType(ImageView.ScaleType.CENTER_CROP);

boolean zoomWallpaper = !Xprefs.getBoolean(UNZOOM_DEPTH_WALLPAPER, false);
boolean zoomWallpaper = !Xprefs.getBoolean(UNZOOM_DEPTH_WALLPAPER, false);

if (zoomWallpaper) {
mDepthWallpaperBackground.setScaleX(1.1f);
mDepthWallpaperBackground.setScaleY(1.1f);
}
if (zoomWallpaper) {
mDepthWallpaperBackground.setScaleX(1.1f);
mDepthWallpaperBackground.setScaleY(1.1f);
}

mDepthWallpaperForeground.setImageDrawable(foregroundDrawable);
mDepthWallpaperForeground.setClipToOutline(true);
mDepthWallpaperForeground.setScaleType(ImageView.ScaleType.CENTER_CROP);
mDepthWallpaperForeground.setImageDrawable(foregroundDrawable);
mDepthWallpaperForeground.setClipToOutline(true);
mDepthWallpaperForeground.setScaleType(ImageView.ScaleType.CENTER_CROP);

if (zoomWallpaper) {
mDepthWallpaperForeground.setScaleX(1.1f);
mDepthWallpaperForeground.setScaleY(1.1f);
}
if (zoomWallpaper) {
mDepthWallpaperForeground.setScaleX(1.1f);
mDepthWallpaperForeground.setScaleY(1.1f);
}

mDepthWallpaperLayout.setVisibility(View.VISIBLE);
} catch (Throwable ignored) {
}
mDepthWallpaperLayout.setVisibility(View.VISIBLE);
} catch (Throwable ignored) {
}
});

executor.shutdown();
executor.shutdownNow();
Expand Down

0 comments on commit 12ff445

Please sign in to comment.