Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b08faf2 authored by Hidenari Koshimae's avatar Hidenari Koshimae Committed by android-build-merger
Browse files

Merge "CountDownTimer: not skip onTick()" am: 224d9e48 am: 9997fcc7

am: 9f0cc266

Change-Id: I75127bfd0fc4ce9256c775eaeb46582afd637e8d
parents d7e2ae5f 9f0cc266
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -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;

                    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);
                }