List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.android.nobug.view.pattern.PatternView.java
private void handleActionDown(MotionEvent event) { resetPattern();//www .j av a2s .c o m final float x = event.getX(); final float y = event.getY(); final Cell hitCell = detectAndAddHit(x, y); if (hitCell != null) { setPatternInProgress(true); mPatternDisplayMode = DisplayMode.Correct; notifyPatternStarted(); } else if (mPatternInProgress) { setPatternInProgress(false); notifyPatternCleared(); } if (hitCell != null) { final float startX = getCenterXForColumn(hitCell.column); final float startY = getCenterYForRow(hitCell.row); final float widthOffset = mSquareWidth / 2f; final float heightOffset = mSquareHeight / 2f; invalidate((int) (startX - widthOffset), (int) (startY - heightOffset), (int) (startX + widthOffset), (int) (startY + heightOffset)); } mInProgressX = x; mInProgressY = y; if (PROFILE_DRAWING) { if (!mDrawingProfilingStarted) { Debug.startMethodTracing("LockPatternDrawing"); mDrawingProfilingStarted = true; } } }
From source file:com.callba.phone.widget.refreshlayout.RefreshLayout.java
private boolean footerInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsFooterBeingDragged = false;//from w ww. j a v a 2s . c om mFooterCurrPercentage = 0; break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); return false; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = y - mInitialMotionY; if (yDiff < -mTouchSlop) { mLastMotionY = y; mIsFooterBeingDragged = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsFooterBeingDragged = false; mFooterCurrPercentage = 0; mActivePointerId = INVALID_POINTER; break; } return mIsFooterBeingDragged; }
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
/** * Manage cursor for measurement//from w ww.jav a2 s .c o m */ private void measureEvent(MotionEvent event) { switch (event.getPointerCount()) { case 1: graphView.setCursor(event.getX(), event.getY()); // TODO: if touch point is very close to boundary for a long time, move the view break; case 2: if (isInGraphView(event.getX(1), event.getY(1))) { switchMeasureAndScaleMode(); } } }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide || !mIsSlidingEnabled) { return super.onTouchEvent(ev); }//from w w w . j a v a 2 s . com mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { 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(); View dragView = mDragView != null ? mDragView : mSlideableView; if (dx * dx + dy * dy < slop * slop && isDragViewUnder((int) x, (int) y)) { dragView.playSoundEffect(SoundEffectConstants.CLICK); if (!isExpanded() && !isAnchored()) { expandPane(mAnchorPoint); } else { collapsePane(); } break; } break; } } return wantTouchEvents; }
From source file:com.cssweb.android.view.TrendView.java
public void touchesEnded(MotionEvent event) { int x = (int) event.getX(); int y = (int) event.getY(); //if (x < LSpace || x > (width - LSpace)) if (x < LSpace || x > width) return;//from ww w . ja va 2 s. c om if (y < this.topTitleHeight || y > height - this.axisLabelHeight) return; isTouched = false; if (isTouchMoved == false) { isTouchMoved = false; isTrackStatus = !isTrackStatus; if (isTrackStatus) {//?? //if (x > LSpace && x < (width - LSpace)) if (x > LSpace && x < width) trackLineV = x; if (y > axisLabelHeight && y < (height - axisLabelHeight)) trackLineH = y; int idx = (int) ((x - LSpace) / SPACE); if (idx < actualDataLen && idx >= 0) { isTrackNumber = idx; trackLineV = (int) (LSpace + idx * SPACE); } else { if (idx < 0) { isTrackNumber = 0; trackLineV = LSpace; } if (idx >= actualDataLen) { isTrackNumber = actualDataLen - 1; trackLineV = (int) (LSpace + (actualDataLen - 1) * SPACE); } } } } this.invalidate(); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}//from w ww.jav a 2s. c om */ @Override public boolean onTouchEvent(final MotionEvent event) { final int action = event.getActionMasked(); final int index = event.getActionIndex(); final int pointerId = event.getPointerId(index); switch (action) { case MotionEvent.ACTION_DOWN: // Initialize velocity tracker if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } mVelocityTracker.addMovement(event); mScroller.forceFinished(true); mState = STATE_INITIALIZE; mInitialTouchOffset = mCurrentOffset; mInitialTouchX = event.getX(); mInitialTouchY = event.getY(); return true; case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(event); float diffX = event.getX() - mInitialTouchX; float diffY = event.getY() - mInitialTouchY; if (Math.abs(diffX) > mTouchSlop || mState >= STATE_MOVING) { mCurrentOffset = mInitialTouchOffset + diffX; if (mCurrentOffset < 0) { onOverScroll(); mCurrentOffset = 0; } else if (mCurrentOffset > mMaxOffset) { onOverScroll(); mCurrentOffset = mMaxOffset; } mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); mState = STATE_MOVING; ViewCompat.postInvalidateOnAnimation(this); } else if (Math.abs(diffY) > mTouchSlop && mState < STATE_MOVING) { return false; } return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mState >= STATE_MOVING) { final int velocity = (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId); mScroller.forceFinished(true); mState = STATE_FLINGING; mScroller.fling((int) mCurrentOffset, 0, velocity, 0, 0, (int) mMaxOffset, 0, 0); ViewCompat.postInvalidateOnAnimation(this); } else { // Reset scrolling state mState = STATE_IDLE; } return true; } return false; }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; mGestureDetector.onTouchEvent(event); boolean scaleInProgress = scaleInProgress(); mScaleGestureDetector.onTouchEvent(event); if (mInteractionMode == InteractionMode.SCALE) { return true; }//w ww .j ava2 s . c om if (!scaleInProgress() && scaleInProgress) { // If we were scaling, the scale will stop but we will // still issue an ACTION_UP. Let the subclasses know. mFinishedScalingOperation = true; } int ex = (int) event.getX(); int ey = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; mTouchShowOriginalDate = System.currentTimeMillis(); mShowOriginalDirection = 0; MasterImage.getImage().setOriginalTranslation(MasterImage.getImage().getTranslation()); } if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) { mTouch.x = ex; mTouch.y = ey; float scaleFactor = MasterImage.getImage().getScaleFactor(); if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = MasterImage.getImage().getOriginalTranslation(); Point translation = MasterImage.getImage().getTranslation(); translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); mTouchShowOriginal = false; } else if (enableComparison() && !mOriginalDisabled && (System.currentTimeMillis() - mTouchShowOriginalDate > mTouchShowOriginalDelayMin) && event.getPointerCount() == 1) { mTouchShowOriginal = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; mTouchShowOriginal = false; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; mTouch.y = 0; if (MasterImage.getImage().getScaleFactor() <= 1) { MasterImage.getImage().setScaleFactor(1); MasterImage.getImage().resetTranslation(); } } float scaleFactor = MasterImage.getImage().getScaleFactor(); Point translation = MasterImage.getImage().getTranslation(); constrainTranslation(translation, scaleFactor); MasterImage.getImage().setTranslation(translation); invalidate(); return true; }
From source file:android.support.design.widget.BottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }/*w ww . jav a 2s. co m*/ int action = MotionEventCompat.getActionMasked(event); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } mViewDragHelper.processTouchEvent(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
From source file:com.cssweb.android.view.TrendView.java
public void touchesMoved(MotionEvent event) { currentPositionX = event.getX();// ww w. j a va 2 s . c o m currentPositionY = event.getY(); float deltaX = startPositionX - currentPositionX; float deltaY = startPositionY - currentPositionY; if (Math.abs(deltaX) < 8 && Math.abs(deltaY) < 8) { isTouchMoved = false; } else { isTouchMoved = true; } if (isTrackStatus) {//?? int x = (int) event.getX(); int y = (int) event.getY(); float sep = SPACE; int idx = (int) ((x - LSpace) / sep); if (idx < actualDataLen && idx >= 0) { //if (x >= LSpace && x <= (width - LSpace)) if (x >= LSpace || x <= width) { trackLineV = (int) (LSpace + idx * SPACE); } if (y > axisLabelHeight && y < (height - axisLabelHeight)) trackLineH = y; isTrackNumber = idx; } else { if (idx < 0) { idx = 0; isTrackNumber = idx; trackLineV = LSpace; } if (idx >= actualDataLen) { isTrackNumber = actualDataLen - 1; trackLineV = (int) (LSpace + (actualDataLen - 1) * SPACE); } } } this.invalidate(); }
From source file:com.canyinghao.canrefresh.CanRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent e) { // ??view if (!canChildScrollDown() && !canChildScrollUp()) { if (isUpOrDown == NO_SCROLL_UP) { if (canRefresh()) { return touch(e, true); }/*w ww .ja v a 2 s.c om*/ } else if (isUpOrDown == NO_SCROLL_DOWN) { if (canLoadMore()) { return touch(e, false); } } else { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: directionY = e.getY(); directionX = e.getX(); break; case MotionEvent.ACTION_MOVE: if (directionY <= 0 || directionX <= 0) { break; } float eventY = e.getY(); float eventX = e.getX(); float offY = eventY - directionY; float offX = eventX - directionX; directionY = eventY; directionX = eventX; boolean moved = Math.abs(offY) > Math.abs(offX); if (offY > 0 && moved && canRefresh()) { isUpOrDown = NO_SCROLL_UP; } else if (offY < 0 && moved && canLoadMore()) { isUpOrDown = NO_SCROLL_DOWN; } else { isUpOrDown = NO_SCROLL; } break; } return true; } } else { if (canRefresh()) { return touch(e, true); } else if (canLoadMore()) { return touch(e, false); } } return super.onTouchEvent(e); }