Here is my onTouchEvent, it should be fairly self explanatory.
@Override
public boolean onTouchEvent(MotionEvent event) {
float mvX;
float mvY;
boolean chg;
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
startY = event.getY();
startX = event.getX();
break;
case MotionEvent.ACTION_MOVE:
endY = event.getY();
endX = event.getX();
break;
case MotionEvent.ACTION_UP:
endY = event.getY();
endX = event.getX();
break;
default:
return false;
}
chg = false;
mvY = endY - startY;
if(mvY > 5) {
mySecondsTotal += 1;
chg = true;
}
if(mvY < -5) {
mySecondsTotal -= 1;
chg = true;
}
mvX = endX - startX;
if(mvX > 5) {
mySecondsTotal += 1;
chg = true;
}
if(mvX < -5) {
mySecondsTotal -= 1;
chg = true;
}
if (chg == false)
return true;
startY = event.getY();
startX = event.getX();
if (mySecondsTotal < 0)
mySecondsTotal = 0;
Message m = new Message();
m.what = timer.GUIUPDATEIDENTIFIER;
this.myYogaViewUpdateHandler.sendMessage(m);
return true;
}
No comments:
Post a Comment