monochrome wp
This commit is contained in:
@@ -8,6 +8,8 @@ import static ru.vtosters.lite.ui.wallpapers.WallpapersHooks.requestUpdateWallpa
|
||||
import static ru.vtosters.lite.utils.CacheUtils.deleteCache;
|
||||
import static ru.vtosters.lite.utils.Globals.edit;
|
||||
import static ru.vtosters.lite.utils.Globals.getIdentifier;
|
||||
import static ru.vtosters.lite.utils.Globals.getPreferences;
|
||||
import static ru.vtosters.lite.utils.Preferences.DoNotUseOldIcons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -27,6 +29,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import ru.vtosters.lite.ui.PreferencesUtil;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
|
||||
public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{
|
||||
|
||||
@@ -93,6 +96,14 @@ public class WallpaperMenuFragment extends MaterialPreferenceToolbarFragment{
|
||||
"disabled", "low", "med", "high"
|
||||
});
|
||||
|
||||
PreferencesUtil.addMaterialSwitchPreference(this, "msg_monochrome", "Черно-белый фон", "", null, false, (preference, o) -> {
|
||||
boolean value = (boolean) o;
|
||||
edit().putBoolean("msg_monochrome", value).commit();
|
||||
requestUpdateWallpaper();
|
||||
mWPPreviewPref.redraw();
|
||||
return true;
|
||||
});
|
||||
|
||||
ListPreference blur = (ListPreference) findPreference("msg_blur_radius");
|
||||
ListPreference dim = (ListPreference) findPreference("msg_dim");
|
||||
ListPreference mosaic = (ListPreference) findPreference("msg_mosaic");
|
||||
|
||||
@@ -61,6 +61,10 @@ public class WallpapersHooks{
|
||||
mWallpaper = getMosaic(mWallpaper);
|
||||
}
|
||||
|
||||
if (getPreferences().getBoolean("msg_monochrome", false)) {
|
||||
mWallpaper = getMonochrome(mWallpaper);
|
||||
}
|
||||
|
||||
mUpdateWallpaperRequested = false;
|
||||
}
|
||||
|
||||
@@ -175,6 +179,27 @@ public class WallpapersHooks{
|
||||
return new BitmapDrawable(getResources(), instance);
|
||||
}
|
||||
|
||||
public static Drawable getMonochrome(Drawable orig){
|
||||
if (orig == null) return null;
|
||||
if (!(orig instanceof BitmapDrawable)) return orig;
|
||||
Bitmap instance = ((BitmapDrawable) orig).getBitmap().copy(Bitmap.Config.ARGB_8888, true);
|
||||
|
||||
Bitmap bwBitmap = Bitmap.createBitmap( instance.getWidth(), instance.getHeight(), Bitmap.Config.RGB_565 );
|
||||
float[] hsv = new float[ 3 ];
|
||||
for( int col = 0; col < instance.getWidth(); col++ ) {
|
||||
for( int row = 0; row < instance.getHeight(); row++ ) {
|
||||
Color.colorToHSV( instance.getPixel( col, row ), hsv );
|
||||
if( hsv[ 2 ] > 0.5f ) {
|
||||
bwBitmap.setPixel( col, row, 0xffffffff );
|
||||
} else {
|
||||
bwBitmap.setPixel( col, row, 0xff000000 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new BitmapDrawable(getResources(), bwBitmap);
|
||||
}
|
||||
|
||||
private static Bitmap darken(Bitmap bm){
|
||||
Canvas canvas = new Canvas(bm);
|
||||
Paint p = new Paint(Color.RED);
|
||||
|
||||
Reference in New Issue
Block a user