Merge "CountDownTimer: not skip onTick()"
This commit is contained in:
@@ -125,19 +125,28 @@ public abstract class CountDownTimer {
|
|||||||
|
|
||||||
if (millisLeft <= 0) {
|
if (millisLeft <= 0) {
|
||||||
onFinish();
|
onFinish();
|
||||||
} else if (millisLeft < mCountdownInterval) {
|
|
||||||
// no tick, just delay until done
|
|
||||||
sendMessageDelayed(obtainMessage(MSG), millisLeft);
|
|
||||||
} else {
|
} else {
|
||||||
long lastTickStart = SystemClock.elapsedRealtime();
|
long lastTickStart = SystemClock.elapsedRealtime();
|
||||||
onTick(millisLeft);
|
onTick(millisLeft);
|
||||||
|
|
||||||
// take into account user's onTick taking time to execute
|
// take into account user's onTick taking time to execute
|
||||||
long delay = lastTickStart + mCountdownInterval - SystemClock.elapsedRealtime();
|
long lastTickDuration = SystemClock.elapsedRealtime() - lastTickStart;
|
||||||
|
long delay;
|
||||||
|
|
||||||
// special case: user's onTick took more than interval to
|
if (millisLeft < mCountdownInterval) {
|
||||||
// complete, skip to next interval
|
// just delay until done
|
||||||
while (delay < 0) delay += mCountdownInterval;
|
delay = millisLeft - lastTickDuration;
|
||||||
|
|
||||||
|
// special case: user's onTick took more than interval to
|
||||||
|
// complete, trigger onFinish without delay
|
||||||
|
if (delay < 0) delay = 0;
|
||||||
|
} else {
|
||||||
|
delay = mCountdownInterval - lastTickDuration;
|
||||||
|
|
||||||
|
// special case: user's onTick took more than interval to
|
||||||
|
// complete, skip to next interval
|
||||||
|
while (delay < 0) delay += mCountdownInterval;
|
||||||
|
}
|
||||||
|
|
||||||
sendMessageDelayed(obtainMessage(MSG), delay);
|
sendMessageDelayed(obtainMessage(MSG), delay);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user