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

Commit b69f4084 authored by Robyn Coultas's avatar Robyn Coultas Committed by Isaac Katzenelson
Browse files

ACTION_ON_QUARTER_HOUR replaces ACTION_TIME_TICK

BUG: 7522888

Consolidated common code for this alarm into Utils
refresh quarter-hour-alarm when time changes

Change-Id: I96645d07db942a9030485cd71bd2a27a04475672
parent cb228aa0
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.alarmclock;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -49,6 +50,7 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo
    private boolean mReloadCitiesList = true;
    private boolean mReloadCitiesDb = true;
    private float mFontScale = 1;
    private PendingIntent mQuarterlyIntent;

    // An adapter to provide the view for the list of cities in the world clock.
    private class RemoteWorldClockAdapter extends WorldClockAdapter {
@@ -176,13 +178,14 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo

    @Override
    public void onCreate() {
        mQuarterlyIntent = Utils.startAlarmOnQuarterHour(mContext);
        // Do intent listening registration here since doing it in the manifest creates a new
        // new factory
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DATE_CHANGED);
        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_TIME_TICK);
        filter.addAction(Utils.ACTION_ON_QUARTER_HOUR);
        filter.addAction(Intent.ACTION_TIME_CHANGED);
        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
        filter.addAction("com.android.deskclock.NEXT_ALARM_TIME_SET");
@@ -206,6 +209,7 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo

    @Override
    public void onDestroy() {
        Utils.cancelAlarmOnQuarterHour(mContext, mQuarterlyIntent);
        mContext.unregisterReceiver(this);
    }

@@ -250,6 +254,7 @@ public class DigitalWidgetViewsFactory extends BroadcastReceiver implements Remo
            WidgetUtils.setClockSize(context, widget, ratio);
            refreshAlarm(context, widget);
            widgetManager.partiallyUpdateAppWidget(mId, widget);
            mQuarterlyIntent = Utils.refreshAlarmOnQuarterHour(context, mQuarterlyIntent);
        }
    }

+5 −9
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.deskclock;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -86,6 +85,9 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen
                    || action.equals(Alarms.ALARM_SNOOZE_CANCELLED)) {
                Utils.refreshAlarm(getActivity(), mClockFrame);
            }
            if (changed) {
                mQuarterlyIntent = Utils.refreshAlarmOnQuarterHour(getActivity(), mQuarterlyIntent);
            }
        }
    };

@@ -159,12 +161,7 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen
        mDateFormat = getString(R.string.abbrev_wday_month_day_no_year);
        mDateFormatForAccessibility = getString(R.string.full_wday_month_day_no_year);

        long alarmOnQuarterHour = Utils.getAlarmOnQuarterHour();
        mQuarterlyIntent = PendingIntent.getBroadcast(
                getActivity(), 0, new Intent(Utils.ACTION_ON_QUARTER_HOUR), 0);
        ((AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE)).setRepeating(
                AlarmManager.RTC, alarmOnQuarterHour, AlarmManager.INTERVAL_FIFTEEN_MINUTES,
                mQuarterlyIntent);
        mQuarterlyIntent = Utils.startAlarmOnQuarterHour(getActivity());
        // Besides monitoring when quarter-hour changes, monitor other actions that
        // effect clock time
        IntentFilter filter = new IntentFilter(Utils.ACTION_ON_QUARTER_HOUR);
@@ -197,8 +194,7 @@ public class ClockFragment extends DeskClockFragment implements OnSharedPreferen
    public void onPause() {
        super.onPause();
        mPrefs.unregisterOnSharedPreferenceChangeListener(this);
        ((AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE)).cancel(
                mQuarterlyIntent);
        Utils.cancelAlarmOnQuarterHour(getActivity(), mQuarterlyIntent);
        getActivity().unregisterReceiver(mIntentReceiver);
    }

+4 −28
Original line number Diff line number Diff line
@@ -16,44 +16,23 @@

package com.android.deskclock;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.service.dreams.DreamService;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.TextView;

import com.android.deskclock.Utils.ScreensaverMoveSaverRunnable;

import java.util.Calendar;

public class ScreensaverActivity extends Activity {
    static final boolean DEBUG = false;
    static final String TAG = "DeskClock/ScreensaverActivity";
@@ -96,6 +75,8 @@ public class ScreensaverActivity extends Activity {

            if (changed) {
                Utils.refreshAlarm(ScreensaverActivity.this, mContentView);
                mQuarterlyIntent = Utils.refreshAlarmOnQuarterHour(
                        ScreensaverActivity.this, mQuarterlyIntent);
            }

        }
@@ -136,18 +117,13 @@ public class ScreensaverActivity extends Activity {
        layoutClockSaver();
        mHandler.post(mMoveSaverRunnable);

        long alarmOnQuarterHour = Utils.getAlarmOnQuarterHour();
        mQuarterlyIntent = PendingIntent.getBroadcast(
                this, 0, new Intent(Utils.ACTION_ON_QUARTER_HOUR), 0);
        ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).setRepeating(
                AlarmManager.RTC, alarmOnQuarterHour, AlarmManager.INTERVAL_FIFTEEN_MINUTES,
                mQuarterlyIntent);
        mQuarterlyIntent = Utils.startAlarmOnQuarterHour(this);
    }

    @Override
    public void onPause() {
        mHandler.removeCallbacks(mMoveSaverRunnable);
        ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).cancel(mQuarterlyIntent);
        Utils.cancelAlarmOnQuarterHour(this, mQuarterlyIntent);
        finish();
        super.onPause();
    }
+30 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -313,7 +315,7 @@ public class Utils {
    }

    /** Setup to find out when the quarter-hour changes (e.g. Kathmandu is GMT+5:45) **/
    public static long getAlarmOnQuarterHour() {
    private static long getAlarmOnQuarterHour() {
        Calendar nextQuarter = Calendar.getInstance();
        //  Set 1 second to ensure quarter-hour threshold passed.
        nextQuarter.set(Calendar.SECOND, 1);
@@ -327,6 +329,33 @@ public class Utils {
        return alarmOnQuarterHour;
    }

    /** Setup alarm refresh when the quarter-hour changes **/
    public static PendingIntent startAlarmOnQuarterHour(Context context) {
        if (context != null) {
            PendingIntent quarterlyIntent = PendingIntent.getBroadcast(
                    context, 0, new Intent(Utils.ACTION_ON_QUARTER_HOUR), 0);
            ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setRepeating(
                    AlarmManager.RTC, getAlarmOnQuarterHour(),
                    AlarmManager.INTERVAL_FIFTEEN_MINUTES, quarterlyIntent);
            return quarterlyIntent;
        } else {
            return null;
        }
    }

    public static void cancelAlarmOnQuarterHour(Context context, PendingIntent quarterlyIntent) {
        if (quarterlyIntent != null && context != null) {
            ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).cancel(
                    quarterlyIntent);
        }
    }

    public static PendingIntent refreshAlarmOnQuarterHour(
            Context context, PendingIntent quarterlyIntent) {
        cancelAlarmOnQuarterHour(context, quarterlyIntent);
        return startAlarmOnQuarterHour(context);
    }

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