List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.dycody.android.idealnote.DetailFragment.java
@SuppressLint("NewApi") @Override//from w w w .j a v a2 s. com public boolean onTouch(View v, MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Log.v(Constants.TAG, "MotionEvent.ACTION_DOWN"); int w; Point displaySize = Display.getUsableSize(mainActivity); w = displaySize.x; if (x < Constants.SWIPE_MARGIN || x > w - Constants.SWIPE_MARGIN) { swiping = true; startSwipeX = x; } break; case MotionEvent.ACTION_UP: Log.v(Constants.TAG, "MotionEvent.ACTION_UP"); if (swiping) swiping = false; break; case MotionEvent.ACTION_MOVE: if (swiping) { Log.v(Constants.TAG, "MotionEvent.ACTION_MOVE at position " + x + ", " + y); if (Math.abs(x - startSwipeX) > Constants.SWIPE_OFFSET) { swiping = false; FragmentTransaction transaction = mainActivity.getSupportFragmentManager().beginTransaction(); mainActivity.animateTransition(transaction, mainActivity.TRANSITION_VERTICAL); DetailFragment mDetailFragment = new DetailFragment(); Bundle b = new Bundle(); b.putParcelable(Constants.INTENT_NOTE, new Note()); mDetailFragment.setArguments(b); transaction.replace(R.id.fragment_container, mDetailFragment, mainActivity.FRAGMENT_DETAIL_TAG) .addToBackStack(mainActivity.FRAGMENT_DETAIL_TAG).commit(); } } break; default: Log.e(Constants.TAG, "Wrong element choosen: " + event.getAction()); } return true; }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
private void setGestureDetector(final Context context) { this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from w w w . j a v a 2 s .c om*/ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale; float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD) .withPanLimited(false).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (doubleTapListener != null) { return doubleTapListener.onSingleTapConfirmed(e); } performClick(); return true; } @Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = scale <= doubleTapZoomScale * 0.9; float targetScale = zoomIn ? doubleTapZoomScale : Math.min(getWidth() / (float) sWidth(), getHeight() / (float) sHeight()); PointF targetSCenter = viewToSourceCoord(new PointF(e.getX(), e.getY())); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, targetSCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn) { new AnimationBuilder(targetScale, targetSCenter).withInterruptible(false).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, targetSCenter, new PointF(e.getX(), e.getY())) .withInterruptible(false).start(); } // Hacky solution for #15 - after a double tap the // GestureDetector gets in a state where the next // fling is ignored, so here we replace it with a // new one. setGestureDetector(context); invalidate(); return true; } return super.onDoubleTapEvent(e); } }); }
From source file:com.android.launcher3.ItemTouchHelper.java
View findChildView(MotionEvent event) { // first check elevated views, if none, then call RV final float x = event.getX(); final float y = event.getY(); if (mSelected != null) { final View selectedView = mSelected.itemView; if (hitTest(selectedView, x, y, mSelectedStartX + mDx, mSelectedStartY + mDy)) { return selectedView; }//from ww w.ja v a 2s . c o m } for (int i = mRecoverAnimations.size() - 1; i >= 0; i--) { final RecoverAnimation anim = mRecoverAnimations.get(i); final View view = anim.mViewHolder.itemView; if (hitTest(view, x, y, anim.mX, anim.mY)) { return view; } } return mRecyclerView.findChildViewUnder(x, y); }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { // ======================== START ======================== if (!isSwipeBackEnable()) { return super.onTouchEvent(ev); }/* w w w .j a va2 s. co m*/ // ======================== END ======================== if (!mCanSlide) { return super.onTouchEvent(ev); } mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mMoveState = MOVE_STATE_LEFT; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { if (mSlideableView.getLeft() > mSlideRange * mSwipeBackThreshold) { mMoveState = MOVE_STATE_RIGHT; } else { mMoveState = MOVE_STATE_LEFT; } if (isDimmed(mSlideableView)) { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) { // Taps close a dimmed open pane. closePane(mSlideableView, 0); break; } } break; } case MotionEvent.ACTION_CANCEL: { if (mSlideableView.getLeft() > mSlideRange * mSwipeBackThreshold) { mMoveState = MOVE_STATE_RIGHT; } else { mMoveState = MOVE_STATE_LEFT; } break; } default: break; } return wantTouchEvents; }
From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java
@Override public boolean onTouchEvent(final MotionEvent event) { // Return if animation is running if (mAnimator.isRunning()) return true; // If is not idle state, return if (mScrollState != ViewPager.SCROLL_STATE_IDLE) return true; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // Action down touch mIsActionDown = true;/*from w w w. j a v a 2 s. c o m*/ if (!mIsViewPagerMode) break; if (!mIsSwiped) break; // Detect if we touch down on pointer, later to move if (mIsHorizontalOrientation) mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex; else mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex; break; case MotionEvent.ACTION_MOVE: // If pointer touched, so move if (mIsPointerActionDown) { if (mIsHorizontalOrientation) mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true); else mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true); break; } if (mIsActionDown) break; case MotionEvent.ACTION_UP: // Press up and set model index relative to current coordinate if (mIsActionDown) { playSoundEffect(SoundEffectConstants.CLICK); if (mIsHorizontalOrientation) setModelIndex((int) (event.getX() / mModelSize)); else setModelIndex((int) (event.getY() / mModelSize)); } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: default: // Reset action touch variables mIsPointerActionDown = false; mIsActionDown = false; break; } return true; }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { Log.i(TAG, "onTouchEvent()"); final int action = ev.getAction(); boolean wantTouchEvents = true; try {/*from w w w . j av a 2 s . co m*/ mLeftDragger.processTouchEvent(ev); mRightDragger.processTouchEvent(ev); mTopDragger.processTouchEvent(ev); mBottomDragger.processTouchEvent(ev); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onTouchEvent() -- 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: { Log.i(TAG, "onTouchEvent() -- ACTION_UP"); final float x = ev.getX(); final float y = ev.getY(); boolean peekingOnly = true; final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y); if (touchedView != null && isContentView(touchedView)) { final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mLeftDragger.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: { Log.i(TAG, "onTouchEvent() -- ACTION_CANCEL"); closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } } } catch (IllegalArgumentException e) { // TODO: handle exception } boolean result = wantTouchEvents; Log.i(TAG, "onTouchEvent() -- result = " + result); return result; }
From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent()"); final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev) | mTopDragger.shouldInterceptTouchEvent(ev) | mBottomDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_DOWN"); final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;/*from w w w . j av a 2 s . c om*/ mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE"); // If we cross the touch slop, don't perform the delayed peek for an // edge touch. if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2"); mLeftCallback.removeCallbacks(); mRightCallback.removeCallbacks(); mTopCallback.removeCallbacks(); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_CANCEL | ACTION_UP"); closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } boolean result = interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; Log.i(TAG, "onInterceptTouchEvent() -- result = " + result); return result; }
From source file:com.android.ex.chips.RecipientEditTextView.java
@Override public void onLongPress(final MotionEvent event) { if (mSelectedChip != null) return;//from www . jav a 2 s.c o m final float x = event.getX(); final float y = event.getY(); final int offset = putOffsetInRange(x, y); final DrawableRecipientChip currentChip = findChip(offset); if (currentChip != null) // Copy the selected chip email address. showCopyDialog(currentChip.getEntry().getDestination()); }
From source file:com.buka.view.grid.ExtendableListView.java
private boolean onTouchDown(final MotionEvent event) { final int x = (int) event.getX(); final int y = (int) event.getY(); int motionPosition = pointToPosition(x, y); mVelocityTracker.clear();/*w ww .j a v a 2s .c o m*/ mActivePointerId = MotionEventCompat.getPointerId(event, 0); // TODO : use the motion position for fling support // TODO : support long press! // startLongPressCheck(); if ((mTouchMode != TOUCH_MODE_FLINGING) && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { // is it a tap or a scroll .. we don't know yet! mTouchMode = TOUCH_MODE_DOWN; // TODO : add handling for a click removed from here if (event.getEdgeFlags() != 0 && motionPosition < 0) { // If we couldn't find a view to click on, but the down event was touching // the edge, we will bail out and try again. This allows the edge correcting // code in ViewRoot to try to find a nearby view to select return false; } } else if (mTouchMode == TOUCH_MODE_FLINGING) { mTouchMode = TOUCH_MODE_SCROLLING; mMotionCorrection = 0; motionPosition = findMotionRow(y); } mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mLastY = Integer.MIN_VALUE; return true; }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
private void handleQsDown(MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN && shouldQuickSettingsIntercept(event.getX(), event.getY(), -1)) { mQsTracking = true;/* w w w . j a v a 2s. c om*/ onQsExpansionStarted(); mInitialHeightOnTouch = mQsExpansionHeight; mInitialTouchY = event.getX(); mInitialTouchX = event.getY(); // If we interrupt an expansion gesture here, make sure to update the state correctly. notifyExpandingFinished(); } }