Skip to content

Commit

Permalink
Changed return type of all color changing methods (*bar touch changes…
Browse files Browse the repository at this point in the history
…, circle touch change with color manipulation through bars) to "int" (containing the color value). With a few additional tweaks the listener does not get notified about the intermediate steps when bars are attached to ColorPicker. Fixes LarsWerkman#60 of the original repository.
  • Loading branch information
ilueckel committed Jun 14, 2015
1 parent c8a9d33 commit 6e0375a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,24 +628,26 @@ else if (Math.sqrt(x*x + y*y) <= mColorWheelRadius + mColorPointerHaloRadius
mAngle = (float) Math.atan2(y - mSlopY, x - mSlopX);
mPointerColor.setColor(calculateColor(mAngle));

setNewCenterColor(mCenterNewColor = calculateColor(mAngle));
mCenterNewColor = calculateColor(mAngle);

if (mOpacityBar != null) {
mOpacityBar.setColor(mColor);
mColor = mOpacityBar.setColor(mColor);
}

if (mValueBar != null) {
mValueBar.setColor(mColor);
mColor = mValueBar.setColor(mColor);
}

if (mSaturationBar != null) {
mSaturationBar.setColor(mColor);
mColor = mSaturationBar.setColor(mColor);
}

if (mSVbar != null) {
mSVbar.setColor(mColor);
mColor = mSVbar.setColor(mColor);
}

setNewCenterColor(mColor);

invalidate();
}
// If user did not press pointer or center, report event not handled
Expand Down Expand Up @@ -781,10 +783,11 @@ public boolean getShowOldCenterColor() {
*
* @param color int of the color used to change the opacity bar color.
*/
public void changeOpacityBarColor(int color) {
public int changeOpacityBarColor(int color) {
if (mOpacityBar != null) {
mOpacityBar.setColor(color);
return mOpacityBar.setColor(color);
}
return color;
}

/**
Expand All @@ -793,21 +796,23 @@ public void changeOpacityBarColor(int color) {
* @param color
* int of the color used to change the opacity bar color.
*/
public void changeSaturationBarColor(int color) {
public int changeSaturationBarColor(int color) {
if (mSaturationBar != null) {
mSaturationBar.setColor(color);
return mSaturationBar.setColor(color);
}
return color;
}

/**
* Used to change the color of the {@code ValueBar}.
*
* @param color int of the color used to change the opacity bar color.
*/
public void changeValueBarColor(int color) {
public int changeValueBarColor(int color) {
if (mValueBar != null) {
mValueBar.setColor(color);
return mValueBar.setColor(color);
}
return color;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,12 @@ public boolean onTouchEvent(MotionEvent event) {
*
* @param color
*/
public void setColor(int color) {
public int setColor(int color) {
int x1, y1;
if(mOrientation == ORIENTATION_HORIZONTAL) {
if(mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
y1 = mBarThickness;
}
else {
} else {
x1 = mBarThickness;
y1 = (mBarLength + mBarPointerHaloRadius);
}
Expand All @@ -428,10 +427,11 @@ public void setColor(int color) {
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
}
// if (mPicker != null) {
// mPicker.setNewCenterColor(mColor);
// }
invalidate();
return mColor;
}

/**
Expand Down
20 changes: 8 additions & 12 deletions libary/src/main/java/com/larswerkman/holocolorpicker/SVBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,26 @@ public boolean onTouchEvent(MotionEvent event) {
calculateColor(Math.round(dimen));
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen < mBarPointerHaloRadius) {
mBarPointerPosition = mBarPointerHaloRadius;
mColor = Color.WHITE;
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen > (mBarPointerHaloRadius + mBarLength)) {
mBarPointerPosition = mBarPointerHaloRadius + mBarLength;
mColor = Color.BLACK;
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand All @@ -395,8 +395,8 @@ public void setSaturation(float saturation) {
// Check whether the Saturation/Value bar is added to the ColorPicker
// wheel
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand All @@ -414,8 +414,8 @@ public void setValue(float value) {
// Check whether the Saturation/Value bar is added to the ColorPicker
// wheel
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand All @@ -427,7 +427,7 @@ public void setValue(float value) {
*
* @param color
*/
public void setColor(int color) {
public int setColor(int color) {
int x1, y1;
if(mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
Expand All @@ -442,14 +442,10 @@ public void setColor(int color) {
x1, y1, new int[] {Color.WHITE, color, Color.BLACK}, null,
Shader.TileMode.CLAMP);
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
if(mPicker.hasOpacityBar())
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
return mColor;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,29 +369,29 @@ public boolean onTouchEvent(MotionEvent event) {
calculateColor(Math.round(dimen));
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeValueBarColor(mColor);
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeValueBarColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen < mBarPointerHaloRadius) {
mBarPointerPosition = mBarPointerHaloRadius;
mColor = Color.WHITE;
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeValueBarColor(mColor);
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeValueBarColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen > (mBarPointerHaloRadius + mBarLength)) {
mBarPointerPosition = mBarPointerHaloRadius + mBarLength;
mColor = Color.HSVToColor(mHSVColor);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeValueBarColor(mColor);
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeValueBarColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand All @@ -415,9 +415,9 @@ public boolean onTouchEvent(MotionEvent event) {
*
* @param color
*/
public void setColor(int color) {
public int setColor(int color) {
int x1, y1;
if(mOrientation == ORIENTATION_HORIZONTAL) {
if(mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
y1 = mBarThickness;
}
Expand All @@ -434,14 +434,8 @@ public void setColor(int color) {
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
if(mPicker.hasValueBar())
mPicker.changeValueBarColor(mColor);
else if(mPicker.hasOpacityBar())
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
return mColor;
}

/**
Expand All @@ -454,10 +448,11 @@ public void setSaturation(float saturation) {
+ mBarPointerHaloRadius;
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);

if (mPicker != null) {
mColor = mPicker.changeValueBarColor(mColor);
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeValueBarColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand Down
21 changes: 8 additions & 13 deletions libary/src/main/java/com/larswerkman/holocolorpicker/ValueBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,26 @@ public boolean onTouchEvent(MotionEvent event) {
calculateColor(Math.round(dimen));
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen < mBarPointerHaloRadius) {
mBarPointerPosition = mBarPointerHaloRadius;
mColor = Color.HSVToColor(mHSVColor);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
} else if (dimen > (mBarPointerHaloRadius + mBarLength)) {
mBarPointerPosition = mBarPointerHaloRadius + mBarLength;
mColor = Color.BLACK;
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand All @@ -413,13 +413,12 @@ public boolean onTouchEvent(MotionEvent event) {
*
* @param color
*/
public void setColor(int color) {
public int setColor(int color) {
int x1, y1;
if(mOrientation == ORIENTATION_HORIZONTAL) {
if(mOrientation) {
x1 = (mBarLength + mBarPointerHaloRadius);
y1 = mBarThickness;
}
else {
} else {
x1 = mBarThickness;
y1 = (mBarLength + mBarPointerHaloRadius);
}
Expand All @@ -431,12 +430,8 @@ public void setColor(int color) {
mBarPaint.setShader(shader);
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mPicker.setNewCenterColor(mColor);
if(mPicker.hasOpacityBar())
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
return mColor;
}

/**
Expand All @@ -451,8 +446,8 @@ public void setValue(float value) {
calculateColor(mBarPointerPosition);
mBarPointerPaint.setColor(mColor);
if (mPicker != null) {
mColor = mPicker.changeOpacityBarColor(mColor);
mPicker.setNewCenterColor(mColor);
mPicker.changeOpacityBarColor(mColor);
}
invalidate();
}
Expand Down

1 comment on commit 6e0375a

@hoqn
Copy link

@hoqn hoqn commented on 6e0375a Oct 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! Thanks to you, I could fix problems in my project 👍 👍 👍 👍 👍 👍 👍

Please sign in to comment.