@Override
  public boolean onTouchEvent(MotionEvent event) {
    if (velocityTracker == null) { // If we do not have velocity tracker
      velocityTracker = VelocityTracker.obtain(); // then get one
    }
    velocityTracker.addMovement(event); // add this movement to it
    positiveScroll = true;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (!flinger.isFinished()) { // If scrolling, then stop now
            flinger.forceFinished();
          }
          currentX = (int) event.getRawX();
          currentY = (int) event.getRawY();
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          final int x2 = (int) event.getRawX();
          final int y2 = (int) event.getRawY();
          final int diffX = currentX - x2;
          final int diffY = currentY - y2;
          currentX = x2;
          currentY = y2;

          scrollBy(diffX, diffY);
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          final VelocityTracker velocityTracker = this.velocityTracker;
          velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
          int velocityX = (int) velocityTracker.getXVelocity();
          int velocityY = (int) velocityTracker.getYVelocity();

          if (Math.abs(velocityX) > minimumVelocity || Math.abs(velocityY) > minimumVelocity) {
            flinger.start(
                getActualScrollX(),
                getActualScrollY(),
                velocityX,
                velocityY,
                getMaxScrollX(),
                getMaxScrollY());
          } else {
            if (this.velocityTracker != null) { // If the velocity less than threshold
              this.velocityTracker.recycle(); // recycle the tracker
              this.velocityTracker = null;
            }
          }
          break;
        }
    }
    return true;
  }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent event) {
   boolean intercept = false;
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       {
         currentX = (int) event.getRawX();
         currentY = (int) event.getRawY();
         break;
       }
     case MotionEvent.ACTION_MOVE:
       {
         int x2 = Math.abs(currentX - (int) event.getRawX());
         int y2 = Math.abs(currentY - (int) event.getRawY());
         if (x2 > touchSlop || y2 > touchSlop) {
           intercept = true;
         }
         break;
       }
   }
   return intercept;
 }
Example #3
0
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {

    float xDelta = Math.abs(motionEvent.getRawX() - showcaseX);
    float yDelta = Math.abs(motionEvent.getRawY() - showcaseY);
    double distanceFromFocus = Math.sqrt(Math.pow(xDelta, 2) + Math.pow(yDelta, 2));

    if (mOptions.hideOnClickOutside && distanceFromFocus > showcaseRadius) {
      this.hide();
      return true;
    }

    return mOptions.block && distanceFromFocus > showcaseRadius;
  }