List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { //super.onInterceptTouchEvent(event); float endX = event.getX(); float endY = event.getY(); if (isAClick(startX, endX, startY, endY)) { if (mOnItemClickListener != null) { mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem()); }/*from w ww .j a va2 s .c om*/ } else { super.onInterceptTouchEvent(event); } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { startX = event.getX(); startY = event.getY(); } float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onInterceptTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:adapters.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { //We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int) ev.getX(); mInitialTouch.y = (int) ev.getY(); default:/*from w ww . j a v a 2 s .co m*/ ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); }
From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java
@Override public boolean onTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { //super.onInterceptTouchEvent(event); float endX = event.getX(); float endY = event.getY(); if (isAClick(startX, endX, startY, endY)) { if (mOnItemClickListener != null) { mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem()); }/*from w w w . jav a 2 s.co m*/ //launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!! } else { super.onTouchEvent(event); } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { startX = event.getX(); startY = event.getY(); } /*if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onTouchEvent(event); }*/ float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onTouchEvent(event); } } return false; }
From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java
/** *//* w ww.j a va2s. c o m*/ @Override boolean shouldStartPull(MotionEvent event) { switch (mState) { case STATE_PULLING_AT_START: return mTouchLastX < event.getX(); case STATE_PULLING_AT_END: return mTouchLastX > event.getX(); } return false; }
From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java
/** */// w w w.java2 s. com @Override boolean shouldCancelPull(MotionEvent event) { switch (mState) { case STATE_PULLING_AT_START: return mTouchLastX > event.getX(); case STATE_PULLING_AT_END: return mTouchLastX < event.getX(); } return true; }
From source file:com.albedinsky.android.ui.controller.HorizontalPullHelper.java
/** *//*w w w . ja va2 s.c o m*/ @Override boolean shouldStartPull(MotionEvent event) { switch (mState) { case STATE_PULLING_AT_START: return (mMode & START) != 0 && mTouchLastX < event.getX(); case STATE_PULLING_AT_END: return (mMode & END) != 0 && mTouchLastX > event.getX(); } return false; }
From source file:com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy.java
/** * Receives hover events when touch exploration is turned on in SDK versions * ICS and higher.//w ww . j a v a 2 s . c o m * * @param event The hover event. * @return {@code true} if the event is handled */ public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) { final int x = (int) event.getX(); final int y = (int) event.getY(); final Key previousKey = mLastHoverKey; final Key key; if (pointInView(x, y)) { key = tracker.getKeyOn(x, y); } else { key = null; } mLastHoverKey = key; switch (event.getAction()) { case MotionEvent.ACTION_HOVER_EXIT: // Make sure we're not getting an EXIT event because the user slid // off the keyboard area, then force a key press. if (key != null) { getAccessibilityNodeProvider().simulateKeyPress(key); } //$FALL-THROUGH$ case MotionEvent.ACTION_HOVER_ENTER: return onHoverKey(key, event); case MotionEvent.ACTION_HOVER_MOVE: if (key != previousKey) { return onTransitionKey(key, previousKey, event); } else { return onHoverKey(key, event); } } return false; }
From source file:com.barchart.tester.pager.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { // We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int) ev.getX(); mInitialTouch.y = (int) ev.getY(); default:/*from w w w . j av a2s. c o m*/ ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); }
From source file:cn.limc.androidcharts.event.SlipGestureDetector.java
public boolean onTouchEvent(MotionEvent event) { int pointers = event.getPointerCount(); switch (event.getAction() & MotionEvent.ACTION_MASK) { // ?// w w w . j a v a 2 s .c o m case MotionEvent.ACTION_DOWN: initalX = event.getX(); if (pointers > 1) { touchMode = TOUCH_MODE_MULTI; } else { touchMode = TOUCH_MODE_SINGLE; } break; case MotionEvent.ACTION_UP: startPointA = null; startPointB = null; break; case MotionEvent.ACTION_POINTER_UP: startPointA = null; startPointB = null; case MotionEvent.ACTION_POINTER_DOWN: olddistance = calcDistance(event); if (olddistance > MIN_DISTANCE) { touchMode = TOUCH_MODE_MULTI; startPointA = new PointF(event.getX(0), event.getY(0)); startPointB = new PointF(event.getX(1), event.getY(1)); } return true; case MotionEvent.ACTION_MOVE: if (touchMode == TOUCH_MODE_SINGLE) { final float finalX = event.getX(); // MotionEvent finalEvent = event; if (performLongClick) { return super.onTouchEvent(event); } else { if (finalX - initalX >= mStickScaleValue) { if (onSlipGestureListener != null) { onSlipGestureListener.onMoveRight((ISlipable) instance, event); } } else if (initalX - finalX >= mStickScaleValue) { if (onSlipGestureListener != null) { onSlipGestureListener.onMoveLeft((ISlipable) instance, event); } } initalX = finalX; // initalEvent = finalEvent; return true; } } else if (touchMode == TOUCH_MODE_MULTI) { newdistance = calcDistance(event); if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) { if (onZoomGestureListener != null) { if (newdistance > olddistance) { onZoomGestureListener.onZoomIn((IZoomable) instance, event); } else { onZoomGestureListener.onZoomOut((IZoomable) instance, event); } } } olddistance = newdistance; return true; // startPointA = new PointF(event.getX(), event.getY()); // startPointB = new PointF(event.getX(1), event.getY(1)); } break; } return super.onTouchEvent(event); }
From source file:com.android.calculator2.CalculatorPadViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean shouldIntercept = super.onInterceptTouchEvent(ev); // Only allow the current item to receive touch events. if (!shouldIntercept && ev.getActionMasked() == MotionEvent.ACTION_DOWN) { final int x = (int) ev.getX() + getScrollX(); final int y = (int) ev.getY() + getScrollY(); final int childCount = getChildCount(); for (int i = childCount - 1; i >= 0; --i) { final int childIndex = getChildDrawingOrder(childCount, i); final View child = getChildAt(childIndex); if (child.getVisibility() == View.VISIBLE && x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { shouldIntercept = (childIndex != getCurrentItem()); break; }//from ww w . ja v a2 s . c o m } } return shouldIntercept; }