List of usage examples for android.view MotionEvent getPointerCount
public final int getPointerCount()
From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java
private void onTouchMove(MotionEvent event) { mLastEventTime = event.getEventTime(); for (int i = 0; i < event.getPointerCount(); i++) { PointerInfo pointerInfo = pointerInfoForEventIndex(event, i); if (pointerInfo != null) { pointerInfo.populate(event, i); }//from w w w .ja va2s. c o m } if (getPointersDown() == 2) { sendScaleGesture(EventType.CONTINUE); } }
From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java
@Override public boolean onTouch(View view, MotionEvent event) { if (event.getPointerCount() > 1) { return super.onTouchEvent(event); }/*w ww. j a v a2 s. co m*/ RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams(); int action = MotionEventCompat.getActionMasked(event); if (view.getId() == R.id.frame_bottom || view.getId() == R.id.frame_top) { switch (action) { case MotionEvent.ACTION_DOWN: initialPoint = event.getRawY(); moving = true; break; case MotionEvent.ACTION_MOVE: if (moving) { hinter.interrupt(); currentPoint = event.getRawY(); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int screenHeight = displayMetrics.heightPixels; if (view.getId() == R.id.frame_top) { int new_margin = (int) (currentPoint - initialPoint); params.topMargin = (new_margin > 0) ? new_margin : 0; if ((new_margin > (screenHeight / 3)) && (!isFinishing())) { snoozeAlarm(); break; } } else { int new_margin = (int) (initialPoint - currentPoint); params.bottomMargin = (new_margin > 0) ? new_margin : 0; if ((new_margin > (screenHeight / 3)) && (!isFinishing())) { cancelAlarm(); break; } } view.setLayoutParams(params); view.invalidate(); } break; case MotionEvent.ACTION_UP: initialPoint = 0; TranslateAnimation ta; if (view.getId() == R.id.frame_top) { ta = new TranslateAnimation(0, 0, params.topMargin, 0); params.topMargin = 0; } else { ta = new TranslateAnimation(0, 0, -params.bottomMargin, 0); params.bottomMargin = 0; } ta.setDuration(100); view.setLayoutParams(params); view.startAnimation(ta); moving = false; startHinter(); break; default: return super.onTouchEvent(event); } } return true; }
From source file:com.stfalcon.frescoimageviewer.ImageViewerView.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { onUpDownEvent(event);/*from w ww . j a v a2 s .c om*/ if (direction == null) { if (scaleDetector.isInProgress() || event.getPointerCount() > 1) { wasScaled = true; return pager.dispatchTouchEvent(event); } } if (!adapter.isScaled(pager.getCurrentItem())) { directionDetector.onTouchEvent(event); if (direction != null) { switch (direction) { case UP: case DOWN: if (isSwipeToDismissAllowed && !wasScaled && pager.isScrolled()) { return swipeDismissListener.onTouch(dismissContainer, event); } else break; case LEFT: case RIGHT: return pager.dispatchTouchEvent(event); } } return true; } return super.dispatchTouchEvent(event); }
From source file:gov.sfmta.sfpark.AnnotationsOverlay.java
@Override public boolean onTouchEvent(MotionEvent e, MapView mapView) { int fingers = e.getPointerCount(); int action = e.getAction(); Log.v(TAG, "onTouchEvent " + action); if (action == MotionEvent.ACTION_DOWN) { isPinch = false;/*from w w w. j a v a 2s. com*/ } if (action == MotionEvent.ACTION_MOVE && fingers == 2) { isPinch = true; } if (popupView != null) { MainScreenActivity.mapView.removeView(popupView); popupView = null; } return super.onTouchEvent(e, mapView); }
From source file:ch.fhnw.comgr.GLES3Activity.java
public boolean handleTouchUp(final MotionEvent event) { int touchCount = event.getPointerCount(); //Log.i(TAG, "Up:" + touchCount + " x: " + (int)event.getX(0) + " y: " + (int)event.getY(0)); final int x0 = (int) event.getX(0); final int y0 = (int) event.getY(0); if (touchCount == 1) { myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onMouseUp(1, x0, y0); }// w w w . j a v a 2s . c o m }); } else if (touchCount == 2) { final int x1 = (int) event.getX(1); final int y1 = (int) event.getY(1); myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onTouch2Up(x0, y0, x1, y1); } }); } pointersDown = touchCount; myView.requestRender(); return true; }
From source file:com.android.mms.rcs.FavoriteDetailActivity.java
public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getPointerCount() > 1) { mScaleDetector.onTouchEvent(ev); }/* w ww . ja v a2s . com*/ return super.dispatchTouchEvent(ev); }
From source file:ch.fhnw.comgr.GLES3Activity.java
/** * Events://from w ww . ja v a 2s . c om * <p> * Finger Down * ----------- * Just tap on screen -> onMouseDown, onMouseUp * Tap and hold -> onMouseDown * release -> onMouseUp * 2 Fingers same time -> onTouch2Down * 2 Fingers not same time -> onMouseDown, onMouseUp, onTouch2Down * <p> * Finger Up * --------- * 2 Down, release one -> onTouch2Up * release other one -> onMouseUp * 2 Down, release one, put another one down -> onTouch2Up, onTouch2Down * 2 Down, release both same time -> onTouch2Up * 2 Down, release both not same time -> onTouch2Up */ public boolean handleTouchDown(final MotionEvent event) { int touchCount = event.getPointerCount(); final int x0 = (int) event.getX(0); final int y0 = (int) event.getY(0); //Log.i(TAG, "Dn:" + touchCount); // just got a new single touch if (touchCount == 1) { // get time to detect double taps long touchNowMS = System.currentTimeMillis(); long touchDeltaMS = touchNowMS - lastTouchMS; lastTouchMS = touchNowMS; if (touchDeltaMS < 250) myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onDoubleClick(1, x0, y0); } }); else myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onMouseDown(1, x0, y0); } }); } // it's two fingers but one delayed (already executed mouse down else if (touchCount == 2 && pointersDown == 1) { final int x1 = (int) event.getX(1); final int y1 = (int) event.getY(1); myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onMouseUp(1, x0, y0); } }); myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onTouch2Down(x0, y0, x1, y1); } }); // it's two fingers at the same time } else if (touchCount == 2) { // get time to detect double taps long touchNowMS = System.currentTimeMillis(); long touchDeltaMS = touchNowMS - lastTouchMS; lastTouchMS = touchNowMS; final int x1 = (int) event.getX(1); final int y1 = (int) event.getY(1); if (touchDeltaMS < 250) myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onMenuButton(); } }); else myView.queueEvent(new Runnable() { public void run() { GLES3Lib.onTouch2Down(x0, y0, x1, y1); } }); } pointersDown = touchCount; myView.requestRender(); return true; }
From source file:com.hippo.largeimageview.GestureRecognizer.java
public void onTouchEvent(MotionEvent event) { // If pointer count is more than 1, must be scale action switch (event.getActionMasked()) { case MotionEvent.ACTION_UP: mListener.onUp();/*from ww w. j a va 2 s .c om*/ break; case MotionEvent.ACTION_CANCEL: mListener.onCancel(); break; case MotionEvent.ACTION_POINTER_DOWN: mScale = event.getPointerCount() > 1; break; case MotionEvent.ACTION_POINTER_UP: mScale = (event.getPointerCount() - 1) > 1; break; } mGestureDetector.onTouchEvent(event); mScaleDetector.onTouchEvent(event); }
From source file:com.dastanapps.camera2.view.Cam2AutoFitTextureView.java
protected void pinchToZoom(MotionEvent event) { maximumZoomLevel = mCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM) * 10; Rect rect = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); float currentFingerSpacing; if (event.getPointerCount() > 1) { // Multi touch logic currentFingerSpacing = getFingerSpacing(event); if (fingerSpacing != 0) { if (currentFingerSpacing > fingerSpacing && maximumZoomLevel > zoomLevel) { zoomLevel = zoomLevel + .4; } else if (currentFingerSpacing < fingerSpacing && zoomLevel > 1) { zoomLevel = zoomLevel - .4; }//from w w w . ja v a 2s.com int minW = (int) (rect.width() / maximumZoomLevel); int minH = (int) (rect.height() / maximumZoomLevel); int difW = rect.width() - minW; int difH = rect.height() - minH; int cropW = difW / 100 * (int) zoomLevel; int cropH = difH / 100 * (int) zoomLevel; cropW -= cropW & 3; cropH -= cropH & 3; Rect zoom = new Rect(cropW, cropH, rect.width() - cropW, rect.height() - cropH); mPreviewBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoom); } fingerSpacing = currentFingerSpacing; } }
From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java
@Override public boolean onInterceptTouchEvent(final RecyclerView recyclerView, final MotionEvent event) { if (event.getPointerCount() > 1) { // Ignore subsequent pointers. return false; }//from w ww. j av a 2 s. c o m // We are not yet tracking a swipe gesture. Begin detection by spying on // touch events bubbling down to our children. final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: if (!hasGestureSwipeTarget()) { onGestureStart(); mVelocityTracker.addMovement(event); mInitialX = event.getX(); mInitialY = event.getY(); final View viewAtPoint = mRecyclerView.findChildViewUnder(mInitialX, mInitialY); final ConversationListItemView child = (ConversationListItemView) viewAtPoint; if (viewAtPoint instanceof ConversationListItemView && child != null && child.isSwipeAnimatable()) { // Begin detecting swipe on the target for the rest of the gesture. mListItemView = child; if (mListItemView.isAnimating()) { mListItemView = null; } } else { mListItemView = null; } } break; case MotionEvent.ACTION_MOVE: if (hasValidGestureSwipeTarget()) { mVelocityTracker.addMovement(event); final int historicalCount = event.getHistorySize(); // First consume the historical events, then consume the current ones. for (int i = 0; i < historicalCount + 1; i++) { float currX; float currY; if (i < historicalCount) { currX = event.getHistoricalX(i); currY = event.getHistoricalY(i); } else { currX = event.getX(); currY = event.getY(); } final float deltaX = currX - mInitialX; final float deltaY = currY - mInitialY; final float absDeltaX = Math.abs(deltaX); final float absDeltaY = Math.abs(deltaY); if (!mIsSwiping && absDeltaY > mTouchSlop && absDeltaY > (ERROR_FACTOR_MULTIPLIER * absDeltaX)) { // Stop detecting swipe for the remainder of this gesture. onGestureEnd(); return false; } if (absDeltaX > mTouchSlop) { // Swipe detected. Return true so we can handle the gesture in // onTouchEvent. mIsSwiping = true; // We don't want to suddenly jump the slop distance. mInitialX = event.getX(); mInitialY = event.getY(); onSwipeGestureStart(mListItemView); return true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (hasGestureSwipeTarget()) { onGestureEnd(); } break; } // Start intercepting touch events from children if we detect a swipe. return mIsSwiping; }