Program: 86952
Project: 86952
Buggy source:
@Override public boolean onTouch(View v,MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    downRawX=last1MoveX=event.getRawX();
  downRawY=last1MoveY=event.getRawY();
downTime=new Date().getTime();
directionKnown=false;
break;
case MotionEvent.ACTION_MOVE:
last2MoveX=last1MoveX;
last2MoveY=last1MoveY;
last1MoveX=event.getRawX();
last1MoveY=event.getRawY();
last2MoveTime=last1MoveTime;
last1MoveTime=new Date().getTime();
if (!directionKnown) {
if (downRawY - event.getRawY() > MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_UP;
}
 else if (downRawY - event.getRawY() < -MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_DOWN;
}
 else if (downRawX - event.getRawX() > MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_LEFT;
}
 else if (downRawX - event.getRawX() < -MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_RIGHT;
}
}
if (directionKnown) {
onMove(event,direction,downRawX,downRawY);
}
break;
case MotionEvent.ACTION_UP:
upRawX=event.getRawX();
upRawY=event.getRawY();
upTime=new Date().getTime();
if (last1MoveX != upRawX || last1MoveY != upRawY) {
distX=convertPxToDip((int)(upRawX - last1MoveX));
distY=convertPxToDip((int)(upRawY - last1MoveY));
velocityX=distX / ((upTime - last1MoveTime) / 1000.0f);
velocityY=distY / ((upTime - last1MoveTime) / 1000.0f);
}
 else {
distX=convertPxToDip((int)(upRawX - last2MoveX));
distY=convertPxToDip((int)(upRawY - last2MoveY));
velocityX=distX / ((upTime - last2MoveTime) / 1000.0f);
velocityY=distY / ((upTime - last2MoveTime) / 1000.0f);
}
if (velocityX == 0 && velocityY == 0) {
distX=convertPxToDip((int)(upRawX - downRawX));
distY=convertPxToDip((int)(upRawY - downRawY));
velocityX=distX / ((upTime - downTime) / 1000.0f);
velocityY=distY / ((upTime - downTime) / 1000.0f);
}
if (directionKnown) {
if (direction == DIRECTION_UP && velocityY < -MIN_THRESHOLD_VELOCITY) {
onBottomToTop(-velocityY / 500.0f);
}
 else if (direction == DIRECTION_DOWN && velocityY > MIN_THRESHOLD_VELOCITY) {
onTopToBottom(velocityY / 500.0f);
}
 else if (direction == DIRECTION_LEFT && velocityX < -MIN_THRESHOLD_VELOCITY) {
onRightToLeft(-velocityX / 500.0f);
}
 else if (direction == DIRECTION_RIGHT && velocityX > MIN_THRESHOLD_VELOCITY) {
onLeftToRight(velocityX / 500.0f);
}
 else {
onSwipeFail();
}
}
 else {
v.callOnClick();
}
break;
}
return true;
}

Fixed version (ground truth):
@Override public boolean onTouch(View v,MotionEvent event){
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
    downRawX=last1MoveX=event.getRawX();
  downRawY=last1MoveY=event.getRawY();
downTime=new Date().getTime();
directionKnown=false;
break;
case MotionEvent.ACTION_MOVE:
last2MoveX=last1MoveX;
last2MoveY=last1MoveY;
last1MoveX=event.getRawX();
last1MoveY=event.getRawY();
last2MoveTime=last1MoveTime;
last1MoveTime=new Date().getTime();
if (!directionKnown) {
if (downRawY - event.getRawY() > MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_UP;
}
 else if (downRawY - event.getRawY() < -MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_DOWN;
}
 else if (downRawX - event.getRawX() > MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_LEFT;
}
 else if (downRawX - event.getRawX() < -MIN_SWIPE_DIST) {
directionKnown=true;
direction=DIRECTION_RIGHT;
}
}
if (directionKnown) {
onMove(event,direction,downRawX,downRawY);
}
break;
case MotionEvent.ACTION_UP:
upRawX=event.getRawX();
upRawY=event.getRawY();
upTime=new Date().getTime();
if (last1MoveX != upRawX || last1MoveY != upRawY) {
distX=convertPxToDip((int)(upRawX - last1MoveX));
distY=convertPxToDip((int)(upRawY - last1MoveY));
velocityX=distX / ((upTime - last1MoveTime) / 1000.0f);
velocityY=distY / ((upTime - last1MoveTime) / 1000.0f);
}
 else {
distX=convertPxToDip((int)(upRawX - last2MoveX));
distY=convertPxToDip((int)(upRawY - last2MoveY));
velocityX=distX / ((upTime - last2MoveTime) / 1000.0f);
velocityY=distY / ((upTime - last2MoveTime) / 1000.0f);
}
if (velocityX == 0 && velocityY == 0) {
distX=convertPxToDip((int)(upRawX - downRawX));
distY=convertPxToDip((int)(upRawY - downRawY));
velocityX=distX / ((upTime - downTime) / 1000.0f);
velocityY=distY / ((upTime - downTime) / 1000.0f);
}
if (directionKnown) {
if (direction == DIRECTION_UP && velocityY < -MIN_THRESHOLD_VELOCITY) {
onBottomToTop(-velocityY / 300.0f);
}
 else if (direction == DIRECTION_DOWN && velocityY > MIN_THRESHOLD_VELOCITY) {
onTopToBottom(velocityY / 300.0f);
}
 else if (direction == DIRECTION_LEFT && velocityX < -MIN_THRESHOLD_VELOCITY) {
onRightToLeft(-velocityX / 300.0f);
}
 else if (direction == DIRECTION_RIGHT && velocityX > MIN_THRESHOLD_VELOCITY) {
onLeftToRight(velocityX / 300.0f);
}
 else {
onSwipeFail();
}
}
 else {
v.callOnClick();
}
break;
}
return true;
}