Exemplo n.º 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;
 }
Exemplo n.º 2
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (!isEnabled()) {
     return false;
   }
   int actionMasked = MotionEventCompat.getActionMasked(event);
   switch (actionMasked) {
     case MotionEvent.ACTION_DOWN:
       mDownX = event.getX();
       startDragging(event, isInScrollingContainer());
       break;
     case MotionEvent.ACTION_MOVE:
       if (isDragging()) {
         updateDragging(event);
       } else {
         final float x = event.getX();
         if (Math.abs(x - mDownX) > mTouchSlop) {
           startDragging(event, false);
         }
       }
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       stopDragging();
       break;
   }
   return true;
 }