@Override protected void resetState() { super.resetState(); mSloppyGesture = false; }
@Override protected void handleStartProgressEvent(int actionCode, MotionEvent event){ switch (actionCode) { case MotionEvent.ACTION_DOWN: resetState(); // In case we missed an UP/CANCEL event mPrevEvent = MotionEvent.obtain(event); mTimeDelta = 0; updateStateByEvent(event); break; case MotionEvent.ACTION_MOVE: mGestureInProgress = mListener.onMoveBegin(this); break; } }
resetState(); // In case we missed an UP/CANCEL event mPrevEvent = MotionEvent.obtain(event); mTimeDelta = 0; updateStateByEvent(event); mSloppyGesture = isSloppyGesture(event); if(!mSloppyGesture){ mGestureInProgress = mListener.onShoveBegin(this); mSloppyGesture = isSloppyGesture(event); if(!mSloppyGesture){ mGestureInProgress = mListener.onShoveBegin(this);
case MotionEvent.ACTION_POINTER_UP: updateStateByEvent(event); mListener.onShoveEnd(this); resetState(); break; mListener.onShoveEnd(this); resetState(); break; updateStateByEvent(event); && Math.abs(getShovePixelsDelta()) > 0.5f) { final boolean updatePrevious = mListener.onShove(this); if (updatePrevious) { mPrevEvent.recycle();
resetState(); // In case we missed an UP/CANCEL event mPrevEvent = MotionEvent.obtain(event); mTimeDelta = 0; updateStateByEvent(event); mSloppyGesture = isSloppyGesture(event); if(!mSloppyGesture){ mGestureInProgress = mListener.onRotateBegin(this); mSloppyGesture = isSloppyGesture(event); if(!mSloppyGesture){ mGestureInProgress = mListener.onRotateBegin(this);
case MotionEvent.ACTION_POINTER_UP: updateStateByEvent(event); mListener.onRotateEnd(this); resetState(); break; mListener.onRotateEnd(this); resetState(); break; updateStateByEvent(event); final boolean updatePrevious = mListener.onRotate(this); if (updatePrevious) { mPrevEvent.recycle();
@Override protected void handleInProgressEvent(int actionCode, MotionEvent event){ switch (actionCode) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mListener.onMoveEnd(this); resetState(); break; case MotionEvent.ACTION_MOVE: // If the gesture started before this detector was attached (somehow), // mPrevEvent will be null at this point and BaseGestureDetector's // updateStateByEvent() will crash. The following check will prevent this. if (mPrevEvent == null) { return; } updateStateByEvent(event); // Only accept the event if our relative pressure is within // a certain limit. This can help filter shaky data as a // finger is lifted. if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) { final boolean updatePrevious = mListener.onMove(this); if (updatePrevious) { mPrevEvent.recycle(); mPrevEvent = MotionEvent.obtain(event); } } break; } }
protected void updateStateByEvent(MotionEvent curr) { super.updateStateByEvent(curr); final MotionEvent prev = mPrevEvent; // Focus intenal mCurrFocusInternal = determineFocalPoint(curr); mPrevFocusInternal = determineFocalPoint(prev); // Focus external // - Prevent skipping of focus delta when a finger is added or removed boolean mSkipNextMoveEvent = prev.getPointerCount() != curr.getPointerCount(); mFocusDeltaExternal = mSkipNextMoveEvent ? FOCUS_DELTA_ZERO : new PointF(mCurrFocusInternal.x - mPrevFocusInternal.x, mCurrFocusInternal.y - mPrevFocusInternal.y); // - Don't directly use mFocusInternal (or skipping will occur). Add // unskipped delta values to mFocusExternal instead. mFocusExternal.x += mFocusDeltaExternal.x; mFocusExternal.y += mFocusDeltaExternal.y; }
/** * All gesture detectors need to be called through this method to be able to * detect gestures. This method delegates work to handler methods * (handleStartProgressEvent, handleInProgressEvent) implemented in * extending classes. * * @param event * @return */ public boolean onTouchEvent(MotionEvent event){ final int actionCode = event.getAction() & MotionEvent.ACTION_MASK; if (!mGestureInProgress) { handleStartProgressEvent(actionCode, event); } else { handleInProgressEvent(actionCode, event); } return true; }
public MyTouchInput(Context context, TouchInput onTouchListener) { this.orig = onTouchListener; this.panTapGestureDetector = new GestureDetector(context, this); this.panTapGestureDetector.setIsLongpressEnabled(false); this.longPressGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public void onLongPress(MotionEvent e) { MyTouchInput.this.onLongPress(e); } } ); this.scaleGestureDetector = new ScaleGestureDetector(context, this); this.rotateGestureDetector = new RotateGestureDetector(context, this); this.shoveGestureDetector = new ShoveGestureDetector(context, this); }
@Override protected void updateStateByEvent(MotionEvent curr){ super.updateStateByEvent(curr); final MotionEvent prev = mPrevEvent; float py0 = prev.getY(0); float py1 = prev.getY(1); mPrevAverageY = (py0 + py1) / 2.0f; float cy0 = curr.getY(0); float cy1 = curr.getY(1); mCurrAverageY = (cy0 + cy1) / 2.0f; }
@Override protected boolean isSloppyGesture(MotionEvent event){ boolean sloppy = super.isSloppyGesture(event); if (sloppy) return true; // If it's not traditionally sloppy, we check if the angle between fingers // is acceptable. double angle = Math.abs(Math.atan2(mCurrFingerDiffY, mCurrFingerDiffX)); //about 20 degrees, left or right return !(( 0.0f < angle && angle < 0.35f) || 2.79f < angle && angle < Math.PI); }
protected void updateStateByEvent(MotionEvent curr){ super.updateStateByEvent(curr); final MotionEvent prev = mPrevEvent; mCurrLen = -1; mPrevLen = -1; // Previous final float px0 = prev.getX(0); final float py0 = prev.getY(0); final float px1 = prev.getX(1); final float py1 = prev.getY(1); final float pvx = px1 - px0; final float pvy = py1 - py0; mPrevFingerDiffX = pvx; mPrevFingerDiffY = pvy; // Current final float cx0 = curr.getX(0); final float cy0 = curr.getY(0); final float cx1 = curr.getX(1); final float cy1 = curr.getY(1); final float cvx = cx1 - cx0; final float cvy = cy1 - cy0; mCurrFingerDiffX = cvx; mCurrFingerDiffY = cvy; }
@Override public boolean onRotate(RotateGestureDetector detector) { final float rotationDegreesDelta = detector.getRotationDegreesDelta(); Log.e(TAG,"rotationDegreesDelta : "+rotationDegreesDelta); // mScaleMatrix.postRotate(-rotationDegreesDelta,centerX,centerY); // invalidate(); return true; }
@Override protected void handleStartProgressEvent(int actionCode, MotionEvent event) { switch (actionCode) { case MotionEvent.ACTION_DOWN: resetState(); // In case we missed an UP/CANCEL event mPrevEvent = MotionEvent.obtain(event); mTimeDelta = 0; updateStateByEvent(event); break; case MotionEvent.ACTION_MOVE: mGestureInProgress = mListener.onMoveBegin(this); break; } }
@Override protected void resetState() { super.resetState(); mSloppyGesture = false; mPrevAverageY = 0.0f; mCurrAverageY = 0.0f; }
@Override protected void updateStateByEvent(MotionEvent curr) { super.updateStateByEvent(curr); final MotionEvent prev = mPrevEvent; float py0 = prev.getY(0); float py1 = prev.getY(1); mPrevAverageY = (py0 + py1) / 2.0f; float cy0 = curr.getY(0); float cy1 = curr.getY(1); mCurrAverageY = (cy0 + cy1) / 2.0f; }
@Override protected void resetState() { super.resetState(); mSloppyGesture = false; mPrevAverageY = 0.0f; mCurrAverageY = 0.0f; }
@Override protected void resetState() { super.resetState(); mSloppyGesture = false; }