List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.appsummary.luoxf.mylibrary.swipbackhelper.ViewDragHelper.java
/** * Check if this event as provided to the parent view's * onInterceptTouchEvent should cause the parent to intercept the touch * event stream./*from w ww . java 2 s . com*/ * * @param ev MotionEvent provided to onInterceptTouchEvent * @return true if the parent view should return true from * onInterceptTouchEvent */ public boolean shouldInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. tryCaptureViewForDrag(toCapture, pointerId); if (mDragState == STATE_SETTLING) { setDragState(STATE_DRAGGING); } else if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } setDragState(STATE_JUDGING); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); break; } case MotionEvent.ACTION_MOVE: { if (mDragState == STATE_JUDGING) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } if (mDragState == STATE_DRAGGING) mVelocityTracker.addMovement(ev); final int i = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[mActivePointerId]; final float dy = y - mInitialMotionY[mActivePointerId]; reportNewEdgeDrags(dx, dy, mActivePointerId); final View toCapture = findTopChildUnder((int) x, (int) y); int slop = checkTouchSlop(toCapture, dx, dy); if (slop == -1) cancel(); else if (slop > 0 && tryCaptureViewForDrag(toCapture, mActivePointerId)) { break; } saveLastMotion(ev); } break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: { releaseViewForPointerUp(); cancel(); break; } case MotionEvent.ACTION_CANCEL: { dispatchViewReleased(0, 0); cancel(); break; } } return mDragState == STATE_DRAGGING; }
From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java
@Override public boolean onTouchEvent(MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. In this case, you are only // interested in events where the touch position changed. switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else {//ww w. j a va2s . c o m mVelocityTracker.clear(); } queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasStarted(); } }); // No break is intentional case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); // Compute velocity in pixels per second mVelocityTracker.computeCurrentVelocity(1); final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1); Vector2 viewportPosition; Vector2 viewportVelocity = new Vector2( VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()), VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex())); // Add previous touch coordinates for (int i = 0; i < e.getHistorySize(); i++) { viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i)); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getHistoricalSize(i), e.getHistoricalPressure(i))); } // Add current touch coordinates viewportPosition = new Vector2(e.getX(), e.getY()); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getSize(), e.getPressure())); // Ensure we call switchMode() on the OpenGL thread. // queueEvent() is a method of GLSurfaceView that will do this for us. queueEvent(new Runnable() { @Override public void run() { mRenderer.addTouchData(touchDataList); } }); requestRender(); break; case MotionEvent.ACTION_UP: queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasEnded(); } }); requestRender(); break; } return true; }
From source file:com.abewy.android.apps.klyph.messenger.widget.SlidingPaneLayout.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()); }//w w w.j av a2 s. co m } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) { interceptTap = true; } 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 (adx > slop && ady > adx) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }
From source file:com.appsummary.luoxf.mylibrary.swipbackhelper.ViewDragHelper.java
/** * Process a touch event received by the parent view. This method will * dispatch callback events as needed before returning. The parent view's * onTouchEvent implementation should call this. * * @param ev The touch event received by the parent view *//*from w w w.ja v a 2 s. c om*/ public void processTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); final int actionIndex = MotionEventCompat.getActionIndex(ev); if (action == MotionEvent.ACTION_DOWN) { // Reset things for a new event stream, just in case we didn't get // the whole previous stream. cancel(); } switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); final int pointerId = MotionEventCompat.getPointerId(ev, 0); saveInitialMotion(x, y, pointerId); final View toCapture = findTopChildUnder((int) x, (int) y); // Catch a settling view if possible. tryCaptureViewForDrag(toCapture, pointerId); if (mDragState == STATE_SETTLING) { setDragState(STATE_DRAGGING); } else if (mDragState == STATE_IDLE) { final int edgesTouched = mInitialEdgeTouched[pointerId]; if ((edgesTouched & mTrackingEdges) != 0) { mCallback.onEdgeTouched(edgesTouched & mTrackingEdges, pointerId); } setDragState(STATE_JUDGING); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); final float x = MotionEventCompat.getX(ev, actionIndex); final float y = MotionEventCompat.getY(ev, actionIndex); saveInitialMotion(x, y, pointerId); break; } case MotionEvent.ACTION_MOVE: { if (mDragState == STATE_JUDGING) { final int i = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); final float dx = x - mInitialMotionX[mActivePointerId]; final float dy = y - mInitialMotionY[mActivePointerId]; reportNewEdgeDrags(dx, dy, mActivePointerId); if (mDragState == STATE_DRAGGING) { // Callback might have started an edge drag. break; } final View toCapture = findTopChildUnder((int) x, (int) y); int slop = checkTouchSlop(toCapture, dx, dy); if (slop == -1) cancel(); else if (slop > 0 && tryCaptureViewForDrag(toCapture, mActivePointerId)) { break; } saveLastMotion(ev); } if (mDragState == STATE_DRAGGING) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } if (mDragState == STATE_DRAGGING) mVelocityTracker.addMovement(ev); final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); //???????? if (index == -1) break; final float x = MotionEventCompat.getX(ev, index); final float y = MotionEventCompat.getY(ev, index); final int idx = (int) (x - mLastMotionX[mActivePointerId]); final int idy = (int) (y - mLastMotionY[mActivePointerId]); dragTo(mCapturedView.getLeft() + idx, mCapturedView.getTop() + idy, idx, idy); saveLastMotion(ev); } break; } case MotionEventCompat.ACTION_POINTER_UP: { final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex); clearMotionHistory(pointerId); break; } case MotionEvent.ACTION_UP: { releaseViewForPointerUp(); cancel(); break; } case MotionEvent.ACTION_CANCEL: { dispatchViewReleased(0, 0); cancel(); break; } } }
From source file:illab.nabal.NabalSimpleDemoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nabal_simple_demo); CookieSyncManager.createInstance(NabalSimpleDemoActivity.this); mBackground = (RelativeLayout) findViewById(R.id.relativeLayout1); mImgBtn1 = (ImageButton) findViewById(R.id.imageButton1); mImgBtn2 = (ImageButton) findViewById(R.id.imageButton2); mImgBtn3 = (ImageButton) findViewById(R.id.imageButton3); mImgBtn4 = (ImageButton) findViewById(R.id.imageButton4); mImgBtn5 = (ImageButton) findViewById(R.id.imageButton5); mImgBtn7 = (ImageButton) findViewById(R.id.imageButton7); mImgBtn8 = (ImageButton) findViewById(R.id.imageButton8); mEditText1 = (EditText) findViewById(R.id.editText1); mEditText2 = (EditText) findViewById(R.id.editText2); mEditText3 = (EditText) findViewById(R.id.editText3); mDialogHelper.toast("Please log in first."); mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); mInputMethodManager.hideSoftInputFromWindow(mEditText1.getWindowToken(), 0); mInputMethodManager.hideSoftInputFromWindow(mEditText2.getWindowToken(), 0); // set a listener to background for a fling mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override/*from www. j ava 2 s . c om*/ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { return false; } // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { if (mCurrentSnsId == SocialNetwork.FACEBOOK) { toggleSnsButtons(SocialNetwork.WEIBO); } else if (mCurrentSnsId == SocialNetwork.TWITTER) { toggleSnsButtons(SocialNetwork.FACEBOOK); } else if (mCurrentSnsId == SocialNetwork.WEIBO) { toggleSnsButtons(SocialNetwork.TWITTER); } } // left to right swipe else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { if (mCurrentSnsId == SocialNetwork.FACEBOOK) { toggleSnsButtons(SocialNetwork.TWITTER); } else if (mCurrentSnsId == SocialNetwork.TWITTER) { toggleSnsButtons(SocialNetwork.WEIBO); } else if (mCurrentSnsId == SocialNetwork.WEIBO) { toggleSnsButtons(SocialNetwork.FACEBOOK); } } } catch (Exception e) { // nothing } return false; } }); View.OnTouchListener gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return mGestureDetector.onTouchEvent(event); } }; mBackground.setOnTouchListener(gestureListener); // set a listener to background for a long-click mBackground.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { Log.i(TAG, "#### background area long-clicked"); if (mCurrentSnsId == SocialNetwork.FACEBOOK) { if (mFbBgBitmap != null) { new PhotoDialog(NabalSimpleDemoActivity.this, mFbBgBitmap).show(); } } else if (mCurrentSnsId == SocialNetwork.TWITTER) { if (mTwBgBitmap != null) { new PhotoDialog(NabalSimpleDemoActivity.this, mTwBgBitmap).show(); } } else if (mCurrentSnsId == SocialNetwork.WEIBO) { if (mWeBgBitmap != null) { new PhotoDialog(NabalSimpleDemoActivity.this, mWeBgBitmap).show(); } } return false; } }); // set a listener to Facebook button mImgBtn3.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### Facebook button clicked"); toggleSnsButtons(SocialNetwork.FACEBOOK); } }); // set a listener to Twitter button mImgBtn4.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### Twitter button clicked"); toggleSnsButtons(SocialNetwork.TWITTER); } }); // set a listener to Weibo button mImgBtn5.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### Weibo button clicked"); toggleSnsButtons(SocialNetwork.WEIBO); } }); // set a listener to portrait button mImgBtn1.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### portrait button clicked"); clearOutProfileUi(); clearProfileBufferData(mCurrentSnsId); mHasErrorOccurredWhileFetchingProfile = false; mImgBtn1.setVisibility(View.GONE); requestMyProfile(); requestMyLastStatus(); } }); mImgBtn1.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View paramView) { //Log.i(TAG, "#### portrait button long-clicked"); confirmJumpToSnsProfile(); return true; } }); // set a listener to photo attach button mImgBtn7.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### photo attach button clicked"); // if not logged-in yet if (mOpAgent.isSessionValid(mCurrentSnsId) == false) { mEditText1.setText(""); mDialogHelper.toast("Please log in first."); } // if logged-in already else { final String message = mEditText1.getText().toString(); if (StringHelper.isEmpty(message) == true) { mDialogHelper.toast("Please enter the photo description correctly."); } else { Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, REQ_CODE_FETCH_BITMAP_FROM_GALLERY); } } } }); // set a listener to status update button mImgBtn2.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### status update button clicked"); // if not logged-in yet if (mOpAgent.isSessionValid(mCurrentSnsId) == false) { mEditText1.setText(""); mDialogHelper.toast("Please log in first."); } // if logged-in already else { final String message = mEditText1.getText().toString(); if (StringHelper.isEmpty(message) == true) { mDialogHelper.toast("Please enter your status correctly."); } else { postStatus(message); } } } }); // set a listener to link button mImgBtn8.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { //Log.i(TAG, "#### photo attach button clicked"); // if not logged-in yet if (mOpAgent.isSessionValid(mCurrentSnsId) == false) { } // if logged-in already else { confirmJumpToLinkDialog(); } } }); }
From source file:com.aidy.bottomdrawerlayout.BottomDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent()"); final int action = MotionEventCompat.getActionMasked(ev); final boolean interceptForDrag = 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;/* ww w .jav a 2s.c om*/ mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE"); if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2"); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.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.actionbarsherlock.custom.widget.VerticalDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = mTopDragger.shouldInterceptTouchEvent(ev) | mBottomDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;//from ww w .j a va 2 s .c o m mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mTopDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (mTopDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { mTopCallback.removeCallbacks(); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; }
From source file:com.aidy.launcher3.support.views.bottomdrawer.BottomDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent()"); final int action = MotionEventCompat.getActionMasked(ev); final boolean interceptForDrag = 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 ww w . j a v a 2 s. c om*/ mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mBottomDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE"); if (mBottomDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { Log.i(TAG, "onInterceptTouchEvent() -- ACTION_MOVE -- 2"); mBottomCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.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.slidingmenu.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 ww w. j a v a2 s .c o m 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.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;/*from ww w . ja v a 2 s .co m*/ mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { mLeftCallback.removeCallbacks(); mRightCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; }