List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.appsummary.luoxf.myappsummary.recyclerView.fastscroll.Views.FastScroller.java
/** * Handles the touch event and determines whether to show the fast scroller (or updates it if * it is already showing).//from ww w . ja v a2s.c om */ public void handleTouchEvent(MotionEvent ev, int downX, int downY, int lastY) { ViewConfiguration config = ViewConfiguration.get(mRecyclerView.getContext()); int action = ev.getAction(); int y = (int) ev.getY(); switch (action) { case MotionEvent.ACTION_DOWN: if (isNearPoint(downX, downY)) { mTouchOffset = downY - mThumbPosition.y; } break; case MotionEvent.ACTION_MOVE: // Check if we should start scrolling if (!mIsDragging && isNearPoint(downX, downY) && Math.abs(y - downY) > config.getScaledTouchSlop()) { mRecyclerView.getParent().requestDisallowInterceptTouchEvent(true); mIsDragging = true; mTouchOffset += (lastY - downY); mPopup.animateVisibility(true); } if (mIsDragging) { // Update the fastscroller section name at this touch position int top = 0; int bottom = mRecyclerView.getHeight() - mThumbHeight; float boundedY = (float) Math.max(top, Math.min(bottom, y - mTouchOffset)); String sectionName = mRecyclerView.scrollToPositionAtProgress((boundedY - top) / (bottom - top)); mPopup.setSectionName(sectionName); mPopup.animateVisibility(!sectionName.isEmpty()); mRecyclerView.invalidate(mPopup.updateFastScrollerBounds(mRecyclerView, mThumbPosition.y)); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchOffset = 0; if (mIsDragging) { mIsDragging = false; mPopup.animateVisibility(false); } break; } }
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastTouchY = currentTouchY;/* www .j a va 2 s . c om*/ break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastTouchY; if (Math.abs(differentY) > mTouchSlop) { if (!isHeaderViewCompleteInvisible() || (isContentViewToTop() && isHeaderViewCompleteInvisible() && mIsInControl)) { mLastTouchY = currentTouchY; return true; } } break; } return super.onInterceptTouchEvent(ev); }
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
/** * Launch Ripple animation for the current view with a MotionEvent * * @param event MotionEvent registered by the Ripple gesture listener *//* www. j a v a2 s .co m*/ public void animateRipple(MotionEvent event) { createAnimation(event.getX(), event.getY()); }
From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { float currentTouchY = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mLastDispatchY = currentTouchY;// ww w . j a v a 2 s.c o m break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastDispatchY; mLastDispatchY = currentTouchY; if (isContentViewToTop() && isHeaderViewCompleteInvisible()) { if (differentY >= 0 && !mIsInControl) { mIsInControl = true; return resetDispatchTouchEvent(ev); } if (differentY <= 0 && mIsInControl) { mIsInControl = false; return resetDispatchTouchEvent(ev); } } break; } return super.dispatchTouchEvent(ev); }
From source file:com.cubic9.android.droidglove.Main.java
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mYPointWhenDown = event.getY(); break;// w w w . j av a 2 s .c o m case MotionEvent.ACTION_MOVE: mYDiff = event.getY() - mYPointWhenDown; if (mYDiff < 0) { mYDiff = 0; mYPointWhenDown = event.getY(); } else if (mYDiff > 100) { mYDiff = 100; mYPointWhenDown = event.getY() - 100; } break; case MotionEvent.ACTION_UP: mYDiff = 0; break; default: break; } return true; }
From source file:am.widget.tabstrip.TabStripHelper.java
boolean onTouchEvent(MotionEvent event) { if (mClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mClickPosition = PagerAdapter.POSITION_NONE; mDownX = x;/*from w ww .ja v a2s . c o m*/ mDownY = y; break; case MotionEvent.ACTION_UP: mClickPosition = PagerAdapter.POSITION_NONE; if (mPager != null && getPageCount() > 0) { if (mView instanceof TabStripView) mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y); else if (mView instanceof TabStripViewGroup) mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y); } break; case MotionEvent.ACTION_CANCEL: mClickPosition = PagerAdapter.POSITION_NONE; break; } } if (mDoubleClickable) { final float x = event.getX(); final float y = event.getY(); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mFirstDownX = mSecondDownX; mFirstDownY = mSecondDownY; mSecondDownX = x; mSecondDownY = y; break; case MotionEvent.ACTION_UP: final long downTime = event.getDownTime(); if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) { mDoubleClicked = true; if (mView instanceof TabStripView) mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); else if (mView instanceof TabStripViewGroup) mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY, mFirstUpX, mFirstUpY); if (mView instanceof TabStripView) mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); else if (mView instanceof TabStripViewGroup) mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY, x, y); mLastUpTime = 0; } else { mDoubleClicked = false; mFirstPosition = PagerAdapter.POSITION_NONE; mSecondPosition = PagerAdapter.POSITION_NONE; mFirstUpX = x; mFirstUpY = y; mLastUpTime = event.getEventTime(); } break; case MotionEvent.ACTION_CANCEL: break; } } return false; }
From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java
private boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] leftTop = { 0, 0 }; // ??location? v.getLocationInWindow(leftTop);// ww w .ja v a 2s . co m int left = leftTop[0]; int top = leftTop[1]; int bottom = top + v.getHeight(); int right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // ?EditText return false; } else { return true; } } return false; }
From source file:it.angrydroids.epub3reader.TextSelectionSupport.java
@Override public boolean onTouch(View v, MotionEvent event) { final Context ctx = mActivity; float xPoint = getDensityIndependentValue(event.getX(), ctx) / getDensityIndependentValue(mScale, ctx); float yPoint = getDensityIndependentValue(event.getY(), ctx) / getDensityIndependentValue(mScale, ctx); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: final String startTouchUrl = String.format("javascript:android.selection.startTouch(%f, %f);", xPoint, yPoint);/* ww w . j av a2s . co m*/ mLastTouchX = xPoint; mLastTouchY = yPoint; mWebView.loadUrl(startTouchUrl); break; case MotionEvent.ACTION_UP: if (!mScrolling) { endSelectionMode(); // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return false; } } mScrollDiffX = 0; mScrollDiffY = 0; mScrolling = false; // // Fixes 4.4 double selection // See: // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { return true; } break; case MotionEvent.ACTION_MOVE: mScrollDiffX += (xPoint - mLastTouchX); mScrollDiffY += (yPoint - mLastTouchY); mLastTouchX = xPoint; mLastTouchY = yPoint; if (Math.abs(mScrollDiffX) > SCROLLING_THRESHOLD || Math.abs(mScrollDiffY) > SCROLLING_THRESHOLD) { mScrolling = true; } break; } return false; }
From source file:cn.ieclipse.af.view.ScrollLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); }/*from w w w.j a v a 2s . c o m*/ mVelocityTracker.addMovement(event); final int action = event.getAction(); final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: if (debug) { Log.v(TAG, "event down!"); } if (!mScroller.isFinished()) { mScroller.abortAnimation(); } mLastMotionX = x; break; case MotionEvent.ACTION_MOVE: int deltaX = (int) (mLastMotionX - x); mLastMotionX = x; scrollBy(deltaX, 0); break; case MotionEvent.ACTION_UP: if (debug) { Log.v(TAG, "event : up"); } // if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000); int velocityX = (int) velocityTracker.getXVelocity(); if (debug) { Log.v(TAG, "velocityX:" + velocityX); } if (velocityX > mSnapVelocity) { if (mCurScreen > 0) { // Fling enough to move left if (debug) { Log.v(TAG, "snap left"); } snapToScreen(mCurScreen - 1); } else { // TODO disableWipe(false); snapToDestination(); } } else if (velocityX < -mSnapVelocity) { if (mCurScreen < getChildCount() - 1) { // Fling enough to move right if (debug) { Log.v(TAG, "snap right"); } snapToScreen(mCurScreen + 1); } else { // TODO disableWipe(false); snapToDestination(); } } else { snapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } // } mTouchState = TOUCH_STATE_REST; break; case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; break; } return true; }