List of usage examples for android.view MotionEvent ACTION_MOVE
int ACTION_MOVE
To view the source code for android.view MotionEvent ACTION_MOVE.
Click Source Link
From source file:cn.ieclipse.af.view.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from w w w . j a va 2 s .c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 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 y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, 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.getYVelocity(mVelocityTracker, mActivePointerId); if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } break; } return true; }
From source file:com.example.appf.CS3570.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. float x = e.getX(); float y = e.getY(); switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (mother.out != null) { mother.out.println("{\"type\": \"DOWN\", \"x\": " + x + ", \"y\": " + y + "}\0"); }/*from w w w .j a v a 2 s .c om*/ break; case MotionEvent.ACTION_UP: if (mother.out != null) { mother.out.println("{\"type\": \"UP\", \"x\": " + x + ", \"y\": " + y + "}\0"); } break; case MotionEvent.ACTION_MOVE: float dx = x - mPreviousX; float dy = y - mPreviousY; // reverse direction of rotation above the mid-line if (y > getHeight() / 2) { dx = dx * -1; } // reverse direction of rotation to left of the mid-line if (x < getWidth() / 2) { dy = dy * -1; } //mRenderer.mAngle += (dx + dy) * TOUCH_SCALE_FACTOR; // = 180.0f / 320 //mRenderer.mTetra.rotate(dx, 0, 1, 0); //mRenderer.mTetra.rotate(dy, 1, 0, 0); //mRenderer.mCamera.rotateY((double)(dx * TOUCH_SCALE_FACTOR)); //mRenderer.mCamera.rotateX((double)(dy * TOUCH_SCALE_FACTOR)); if (mother.out != null) { Log.e("eee", "{\"type\": \"MOVE\", \"x\": " + x + ", \"y\": " + y + "}"); mother.out.println("{\"type\": \"MOVE\", \"x\": " + x + ", \"y\": " + y + "}\0"); } requestRender(); } mPreviousX = x; mPreviousY = y; return true; }
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
/** * This is why you don't implement your own TextView kids; you have to handle everything! *//* ww w.j a va2 s .c o m*/ @Override public boolean onTouchEvent(MotionEvent event) { if (!(text instanceof Spanned)) return super.onTouchEvent(event); Spannable spannedText = (Spannable) text; boolean handled = false; if (event.getAction() == MotionEvent.ACTION_DOWN) { pressedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null) { pressedSpan.setPressed(true); Selection.setSelection(spannedText, spannedText.getSpanStart(pressedSpan), spannedText.getSpanEnd(pressedSpan)); handled = true; postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { TouchableUrlSpan touchedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null && touchedSpan != pressedSpan) { pressedSpan.setPressed(false); pressedSpan = null; Selection.removeSelection(spannedText); postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_UP) { if (pressedSpan != null) { pressedSpan.setPressed(false); pressedSpan.onClick(this); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } else { if (pressedSpan != null) { pressedSpan.setPressed(false); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } return handled; }
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from w w w .j a va 2 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:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (!isEnabled() || canChildScrollUp()) { return false; }/*from w w w. j a v a2 s. c o m*/ mIsBeingDropped = mWaveView.isDisappearCircleAnimatorRunning(); final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: // Here is not called from anywhere break; case MotionEvent.ACTION_MOVE: final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId); return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex); case MotionEvent.ACTION_UP: if (mIsBeingDropped) { mIsBeingDropped = false; return false; } final float diffY = event.getY() - mFirstTouchDownPointY; final float waveHeightThreshold = diffY * (5f - 2 * diffY / Math.min(getMeasuredWidth(), getMeasuredHeight())) / 1000f; mWaveView.startWaveAnimation(waveHeightThreshold); case MotionEvent.ACTION_CANCEL: if (mActivePointerId == INVALID_POINTER) { return false; } if (!isRefreshing()) { mCircleView.setProgressStartEndTrim(0f, 0f); mCircleView.showArrow(false); mCircleView.setVisibility(GONE); } mActivePointerId = INVALID_POINTER; return false; } return true; }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
public boolean sendTouchEvent(@NonNull MotionEvent event) { final int action = event.getActionMasked(); // If current circle is canceled then // ignore all actions except of touch down (to reset state.) if (mCanceled && action != MotionEvent.ACTION_DOWN) return false; // Cancel the current circle on two-or-more-fingers touch. if (event.getPointerCount() > 1) { cancelCircle();//from w w w . ja v a 2 s . co m return false; } final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: clearAnimation(); Config config = Config.getInstance(); // Corner actions int width = getWidth(); int height = getHeight(); int radius = Math.min(width, height) / 3; if (MathUtils.isInCircle(x, y, 0, 0, radius)) { // Top left mCornerActionId = config.getCornerActionLeftTop(); } else if (MathUtils.isInCircle(x, y, -width, 0, radius)) { // Top right mCornerActionId = config.getCornerActionRightTop(); } else if (MathUtils.isInCircle(x, y, 0, -height, radius)) { // Bottom left mCornerActionId = config.getCornerActionLeftBottom(); } else if (MathUtils.isInCircle(x, y, -width, -height, radius)) { // Bottom right mCornerActionId = config.getCornerActionRightBottom(); } else { // The default action is unlocking. mCornerActionId = Config.CORNER_UNLOCK; } // Update colors and icon drawable. boolean needsColorReset = updateIcon(); setInnerColor(getColor(config.getCircleInnerColor()), needsColorReset); setOuterColor(getColor(config.getCircleOuterColor())); // Initialize circle mRadiusTargetAimed = false; mRadiusMaxPeak = 0; mPoint[0] = x; mPoint[1] = y; mCanceled = false; if (mHandler.hasMessages(ACTION_UNLOCK)) { // Cancel unlocking process. mHandler.sendEmptyMessage(ACTION_UNLOCK_CANCEL); } mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessageDelayed(MSG_CANCEL, 1000); mHandler.sendEmptyMessage(ACTION_START); break; case MotionEvent.ACTION_MOVE: setRadius(x, y); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mRadiusTargetAimed || action == MotionEvent.ACTION_CANCEL) { cancelCircle(); break; } startUnlock(); break; } return true; }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int action = ev.getAction(); if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null && isStickyViewTouched(stickyWrapper.view, x, y)) { touchTarget = stickyWrapper.view; touchPt.x = x;/*from w w w. j a va 2s.c o m*/ touchPt.y = y; downEvent = MotionEvent.obtain(ev); } if (touchTarget != null) { if (isStickyViewTouched(touchTarget, x, y)) { // forward event to header view touchTarget.dispatchTouchEvent(ev); } if (action == MotionEvent.ACTION_UP) { super.dispatchTouchEvent(ev); clearTouchTarget(); } else if (action == MotionEvent.ACTION_CANCEL) { clearTouchTarget(); } else if (action == MotionEvent.ACTION_MOVE) { if (Math.abs(y - touchPt.y) > touchSlop) { MotionEvent event = MotionEvent.obtain(ev); event.setAction(MotionEvent.ACTION_CANCEL); touchTarget.dispatchTouchEvent(event); event.recycle(); super.dispatchTouchEvent(downEvent); super.dispatchTouchEvent(ev); clearTouchTarget(); } } return true; } return super.dispatchTouchEvent(ev); }
From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;/*w w w . j a v a 2 s . c om*/ mDownEvent = MotionEvent.obtain(event); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh mUserInteracting = true; startRefresh(); handled = true; break; } // Just track the user's movement setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); updatePositionTimeout(); handled = true; } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mUserInteracting = false; if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Pinch to zoom.// w ww . ja va2 s.com */ @Override public boolean onTouch(View v, MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. float newDist = 0; switch (e.getAction()) { case MotionEvent.ACTION_MOVE: // pinch to zoom if (e.getPointerCount() == 2) { if (distance == 0) { distance = fingerDist(e); } newDist = fingerDist(e); zoom *= distance / newDist; dynamicPlot.setMaxRange(zoom * Math.log(zoom)); dynamicPlot.setMinRange(-zoom * Math.log(zoom)); distance = newDist; } } return false; }
From source file:co.vn.e_alarm.customwiget.SlidingLayer.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }//from w ww .j ava 2s .co m final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { /* * Return event touch to children view. */ mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastY; final float yDiff = Math.abs(y - mLastY); if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) { // mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) { // mIsDragging = true; mLastY = y; setDrawingCacheEnabled(true); } float matY = (float) Math.abs(corY - ev.getRawY()); float matX = (float) Math.abs(corX - ev.getRawX()); if (matY - 100 > 0) { mIsDragging = true; setDrawingCacheEnabled(true); // Dang di chuyen len } else if (matX - 100 > 0) { mIsDragging = false; } if (matY == 0) { setDrawingCacheEnabled(false); } /* }else{ mIsDragging = false; setDrawingCacheEnabled(true); }*/ /* }else if(corX +150 > ev.getRawX()){ mIsDragging = false; setDrawingCacheEnabled(true); }else if(corX +150 < ev.getRawX()){ mIsDragging = false; setDrawingCacheEnabled(true); }*/ // double corY = ev.getY(); break; case MotionEvent.ACTION_DOWN: corX = ev.getRawX(); corY = ev.getRawY(); mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEventCompat.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHereX(ev, mInitialX)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else if (allowSlidingFromHereY(ev, mInitialY)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }