public boolean onTouchEvent(MotionEvent event) {
//mGestureDetector.onTouchEvent(event);
int action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
initialX = event.getX();
initialY = event.getY();
Log.d(TAG, "Action was DOWN");
break;
case MotionEvent.ACTION_MOVE:
Log.d(TAG, "Action was MOVE");
break;
case MotionEvent.ACTION_UP:
float finalX = event.getX();
float finalY = event.getY();
Log.d(TAG, "Action was UP");
if (initialX < finalX) {
Log.d(TAG, "Left to Right swipe performed");
}
if (initialX > finalX) {
Log.d(TAG, "Right to Left swipe performed");
}
if (initialY < finalY) {
Log.d(TAG, "Up to Down swipe performed");
}
if (initialY > finalY) {
Log.d(TAG, "Down to Up swipe performed");
}
break;
case MotionEvent.ACTION_CANCEL:
Log.d(TAG,"Action was CANCEL");
break;
case MotionEvent.ACTION_OUTSIDE:
Log.d(TAG, "Movement occurred outside bounds of current screen element");
break;
}
return super.onTouchEvent(event);
}
here is my code
private int getDirection(float startx, float starty,float endx ,float endy )
{
int direction=-1;
startx = (((int) startx / _size) *_size) ;
starty = (((int) starty / _size) * _size) ;
endx = (((int) endx / _size) * _size) ;
endy = (((int) endy / _size) * _size) ;
// Log.i("direction","startx:"+startx+"endx:"+endx+"starty: "+starty+"endy: "+endy+" ");
if (starty==endy)
{
direction= 0;
return direction;
}
if(startx==endx)
{
direction =1;
return direction;
}
if(Math.abs(startx-endx)==Math.abs(starty-endy))
{
direction =2;
return direction;
}
else
{
direction =-1;
return direction;
}
}
so i can find i'm in horizantal or vertical or non of these 2 cordinates but i need a way to compare the previous and current orientation while in action.move some thing like onDirectionChanggeListener
i can use action_up but i need it during move action.