From 76d9da98d8c23b485e46a03990ecd578f7ed9332 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Thu, 21 Sep 2023 19:55:16 +0600 Subject: [PATCH] Xposed: Reload resources without restarting SystemUI --- .../iconify/xposed/mods/DepthWallpaper.java | 54 ++++++++++++------- .../iconify/xposed/mods/HeaderClock.java | 19 +++++++ .../iconify/xposed/mods/HeaderImage.java | 49 +++++++++++------ .../iconify/xposed/mods/LockscreenClock.java | 19 +++++++ 4 files changed, 106 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java index 0e6e061df..076a9da12 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/DepthWallpaper.java @@ -25,6 +25,9 @@ import java.io.File; import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.callbacks.XC_LoadPackage; @@ -173,25 +176,38 @@ private void updateWallpaper() { } 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); - - mDepthWallpaperBackground.setImageDrawable(backgroundDrawable); - mDepthWallpaperBackground.setClipToOutline(true); - mDepthWallpaperBackground.setScaleType(ImageView.ScaleType.CENTER_CROP); - mDepthWallpaperBackground.setScaleX(1.1f); - mDepthWallpaperBackground.setScaleY(1.1f); - - mDepthWallpaperForeground.setImageDrawable(foregroundDrawable); - mDepthWallpaperForeground.setClipToOutline(true); - mDepthWallpaperForeground.setScaleType(ImageView.ScaleType.CENTER_CROP); - mDepthWallpaperForeground.setScaleX(1.1f); - mDepthWallpaperForeground.setScaleY(1.1f); - - mDepthWallpaperLayout.setVisibility(View.VISIBLE); + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleAtFixedRate(() -> { + 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")); + + Drawable backgroundDrawable = ImageDecoder.decodeDrawable(backgroundImg); + Drawable foregroundDrawable = ImageDecoder.decodeDrawable(foregroundImg); + + mDepthWallpaperBackground.setImageDrawable(backgroundDrawable); + mDepthWallpaperBackground.setClipToOutline(true); + mDepthWallpaperBackground.setScaleType(ImageView.ScaleType.CENTER_CROP); + mDepthWallpaperBackground.setScaleX(1.1f); + mDepthWallpaperBackground.setScaleY(1.1f); + + mDepthWallpaperForeground.setImageDrawable(foregroundDrawable); + mDepthWallpaperForeground.setClipToOutline(true); + mDepthWallpaperForeground.setScaleType(ImageView.ScaleType.CENTER_CROP); + mDepthWallpaperForeground.setScaleX(1.1f); + mDepthWallpaperForeground.setScaleY(1.1f); + + mDepthWallpaperLayout.setVisibility(View.VISIBLE); + } catch (Throwable ignored) { + } + + executor.shutdown(); + executor.shutdownNow(); + } + }, 0, 5, TimeUnit.SECONDS); } catch (Throwable ignored) { } } diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java index 7b18d9525..d3ed9cc25 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderClock.java @@ -23,6 +23,7 @@ import android.content.Context; import android.content.res.Configuration; import android.os.Build; +import android.os.Environment; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -33,7 +34,11 @@ import com.drdisagree.iconify.xposed.ModPack; import com.drdisagree.iconify.xposed.utils.HeaderClockStyles; +import java.io.File; import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodHook; @@ -173,6 +178,20 @@ protected void afterHookedMethod(MethodHookParam param) { } hideStockClockDate(); + + try { + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleAtFixedRate(() -> { + File Android = new File(Environment.getExternalStorageDirectory() + "/Android"); + + if (Android.isDirectory()) { + updateClockView(); + executor.shutdown(); + executor.shutdownNow(); + } + }, 0, 5, TimeUnit.SECONDS); + } catch (Throwable ignored) { + } } private void hideStockClockDate() { diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderImage.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderImage.java index c80adb88a..dd2832e01 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderImage.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/HeaderImage.java @@ -35,6 +35,9 @@ import java.io.File; import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodHook; @@ -181,24 +184,38 @@ private void addOrRemoveProperty(View view, int property, boolean flag) { private void loadImageOrGif(ImageView iv) { try { - ImageDecoder.Source source = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/header_image.png")); + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleAtFixedRate(() -> { + File Android = new File(Environment.getExternalStorageDirectory() + "/Android"); + + if (Android.isDirectory()) { + try { + ImageDecoder.Source source = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.iconify_files/header_image.png")); + + Drawable drawable = ImageDecoder.decodeDrawable(source); + iv.setImageDrawable(drawable); + iv.setClipToOutline(true); + if (!zoomToFit) { + iv.setScaleType(ImageView.ScaleType.FIT_XY); + } else { + iv.setScaleType(ImageView.ScaleType.CENTER_CROP); + iv.setAdjustViewBounds(false); + iv.setCropToPadding(false); + iv.setMinimumWidth(ViewGroup.LayoutParams.MATCH_PARENT); + addOrRemoveProperty(iv, RelativeLayout.CENTER_IN_PARENT, true); + } + + if (drawable instanceof AnimatedImageDrawable) { + ((AnimatedImageDrawable) drawable).start(); + } + } catch (Throwable ignored) { + } - Drawable drawable = ImageDecoder.decodeDrawable(source); - iv.setImageDrawable(drawable); - iv.setClipToOutline(true); - if (!zoomToFit) { - iv.setScaleType(ImageView.ScaleType.FIT_XY); - } else { - iv.setScaleType(ImageView.ScaleType.CENTER_CROP); - iv.setAdjustViewBounds(false); - iv.setCropToPadding(false); - iv.setMinimumWidth(ViewGroup.LayoutParams.MATCH_PARENT); - addOrRemoveProperty(iv, RelativeLayout.CENTER_IN_PARENT, true); - } + executor.shutdown(); + executor.shutdownNow(); + } + }, 0, 5, TimeUnit.SECONDS); - if (drawable instanceof AnimatedImageDrawable) { - ((AnimatedImageDrawable) drawable).start(); - } } catch (Throwable ignored) { } } diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java b/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java index 5d1ae2e3f..bc6d68b8d 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java +++ b/app/src/main/java/com/drdisagree/iconify/xposed/mods/LockscreenClock.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.view.Gravity; @@ -36,7 +37,11 @@ import com.drdisagree.iconify.xposed.ModPack; import com.drdisagree.iconify.xposed.utils.LockscreenClockStyles; +import java.io.File; import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import de.robv.android.xposed.IXposedHookLoadPackage; import de.robv.android.xposed.XC_MethodHook; @@ -167,6 +172,20 @@ protected void afterHookedMethod(MethodHookParam param) { registerClockUpdater(); } }); + + try { + ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); + executor.scheduleAtFixedRate(() -> { + File Android = new File(Environment.getExternalStorageDirectory() + "/Android"); + + if (Android.isDirectory()) { + updateClockView(); + executor.shutdown(); + executor.shutdownNow(); + } + }, 0, 5, TimeUnit.SECONDS); + } catch (Throwable ignored) { + } } // Broadcast receiver for updating clock