Clean ups. Replaced deprecated getResources.getColor() with ContextCompat.getColor(this, int color)
This commit is contained in:
parent
48337bb7da
commit
c0e345fcef
9 changed files with 37 additions and 22 deletions
|
|
@ -8,6 +8,7 @@ import android.support.annotation.AttrRes;
|
|||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.graphics.Palette;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
|
@ -82,6 +83,14 @@ public class ColorUtil {
|
|||
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
|
||||
}
|
||||
|
||||
public static int getPrimaryTextColor(final Context context, boolean dark) {
|
||||
return dark ? ContextCompat.getColor(context, R.color.primary_text_default_material_light) : ContextCompat.getColor(context, R.color.primary_text_default_material_dark);
|
||||
}
|
||||
|
||||
public static int getSecondaryTextColor(final Context context, boolean dark) {
|
||||
return dark ? ContextCompat.getColor(context, R.color.secondary_text_default_material_light) : ContextCompat.getColor(context, R.color.secondary_text_default_material_dark);
|
||||
}
|
||||
|
||||
public static float getLuminance(@ColorInt int color) {
|
||||
return (Color.red(color) * 0.299f + Color.green(color) * 0.587f + Color.blue(color) * 0.114f);
|
||||
}
|
||||
|
|
@ -90,19 +99,19 @@ public class ColorUtil {
|
|||
return getLuminance(backgroundColor) > (255f / 2f);
|
||||
}
|
||||
|
||||
public static int getPrimaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return useDarkTextColorOnBackground(backgroundColor) ? context.getResources().getColor(R.color.primary_text_default_material_light) : context.getResources().getColor(R.color.primary_text_default_material_dark);
|
||||
}
|
||||
|
||||
public static int getSecondaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return useDarkTextColorOnBackground(backgroundColor) ? context.getResources().getColor(R.color.secondary_text_default_material_light) : context.getResources().getColor(R.color.secondary_text_default_material_dark);
|
||||
}
|
||||
|
||||
public static boolean useDarkDrawableColorOnBackground(@ColorInt int backgroundColor) {
|
||||
public static boolean useDarkFabDrawableOnBackground(@ColorInt int backgroundColor) {
|
||||
return getLuminance(backgroundColor) > (255f / 1.3f);
|
||||
}
|
||||
|
||||
public static int getDrawableColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return useDarkDrawableColorOnBackground(backgroundColor) ? context.getResources().getColor(R.color.primary_text_default_material_light) : context.getResources().getColor(R.color.primary_text_default_material_dark);
|
||||
public static int getPrimaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return getPrimaryTextColor(context, useDarkTextColorOnBackground(backgroundColor));
|
||||
}
|
||||
|
||||
public static int getSecondaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return getSecondaryTextColor(context, useDarkTextColorOnBackground(backgroundColor));
|
||||
}
|
||||
|
||||
public static int getFabDrawableColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||
return getPrimaryTextColor(context, useDarkFabDrawableOnBackground(backgroundColor));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.SortOrder;
|
||||
|
|
@ -106,7 +107,7 @@ public final class PreferenceUtil {
|
|||
}
|
||||
|
||||
public int getThemeColorPrimary(Context context) {
|
||||
return mPreferences.getInt("primary_color", context.getResources().getColor(R.color.indigo_500));
|
||||
return mPreferences.getInt("primary_color", ContextCompat.getColor(context, R.color.indigo_500));
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
|
|
@ -115,7 +116,7 @@ public final class PreferenceUtil {
|
|||
}
|
||||
|
||||
public int getThemeColorAccent(Context context) {
|
||||
return mPreferences.getInt("accent_color", context.getResources().getColor(R.color.pink_A200));
|
||||
return mPreferences.getInt("accent_color", ContextCompat.getColor(context, R.color.pink_A200));
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue