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:android.support.v7.widget.FastScroller.java
@Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent me) { if (mState == STATE_HIDDEN) { return;/*from ww w . j a v a 2 s . c om*/ } if (me.getAction() == MotionEvent.ACTION_DOWN) { boolean insideVerticalThumb = isPointInsideVerticalThumb(me.getX(), me.getY()); boolean insideHorizontalThumb = isPointInsideHorizontalThumb(me.getX(), me.getY()); if (insideVerticalThumb || insideHorizontalThumb) { if (insideHorizontalThumb) { mDragState = DRAG_X; mHorizontalDragX = (int) me.getX(); } else if (insideVerticalThumb) { mDragState = DRAG_Y; mVerticalDragY = (int) me.getY(); } setState(STATE_DRAGGING); } } else if (me.getAction() == MotionEvent.ACTION_UP && mState == STATE_DRAGGING) { mVerticalDragY = 0; mHorizontalDragX = 0; setState(STATE_VISIBLE); mDragState = DRAG_NONE; } else if (me.getAction() == MotionEvent.ACTION_MOVE && mState == STATE_DRAGGING) { show(); if (mDragState == DRAG_X) { horizontalScrollTo(me.getX()); } if (mDragState == DRAG_Y) { verticalScrollTo(me.getY()); } } }
From source file:com.app.afteryou.ui.staggered.StaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/* w ww.j a v a 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; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! setTouchMode(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 y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { setTouchMode(TOUCH_MODE_DRAGGING); return true; } } } return false; }
From source file:com.canyinghao.canrefresh.CanRefreshLayout.java
/** * ?/* w w w . j ava2s . c om*/ * * @param e * @param isHead * @return */ private boolean touch(MotionEvent e, boolean isHead) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: lastY = e.getY(); return true; case MotionEvent.ACTION_MOVE: if (lastY > 0) { currentOffSetY = (int) (e.getY() - lastY); offsetSum += currentOffSetY; } lastY = e.getY(); boolean isCanMove; if (isHead) { isCanMove = offsetSum > 0; } else { isCanMove = offsetSum < 0; } if (isCanMove) { float ratio = getRatio(); if (ratio < 0) { ratio = 0; } int scrollNum = -((int) (currentOffSetY * ratio)); scrollSum += scrollNum; if (isHead) { smoothMove(true, true, scrollNum, scrollSum); if (Math.abs(scrollSum) > mHeaderHeight) { getHeaderInterface().onPrepare(); } getHeaderInterface().onPositionChange(Math.abs(scrollSum) / (float) mHeaderHeight); } else { smoothMove(false, true, scrollNum, scrollSum); if (Math.abs(scrollSum) > mFooterHeight) { getFooterInterface().onPrepare(); } getFooterInterface().onPositionChange(Math.abs(scrollSum) / (float) mFooterHeight); } } return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (Math.abs(scrollSum) > 3) { if (isHead) { if (Math.abs(scrollSum) > mHeaderHeight) { smoothMove(true, false, -mHeaderHeight, mHeaderHeight); getHeaderInterface().onRelease(); refreshing(); } else { smoothMove(true, false, 0, 0); } } else { if (Math.abs(scrollSum) > mFooterHeight) { smoothMove(false, false, mContentView.getMeasuredHeight() - getMeasuredHeight() + mFooterHeight, mFooterHeight); getFooterInterface().onRelease(); loadingMore(); } else { smoothMove(false, false, mContentView.getMeasuredHeight() - getMeasuredHeight(), 0); } } } resetParameter(); break; } return super.onTouchEvent(e); }
From source file:com.android.backups.BackupStaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);/*ww w. j av a 2 s. co m*/ 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; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; setTouchMode(mTouchMode); 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 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; setTouchMode(mTouchMode); return true; } } } return false; }
From source file:com.cloverstudio.spika.CameraCropActivity.java
@Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix);/*from w w w. j a v a 2s . c o m*/ start.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(mid, event); mode = ZOOM; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { // ... matrix.set(savedMatrix); matrix.postTranslate(event.getX() - start.x, event.getY() - start.y); start_x = event.getX() - start.x; start_y = event.getY() - start.y; } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; mAspect = scale; matrix.postScale(scale, scale, mid.x, mid.y); } } break; } view.setImageMatrix(matrix); view.invalidate(); return true; }
From source file:com.netease.qa.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. */// w ww. j a va 2s. c om private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(viFloatingWindow, wmParams); viFloatingWindow.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY() - statusBarHeight; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchStartX = event.getX(); mTouchStartY = event.getY(); break; case MotionEvent.ACTION_MOVE: updateViewPosition(); break; case MotionEvent.ACTION_UP: updateViewPosition(); mTouchStartX = mTouchStartY = 0; break; } return true; } }); btnWifi.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); String buttonText = (String) btnWifi.getText(); String wifiText = getResources().getString(R.string.open_wifi); if (buttonText.equals(wifiText)) { wifiManager.setWifiEnabled(true); btnWifi.setText(R.string.close_wifi); } else { wifiManager.setWifiEnabled(false); btnWifi.setText(R.string.open_wifi); } } catch (Exception e) { Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast), Toast.LENGTH_LONG).show(); Log.e(LOG_TAG, e.toString()); } } }); }
From source file:com.ssn.currency.convertor.WheelView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled() || getViewAdapter() == null) { return true; }/*from w ww . j av a 2 s. c o m*/ switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: if (!isScrollingPerformed) { int distance = (int) event.getY() - getHeight() / 2; if (distance > 0) { distance += getItemHeight() / 2; } else { distance -= getItemHeight() / 2; } int items = distance / getItemHeight(); if (items != 0 && isValidItemIndex(currentItem + items)) { notifyClickListenersAboutClick(currentItem + items); } } break; } return scroller.onTouchEvent(event); }
From source file:com.example.SmartBoard.DrawingView.java
@Override public boolean onTouchEvent(MotionEvent event) { //detect user touch float touchX = event.getX(); float touchY = event.getY(); //System.out.println("X"+touchX); // System.out.println("Y"+touchY); if (rectMode) { onTouchRectangleMode(event);/*from ww w. ja v a 2 s. com*/ return true; } else if (circleMode) { onTouchCircleMode(event); return true; } else if (lineMode) { onTouchLineMode(event); return true; } else if (textMode) { onTouchTextMode(event); return true; } else if (dragMode) { onTouchDragEvent(event); return true; } else if (removeObjectMode) { onRemoveObjectEvent(event); return true; } else if (colorDropperMode) { onTouchColorDropperMode(event); return true; } else if (textSizeMode) { onTouchTextResizeEvent(event); return true; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: drawPath.moveTo(touchX, touchY); break; case MotionEvent.ACTION_MOVE: drawPath.lineTo(touchX, touchY); break; case MotionEvent.ACTION_UP: drawCanvas.drawPath(drawPath, drawPaint); drawPath.reset(); break; default: return false; } //System.out.println(mqtt); invalidate(); mqtt.publish(touchX, touchY, event.getAction(), paintColor, mode, strokeWidth); return true; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from ww w.ja v a 2 s . c o m final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: LogUtil.d("--------------onInterceptTouchEvent ACTION_DOWN---------"); mFirstDownY = ev.getRawY(); mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode == TOUCH_MODE_FLINGING) { // Catch! mTouchMode = TOUCH_MODE_DRAGGING; reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); 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 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; reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); return true; } } } return false; }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); final float x = event.getX(); final float y = event.getY(); final int currentState = mCurrentState; final boolean isTapContent = mIsTapContent; mVelocityTracker.addMovement(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x;//from w w w . j a va 2 s. co m mIsTapContent = isTapContent(x, y); if (mIsTapContent) { mScroller.abortAnimation(); } mVelocityTracker = VelocityTracker.obtain(); break; case MotionEvent.ACTION_MOVE: if (Math.abs(x - mPressedX) >= mTouchSlop && isTapContent && currentState != STATE_DRAG) { setCurrentState(STATE_DRAG); } if (STATE_DRAG != currentState) { mLastMotionX = x; return false; } drag(mLastMotionX, x); mLastMotionX = x; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: if (STATE_DRAG == currentState) { mVelocityTracker.computeCurrentVelocity(1000); endDrag(x, mVelocityTracker.getXVelocity()); } else if (isTapContent) { performContentClick(); } mVelocityTracker.recycle(); mIsTapContent = false; break; } return true; }