Code cleanup

This commit is contained in:
Peter Osterlund 2020-03-22 16:41:00 +01:00
parent 7ea6a9862f
commit d3c4be4737
2 changed files with 35 additions and 81 deletions

View File

@ -31,22 +31,18 @@ import android.view.View;
*/
public class ColorPickerPanelView extends View {
/**
* The width in pixels of the border
* surrounding the color panel.
*/
/** The width in pixels of the border surrounding the color panel. */
private final static float BORDER_WIDTH_PX = 1;
private float mDensity = 1f;
private int mBorderColor = 0xff6E6E6E;
private int mColor = 0xff000000;
private Paint mBorderPaint;
private Paint mColorPaint;
private Paint mBorderPaint = new Paint();
private Paint mColorPaint = new Paint();
private RectF mDrawingRect;
private RectF mColorRect;
private RectF mDrawingRect;
private RectF mColorRect;
private AlphaPatternDrawable mAlphaPattern;
@ -65,27 +61,21 @@ public class ColorPickerPanelView extends View {
}
private void init() {
mBorderPaint = new Paint();
mColorPaint = new Paint();
mDensity = getContext().getResources().getDisplayMetrics().density;
}
@Override
protected void onDraw(Canvas canvas) {
final RectF rect = mColorRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
mBorderPaint.setColor(0xff6E6E6E);
canvas.drawRect(mDrawingRect, mBorderPaint);
}
if (mAlphaPattern != null) {
if (mAlphaPattern != null)
mAlphaPattern.draw(canvas);
}
mColorPaint.setColor(mColor);
canvas.drawRect(rect, mColorPaint);
canvas.drawRect(mColorRect, mColorPaint);
}
@Override
@ -121,12 +111,10 @@ public class ColorPickerPanelView extends View {
mAlphaPattern = new AlphaPatternDrawable((int)(5 * mDensity));
mAlphaPattern.setBounds(
Math.round(mColorRect.left),
Math.round(mColorRect.top),
Math.round(mColorRect.right),
Math.round(mColorRect.bottom)
);
mAlphaPattern.setBounds(Math.round(mColorRect.left),
Math.round(mColorRect.top),
Math.round(mColorRect.right),
Math.round(mColorRect.bottom));
}
/**
@ -138,24 +126,9 @@ public class ColorPickerPanelView extends View {
}
/**
* Get the color currently show by this view.
* Get the color currently shown by this view.
*/
public int getColor() {
return mColor;
}
/**
* Set the color of the border surrounding the panel.
*/
public void setBorderColor(int color) {
mBorderColor = color;
invalidate();
}
/**
* Get the color of the border surrounding the panel.
*/
public int getBorderColor() {
return mBorderColor;
}
}

View File

@ -34,41 +34,28 @@ import android.view.MotionEvent;
import android.view.View;
/**
* Displays a color picker to the user and allow them
* to select a color.
* Displays a color picker to the user and allow them to select a color.
* @author Daniel Nilsson
*/
@SuppressLint("ClickableViewAccessibility")
public class ColorPickerView extends View {
/**
* The width in pixels of the border
* surrounding all color panels.
*/
/** The width in pixels of the border surrounding all color panels. */
private final static float BORDER_WIDTH_PX = 1;
/**
* The width in dp of the hue panel.
*/
/** The width in dp of the hue panel. */
private float HUE_PANEL_WIDTH = 30f;
/**
* The height in dp of the alpha panel
*/
private float ALPHA_PANEL_HEIGHT = 20f;
/**
* The distance in dp between the different
* color panels.
*/
/** The height in dp of the alpha panel */
private float ALPHA_PANEL_HEIGHT = 20f;
/** The distance in dp between the different color panels. */
private float PANEL_SPACING = 10f;
/**
* The radius in dp of the color palette tracker circle.
*/
/** The radius in dp of the color palette tracker circle. */
private float PALETTE_CIRCLE_TRACKER_RADIUS = 5f;
/**
* The dp which the tracker of the hue or alpha panel
* will extend outside of its bounds.
*/
private float RECTANGLE_TRACKER_OFFSET = 2f;
/** The dp which the tracker of the hue or alpha panel will extend outside of its bounds. */
private float RECTANGLE_TRACKER_OFFSET = 2f;
private float mDensity = 1f;
@ -91,26 +78,20 @@ public class ColorPickerView extends View {
private final int mBorderColor = 0xff6E6E6E;
/**
* Offset from the edge we must have or else
* the finger tracker will get clipped when
* it is drawn outside of the view.
*/
/** Offset from the edge we must have or else the finger tracker will
* get clipped when it is drawn outside of the view. */
private float mDrawingOffset;
/*
* Distance form the edges of the view
* of where we are allowed to draw.
*/
private RectF mDrawingRect;
/** Distance form the edges of the view of where we are allowed to draw. */
private RectF mDrawingRect;
private RectF mSatValRect;
private RectF mHueRect;
private RectF mAlphaRect;
private RectF mSatValRect;
private RectF mHueRect;
private RectF mAlphaRect;
private AlphaPatternDrawable mAlphaPattern;
private AlphaPatternDrawable mAlphaPattern;
private Point mStartTouchPoint = null;
private Point mStartTouchPoint = null;
public interface OnColorChangedListener {
void onColorChanged(int color);