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.IBinder;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
|
|
@ -140,7 +141,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
navigationView.getMenu().getItem(startPosition).setChecked(true);
|
||||
|
||||
tabs.setupWithViewPager(pager);
|
||||
setUpTabStripColor();
|
||||
setUpTabStripColor(getThemeColorAccent() == Color.WHITE ? Color.WHITE : ThemeSingleton.get().positiveColor.getDefaultColor());
|
||||
|
||||
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
|
|
@ -162,7 +163,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
pager.setCurrentItem(startPosition);
|
||||
}
|
||||
|
||||
private void setUpTabStripColor() {
|
||||
private void setUpTabStripColor(@ColorInt int color) {
|
||||
// use reflection to set the selected indicator color
|
||||
try {
|
||||
Field tabStripField = tabs.getClass().getDeclaredField("mTabStrip");
|
||||
|
|
@ -171,7 +172,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
|
||||
Method setSelectedIndicatorColorMethod = tabStrip.getClass().getDeclaredMethod("setSelectedIndicatorColor", Integer.TYPE);
|
||||
setSelectedIndicatorColorMethod.setAccessible(true);
|
||||
setSelectedIndicatorColorMethod.invoke(tabStrip, ThemeSingleton.get().positiveColor.getDefaultColor());
|
||||
setSelectedIndicatorColorMethod.invoke(tabStrip, color);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -199,7 +200,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
new int[]{
|
||||
// 0,
|
||||
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(
|
||||
|
|
@ -211,7 +212,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
new int[]{
|
||||
// 0,
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ import butterknife.ButterKnife;
|
|||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
* <p/>
|
||||
* <p>
|
||||
* Do not use {@link #setContentView(int)} but wrap your layout with
|
||||
* {@link #wrapSlidingMusicPanelAndFab(int)} first and then return it in {@link #createContentView()}
|
||||
*/
|
||||
|
|
@ -213,12 +213,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
|||
updateFabState(false);
|
||||
|
||||
playPauseFab.setImageDrawable(playPauseDrawable);
|
||||
playPauseFab.setBackgroundTintList(ThemeSingleton.get().positiveColor);
|
||||
if (getThemeColorAccent() == Color.WHITE) {
|
||||
playPauseFab.getDrawable().setColorFilter(getResources().getColor(R.color.primary_text_default_material_light), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
playPauseFab.getDrawable().clearColorFilter();
|
||||
}
|
||||
|
||||
int fabColor = getThemeColorAccent();
|
||||
int fabDrawableColor = ColorUtil.getDrawableColorForBackground(this, fabColor);
|
||||
playPauseFab.setBackgroundTintList(ColorStateList.valueOf(getThemeColorAccent()));
|
||||
playPauseFab.getDrawable().setColorFilter(fabDrawableColor, PorterDuff.Mode.SRC_IN);
|
||||
|
||||
final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
|
|
@ -535,7 +534,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
|||
switch (MusicPlayerRemote.getShuffleMode()) {
|
||||
case MusicService.SHUFFLE_MODE_SHUFFLE:
|
||||
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;
|
||||
default:
|
||||
shuffleButton.setImageDrawable(Util.getTintedDrawable(this, R.drawable.ic_shuffle_white_36dp,
|
||||
|
|
@ -562,11 +561,11 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicStateActivity
|
|||
break;
|
||||
case MusicService.REPEAT_MODE_ALL:
|
||||
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;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
|||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
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;
|
||||
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().negativeColor = accentColorStateList;
|
||||
ThemeSingleton.get().neutralColor = accentColorStateList;
|
||||
ThemeSingleton.get().widgetColor = colorAccent;
|
||||
ThemeSingleton.get().widgetColor = accentColorStateList.getDefaultColor();
|
||||
ThemeSingleton.get().darkTheme = darkTheme;
|
||||
|
||||
if (!overridesTaskColor()) {
|
||||
|
|
|
|||
|
|
@ -49,8 +49,12 @@ public class ColorUtil {
|
|||
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) {
|
||||
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) {
|
||||
|
|
@ -60,4 +64,12 @@ public class ColorUtil {
|
|||
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) {
|
||||
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.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
|
|
@ -20,13 +18,10 @@ import com.kabouzeid.gramophone.util.ColorUtil;
|
|||
public class ColorView extends FrameLayout {
|
||||
|
||||
private final Bitmap mCheck;
|
||||
@NonNull
|
||||
private final Paint paint;
|
||||
@NonNull
|
||||
private final Paint paintBorder;
|
||||
@Nullable
|
||||
private Paint paintCheck;
|
||||
private final int borderWidth;
|
||||
private Paint paintCheck;
|
||||
|
||||
public ColorView(@NonNull Context context) {
|
||||
this(context, null, 0);
|
||||
|
|
@ -49,6 +44,9 @@ public class ColorView extends FrameLayout {
|
|||
paintBorder = new Paint();
|
||||
paintBorder.setAntiAlias(true);
|
||||
|
||||
paintCheck = new Paint();
|
||||
paintCheck.setAntiAlias(true);
|
||||
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +68,7 @@ public class ColorView extends FrameLayout {
|
|||
public void setBackgroundColor(int color) {
|
||||
paint.setColor(color);
|
||||
paintBorder.setColor(ColorUtil.shiftColorDown(color));
|
||||
paintCheck.setColorFilter(new PorterDuffColorFilter(ColorUtil.getDrawableColorForBackground(getContext(), color), PorterDuff.Mode.SRC_IN));
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
|
|
@ -106,15 +105,6 @@ public class ColorView extends FrameLayout {
|
|||
|
||||
if (isActivated()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue