The first first-order approximation would be to sum the local length of each detected tiny element of motion:
On ACTION_DOWN
total = 0; xPrec = ev.getX(); yPrec = ev.getY();
In ACTION_MOVE
final float dx = ev.getX() - xPrec; final float dy = ev.getY() - yPrec; final float dl = sqrt(dx * dx + dy * dy); total += dl; xPrec = ev.getX(); yPrec = ev.getY();
In ACTION_UP you can do whatever you want with total , which contains the total approximate length of your path.
If you read the official MotionEvent documentation MotionEvent http://developer.android.com/reference/android/view/MotionEvent.html , you will see a section called Batching that explains that a given motion event can combine multiple motion patterns. For the best first-order approximation, you need to use all of these patterns using getHistorySize , getHistoricalX , getHistoricalY . Remember to process the last sample, which is in getX and getY .
If you need a better approximation, I suggest you read about the problem of fitting the curve http://en.wikipedia.org/wiki/Curve_fitting , but as the frequency of sensory events is fast enough that you may not need to do this, and be satisfied with the approximation of the first order.
ovmjm source share