move some stuff from ThemesUtils
This commit is contained in:
@@ -6,13 +6,12 @@ import android.graphics.Color;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class ColorReferences {
|
||||
public static List<String> accentColors = Arrays.asList(
|
||||
"5692d7", "528bcc", "7aa0cc", "518bcc", "6296d0", "2f68aa", "638ebf", "5181b8", "71aaeb",
|
||||
"4774a8", "5baaf4", "4186c8", "add3ff", "4774a8", "718198", "5a9eff", "99a2ad", "74a2d6",
|
||||
"e9eef3", "dfe3e7", "eff1f3", "5c9ce6", "4986cc", "4680c2", "3f8ae0"
|
||||
public static List<Integer> accentColors = Arrays.asList(
|
||||
Color.parseColor("#3f8ae0"), // azure_300 (light accent)
|
||||
Color.parseColor("#4986cc"), // azure_a400
|
||||
Color.parseColor("#528bcc"), // another light accent
|
||||
Color.parseColor("#71AAEB") // vk_sky_300 (dark accent)
|
||||
);
|
||||
|
||||
public static boolean isAccentedColor(ColorStateList target) {
|
||||
@@ -20,7 +19,7 @@ public class ColorReferences {
|
||||
}
|
||||
|
||||
public static boolean isAccentedColor(int target) {
|
||||
return accentColors.contains(ThemesUtils.hexx(target).toLowerCase());
|
||||
return accentColors.contains(target);
|
||||
}
|
||||
|
||||
public static boolean isColorRefAccented(int target) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import androidx.annotation.NonNull;
|
||||
|
||||
import com.vtosters.lite.R;
|
||||
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class ThemesHacks {
|
||||
if (i != R.layout.themed_feed_tab_2) {
|
||||
return;
|
||||
}
|
||||
textView.setTextColor(ThemesUtils.recolorCSL(textView.getTextColors()));
|
||||
textView.setTextColor(RecolorUtils.recolorCSL(textView.getTextColors()));
|
||||
((InsetDrawable) ((DrawableContainer.DrawableContainerState) textView.getBackground().getConstantState()).getChildren()[0]).getDrawable().setTint(ThemesUtils.lighten(ThemesUtils.getAccentColor(), 0.15f));
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ public class ThemesHacks {
|
||||
}
|
||||
|
||||
public static int getHackedColor(@NonNull Context context, @ColorRes int color) {
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isColorRefAccented(color)) {
|
||||
if (ThemesCore.isCachedAccents() && ColorReferences.isAccentedColor(context.getColor(color))) {
|
||||
Log.d("ThemesHacks", "getHackedColor: got accent color: " + AndroidUtils.getResources().getResourceName(color));
|
||||
return ThemesUtils.getAccentColor();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package ru.vtosters.lite.themes.hooks;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -27,6 +28,7 @@ public class TextViewHook implements BaseHook {
|
||||
if (view instanceof TextView) {
|
||||
var textView = (TextView) view;
|
||||
|
||||
Log.d(TAG, "inject: " + textView.getText() + " " + textView.getCurrentTextColor());
|
||||
if (ColorReferences.isAccentedColor(textView.getCurrentTextColor())) {
|
||||
textView.setTextColor(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.View;
|
||||
|
||||
import com.vk.imageloader.view.VKImageView;
|
||||
|
||||
import ru.vtosters.lite.themes.utils.RecolorUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class VKImageViewHook implements BaseHook {
|
||||
@@ -20,7 +21,7 @@ public class VKImageViewHook implements BaseHook {
|
||||
if (view instanceof VKImageView) {
|
||||
var imageView = (VKImageView) view;
|
||||
if (imageView.getImageTintList() != null) {
|
||||
imageView.setImageTintList(ThemesUtils.recolorCSL(imageView.getImageTintList()));
|
||||
imageView.setImageTintList(RecolorUtils.recolorCSL(imageView.getImageTintList()));
|
||||
imageView.setColorFilter(ThemesUtils.getAccentColor(), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package ru.vtosters.lite.themes.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import com.vk.core.drawable.RecoloredDrawable;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
import ru.vtosters.lite.utils.AndroidUtils;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
public class RecolorUtils {
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
return new RecoloredDrawable(drawable, ThemesUtils.getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = AndroidUtils.getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, ThemesUtils.getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (ColorReferences.isColorRefAccented(color)) {
|
||||
return ColorStateList.valueOf(ThemesUtils.getAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{isSelAccent ? ThemesUtils.getAccentColor() : sel, isUnselAccent ? ThemesUtils.getAccentColor() : unsel});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static ColorStateList themeCSL(ColorStateList csl){
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[] {-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[] {android.R.attr.state_selected}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
return new ColorStateList(new int[][] {
|
||||
new int[] {android.R.attr.state_selected}, new int[] {-android.R.attr.state_selected}
|
||||
}, new int[] {isSelAccent ? ThemesUtils.getAccentColor() : sel, isUnselAccent ? ThemesUtils.getAccentColor() : unsel});
|
||||
}
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import static ru.vtosters.lite.utils.Preferences.milkshake;
|
||||
import static ru.vtosters.lite.utils.Preferences.navbar;
|
||||
import static ru.vtosters.lite.utils.Preferences.vkme;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
@@ -40,8 +39,6 @@ import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
|
||||
import ru.vtosters.lite.themes.ColorReferences;
|
||||
|
||||
public class ThemesUtils {
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
var currentActivity = LifecycleUtils.getCurrentActivity();
|
||||
@@ -220,66 +217,6 @@ public class ThemesUtils {
|
||||
} // Recolor vk icon to accent color
|
||||
|
||||
|
||||
public static Drawable recolorDrawableToolbar(Drawable drawable) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return drawable;
|
||||
|
||||
return new RecoloredDrawable(drawable, getHeaderText());
|
||||
} // Recolor toolbar drawable to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables")
|
||||
public static Drawable recolorDrawableInt(int drawable) {
|
||||
if (!isAndroidMonet()) return getResources().getDrawable(drawable);
|
||||
|
||||
@SuppressLint("UseCompatLoadingForDrawables") Drawable res = getResources().getDrawable(drawable);
|
||||
return new RecoloredDrawable(res, getAccentColor());
|
||||
} // Get res drawable via id and coloring to accent
|
||||
|
||||
public static ColorStateList recolorCSL(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) return null;
|
||||
|
||||
if (!isAndroidMonet()) return colorStateList;
|
||||
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
} // Recolor ColorStateList to accent color
|
||||
|
||||
@SuppressLint("UseCompatLoadingForColorStateLists")
|
||||
public static ColorStateList themeCSL(Context context, int color) {
|
||||
if (isColorRefAccented(color) && isAndroidMonet()) {
|
||||
return ColorStateList.valueOf(getAccentColor());
|
||||
}
|
||||
|
||||
ColorStateList csl;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
csl = context.getColorStateList(color);
|
||||
} else {
|
||||
csl = context.getResources().getColorStateList(color);
|
||||
}
|
||||
|
||||
try {
|
||||
int unsel = csl.getColorForState(new int[]{-android.R.attr.state_selected}, Color.BLACK);
|
||||
int sel = csl.getColorForState(new int[]{android.R.attr.state_selected}, Color.BLACK);
|
||||
|
||||
boolean isUnselAccent = ColorReferences.isAccentedColor(unsel);
|
||||
boolean isSelAccent = ColorReferences.isAccentedColor(sel);
|
||||
|
||||
if (isUnselAccent || isSelAccent) {
|
||||
|
||||
return new ColorStateList(new int[][]{
|
||||
new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}
|
||||
}, new int[]{isSelAccent ? getAccentColor() : sel, isUnselAccent ? getAccentColor() : unsel});
|
||||
}
|
||||
|
||||
return csl;
|
||||
} catch (Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} // Recolor ColorStateList
|
||||
|
||||
public static int darken(int color, float by) {
|
||||
float[] hsl = new float[3];
|
||||
ColorUtils.colorToHSL(color, hsl);
|
||||
|
||||
Reference in New Issue
Block a user