From c94446eb2ff05c5ac46a985ac7d7c79b12c75946 Mon Sep 17 00:00:00 2001 From: FromSi Date: Wed, 27 Jun 2018 18:35:56 +0600 Subject: [PATCH] Updated design --- .../holocolorpicker/ColorPicker.java | 12 ++- .../holocolorpicker/OpacityBar.java | 61 ++++++++++++- .../larswerkman/holocolorpicker/SVBar.java | 62 ++++++++++++- .../holocolorpicker/SaturationBar.java | 61 ++++++++++++- .../larswerkman/holocolorpicker/ValueBar.java | 86 +++++++++++++++---- 5 files changed, 259 insertions(+), 23 deletions(-) diff --git a/library/src/main/java/com/larswerkman/holocolorpicker/ColorPicker.java b/library/src/main/java/com/larswerkman/holocolorpicker/ColorPicker.java index ee1fd3e..38e7c52 100644 --- a/library/src/main/java/com/larswerkman/holocolorpicker/ColorPicker.java +++ b/library/src/main/java/com/larswerkman/holocolorpicker/ColorPicker.java @@ -357,7 +357,7 @@ private void init(AttributeSet attrs, int defStyle) { mColorWheelPaint.setStrokeWidth(mColorWheelThickness); mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mPointerHaloPaint.setColor(Color.BLACK); + mPointerHaloPaint.setColor(calculateColor(mAngle)); mPointerHaloPaint.setAlpha(0x50); mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -372,7 +372,7 @@ private void init(AttributeSet attrs, int defStyle) { mCenterOldPaint.setStyle(Paint.Style.FILL); mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mCenterHaloPaint.setColor(Color.BLACK); + mCenterHaloPaint.setColor(calculateColor(mAngle)); mCenterHaloPaint.setAlpha(0x00); mCenterNewColor = calculateColor(mAngle); @@ -525,6 +525,8 @@ public int getColor() { public void setColor(int color) { mAngle = colorToAngle(color); mPointerColor.setColor(calculateColor(mAngle)); + mPointerHaloPaint.setColor(calculateColor(mAngle)); + mPointerHaloPaint.setAlpha(0x50); // check of the instance isn't null if (mOpacityBar != null) { @@ -627,6 +629,8 @@ else if (Math.sqrt(x*x + y*y) <= mColorWheelRadius + mColorPointerHaloRadius if (mUserIsMovingPointer) { mAngle = (float) Math.atan2(y - mSlopY, x - mSlopX); mPointerColor.setColor(calculateColor(mAngle)); + mPointerHaloPaint.setColor(calculateColor(mAngle)); + mPointerHaloPaint.setAlpha(0x50); setNewCenterColor(mCenterNewColor = calculateColor(mAngle)); @@ -735,6 +739,8 @@ public void addValueBar(ValueBar bar) { public void setNewCenterColor(int color) { mCenterNewColor = color; mCenterNewPaint.setColor(color); + mCenterHaloPaint.setColor(color); + mCenterHaloPaint.setAlpha(0x00); if (mCenterOldColor == 0) { mCenterOldColor = color; mCenterOldPaint.setColor(color); @@ -871,6 +877,8 @@ protected void onRestoreInstanceState(Parcelable state) { mShowCenterOldColor = savedState.getBoolean(STATE_SHOW_OLD_COLOR); int currentColor = calculateColor(mAngle); mPointerColor.setColor(currentColor); + mPointerHaloPaint.setColor(currentColor); + mPointerHaloPaint.setAlpha(0x50); setNewCenterColor(currentColor); } diff --git a/library/src/main/java/com/larswerkman/holocolorpicker/OpacityBar.java b/library/src/main/java/com/larswerkman/holocolorpicker/OpacityBar.java index fccac9a..328b814 100644 --- a/library/src/main/java/com/larswerkman/holocolorpicker/OpacityBar.java +++ b/library/src/main/java/com/larswerkman/holocolorpicker/OpacityBar.java @@ -85,6 +85,11 @@ public class OpacityBar extends View { */ private Paint mBarPaint; + /** + * {@code Paint} instance used to draw the halo of the bar. + */ + private Paint mBarPaintHalo; + /** * {@code Paint} instance used to draw the pointer. */ @@ -100,11 +105,21 @@ public class OpacityBar extends View { */ private RectF mBarRect = new RectF(); + /** + * The rectangle enclosing the halo of the bar. + */ + private RectF mBarRectHalo = new RectF(); + /** * {@code Shader} instance used to fill the shader of the paint. */ private Shader shader; + /** + * {@code Shader} instance used to fill the shader of the halo of the paint. + */ + private Shader shaderHalo; + /** * {@code true} if the user clicked on the pointer to start the move mode.
* {@code false} once the user stops touching the screen. @@ -207,10 +222,14 @@ private void init(AttributeSet attrs, int defStyle) { mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBarPaint.setShader(shader); + mBarPaintHalo = new Paint(Paint.ANTI_ALIAS_FLAG); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); + mBarPointerPosition = mBarLength + mBarPointerHaloRadius; mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mBarPointerHaloPaint.setColor(Color.BLACK); + mBarPointerHaloPaint.setColor(0xff81ff00); mBarPointerHaloPaint.setAlpha(0x50); mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -273,6 +292,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { (mBarPointerHaloRadius - (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius)), (mBarPointerHaloRadius + (mBarThickness / 2))); + mBarRectHalo.set(mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f); } else { x1 = mBarThickness; @@ -282,6 +305,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBarPointerHaloRadius, (mBarPointerHaloRadius + (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius))); + mBarRectHalo.set((mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f); } // Update variables that depend of mBarLength. @@ -291,14 +318,23 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { Color.HSVToColor(0x00, mHSVColor), Color.HSVToColor(0xFF, mHSVColor) }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + Color.HSVToColor(0x00, mHSVColor), + Color.HSVToColor(0xFF, mHSVColor) }, null, + Shader.TileMode.CLAMP); } else { shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] { 0x0081ff00, 0xff81ff00 }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + 0x0081ff00, 0xff81ff00 }, null, Shader.TileMode.CLAMP); Color.colorToHSV(0xff81ff00, mHSVColor); } mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); mPosToOpacFactor = 0xFF / ((float) mBarLength); mOpacToPosFactor = ((float) mBarLength) / 0xFF; @@ -315,8 +351,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onDraw(Canvas canvas) { + // Draw the halo of the bar. + canvas.drawRoundRect(mBarRectHalo, 5, 5, mBarPaintHalo); + // Draw the bar. - canvas.drawRect(mBarRect, mBarPaint); + canvas.drawRoundRect(mBarRect, 5, 5, mBarPaint); // Calculate the center of the pointer. int cX, cY; @@ -357,6 +396,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); invalidate(); } break; @@ -368,6 +409,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } @@ -376,6 +419,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.TRANSPARENT; mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } @@ -384,6 +429,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.HSVToColor(mHSVColor); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } @@ -425,9 +472,17 @@ public void setColor(int color) { x1, y1, new int[] { Color.HSVToColor(0x00, mHSVColor), color }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + Color.HSVToColor(0x00, mHSVColor), color }, null, + Shader.TileMode.CLAMP); mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } @@ -444,6 +499,8 @@ public void setOpacity(int opacity) { + mBarPointerHaloRadius; calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); } diff --git a/library/src/main/java/com/larswerkman/holocolorpicker/SVBar.java b/library/src/main/java/com/larswerkman/holocolorpicker/SVBar.java index 352159f..4b06a0d 100644 --- a/library/src/main/java/com/larswerkman/holocolorpicker/SVBar.java +++ b/library/src/main/java/com/larswerkman/holocolorpicker/SVBar.java @@ -86,6 +86,11 @@ public class SVBar extends View { */ private Paint mBarPaint; + /** + * {@code Paint} instance used to draw the halo of the bar. + */ + private Paint mBarPaintHalo; + /** * {@code Paint} instance used to draw the pointer. */ @@ -101,11 +106,21 @@ public class SVBar extends View { */ private RectF mBarRect = new RectF(); + /** + * The rectangle enclosing the halo of the bar. + */ + private RectF mBarRectHalo = new RectF(); + /** * {@code Shader} instance used to fill the shader of the paint. */ private Shader shader; + /** + * {@code Shader} instance used to fill the shader of the halo of the paint. + */ + private Shader shaderHalo; + /** * {@code true} if the user clicked on the pointer to start the move mode.
* {@code false} once the user stops touching the screen. @@ -185,10 +200,14 @@ private void init(AttributeSet attrs, int defStyle) { mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBarPaint.setShader(shader); + mBarPaintHalo = new Paint(Paint.ANTI_ALIAS_FLAG); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); + mBarPointerPosition = (mBarLength / 2) + mBarPointerHaloRadius; mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mBarPointerHaloPaint.setColor(Color.BLACK); + mBarPointerHaloPaint.setColor(0xff81ff00); mBarPointerHaloPaint.setAlpha(0x50); mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -251,6 +270,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { (mBarPointerHaloRadius - (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius)), (mBarPointerHaloRadius + (mBarThickness / 2))); + mBarRectHalo.set(mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f); } else { x1 = mBarThickness; @@ -260,6 +283,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBarPointerHaloRadius, (mBarPointerHaloRadius + (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius))); + mBarRectHalo.set((mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f); } // Update variables that depend of mBarLength. @@ -268,15 +295,24 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { x1, y1, new int[] { 0xffffffff, Color.HSVToColor(mHSVColor), 0xff000000 }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + 0xffffffff, Color.HSVToColor(mHSVColor), 0xff000000 }, + null, Shader.TileMode.CLAMP); } else { shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] { 0xffffffff, 0xff81ff00, 0xff000000 }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + 0xffffffff, 0xff81ff00, 0xff000000 }, null, + Shader.TileMode.CLAMP); Color.colorToHSV(0xff81ff00, mHSVColor); } mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); mPosToSVFactor = 1 / ((float) mBarLength / 2); mSVToPosFactor = ((float) mBarLength / 2) / 1; float[] hsvColor = new float[3]; @@ -296,8 +332,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onDraw(Canvas canvas) { + // Draw the halo of the bar. + canvas.drawRoundRect(mBarRectHalo, 5, 5, mBarPaintHalo); + // Draw the bar. - canvas.drawRect(mBarRect, mBarPaint); + canvas.drawRoundRect(mBarRect, 5, 5, mBarPaint); // Calculate the center of the pointer. int cX, cY; @@ -338,6 +377,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); invalidate(); } break; @@ -349,6 +390,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -358,6 +401,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.WHITE; mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -367,6 +412,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.BLACK; mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -392,6 +439,8 @@ public void setSaturation(float saturation) { + mBarPointerHaloRadius); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); // Check whether the Saturation/Value bar is added to the ColorPicker // wheel if (mPicker != null) { @@ -411,6 +460,8 @@ public void setValue(float value) { + mBarPointerHaloRadius + (mBarLength / 2)); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); // Check whether the Saturation/Value bar is added to the ColorPicker // wheel if (mPicker != null) { @@ -441,9 +492,16 @@ public void setColor(int color) { shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null, + Shader.TileMode.CLAMP); mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); if(mPicker.hasOpacityBar()) diff --git a/library/src/main/java/com/larswerkman/holocolorpicker/SaturationBar.java b/library/src/main/java/com/larswerkman/holocolorpicker/SaturationBar.java index fd736ea..102955a 100644 --- a/library/src/main/java/com/larswerkman/holocolorpicker/SaturationBar.java +++ b/library/src/main/java/com/larswerkman/holocolorpicker/SaturationBar.java @@ -85,6 +85,11 @@ public class SaturationBar extends View { */ private Paint mBarPaint; + /** + * {@code Paint} instance used to draw the halo of the bar. + */ + private Paint mBarPaintHalo; + /** * {@code Paint} instance used to draw the pointer. */ @@ -100,11 +105,21 @@ public class SaturationBar extends View { */ private RectF mBarRect = new RectF(); + /** + * The rectangle enclosing the halo of the bar. + */ + private RectF mBarRectHalo = new RectF(); + /** * {@code Shader} instance used to fill the shader of the paint. */ private Shader shader; + /** + * {@code Shader} instance used to fill the shader of the halo of the paint. + */ + private Shader shaderHalo; + /** * {@code true} if the user clicked on the pointer to start the move mode.
* {@code false} once the user stops touching the screen. @@ -207,10 +222,14 @@ private void init(AttributeSet attrs, int defStyle) { mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBarPaint.setShader(shader); + mBarPaintHalo = new Paint(Paint.ANTI_ALIAS_FLAG); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); + mBarPointerPosition = mBarLength + mBarPointerHaloRadius; mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mBarPointerHaloPaint.setColor(Color.BLACK); + mBarPointerHaloPaint.setColor(0xff81ff00); mBarPointerHaloPaint.setAlpha(0x50); mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -273,6 +292,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { (mBarPointerHaloRadius - (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius)), (mBarPointerHaloRadius + (mBarThickness / 2))); + mBarRectHalo.set(mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f); } else { x1 = mBarThickness; @@ -282,6 +305,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBarPointerHaloRadius, (mBarPointerHaloRadius + (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius))); + mBarRectHalo.set((mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f); } // Update variables that depend of mBarLength. @@ -291,14 +318,23 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { Color.WHITE, Color.HSVToColor(0xFF, mHSVColor) }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + Color.WHITE, + Color.HSVToColor(0xFF, mHSVColor) }, null, + Shader.TileMode.CLAMP); } else { shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] { Color.WHITE, 0xff81ff00 }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + Color.WHITE, 0xff81ff00 }, null, Shader.TileMode.CLAMP); Color.colorToHSV(0xff81ff00, mHSVColor); } mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); mPosToSatFactor = 1 / ((float) mBarLength); mSatToPosFactor = ((float) mBarLength) / 1; @@ -315,8 +351,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onDraw(Canvas canvas) { + // Draw the halo of the bar. + canvas.drawRoundRect(mBarRectHalo, 5, 5, mBarPaintHalo); + // Draw the bar. - canvas.drawRect(mBarRect, mBarPaint); + canvas.drawRoundRect(mBarRect, 5, 5, mBarPaint); // Calculate the center of the pointer. int cX, cY; @@ -357,6 +396,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); invalidate(); } break; @@ -368,6 +409,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeValueBarColor(mColor); @@ -378,6 +421,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.WHITE; mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeValueBarColor(mColor); @@ -388,6 +433,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.HSVToColor(mHSVColor); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeValueBarColor(mColor); @@ -431,9 +478,17 @@ public void setColor(int color) { x1, y1, new int[] { Color.WHITE, color }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + Color.WHITE, color }, null, + Shader.TileMode.CLAMP); mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); if(mPicker.hasValueBar()) @@ -454,6 +509,8 @@ public void setSaturation(float saturation) { + mBarPointerHaloRadius; calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeValueBarColor(mColor); diff --git a/library/src/main/java/com/larswerkman/holocolorpicker/ValueBar.java b/library/src/main/java/com/larswerkman/holocolorpicker/ValueBar.java index 93e337e..ffd1158 100644 --- a/library/src/main/java/com/larswerkman/holocolorpicker/ValueBar.java +++ b/library/src/main/java/com/larswerkman/holocolorpicker/ValueBar.java @@ -42,13 +42,13 @@ public class ValueBar extends View { private static final String STATE_COLOR = "color"; private static final String STATE_VALUE = "value"; private static final String STATE_ORIENTATION = "orientation"; - + /** * Constants used to identify orientation. */ private static final boolean ORIENTATION_HORIZONTAL = true; private static final boolean ORIENTATION_VERTICAL = false; - + /** * Default orientation of the bar. */ @@ -85,6 +85,11 @@ public class ValueBar extends View { */ private Paint mBarPaint; + /** + * {@code Paint} instance used to draw the halo of the bar. + */ + private Paint mBarPaintHalo; + /** * {@code Paint} instance used to draw the pointer. */ @@ -100,15 +105,25 @@ public class ValueBar extends View { */ private RectF mBarRect = new RectF(); + /** + * The rectangle enclosing the halo of the bar. + */ + private RectF mBarRectHalo = new RectF(); + /** * {@code Shader} instance used to fill the shader of the paint. */ private Shader shader; + /** + * {@code Shader} instance used to fill the shader of the halo of the paint. + */ + private Shader shaderHalo; + /** * {@code true} if the user clicked on the pointer to start the move mode.
* {@code false} once the user stops touching the screen. - * + * * @see #onTouchEvent(android.view.MotionEvent) */ private boolean mIsMovingPointer; @@ -143,13 +158,13 @@ public class ValueBar extends View { * Used to toggle orientation between vertical and horizontal. */ private boolean mOrientation; - + /** * Interface and listener so that changes in ValueBar are sent * to the host activity/fragment */ private OnValueChangedListener onValueChangedListener; - + /** * Value of the latest entry of the onValueChangedListener. */ @@ -207,10 +222,14 @@ private void init(AttributeSet attrs, int defStyle) { mBarPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBarPaint.setShader(shader); + mBarPaintHalo = new Paint(Paint.ANTI_ALIAS_FLAG); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); + mBarPointerPosition = mBarPointerHaloRadius; mBarPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mBarPointerHaloPaint.setColor(Color.BLACK); + mBarPointerHaloPaint.setColor(0xff81ff00); mBarPointerHaloPaint.setAlpha(0x50); mBarPointerPaint = new Paint(Paint.ANTI_ALIAS_FLAG); @@ -273,6 +292,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { (mBarPointerHaloRadius - (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius)), (mBarPointerHaloRadius + (mBarThickness / 2))); + mBarRectHalo.set(mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f); } else { x1 = mBarThickness; @@ -282,6 +305,10 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { mBarPointerHaloRadius, (mBarPointerHaloRadius + (mBarThickness / 2)), (mBarLength + (mBarPointerHaloRadius))); + mBarRectHalo.set((mBarPointerHaloRadius - (mBarThickness / 2)) - 2f, + mBarPointerHaloRadius - 2f, + (mBarPointerHaloRadius + (mBarThickness / 2)) + 2f, + (mBarLength + (mBarPointerHaloRadius)) + 2f); } // Update variables that depend of mBarLength. @@ -290,15 +317,24 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { x1, y1, new int[] { Color.HSVToColor(0xFF, mHSVColor), Color.BLACK }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, + new int[] { Color.HSVToColor(0xFF, mHSVColor), Color.BLACK }, + null, Shader.TileMode.CLAMP); } else { shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] { 0xff81ff00, Color.BLACK }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, + new int[] { 0xff81ff00, Color.BLACK }, null, + Shader.TileMode.CLAMP); Color.colorToHSV(0xff81ff00, mHSVColor); } mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); mPosToSatFactor = 1 / ((float) mBarLength); mSatToPosFactor = ((float) mBarLength) / 1; @@ -316,8 +352,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { @Override protected void onDraw(Canvas canvas) { + // Draw the halo of the bar. + canvas.drawRoundRect(mBarRectHalo, 5, 5, mBarPaintHalo); + // Draw the bar. - canvas.drawRect(mBarRect, mBarPaint); + canvas.drawRoundRect(mBarRect, 5, 5, mBarPaint); // Calculate the center of the pointer. int cX, cY; @@ -329,7 +368,7 @@ protected void onDraw(Canvas canvas) { cX = mBarPointerHaloRadius; cY = mBarPointerPosition; } - + // Draw the pointer halo. canvas.drawCircle(cX, cY, mBarPointerHaloRadius, mBarPointerHaloPaint); // Draw the pointer. @@ -358,6 +397,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); invalidate(); } break; @@ -369,6 +410,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = Math.round(dimen); calculateColor(Math.round(dimen)); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -378,6 +421,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius; mColor = Color.HSVToColor(mHSVColor); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -387,6 +432,8 @@ public boolean onTouchEvent(MotionEvent event) { mBarPointerPosition = mBarPointerHaloRadius + mBarLength; mColor = Color.BLACK; mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); @@ -410,7 +457,7 @@ public boolean onTouchEvent(MotionEvent event) { * Set the bar color.
*
* Its discouraged to use this method. - * + * * @param color */ public void setColor(int color) { @@ -423,14 +470,21 @@ public void setColor(int color) { x1 = mBarThickness; y1 = (mBarLength + mBarPointerHaloRadius); } - + Color.colorToHSV(color, mHSVColor); shader = new LinearGradient(mBarPointerHaloRadius, 0, x1, y1, new int[] { color, Color.BLACK }, null, Shader.TileMode.CLAMP); + shaderHalo = new LinearGradient(mBarPointerHaloRadius, 0, + x1, y1, new int[] { + color, Color.BLACK }, null, Shader.TileMode.CLAMP); mBarPaint.setShader(shader); + mBarPaintHalo.setShader(shaderHalo); + mBarPaintHalo.setAlpha(0x50); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); if(mPicker.hasOpacityBar()) @@ -441,7 +495,7 @@ public void setColor(int color) { /** * Set the pointer on the bar. With the opacity value. - * + * * @param value float between 0 and 1 */ public void setValue(float value) { @@ -450,16 +504,18 @@ public void setValue(float value) { + mBarPointerHaloRadius); calculateColor(mBarPointerPosition); mBarPointerPaint.setColor(mColor); + mBarPointerHaloPaint.setColor(mColor); + mBarPointerHaloPaint.setAlpha(0x50); if (mPicker != null) { mPicker.setNewCenterColor(mColor); mPicker.changeOpacityBarColor(mColor); } invalidate(); } - + /** * Calculate the color selected by the pointer on the bar. - * + * * @param coord Coordinate of the pointer. */ private void calculateColor(int coord) { @@ -476,7 +532,7 @@ private void calculateColor(int coord) { /** * Get the currently selected color. - * + * * @return The ARGB value of the currently selected color. */ public int getColor() { @@ -488,7 +544,7 @@ public int getColor() { *
* WARNING: Don't change the color picker. it is done already when the bar * is added to the ColorPicker - * + * * @see com.larswerkman.holocolorpicker.ColorPicker#addSVBar(com.larswerkman.holocolorpicker.SVBar) * @param picker */