Fixed some readability issues with the white and black accent colors
This commit is contained in:
parent
6b68c17ae2
commit
431cf23da3
5 changed files with 44 additions and 33 deletions
|
|
@ -12,6 +12,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
|
|
@ -140,7 +141,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
||||||
navigationView.getMenu().getItem(startPosition).setChecked(true);
|
navigationView.getMenu().getItem(startPosition).setChecked(true);
|
||||||
|
|
||||||
tabs.setupWithViewPager(pager);
|
tabs.setupWithViewPager(pager);
|
||||||
setUpTabStripColor();
|
setUpTabStripColor(getThemeColorAccent() == Color.WHITE ? Color.WHITE : ThemeSingleton.get().positiveColor.getDefaultColor());
|
||||||
|
|
||||||
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -162,7 +163,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
||||||
pager.setCurrentItem(startPosition);
|
pager.setCurrentItem(startPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpTabStripColor() {
|
private void setUpTabStripColor(@ColorInt int color) {
|
||||||
// use reflection to set the selected indicator color
|
// use reflection to set the selected indicator color
|
||||||
try {
|
try {
|
||||||
Field tabStripField = tabs.getClass().getDeclaredField("mTabStrip");
|
Field tabStripField = tabs.getClass().getDeclaredField("mTabStrip");
|
||||||
|
|
@ -171,7 +172,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
||||||
|
|
||||||
Method setSelectedIndicatorColorMethod = tabStrip.getClass().getDeclaredMethod("setSelectedIndicatorColor", Integer.TYPE);
|
Method setSelectedIndicatorColorMethod = tabStrip.getClass().getDeclaredMethod("setSelectedIndicatorColor", Integer.TYPE);
|
||||||
setSelectedIndicatorColorMethod.setAccessible(true);
|
setSelectedIndicatorColorMethod.setAccessible(true);
|
||||||
setSelectedIndicatorColorMethod.invoke(tabStrip, ThemeSingleton.get().positiveColor.getDefaultColor());
|
setSelectedIndicatorColorMethod.invoke(tabStrip, color);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -199,7 +200,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
||||||
new int[]{
|
new int[]{
|
||||||
// 0,
|
// 0,
|
||||||
colorAccent,
|
colorAccent,
|
||||||
ThemeSingleton.get().darkTheme ? Color.argb(222, 255, 255, 255) : Color.argb(222, 0, 0, 0)
|
ThemeSingleton.get().darkTheme ? getResources().getColor(R.color.primary_text_default_material_dark) : getResources().getColor(R.color.primary_text_default_material_light)
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
navigationView.setItemIconTintList(new ColorStateList(
|
navigationView.setItemIconTintList(new ColorStateList(
|
||||||
|
|
@ -211,7 +212,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
||||||
new int[]{
|
new int[]{
|
||||||
// 0,
|
// 0,
|
||||||
colorAccent,
|
colorAccent,
|
||||||
ThemeSingleton.get().darkTheme ? Color.argb(138, 255, 255, 255) : Color.argb(138, 0, 0, 0)
|
ThemeSingleton.get().darkTheme ? getResources().getColor(R.color.secondary_text_default_material_dark) : getResources().getColor(R.color.secondary_text_default_material_light)
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ import butterknife.ButterKnife;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid)
|
* @author Karim Abou Zeid (kabouzeid)
|
||||||
* <p/>
|
* <p>
|
||||||
* Do not use {@link #setContentView(int)} but wrap your layout with
|
* Do not use {@link #setContentView(int)} but wrap your layout with
|
||||||
* {@link #wrapSlidingMusicPanelAndFab(int)} first and then return it in {@link #createContentView()}
|
* {@link #wrapSlidingMusicPanelAndFab(int)} first and then return it in {@link #createContentView()}
|
||||||
*/
|
*/
|
||||||
|
|
@ -213,12 +213,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
||||||
updateFabState(false);
|
updateFabState(false);
|
||||||
|
|
||||||
playPauseFab.setImageDrawable(playPauseDrawable);
|
playPauseFab.setImageDrawable(playPauseDrawable);
|
||||||
playPauseFab.setBackgroundTintList(ThemeSingleton.get().positiveColor);
|
|
||||||
if (getThemeColorAccent() == Color.WHITE) {
|
int fabColor = getThemeColorAccent();
|
||||||
playPauseFab.getDrawable().setColorFilter(getResources().getColor(R.color.primary_text_default_material_light), PorterDuff.Mode.SRC_IN);
|
int fabDrawableColor = ColorUtil.getDrawableColorForBackground(this, fabColor);
|
||||||
} else {
|
playPauseFab.setBackgroundTintList(ColorStateList.valueOf(getThemeColorAccent()));
|
||||||
playPauseFab.getDrawable().clearColorFilter();
|
playPauseFab.getDrawable().setColorFilter(fabDrawableColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
|
||||||
|
|
||||||
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -535,7 +534,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
||||||
switch (MusicPlayerRemote.getShuffleMode()) {
|
switch (MusicPlayerRemote.getShuffleMode()) {
|
||||||
case MusicService.SHUFFLE_MODE_SHUFFLE:
|
case MusicService.SHUFFLE_MODE_SHUFFLE:
|
||||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
|
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
|
||||||
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
|
ThemeSingleton.get().positiveColor.getDefaultColor()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
|
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
|
||||||
|
|
@ -562,11 +561,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
||||||
break;
|
break;
|
||||||
case MusicService.REPEAT_MODE_ALL:
|
case MusicService.REPEAT_MODE_ALL:
|
||||||
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_white_36dp,
|
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_white_36dp,
|
||||||
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
|
ThemeSingleton.get().positiveColor.getDefaultColor()));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_one_white_36dp,
|
repeatButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_repeat_one_white_36dp,
|
||||||
getThemeColorAccent() == Color.WHITE ? getResources().getColor(R.color.primary_text_default_material_light) : getThemeColorAccent()));
|
ThemeSingleton.get().positiveColor.getDefaultColor()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
|
|
@ -50,11 +51,19 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
|
||||||
darkTheme = PreferenceUtil.getInstance(this).getGeneralTheme() == R.style.Theme_MaterialMusic;
|
darkTheme = PreferenceUtil.getInstance(this).getGeneralTheme() == R.style.Theme_MaterialMusic;
|
||||||
coloredNavigationBar = PreferenceUtil.getInstance(this).shouldUseColoredNavigationBar();
|
coloredNavigationBar = PreferenceUtil.getInstance(this).shouldUseColoredNavigationBar();
|
||||||
|
|
||||||
final ColorStateList accentColorStateList = ColorStateList.valueOf(colorAccent);
|
final ColorStateList accentColorStateList;
|
||||||
|
if (colorAccent == Color.WHITE && !darkTheme) {
|
||||||
|
accentColorStateList = ColorStateList.valueOf(Color.BLACK);
|
||||||
|
} else if (colorAccent == Color.BLACK && darkTheme) {
|
||||||
|
accentColorStateList = ColorStateList.valueOf(Color.WHITE);
|
||||||
|
} else {
|
||||||
|
accentColorStateList = ColorStateList.valueOf(colorAccent);
|
||||||
|
}
|
||||||
|
|
||||||
ThemeSingleton.get().positiveColor = accentColorStateList;
|
ThemeSingleton.get().positiveColor = accentColorStateList;
|
||||||
ThemeSingleton.get().negativeColor = accentColorStateList;
|
ThemeSingleton.get().negativeColor = accentColorStateList;
|
||||||
ThemeSingleton.get().neutralColor = accentColorStateList;
|
ThemeSingleton.get().neutralColor = accentColorStateList;
|
||||||
ThemeSingleton.get().widgetColor = colorAccent;
|
ThemeSingleton.get().widgetColor = accentColorStateList.getDefaultColor();
|
||||||
ThemeSingleton.get().darkTheme = darkTheme;
|
ThemeSingleton.get().darkTheme = darkTheme;
|
||||||
|
|
||||||
if (!overridesTaskColor()) {
|
if (!overridesTaskColor()) {
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,12 @@ public class ColorUtil {
|
||||||
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
|
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float getLuminance(@ColorInt int color) {
|
||||||
|
return (Color.red(color) * 0.299f + Color.green(color) * 0.587f + Color.blue(color) * 0.114f);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean useDarkTextColorOnBackground(@ColorInt int backgroundColor) {
|
public static boolean useDarkTextColorOnBackground(@ColorInt int backgroundColor) {
|
||||||
return (Color.red(backgroundColor) * 0.299 + Color.green(backgroundColor) * 0.587 + Color.blue(backgroundColor) * 0.114) > (255 / 2);
|
return getLuminance(backgroundColor) > (255f / 2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPrimaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
public static int getPrimaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
||||||
|
|
@ -60,4 +64,12 @@ public class ColorUtil {
|
||||||
public static int getSecondaryTextColorForBackground(final Context context, @ColorInt int backgroundColor) {
|
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);
|
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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,11 @@ import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Matrix;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
|
@ -20,13 +18,10 @@ import com.kabouzeid.gramophone.util.ColorUtil;
|
||||||
public class ColorView extends FrameLayout {
|
public class ColorView extends FrameLayout {
|
||||||
|
|
||||||
private final Bitmap mCheck;
|
private final Bitmap mCheck;
|
||||||
@NonNull
|
|
||||||
private final Paint paint;
|
private final Paint paint;
|
||||||
@NonNull
|
|
||||||
private final Paint paintBorder;
|
private final Paint paintBorder;
|
||||||
@Nullable
|
|
||||||
private Paint paintCheck;
|
|
||||||
private final int borderWidth;
|
private final int borderWidth;
|
||||||
|
private Paint paintCheck;
|
||||||
|
|
||||||
public ColorView(@NonNull Context context) {
|
public ColorView(@NonNull Context context) {
|
||||||
this(context, null, 0);
|
this(context, null, 0);
|
||||||
|
|
@ -49,6 +44,9 @@ public class ColorView extends FrameLayout {
|
||||||
paintBorder = new Paint();
|
paintBorder = new Paint();
|
||||||
paintBorder.setAntiAlias(true);
|
paintBorder.setAntiAlias(true);
|
||||||
|
|
||||||
|
paintCheck = new Paint();
|
||||||
|
paintCheck.setAntiAlias(true);
|
||||||
|
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,6 +68,7 @@ public class ColorView extends FrameLayout {
|
||||||
public void setBackgroundColor(int color) {
|
public void setBackgroundColor(int color) {
|
||||||
paint.setColor(color);
|
paint.setColor(color);
|
||||||
paintBorder.setColor(ColorUtil.shiftColorDown(color));
|
paintBorder.setColor(ColorUtil.shiftColorDown(color));
|
||||||
|
paintCheck.setColorFilter(new PorterDuffColorFilter(ColorUtil.getDrawableColorForBackground(getContext(), color), PorterDuff.Mode.SRC_IN));
|
||||||
requestLayout();
|
requestLayout();
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
@ -106,15 +105,6 @@ public class ColorView extends FrameLayout {
|
||||||
|
|
||||||
if (isActivated()) {
|
if (isActivated()) {
|
||||||
final int offset = (canvasSize / 2) - (mCheck.getWidth() / 2);
|
final int offset = (canvasSize / 2) - (mCheck.getWidth() / 2);
|
||||||
if (paint.getColor() == Color.WHITE) {
|
|
||||||
if (paintCheck == null) {
|
|
||||||
paintCheck = new Paint();
|
|
||||||
paintCheck.setAntiAlias(true);
|
|
||||||
paintCheck.setColorFilter(new PorterDuffColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
paintCheck = null;
|
|
||||||
}
|
|
||||||
canvas.drawBitmap(mCheck, offset, offset, paintCheck);
|
canvas.drawBitmap(mCheck, offset, offset, paintCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue