material-range-bar
material-range-bar copied to clipboard
Fixed Bug when the distance between mLeftThumb and mRightThumb is too close, click mRightThumb always make mLeftThumb be clicked.
In onActionDown()
of RangeBar, add these code before if (!mRightThumb.isPressed() && mLeftThumb.isInTargetZone(x, y))
, maybe (!mLeftThumb.isPressed() || !mRightThumb.isPressed())
is unnecessary ? I haven't to concern that, if you check it, please tell me.
if ((!mLeftThumb.isPressed() || !mRightThumb.isPressed()) && mLeftThumb.isInTargetZone(x, y) && mRightThumb.isInTargetZone(x, y)) {
if (Math.abs(x - mLeftThumb.getX()) <= Math.abs(x - mRightThumb.getX())) {
pressPin(mLeftThumb);
} else {
pressPin(mRightThumb);
}
return;
}
And make the code like this:
private void onActionDown(float x, float y) {
if (mIsRangeBar) {
if ((!mLeftThumb.isPressed() || !mRightThumb.isPressed()) && mLeftThumb.isInTargetZone(x, y) && mRightThumb.isInTargetZone(x, y)) {
if (Math.abs(x - mLeftThumb.getX()) <= Math.abs(x - mRightThumb.getX())) {
pressPin(mLeftThumb);
} else {
pressPin(mRightThumb);
}
return;
}
if (!mRightThumb.isPressed() && mLeftThumb.isInTargetZone(x, y)) {
pressPin(mLeftThumb);
} else if (!mLeftThumb.isPressed() && mRightThumb.isInTargetZone(x, y)) {
pressPin(mRightThumb);
}
} else {
if (mRightThumb.isInTargetZone(x, y)) {
pressPin(mRightThumb);
}
}
}