UPDATE: This person seems to know what I'm talking about https://code.google.com/p/android/issues/detail?id=174970
Current Project: I'm working on a remote mouse and I am using a VelocityTracker
to get the X and Y movements needed. (I tried using MotionEvent
's directly but it just didn't work as nicely as the VelocityTracker
)
Problem: In a casual swipe from left to right (A to B in the picture below), you would make the assumption that my X Velocity should only be going positive at all times. HOWEVER, this is not the case, as I decelerate my thumb (approach point B) I start receiving negative values on the X Velocity and although they might not be big (almost close to zero) they affect the mouse movement in a way that makes it let less easy to control. How can I get this velocity tracker to provide smoother or more accurate results?
Logs for the movement above:
06-03 22:06:33.551 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_DOWN
06-03 22:06:33.671 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 20.689539 Y: 0.112973444
06-03 22:06:33.811 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 25.343899 Y: 0.9028549
06-03 22:06:33.922 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 16.566969 Y: 0.5636469
06-03 22:06:34.042 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: -1.6488186 Y: -0.39940003 // These shouldnt be here!
06-03 22:06:34.182 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: -2.4089027E-4 Y: -2.4089027E-4 // These shouldnt be here!
06-03 22:06:34.322 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 5.488204E-4 Y: 7.3197135E-4
06-03 22:06:34.452 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 0.0 Y: 0.0
06-03 22:06:34.572 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_MOVE X: 0.0 Y: -3.7341337
06-03 22:06:34.582 9413-9413/com.tutorials.jurko.androidmouse I/System.out﹕ ACTION_UP
onTouch() handling Code:
if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) {
mouseTouchPaint.setColor(Color.WHITE);
speedX = 0;
speedY = 0;
System.out.println("ACTION_UP");
Byte bytes[] = {speedX, speedY};
sendMessage(bytes);
mVelocityTracker.recycle();
mVelocityTracker = null;
view.invalidate();
return true;
}
else if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE || motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
System.out.println("ACTION_DOWN");
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
mouseTouchPaint.setColor(Color.parseColor("#CD5C5C"));
view.invalidate();
}
mVelocityTracker.addMovement(motionEvent);
if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
mVelocityTracker.computeCurrentVelocity(10);
float XVelocity = VelocityTrackerCompat.getXVelocity(mVelocityTracker, motionEvent.getPointerId(motionEvent.getActionIndex()));
float YVelocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, motionEvent.getPointerId(motionEvent.getActionIndex()));
System.out.println("ACTION_MOVE X: " + XVelocity + " Y: " + YVelocity);
sendMessage(XVelocity, YVelocity);
mVelocityTracker.clear();
return true;
}
return true;
}