My app contains a ViewFlipper
with some images. when app starts, the ViewFlipper
startflipping()
. When user touch the screen ViewFlipper stopflipping()
. I must do that after 60 seconds from last touch, ViewFlipper to start again flipping. My class implements onTouchListener
and I have this method onTouch
:
public boolean onTouch(View arg0, MotionEvent arg1) {
switch (arg1.getAction()) {
case MotionEvent.ACTION_DOWN: {
downXValue = arg1.getX();
break;
}
case MotionEvent.ACTION_UP: {
currentX = arg1.getX();
if (downXValue < currentX) {
// Set the animation
vf.stopFlipping();
vf.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
vf.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
// Flip!
vf.showPrevious();
}
if (downXValue > currentX) {
// Set the animation
vf.stopFlipping();
vf.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
vf.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
// Flip!
vf.showNext();
}
if (downXValue == currentX) {
final int idImage = arg0.getId();
vf.stopFlipping();
System.out.println("id" + idImage);
System.out.println("last touch "+getTimeOfLastEvent());
}
break;
}
}
// if you return false, these actions will not be recorded
return true;
}
and I found this method, for finding time of the last touch :
static long timeLastEvent=0;
public long getTimeOfLastEvent() {
long duration = System.currentTimeMillis() - timeLastEvent;
timeLastEvent = System.currentTimeMillis();
return duration;
}
My question is : where should I call the getTimeOfLastEvent()
? If I put it on onTouch()
I will never catch the moment when getTimeOfLastEvent==60000, right?