@Override public boolean onInterceptTouchEvent(MotionEvent event) { final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); if (mAnimating) { return false; } View leftHandle = mLeftSlider.tab; leftHandle.getHitRect(mTmpRect); boolean leftHit = mTmpRect.contains((int) x, (int) y); View rightHandle = mRightSlider.tab; rightHandle.getHitRect(mTmpRect); boolean rightHit = mTmpRect.contains((int) x, (int) y); if (!mTracking && !(leftHit || rightHit)) { return false; } switch (action) { case MotionEvent.ACTION_DOWN: { mTracking = true; mTriggered = false; vibrate(VIBRATE_SHORT); if (leftHit) { mCurrentSlider = mLeftSlider; mOtherSlider = mRightSlider; mThreshold = isHorizontal() ? THRESHOLD : 1.0f - THRESHOLD; setGrabbedState(OnTriggerListener.LEFT_HANDLE); } else { mCurrentSlider = mRightSlider; mOtherSlider = mLeftSlider; mThreshold = isHorizontal() ? 1.0f - THRESHOLD : THRESHOLD; setGrabbedState(OnTriggerListener.RIGHT_HANDLE); } mCurrentSlider.setState(Slider.STATE_PRESSED); mCurrentSlider.showTarget(); mOtherSlider.hide(); break; } } return true; }
@Override public boolean onTouchEvent(MotionEvent event) { if (mTracking) { final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_MOVE: if (withinView(x, y, this)) { moveHandle(x, y); float position = isHorizontal() ? x : y; float target = mThreshold * (isHorizontal() ? getWidth() : getHeight()); boolean thresholdReached; if (isHorizontal()) { thresholdReached = mCurrentSlider == mLeftSlider ? position > target : position < target; } else { thresholdReached = mCurrentSlider == mLeftSlider ? position < target : position > target; } if (!mTriggered && thresholdReached) { mTriggered = true; mTracking = false; mCurrentSlider.setState(Slider.STATE_ACTIVE); boolean isLeft = mCurrentSlider == mLeftSlider; dispatchTriggerEvent( isLeft ? OnTriggerListener.LEFT_HANDLE : OnTriggerListener.RIGHT_HANDLE); startAnimating(isLeft ? mHoldLeftOnTransition : mHoldRightOnTransition); setGrabbedState(OnTriggerListener.NO_HANDLE); } break; } // Intentionally fall through - we're outside tracking rectangle case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: cancelGrab(); break; } } return mTracking || super.onTouchEvent(event); }