diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-07-17 01:51:30 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-07-17 01:51:30 +0000 |
commit | cf63ccaad1e8176b78c65c7857704ef765a68b51 (patch) | |
tree | e5ab94688a6f28406a01cf69b18bf8d53a5d0d0a /app/src/main/java/ml/docilealligator | |
parent | e10fc4c96ea9344fbcce80e47c3cffbd0ac437a3 (diff) | |
download | infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar.gz infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar.bz2 infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar.lz infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar.xz infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.tar.zst infinity-for-reddit-cf63ccaad1e8176b78c65c7857704ef765a68b51.zip |
Generate a better theme in Material You.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java index 6c93b42b..520719b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/MaterialYouUtils.java @@ -55,12 +55,12 @@ public class MaterialYouUtils { CustomTheme darkTheme = CustomThemeWrapper.getIndigoDark(context); CustomTheme amoledTheme = CustomThemeWrapper.getIndigoAmoled(context); - int colorPrimaryInt = shiftColorTo255(wallpaperColors.getPrimaryColor().toArgb(), 0.4); - int colorPrimaryDarkInt = shiftColorTo0(colorPrimaryInt, 0.3); - int backgroundColor = shiftColorTo255(colorPrimaryInt, 0.6); - int cardViewBackgroundColor = shiftColorTo255(colorPrimaryInt, 0.9); + int colorPrimaryInt = lightenColor(wallpaperColors.getPrimaryColor().toArgb(), 0.4); + int colorPrimaryDarkInt = darkenColor(colorPrimaryInt, 0.3); + int backgroundColor = lightenColor(colorPrimaryInt, 0.2); + int cardViewBackgroundColor = lightenColor(colorPrimaryInt, 0.6); Color colorAccent = wallpaperColors.getSecondaryColor(); - int colorAccentInt = shiftColorTo255(colorAccent == null ? customThemeWrapper.getColorAccent() : colorAccent.toArgb(), 0.4); + int colorAccentInt = lightenColor(colorAccent == null ? customThemeWrapper.getColorAccent() : colorAccent.toArgb(), 0.4); int colorPrimaryAppropriateTextColor = getAppropriateTextColor(colorPrimaryInt); int backgroundColorAppropriateTextColor = getAppropriateTextColor(backgroundColor); @@ -120,18 +120,16 @@ public class MaterialYouUtils { }); } - private static int shiftColorTo255(int color, double ratio) { - int offset = (int) (Math.min(Math.min(255 - Color.red(color), 255 - Color.green(color)), 255 - Color.blue(color)) * ratio); - return Color.argb(Color.alpha(color), Color.red(color) + offset, - Color.green(color) + offset, - Color.blue(color) + offset); + private static int lightenColor(int color, double ratio) { + return Color.argb(Color.alpha(color), (int) (Color.red(color) + (255 - Color.red(color)) * ratio), + (int) (Color.green(color) + (255 - Color.green(color)) * ratio), + (int) (Color.blue(color) + (255 - Color.blue(color)) * ratio)); } - private static int shiftColorTo0(int color, double ratio) { - int offset = (int) (Math.min(Math.min(Color.red(color), Color.green(color)), Color.blue(color)) * ratio); - return Color.argb(Color.alpha(color), Color.red(color) - offset, - Color.green(color) - offset, - Color.blue(color) - offset); + private static int darkenColor(int color, double ratio) { + return Color.argb(Color.alpha(color), (int) (Color.red(color) * (1 - ratio)), + (int) (Color.green(color) * (1 - ratio)), + (int) (Color.blue(color) * (1 - ratio))); } |