I m doing counting on how long the button was pressed right after ACTION_DOWN, depending on how long it was pressed - I respond to the press differently in ACTION_UP.
The problem is that when i do action_down(press), it does not count down to the end, and sometime it does.
Code:
@Override
public boolean onTouch(final View v, final MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
still_down = false;
main_timer = new CountDownTimer(500, 4) {
@Override
public void onTick(long millisUntilFinished) {
Log.wtf("x", "timer: " + millisUntilFinished);
if ((int) millisUntilFinished < 100 && e.getAction() == MotionEvent.ACTION_DOWN) {
// above is where i detect that timer does not count down to 0, it stops at 119,107 etc
still_down = true;
}
}
@Override
public void onFinish() {
if (still_down) {
Log.wtf("x", "SHOW THE LARGE CARD!!!!!!!!!!!!!!!!!");
answer.setTextSize(50);
RelativeLayout.LayoutParams x = new RelativeLayout.LayoutParams(350, 500);
x.setMargins(margin_long_press_x1, margin_long_press_y1, 0, 0);
answer.setLayoutParams(x);
answer.requestLayout();
}
}
};
main_timer.start();
break;
case MotionEvent.ACTION_UP:
if (still_down) {
//image becomes small size again
main_timer.cancel();
} else {
action_on_single_tap( e);
}
break;
}
return true;
}
I put a log in onTick()and see that the timer does not always count to 0.
Are there alternatives to counting how long button is pressed in android? I dont know any other ways.