Android examples for User Interface:MotionEvent
is Multi Tap MotionEvent
import android.util.MathUtils; import android.view.MotionEvent; public class Main{ public static boolean isMultiTap(MotionEvent firstUp, MotionEvent secondUp, int multiTapTimeSlop, int multiTapDistanceSlop, int actionIndex) { return eventsWithinTimeAndDistanceSlop(firstUp, secondUp, multiTapTimeSlop, multiTapDistanceSlop, actionIndex); }//from w ww.ja va2s .c o m private static boolean eventsWithinTimeAndDistanceSlop( MotionEvent first, MotionEvent second, int timeout, int distance, int actionIndex) { if (isTimedOut(first, second, timeout)) { return false; } final double deltaMove = computeDistance(first, second, actionIndex); if (deltaMove >= distance) { return false; } return true; } public static boolean isTimedOut(MotionEvent firstUp, MotionEvent secondUp, int timeout) { final long deltaTime = secondUp.getEventTime() - firstUp.getEventTime(); return (deltaTime >= timeout); } public static double computeDistance(MotionEvent first, MotionEvent second, int pointerIndex) { return MathUtils.dist(first.getX(pointerIndex), first.getY(pointerIndex), second.getX(pointerIndex), second.getY(pointerIndex)); } }