Last active
August 16, 2020 06:16
-
-
Save MrCrambo/459727483fbc6c7fcb961597b3eb0d8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.navigine.navigine; | |
import android.view.MotionEvent; | |
public abstract class BaseGestureDetector | |
{ | |
protected boolean inProgress; | |
protected MotionEvent previousEvent; | |
protected MotionEvent currentEvent; | |
protected float currentPress; | |
protected float previousPress; | |
protected long delta; | |
protected abstract void gestureStarted(int actionCode, MotionEvent event); | |
protected abstract void gestureProgress(int actionCode, MotionEvent event); | |
public BaseGestureDetector() { } | |
public boolean onTouchEvent(MotionEvent event) | |
{ | |
if (!inProgress) | |
gestureStarted(actionCode, event.getActionMasked()); | |
else | |
gestureProgress(actionCode, event.getActionMasked()); | |
return true; | |
} | |
protected void updateStateByEvent(MotionEvent current) | |
{ | |
final MotionEvent previous = previousEvent; | |
if (currentEvent != null) | |
{ | |
currentEvent.recycle(); | |
currentEvent = null; | |
} | |
currentEvent = MotionEvent.obtain(current); | |
mTimeDelta = current.getEventTime() - previous.getEventTime(); | |
currentPress = current.getPressure(current.getActionIndex()); | |
previousPress = previous.getPressure(previous.getActionIndex()); | |
} | |
protected void resetState() | |
{ | |
if (previousEvent != null) | |
{ | |
previousEvent.recycle(); | |
previousEvent = null; | |
} | |
if (currentEvent != null) | |
{ | |
currentEvent.recycle(); | |
currentEvent = null; | |
} | |
inProgress = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment