4

I implemented a SimpleOnGestureListener on this Android app and it's the basic implementation and it's all working as it should:

the class implements OnTouchListener and I set it as TouchListener for the correct View, on the touch event I call my instance of SimpleOnGestureListener

@Override
public boolean onTouch(View v, MotionEvent event) {
   return gestureDetector.onTouchEvent(event);
}

and in my fling callback I'm logging the velocityY (the app is using some swipe-down gesture)

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
   Log.d(TAG, "velocityY = " + velocityY);

  ... some code ...
}

the method is called and I see values on my Log.

The issue is that for the Nexus 4 and Nexus 10 for a downward fling the velocityY is a positive value and for the Nexus 7 it's a negative value.

I know someone will suggest to use e2.getY - e1.getY (or the raw) but they are not totally reliable, because silly users might (and will) drag the view down and then fling it up, but the difference will still be positive.

So the question is: is there a way to query the system what's the direction of this thing?

Budius
  • 39,391
  • 16
  • 102
  • 144
  • are you really sure? Velocity is taken directly from VelocityTracker so if VT returns different values it would hurt any app that uses VT (directly or indirectly) – pskink Sep 20 '13 at 11:33
  • well, as you can see it's a very simple and straight forward test and yes, every downward fling on the N7 gives me negative values. – Budius Sep 20 '13 at 11:49

1 Answers1

1

So I found out the cause of the problem and will post a new question soon to which could be a workaround it.

The problem is that I'm using the onScroll() to move the view up and down on the screen using View.offsetTopAndBottom and with that change in position the VelocityTracker is getting completely crazy

I'll study some more to see if I can tryck the VT or if I roll my own workaround, but yeah, that's why!

Budius
  • 39,391
  • 16
  • 102
  • 144