mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Remove complicated and unreliable calculation of shading colors.
This commit is contained in:
@@ -134,101 +134,6 @@ public class AndroidUtilities {
|
||||
checkDisplaySize();
|
||||
}
|
||||
|
||||
public static int[] calcDrawableColor(Drawable drawable) {
|
||||
int bitmapColor = 0xff000000;
|
||||
int result[] = new int[2];
|
||||
try {
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
|
||||
if (bitmap != null) {
|
||||
Bitmap b = Bitmaps.createScaledBitmap(bitmap, 1, 1, true);
|
||||
if (b != null) {
|
||||
bitmapColor = b.getPixel(0, 0);
|
||||
b.recycle();
|
||||
}
|
||||
}
|
||||
} else if (drawable instanceof ColorDrawable) {
|
||||
bitmapColor = ((ColorDrawable) drawable).getColor();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e("messenger", e);
|
||||
}
|
||||
|
||||
double[] hsv = rgbToHsv((bitmapColor >> 16) & 0xff, (bitmapColor >> 8) & 0xff, bitmapColor & 0xff);
|
||||
hsv[1] = Math.min(1.0, hsv[1] + 0.05 + 0.1 * (1.0 - hsv[1]));
|
||||
hsv[2] = Math.max(0, hsv[2] * 0.65);
|
||||
int rgb[] = hsvToRgb(hsv[0], hsv[1], hsv[2]);
|
||||
result[0] = Color.argb(0x66, rgb[0], rgb[1], rgb[2]);
|
||||
result[1] = Color.argb(0x88, rgb[0], rgb[1], rgb[2]);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double[] rgbToHsv(int r, int g, int b) {
|
||||
double rf = r / 255.0;
|
||||
double gf = g / 255.0;
|
||||
double bf = b / 255.0;
|
||||
double max = (rf > gf && rf > bf) ? rf : (gf > bf) ? gf : bf;
|
||||
double min = (rf < gf && rf < bf) ? rf : (gf < bf) ? gf : bf;
|
||||
double h, s;
|
||||
double d = max - min;
|
||||
s = max == 0 ? 0 : d / max;
|
||||
if (max == min) {
|
||||
h = 0;
|
||||
} else {
|
||||
if (rf > gf && rf > bf) {
|
||||
h = (gf - bf) / d + (gf < bf ? 6 : 0);
|
||||
} else if (gf > bf) {
|
||||
h = (bf - rf) / d + 2;
|
||||
} else {
|
||||
h = (rf - gf) / d + 4;
|
||||
}
|
||||
h /= 6;
|
||||
}
|
||||
return new double[]{h, s, max};
|
||||
}
|
||||
|
||||
private static int[] hsvToRgb(double h, double s, double v) {
|
||||
double r = 0, g = 0, b = 0;
|
||||
double i = (int) Math.floor(h * 6);
|
||||
double f = h * 6 - i;
|
||||
double p = v * (1 - s);
|
||||
double q = v * (1 - f * s);
|
||||
double t = v * (1 - (1 - f) * s);
|
||||
switch ((int) i % 6) {
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
case 4:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
case 5:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
return new int[]{(int) (r * 255), (int) (g * 255), (int) (b * 255)};
|
||||
}
|
||||
|
||||
public static void requestAdjustResize(Activity activity, int classGuid) {
|
||||
if (activity == null || isTablet()) {
|
||||
return;
|
||||
|
||||
@@ -53,9 +53,6 @@ public class ApplicationLoader extends Application {
|
||||
private static boolean isCustomTheme;
|
||||
private static final Object sync = new Object();
|
||||
|
||||
private static int serviceMessageColor;
|
||||
private static int serviceSelectedMessageColor;
|
||||
|
||||
public static volatile Context applicationContext;
|
||||
public static volatile Handler applicationHandler;
|
||||
private static volatile boolean applicationInited = false;
|
||||
@@ -73,25 +70,11 @@ public class ApplicationLoader extends Application {
|
||||
|
||||
public static void reloadWallpaper() {
|
||||
cachedWallpaper = null;
|
||||
serviceMessageColor = 0;
|
||||
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE).edit().remove("serviceMessageColor").commit();
|
||||
loadWallpaper();
|
||||
}
|
||||
|
||||
private static void calcBackgroundColor() {
|
||||
int result[] = AndroidUtilities.calcDrawableColor(cachedWallpaper);
|
||||
serviceMessageColor = result[0];
|
||||
serviceSelectedMessageColor = result[1];
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
preferences.edit().putInt("serviceMessageColor", serviceMessageColor).putInt("serviceSelectedMessageColor", serviceSelectedMessageColor).commit();
|
||||
}
|
||||
|
||||
public static int getServiceMessageColor() {
|
||||
return serviceMessageColor;
|
||||
}
|
||||
|
||||
public static int getServiceSelectedMessageColor() {
|
||||
return serviceSelectedMessageColor;
|
||||
return 0xAA777777; // this color is used as a background for date headlines, empty chat hints and in the drawer
|
||||
}
|
||||
|
||||
public static void loadWallpaper() {
|
||||
@@ -107,8 +90,6 @@ public class ApplicationLoader extends Application {
|
||||
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
||||
int selectedBackground = preferences.getInt("selectedBackground", 1000001);
|
||||
selectedColor = preferences.getInt("selectedColor", 0);
|
||||
serviceMessageColor = preferences.getInt("serviceMessageColor", 0);
|
||||
serviceSelectedMessageColor = preferences.getInt("serviceSelectedMessageColor", 0);
|
||||
if (selectedColor == 0) {
|
||||
if (selectedBackground == 1000001) {
|
||||
cachedWallpaper = applicationContext.getResources().getDrawable(R.drawable.background_hd);
|
||||
@@ -133,9 +114,6 @@ public class ApplicationLoader extends Application {
|
||||
}
|
||||
cachedWallpaper = new ColorDrawable(selectedColor);
|
||||
}
|
||||
if (serviceMessageColor == 0) {
|
||||
calcBackgroundColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -185,16 +185,12 @@ public class Theme {
|
||||
|
||||
public static Drawable shareIconDrawable;
|
||||
|
||||
public static Drawable geoInDrawable;
|
||||
public static Drawable geoOutDrawable;
|
||||
|
||||
public static Drawable[] contactDrawable = new Drawable[2];
|
||||
public static Drawable[][] fileStatesDrawable = new Drawable[10][2];
|
||||
public static Drawable[][] photoStatesDrawables = new Drawable[13][2];
|
||||
public static Drawable[] docMenuDrawable = new Drawable[4];
|
||||
|
||||
public static PorterDuffColorFilter colorFilter;
|
||||
public static PorterDuffColorFilter colorPressedFilter;
|
||||
private static int currentColor;
|
||||
|
||||
public static Drawable attachButtonDrawables[] = new Drawable[8];
|
||||
@@ -290,7 +286,6 @@ public class Theme {
|
||||
int color = ApplicationLoader.getServiceMessageColor();
|
||||
if (currentColor != color) {
|
||||
colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY);
|
||||
colorPressedFilter = new PorterDuffColorFilter(ApplicationLoader.getServiceSelectedMessageColor(), PorterDuff.Mode.MULTIPLY);
|
||||
currentColor = color;
|
||||
for (int a = 0; a < 4; a++) {
|
||||
cornerOuter[a].setColorFilter(colorFilter);
|
||||
|
||||
@@ -79,8 +79,6 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
|
||||
private ListAdapter listAdapter;
|
||||
private ImageView backgroundImage;
|
||||
private FrameLayout progressView;
|
||||
private View progressViewBackground;
|
||||
private int selectedBackground;
|
||||
private int selectedColor;
|
||||
private ArrayList<TLRPC.WallPaper> wallPapers = new ArrayList<>();
|
||||
@@ -199,24 +197,6 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
}
|
||||
});
|
||||
|
||||
progressView = new FrameLayout(context);
|
||||
progressView.setVisibility(View.INVISIBLE);
|
||||
frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));
|
||||
|
||||
progressViewBackground = new View(context);
|
||||
progressViewBackground.setBackgroundResource(R.drawable.system_loader);
|
||||
progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
|
||||
|
||||
ProgressBar progressBar = new ProgressBar(context);
|
||||
try {
|
||||
progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation));
|
||||
} catch (Exception e) {
|
||||
//don't promt
|
||||
}
|
||||
progressBar.setIndeterminate(true);
|
||||
AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
|
||||
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
|
||||
|
||||
RecyclerListView listView = new RecyclerListView(context);
|
||||
listView.setClipToPadding(false);
|
||||
listView.setTag(8);
|
||||
@@ -357,12 +337,9 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
|
||||
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
||||
if (!f.exists()) {
|
||||
int result[] = AndroidUtilities.calcDrawableColor(backgroundImage.getDrawable());
|
||||
progressViewBackground.getBackground().setColorFilter(new PorterDuffColorFilter(result[0], PorterDuff.Mode.MULTIPLY));
|
||||
loadingFile = fileName;
|
||||
loadingFileObject = f;
|
||||
doneButton.setEnabled(false);
|
||||
progressView.setVisibility(View.VISIBLE);
|
||||
loadingSize = size;
|
||||
selectedColor = 0;
|
||||
FileLoader.getInstance().loadFile(size, null, true);
|
||||
@@ -382,7 +359,6 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
backgroundImage.setBackgroundColor(0);
|
||||
selectedColor = 0;
|
||||
doneButton.setEnabled(true);
|
||||
progressView.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
if (loadingFile != null) {
|
||||
@@ -418,7 +394,6 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
loadingFile = null;
|
||||
loadingSize = null;
|
||||
doneButton.setEnabled(true);
|
||||
progressView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,14 +406,12 @@ public class WallpapersActivity extends BaseFragment implements NotificationCent
|
||||
loadingFileObject = null;
|
||||
loadingFile = null;
|
||||
loadingSize = null;
|
||||
progressView.setVisibility(View.GONE);
|
||||
doneButton.setEnabled(false);
|
||||
}
|
||||
} else if (id == NotificationCenter.FileDidLoaded) {
|
||||
String location = (String) args[0];
|
||||
if (loadingFile != null && loadingFile.equals(location)) {
|
||||
backgroundImage.setImageURI(Uri.fromFile(loadingFileObject));
|
||||
progressView.setVisibility(View.GONE);
|
||||
backgroundImage.setBackgroundColor(0);
|
||||
doneButton.setEnabled(true);
|
||||
loadingFileObject = null;
|
||||
|
||||
Reference in New Issue
Block a user