From 5e7eb5112794d1891f5afab1b8bcdff6396d81de Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Tue, 12 Jul 2022 13:46:04 +0300 Subject: [PATCH] mosaic effect --- .../ui/wallpapers/WallpaperMenuFragment.java | 17 ++++++ .../lite/ui/wallpapers/WallpapersHooks.java | 53 ++++++++++++++++--- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpaperMenuFragment.java b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpaperMenuFragment.java index 4cc4ad1f4..9a443647d 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpaperMenuFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpaperMenuFragment.java @@ -1,5 +1,6 @@ package ru.vtosters.lite.ui.wallpapers; import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getDimmingSummary; +import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getMosaicSummary; import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getRadiusSummary; import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.getWallpaperFile; import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.removeWallpaper; @@ -86,11 +87,19 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{ "off", "dim_black", "dim_white" }); + PreferencesUtil.addListPreference(this, "msg_mosaic", "disabled", "Мозаика", new CharSequence[] { + "Отключено", "Низкое", "Среднее", "Высокое" + }, new String[] { + "disabled", "low", "med", "high" + }); + ListPreference blur = (ListPreference) findPreference("msg_blur_radius"); ListPreference dim = (ListPreference) findPreference("msg_dim"); + ListPreference mosaic = (ListPreference) findPreference("msg_mosaic"); blur.setSummary(getRadiusSummary()); dim.setSummary(getDimmingSummary()); + mosaic.setSummary(getMosaicSummary()); blur.setOnPreferenceChangeListener((preference, o) -> { edit().putString("msg_blur_radius", (String) o).apply(); @@ -107,6 +116,14 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{ mWPPreviewPref.redraw(); return true; }); + + mosaic.setOnPreferenceChangeListener((preference, o) -> { + edit().putString("msg_mosaic", (String) o).apply(); + preference.setSummary(getMosaicSummary()); + requestUpdateWallpaper(); + mWPPreviewPref.redraw(); + return true; + }); } @Override diff --git a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java index 357098824..fc6dbfad7 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java +++ b/app/src/main/java/ru/vtosters/lite/ui/wallpapers/WallpapersHooks.java @@ -57,6 +57,10 @@ public class WallpapersHooks{ mWallpaper = getDimmed(mWallpaper); } + if (!getPreferences().getString("msg_mosaic", "disabled").equals("disabled")) { + mWallpaper = getMosaic(mWallpaper); + } + mUpdateWallpaperRequested = false; } @@ -82,28 +86,40 @@ public class WallpapersHooks{ public static String getRadiusSummary(){ String radius = getPreferences().getString("msg_blur_radius", "disabled"); switch(radius) { - case "disabled": - return "Отключено"; case "low": return "Низкое"; case "med": return "Среднее"; - default: + case "high": return "Высокое"; + default: + return "Отключено"; } } public static String getDimmingSummary(){ String radius = getPreferences().getString("msg_dim", "disabled"); switch(radius) { - case "off": - return "Отключено"; case "dim_black": return "Затемнить"; case "dim_white": return "Осветлить"; default: - return "OwO"; + return "Отключено"; + } + } + + public static String getMosaicSummary(){ + String radius = getPreferences().getString("msg_mosaic", "disabled"); + switch(radius) { + case "low": + return "Низкое"; + case "med": + return "Среднее"; + case "high": + return "Высокое"; + default: + return "Отключено"; } } @@ -120,6 +136,31 @@ public class WallpapersHooks{ } } + public static Drawable getMosaic(Drawable orig){ + int scale = 100; + + if (orig == null) return null; + if (!(orig instanceof BitmapDrawable)) return orig; + Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true); + String radius = getPreferences().getString("msg_mosaic", "disabled"); + + switch(radius) { + case "high": + scale = 25; + break; + case "med": + scale = 50; + break; + case "low": + scale = 75; + } + + Bitmap temp = Bitmap.createScaledBitmap(instance, scale, scale, false); + Bitmap mosaicBitmap = Bitmap.createScaledBitmap(temp, instance.getWidth(), instance.getHeight(), false); + + return new BitmapDrawable(getResources(), mosaicBitmap); + } + public static Drawable getDimmed(Drawable orig){ if (orig == null) return null; if (!(orig instanceof BitmapDrawable)) return orig;