Skip to content

Commit

Permalink
fix: Simplify color utils
Browse files Browse the repository at this point in the history
  • Loading branch information
axel358 committed Oct 9, 2023
1 parent 0976ef5 commit 29a5729
Showing 1 changed file with 23 additions and 43 deletions.
66 changes: 23 additions & 43 deletions app/src/main/java/cu/axel/smartdock/utils/ColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ArrayList<String> getWallpaperColors(Context context) {
*/

if (DeviceUtils.hasStoragePermission(context) && Build.VERSION.SDK_INT < 33) {
if (DeviceUtils.hasStoragePermission(context)) {

WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
//noinspection all
Expand All @@ -40,29 +40,11 @@ public static ArrayList<String> getWallpaperColors(Context context) {
wallpaperDrawable.invalidateSelf();
Bitmap wallpaperBitmap = drawableToBitmap(wallpaperDrawable);

int color1 = wallpaperBitmap.getPixel(wallpaperBitmap.getWidth() / 4, wallpaperBitmap.getHeight() / 4);
int color2 = wallpaperBitmap.getPixel(wallpaperBitmap.getWidth() - wallpaperBitmap.getWidth() / 4,
wallpaperBitmap.getHeight() / 4);
int color3 = wallpaperBitmap.getPixel(wallpaperBitmap.getWidth() / 2,
wallpaperBitmap.getHeight() - wallpaperBitmap.getHeight() / 4);

wallpaperColors.add(toHexColor(manipulateColor(color1, 1.5f)));
wallpaperColors.add(toHexColor(manipulateColor(color1, 1.2f)));
wallpaperColors.add(toHexColor(color1));
wallpaperColors.add(toHexColor(manipulateColor(color1, .8f)));
wallpaperColors.add(toHexColor(manipulateColor(color1, .5f)));

wallpaperColors.add(toHexColor(manipulateColor(color2, 1.5f)));
wallpaperColors.add(toHexColor(manipulateColor(color2, 1.2f)));
wallpaperColors.add(toHexColor(color2));
wallpaperColors.add(toHexColor(manipulateColor(color2, .8f)));
wallpaperColors.add(toHexColor(manipulateColor(color2, .5f)));

wallpaperColors.add(toHexColor(manipulateColor(color3, 1.5f)));
wallpaperColors.add(toHexColor(manipulateColor(color3, 1.2f)));
wallpaperColors.add(toHexColor(color3));
wallpaperColors.add(toHexColor(manipulateColor(color3, .8f)));
wallpaperColors.add(toHexColor(manipulateColor(color3, .5f)));
int color = wallpaperBitmap.getPixel(wallpaperBitmap.getWidth() / 4, wallpaperBitmap.getHeight() / 4);

wallpaperColors.add(toHexColor(color));
wallpaperColors.add(toHexColor(manipulateColor(color, .8f)));
wallpaperColors.add(toHexColor(manipulateColor(color, .5f)));

}

Expand Down Expand Up @@ -137,45 +119,43 @@ public static void applyColor(View view, int color) {

public static int[] getMainColors(SharedPreferences sp, Context context) {
String theme = sp.getString("theme", "dark");
int color = 0;
int mainColor = 0;
int secondaryColor = 0;
int alpha = 255;
int color2 = 0;

int[] colors = new int[5];
switch (theme) {
case "dark":
color = Color.parseColor("#212121");
color2 = ColorUtils.manipulateColor(color, 1.35f);
mainColor = Color.parseColor("#212121");
secondaryColor = ColorUtils.manipulateColor(mainColor, 1.35f);
break;
case "black":
color = Color.parseColor("#060606");
color2 = ColorUtils.manipulateColor(color, 2.2f);
mainColor = Color.parseColor("#060606");
secondaryColor = ColorUtils.manipulateColor(mainColor, 2.2f);
break;
case "transparent":
color = Color.parseColor("#050505");
color2 = ColorUtils.manipulateColor(color, 2f);
mainColor = Color.parseColor("#050505");
secondaryColor = ColorUtils.manipulateColor(mainColor, 2f);
alpha = 225;
break;
case "material_u":
if (DynamicColors.isDynamicColorAvailable()) {
int surfaceColor = getThemeColors(context, true)[1];
color = ColorUtils.manipulateColor(surfaceColor, 0.9f);
color2 = ColorUtils.manipulateColor(surfaceColor, 1.2f);
mainColor = ColorUtils.manipulateColor(surfaceColor, 0.9f);
secondaryColor = ColorUtils.manipulateColor(surfaceColor, 1.2f);
} else {
color = Color.parseColor(getWallpaperColors(context).get(4));
color2 = Color.parseColor(getWallpaperColors(context).get(3));
mainColor = Color.parseColor(getWallpaperColors(context).get(2));
secondaryColor = Color.parseColor(getWallpaperColors(context).get(1));
}
break;
case "custom":
color = Color.parseColor(sp.getString("theme_main_color", "#212121"));
color2 = ColorUtils.manipulateColor(color, 1.2f);
mainColor = Color.parseColor(sp.getString("theme_main_color", "#212121"));
secondaryColor = ColorUtils.manipulateColor(mainColor, 1.2f);
alpha = sp.getInt("theme_main_alpha", 255);
}
//main color
colors[0] = color;
//main color alpha
colors[0] = mainColor;
colors[1] = alpha;
//secondary color
colors[2] = color2;
colors[2] = secondaryColor;
if (alpha < 255)
alpha -= alpha * 0.60;
//secondary color alpha
Expand Down

0 comments on commit 29a5729

Please sign in to comment.