List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;//from w w w . j a v a 2 s .c om if (!mIsViewPagerMode) break; if (!mIsSwiped) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; else mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); else mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { playSoundEffect(SoundEffectConstants.CLICK); if (mIsHorizontalOrientation) setModelIndex((int) (event.getX() / mModelSize)); else setModelIndex((int) (event.getY() / mModelSize)); } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent()"); final int action = MotionEventCompat.getActionMasked(ev); final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN"); final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;//from w ww. j ava2 s .c om mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE"); if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2"); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; Log.i(TAG, "onInterceptTouchEvent() -- result = " + result); return result; }
From source file:com.aidy.launcher3.support.views.bottomdrawer.BottomDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent()"); final int action = MotionEventCompat.getActionMasked(ev); final boolean interceptForDrag = mBottomDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN"); final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;//from w ww.j a v a 2 s .co m mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE"); if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2"); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; Log.i(TAG, "onInterceptTouchEvent() -- result = " + result); return result; }
From source file:cn.zmdx.kaka.locker.widget.SlidingPaneLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // Preserve the open state based on the last view that was touched. if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) { // After the first things will be slideable. final View secondChild = getChildAt(1); if (secondChild != null) { mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY()); }/*from w w w .jav a2 s .co m*/ } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) { interceptTap = true; } break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float deltaX = x - mInitialMotionX; final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if ((adx > slop && ady > adx) || deltaX < 0) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }
From source file:com.albedinsky.android.ui.widget.SearchView.java
/** *///from w w w . j av a 2 s.c o m @Override public boolean onTouchEvent(@NonNull MotionEvent event) { // SearchView is expected to be used mainly above or at the place of toolbar so it will handle // touch events like the Toolbar widget. final int action = event.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_DOWN) { this.mEatingTouch = false; } if (!mEatingTouch) { final boolean handled = super.onTouchEvent(event); if (action == MotionEvent.ACTION_DOWN && !handled) { this.mEatingTouch = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { this.mEatingTouch = false; } return true; }
From source file:cn.emagsoftware.ui.BugFixedSlidingPaneLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { try {//from w w w. j a v a 2 s .co m if (!mCanSlide) { return super.onTouchEvent(ev); } mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { if (isDimmed(mSlideableView)) { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) { // Taps close a dimmed open pane. closePane(mSlideableView, 0); break; } } break; } } return wantTouchEvents; } catch (ArrayIndexOutOfBoundsException e) { LogManager.logE(BugFixedSlidingPaneLayout.class, "internal bug in SlidingPaneLayout,this bug can be ignored in most cases.", e); return false; } catch (IllegalArgumentException e) { LogManager.logE(BugFixedSlidingPaneLayout.class, "internal bug in SlidingPaneLayout,this bug can be ignored in most cases.", e); return false; } }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = mTopDragger.shouldInterceptTouchEvent(ev) | mBottomDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;//from w w w.ja v a 2s .c o m mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mTopDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (mTopDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { mTopCallback.removeCallbacks(); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; }
From source file:radu.pidroid.Controller.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { int action = motionEvent.getActionMasked(); switch (view.getId()) { case R.id.forwardsPowerImageView: ///*from w w w . ja v a 2 s . co m*/ if (action == MotionEvent.ACTION_DOWN) { if (roverAccelerationState != ROVER_STOPPED && roverDirection != ROVER_FORWARDS) { roverAccelerationState = ROVER_STOPPED; mMessenger.updateRoverSpeed(roverSpeed = 0); } // if else { roverDirection = ROVER_FORWARDS; roverAccelerationState = ROVER_ACCELERATING; resetTimer(new roverSpeedTask()); } // else } // if else // if ((action == MotionEvent.ACTION_UP || !isTouchOnView(view, motionEvent)) && roverAccelerationState != ROVER_DECELERATING) { roverAccelerationState = ROVER_DECELERATING; resetTimer(new roverSpeedTask()); } // if break; case R.id.backwardsPowerImageView: // if (action == MotionEvent.ACTION_DOWN) { if (roverAccelerationState != ROVER_STOPPED && roverDirection != ROVER_BACKWARDS) { roverAccelerationState = ROVER_STOPPED; mMessenger.updateRoverSpeed(roverSpeed = 0); } // if else { roverDirection = ROVER_BACKWARDS; roverAccelerationState = ROVER_ACCELERATING; resetTimer(new roverSpeedTask()); } // else } // if else if ((action == MotionEvent.ACTION_UP || !isTouchOnView(view, motionEvent)) && roverAccelerationState != ROVER_DECELERATING) { roverAccelerationState = ROVER_DECELERATING; resetTimer(new roverSpeedTask()); } // if break; default: Log.e("OnTouch:", "wut?"); } // switch return true; }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { Log.i(TAG, "onTouchEvent()"); mBottomDragger.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onTouchEvent() -- ACTION_DOWN"); final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;/*w ww . java 2 s .c o m*/ mInitialMotionY = y; mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_UP: { Log.i(TAG, "onTouchEvent() -- ACTION_UP"); final float x = ev.getX(); final float y = ev.getY(); boolean peekingOnly = true; final View touchedView = mBottomDragger.findTopChildUnder((int) x, (int) y); if (touchedView != null && isContentView(touchedView)) { final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mBottomDragger.getTouchSlop(); if (dx * dx + dy * dy < slop * slop) { // Taps close a dimmed open drawer but only if it isn't // locked open. final View openDrawer = findOpenDrawer(); if (openDrawer != null) { peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN; } } } closeDrawers(peekingOnly); mDisallowInterceptRequested = false; break; } case MotionEvent.ACTION_CANCEL: { Log.i(TAG, "onTouchEvent() -- ACTION_CANCEL"); closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } } boolean result = wantTouchEvents; Log.i(TAG, "onTouchEvent() -- result = " + result); return result; }
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public boolean onTouch(View v, final MotionEvent event) { mGestureDetector.onTouchEvent(event); if (event.getPointerCount() > 1) { return true; }//from www . j a v a 2 s . com switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mDownX = event.getX(); mDownY = event.getY(); isOnClick = true; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (isOnClick) { swipe = false; } break; case MotionEvent.ACTION_MOVE: if (isOnClick && (Math.abs(mDownX - event.getX()) > 120 || Math.abs(mDownY - event.getY()) > 120)) { swipe = true; isOnClick = false; } break; default: break; } return false; }