Show auto silence view

This commit is contained in:
Phillip Hsu
2016-08-06 02:52:49 -07:00
parent d845f241e9
commit 29194f241f
7 changed files with 86 additions and 24 deletions
@@ -1,6 +1,9 @@
package com.philliphsu.clock2.alarms;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.ViewGroup;
import com.philliphsu.clock2.Alarm;
@@ -8,10 +11,13 @@ import com.philliphsu.clock2.R;
import com.philliphsu.clock2.ringtone.RingtoneActivity;
import com.philliphsu.clock2.ringtone.RingtoneService;
import com.philliphsu.clock2.util.AlarmController;
import com.philliphsu.clock2.util.DateFormatUtils;
public class AlarmActivity extends RingtoneActivity<Alarm> {
private static final String TAG = "TimesUpActivity";
private AlarmController mAlarmController;
private NotificationManager mNotificationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -20,6 +26,13 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
// TODO: If the upcoming alarm notification isn't present, verify other notifications aren't affected.
// This could be the case if we're starting a new instance of this activity after leaving the first launch.
mAlarmController.removeUpcomingAlarmNotification(getRingingObject());
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
@Override
public void finish() {
super.finish();
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
}
@Override
@@ -75,4 +88,20 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
mAlarmController.cancelAlarm(getRingingObject(), false);
stopAndFinish();
}
// TODO: Consider changing the return type to Notification, and move the actual
// task of notifying to the base class.
@Override
protected void showAutoSilenced() {
super.showAutoSilenced();
// Post notification that alarm was missed
String alarmTime = DateFormatUtils.formatTime(this,
getRingingObject().hour(), getRingingObject().minutes());
Notification note = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.missed_alarm))
.setContentText(alarmTime)
.setSmallIcon(R.mipmap.ic_launcher)
.build();
mNotificationManager.notify(TAG, getRingingObject().getIntId(), note);
}
}
@@ -1,7 +1,6 @@
package com.philliphsu.clock2.alarms;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
@@ -20,7 +19,6 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
private static final String ACTION_SNOOZE = "com.philliphsu.clock2.ringtone.action.SNOOZE";
private static final String ACTION_DISMISS = "com.philliphsu.clock2.ringtone.action.DISMISS";
private String mNormalRingTime;
private AlarmController mAlarmController;
@Override
@@ -52,14 +50,6 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
protected void onAutoSilenced() {
// TODO do we really need to cancel the alarm and intent?
mAlarmController.cancelAlarm(getRingingObject(), false);
// Post notification that alarm was missed
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.missed_alarm))
.setContentText(mNormalRingTime)
.setSmallIcon(R.mipmap.ic_launcher)
.build();
nm.notify(TAG, getRingingObject().getIntId(), note);
}
@Override
@@ -72,12 +62,11 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
String title = getRingingObject().label().isEmpty()
? getString(R.string.alarm)
: getRingingObject().label();
mNormalRingTime = formatTime(this, System.currentTimeMillis()); // now
return new NotificationCompat.Builder(this)
// Required contents
.setSmallIcon(R.mipmap.ic_launcher) // TODO: alarm icon
.setContentTitle(title)
.setContentText(mNormalRingTime)
.setContentText(formatTime(this, System.currentTimeMillis()))
.addAction(R.mipmap.ic_launcher, // TODO: correct icon
getString(R.string.snooze),
getPendingIntent(ACTION_SNOOZE, getRingingObject().getIntId()))