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

Commit 968d29f8 authored by Stevie Kideckel's avatar Stevie Kideckel Committed by Automerger Merge Worker
Browse files

Merge "Stop using TIME_TICK broadcast in TextClock" into sc-dev am: a0a7d15b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14899456

Change-Id: I6606dbed7263458c023410f405aad9908f42ed76
parents cb11ce6b a0a7d15b
Loading
Loading
Loading
Loading
+24 −16
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import android.icu.text.DateTimePatternGenerator;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.format.DateFormat;
@@ -45,6 +44,10 @@ import android.view.inspector.InspectableProperty;

import com.android.internal.R;

import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.TimeZone;

@@ -185,18 +188,29 @@ public class TextClock extends TextView {

    private final Runnable mTicker = new Runnable() {
        public void run() {
            if (mStopTicking) {
            removeCallbacks(this);
            if (mStopTicking || !mShouldRunTicker) {
                return; // Test disabled the clock ticks
            }
            onTimeChanged();

            long now = SystemClock.uptimeMillis();
            long next = now + (1000 - now % 1000);
            Instant now = mTime.toInstant();
            ZoneId zone = mTime.getTimeZone().toZoneId();

            ZonedDateTime nextTick;
            if (mHasSeconds) {
                nextTick = now.atZone(zone).plusSeconds(1).withNano(0);
            } else {
                nextTick = now.atZone(zone).plusMinutes(1).withSecond(0).withNano(0);
            }

            Handler handler = getHandler();
            if (handler != null) {
                handler.postAtTime(mTicker, next);
            long millisUntilNextTick = Duration.between(now, nextTick.toInstant()).toMillis();
            if (millisUntilNextTick <= 0) {
                // This should never happen, but if it does, then tick again in a second.
                millisUntilNextTick = 1000;
            }

            postDelayed(this, millisUntilNextTick);
        }
    };

@@ -519,8 +533,7 @@ public class TextClock extends TextView {
        mHasSeconds = DateFormat.hasSeconds(mFormat);

        if (mShouldRunTicker && hadSeconds != mHasSeconds) {
            if (hadSeconds) getHandler().removeCallbacks(mTicker);
            else mTicker.run();
            mTicker.run();
        }
    }

@@ -557,14 +570,10 @@ public class TextClock extends TextView {

        if (!mShouldRunTicker && isVisible) {
            mShouldRunTicker = true;
            if (mHasSeconds) {
            mTicker.run();
            } else {
                onTimeChanged();
            }
        } else if (mShouldRunTicker && !isVisible) {
            mShouldRunTicker = false;
            getHandler().removeCallbacks(mTicker);
            removeCallbacks(mTicker);
        }
    }

@@ -592,7 +601,6 @@ public class TextClock extends TextView {
    private void registerReceiver() {
        final IntentFilter filter = new IntentFilter();

        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);