List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.android.utils.ExploreByTouchHelper.java
/** * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when * the Explore by Touch feature is enabled. * <p>// w w w. j a v a2 s. c om * This method should be called by overriding * {@link View#dispatchHoverEvent}: * * <pre> * @Override * public boolean dispatchHoverEvent(MotionEvent event) { * if (mHelper.dispatchHoverEvent(this, event) { * return true; * } * return super.dispatchHoverEvent(event); * } * </pre> * * @param event The hover event to dispatch to the virtual view hierarchy. * @return Whether the hover event was handled. */ public boolean dispatchHoverEvent(MotionEvent event) { if (!mManager.isTouchExplorationEnabled()) { return false; } int virtualViewId = getVirtualViewIdAt(event.getX(), event.getY()); if (virtualViewId == INVALID_ID) { virtualViewId = ROOT_ID; } switch (event.getAction()) { case MotionEvent.ACTION_HOVER_ENTER: case MotionEvent.ACTION_HOVER_MOVE: setHoveredVirtualViewId(virtualViewId); break; case MotionEvent.ACTION_HOVER_EXIT: setHoveredVirtualViewId(virtualViewId); break; } return true; }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent me) { if (mStripVisibilityGroup.isShowingImportantNoticeStrip()) { return false; }/*from w ww . ja va 2 s . c o m*/ // Detecting sliding up finger to show {@link MoreSuggestionsView}. if (!mMoreSuggestionsView.isShowingInParent()) { mLastX = (int) me.getX(); mLastY = (int) me.getY(); return mMoreSuggestionsSlidingDetector.onTouchEvent(me); } if (mMoreSuggestionsView.isInModalMode()) { return false; } final int action = me.getAction(); final int index = me.getActionIndex(); final int x = (int) me.getX(index); final int y = (int) me.getY(index); if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance || mOriginY - y >= mMoreSuggestionsModalTolerance) { // Decided to be in the sliding suggestion mode only when the touch point has been moved // upward. Further {@link MotionEvent}s will be delivered to // {@link #onTouchEvent(MotionEvent)}. mNeedsToTransformTouchEventToHoverEvent = AccessibilityUtils.getInstance().isTouchExplorationEnabled(); mIsDispatchingHoverEventToMoreSuggestions = false; return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { // Decided to be in the modal input mode. mMoreSuggestionsView.setModalMode(); } return false; }
From source file:app.android.datetimepicker.date.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: final int day = getDayFromLocation(event.getX(), event.getY()); if (day >= 0) { onDayClick(day);// w w w. j a v a 2 s . c o m } break; } return true; }
From source file:SwipeListView.java
/** * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) *///w w w . j av a2 s .co m @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: super.onInterceptTouchEvent(ev); 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); }
From source file:activitydialogtest.pczhu.com.everytest.refresh2.SwipeListView.java
/** * @see ListView#onInterceptTouchEvent(MotionEvent) *///w ww .j a va 2 s. c o m @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); }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent ev) { mHeaderTouched = false;/*from ww w . j a v a2 s. co m*/ if (super.onInterceptTouchEvent(ev)) return true; if (mScrollState == SCROLL_STATE_IDLE) { final int y = (int) ev.getY(); final int x = (int) ev.getX(); for (int i = mSize; --i >= 0;) { final PinnedHeader header = mHeaders[i]; // For RTL layouts, this also takes into account that the scrollbar is on the left // side. final int padding = getPaddingLeft(); if (header.visible && header.y <= y && header.y + header.height > y && x >= padding && padding + header.view.getWidth() >= x) { mHeaderTouched = true; if (mScrollToSectionOnHeaderTouch && ev.getAction() == MotionEvent.ACTION_DOWN) return smoothScrollToPartition(i); else return true; } } } return false; }
From source file:com.asiaonline.tobaccoassistant.widget.SwipeListView.java
/** * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) *///from w w w . j a v a2s. com @Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = MotionEventCompat.getActionMasked(ev); final float x = ev.getX(); final float y = ev.getY(); getParent().requestDisallowInterceptTouchEvent(true); 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); }
From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java
/** * This handles receiving the touch events in the WebView so that we can * toggle between fullscreen and windowed mode. * <p/>/* ww w . ja v a 2 s. c om*/ * The first time the user touches the screen we save the X and Y coordinates. * If we receive a {@link MotionEvent#ACTION_DOWN} event we compare the previous * X and Y coordinates to the saved coordinates, if they are greater than {@link * #MOVE_THRESHOLD} * we prevent the toggle from windowed mode to fullscreen mode or vice versa, the idea * being that the user is either dragging the image or using pinch-to-zoom. * <p/> * TODO: Implement handling for double tap to zoom. * * @return The {@link OnTouchListener} for the {@link WebView} to use. */ public OnTouchListener getWebViewOnTouchListener() { return new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mCancelClick = false; mDownXPos = event.getX(); mDownYPos = event.getY(); break; case MotionEvent.ACTION_UP: if (!mCancelClick) { Intent intent = new Intent(Constants.Broadcast.BROADCAST_TOGGLE_FULLSCREEN); intent.putExtra(Constants.Extra.EXTRA_IS_SYSTEM_UI_VISIBLE, mSystemUiStateProvider.isSystemUiVisible()); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); } break; case MotionEvent.ACTION_MOVE: if (Math.abs(event.getX() - mDownXPos) > MOVE_THRESHOLD || Math.abs(event.getY() - mDownYPos) > MOVE_THRESHOLD) { mCancelClick = true; } break; } // Return false so that we still let the WebView consume the event return false; } }; }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean isIntercepted = super.onInterceptTouchEvent(ev); int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = mLastX = (int) ev.getX(); mDownY = (int) ev.getY(); isIntercepted = false;//from ww w.ja v a2 s. c o m break; case MotionEvent.ACTION_MOVE: int disX = (int) (ev.getX() - mDownX); int disY = (int) (ev.getY() - mDownY); isIntercepted = Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY); break; case MotionEvent.ACTION_UP: isIntercepted = false; if (isMenuOpen() && mSwipeCurrentHorizontal.isClickOnContentView(getWidth(), ev.getX())) { smoothCloseMenu(); isIntercepted = true; } break; case MotionEvent.ACTION_CANCEL: isIntercepted = false; if (!mScroller.isFinished()) mScroller.abortAnimation(); break; } return isIntercepted; }
From source file:dk.ciid.android.infobooth.activities.SubscriptionFinalActivity.java
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try {//w w w .j a v a 2 s.c o m if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe, previous if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // go to the next screen changeActivity("dk.ciid.android.infobooth.activities.INTRODUCTIONACTIVITY"); } // left to right swipe, next else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { // go to the next screen changeActivity("dk.ciid.android.infobooth.activities.INTRODUCTIONACTIVITY"); } // bottom to top swipe else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { } // top to bottom swipe else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { } } catch (Exception e) { // nothing } return true; }