Skip to content

Commit

Permalink
Xposed: Reload resources without restarting SystemUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 21, 2023
1 parent 1e459b9 commit 76d9da9
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 76d9da9

Please sign in to comment.