Esempio n. 1
0
  public boolean onTouchEvent(@NonNull MotionEvent event) {
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_MOVE) {
      mVelocityTracker.addMovement(event);
    }
    if (mState == State.DRAGGING) {
      switch (action) {
        case MotionEvent.ACTION_MOVE:
          int deltaY = calculateDistanceForDrag(event);
          mProgressManager.applyDelta(deltaY);
          break;
        case MotionEvent.ACTION_UP:
          finishMotionEvent();
          if (type == LEFT) {
            mCalendarView.prev();
          } else if (type == RIGHT) {
            mCalendarView.next();
          }
          break;
      }

    } else if (action == MotionEvent.ACTION_MOVE) {
      checkForResizing(event);
    } else if (action == MotionEvent.ACTION_UP) {
      if (type == LEFT) {
        mCalendarView.prev();
      } else if (type == RIGHT) {
        mCalendarView.next();
      }
    }

    return true;
  }
Esempio n. 2
0
  /** @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (isEnabled() && touchListener.isSwipeEnabled()) {

      if (touchState == TOUCH_STATE_SCROLLING_X) {
        return touchListener.onTouch(this, ev);
      }

      switch (action) {
        case MotionEvent.ACTION_MOVE:
          checkInMoving(x, y);
          return touchState == TOUCH_STATE_SCROLLING_Y;
        case MotionEvent.ACTION_DOWN:
          touchListener.onTouch(this, ev);
          touchState = TOUCH_STATE_REST;
          lastMotionX = x;
          lastMotionY = y;
          return false;
        case MotionEvent.ACTION_CANCEL:
          touchState = TOUCH_STATE_REST;
          break;
        case MotionEvent.ACTION_UP:
          touchListener.onTouch(this, ev);
          return touchState == TOUCH_STATE_SCROLLING_Y;
        default:
          break;
      }
    }

    return super.onInterceptTouchEvent(ev);
  }
Esempio n. 3
0
  /**
   * Triggered
   *
   * @param event Down event
   */
  private boolean onDownEvent(@NonNull MotionEvent event) {
    if (MotionEventCompat.getActionMasked(event) != MotionEvent.ACTION_DOWN) {
      throw new IllegalStateException("Has to be down event!");
    }
    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    } else {
      mVelocityTracker.clear();
    }
    mDownY = event.getY();
    mDownX = event.getX();

    if (!mScroller.isFinished()) {
      mScroller.forceFinished(true);
      if (mScroller.getFinalY() == 0) {
        mDragStartY = mDownY + mScroller.getStartY() - mScroller.getCurrY();
      } else {
        mDragStartY = mDownY - mScroller.getCurrY();
      }
      mState = State.DRAGGING;
      return true;
    } else {
      return false;
    }
  }
  @Override
  public boolean onTouchEvent(@NonNull MotionEvent event) {

    if (!isEnabled() || mNestedScrollInProgress) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }
    final int action = MotionEventCompat.getActionMasked(event);
    final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId);
    switch (action) {
      case MotionEvent.ACTION_MOVE:
        releaseEvent();
        mLastMoveEvent = MotionEvent.obtain(event);
        return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex);
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mActivePointerId == INVALID_POINTER_ID) {
          return false;
        }
        touchUp(event);
        mLastEventOffset = -1;
        mFirstTouchDownPointY = -1;
        mActivePointerId = INVALID_POINTER_ID;
        return false;
    }
    return true;
  }
Esempio n. 5
0
  // Change page
  protected void swipePage(View v, MotionEvent event, int book) {
    int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
      case (MotionEvent.ACTION_DOWN):
        swipeOriginX = event.getX();
        swipeOriginY = event.getY();
        break;

      case (MotionEvent.ACTION_UP):
        int quarterWidth = (int) (screenWidth * 0.25);
        float diffX = swipeOriginX - event.getX();
        float diffY = swipeOriginY - event.getY();
        float absDiffX = Math.abs(diffX);
        float absDiffY = Math.abs(diffY);

        if ((diffX > quarterWidth) && (absDiffX > absDiffY)) {
          try {
            navigator.goToNextChapter(index);
          } catch (Exception e) {
            errorMessage(getString(R.string.error_cannotTurnPage));
          }
        } else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) {
          try {
            navigator.goToPrevChapter(index);
          } catch (Exception e) {
            errorMessage(getString(R.string.error_cannotTurnPage));
          }
        }
        break;
    }
  }
Esempio n. 6
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if ((action != MotionEvent.ACTION_DOWN)) {
      mDragHelper.cancel();
      return super.onInterceptTouchEvent(ev);
    }

    final float x = ev.getX();
    final float y = ev.getY();
    boolean interceptTap = false;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mInitialMotionX = x;
          mInitialMotionY = y;
          interceptTap = mDragHelper.isViewUnder(mTitle, (int) x, (int) y);
          break;
        }
      default:
        break;
    }

    return mDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
  }
 @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;
 }
 public boolean dispatchTouchEvent(MotionEvent ev) {
   if (isEnabled() && isSlideEnable()) {
     int action = MotionEventCompat.getActionMasked(ev);
     if (action == MotionEvent.ACTION_DOWN) {
       int downPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
       int opendPosition = mTouchListener.getOpendPosition();
       // There is a item in opend or half opend(exception occured in
       // previous slideing event) status
       if (opendPosition != INVALID_POSITION) {
         // if slideing or auto
         // slideing(SlideTouchListener.autoScroll()) has not
         // finished,drop this motion event(avoid
         // NullPointerException)
         if (mTouchListener.isInSliding()) {
           return false;
         }
         // if down position not equals the opend position,drop this
         // motion event and close the opend item
         if (downPosition != opendPosition) {
           mTouchListener.closeOpenedItem();
           return false;
         }
       }
     }
   }
   return super.dispatchTouchEvent(ev);
 }
 public void onTouchEvent(MotionEvent event) {
   mGestrueDetector.onTouchEvent(event);
   int action = MotionEventCompat.getActionMasked(event);
   switch (action) {
     case (MotionEvent.ACTION_UP):
       // Log.d(DEBUG_TAG, "Action was UP");
       if (mStarted) {
         mListener.onDragEnd(mOriginalEvent, event);
       }
       mStarted = false;
       break;
     case (MotionEvent.ACTION_DOWN):
       // need to set this, quick tap will not generate drap event, so the
       // originalEvent may be null for case action_up
       // which lead to null pointer
       mOriginalEvent = event;
       break;
     case (MotionEvent.ACTION_CANCEL):
       Log.d(DEBUG_TAG, "Action was cancel!");
       if (mStarted) {
         mListener.onDragEnd(mOriginalEvent, event);
       }
       mStarted = false;
       break;
   }
 }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent ev) {
   int action = MotionEventCompat.getActionMasked(ev);
   if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
     return false;
   }
   return mDragHlper.shouldInterceptTouchEvent(ev);
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();

    final int action = MotionEventCompat.getActionMasked(ev);

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
      mReturningToStart = false;
    }

    if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
      // Fail fast if we're not in a state where a swipe is possible
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialDownY = getMotionEventY(ev, mActivePointerId);
        if (initialDownY == -1) {
          return false;
        }
        mInitialDownY = initialDownY;
        break;

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
          return false;
        }

        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
          return false;
        }
        final float yDiff = y - mInitialDownY;
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
          mInitialMotionY = mInitialDownY + mTouchSlop;
          mIsBeingDragged = true;
          mProgress.setAlpha(STARTING_PROGRESS_ALPHA);
        }
        break;

      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
    }

    return mIsBeingDragged;
  }
Esempio n. 12
0
  @Override
  @SuppressLint("ClickableViewAccessibility")
  public boolean onTouchEvent(@NonNull MotionEvent ev) {

    // Cancel animate
    cancelAnimation();

    try {
      mDragHelper.processTouchEvent(ev);
    } catch (Throwable e) {
      // Ignore
    }

    final int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (action == MotionEvent.ACTION_DOWN) {
      mIntercepted = true;
    }

    if (!mIntercepted) return false;

    if (!isDrawersTouchable()) return false;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mLeftState == STATE_SLIDING) {
          if (mLeftOpened && mLeftPercent < CLOSE_SENSITIVITY) startAnimation(true, false, false);
          else if (!mLeftOpened && mLeftPercent < OPEN_SENSITIVITY)
            startAnimation(true, false, true);
          else if (mLeftOpened && mLeftPercent >= CLOSE_SENSITIVITY)
            startAnimation(true, true, true);
          else if (!mLeftOpened && mLeftPercent >= OPEN_SENSITIVITY)
            startAnimation(true, true, false);
        } else if (mRightState == STATE_SLIDING) {
          if (mRightOpened && mRightPercent < CLOSE_SENSITIVITY)
            startAnimation(false, false, false);
          else if (!mRightOpened && mRightPercent < OPEN_SENSITIVITY)
            startAnimation(false, false, true);
          else if (mRightOpened && mRightPercent >= CLOSE_SENSITIVITY)
            startAnimation(false, true, true);
          else if (!mRightOpened && mRightPercent >= OPEN_SENSITIVITY)
            startAnimation(false, true, false);
        } else if (shouldCloseDrawers(x, y)) {
          closeDrawers();
        }
        break;
    }

    return true;
  }
Esempio n. 13
0
  /**
   * Override method to intercept only touch events over the drag view and to cancel the drag when
   * the action associated to the MotionEvent is equals to ACTION_CANCEL or ACTION_UP.
   *
   * @param ev captured.
   * @return true if the view is going to process the touch event or false if not.
   */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
      viewDragHelper.cancel();
      return false;
    }
    boolean interceptTap = viewDragHelper.isViewUnder(dragView, (int) ev.getX(), (int) ev.getY());
    return viewDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
  }
Esempio n. 14
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   mOverlayGesturePresenter.onTouchEvent(event);
   int action = MotionEventCompat.getActionMasked(event);
   switch (action) {
     case MotionEvent.ACTION_CANCEL:
     case MotionEvent.ACTION_UP:
       mDownX = -1;
   }
   return true;
 }
Esempio n. 15
0
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    ensureTarget();

    int action = MotionEventCompat.getActionMasked(ev);

    if ((this.mReturningToStart) && (action == 0)) {
      this.mReturningToStart = false;
    }

    if ((!isEnabled()) || (this.mReturningToStart) || (canChildScrollUp()) || (this.mRefreshing)) {
      return false;
    }

    switch (action) {
      case 0:
        setTargetOffsetTopAndBottom(this.mOriginalOffsetTop - this.mCircleView.getTop(), true);
        this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        this.mIsBeingDragged = false;
        float initialDownY = getMotionEventY(ev, this.mActivePointerId);
        if (initialDownY == -1.0F) {
          return false;
        }
        this.mInitialDownY = initialDownY;
        break;
      case 2:
        if (this.mActivePointerId == -1) {
          Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
          return false;
        }

        float y = getMotionEventY(ev, this.mActivePointerId);
        if (y == -1.0F) {
          return false;
        }
        float yDiff = y - this.mInitialDownY;
        if ((yDiff > this.mTouchSlop) && (!this.mIsBeingDragged)) {
          this.mInitialMotionY = (this.mInitialDownY + this.mTouchSlop);
          this.mIsBeingDragged = true;
          this.mProgress.setAlpha(76);
        }
        break;
      case 6:
        onSecondaryPointerUp(ev);
        break;
      case 1:
      case 3:
        this.mIsBeingDragged = false;
        this.mActivePointerId = -1;
      case 4:
      case 5:
    }
    return this.mIsBeingDragged;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (!isEnabled()
        || !isTouchEnabled()
        || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
      mDragHelper.cancel();
      return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
      mDragHelper.cancel();
      return false;
    }

    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mIsUnableToDrag = false;
          mInitialMotionX = x;
          mInitialMotionY = y;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          final float adx = Math.abs(x - mInitialMotionX);
          final float ady = Math.abs(y - mInitialMotionY);
          final int dragSlop = mDragHelper.getTouchSlop();

          // Handle any horizontal scrolling on the drag view.
          if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) {
            return super.onInterceptTouchEvent(ev);
          }

          if ((ady > dragSlop && adx > ady)
              || !isDragViewUnder((int) mInitialMotionX, (int) mInitialMotionY)) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
          }
          break;
        }
    }

    return mDragHelper.shouldInterceptTouchEvent(ev);
  }
  /** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {

    if (!isEnabled() || mNestedScrollInProgress) {
      return false;
    }
    if (!mEnableFresh && !mEnablePullLoad) {
      return false;
    }
    final int action = MotionEventCompat.getActionMasked(event);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(event, 0);
        mFirstTouchDownPointY = getMotionEventY(event, mActivePointerId);
        mLastEventOffset = (int) mFirstTouchDownPointY;
        break;

      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER_ID) {
          return false;
        }

        final float currentY = getMotionEventY(event, mActivePointerId);

        if (currentY == -1) {
          return false;
        }

        if (mFirstTouchDownPointY == -1) {
          mFirstTouchDownPointY = currentY;
        }
        if (mLastEventOffset == -1) mLastEventOffset = (int) currentY;

        final float yDiff = currentY - mFirstTouchDownPointY;

        // State is changed to drag if over slop
        if (Math.abs(yDiff) > ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
          return shouldIntercept((int) yDiff);
        }

        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }

    return false;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    // If the scrollable view is handling touch, never intercept
    if (mIsScrollableViewHandlingTouch) {
      mDragHelper.cancel();
      return false;
    }

    final int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mIsUnableToDrag = false;
          mInitialMotionX = x;
          mInitialMotionY = y;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          final float adx = Math.abs(x - mInitialMotionX);
          final float ady = Math.abs(y - mInitialMotionY);
          final int dragSlop = mDragHelper.getTouchSlop();

          if ((ady > dragSlop && adx > ady)
              || !isViewUnder(mDragView, (int) mInitialMotionX, (int) mInitialMotionY)) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
          }
          break;
        }

      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        // If the dragView is still dragging when we get here, we need to call processTouchEvent
        // so that the view is settled
        // Added to make scrollable views work (tokudu)
        if (mDragHelper.isDragging()) {
          mDragHelper.processTouchEvent(ev);
          return true;
        }
        break;
    }
    return mDragHelper.shouldInterceptTouchEvent(ev);
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!isEnabled() || canChildScrollUp() || mRefreshing) {
      return false;
    }

    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        setTargetOffsetTop(0, true);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        final float initialMotionY = getMotionEventY(ev, mActivePointerId);
        if (initialMotionY == -1) {
          return false;
        }
        mInitialMotionY = initialMotionY;
        break;
      case MotionEvent.ACTION_MOVE:
        if (mActivePointerId == INVALID_POINTER) {
          return false;
        }
        final float y = getMotionEventY(ev, mActivePointerId);
        if (y == -1) {
          return false;
        }
        final float yDiff = y - mInitialMotionY;
        //                if (Math.abs(yDiff) > mTouchSlop && !mIsBeingDragged) {
        //                    mIsBeingDragged = true;
        //                    mMode = yDiff > 0 ? MODE_TOP : MODE_BOTTOM;
        //                }
        if (yDiff > mTouchSlop && !mIsBeingDragged) {
          mIsBeingDragged = true;
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        break;
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    return mIsBeingDragged;
  }
Esempio n. 20
0
  @Override
  public boolean onInterceptTouchEvent(@NonNull MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (!isDrawersTouchable()) {
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mIntercepted = shouldCloseDrawers(x, y);
        mCanIntercept = true;
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
      case MotionEvent.ACTION_MOVE:
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if (ady > slop && ady > adx) {
          mCanIntercept = false;
        }
        if (mCanIntercept && adx > slop && adx > ady) {
          mIntercepted = true;
        }
        if (shouldCloseDrawers(x, y)) {
          mIntercepted = true;
        }
        break;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mDragHelper.cancel();
        if (shouldCloseDrawers(x, y)) {
          closeDrawers();
        }
        break;
    }

    try {
      mDragHelper.shouldInterceptTouchEvent(ev);
    } catch (Throwable e) {
      // Ignore
    }

    return mIntercepted;
  }
Esempio n. 21
0
 @Override
 public boolean onInterceptTouchEvent(MotionEvent ev) {
   final int action = MotionEventCompat.getActionMasked(ev);
   if (action == MotionEvent.ACTION_DOWN) {
     // 记录初始touch位置,如果初始touch的是空白区域,不进行拖动事件处理
     initTouchDownX = (int) ev.getX();
     initTouchDownY = (int) ev.getY();
   }
   if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
     mViewDragHelper.cancel();
     initTouchDownX = 0;
     initTouchDownY = 0;
     return false;
   }
   return mViewDragHelper.shouldInterceptTouchEvent(ev);
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    int actionMasked = MotionEventCompat.getActionMasked(event);
    switch (actionMasked) {
      case MotionEvent.ACTION_DOWN:
        {
          if (isAnimRunning()) {
            return false;
          }

          isDisappear = false;
          isOutOfRange = false;
          updateDragCenter(event.getRawX(), event.getRawY());

          break;
        }
      case MotionEvent.ACTION_MOVE:
        {

          // 如果两圆间距大于最大距离farest,执行拖拽结束动画
          PointF p0 = new PointF(mDragCenter.x, mDragCenter.y);
          PointF p1 = new PointF(mStickCenter.x, mStickCenter.y);
          if (GeometryUtil.getDistanceBetween2Points(p0, p1) > farest) {
            isOutOfRange = true;

            updateDragCenter(event.getRawX(), event.getRawY());
            return false;
          }

          updateDragCenter(event.getRawX(), event.getRawY());
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          handleActionUp();

          break;
        }
      default:
        {
          isOutOfRange = false;
          break;
        }
    }
    return true;
  }
  /**
   *
   *
   * <ul>
   *   if stopScrollWhenTouch is true
   *   <li>if event is down, stop auto scroll.
   *   <li>if event is up, start auto scroll again.
   * </ul>
   */
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);

    if (stopScrollWhenTouch) {
      if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) {
        isStopByTouch = true;
        stopAutoScroll();
      } else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
        startAutoScroll();
      }
    }

    if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT
        || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
      touchX = ev.getX();
      if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        downX = touchX;
      }
      int currentItem = getCurrentItem();
      PagerAdapter adapter = getAdapter();
      int pageCount = adapter == null ? 0 : adapter.getCount();
      /**
       * current index is first one and slide to right or current index is last one and slide to
       * left.<br>
       * if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br>
       * else scroll to last one when current item is first one, scroll to first one when current
       * item is last one.
       */
      if ((currentItem == 0 && downX <= touchX)
          || (currentItem == pageCount - 1 && downX >= touchX)) {
        if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
          getParent().requestDisallowInterceptTouchEvent(false);
        } else {
          if (pageCount > 1) {
            setCurrentItem(pageCount - currentItem - 1, isBorderAnimation);
          }
          getParent().requestDisallowInterceptTouchEvent(true);
        }
        return super.dispatchTouchEvent(ev);
      }
    }
    getParent().requestDisallowInterceptTouchEvent(true);

    return super.dispatchTouchEvent(ev);
  }
Esempio n. 24
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    clearExtraInformationTextViews();
    scaleDetector.onTouchEvent(event);
    // Check if multitouch action or single touch based on pointer count.
    if (event.getPointerCount() > 1) {
      clearExtraInformationTextViews();
      gestureTypeTV.setText("MULTI TOUCH EVENT");
      textView3.setText("Num Pointers: " + event.getPointerCount());
      int action = MotionEventCompat.getActionMasked(event);
      textView4.setText(actionToString(action));
      int index = MotionEventCompat.getActionIndex(event);
      textView5.setText("Pointer index: " + index);
    } else gestureDetect.onTouchEvent(event);

    return true;
  }
Esempio n. 25
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    int action = MotionEventCompat.getActionMasked(ev);
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        Log.d("view", "viewDown");
        break;
      case MotionEvent.ACTION_UP:
        Log.d("view", "viewUp");
        break;
      case MotionEvent.ACTION_MOVE:
        Log.d("view", "viewMove");

        break;
    }
    return true;
  }
Esempio n. 26
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int index = -1;
   switch (MotionEventCompat.getActionMasked(event)) {
     case MotionEvent.ACTION_DOWN:
       // 获取当前触摸到的字母索引
       index = (int) (event.getY() / cellHeight);
       if (index >= 0 && index < LETTERS.length) {
         // 判断是否跟上一次触摸到的一样
         if (index != touchIndex) {
           if (listener != null) {
             listener.onLetterUpdate(LETTERS[index]);
           }
           Log.d(TAG, "onTouchEvent: " + LETTERS[index]);
           touchIndex = index;
         }
       }
       break;
     case MotionEvent.ACTION_MOVE:
       // 获取当前触摸到的字母索引
       index = (int) (event.getY() / cellHeight);
       if (index >= 0 && index < LETTERS.length) {
         // 判断是否跟上一次触摸到的一样
         if (index != touchIndex) {
           if (listener != null) {
             listener.onLetterUpdate(LETTERS[index]);
           }
           Log.d(TAG, "onTouchEvent: " + LETTERS[index]);
           touchIndex = index;
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       touchIndex = -1;
       break;
     default:
       break;
   }
   invalidate();
   // 这个地方需要特别注意,需要消费事件
   return true;
 }
Esempio n. 27
0
 public boolean onInterceptTouchEvent(@NonNull MotionEvent ev) {
   final int action = MotionEventCompat.getActionMasked(ev);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       type = -1;
       return onDownEvent(ev);
     case MotionEvent.ACTION_MOVE:
       mVelocityTracker.addMovement(ev);
       return checkForResizing(ev);
     case MotionEvent.ACTION_UP:
       finishMotionEvent();
       if (type == LEFT) {
         mCalendarView.prev();
       } else if (type == RIGHT) {
         mCalendarView.next();
       }
       return false;
   }
   return false;
 }
    public boolean onForwardedEvent(MotionEvent motionevent, int i)
    {
        int j = MotionEventCompat.getActionMasked(motionevent);
        j;
        JVM INSTR tableswitch 1 3: default 36
    //                   1 108
    //                   2 227
    //                   3 100;
           goto _L1 _L2 _L3 _L4
_L3:
        break MISSING_BLOCK_LABEL_227;
_L1:
        boolean flag;
        i = 0;
        flag = true;
_L7:
        if (!flag || i != 0)
        {
            clearPressedItem();
        }
        if (!flag) goto _L6; else goto _L5
Esempio n. 29
0
  @Override
  public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    Log.d(TAG, "onTouchEvent: " + e.getAction());

    if (mExpandAndCollapseAnim != null && mExpandAndCollapseAnim.isRunning() || mTargetView == null)
      return;

    // 如果要响应fling事件设置将mIsDragging设为false
    if (mGestureDetector.onTouchEvent(e)) {
      mIsDragging = false;
      return;
    }

    int x = (int) e.getX();
    int y = (int) e.getY();
    int action = MotionEventCompat.getActionMasked(e);
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        // RecyclerView 不会转发这个Down事件

        break;
      case MotionEvent.ACTION_MOVE:
        int deltaX = (int) (mLastX - e.getX());
        if (mIsDragging) {
          horizontalDrag(deltaX);
        }
        mLastX = x;
        break;

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
          if (!smoothHorizontalExpandOrCollapse(0) && isCollapsed()) mTargetView = null;

          mIsDragging = false;
        }

        break;
    }
  }
Esempio n. 30
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (action != MotionEvent.ACTION_DOWN) {
      mDragHelper.cancel();
      return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
      mDragHelper.cancel();
      return false;
    }

    final float x = ev.getX();
    final float y = ev.getY();
    boolean interceptTap = false;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mInitialMotionX = x;
        mInitialMotionY = y;
        interceptTap = mDragHelper.isViewUnder(mHeaderView, (int) x, (int) y);
        break;

      case MotionEvent.ACTION_MOVE:
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        LogUtil.d(TAG, "adx:" + adx + " ady:" + ady + " slop:" + slop);
        if (ady > slop && adx > ady) {
          mDragHelper.cancel();
          return false;
        }
        break;
    }

    return mDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
  }