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

Commit 1034bf17 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add TestApi to disable the TextClock clock tick."

parents e1a67fab 1c9b3136
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -977,6 +977,10 @@ package android.widget {
    method public boolean isPopupShowing();
  }

  public class TextClock extends android.widget.TextView {
    method public void disableClockTick();
  }

  public class TimePicker extends android.widget.FrameLayout {
    method public android.view.View getAmView();
    method public android.view.View getHourView();
+19 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.ViewDebug.ExportedProperty;
import static android.widget.RemoteViews.RemoteView;

import android.annotation.NonNull;
import android.annotation.TestApi;
import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -141,6 +142,9 @@ public class TextClock extends TextView {
    private boolean mShowCurrentUserTime;

    private ContentObserver mFormatChangeObserver;
    // Used by tests to stop time change events from triggering the text update
    private boolean mStopTicking;

    private class FormatChangeObserver extends ContentObserver {

        public FormatChangeObserver(Handler handler) {
@@ -163,6 +167,9 @@ public class TextClock extends TextView {
    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (mStopTicking) {
                return; // Test disabled the clock ticks
            }
            if (mTimeZone == null && Intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
                final String timeZone = intent.getStringExtra("time-zone");
                createTime(timeZone);
@@ -173,6 +180,9 @@ public class TextClock extends TextView {

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

            long now = SystemClock.uptimeMillis();
@@ -546,6 +556,15 @@ public class TextClock extends TextView {
        }
    }

    /**
     * Used by tests to stop the clock tick from updating the text.
     * @hide
     */
    @TestApi
    public void disableClockTick() {
        mStopTicking = true;
    }

    private void registerReceiver() {
        final IntentFilter filter = new IntentFilter();