wp disabled

This commit is contained in:
gdlbo
2022-08-27 15:53:56 +03:00
parent 05e118ff31
commit 652f5e665f
3 changed files with 63 additions and 125 deletions
@@ -3,6 +3,7 @@ package ru.vtosters.lite.ui.fragments;
import static ru.vtosters.lite.utils.AndroidUtils.getGlobalContext;
import static ru.vtosters.lite.utils.AndroidUtils.getIdentifier;
import static ru.vtosters.lite.utils.AndroidUtils.getPreferences;
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
import static ru.vtosters.lite.utils.LifecycleUtils.restartApplicationWithTimer;
import static ru.vtosters.lite.utils.Preferences.autoalltranslate;
import static ru.vtosters.lite.utils.Preferences.vkme;
@@ -100,10 +101,11 @@ public class MessagesFragment extends MaterialPreferenceToolbarFragment {
public class openwp implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
Context context = getContext();
Intent a2 = new Navigator(WallpaperMenuFragment.class).b(context);
a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(a2);
// Context context = getContext();
// Intent a2 = new Navigator(WallpaperMenuFragment.class).b(context);
// a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(a2);
sendToast("Обои временно недоступны. Следите за новостями на @vtosters в Telegram");
return true;
}
}
@@ -32,21 +32,9 @@ public class ImageFilters {
if (!(orig instanceof BitmapDrawable)) return orig;
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
if (bm == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
if (instance == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
if (getPreferences().getBoolean("msg_invert", false)) {
instance = applyInvertEffect(instance);
@@ -81,22 +69,8 @@ public class ImageFilters {
if (!(orig instanceof BitmapDrawable)) return orig; // we need only BitmapDrawable
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
if (bm == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
if (instance == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
MediaNative.blurBitmap(instance, radius);
return new BitmapDrawable(getResources(), instance);
} catch (Exception e) {
@@ -112,21 +86,9 @@ public class ImageFilters {
if (!(orig instanceof BitmapDrawable)) return orig;
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
if (bm == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
if (instance == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
String radius = getPreferences().getString("msg_mosaic", "disabled");
@@ -152,21 +114,9 @@ public class ImageFilters {
if (!(orig instanceof BitmapDrawable)) return orig;
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
if (bm == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
if (instance == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
String radius = getPreferences().getString("msg_dim", "disabled");
switch (radius) {
@@ -183,22 +133,8 @@ public class ImageFilters {
if (!(orig instanceof BitmapDrawable)) return orig;
Bitmap bm = ((BitmapDrawable) orig).getBitmap();
if (bm == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
Bitmap instance = bm.copy(Bitmap.Config.ARGB_8888, true);
if (instance == null) {
Log.d("Wallpaper", "bitmap null");
sendToast("Ошибка при установке фильтра. Сбрасываем настройки на по умолчанию");
removeWallpaper();
return orig;
}
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++) {
@@ -31,12 +31,17 @@ import ru.vtosters.lite.utils.ThemesUtils;
public class WallpapersHooks {
private static File mWallpaperFile;
private static File mWallpaperFilteredFile; // TODO
private static Drawable mWallpaper;
private static boolean mUpdateWallpaperRequested = true;
public static File getWallpaperFile() {
return mWallpaperFile == null ? mWallpaperFile = new File(getGlobalContext().getFilesDir(), "wallpaper.png") : mWallpaperFile;
if (mWallpaperFile == null) {
return mWallpaperFile = new File(getGlobalContext().getFilesDir(), "wallpaper.png");
}
return mWallpaperFile;
}
private static Boolean eligibleWallpaperFile(File file) {
@@ -50,67 +55,64 @@ public class WallpapersHooks {
}
public static File compress(File file){
try {
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
o.inSampleSize = 6;
FileInputStream inputStream = new FileInputStream(file);
BitmapFactory.decodeStream(inputStream, null, o);
inputStream.close();
final int REQUIRED_SIZE=200;
int scale = 1;
while(o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
inputStream = new FileInputStream(file);
Bitmap selectedBitmap = BitmapFactory.decodeStream(inputStream, null, o2);
inputStream.close();
File outPutFile = File.createTempFile("wallpaper_temp","image");
outPutFile.deleteOnExit();
FileOutputStream outputStream = new FileOutputStream(outPutFile);
try {
selectedBitmap.compress(Bitmap.CompressFormat.PNG, 85 , outputStream);
} catch (Exception e) {
Log.e("WallpapersCompression", e.getMessage());
}
outputStream.close();
return outPutFile;
} catch (Exception e) {
Log.d("Wallpapers", e.getMessage());
return file;
}
return file;
// try {
// BitmapFactory.Options o = new BitmapFactory.Options();
// o.inJustDecodeBounds = true;
// o.inSampleSize = 6;
//
// FileInputStream inputStream = new FileInputStream(file);
// BitmapFactory.decodeStream(inputStream, null, o);
// inputStream.close();
//
// final int REQUIRED_SIZE=200;
//
// int scale = 1;
// while(o.outWidth / scale / 2 >= REQUIRED_SIZE && o.outHeight / scale / 2 >= REQUIRED_SIZE) {
// scale *= 2;
// }
//
// BitmapFactory.Options o2 = new BitmapFactory.Options();
// o2.inSampleSize = scale;
// inputStream = new FileInputStream(file);
//
// Bitmap selectedBitmap = BitmapFactory.decodeStream(inputStream, null, o2);
// inputStream.close();
//
// File outPutFile = File.createTempFile("wallpaper_temp","image");
//
// FileOutputStream outputStream = new FileOutputStream(outPutFile);
//
// selectedBitmap.compress(Bitmap.CompressFormat.PNG, 85 , outputStream);
//
// outputStream.close();
//
// return outPutFile;
// } catch (Exception e) {
// Log.d("Wallpapers", e.getMessage());
// return file;
// }
}
public static void setBg(View view) {
if (getWallpaper() != null) {
((ImageView) view).setImageDrawable(getWallpaper()); // set picture to background
return;
}
// if (getWallpaper() != null) {
// ((ImageView) view).setImageDrawable(getWallpaper()); // set picture to background
// return;
// }
view.setBackgroundColor(ThemesUtils.getColorFromAttr(im_bg_chat)); // set default bg color
}
public static String getWallpaperUrl() {
var file = getWallpaperFile();
if (file.exists() && eligibleWallpaperFile(file)) {
if (getBoolValue("compresswp", true)) {
return compress(file).getAbsolutePath();
} else {
return file.getAbsolutePath();
}
}
// var file = getWallpaperFile();
//
// if (file.exists() && eligibleWallpaperFile(file)) {
// if (getBoolValue("compresswp", true)) {
// return compress(file).getAbsolutePath();
// } else {
// return file.getAbsolutePath();
// }
// }
return "default";
}
@@ -125,9 +127,7 @@ public class WallpapersHooks {
Drawable drawable = Drawable.createFromPath(getWallpaperUrl());
if (drawable == null || ((BitmapDrawable) drawable).getBitmap() == null) {
Log.d("Wallpaper", "drawable null");
removeWallpaper();
if (drawable == null) {
return null;
}