@Override public boolean onTouch(View v, MotionEvent ev) { mDetector.onTouchEvent(ev); if (mRemoveEnabled && mDragging && (mRemoveMode == FLING_RIGHT_REMOVE || mRemoveMode == FLING_LEFT_REMOVE)) { mFlingRemoveDetector.onTouchEvent(ev); } int action = ev.getAction() & MotionEvent.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mCurrX = (int) ev.getX(); mCurrY = (int) ev.getY(); break; case MotionEvent.ACTION_UP: if (mRemoveEnabled) { final int x = (int) ev.getX(); int thirdW = mDslv.getWidth() / 3; int twoThirdW = mDslv.getWidth() - thirdW; if ((mRemoveMode == SLIDE_RIGHT_REMOVE && x > twoThirdW) || (mRemoveMode == SLIDE_LEFT_REMOVE && x < thirdW)) { mDslv.stopDrag(true); } } case MotionEvent.ACTION_CANCEL: mDragging = false; break; } return false; }
@Override public boolean onTouch(View v, MotionEvent ev) { if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) { return false; } mDetector.onTouchEvent(ev); if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) { mFlingRemoveDetector.onTouchEvent(ev); } int action = ev.getAction() & MotionEvent.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mCurrX = (int) ev.getX(); mCurrY = (int) ev.getY(); break; case MotionEvent.ACTION_UP: if (mRemoveEnabled && mIsRemoving) { int x = mPositionX >= 0 ? mPositionX : -mPositionX; int removePoint = mDslv.getWidth() / 2; if (x > removePoint) { mDslv.stopDragWithVelocity(true, 0); } } case MotionEvent.ACTION_CANCEL: mIsRemoving = false; mDragging = false; break; } return false; }
@Test public void test_setNextOnTouchEventReturnValue() throws Exception { assertTrue(detector.onTouchEvent(motionEvent)); shadowOf(detector).setNextOnTouchEventReturnValue(true); assertTrue(detector.onTouchEvent(motionEvent)); shadowOf(detector).setNextOnTouchEventReturnValue(false); assertFalse(detector.onTouchEvent(motionEvent)); }
// glView onTouch Event handler public boolean onTouch(View v, MotionEvent event) { boolean result = false; for (int i = 0; i < buttons.length; ++i) { if (buttons[i].processTouch(v, event)) { result = true; break; } } if (result != true) { gestureDetector.onTouchEvent(event); for (int i = 0; i < joysticks.length; ++i) { JoystickBase joy = joysticks[i]; if (joy != null) { if (joy.processTouch(v, event)) { result = true; } } } } return result; }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (gd != null) { if (gd.onTouchEvent(ev)) return true; } return super.dispatchTouchEvent(ev); }
public void onTouchEvent(MotionEvent event) { mGestureDetector.onTouchEvent(event); mScaleDetector.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_UP) { mListener.onUp(event.getX(), event.getY()); } }
@Override public boolean dispatchTouchEvent(MotionEvent event) { boolean ret = false; if (mIsScroll && event.getAction() == MotionEvent.ACTION_UP) { if (mScrollX > 0 && mScrollX < mMaxDistance) { unFold(); ret = true; } event.setAction(MotionEvent.ACTION_CANCEL); mIsScroll = false; } else if (mGestureDetector != null && mGestureDetector.onTouchEvent(event)) { event.setAction(MotionEvent.ACTION_CANCEL); ret = true; } if (super.dispatchTouchEvent(event)) { ret = true; } if (ret) { invalidate(); } return ret; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub boolean spend = false; spend = detector.onTouchEvent(ev); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: // log("onInterceptTouchEvent.ACTION_DOWN, " + spend); break; case MotionEvent.ACTION_MOVE: // log("onInterceptTouchEvent.ACTION_MOVE, " + spend); // detector.onTouchEvent(ev); break; case MotionEvent.ACTION_UP: // log("onInterceptTouchEvent.ACTION_UP, " + spend); // onTouchRelease(); ov.clear(); break; case MotionEvent.ACTION_CANCEL: // log("onInterceptTouchEvent.ACTION_CANCEL, " + spend); // onTouchRelease(); break; } return spend; }
@Override public boolean onTouchEvent(MotionEvent event) { // 触摸时停止自动播放 flipStop(); // 点击事件后,停止自动播放 gestureDetector.onTouchEvent(event); // 注册手势事件 return true; }
@Override public boolean onTouchEvent(MotionEvent event) { if (mGesture.onTouchEvent(event)) { return true; } switch (event.getAction()) { case MotionEvent.ACTION_MOVE: int moveX = (int) event.getRawX(); int deltaX = tempX - moveX; tempX = moveX; if (moveX - downX > mTouchSlop && Math.abs((int) event.getRawY() - downY) < mTouchSlop) { isSilding = true; } if (moveX - downX >= 0 && isSilding) { mContentView.scrollBy(deltaX, 0); } break; case MotionEvent.ACTION_UP: isSilding = false; if (mContentView.getScrollX() <= -viewWidth / 2) { isFinish = true; scrollRight(); } else { scrollOrigin(); isFinish = false; } break; } return true; }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { super.dispatchTouchEvent(ev); boolean consumed = gesturedetector.onTouchEvent(ev); if (!consumed && ev.getAction() == MotionEvent.ACTION_DOWN) return true; else return consumed; }
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) return false; switch (event.getAction()) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!knobState) { innerContentAnimator = ObjectAnimator.ofFloat(AnSwitch.this, innerContentProperty, innerContentRate, 1.0F); innerContentAnimator.setDuration(300L); innerContentAnimator.setInterpolator(new DecelerateInterpolator()); innerContentAnimator.start(); } knobExpandAnimator = ObjectAnimator.ofFloat(AnSwitch.this, knobExpandProperty, knobExpandRate, 0.0F); knobExpandAnimator.setDuration(300L); knobExpandAnimator.setInterpolator(new DecelerateInterpolator()); knobExpandAnimator.start(); mIsChecked = knobState; if (AnSwitch.this.onSwitchStateChangeListener != null && mIsChecked != preIsOn) { AnSwitch.this.onSwitchStateChangeListener.onSwitchStateChange(mIsChecked); } break; } return gestureDetector.onTouchEvent(event); }
/** 事件拦截操作 */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { // 处理ViewPager冲突问题 ViewPager mViewPager = getTouchViewPager(mViewPagers, ev); Log.i(TAG, "mViewPager = " + mViewPager); if (mViewPager != null && mViewPager.getCurrentItem() != 0) { return super.onInterceptTouchEvent(ev); } // 如果是左右滑动事件,则不将事件传递给子view if (mGesture.onTouchEvent(ev)) { return true; } switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: downX = tempX = (int) ev.getRawX(); downY = (int) ev.getRawY(); break; case MotionEvent.ACTION_MOVE: int moveX = (int) ev.getRawX(); // 满足此条件屏蔽SildingFinishLayout里面子类的touch事件 if (moveX - downX > mTouchSlop && Math.abs((int) ev.getRawY() - downY) < mTouchSlop) { return true; } break; } return super.onInterceptTouchEvent(ev); }
@Override public boolean onTouchEvent(@NonNull MotionEvent ev) { stopAnimationsOnTouch = true; mScaleDetector.onTouchEvent(ev); if (!mScaleDetector.isInProgress()) mGestureDetector.onTouchEvent(ev); return true; }
@Override public boolean onTouchEvent(VisualizationView view, MotionEvent event) { if (visible) { Preconditions.checkNotNull(pose); if (event.getAction() == MotionEvent.ACTION_MOVE) { Vector3 orientationVector = camera .toWorldCoordinates(new Point((int) event.getX(), (int) event.getY())) .subtract(pose.getTranslation()); if (orientationVector.length() > 0) { pose.setRotation( Quaternion.rotationBetweenVectors(new Vector3(1, 0, 0), orientationVector)); } else { pose.setRotation(Quaternion.newIdentityQuaternion()); } shape.setTransform(pose); requestRender(); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { posePublisher.publish( pose.toPoseStampedMessage( camera.getFixedFrame(), connectedNode.getCurrentTime(), posePublisher.newMessage())); visible = false; requestRender(); return true; } } gestureDetector.onTouchEvent(event); return false; }
@Override public boolean onTouchEvent(MotionEvent event) { mScaleGestureDetector.onTouchEvent(event); if (!mScaling) mGestureDetector.onTouchEvent(event); if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { mUserInteracting = true; } if (event.getActionMasked() == MotionEvent.ACTION_UP) { mScrollDisabled = false; mUserInteracting = false; View v = mChildViews.get(mCurrent); if (v != null) { if (mScroller.isFinished()) { // If, at the end of user interaction, there is no // current inertial scroll in operation then animate // the view onto screen if necessary slideViewOntoScreen(v); } if (mScroller.isFinished()) { // If still there is no inertial scroll in operation // then the layout is stable postSettle(v); } } } requestLayout(); return true; }
@Override public boolean onTouchEvent(MotionEvent event) { // Avoid short-circuit logic evaluation - ensure all gesture detectors see all events so // that they generate correct notifications. boolean handled = mScroller.onTouchEvent(event); handled |= mZoomer.onTouchEvent(event); handled |= mTapDetector.onTouchEvent(event); mSwipePinchDetector.onTouchEvent(event); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: mViewer.setAnimationEnabled(false); mSuppressCursorMovement = false; mSuppressFling = false; mSwipeCompleted = false; break; case MotionEvent.ACTION_POINTER_DOWN: mTotalMotionY = 0; break; case MotionEvent.ACTION_UP: releaseAnyHeldButton(); break; default: break; } return handled; }
@Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) { childView = view.findChildViewUnder(event.getX(), event.getY()); childViewPosition = view.getChildPosition(childView); return childView != null && gestureDetector.onTouchEvent(event); }
public boolean onTouch(View v, MotionEvent event) { boolean result = false; for (int i = 0; i < buttons.length; ++i) { if (buttons[i].processTouch(v, event)) { result = true; break; } } if (result != true) { gestureDetector.onTouchEvent(event); for (int i = 0; i < joysticks.length; ++i) { JoystickBase joy = joysticks[i]; if (joy != null) { if (joy.processTouch(v, event)) { result = true; } } } } // if (event.getAction() == MotionEvent.ACTION_MOVE) { // // Trying to avoid flooding of ACTION_MOVE events // try { // Thread.sleep(33); // } catch (InterruptedException e) { // e.printStackTrace(); // } // } return result; }
public boolean onTouch(View v, MotionEvent event) { if (mState == State.ANIMATING) { // we are animating return false; } int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { // if (mBringToFront) { bringToFront(); // } touchX = event.getX(); touchY = event.getY(); } if (!mGestureDetector.onTouchEvent(event)) { if (action == MotionEvent.ACTION_UP) { // tup up after scrolling int size = (int) (Math.abs(touchX - event.getX()) + Math.abs(touchY - event.getY())); if (size == mContentWidth || size == mContentHeight) { mState = State.ABOUT_TO_ANIMATE; // Log.e("size", String.valueOf(size)); // Log.e(String.valueOf(mContentWidth),String.valueOf(mContentHeight)); } post(startAnimation); } } return false; }
@Override public final boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); return super.onTouchEvent(event); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { mGestureDetector.onTouchEvent(ev); // scroll.onTouchEvent(ev); return super.dispatchTouchEvent(ev); }
/** * Handles Touch event * * @param event the motion event * @return */ public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: lastTouchedPosition = getMotionEventPosition(event); scroller.forceFinished(true); clearMessages(); listener.onTouch(); break; case MotionEvent.ACTION_UP: if (scroller.isFinished()) listener.onTouchUp(); break; case MotionEvent.ACTION_MOVE: // perform scrolling int distance = (int) (getMotionEventPosition(event) - lastTouchedPosition); if (distance != 0) { startScrolling(); listener.onScroll(distance); lastTouchedPosition = getMotionEventPosition(event); } break; } if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) { justify(); } return true; }
@Override public boolean onTouchEventInternal(MotionEvent e) { final int action = e.getActionMasked(); // This path mimics the Android long press detection while still allowing // other touch events to come through the gesture detector. if (!mUseDefaultLongPress) { if (e.getPointerCount() > 1) { // If there's more than one pointer ignore the long press. if (mLongPressRunnable.isPending()) { cancelLongPress(); } } else if (action == MotionEvent.ACTION_DOWN) { // If there was a pending event kill it off. if (mLongPressRunnable.isPending()) { cancelLongPress(); } mLongPressRunnable.init(e); mLongPressHandler.postDelayed(mLongPressRunnable, mLongPressTimeoutMs); } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { cancelLongPress(); } else if (mLongPressRunnable.isPending()) { // Allow for a little bit of touch slop. MotionEvent initialEvent = mLongPressRunnable.getInitialEvent(); float distanceX = initialEvent.getX() - e.getX(); float distanceY = initialEvent.getY() - e.getY(); float distance = distanceX * distanceX + distanceY * distanceY; // Save a square root here by comparing to squared touch slop if (distance > mScaledTouchSlop * mScaledTouchSlop) { cancelLongPress(); } } } // Sends the pinch event if two or more fingers touch the screen. According to test // Android handles the fingers order pretty consistently so always requesting // index 0 and 1 works here. // This might need some rework if 3 fingers event are supported. if (e.getPointerCount() > 1) { mHandler.onPinch( e.getX(0) * mPxToDp, e.getY(0) * mPxToDp, e.getX(1) * mPxToDp, e.getY(1) * mPxToDp, action == MotionEvent.ACTION_POINTER_DOWN); mDetector.setIsLongpressEnabled(false); mSingleInput = false; } else { mDetector.setIsLongpressEnabled(mUseDefaultLongPress); mSingleInput = true; } mDetector.onTouchEvent(e); // Propagate the up event after any gesture events. if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mHandler.onUpOrCancel(); } return true; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mGestureDetector = new GestureDetector(new YScrollDetector()); return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); }
@Override public boolean onTouchEvent(MotionEvent ev) { // Intercept ListView's touch event if (mScroller != null && mScroller.onTouchEvent(ev)) { return true; } if (mGestureDetector == null) { // Create a new GestureDetector -- 手势探测器 mGestureDetector = new GestureDetector( getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mScroller != null) { mScroller.show(); } return super.onFling(e1, e2, velocityX, velocityY); } }); } mGestureDetector.onTouchEvent(ev); return super.onTouchEvent(ev); }
/*----------------------onTouchEvent-------------------------------------------------------------------------------*/ @Override public boolean onTouchEvent(MotionEvent event) { Log.d(TAG, "onTouchEvent()"); mGestureDetector.onTouchEvent(event); return multiTouchController.onTouchEvent(event); }
@Test public void canAnswerLastGestureDetector() throws Exception { GestureDetector newDetector = new GestureDetector(Robolectric.application, null); assertNotSame(newDetector, ShadowGestureDetector.getLastActiveDetector()); newDetector.onTouchEvent(null); assertSame(newDetector, ShadowGestureDetector.getLastActiveDetector()); }
@Override public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return true; } return super.onTouchEvent(event); }
@Override public boolean onTouch(View v, MotionEvent event) { boolean handled = false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mLastTouchX = event.getX(); mLastTouchY = event.getY(); forceFinished(true); clearMessages(); handled = true; break; case MotionEvent.ACTION_MOVE: int dX = (int) (event.getX() - mLastTouchX); int dY = (int) (event.getY() - mLastTouchY); if (dX != 0 || dY != 0) { startScrolling(); mScrollListener.onScroll(dX, dY); mLastTouchX = event.getX(); mLastTouchY = event.getY(); } handled = true; break; default: break; } return mGestureDetector.onTouchEvent(event) || handled; }