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

Commit 03b472e0 authored by Dan Pasanen's avatar Dan Pasanen Committed by Michael Bestas
Browse files

Revert "DeskClock: use non-Compat Notification classes"

This reverts commit dcb41bc4.

Change-Id: Id0cbee9c0fbec3800f34dffbee1bf47f3637287e
parent 0b316de0
Loading
Loading
Loading
Loading
+33 −37
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.service.notification.StatusBarNotification;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.content.ContextCompat;

import com.android.deskclock.AlarmClockFragment;
@@ -86,7 +88,7 @@ final class AlarmNotifications {

        Utils.createNotificationChannelsIfNeeded(context);

        Notification.Builder builder = new Notification.Builder(context,
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                    Utils.ALARM_CHANNEL)
                .setShowWhen(false)
                .setContentTitle(context.getString(
@@ -96,8 +98,8 @@ final class AlarmNotifications {
                .setSmallIcon(R.drawable.stat_notify_alarm)
                .setAutoCancel(false)
                .setSortKey(createSortKey(instance))
                .setCategory(Notification.CATEGORY_ALARM)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLocalOnly(true);

        if (Utils.isNOrLater()) {
@@ -125,8 +127,7 @@ final class AlarmNotifications {
        builder.setContentIntent(PendingIntent.getActivity(context, id,
                viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        final Notification notification = builder.build();
        nm.notify(id, notification);
        updateUpcomingAlarmGroupNotification(context, -1, notification);
@@ -138,7 +139,7 @@ final class AlarmNotifications {

        Utils.createNotificationChannelsIfNeeded(context);

        Notification.Builder builder = new Notification.Builder(context,
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                    Utils.ALARM_CHANNEL)
                .setShowWhen(false)
                .setContentTitle(context.getString(R.string.alarm_alert_predismiss_title))
@@ -147,8 +148,8 @@ final class AlarmNotifications {
                .setSmallIcon(R.drawable.stat_notify_alarm)
                .setAutoCancel(false)
                .setSortKey(createSortKey(instance))
                .setCategory(Notification.CATEGORY_ALARM)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLocalOnly(true);

        if (Utils.isNOrLater()) {
@@ -169,8 +170,7 @@ final class AlarmNotifications {
        builder.setContentIntent(PendingIntent.getActivity(context, id,
                viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        final Notification notification = builder.build();
        nm.notify(id, notification);
        updateUpcomingAlarmGroupNotification(context, -1, notification);
@@ -235,8 +235,8 @@ final class AlarmNotifications {
            return;
        }

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        final NotificationManagerCompat nm = NotificationManagerCompat.from(context);

        final Notification firstUpcoming = getFirstActiveNotification(context, UPCOMING_GROUP_KEY,
                canceledNotificationId, postedNotification);
        if (firstUpcoming == null) {
@@ -249,7 +249,7 @@ final class AlarmNotifications {
                || !Objects.equals(summary.contentIntent, firstUpcoming.contentIntent)) {
            Utils.createNotificationChannelsIfNeeded(context);

            summary = new Notification.Builder(context,
            summary = new NotificationCompat.Builder(context,
                        Utils.ALARM_CHANNEL)
                    .setShowWhen(false)
                    .setContentIntent(firstUpcoming.contentIntent)
@@ -257,8 +257,8 @@ final class AlarmNotifications {
                    .setSmallIcon(R.drawable.stat_notify_alarm)
                    .setGroup(UPCOMING_GROUP_KEY)
                    .setGroupSummary(true)
                    .setCategory(Notification.CATEGORY_ALARM)
                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_ALARM)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setLocalOnly(true)
                    .build();
            nm.notify(ALARM_GROUP_NOTIFICATION_ID, summary);
@@ -271,8 +271,8 @@ final class AlarmNotifications {
            return;
        }

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        final NotificationManagerCompat nm = NotificationManagerCompat.from(context);

        final Notification firstMissed = getFirstActiveNotification(context, MISSED_GROUP_KEY,
                canceledNotificationId, postedNotification);
        if (firstMissed == null) {
@@ -285,7 +285,7 @@ final class AlarmNotifications {
                || !Objects.equals(summary.contentIntent, firstMissed.contentIntent)) {
            Utils.createNotificationChannelsIfNeeded(context);

            summary = new Notification.Builder(context,
            summary = new NotificationCompat.Builder(context,
                        Utils.ALARM_CHANNEL)
                    .setShowWhen(false)
                    .setContentIntent(firstMissed.contentIntent)
@@ -293,8 +293,8 @@ final class AlarmNotifications {
                    .setSmallIcon(R.drawable.stat_notify_alarm)
                    .setGroup(MISSED_GROUP_KEY)
                    .setGroupSummary(true)
                    .setCategory(Notification.CATEGORY_ALARM)
                    .setVisibility(Notification.VISIBILITY_PUBLIC)
                    .setCategory(NotificationCompat.CATEGORY_ALARM)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setLocalOnly(true)
                    .build();
            nm.notify(ALARM_GROUP_MISSED_NOTIFICATION_ID, summary);
@@ -307,7 +307,7 @@ final class AlarmNotifications {

        Utils.createNotificationChannelsIfNeeded(context);

        Notification.Builder builder = new Notification.Builder(context,
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                    Utils.ALARM_CHANNEL)
                .setShowWhen(false)
                .setContentTitle(instance.getLabelOrDefault(context))
@@ -317,8 +317,8 @@ final class AlarmNotifications {
                .setSmallIcon(R.drawable.stat_notify_alarm)
                .setAutoCancel(false)
                .setSortKey(createSortKey(instance))
                .setCategory(Notification.CATEGORY_ALARM)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLocalOnly(true);

        if (Utils.isNOrLater()) {
@@ -339,8 +339,7 @@ final class AlarmNotifications {
        builder.setContentIntent(PendingIntent.getActivity(context, id,
                viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        final Notification notification = builder.build();
        nm.notify(id, notification);
        updateUpcomingAlarmGroupNotification(context, -1, notification);
@@ -355,7 +354,7 @@ final class AlarmNotifications {

        Utils.createNotificationChannelsIfNeeded(context);

        Notification.Builder builder = new Notification.Builder(context,
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
                    Utils.ALARM_CHANNEL)
                .setShowWhen(false)
                .setContentTitle(context.getString(R.string.alarm_missed_title))
@@ -364,8 +363,8 @@ final class AlarmNotifications {
                .setColor(ContextCompat.getColor(context, R.color.default_background))
                .setSortKey(createSortKey(instance))
                .setSmallIcon(R.drawable.stat_notify_alarm)
                .setCategory(Notification.CATEGORY_ALARM)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLocalOnly(true);

        if (Utils.isNOrLater()) {
@@ -388,8 +387,7 @@ final class AlarmNotifications {
        builder.setContentIntent(PendingIntent.getBroadcast(context, id,
                showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT));

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        final Notification notification = builder.build();
        nm.notify(id, notification);
        updateMissedAlarmGroupNotification(context, -1, notification);
@@ -402,7 +400,7 @@ final class AlarmNotifications {

        Utils.createNotificationChannelsIfNeeded(service);

        Notification.Builder notification = new Notification.Builder(service,
        NotificationCompat.Builder notification = new NotificationCompat.Builder(service,
                    Utils.ALARM_CHANNEL)
                .setContentTitle(instance.getLabelOrDefault(service))
                .setContentText(AlarmUtils.getFormattedTime(service, instance.getAlarmTime()))
@@ -410,10 +408,10 @@ final class AlarmNotifications {
                .setSmallIcon(R.drawable.stat_notify_alarm)
                .setOngoing(true)
                .setAutoCancel(false)
                .setDefaults(Notification.DEFAULT_LIGHTS)
                .setDefaults(NotificationCompat.DEFAULT_LIGHTS)
                .setWhen(0)
                .setCategory(Notification.CATEGORY_ALARM)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLocalOnly(true);

        // Setup Snooze Action
@@ -458,9 +456,7 @@ final class AlarmNotifications {

    static synchronized void clearNotification(Context context, AlarmInstance instance) {
        LogUtils.v("Clearing notifications for alarm instance: " + instance.mId);

        final NotificationManager nm =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationManagerCompat nm = NotificationManagerCompat.from(context);
        final int id = instance.hashCode();
        nm.cancel(id);
        updateUpcomingAlarmGroupNotification(context, id, null);
+6 −4
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.deskclock.data;

import android.app.Notification;
import android.app.Notification.Action;
import android.app.Notification.Builder;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -26,6 +24,10 @@ import android.content.res.Resources;
import android.os.SystemClock;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.widget.RemoteViews;

@@ -128,7 +130,7 @@ class StopwatchNotificationBuilder {

        Utils.createNotificationChannelsIfNeeded(context);

        final Builder notification = new Notification.Builder(context,
        final Builder notification = new NotificationCompat.Builder(context,
                    Utils.STOPWATCH_CHANNEL)
                .setLocalOnly(true)
                .setOngoing(running)
@@ -136,7 +138,7 @@ class StopwatchNotificationBuilder {
                .setContentIntent(pendingShowApp)
                .setAutoCancel(stopwatch.isPaused())
                .setSmallIcon(R.drawable.stat_notify_stopwatch)
                .setStyle(new Notification.DecoratedCustomViewStyle())
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setColor(ContextCompat.getColor(context, R.color.default_background));

        if (Utils.isNOrLater()) {
+13 −12
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ package com.android.deskclock.data;
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.Notification.Action;
import android.app.Notification.Builder;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -28,6 +26,7 @@ import android.content.res.Resources;
import android.os.Build;
import android.os.SystemClock;
import android.support.annotation.DrawableRes;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.widget.RemoteViews;
@@ -42,6 +41,8 @@ import com.android.deskclock.timer.TimerService;
import java.util.ArrayList;
import java.util.List;

import static android.support.v4.app.NotificationCompat.Action;
import static android.support.v4.app.NotificationCompat.Builder;
import static android.text.format.DateUtils.MINUTE_IN_MILLIS;
import static android.text.format.DateUtils.SECOND_IN_MILLIS;

@@ -149,18 +150,18 @@ class TimerNotificationBuilder {

        Utils.createNotificationChannelsIfNeeded(context);

        final Builder notification = new Notification.Builder(context,
        final Builder notification = new NotificationCompat.Builder(context,
                    Utils.TIMER_CHANNEL)
                .setOngoing(true)
                .setLocalOnly(true)
                .setShowWhen(false)
                .setAutoCancel(false)
                .setContentIntent(pendingShowApp)
                .setCategory(Notification.CATEGORY_ALARM)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setSmallIcon(R.drawable.stat_notify_timer)
                .setSortKey(nm.getTimerNotificationSortKey())
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setStyle(new Notification.DecoratedCustomViewStyle())
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setColor(ContextCompat.getColor(context, R.color.default_background));

        for (Action action : actions) {
@@ -264,7 +265,7 @@ class TimerNotificationBuilder {

        Utils.createNotificationChannelsIfNeeded(context);

        final Builder notification = new Notification.Builder(context,
        final Builder notification = new NotificationCompat.Builder(context,
                    Utils.TIMER_CHANNEL)
                .setOngoing(true)
                .setLocalOnly(true)
@@ -274,7 +275,7 @@ class TimerNotificationBuilder {
                .setDefaults(Notification.DEFAULT_LIGHTS)
                .setSmallIcon(R.drawable.stat_notify_timer)
                .setFullScreenIntent(pendingFullScreen, true)
                .setStyle(new Notification.DecoratedCustomViewStyle())
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setColor(ContextCompat.getColor(context, R.color.default_background));

        for (Action action : actions) {
@@ -349,17 +350,17 @@ class TimerNotificationBuilder {

        Utils.createNotificationChannelsIfNeeded(context);

        final Builder notification = new Notification.Builder(context,
        final Builder notification = new NotificationCompat.Builder(context,
                    Utils.TIMER_CHANNEL)
                .setLocalOnly(true)
                .setShowWhen(false)
                .setAutoCancel(false)
                .setContentIntent(pendingShowApp)
                .setCategory(Notification.CATEGORY_ALARM)
                .setCategory(NotificationCompat.CATEGORY_ALARM)
                .setSmallIcon(R.drawable.stat_notify_timer)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setSortKey(nm.getTimerNotificationMissedSortKey())
                .setStyle(new Notification.DecoratedCustomViewStyle())
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .addAction(action)
                .setColor(ContextCompat.getColor(context, R.color.default_background));