예제 #1
0
 private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
   final Rect bounds = mTempRect;
   mThumb.copyBounds(bounds);
   // Grow the current thumb rect for a bigger touch area
   bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
   mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
   if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
     // If the user clicked outside the thumb, we compute the current
     // position
     // and force an immediate drag to it.
     mIsDragging = true;
     mDraggOffset = (bounds.width() / 2) - mAddedTouchBounds;
     updateDragging(ev);
     // As the thumb may have moved, get the bounds again
     mThumb.copyBounds(bounds);
     bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
   }
   if (mIsDragging) {
     setPressed(true);
     attemptClaimDrag();
     setHotspot(ev.getX(), ev.getY());
     mDraggOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
   }
   return mIsDragging;
 }
예제 #2
0
  private void updateDragging(MotionEvent ev) {
    setHotspot(ev.getX(), ev.getY());
    int x = (int) ev.getX();
    Rect oldBounds = mThumb.getBounds();
    int halfThumb = oldBounds.width() / 2;
    int addedThumb = mAddedTouchBounds;
    int newX = x - mDraggOffset + halfThumb;
    int left = getPaddingLeft() + halfThumb + addedThumb;
    int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
    if (newX < left) {
      newX = left;
    } else if (newX > right) {
      newX = right;
    }

    int available = right - left;
    float scale = (float) (newX - left) / (float) available;
    if (isRtl()) {
      scale = 1f - scale;
    }
    int progress = Math.round((scale * (mMax - mMin)) + mMin);
    setProgress(progress, true);
  }