Additional notification cancellations.

This commit is contained in:
Timothy Allen 2014-03-26 14:23:03 +02:00
parent be115f4c7f
commit fa4c1152d3
4 changed files with 16 additions and 4 deletions

View File

@ -9,10 +9,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;

View File

@ -1,6 +1,7 @@
package za.org.treehouse.hypoalarm; package za.org.treehouse.hypoalarm;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@ -23,6 +24,11 @@ public class AlarmReceiver extends BroadcastReceiver {
Boolean alarmActive = sharedPref.getBoolean(context.getString(R.string.AlarmActivePref), true); Boolean alarmActive = sharedPref.getBoolean(context.getString(R.string.AlarmActivePref), true);
if (alarmActive) { if (alarmActive) {
// Cancel notification if it's not already cancelled.
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(AlarmNotify.notifyID);
// Set a grace period alarm to send SMS // Set a grace period alarm to send SMS
int gracePeriod = sharedPref.getInt(context.getString(R.string.GracePeriodPref), 60); int gracePeriod = sharedPref.getInt(context.getString(R.string.GracePeriodPref), 60);

View File

@ -1,6 +1,7 @@
package za.org.treehouse.hypoalarm; package za.org.treehouse.hypoalarm;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@ -11,6 +12,10 @@ import android.widget.Toast;
public class CancelGraceReceiver extends BroadcastReceiver { public class CancelGraceReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// Cancel notification if it's not already cancelled.
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(AlarmNotify.notifyID);
AlarmManager graceManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager graceManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent graceIntent = new Intent(context, GraceReceiver.class); Intent graceIntent = new Intent(context, GraceReceiver.class);
PendingIntent gracePendingIntent = PendingIntent.getBroadcast(context, MainActivity.GRACE_REQUEST, graceIntent, 0); PendingIntent gracePendingIntent = PendingIntent.getBroadcast(context, MainActivity.GRACE_REQUEST, graceIntent, 0);

View File

@ -3,6 +3,7 @@ package za.org.treehouse.hypoalarm;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.TimePickerDialog; import android.app.TimePickerDialog;
import android.content.ComponentName; import android.content.ComponentName;
@ -114,6 +115,10 @@ public class MainActivity extends ActionBarActivity {
editor.commit(); editor.commit();
if (!b) { if (!b) {
// Cancel notification if it's not already cancelled.
NotificationManager nm = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
nm.cancel(AlarmNotify.notifyID);
// Cancel any current alarm // Cancel any current alarm
alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(getActivity(), AlarmReceiver.class); Intent alarmIntent = new Intent(getActivity(), AlarmReceiver.class);