List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mThumb.copyBounds(bounds);/*from www . j a va 2 s. c o m*/ //Grow the current thumb rect for a bigger touch area bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. setProgress(mMax-1); mIsDragging = true; mDragOffset = (bounds.width() / 2) - mAddedTouchBounds; updateDragging(ev); //As the thumb may have moved, get the bounds again mThumb.copyBounds(bounds); bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds); } if (mIsDragging) { setPressed(true); attemptClaimDrag(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds); } return mIsDragging; }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*from w ww. ja v a2s . c om*/ final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; return true; } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaY = (int) dx; mTouchRemainderX = dx - deltaY; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; return true; } } } return false; }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
@Override public boolean onTouchEvent(MotionEvent event) { final int x = (int) (event.getX() + 0.5f); final int y = (int) (event.getY() + 0.5f); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mDownX = x;/*from w w w . j ava 2s . c o m*/ mDownY = y; mInitialTarget = getDayAtLocation(mDownX, mDownY); if (mInitialTarget < 0) { return false; } if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); break; case MotionEvent.ACTION_MOVE: if (!isStillAClick(x, y)) { if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } mInitialTarget = -1; if (mTouchedItem >= 0) { mTouchedItem = -1; invalidate(); } } break; case MotionEvent.ACTION_UP: onDayClicked(mInitialTarget); // Fall through. case MotionEvent.ACTION_CANCEL: if (mPendingCheckForTap != null) { removeCallbacks(mPendingCheckForTap); } // Reset touched day on stream end. mTouchedItem = -1; mInitialTarget = -1; invalidate(); break; } return true; }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);// w ww . j ava2 s. c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 0; break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaX = (int) dx; mTouchRemainderX = dx - deltaX; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchX = x; if (!trackMotionScroll(deltaX, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } } break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId); if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, (int) velocity, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); mLastTouchX = 0; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } break; } return true; }
From source file:com.codeim.coxin.LoginActivity.java
private boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] l1 = { 0, 0 }; int[] l2 = { 0, 0 }; mUsernameEdit.getLocationInWindow(l1); mPasswordEdit.getLocationInWindow(l2); // int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth(); int left = l1[0], top = l1[1], bottom = l2[1] + mPasswordEdit.getHeight(), right = l2[0] + mPasswordEdit.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // EditText return false; } else {//from ww w . j a v a 2s. c o m return true; } } // ?EditText??EditView? return false; }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_HOVER_ENTER: // Fall-through to movement events. onEnter(event.getX(), event.getY()); case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_HOVER_MOVE: onMove(event.getX(), event.getY()); break;//from w ww . j a v a2 s. c o m case MotionEvent.ACTION_UP: case MotionEvent.ACTION_HOVER_EXIT: onUp(event.getX(), event.getY()); break; default: // Don't handle other types of events. return false; } mHandler.onTouch(this, event); return true; }
From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; }// w ww .j a va 2 s.c o m final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; mViewPager.fakeDragBy(deltaX); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.cssweb.android.view.KlineMini.java
public void touchesBegan(MotionEvent event) { isTouched = true;/*from www . j a v a2 s.co m*/ isTouchMoved = false; startPositionX = event.getX(); startPositionY = event.getY(); //Log.i("========startPositionX==========", startPositionX+">>>>>>>>>>"); //Log.i("========startPositionY==========", startPositionY+">>>>>>>>>>"); }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return super.onTouchEvent(ev); }/*ww w. j av a 2s. c om*/ mVelocityTracker.addMovement(ev); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mActivePointerId = ev.getPointerId(0); if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) { mIsDragging = handled = true; } handled |= mCollapsibleHeight > 0; mScroller.abortAnimation(); } break; case MotionEvent.ACTION_MOVE: { int index = ev.findPointerIndex(mActivePointerId); if (index < 0) { Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting"); index = 0; mActivePointerId = ev.getPointerId(0); mInitialTouchX = ev.getX(); mInitialTouchY = mLastTouchY = ev.getY(); } final float x = ev.getX(index); final float y = ev.getY(index); if (!mIsDragging) { final float dy = y - mInitialTouchY; if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) { handled = mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } if (mIsDragging) { final float dy = y - mLastTouchY; performDrag(dy); } mLastTouchY = y; } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = ev.getActionIndex(); final int pointerId = ev.getPointerId(pointerIndex); mActivePointerId = pointerId; mInitialTouchX = ev.getX(pointerIndex); mInitialTouchY = mLastTouchY = ev.getY(pointerIndex); } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_UP: { mIsDragging = false; if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null && findChildUnder(ev.getX(), ev.getY()) == null) { if (mClickOutsideListener != null) { mClickOutsideListener.onClick(this); resetTouch(); return true; } } if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) { smoothScrollTo(0, 0); return true; } mVelocityTracker.computeCurrentVelocity(1000); final float yvel = mVelocityTracker.getYVelocity(mActivePointerId); if (Math.abs(yvel) > mMinFlingVelocity) { smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel); } else { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); } break; case MotionEvent.ACTION_CANCEL: { if (mIsDragging) { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); return true; } } return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0); }
From source file:com.roger.lineselectionwebview.LSWebView.java
@SuppressWarnings("deprecation") @Override//from ww w.j av a 2s . com public boolean onTouch(View v, MotionEvent event) { if (!isLineMode) { return false; } @SuppressWarnings("deprecation") float xPoint = getDensityIndependentValue(event.getX(), mContext) / getDensityIndependentValue(getScale(), mContext); float yPoint = getDensityIndependentValue(event.getY(), mContext) / getDensityIndependentValue(getScale(), mContext); if (event.getAction() == MotionEvent.ACTION_DOWN) { String startTouchUrl = String.format(Locale.US, "javascript:android.selection.startTouch(%f, %f);", xPoint, yPoint); mLastTouchX = xPoint; mLastTouchY = yPoint; loadUrl(startTouchUrl); // Tell the javascript to handle this if not in selection mode if (!isInSelectionMode()) { loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } // Flag scrolling for first touch // mScrolling = !isInSelectionMode(); } else if (event.getAction() == MotionEvent.ACTION_UP) { // Check for scrolling flag if (!mScrolling) { mScrolling = false; endSelectionMode(); return false; } mScrolling = false; // Fixes 4.4 double selection return true; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { mLastTouchX = xPoint; mLastTouchY = yPoint; } // If this is in selection mode, then nothing else should handle this // touch return false; }