mosaic effect
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user