0

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?

enter image description here

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;
    }
Jurko Guba
  • 630
  • 7
  • 17
  • Negate the values that you get? – almightyGOSU Jun 04 '15 at 02:25
  • Then the movement would go forward a little? You don't understand what I am asking, the negative values cause the mouse to go back a bit after the each movement. By negating, it wouldn't solve the problem. I need the VelocityTracker to be more accurate, there should be no move after I get to point B – Jurko Guba Jun 04 '15 at 02:56
  • Can you simply ignore negative values? Would that affect the accuracy? – almightyGOSU Jun 04 '15 at 02:57
  • This will clear things up. Imagine me going from B to A. All my X velocities would be negative, but the glitch (if we can call it that) would be a positive value this time. I can't give up the possibility of negative values because they're needed in case I want to go up or left on the view – Jurko Guba Jun 04 '15 at 03:20
  • Look at my edit to the post (right at the top), this guy seemed to have reported it, but I'm having roughly the same problem as him. – Jurko Guba Jun 04 '15 at 03:22

0 Answers0