I want to fill progressbar when I swipe my hand on the phone. I think I should use scroll method or onfling method. But how can I understand how much I swipe? I use this code :
@Override
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
try {
if(e1.getX()- e2.getX()> min_dist) {
Toast.makeText(getBaseContext(), "Left Swipe", Toast.LENGTH_SHORT).show();
}
else if (e2.getX()- e1.getX()> min_dist ) {
Toast.makeText(getBaseContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
}
if(e1.getY() -e2.getY() > min_dist ) {
Toast.makeText(getBaseContext(), "Swipe up", Toast.LENGTH_SHORT).show();
}
else if (e2.getY() - e1.getY()> min_dist ) {
Toast.makeText(getBaseContext(), "Swipe down", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
// nothing
}
return true;
}
But when I swipe my hand x to y it says sometimes e1.getX() - e2.getX() = 440
sometimes it says
e1.getX() - e2.getX() =200
I do not understand. and I want to worry can I fill progressbar at the same time swipe?