improve theme utilities and fix issue with color drawable
This commit is contained in:
parent
a7cb077cee
commit
2c7113ecb9
17 changed files with 72 additions and 85 deletions
|
|
@ -2,6 +2,8 @@ package com.dkanada.gramophone.util;
|
|||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -67,8 +69,37 @@ public class ThemeUtil {
|
|||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getDisabledTextColor(int color) {
|
||||
return MaterialColors.compositeARGBWithAlpha(color, 140);
|
||||
public static int getPrimaryTextColor(Context context, int color) {
|
||||
return getPrimaryTextColor(context, MaterialColors.isColorLight(color));
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getSecondaryTextColor(Context context, int color) {
|
||||
return getSecondaryTextColor(context, MaterialColors.isColorLight(color));
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColorResource(Context context, int resource, int alpha) {
|
||||
TypedArray array = context.obtainStyledAttributes(new int[]{resource});
|
||||
int color = array.getColor(0, ContextCompat.getColor(context, android.R.color.white));
|
||||
|
||||
array.recycle();
|
||||
|
||||
return MaterialColors.compositeARGBWithAlpha(color, alpha);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColorAlpha(Context context, int color, int alpha) {
|
||||
return MaterialColors.compositeARGBWithAlpha(ContextCompat.getColor(context, color), alpha);
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
public static int getColorDark(int color) {
|
||||
float[] hsv = new float[3];
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[2] *= 0.8f;
|
||||
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
private static class SwatchComparator implements Comparator<Palette.Swatch> {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.ColorInt;
|
||||
|
||||
import com.kabouzeid.appthemehelper.util.ATHUtil;
|
||||
import com.kabouzeid.appthemehelper.util.ColorUtil;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView;
|
||||
|
||||
|
|
@ -78,9 +76,9 @@ public class ViewUtil {
|
|||
|
||||
public static void setUpFastScrollRecyclerViewColor(Context context, FastScrollRecyclerView recyclerView, int accentColor) {
|
||||
recyclerView.setPopupBgColor(accentColor);
|
||||
recyclerView.setPopupTextColor(ThemeUtil.getPrimaryTextColor(context, ColorUtil.isColorLight(accentColor)));
|
||||
recyclerView.setPopupTextColor(ThemeUtil.getPrimaryTextColor(context, accentColor));
|
||||
recyclerView.setThumbColor(accentColor);
|
||||
recyclerView.setTrackColor(ColorUtil.withAlpha(ATHUtil.resolveColor(context, R.attr.colorControlNormal), 0.12f));
|
||||
recyclerView.setTrackColor(ThemeUtil.getColorResource(context, R.attr.colorControlNormal, 40));
|
||||
}
|
||||
|
||||
public static float convertDpToPixel(float dp, Resources resources) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue