Skip to content

Commit

Permalink
closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
bmx666 committed May 26, 2017
1 parent 609baad commit 669884c
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions lib/src/main/java/io/apptik/widget/MultiSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public interface OnTrackingChangeListener {
boolean mMirrorForRtl = true;

//list of all the loaded thumbs
private LinkedList<Thumb> mThumbs;
private final LinkedList<Thumb> mThumbs = new LinkedList<>();


/**
Expand All @@ -133,7 +133,7 @@ public interface OnTrackingChangeListener {
private int mScaledTouchSlop;
private float mTouchDownX;
//thumbs that are currently being dragged
private List<Thumb> mDraggingThumbs = new LinkedList<>();
private final List<Thumb> mDraggingThumbs = new LinkedList<>();
//thumbs that are currently being touched
LinkedList<Thumb> exactTouched = null;

Expand Down Expand Up @@ -580,7 +580,6 @@ private void initMultiSlider(int numThumbs) {
mMaxWidth = 48;
mMinHeight = 24;
mMaxHeight = 48;
mThumbs = new LinkedList<Thumb>();

for (int i = 0; i < numThumbs; i++) {
mThumbs.add(new Thumb().setMin(mScaleMin).setMax(mScaleMax).setTag("thumb " + i));
Expand Down Expand Up @@ -1123,34 +1122,40 @@ public void jumpDrawablesToCurrentState() {

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
if (mDraggingThumbs != null && !mDraggingThumbs.isEmpty()) {
int[] state = getDrawableState();
for (Thumb thumb : mDraggingThumbs) {
if (thumb.getThumb() != null)
thumb.getThumb().setState(state);
}
for (Thumb thumb : mThumbs) {
if (!mDraggingThumbs.contains(thumb) && thumb.getThumb() != null && thumb
.getThumb().isStateful()) {
if (thumb.isEnabled()) {
thumb.getThumb().setState(new int[]{android.R.attr.state_enabled});
} else {
thumb.getThumb().setState(new int[]{-android.R.attr.state_enabled});
synchronized (mDraggingThumbs) {
if (!mDraggingThumbs.isEmpty()) {
int[] state = getDrawableState();
for (Thumb thumb : mDraggingThumbs) {
if (thumb.getThumb() != null) {
thumb.getThumb().setState(state);
}
}
}
} else {
for (Thumb thumb : mThumbs) {
if (thumb.getThumb() != null && thumb.getThumb().isStateful()) {
if (thumb.isEnabled()) {
thumb.getThumb().setState(new int[]{android.R.attr.state_enabled});
} else {
thumb.getThumb().setState(new int[]{-android.R.attr.state_enabled});
for (Thumb thumb : mThumbs) {
if (!mDraggingThumbs.contains(thumb) && thumb.getThumb() != null && thumb
.getThumb().isStateful()) {
if (thumb.isEnabled()) {
thumb.getThumb().setState(new int[]{android.R.attr.state_enabled,
-android.R.attr.state_pressed});
} else {
thumb.getThumb().setState(new int[]{-android.R.attr.state_enabled});
}
}
}
} else {
for (Thumb thumb : mThumbs) {
if (thumb.getThumb() != null && thumb.getThumb().isStateful()) {
if (thumb.isEnabled()) {
thumb.getThumb().setState(new int[]{android.R.attr.state_enabled,
-android.R.attr.state_pressed});
} else {
thumb.getThumb().setState(new int[]{-android.R.attr.state_enabled});
}
}
}
}
}
super.drawableStateChanged();

}


Expand Down Expand Up @@ -1535,40 +1540,24 @@ else if (exactTouched != null && exactTouched.size() > 0) {
break;

case MotionEvent.ACTION_UP:
setPressed(false);
//there are other pointers left
case MotionEvent.ACTION_POINTER_UP:
if (currThumb != null) {
setThumbValue(currThumb, getValue(event, currThumb), true);
setHotspot(xx, yy, currThumb);
boolean toUnPress = false;
if (!isPressed()) {
setPressed(true);
toUnPress = true;
}

onStopTrackingTouch(currThumb);
if (toUnPress) {
setPressed(false);
}
} else {
// currThumb = getClosestThumb(newValue);
// // Touch up when we never crossed the touch slop threshold should
// // be interpreted as a tap-seek to that location.
// onStartTrackingTouch(currThumb);
// setThumbValue(currThumb, newValue, true);
// onStopTrackingTouch(currThumb);
}
// ProgressBar doesn't know to repaint the thumb drawable
// in its inactive state when the touch stops (because the
// value has not apparently changed)
invalidate();
break;
case MotionEvent.ACTION_CANCEL:
if (mDraggingThumbs != null) {
onStopTrackingTouch();
setPressed(false);
}
onStopTrackingTouch();
invalidate(); // see above explanation
break;
}
Expand Down Expand Up @@ -1654,13 +1643,17 @@ private void attemptClaimDrag() {
*/
void onStartTrackingTouch(Thumb thumb) {
if (thumb != null) {
setPressed(true);
mDraggingThumbs.add(thumb);
if (isPressed()) {
drawableStateChanged();
} else {
setPressed(true);
}

if (thumb.getThumb() != null) {
// This may be within the padding region.
invalidate(thumb.getThumb().getBounds());
}
mDraggingThumbs.add(thumb);
drawableStateChanged();
if (hasOnTrackingChangeListener()) {
mOnTrackingChangeListener.onStartTrackingTouch(this, thumb, thumb.getValue());
}
Expand All @@ -1678,12 +1671,22 @@ void onStopTrackingTouch(Thumb thumb) {
if (hasOnTrackingChangeListener()) {
mOnTrackingChangeListener.onStopTrackingTouch(this, thumb, thumb.getValue());
}
drawableStateChanged();
if (mDraggingThumbs.size() == 0) {
setPressed(false);
} else {
drawableStateChanged();
}
}
}

void onStopTrackingTouch() {
mDraggingThumbs.clear();
for (Thumb thumb : mDraggingThumbs) {
mDraggingThumbs.remove(thumb);
if (hasOnTrackingChangeListener()) {
mOnTrackingChangeListener.onStopTrackingTouch(this, thumb, thumb.getValue());
}
}
setPressed(false);
}

private boolean hasOnThumbValueChangeListener() {
Expand Down

0 comments on commit 669884c

Please sign in to comment.