List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
protected boolean isInChartBounds(MotionEvent event) { float x = event.getX(); float y = event.getY(); if (x >= (drawingBounds.left + fretNumberBounds.width()) && x < drawingBounds.right) { if (y >= (drawingBounds.top + stringMarkerBounds.height()) && y < drawingBounds.bottom) { return true; }// w ww . j a va2 s . c o m } return false; }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
protected boolean isInStringMarkerBounds(MotionEvent event) { float x = event.getX(); float y = event.getY(); if (x >= drawingBounds.left && x < drawingBounds.right) { if (y >= drawingBounds.top && y < (drawingBounds.top + stringMarkerBounds.height())) { return true; }// w w w . j av a 2 s . c o m } return false; }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
protected int getSelectedString(MotionEvent event) { float x = event.getX(); int i;//ww w . ja va 2 s . c o m for (i = 0; i < stringCount; i++) { if (x < (((stringMarkerBounds.left) + (i * stringDistance) + (i * stringSize)) + (stringDistance / 2))) { break; } } return stringCount - i; }
From source file:com.android.dialer.widget.OverlappingPaneLayout.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()); }// ww w . j a va 2 s. c o m } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } return false; } switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if (ady > slop && adx > ady || !isCapturableViewUnder((int) x, (int) y)) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag; }
From source file:com.android.mail.browse.ConversationItemView.java
/** * ConversationItemView is given the first chance to handle touch events. *//*w w w.j a v a 2s. co m*/ @Override public boolean onTouchEvent(MotionEvent event) { Utils.traceBeginSection("on touch event"); int x = (int) event.getX(); int y = (int) event.getY(); if (!mSwipeEnabled) { Utils.traceEndSection(); return onTouchEventNoSwipe(event); } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (isTouchInContactPhoto(x, y) || isTouchInInfoIcon(x, y) || isTouchInStar(x, y)) { mDownEvent = true; Utils.traceEndSection(); return true; } break; case MotionEvent.ACTION_UP: if (mDownEvent) { if (isTouchInContactPhoto(x, y)) { // Touch on the check mark Utils.traceEndSection(); mDownEvent = false; toggleCheckedState(); Utils.traceEndSection(); return true; } else if (isTouchInInfoIcon(x, y)) { // Touch on the info icon mDownEvent = false; if (mConversationItemAreaClickListener != null) { mConversationItemAreaClickListener.onInfoIconClicked(); } Utils.traceEndSection(); return true; } else if (isTouchInStar(x, y)) { // Touch on the star mDownEvent = false; if (mConversationItemAreaClickListener == null) { toggleStar(); } else { mConversationItemAreaClickListener.onStarClicked(); } Utils.traceEndSection(); return true; } } break; } // Let View try to handle it as well. boolean handled = super.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { Utils.traceEndSection(); return true; } Utils.traceEndSection(); return handled; }
From source file:com.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (!isEnabled() || !mIsSlidingEnabled || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel();//from w w w .ja va 2s . c o m return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_MOVE: { final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int dragSlop = mDragHelper.getTouchSlop(); // Handle any horizontal scrolling on the drag view. if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) { return super.onInterceptTouchEvent(ev); } if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, (int) mInitialMotionY)) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } break; } } return mDragHelper.shouldInterceptTouchEvent(ev); }
From source file:com.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { mTopDragger.processTouchEvent(ev);//from w ww. ja v a 2 s.c om mBottomDragger.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; mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_UP: { final float x = ev.getX(); final float y = ev.getY(); boolean peekingOnly = true; final View touchedView = mTopDragger.findTopChildUnder((int) x, (int) y); if (touchedView != null && isContentView(touchedView)) { final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mTopDragger.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: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } } return wantTouchEvents; }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
protected boolean isInFretNumberBounds(MotionEvent event) { if (showFretNumbers) { float x = event.getX(); float y = event.getY(); if (x >= drawingBounds.left && x < (drawingBounds.left + fretNumberBounds.width())) { if (y >= drawingBounds.top && y < drawingBounds.bottom) { return true; }/*from w w w. ja va 2s. c o m*/ } } return false; }
From source file:aksha.upcomingdemo.HorizontalListView.java
protected boolean onDown(MotionEvent e) { // If the user just caught a fling, then disable all touch actions until they release their finger mBlockTouchAction = !mFlingTracker.isFinished(); // Allow a finger down event to catch a fling mFlingTracker.forceFinished(true);//from www . j a v a 2 s .com setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE); unpressTouchedChild(); if (!mBlockTouchAction) { // Find the child that was pressed final int index = getChildIndex((int) e.getX(), (int) e.getY()); if (index >= 0) { // Save off view being touched so it can later be released mViewBeingTouched = getChildAt(index); if (mViewBeingTouched != null) { // Set the view as pressed mViewBeingTouched.setPressed(true); refreshDrawableState(); } } } return true; }
From source file:com.android.mail.browse.ConversationItemView.java
private boolean onTouchEventNoSwipe(MotionEvent event) { Utils.traceBeginSection("on touch event no swipe"); boolean handled = false; int x = (int) event.getX(); int y = (int) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (isTouchInContactPhoto(x, y) || isTouchInInfoIcon(x, y) || isTouchInStar(x, y)) { mDownEvent = true;/*from www . j a v a 2s. c om*/ handled = true; } break; case MotionEvent.ACTION_CANCEL: mDownEvent = false; break; case MotionEvent.ACTION_UP: if (mDownEvent) { if (isTouchInContactPhoto(x, y)) { // Touch on the check mark toggleCheckedState(); } else if (isTouchInInfoIcon(x, y)) { if (mConversationItemAreaClickListener != null) { mConversationItemAreaClickListener.onInfoIconClicked(); } } else if (isTouchInStar(x, y)) { // Touch on the star if (mConversationItemAreaClickListener == null) { toggleStar(); } else { mConversationItemAreaClickListener.onStarClicked(); } } handled = true; } break; } if (!handled) { handled = super.onTouchEvent(event); } Utils.traceEndSection(); return handled; }