mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-17 09:37:50 +01:00
Always show alpha slider in ColorPicker
Also some code cleanup.
This commit is contained in:
parent
f61396b1f9
commit
ae4d2a4f16
|
@ -61,9 +61,7 @@ public class ColorPickerDialog
|
||||||
public void reInitUI() {
|
public void reInitUI() {
|
||||||
int oldColor = mOldColor.getColor();
|
int oldColor = mOldColor.getColor();
|
||||||
int newColor = mNewColor.getColor();
|
int newColor = mNewColor.getColor();
|
||||||
boolean alphaSlider = mColorPicker.getAlphaSliderVisible();
|
|
||||||
setUp(oldColor, newColor);
|
setUp(oldColor, newColor);
|
||||||
setAlphaSliderVisible(alphaSlider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUp(int oldColor, int newColor) {
|
private void setUp(int oldColor, int newColor) {
|
||||||
|
@ -95,10 +93,6 @@ public class ColorPickerDialog
|
||||||
mNewColor.setColor(color);
|
mNewColor.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlphaSliderVisible(boolean visible) {
|
|
||||||
mColorPicker.setAlphaSliderVisible(visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a OnColorChangedListener to get notified when the color
|
* Set a OnColorChangedListener to get notified when the color
|
||||||
* selected by the user has changed.
|
* selected by the user has changed.
|
||||||
|
|
|
@ -48,7 +48,6 @@ public class ColorPickerPreference
|
||||||
private int mDefaultValue = Color.BLACK;
|
private int mDefaultValue = Color.BLACK;
|
||||||
private int mValue = Color.BLACK;
|
private int mValue = Color.BLACK;
|
||||||
private float mDensity = 0;
|
private float mDensity = 0;
|
||||||
private boolean mAlphaSliderEnabled = false;
|
|
||||||
|
|
||||||
private static final String androidns = "http://schemas.android.com/apk/res/android";
|
private static final String androidns = "http://schemas.android.com/apk/res/android";
|
||||||
|
|
||||||
|
@ -90,7 +89,6 @@ public class ColorPickerPreference
|
||||||
mDefaultValue = context.getResources().getInteger(resourceId);
|
mDefaultValue = context.getResources().getInteger(resourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAlphaSliderEnabled = attrs.getAttributeBooleanValue(null, "alphaSlider", false);
|
|
||||||
}
|
}
|
||||||
mValue = mDefaultValue;
|
mValue = mDefaultValue;
|
||||||
}
|
}
|
||||||
|
@ -195,8 +193,6 @@ public class ColorPickerPreference
|
||||||
|
|
||||||
private void showDialog() {
|
private void showDialog() {
|
||||||
mDialog = new ColorPickerDialog(getContext(), getValue(), getTitle());
|
mDialog = new ColorPickerDialog(getContext(), getValue(), getTitle());
|
||||||
if (mAlphaSliderEnabled)
|
|
||||||
mDialog.setAlphaSliderVisible(true);
|
|
||||||
mDialog.setOnColorChangedListener(this);
|
mDialog.setOnColorChangedListener(this);
|
||||||
mDialog.setOnDismissListener(this);
|
mDialog.setOnDismissListener(this);
|
||||||
addRemoveConfigChangedListener();
|
addRemoveConfigChangedListener();
|
||||||
|
@ -222,12 +218,6 @@ public class ColorPickerPreference
|
||||||
if (mDialog != null)
|
if (mDialog != null)
|
||||||
mDialog.reInitUI();
|
mDialog.reInitUI();
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Toggle Alpha Slider visibility (by default it's disabled)
|
|
||||||
*/
|
|
||||||
public void setAlphaSliderEnabled(boolean enable) {
|
|
||||||
mAlphaSliderEnabled = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String convertToARGB(int color) {
|
private static String convertToARGB(int color) {
|
||||||
String alpha = Integer.toHexString(Color.alpha(color));
|
String alpha = Integer.toHexString(Color.alpha(color));
|
||||||
|
|
|
@ -35,9 +35,7 @@ import android.view.View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a color picker to the user and allow them
|
* Displays a color picker to the user and allow them
|
||||||
* to select a color. A slider for the alpha channel is
|
* to select a color.
|
||||||
* also available. Enable it by setting
|
|
||||||
* setAlphaSliderVisible(boolean) to true.
|
|
||||||
* @author Daniel Nilsson
|
* @author Daniel Nilsson
|
||||||
*/
|
*/
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
@ -77,27 +75,24 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
private OnColorChangedListener mListener;
|
private OnColorChangedListener mListener;
|
||||||
|
|
||||||
private Paint mSatValPaint;
|
private Paint mSatValPaint = new Paint();
|
||||||
private Paint mSatValTrackerPaint;
|
private Paint mSatValTrackerPaint = new Paint();
|
||||||
|
|
||||||
private Paint mHuePaint;
|
private Paint mHuePaint = new Paint();
|
||||||
private Paint mHueTrackerPaint;
|
private Paint mHueTrackerPaint = new Paint();
|
||||||
|
|
||||||
private Paint mAlphaPaint;
|
private Paint mAlphaPaint = new Paint();
|
||||||
private Paint mBorderPaint;
|
private Paint mBorderPaint = new Paint();
|
||||||
|
|
||||||
private Shader mValShader;
|
private Shader mValShader;
|
||||||
private Shader mSatShader;
|
|
||||||
private Shader mHueShader;
|
private Shader mHueShader;
|
||||||
private Shader mAlphaShader;
|
|
||||||
|
|
||||||
private int mAlpha = 0xff;
|
private int mAlpha = 0xff;
|
||||||
private float mHue = 360f;
|
private float mHue = 360f;
|
||||||
private float mSat = 0f;
|
private float mSat = 0f;
|
||||||
private float mVal = 0f;
|
private float mVal = 0f;
|
||||||
|
|
||||||
private int mBorderColor = 0xff6E6E6E;
|
private final int mBorderColor = 0xff6E6E6E;
|
||||||
private boolean mShowAlphaPanel = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Offset from the edge we must have or else
|
* Offset from the edge we must have or else
|
||||||
|
@ -106,7 +101,6 @@ public class ColorPickerView extends View {
|
||||||
*/
|
*/
|
||||||
private float mDrawingOffset;
|
private float mDrawingOffset;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Distance form the edges of the view
|
* Distance form the edges of the view
|
||||||
* of where we are allowed to draw.
|
* of where we are allowed to draw.
|
||||||
|
@ -114,7 +108,7 @@ public class ColorPickerView extends View {
|
||||||
private RectF mDrawingRect;
|
private RectF mDrawingRect;
|
||||||
|
|
||||||
private RectF mSatValRect;
|
private RectF mSatValRect;
|
||||||
private RectF mHueRect;
|
private RectF mHueRect;
|
||||||
private RectF mAlphaRect;
|
private RectF mAlphaRect;
|
||||||
|
|
||||||
private AlphaPatternDrawable mAlphaPattern;
|
private AlphaPatternDrawable mAlphaPattern;
|
||||||
|
@ -144,7 +138,7 @@ public class ColorPickerView extends View {
|
||||||
RECTANGLE_TRACKER_OFFSET *= mDensity;
|
RECTANGLE_TRACKER_OFFSET *= mDensity;
|
||||||
HUE_PANEL_WIDTH *= mDensity;
|
HUE_PANEL_WIDTH *= mDensity;
|
||||||
ALPHA_PANEL_HEIGHT *= mDensity;
|
ALPHA_PANEL_HEIGHT *= mDensity;
|
||||||
PANEL_SPACING = PANEL_SPACING * mDensity;
|
PANEL_SPACING *= mDensity;
|
||||||
|
|
||||||
mDrawingOffset = calculateRequiredOffset();
|
mDrawingOffset = calculateRequiredOffset();
|
||||||
|
|
||||||
|
@ -155,13 +149,6 @@ public class ColorPickerView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPaintTools() {
|
private void initPaintTools() {
|
||||||
mSatValPaint = new Paint();
|
|
||||||
mSatValTrackerPaint = new Paint();
|
|
||||||
mHuePaint = new Paint();
|
|
||||||
mHueTrackerPaint = new Paint();
|
|
||||||
mAlphaPaint = new Paint();
|
|
||||||
mBorderPaint = new Paint();
|
|
||||||
|
|
||||||
mSatValTrackerPaint.setStyle(Style.STROKE);
|
mSatValTrackerPaint.setStyle(Style.STROKE);
|
||||||
mSatValTrackerPaint.setStrokeWidth(2f * mDensity);
|
mSatValTrackerPaint.setStrokeWidth(2f * mDensity);
|
||||||
mSatValTrackerPaint.setAntiAlias(true);
|
mSatValTrackerPaint.setAntiAlias(true);
|
||||||
|
@ -217,8 +204,8 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
int rgb = Color.HSVToColor(new float[]{mHue,1f,1f});
|
int rgb = Color.HSVToColor(new float[]{mHue,1f,1f});
|
||||||
|
|
||||||
mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
|
Shader mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
|
||||||
0xffffffff, rgb, TileMode.CLAMP);
|
0xffffffff, rgb, TileMode.CLAMP);
|
||||||
ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY);
|
ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY);
|
||||||
mSatValPaint.setShader(mShader);
|
mSatValPaint.setShader(mShader);
|
||||||
|
|
||||||
|
@ -226,11 +213,11 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
Point p = satValToPoint(mSat, mVal);
|
Point p = satValToPoint(mSat, mVal);
|
||||||
|
|
||||||
|
float r = PALETTE_CIRCLE_TRACKER_RADIUS;
|
||||||
mSatValTrackerPaint.setColor(0xff000000);
|
mSatValTrackerPaint.setColor(0xff000000);
|
||||||
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity, mSatValTrackerPaint);
|
canvas.drawCircle(p.x, p.y, r - 1f * mDensity, mSatValTrackerPaint);
|
||||||
|
|
||||||
mSatValTrackerPaint.setColor(0xffdddddd);
|
mSatValTrackerPaint.setColor(0xffdddddd);
|
||||||
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint);
|
canvas.drawCircle(p.x, p.y, r, mSatValTrackerPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawHuePanel(Canvas canvas) {
|
private void drawHuePanel(Canvas canvas) {
|
||||||
|
@ -239,10 +226,10 @@ public class ColorPickerView extends View {
|
||||||
if (BORDER_WIDTH_PX > 0) {
|
if (BORDER_WIDTH_PX > 0) {
|
||||||
mBorderPaint.setColor(mBorderColor);
|
mBorderPaint.setColor(mBorderColor);
|
||||||
canvas.drawRect(rect.left - BORDER_WIDTH_PX,
|
canvas.drawRect(rect.left - BORDER_WIDTH_PX,
|
||||||
rect.top - BORDER_WIDTH_PX,
|
rect.top - BORDER_WIDTH_PX,
|
||||||
rect.right + BORDER_WIDTH_PX,
|
rect.right + BORDER_WIDTH_PX,
|
||||||
rect.bottom + BORDER_WIDTH_PX,
|
rect.bottom + BORDER_WIDTH_PX,
|
||||||
mBorderPaint);
|
mBorderPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHueShader == null) {
|
if (mHueShader == null) {
|
||||||
|
@ -267,7 +254,7 @@ public class ColorPickerView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawAlphaPanel(Canvas canvas) {
|
private void drawAlphaPanel(Canvas canvas) {
|
||||||
if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
|
if (mAlphaRect == null || mAlphaPattern == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final RectF rect = mAlphaRect;
|
final RectF rect = mAlphaRect;
|
||||||
|
@ -287,8 +274,8 @@ public class ColorPickerView extends View {
|
||||||
int color = Color.HSVToColor(hsv);
|
int color = Color.HSVToColor(hsv);
|
||||||
int acolor = Color.HSVToColor(0, hsv);
|
int acolor = Color.HSVToColor(0, hsv);
|
||||||
|
|
||||||
mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
|
Shader mAlphaShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
|
||||||
color, acolor, TileMode.CLAMP);
|
color, acolor, TileMode.CLAMP);
|
||||||
|
|
||||||
mAlphaPaint.setShader(mAlphaShader);
|
mAlphaPaint.setShader(mAlphaShader);
|
||||||
|
|
||||||
|
@ -311,89 +298,57 @@ public class ColorPickerView extends View {
|
||||||
final RectF rect = mHueRect;
|
final RectF rect = mHueRect;
|
||||||
final float height = rect.height();
|
final float height = rect.height();
|
||||||
|
|
||||||
Point p = new Point();
|
return new Point((int) rect.left,
|
||||||
|
(int) (height - (hue * height / 360f) + rect.top));
|
||||||
p.y = (int) (height - (hue * height / 360f) + rect.top);
|
|
||||||
p.x = (int) rect.left;
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point satValToPoint(float sat, float val) {
|
private Point satValToPoint(float sat, float val) {
|
||||||
final RectF rect = mSatValRect;
|
final RectF rect = mSatValRect;
|
||||||
final float height = rect.height();
|
|
||||||
final float width = rect.width();
|
final float width = rect.width();
|
||||||
|
final float height = rect.height();
|
||||||
|
|
||||||
Point p = new Point();
|
return new Point((int) (sat * width + rect.left),
|
||||||
p.x = (int) (sat * width + rect.left);
|
(int) ((1f - val) * height + rect.top));
|
||||||
p.y = (int) ((1f - val) * height + rect.top);
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point alphaToPoint(int alpha) {
|
private Point alphaToPoint(int alpha) {
|
||||||
final RectF rect = mAlphaRect;
|
final RectF rect = mAlphaRect;
|
||||||
final float width = rect.width();
|
final float width = rect.width();
|
||||||
|
|
||||||
Point p = new Point();
|
return new Point((int) (width - (alpha * width / 0xff) + rect.left),
|
||||||
p.x = (int) (width - (alpha * width / 0xff) + rect.left);
|
(int) rect.top);
|
||||||
p.y = (int) rect.top;
|
}
|
||||||
|
|
||||||
return p;
|
private static float clampF(float val, float min, float max) {
|
||||||
|
return Math.min(Math.max(val, min), max);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float[] pointToSatVal(float x, float y) {
|
private float[] pointToSatVal(float x, float y) {
|
||||||
final RectF rect = mSatValRect;
|
final RectF rect = mSatValRect;
|
||||||
float[] result = new float[2];
|
|
||||||
|
|
||||||
float width = rect.width();
|
float width = rect.width();
|
||||||
float height = rect.height();
|
float height = rect.height();
|
||||||
|
|
||||||
if (x < rect.left)
|
x = clampF(x - rect.left, 0f, width);
|
||||||
x = 0f;
|
y = clampF(y - rect.top, 0f, height);
|
||||||
else if (x > rect.right)
|
|
||||||
x = width;
|
|
||||||
else
|
|
||||||
x = x - rect.left;
|
|
||||||
|
|
||||||
if (y < rect.top)
|
return new float[]{ x / width, 1f - y / height };
|
||||||
y = 0f;
|
|
||||||
else if (y > rect.bottom)
|
|
||||||
y = height;
|
|
||||||
else
|
|
||||||
y = y - rect.top;
|
|
||||||
|
|
||||||
result[0] = 1.f / width * x;
|
|
||||||
result[1] = 1.f - (1.f / height * y);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float pointToHue(float y) {
|
private float pointToHue(float y) {
|
||||||
final RectF rect = mHueRect;
|
final RectF rect = mHueRect;
|
||||||
|
|
||||||
float height = rect.height();
|
float height = rect.height();
|
||||||
|
y = clampF(y - rect.top, 0f, height);
|
||||||
if (y < rect.top)
|
|
||||||
y = 0f;
|
|
||||||
else if (y > rect.bottom)
|
|
||||||
y = height;
|
|
||||||
else
|
|
||||||
y = y - rect.top;
|
|
||||||
|
|
||||||
return 360f - (y * 360f / height);
|
return 360f - (y * 360f / height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int pointToAlpha(int x) {
|
private int pointToAlpha(int x) {
|
||||||
final RectF rect = mAlphaRect;
|
final RectF rect = mAlphaRect;
|
||||||
final int width = (int) rect.width();
|
|
||||||
|
|
||||||
if (x < rect.left)
|
final int width = (int) rect.width();
|
||||||
x = 0;
|
x = Math.min(Math.max(x - (int)rect.left, 0), width);
|
||||||
else if (x > rect.right)
|
|
||||||
x = width;
|
|
||||||
else
|
|
||||||
x = x - (int)rect.left;
|
|
||||||
|
|
||||||
return 0xff - (x * 0xff / width);
|
return 0xff - (x * 0xff / width);
|
||||||
}
|
}
|
||||||
|
@ -451,9 +406,6 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||||
|
|
||||||
|
@ -462,27 +414,16 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
widthAllowed = chooseWidth(widthMode, widthAllowed);
|
widthAllowed = chooseWidth(widthMode, widthAllowed);
|
||||||
heightAllowed = chooseHeight(heightMode, heightAllowed);
|
heightAllowed = chooseHeight(heightMode, heightAllowed);
|
||||||
|
|
||||||
if (!mShowAlphaPanel) {
|
|
||||||
height = (int) (widthAllowed - PANEL_SPACING - HUE_PANEL_WIDTH);
|
|
||||||
|
|
||||||
//If calculated height (based on the width) is more than the allowed height.
|
int width = (int) (heightAllowed - ALPHA_PANEL_HEIGHT + HUE_PANEL_WIDTH);
|
||||||
if (height > heightAllowed || getTag().equals("landscape")) {
|
int height;
|
||||||
height = heightAllowed;
|
if (width > widthAllowed) {
|
||||||
width = (int) (height + PANEL_SPACING + HUE_PANEL_WIDTH);
|
width = widthAllowed;
|
||||||
} else {
|
height = (int) (widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT);
|
||||||
width = widthAllowed;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
width = (int) (heightAllowed - ALPHA_PANEL_HEIGHT + HUE_PANEL_WIDTH);
|
height = heightAllowed;
|
||||||
if (width > widthAllowed) {
|
|
||||||
width = widthAllowed;
|
|
||||||
height = (int) (widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT);
|
|
||||||
} else {
|
|
||||||
height = heightAllowed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeasuredDimension(width, height);
|
setMeasuredDimension(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,15 +445,13 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
private int getPreferredWidth() {
|
private int getPreferredWidth() {
|
||||||
int width = getPreferredHeight();
|
int width = getPreferredHeight();
|
||||||
if (mShowAlphaPanel)
|
width -= PANEL_SPACING + ALPHA_PANEL_HEIGHT;
|
||||||
width -= (PANEL_SPACING + ALPHA_PANEL_HEIGHT);
|
|
||||||
return (int) (width + HUE_PANEL_WIDTH + PANEL_SPACING);
|
return (int) (width + HUE_PANEL_WIDTH + PANEL_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getPreferredHeight() {
|
private int getPreferredHeight() {
|
||||||
int height = (int)(200 * mDensity);
|
int height = (int)(200 * mDensity);
|
||||||
if (mShowAlphaPanel)
|
height += PANEL_SPACING + ALPHA_PANEL_HEIGHT;
|
||||||
height += PANEL_SPACING + ALPHA_PANEL_HEIGHT;
|
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,9 +473,7 @@ public class ColorPickerView extends View {
|
||||||
private void setUpSatValRect() {
|
private void setUpSatValRect() {
|
||||||
final RectF dRect = mDrawingRect;
|
final RectF dRect = mDrawingRect;
|
||||||
float panelSide = dRect.height() - BORDER_WIDTH_PX * 2;
|
float panelSide = dRect.height() - BORDER_WIDTH_PX * 2;
|
||||||
|
panelSide -= PANEL_SPACING + ALPHA_PANEL_HEIGHT;
|
||||||
if (mShowAlphaPanel)
|
|
||||||
panelSide -= PANEL_SPACING + ALPHA_PANEL_HEIGHT;
|
|
||||||
|
|
||||||
float left = dRect.left + BORDER_WIDTH_PX;
|
float left = dRect.left + BORDER_WIDTH_PX;
|
||||||
float top = dRect.top + BORDER_WIDTH_PX;
|
float top = dRect.top + BORDER_WIDTH_PX;
|
||||||
|
@ -551,17 +488,13 @@ public class ColorPickerView extends View {
|
||||||
|
|
||||||
float left = dRect.right - HUE_PANEL_WIDTH + BORDER_WIDTH_PX;
|
float left = dRect.right - HUE_PANEL_WIDTH + BORDER_WIDTH_PX;
|
||||||
float top = dRect.top + BORDER_WIDTH_PX;
|
float top = dRect.top + BORDER_WIDTH_PX;
|
||||||
float bottom = dRect.bottom - BORDER_WIDTH_PX -
|
float bottom = dRect.bottom - BORDER_WIDTH_PX - (PANEL_SPACING + ALPHA_PANEL_HEIGHT);
|
||||||
(mShowAlphaPanel ? (PANEL_SPACING + ALPHA_PANEL_HEIGHT) : 0);
|
|
||||||
float right = dRect.right - BORDER_WIDTH_PX;
|
float right = dRect.right - BORDER_WIDTH_PX;
|
||||||
|
|
||||||
mHueRect = new RectF(left, top, right, bottom);
|
mHueRect = new RectF(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpAlphaRect() {
|
private void setUpAlphaRect() {
|
||||||
if (!mShowAlphaPanel)
|
|
||||||
return;
|
|
||||||
|
|
||||||
final RectF dRect = mDrawingRect;
|
final RectF dRect = mDrawingRect;
|
||||||
|
|
||||||
float left = dRect.left + BORDER_WIDTH_PX;
|
float left = dRect.left + BORDER_WIDTH_PX;
|
||||||
|
@ -575,8 +508,7 @@ public class ColorPickerView extends View {
|
||||||
mAlphaPattern.setBounds(Math.round(mAlphaRect.left),
|
mAlphaPattern.setBounds(Math.round(mAlphaRect.left),
|
||||||
Math.round(mAlphaRect.top),
|
Math.round(mAlphaRect.top),
|
||||||
Math.round(mAlphaRect.right),
|
Math.round(mAlphaRect.right),
|
||||||
Math.round(mAlphaRect.bottom)
|
Math.round(mAlphaRect.bottom));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -595,14 +527,6 @@ public class ColorPickerView extends View {
|
||||||
return Color.HSVToColor(mAlpha, new float[]{mHue,mSat,mVal});
|
return Color.HSVToColor(mAlpha, new float[]{mHue,mSat,mVal});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the color the view should show.
|
|
||||||
* @param color The color that should be selected.
|
|
||||||
*/
|
|
||||||
public void setColor(int color) {
|
|
||||||
setColor(color, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the color this view should show.
|
* Set the color this view should show.
|
||||||
* @param color The color that should be selected.
|
* @param color The color that should be selected.
|
||||||
|
@ -640,30 +564,4 @@ public class ColorPickerView extends View {
|
||||||
public float getDrawingOffset() {
|
public float getDrawingOffset() {
|
||||||
return mDrawingOffset;
|
return mDrawingOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set if the user is allowed to adjust the alpha panel. Default is false.
|
|
||||||
* If it is set to false no alpha will be set.
|
|
||||||
*/
|
|
||||||
public void setAlphaSliderVisible(boolean visible) {
|
|
||||||
if (mShowAlphaPanel != visible) {
|
|
||||||
mShowAlphaPanel = visible;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset all shader to force a recreation.
|
|
||||||
* Otherwise they will not look right after
|
|
||||||
* the size of the view has changed.
|
|
||||||
*/
|
|
||||||
mValShader = null;
|
|
||||||
mSatShader = null;
|
|
||||||
mHueShader = null;
|
|
||||||
mAlphaShader = null;
|
|
||||||
|
|
||||||
requestLayout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getAlphaSliderVisible() {
|
|
||||||
return mShowAlphaPanel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,91 +225,76 @@
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_brightSquare"
|
android:key="color_brightSquare"
|
||||||
android:title="@string/prefs_color_brightSquare_title"
|
android:title="@string/prefs_color_brightSquare_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FFFFFFFA">
|
android:defaultValue="#FFFFFFFA">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_darkSquare"
|
android:key="color_darkSquare"
|
||||||
android:title="@string/prefs_color_darkSquare_title"
|
android:title="@string/prefs_color_darkSquare_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FF83A5D2">
|
android:defaultValue="#FF83A5D2">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_selectedSquare"
|
android:key="color_selectedSquare"
|
||||||
android:title="@string/prefs_color_selectedSquare_title"
|
android:title="@string/prefs_color_selectedSquare_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FF3232D1">
|
android:defaultValue="#FF3232D1">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_brightPiece"
|
android:key="color_brightPiece"
|
||||||
android:title="@string/prefs_color_brightPiece_title"
|
android:title="@string/prefs_color_brightPiece_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FFF0F0F0">
|
android:defaultValue="#FFF0F0F0">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_darkPiece"
|
android:key="color_darkPiece"
|
||||||
android:title="@string/prefs_color_darkPiece_title"
|
android:title="@string/prefs_color_darkPiece_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FF282828">
|
android:defaultValue="#FF282828">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow0"
|
android:key="color_arrow0"
|
||||||
android:title="@string/prefs_color_arrow0_title"
|
android:title="@string/prefs_color_arrow0_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#A01F1FFF">
|
android:defaultValue="#A01F1FFF">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow1"
|
android:key="color_arrow1"
|
||||||
android:title="@string/prefs_color_arrow1_title"
|
android:title="@string/prefs_color_arrow1_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#A01FFF1F">
|
android:defaultValue="#A01FFF1F">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow2"
|
android:key="color_arrow2"
|
||||||
android:title="@string/prefs_color_arrow2_title"
|
android:title="@string/prefs_color_arrow2_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#501F1FFF">
|
android:defaultValue="#501F1FFF">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow3"
|
android:key="color_arrow3"
|
||||||
android:title="@string/prefs_color_arrow3_title"
|
android:title="@string/prefs_color_arrow3_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#501FFF1F">
|
android:defaultValue="#501FFF1F">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow4"
|
android:key="color_arrow4"
|
||||||
android:title="@string/prefs_color_arrow4_title"
|
android:title="@string/prefs_color_arrow4_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#371F1FFF">
|
android:defaultValue="#371F1FFF">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow5"
|
android:key="color_arrow5"
|
||||||
android:title="@string/prefs_color_arrow5_title"
|
android:title="@string/prefs_color_arrow5_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#3C1FFF1F">
|
android:defaultValue="#3C1FFF1F">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow6"
|
android:key="color_arrow6"
|
||||||
android:title="@string/prefs_color_arrow6_title"
|
android:title="@string/prefs_color_arrow6_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#1E1F1FFF">
|
android:defaultValue="#1E1F1FFF">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_arrow7"
|
android:key="color_arrow7"
|
||||||
android:title="@string/prefs_color_arrow7_title"
|
android:title="@string/prefs_color_arrow7_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#281FFF1F">
|
android:defaultValue="#281FFF1F">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_squareLabel"
|
android:key="color_squareLabel"
|
||||||
android:title="@string/prefs_color_squareLabel_title"
|
android:title="@string/prefs_color_squareLabel_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FFFF0000">
|
android:defaultValue="#FFFF0000">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_decoration"
|
android:key="color_decoration"
|
||||||
android:title="@string/prefs_color_decoration_title"
|
android:title="@string/prefs_color_decoration_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FF808080">
|
android:defaultValue="#FF808080">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
@ -318,25 +303,21 @@
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_currentMove"
|
android:key="color_currentMove"
|
||||||
android:title="@string/prefs_color_currentMove_title"
|
android:title="@string/prefs_color_currentMove_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FF3333FF">
|
android:defaultValue="#FF3333FF">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_pgnComment"
|
android:key="color_pgnComment"
|
||||||
android:title="@string/prefs_color_pgnComment_title"
|
android:title="@string/prefs_color_pgnComment_title"
|
||||||
alphaSlider="true"
|
|
||||||
android:defaultValue="#FFC0C000">
|
android:defaultValue="#FFC0C000">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_fontForeground"
|
android:key="color_fontForeground"
|
||||||
android:title="@string/prefs_color_fontForeground_title"
|
android:title="@string/prefs_color_fontForeground_title"
|
||||||
alphaSlider="false"
|
|
||||||
android:defaultValue="#FFFFFF00">
|
android:defaultValue="#FFFFFF00">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
<net.margaritov.preference.colorpicker.ColorPickerPreference
|
||||||
android:key="color_generalBackground"
|
android:key="color_generalBackground"
|
||||||
android:title="@string/prefs_color_generalBackground_title"
|
android:title="@string/prefs_color_generalBackground_title"
|
||||||
alphaSlider="false"
|
|
||||||
android:defaultValue="#FF2E2B53">
|
android:defaultValue="#FF2E2B53">
|
||||||
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
</net.margaritov.preference.colorpicker.ColorPickerPreference>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user