Added 1dp borders to each color and added black and white colors.

This commit is contained in:
Karim Abou Zeid 2015-08-25 12:50:49 +02:00
commit e5b5fefc39
7 changed files with 39 additions and 59 deletions

View file

@ -28,6 +28,9 @@
<h3>Version 0.9.44 beta1</h3> <h3>Version 0.9.44 beta1</h3>
<ol> <ol>
<li><b>IMPROVEMENT:</b> Completely rewritten color chooser. Had great help from <a
href="https://plus.google.com/u/0/+AidanFollestad">Aidan Follestad</a> here once again.
</li>
<li><b>IMPROVEMENT:</b> Increased album cover quality when selecting the "ignore media store <li><b>IMPROVEMENT:</b> Increased album cover quality when selecting the "ignore media store
covers" option. covers" option.
</li> </li>

View file

@ -100,7 +100,7 @@ public class ColorChooserDialog extends LeakDetectDialogFragment implements View
private void setIndexesFor(@ColorInt int color) { private void setIndexesFor(@ColorInt int color) {
if (getTopIndex() != -1) return; if (getTopIndex() != -1) return;
if (color != -1) { if (color != 0) {
for (int i = 0; i < colorSetWithHeaders.colors.length; i++) { for (int i = 0; i < colorSetWithHeaders.colors.length; i++) {
for (int z = 0; z < colorSetWithHeaders.colors[i].length; z++) { for (int z = 0; z < colorSetWithHeaders.colors[i].length; z++) {
if (color == colorSetWithHeaders.colors[i][z]) { if (color == colorSetWithHeaders.colors[i][z]) {
@ -223,10 +223,10 @@ public class ColorChooserDialog extends LeakDetectDialogFragment implements View
} }
SelectableColorView child = (SelectableColorView) convertView; SelectableColorView child = (SelectableColorView) convertView;
if (isInSub()) { if (isInSub()) {
child.setBackgroundColor(colorSetWithHeaders.colors[getTopIndex()][position]); child.setColor(colorSetWithHeaders.colors[getTopIndex()][position]);
child.setSelected(getSubIndex() == position); child.setSelected(getSubIndex() == position);
} else { } else {
child.setBackgroundColor(colorSetWithHeaders.colors[position][colorSetWithHeaders.headerColorIndexes[position]]); child.setColor(colorSetWithHeaders.colors[position][colorSetWithHeaders.headerColorIndexes[position]]);
child.setSelected(getTopIndex() == position); child.setSelected(getTopIndex() == position);
} }
child.setTag(position); child.setTag(position);

View file

@ -24,7 +24,7 @@ public class ColorPalette {
5, 5,
5, 5,
5, 5,
5, 6,
5 5
}; };
@ -234,6 +234,7 @@ public class ColorPalette {
Color.parseColor("#3E2723") Color.parseColor("#3E2723")
}, },
new int[]{ new int[]{
Color.parseColor("#FFFFFF"), // not in the original palette
Color.parseColor("#FAFAFA"), Color.parseColor("#FAFAFA"),
Color.parseColor("#F5F5F5"), Color.parseColor("#F5F5F5"),
Color.parseColor("#EEEEEE"), Color.parseColor("#EEEEEE"),
@ -244,6 +245,7 @@ public class ColorPalette {
Color.parseColor("#616161"), Color.parseColor("#616161"),
Color.parseColor("#424242"), Color.parseColor("#424242"),
Color.parseColor("#212121"), Color.parseColor("#212121"),
Color.parseColor("#000000") // not in the original palette
}, },
new int[]{ new int[]{
Color.parseColor("#ECEFF1"), Color.parseColor("#ECEFF1"),
@ -275,6 +277,7 @@ public class ColorPalette {
1, 1,
1, 1,
1, 1,
1,
1 1
}; };
@ -376,5 +379,11 @@ public class ColorPalette {
Color.parseColor("#ff3d00"), Color.parseColor("#ff3d00"),
Color.parseColor("#dd2c00") Color.parseColor("#dd2c00")
}, },
new int[]{
Color.parseColor("#FFFFFF"), // not in the original palette
Color.parseColor("#9E9E9E"), // not in the original palette
Color.parseColor("#424242"), // not in the original palette
Color.parseColor("#000000") // not in the original palette
}
}; };
} }

View file

@ -13,7 +13,7 @@ import com.kabouzeid.gramophone.views.ColorView;
public class ColorChooserPreference extends Preference { public class ColorChooserPreference extends Preference {
@ColorInt @ColorInt
private int color = -1; private int color;
private ColorView colorView; private ColorView colorView;
public ColorChooserPreference(@NonNull Context context) { public ColorChooserPreference(@NonNull Context context) {
@ -44,9 +44,9 @@ public class ColorChooserPreference extends Preference {
private void invalidateColor() { private void invalidateColor() {
if (colorView != null) { if (colorView != null) {
if (this.color != -1) { if (this.color != 0) {
colorView.setVisibility(View.VISIBLE); colorView.setVisibility(View.VISIBLE);
colorView.setBackgroundColor(color); colorView.setColor(color);
} else { } else {
colorView.setVisibility(View.GONE); colorView.setVisibility(View.GONE);
} }

View file

@ -37,8 +37,7 @@ public class ColorView extends FrameLayout {
setWillNotDraw(false); setWillNotDraw(false);
} }
@Override public void setColor(int color) {
public void setBackgroundColor(int color) {
paint.setColor(color); paint.setColor(color);
paintBorder.setColor(ColorUtil.shiftColorDown(color)); paintBorder.setColor(ColorUtil.shiftColorDown(color));
requestLayout(); requestLayout();
@ -62,7 +61,6 @@ public class ColorView extends FrameLayout {
} }
} }
@Override @Override
protected void onDraw(@NonNull Canvas canvas) { protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);

View file

@ -12,8 +12,6 @@ import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.shapes.OvalShape; import android.graphics.drawable.shapes.OvalShape;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.TypedValue; import android.util.TypedValue;
import android.widget.FrameLayout; import android.widget.FrameLayout;
@ -24,13 +22,15 @@ import com.kabouzeid.gramophone.util.ColorUtil;
public class SelectableColorView extends FrameLayout { public class SelectableColorView extends FrameLayout {
private boolean selected;
private final int borderWidthExtraSmall;
private final int borderWidthSmall; private final int borderWidthSmall;
private final int borderWidthLarge; private final int borderWidthLarge;
private Paint outerPaint; private Paint outerPaint;
private Paint gapPaint; private Paint gapPaint;
private Paint innerPaint; private Paint innerPaint;
private boolean mSelected;
public SelectableColorView(Context context) { public SelectableColorView(Context context) {
this(context, null, 0); this(context, null, 0);
@ -43,12 +43,13 @@ public class SelectableColorView extends FrameLayout {
public SelectableColorView(Context context, AttributeSet attrs, int defStyleAttr) { public SelectableColorView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
final Resources r = getResources(); final Resources r = getResources();
borderWidthExtraSmall = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
borderWidthSmall = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, r.getDisplayMetrics()); borderWidthSmall = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, r.getDisplayMetrics());
borderWidthLarge = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); borderWidthLarge = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics());
gapPaint = new Paint(); gapPaint = new Paint();
gapPaint.setAntiAlias(true); gapPaint.setAntiAlias(true);
gapPaint.setColor(ColorUtil.resolveColor(context, R.attr.cardBackgroundColor)); resetGapColor();
innerPaint = new Paint(); innerPaint = new Paint();
innerPaint.setAntiAlias(true); innerPaint.setAntiAlias(true);
@ -59,7 +60,11 @@ public class SelectableColorView extends FrameLayout {
setWillNotDraw(false); setWillNotDraw(false);
} }
private void update(@ColorInt int color) { private void resetGapColor() {
gapPaint.setColor(ColorUtil.resolveColor(getContext(), R.attr.cardBackgroundColor));
}
private void updateColor(@ColorInt int color) {
innerPaint.setColor(color); innerPaint.setColor(color);
outerPaint.setColor(ColorUtil.shiftColorDown(color)); outerPaint.setColor(ColorUtil.shiftColorDown(color));
@ -92,49 +97,15 @@ public class SelectableColorView extends FrameLayout {
} }
} }
@Override public void setColor(@ColorInt int color) {
public void setBackgroundColor(@ColorInt int color) { updateColor(color);
update(color);
requestLayout(); requestLayout();
invalidate(); invalidate();
} }
@Override @Override
public void setBackgroundResource(@ColorRes int color) {
setBackgroundColor(ContextCompat.getColor(getContext(), color));
}
/**
* @deprecated
*/
@Deprecated
@Override
public void setBackground(Drawable background) {
throw new IllegalStateException("Cannot use setBackground() on CircleView.");
}
/**
* @deprecated
*/
@SuppressWarnings("deprecation")
@Deprecated
@Override
public void setBackgroundDrawable(Drawable background) {
throw new IllegalStateException("Cannot use setBackgroundDrawable() on CircleView.");
}
/**
* @deprecated
*/
@SuppressWarnings("deprecation")
@Deprecated
@Override
public void setActivated(boolean activated) {
throw new IllegalStateException("Cannot use setActivated() on CircleView.");
}
public void setSelected(boolean selected) { public void setSelected(boolean selected) {
mSelected = selected; this.selected = selected;
requestLayout(); requestLayout();
invalidate(); invalidate();
} }
@ -159,7 +130,7 @@ public class SelectableColorView extends FrameLayout {
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
final int outerRadius = getMeasuredWidth() / 2; final int outerRadius = getMeasuredWidth() / 2;
if (mSelected) { if (selected) {
final int whiteRadius = outerRadius - borderWidthLarge; final int whiteRadius = outerRadius - borderWidthLarge;
final int innerRadius = whiteRadius - borderWidthSmall; final int innerRadius = whiteRadius - borderWidthSmall;
canvas.drawCircle(getMeasuredWidth() / 2, canvas.drawCircle(getMeasuredWidth() / 2,
@ -175,9 +146,14 @@ public class SelectableColorView extends FrameLayout {
innerRadius, innerRadius,
innerPaint); innerPaint);
} else { } else {
final int innerRadius = outerRadius - borderWidthExtraSmall;
canvas.drawCircle(getMeasuredWidth() / 2, canvas.drawCircle(getMeasuredWidth() / 2,
getMeasuredHeight() / 2, getMeasuredHeight() / 2,
outerRadius, outerRadius,
outerPaint);
canvas.drawCircle(getMeasuredWidth() / 2,
getMeasuredHeight() / 2,
innerRadius,
innerPaint); innerPaint);
} }
} }

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.kabouzeid.gramophone.views.ColorView
android:id="@+id/color_view"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />