Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated design #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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. <br>
* {@code false} once the user stops touching the screen.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Loading