List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (getKeyboard() == null)//I mean, if there isn't any keyboard I'm handling, what's the point? return false; if (areTouchesDisabled(me)) { return super.onTouchEvent(me); }/* ww w .jav a 2 s . c o m*/ final int action = MotionEventCompat.getActionMasked(me); // Gesture detector must be enabled only when mini-keyboard is not // on the screen. if (!mMiniKeyboardPopup.isShowing() && mGestureDetector != null && mGestureDetector.onTouchEvent(me)) { Logger.d(TAG, "Gesture detected!"); mKeyPressTimingHandler.cancelAllMessages(); dismissAllKeyPreviews(); return true; } if (action == MotionEvent.ACTION_DOWN) { mFirstTouchPoint.x = (int) me.getX(); mFirstTouchPoint.y = (int) me.getY(); mIsFirstDownEventInsideSpaceBar = mSpaceBarKey != null && mSpaceBarKey.isInside(mFirstTouchPoint.x, mFirstTouchPoint.y); } // If the motion event is above the keyboard and it's a MOVE event // coming even before the first MOVE event into the extension area if (!mIsFirstDownEventInsideSpaceBar && me.getY() < mExtensionKeyboardYActivationPoint && !mMiniKeyboardPopup.isShowing() && !mExtensionVisible && action == MotionEvent.ACTION_MOVE) { if (mExtensionKeyboardAreaEntranceTime <= 0) mExtensionKeyboardAreaEntranceTime = SystemClock.uptimeMillis(); if (SystemClock.uptimeMillis() - mExtensionKeyboardAreaEntranceTime > DELAY_BEFORE_POPPING_UP_EXTENSION_KBD) { KeyboardExtension extKbd = ((ExternalAnyKeyboard) getKeyboard()).getExtensionLayout(); if (extKbd == null || extKbd.getKeyboardResId() == AddOn.INVALID_RES_ID) { Logger.i(TAG, "No extension keyboard"); return super.onTouchEvent(me); } else { // telling the main keyboard that the last touch was // canceled MotionEvent cancel = MotionEvent.obtain(me.getDownTime(), me.getEventTime(), MotionEvent.ACTION_CANCEL, me.getX(), me.getY(), 0); super.onTouchEvent(cancel); cancel.recycle(); mExtensionVisible = true; dismissAllKeyPreviews(); if (mExtensionKey == null) { mExtensionKey = new AnyKey(new Row(getKeyboard()), getThemedKeyboardDimens()); mExtensionKey.edgeFlags = 0; mExtensionKey.height = 1; mExtensionKey.width = 1; mExtensionKey.popupResId = extKbd.getKeyboardResId(); mExtensionKey.externalResourcePopupLayout = mExtensionKey.popupResId != 0; mExtensionKey.x = getWidth() / 2; mExtensionKey.y = mExtensionKeyboardPopupOffset; } // so the popup will be right above your finger. mExtensionKey.x = (int) me.getX(); onLongPress(extKbd, mExtensionKey, AnyApplication.getConfig().isStickyExtensionKeyboard(), getPointerTracker(me)); // it is an extension.. getMiniKeyboard().setPreviewEnabled(true); return true; } } else { return super.onTouchEvent(me); } } else if (mExtensionVisible && me.getY() > mExtensionKeyboardYDismissPoint) { // closing the popup dismissPopupKeyboard(); return true; } else { return super.onTouchEvent(me); } }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return super.onInterceptTouchEvent(ev); }// w w w . ja va2 s. c o m if (action == MotionEvent.ACTION_DOWN) { mVelocityTracker.clear(); } mVelocityTracker.addMovement(ev); switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mOpenOnClick = isListChildUnderClipped(x, y) && mCollapsibleHeight > 0; } break; case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float dy = y - mInitialTouchY; boolean isSlidingUp = Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null && mCollapseOffset > 0; boolean isSlidingDown = mCollapseOffset == 0 && dy > mTouchSlop; if (isSlidingUp || isSlidingDown) { mActivePointerId = ev.getPointerId(0); mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { resetTouch(); } break; } if (mIsDragging) { mScroller.abortAnimation(); } return mIsDragging || mOpenOnClick; }
From source file:com.android.mail.browse.ConversationContainer.java
private void forwardFakeMotionEvent(MotionEvent original, int newAction) { MotionEvent newEvent = MotionEvent.obtain(original); newEvent.setAction(newAction);/*from www . j a va 2s . co m*/ mWebView.onTouchEvent(newEvent); LogUtils.v(TAG, "in Container.OnTouch. fake: action=%d x/y=%f/%f pointers=%d", newEvent.getActionMasked(), newEvent.getX(), newEvent.getY(), newEvent.getPointerCount()); }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int currentState = mCurrentState; if (STATE_DRAG == currentState || STATE_SCROLL == currentState) { return true; }/* ww w. j a va 2 s.com*/ switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x; mPressedY = y; mIsTapInContent = isTapInContent(x, y); mIsTapInEdgeSlide = isTapInEdgeSlide(x, y); return isOpen() && mIsTapInContent; case MotionEvent.ACTION_MOVE: float dx = x - mPressedX; float dy = y - mPressedY; if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) { return false; } // Detect the vertical scroll if (Math.abs(dy) >= mTouchSlop && mIsTapInContent && canScrollVertically(this, (int) dy, (int) x, (int) y)) { // if the child can response the vertical scroll, we will not to // steal the MotionEvent any more requestDisallowInterceptTouchEvent(true); return false; } if (Math.abs(dx) >= mTouchSlop && mIsTapInContent) { if (!canScrollHorizontally(this, (int) dx, (int) x, (int) y)) { setCurrentState(STATE_DRAG); return true; } } } return false; }
From source file:foam.jellyfish.StarwispActivity.java
@Override public boolean onGenericMotionEvent(final MotionEvent event) { //Get the player # int player = OuyaController.getPlayerNumByDeviceId(event.getDeviceId()); Log.i("starwisp", "ogme"); // Joystick/*from w w w. j a v a 2s . c om*/ if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { //Get all the axis for the event float LS_X = event.getAxisValue(OuyaController.AXIS_LS_X); float LS_Y = event.getAxisValue(OuyaController.AXIS_LS_Y); float RS_X = event.getAxisValue(OuyaController.AXIS_RS_X); float RS_Y = event.getAxisValue(OuyaController.AXIS_RS_Y); float L2 = event.getAxisValue(OuyaController.AXIS_L2); float R2 = event.getAxisValue(OuyaController.AXIS_R2); Log.i("starwisp", "controller " + LS_X + " " + LS_Y + RS_X + " " + RS_Y + L2 + " " + R2); Scheme.eval("(on-fling " + LS_X * -500 + " " + LS_Y * -500 + ")"); } //Touchpad if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { //Print the pixel coordinates of the cursor Log.i("starwisp", "Cursor X: " + event.getX() + "Cursor Y: " + event.getY()); } return true; }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override public boolean onTouchEvent(MotionEvent event) { final float x = event.getX(); final float y = event.getY(); final int currentState = mCurrentState; final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x;/*w w w . j a v a 2 s . c om*/ mPressedY = y; mIsTapInContent = isTapInContent(x, y); mIsTapInEdgeSlide = isTapInEdgeSlide(x, y); if (mIsTapInContent) { mScroller.abortAnimation(); } break; case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(event); if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) { return false; } if (Math.abs(x - mPressedX) >= mTouchSlop && mIsTapInContent && currentState != STATE_DRAG) { getParent().requestDisallowInterceptTouchEvent(true); setCurrentState(STATE_DRAG); } if (STATE_DRAG != currentState) { mLastMotionX = x; return false; } drag(mLastMotionX, x); mLastMotionX = x; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: if (STATE_DRAG == currentState) { mVelocityTracker.computeCurrentVelocity(1000); endDrag(x, mVelocityTracker.getXVelocity()); } else if (mIsTapInContent && MotionEvent.ACTION_UP == action) { performContentTap(); } mVelocityTracker.clear(); getParent().requestDisallowInterceptTouchEvent(false); mIsTapInContent = mIsTapInEdgeSlide = false; break; } return true; }
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onTouchEvent(ev); }/*from w w w. j a v a 2 s .c o m*/ // looks like the ViewPager wants to step in if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && (UP || CANCEL)"); } if (ev.getAction() == MotionEvent.ACTION_UP) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), false); mDayPickerPagerAdapter.onDateRangeSelectionEnded(mTempSelectedDate); } } mIsLongPressed = false; mInitialDownX = -1; mInitialDownY = -1; mScrollingDirection = NOT_SCROLLING; if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } //return true; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_DOWN) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && DOWN"); } mScrollingDirection = NOT_SCROLLING; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_MOVE) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && MOVE"); } int direction = resolveDirectionForScroll(ev.getX()); boolean directionChanged = mScrollingDirection != direction; if (directionChanged) { if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } } if (mScrollerRunnable == null) { mScrollerRunnable = new ScrollerRunnable(); } mScrollingDirection = direction; if (mScrollingDirection == NOT_SCROLLING) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), true); if (mTempSelectedDate != null) { mDayPickerPagerAdapter.onDateRangeSelectionUpdated(mTempSelectedDate); } } } else if (directionChanged) { // SCROLLING_LEFT || SCROLLING_RIGHT post(mScrollerRunnable); } } return mIsLongPressed || super.onTouchEvent(ev); }
From source file:com.android.BluetoothManager.UI.viewpager.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }/*from w ww.j av a2 s.c o m*/ if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; mViewPager.fakeDragBy(deltaX); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.alibaba.akita.widget.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }// w w w . jav a2 s .c om if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; try { mViewPager.fakeDragBy(deltaX); } catch (Exception e) { e.printStackTrace(); } } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) { try { mViewPager.endFakeDrag(); } catch (NullPointerException npe) { npe.printStackTrace(); // fix a crash report. } } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java
/** * This touch allowed.//from ww w .j av a 2 s . c om * * @param ev the ev * @return true, if successful */ private boolean thisTouchAllowed(MotionEvent ev) { int x = (int) (ev.getX() + mScrollX); if (isMenuOpen()) { return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x); } else { switch (mTouchMode) { case SlidingMenu.TOUCHMODE_FULLSCREEN: return !isInIgnoredView(ev); case SlidingMenu.TOUCHMODE_NONE: return false; case SlidingMenu.TOUCHMODE_MARGIN: return mViewBehind.marginTouchAllowed(mContent, x); } } return false; }