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

Commit 6f407e6e authored by Isaac Katzenelson's avatar Isaac Katzenelson Committed by Android (Google) Code Review
Browse files

Merge "Update clock daydream date display at midnight" into klp-dev

parents 9176f18c 8ea47506
Loading
Loading
Loading
Loading
+37 −12
Original line number Original line Diff line number Diff line
@@ -16,29 +16,18 @@


package com.android.deskclock;
package com.android.deskclock;


import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Handler;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.provider.Settings;
import android.service.dreams.DreamService;
import android.service.dreams.DreamService;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;


import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;
import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;


@@ -62,6 +51,31 @@ public class Screensaver extends DreamService {
        }
        }
    };
    };


    // Thread that runs every midnight and refreshes the date.
    private final Runnable mMidnightUpdater = new Runnable() {
        @Override
        public void run() {
            Utils.updateDate(mDateFormat, mDateFormatForAccessibility, mContentView);
            Utils.setMidnightUpdater(mHandler, mMidnightUpdater);
        }
    };

    /**
     * Receiver to handle time reference changes.
     */
    private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (action != null && (action.equals(Intent.ACTION_TIME_CHANGED)
                    || action.equals(Intent.ACTION_TIMEZONE_CHANGED))) {
                Utils.updateDate(mDateFormat, mDateFormatForAccessibility, mContentView);
                Utils.refreshAlarm(Screensaver.this, mContentView);
                Utils.setMidnightUpdater(mHandler, mMidnightUpdater);
            }
        }
    };

    public Screensaver() {
    public Screensaver() {
        if (DEBUG) Log.d(TAG, "Screensaver allocated");
        if (DEBUG) Log.d(TAG, "Screensaver allocated");
        mMoveSaverRunnable = new ScreensaverMoveSaverRunnable(mHandler);
        mMoveSaverRunnable = new ScreensaverMoveSaverRunnable(mHandler);
@@ -97,6 +111,13 @@ public class Screensaver extends DreamService {


        layoutClockSaver();
        layoutClockSaver();


        // Setup handlers for time reference changes and date updates.
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        registerReceiver(mIntentReceiver, filter);
        Utils.setMidnightUpdater(mHandler, mMidnightUpdater);

        getContentResolver().registerContentObserver(
        getContentResolver().registerContentObserver(
                Settings.System.getUriFor(Settings.System.NEXT_ALARM_FORMATTED),
                Settings.System.getUriFor(Settings.System.NEXT_ALARM_FORMATTED),
                false,
                false,
@@ -111,6 +132,10 @@ public class Screensaver extends DreamService {


        mHandler.removeCallbacks(mMoveSaverRunnable);
        mHandler.removeCallbacks(mMoveSaverRunnable);
        getContentResolver().unregisterContentObserver(mSettingsContentObserver);
        getContentResolver().unregisterContentObserver(mSettingsContentObserver);

        // Tear down handlers for time reference changes and date updates.
        Utils.resetMidnightUpdater(mHandler, mMidnightUpdater);
        unregisterReceiver(mIntentReceiver);
    }
    }


    private void setClockStyle() {
    private void setClockStyle() {
+24 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.view.MenuItem;
import android.view.MenuItem;
import android.view.View;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
@@ -397,6 +398,29 @@ public class Utils {
        return startAlarmOnQuarterHour(context);
        return startAlarmOnQuarterHour(context);
    }
    }


    // Setup a thread that starts at midnight plus one second. The extra second is added to ensure
    // the date has changed.
    public static void setMidnightUpdater(Handler handler, Runnable runnable) {
        String timezone = TimeZone.getDefault().getID();
        if (handler == null || runnable == null || timezone == null) {
            return;
        }
        long now = System.currentTimeMillis();
        Time time = new Time(timezone);
        time.set(now);
        long runInMillis = ((24 - time.hour) * 3600 - time.minute * 60 - time.second + 1) * 1000;
        handler.removeCallbacks(runnable);
        handler.postDelayed(runnable, runInMillis);
    }

    // Stop the midnight update thread
    public static void resetMidnightUpdater(Handler handler, Runnable runnable) {
        if (handler == null || runnable == null) {
            return;
        }
        handler.removeCallbacks(runnable);
    }

    /**
    /**
     * For screensavers to set whether the digital or analog clock should be displayed.
     * For screensavers to set whether the digital or analog clock should be displayed.
     * Returns the view to be displayed.
     * Returns the view to be displayed.