Merge "CountDownTimer: not skip onTick()"
am: 224d9e48fa
Change-Id: I7ade5d057e73f53867747c00fcfc5882a57a2f4c
This commit is contained in:
@@ -125,19 +125,28 @@ public abstract class CountDownTimer {
|
||||
|
||||
if (millisLeft <= 0) {
|
||||
onFinish();
|
||||
} else if (millisLeft < mCountdownInterval) {
|
||||
// no tick, just delay until done
|
||||
sendMessageDelayed(obtainMessage(MSG), millisLeft);
|
||||
} else {
|
||||
long lastTickStart = SystemClock.elapsedRealtime();
|
||||
onTick(millisLeft);
|
||||
|
||||
// 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
|
||||
// complete, skip to next interval
|
||||
while (delay < 0) delay += mCountdownInterval;
|
||||
if (millisLeft < mCountdownInterval) {
|
||||
// just delay until done
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user