List of usage examples for android.view MotionEvent getRawY
public final float getRawY()
From source file:tu.tracking.system.activities.TargetsListActivity.java
private TargetModel getTargetFromList(MotionEvent e) { ListAdapter listAdapter = listViewTargets.getAdapter(); float x = e.getX(); float y = e.getY(); float rx = e.getRawX(); float ry = e.getRawY(); int index = listViewTargets.pointToPosition(Math.round(x), Math.round(y)); if (index < 0 || index >= targets.size()) { return null; }/*w w w . j a v a 2s . c om*/ return (TargetModel) listAdapter.getItem(index); }
From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java
public boolean handleRootTouchEvent(MotionEvent event) { final int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN || mSlideState == SlideState.SkipThisRound) { return false; }//w w w .j a v a2 s . c o m final float x = event.getRawX(); final float y = event.getRawY(); final float horzOffset = Math.abs(x - mLastX); final float vertOffset = Math.abs(y - mLastY); if (action == MotionEvent.ACTION_MOVE && handleTouchMove(x, y, horzOffset, vertOffset)) { return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { int width = getMeasuredWidth(); long timeOffset = System.currentTimeMillis() - mDownTimestamp; mSlideState = SlideState.None; if (horzOffset > width / 2 || (timeOffset <= 600 && horzOffset > width / 6)) { continueAnimation(horzOffset, width); } else { updateSlideOffset(0); } return true; } return false; }
From source file:io.syng.fragment.WebViewFragment.java
@Override public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX, float velocityY) { float gapX = start.getRawX() - finish.getRawX(); float gapY = start.getRawY() - finish.getRawY(); float distanceX = Math.abs(gapX); float distanceY = Math.abs(gapY); if (distanceY > distanceX) { // up downs if (gapY > 0) { // up System.out.println("Swipe up"); } else {/*from www. j a va 2 s . c om*/ // down System.out.println("Swipe down"); BaseActivity activity = (BaseActivity) getActivity(); activity.showToolbar(0); activity.hideToolbar(2); } } else { // left right if (gapX > 0) { // left System.out.println("Swipe left"); } else { // rights System.out.println("Swipe right"); } } return false; }
From source file:com.kerkr.edu.recycleView.SwipeToDismissTouchListener.java
private boolean move(MotionEvent motionEvent) { if (mSwipeView == null || mVelocityTracker == null || mPaused) { return false; }/*from w w w .j a va 2s . c o m*/ mVelocityTracker.addMovement(motionEvent); float deltaX = motionEvent.getRawX() - mDownX; float deltaY = motionEvent.getRawY() - mDownY; if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) { mSwiping = true; mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop); mSwipeView.setPressed(false); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mSwipeView.onTouchEvent(cancelEvent); } //Prevent swipes to disallowed directions if ((deltaX < 0 && mAllowedSwipeDirection == SwipeDirection.RIGHT) || (deltaX > 0 && mAllowedSwipeDirection == SwipeDirection.LEFT)) { resetMotion(); return false; } if (mSwiping) { mTranslationX = deltaX; ViewCompat.setTranslationX(mSwipeView, deltaX - mSwipingSlop); ViewCompat.setAlpha(mSwipeView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth))); return true; } return false; }
From source file:com.king.android.common.widget.badge.BGADragBadgeView.java
@Override public boolean onTouchEvent(MotionEvent event) { int badgeWidth = (int) mBadgeViewHelper.getBadgeRectF().width(); int badgeHeight = (int) mBadgeViewHelper.getBadgeRectF().height(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mAnimator.isRunning()) { mStartX = (int) event.getRawX() - badgeWidth / 2; mStartY = (int) event.getRawY() - badgeHeight / 2 - getStatusBarHeight(getContext()); mWindowManager.addView(this, mLayoutParams); postInvalidate();//from ww w . ja v a 2 s . c o m } break; case MotionEvent.ACTION_MOVE: if (!mAnimator.isRunning()) { int newX = (int) event.getRawX() - badgeWidth / 2; int newY = (int) event.getRawY() - badgeHeight / 2 - getStatusBarHeight(getContext()); if (newX < 0) { newX = 0; } if (newY < 0) { newY = 0; } if (newX > mWindowManager.getDefaultDisplay().getWidth() - badgeWidth) { newX = mWindowManager.getDefaultDisplay().getWidth() - badgeWidth; } if (newY > mWindowManager.getDefaultDisplay().getHeight() - badgeHeight) { newY = mWindowManager.getDefaultDisplay().getHeight() - badgeHeight; } mStartX = newX; mStartY = newY; postInvalidate(); } break; case MotionEvent.ACTION_UP: if (!mAnimator.isRunning()) { if (mBadgeViewHelper.satisfyMoveDismissCondition(event)) { startDismissAnim(); } else { mWindowManager.removeView(this); } } break; } return true; }
From source file:com.telenav.expandablepager.SlidingContainer.java
private boolean translate(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int stepSize = stopValues.size(); switch (action) { case MotionEvent.ACTION_DOWN: { startYCoordinate = ev.getRawY(); translated = 0;/*w w w . j a va 2 s. c o m*/ break; } case MotionEvent.ACTION_MOVE: { touchDelta = (startYCoordinate - ev.getRawY()); if (Math.abs(touchDelta) > slideThreshold) { float startingPointY, nextPointY, maxDiff, tempDelta, auxDelta = 0; tempDelta = touchDelta + (touchDelta < 0 ? 1 : -1) * slideThreshold; startingPointY = stopValues.get(stopValueIndex); if (!isUpwardGesture() && stopValueIndex >= 1) { nextPointY = stopValues.get(stopValueIndex - 1); maxDiff = nextPointY - stopValues.get(stopValueIndex); auxDelta = Math.min(-tempDelta, maxDiff); } else if (isUpwardGesture() && stopValueIndex < stepSize - 1) { nextPointY = stopValues.get(stopValueIndex + 1); maxDiff = nextPointY - stopValues.get(stopValueIndex); auxDelta = Math.max(-tempDelta, maxDiff); } float preTranslated = translated; translated = startingPointY + auxDelta; setTranslationY(translated); if (preTranslated != translated) notifySlideEvent(translated); return false; } return true; } case MotionEvent.ACTION_UP: { if (Math.abs(touchDelta) > slideThreshold) { if (!isUpwardGesture() && stopValueIndex > 0) stopValueIndex--; else if (isUpwardGesture() && stopValueIndex < stepSize - 1) stopValueIndex++; if (!stopValues.contains(translated)) { animate(stopValues.get(stopValueIndex)); } else onSettled(stopValueIndex); startYCoordinate = -1; touchDelta = 0; } break; } case MotionEvent.ACTION_CANCEL: { break; } case MotionEvent.ACTION_POINTER_UP: { break; } } return true; }
From source file:com.tmall.wireless.tangram.view.BannerView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = ev.getAction(); float x = ev.getRawX(); float y = ev.getRawY(); switch (action) { case MotionEvent.ACTION_DOWN: xDown = x;//from w ww. j a va 2 s. co m yDown = y; break; case MotionEvent.ACTION_MOVE: int xDiff = (int) (x - xDown); int yDiff = (int) (y - yDown); //y?x? if (Math.abs(xDiff) >= Math.abs(yDiff)) { getParent().requestDisallowInterceptTouchEvent(true); } else { getParent().requestDisallowInterceptTouchEvent(false); } break; } return false; }
From source file:zuo.biao.library.base.BaseFragmentActivity.java
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (onPageReturnListener != null) { float maxDragHeight = getResources().getDimension(R.dimen.page_drag_max_height); float distanceY = e2.getRawY() - e1.getRawY(); if (distanceY < maxDragHeight && distanceY > -maxDragHeight) { float minDragWidth = getResources().getDimension(R.dimen.page_drag_min_width); float distanceX = e2.getRawX() - e1.getRawX(); if (distanceX > minDragWidth) { onPageReturnListener.onPageReturn(); return true; }/* w ww . j a v a 2 s . co m*/ } } return false; }
From source file:com.xee.auth.SignInButton.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { // detect if user is clicking outside Rect viewRect = new Rect(); getGlobalVisibleRect(viewRect);/*from w w w. j a v a2 s .c o m*/ if (viewRect.contains((int) event.getRawX(), (int) event.getRawY())) { if (mListener != null) { mListener.onClick(this); } if (mConnectionCallback != null) { signIn(); } } } return super.dispatchTouchEvent(event); }
From source file:com.waz.zclient.pages.main.conversationlist.views.listview.SwipeListView.java
/** * Retrieves the child of the list view that is hit by the touch event. If it * is the first item or a disabled one, targetView is set to null. */// w ww .ja va2s. c o m private void getHitChild(MotionEvent motionEvent) { int[] listViewCoords = new int[2]; getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; int childCount = getChildCount(); View child; for (int i = 0; i < childCount; i++) { child = getChildAt(i); child.getHitRect(targetRect); if (targetRect.contains(x, y)) { int position = getPositionForView(child); boolean allowSwipe = child instanceof SwipeListRow && ((SwipeListRow) child).isSwipeable(); if (allowSwipe) { if (position != targetChildPosition) { closeItem(); } targetChildPosition = position; // TODO: Investigate causes of ClassCastExecption. Perhaps archiving related views? try { targetView = (SwipeListRow) child; targetView .setMaxOffset(allowSwipeAway ? viewWidth / 2 : listRowMenuIndicatorMaxSwipeOffset); } catch (ClassCastException e) { Timber.e(e, "ClassCastException when swiping"); } downX = motionEvent.getRawX(); } else { closeItem(); targetView = null; } return; } } // no child hit closeItem(); targetView = null; }