Fixed bug where a missed, non-recurring alarm that superseded a previous alarm was not disabled after exiting AlarmActivity. Fixed bug where successive alarms would cancel missed alarm notifications for previous alarms.
This commit is contained in:
parent
7b81bb467f
commit
d7b3fc6ee1
@ -2,6 +2,7 @@ package com.philliphsu.clock2.alarms;
|
|||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -32,9 +33,25 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
|
|||||||
@Override
|
@Override
|
||||||
public void finish() {
|
public void finish() {
|
||||||
super.finish();
|
super.finish();
|
||||||
|
// If the presently ringing alarm is about to be superseded by a successive alarm,
|
||||||
|
// this, unfortunately, will cancel the missed alarm notification for the presently
|
||||||
|
// ringing alarm.
|
||||||
|
//
|
||||||
|
// A workaround is to override onNewIntent() and post the missed alarm notification again,
|
||||||
|
// AFTER calling through to its base implementation, because it calls finish().
|
||||||
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
// -------------- TOneverDO: precede super ---------------
|
||||||
|
// Even though the base implementation calls finish() on this instance and starts a new
|
||||||
|
// instance, this instance will still be alive with all of its member state intact at
|
||||||
|
// this point. So this notification will still refer to the Alarm that was just missed.
|
||||||
|
postMissedAlarmNote();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
|
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
|
||||||
return AlarmRingtoneService.class;
|
return AlarmRingtoneService.class;
|
||||||
@ -102,7 +119,10 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
|
|||||||
@Override
|
@Override
|
||||||
protected void showAutoSilenced() {
|
protected void showAutoSilenced() {
|
||||||
super.showAutoSilenced();
|
super.showAutoSilenced();
|
||||||
// Post notification that alarm was missed
|
postMissedAlarmNote();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postMissedAlarmNote() {
|
||||||
String alarmTime = DateFormatUtils.formatTime(this,
|
String alarmTime = DateFormatUtils.formatTime(this,
|
||||||
getRingingObject().hour(), getRingingObject().minutes());
|
getRingingObject().hour(), getRingingObject().minutes());
|
||||||
Notification note = new NotificationCompat.Builder(this)
|
Notification note = new NotificationCompat.Builder(this)
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package com.philliphsu.clock2.ringtone;
|
package com.philliphsu.clock2.ringtone;
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -130,10 +129,6 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
|||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
//super.onNewIntent(intent); // Not needed since no fragments hosted?
|
//super.onNewIntent(intent); // Not needed since no fragments hosted?
|
||||||
|
|
||||||
// TODO: Do we need this anymore? I think the broadcast that calls through to
|
|
||||||
// this was only sent from EditAlarmActivity?
|
|
||||||
|
|
||||||
// Notifies alarm missed and stops the service
|
// Notifies alarm missed and stops the service
|
||||||
LocalBroadcastHelper.sendBroadcast(this, RingtoneService.ACTION_NOTIFY_MISSED);
|
LocalBroadcastHelper.sendBroadcast(this, RingtoneService.ACTION_NOTIFY_MISSED);
|
||||||
finish();
|
finish();
|
||||||
@ -180,7 +175,6 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
|||||||
@OnClick(R.id.ok)
|
@OnClick(R.id.ok)
|
||||||
public void finish() {
|
public void finish() {
|
||||||
super.finish();
|
super.finish();
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAlive() {
|
public static boolean isAlive() {
|
||||||
|
|||||||
@ -3,6 +3,8 @@ package com.philliphsu.clock2.ringtone;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
@ -57,17 +59,16 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
// // Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
||||||
// that sends such a broadcast, is deprecated.
|
// // that sends such a broadcast, is deprecated.
|
||||||
// private final BroadcastReceiver mNotifyMissedReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mNotifyMissedReceiver = new BroadcastReceiver() {
|
||||||
// @Override
|
@Override
|
||||||
// public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
// // TODO: Do we need to call mAlarmController.cancelAlarm()?
|
onAutoSilenced();
|
||||||
// onAutoSilenced();
|
stopSelf();
|
||||||
// stopSelf();
|
// Activity finishes itself
|
||||||
// // Activity finishes itself
|
}
|
||||||
// }
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback invoked when this Service is stopping and the corresponding
|
* Callback invoked when this Service is stopping and the corresponding
|
||||||
@ -137,7 +138,7 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
||||||
// that sends such a broadcast, is deprecated.
|
// that sends such a broadcast, is deprecated.
|
||||||
// LocalBroadcastHelper.registerReceiver(this, mNotifyMissedReceiver, ACTION_NOTIFY_MISSED);
|
LocalBroadcastHelper.registerReceiver(this, mNotifyMissedReceiver, ACTION_NOTIFY_MISSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -152,7 +153,7 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
|
|||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
|
||||||
// that sends such a broadcast, is deprecated.
|
// that sends such a broadcast, is deprecated.
|
||||||
// LocalBroadcastHelper.unregisterReceiver(this, mNotifyMissedReceiver);
|
LocalBroadcastHelper.unregisterReceiver(this, mNotifyMissedReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user