/**
   * Determine drag.
   *
   * @param ev the ev
   */
  private void determineDrag(MotionEvent ev) {
    final int activePointerId = mActivePointerId;
    final int pointerIndex = getPointerIndex(ev, activePointerId);
    if (activePointerId == INVALID_POINTER) {
      return;
    }

    final float x = MotionEventCompat.getX(ev, pointerIndex);
    final float dx = x - mLastMotionX;
    final float xDiff = Math.abs(dx);
    final float y = MotionEventCompat.getY(ev, pointerIndex);
    final float dy = y - mLastMotionY;
    final float yDiff = Math.abs(dy);
    if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop)
        && xDiff > yDiff
        && thisSlideAllowed(dx)) {
      startDrag();
      mLastMotionX = x;
      mLastMotionY = y;
      setScrollingCacheEnabled(true);
      // TODO add back in touch slop check
    } else if (xDiff > mTouchSlop) {
      mIsUnableToDrag = true;
    }
  }
  @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;
  }
Example #3
0
  public boolean onGenericMotionEvent(MotionEvent var1) {
    if ((MotionEventCompat.getSource(var1) & 2) != 0) {
      switch (var1.getAction()) {
        case 8:
          if (!this.mIsBeingDragged) {
            float var2 = MotionEventCompat.getAxisValue(var1, 9);
            if (var2 != 0.0F) {
              int var3 = (int) (this.getVerticalScrollFactorCompat() * var2);
              int var4 = this.getScrollRange();
              int var6 = this.getScrollY();
              int var5 = var6 - var3;
              if (var5 < 0) {
                var3 = 0;
              } else {
                var3 = var5;
                if (var5 > var4) {
                  var3 = var4;
                }
              }

              if (var3 != var6) {
                super.scrollTo(this.getScrollX(), var3);
                return true;
              }
            }
          }
      }
    }

    return false;
  }
 private float getMotionEventY(@NonNull MotionEvent ev, int activePointerId) {
   final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
   if (index < 0) {
     return -1;
   }
   return MotionEventCompat.getY(ev, index);
 }
 private float getMotionEventY(MotionEvent ev, int activePointerId) {
   int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
   if (index < 0) {
     return -1.0F;
   }
   return MotionEventCompat.getY(ev, index);
 }
 private void onSecondaryPointerUp(MotionEvent ev) {
   int pointerIndex = MotionEventCompat.getActionIndex(ev);
   int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == this.mActivePointerId) {
     int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     this.mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
   }
 }
  @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;
  }
 private void onPointerUp(MotionEvent e) {
   final int actionIndex = MotionEventCompat.getActionIndex(e);
   if (MotionEventCompat.getPointerId(e, actionIndex) == mScrollPointerId) {
     // Pick a new pointer to pick up the slack.
     final int newIndex = actionIndex == 0 ? 1 : 0;
     mScrollPointerId = MotionEventCompat.getPointerId(e, newIndex);
     mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, newIndex) + 0.5f);
     mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, newIndex) + 0.5f);
   }
 }
 private void onSecondaryPointerUp(MotionEvent ev) {
   final int pointerIndex = MotionEventCompat.getActionIndex(ev);
   final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == mActivePointerId) {
     // This was our active pointer going up. Choose a new
     // active pointer and adjust accordingly.
     final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
   }
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
      return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL
        || action == MotionEvent.ACTION_UP
        || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
      endDrag();
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_MOVE:
        determineDrag(ev);
        break;
      case MotionEvent.ACTION_DOWN:
        int index = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        if (mActivePointerId == INVALID_POINTER) {
          break;
        }

        mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
        mLastMotionY = MotionEventCompat.getY(ev, index);
        if (thisTouchAllowed(ev)) {
          mIsBeingDragged = false;
          mIsUnableToDrag = false;
          if (isMenuOpen()
              && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
            mQuickReturn = true;
          }
        } else {
          mIsUnableToDrag = true;
        }
        break;
      case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

    if (!mIsBeingDragged) {
      if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
      }
      mVelocityTracker.addMovement(ev);
    }
    return mIsBeingDragged || mQuickReturn;
  }
  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;
  }
  /** @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;
  }
 /**
  * On secondary pointer up.
  *
  * @param ev the ev
  */
 private void onSecondaryPointerUp(MotionEvent ev) {
   final int pointerIndex = MotionEventCompat.getActionIndex(ev);
   final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
   if (pointerId == mActivePointerId) {
     // This was our active pointer going up. Choose a new
     // active pointer and adjust accordingly.
     final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
     mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
     mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
     if (mVelocityTracker != null) {
       mVelocityTracker.clear();
     }
   }
 }
  @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;
  }
 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;
   }
 }
 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);
 }
Example #17
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;
  }
 @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;
 }
Example #19
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;
    }
  }
Example #20
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;
  }
Example #21
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);
  }
Example #22
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(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;
  }
Example #24
0
  private void onSecondaryPointerUp(MotionEvent var1) {
    int var2 = (var1.getAction() & '\uff00') >> 8;
    if (MotionEventCompat.getPointerId(var1, var2) == this.mActivePointerId) {
      byte var3;
      if (var2 == 0) {
        var3 = 1;
      } else {
        var3 = 0;
      }

      this.mLastMotionY = (int) MotionEventCompat.getY(var1, var3);
      this.mActivePointerId = MotionEventCompat.getPointerId(var1, var3);
      if (this.mVelocityTracker != null) {
        this.mVelocityTracker.clear();
      }
    }
  }
 @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);
 }
  /**
   * Gets the pointer index.
   *
   * @param ev the ev
   * @param id the id
   * @return the pointer index
   */
  private int getPointerIndex(MotionEvent ev, int id) {
    int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id);
    if (activePointerIndex == -1) {
      mActivePointerId = INVALID_POINTER;
    }

    return activePointerIndex;
  }
  @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;
  }
Example #28
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;
 }
Example #29
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;
  }
  @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);
  }