public static void RiseDropAlert(Context context, boolean on, String type, String message, int notificatioId) { if(on) { // This alerts will only happen once. Want to have maxint, but not create overflow. OtherAlert(context, type, message, notificatioId, false, Integer.MAX_VALUE / 100000); } else { NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.cancel(notificatioId); UserNotification.DeleteNotificationByType(type); } }
public static void snoozeAlert(String type, long snoozeMinutes) { UserNotification userNotification = GetNotificationByType(type); if(userNotification == null) { Log.e(TAG, "Error snoozeAlert did not find an alert for type " + type); return; } userNotification.timestamp = new Date().getTime() + snoozeMinutes * 60000; userNotification.save(); }
private void doubleCalibrationRequest() { UserNotification userNotification = UserNotification.lastDoubleCalibrationAlert(); if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) { if (userNotification != null) { userNotification.delete(); } UserNotification.create("Double Calibration", "double_calibration_alert", new Date().getTime()); String title = "Sensor is ready"; //KS String content = getString(R.string.sensor_is_ready_please_enter_double_calibration) + " (@" + JoH.hourMinuteString() + ")"; //KS Intent intent = new Intent(mContext, DoubleCalibrationActivity.class); //KS calibrationNotificationCreate(title, content, intent, calibrationNotificationId); } }
@Override public boolean onPreferenceChange(Preference preference, Object newValue) { // clear any pending alerts final UserNotification userNotification = UserNotification.lastCalibrationAlert(); if (userNotification != null) { userNotification.delete(); } return true; } });
public static void DeleteNotificationByType(String type) { fixUpTable(); if (legacy_types.contains(type)) { UserNotification userNotification = UserNotification.GetNotificationByType(type); if (userNotification != null) { userNotification.delete(); } } else { PersistentStore.setString("UserNotification:timestamp:" + type, ""); } }
@Test public void deleteExistingNewAlert() { // :: Setup UserNotification.create("test1", "testAlert", System.currentTimeMillis()); // :: Act UserNotification.DeleteNotificationByType("testAlert"); // :: Verify UserNotification calibrationAlert = UserNotification.GetNotificationByType("testAlert"); assertThat(calibrationAlert).isNull(); }
@Test public void snoozeNonExistingAlert() { // :: Setup long initialTimestamp = System.currentTimeMillis(); UserNotification.create("test1", "testAlert", initialTimestamp); // :: Act UserNotification.snoozeAlert("testAlert2", 15); // :: Verify UserNotification calibrationAlert = UserNotification.GetNotificationByType("testAlert"); assertThat(calibrationAlert).isNotNull(); assertThat(calibrationAlert.timestamp).isWithin(0).of(initialTimestamp); }
@Test public void deleteNonExistingLegacyAlert() { // :: Act UserNotification.DeleteNotificationByType("calibration_alert"); // :: Verify UserNotification calibrationAlert = UserNotification.GetNotificationByType("calibration_alert"); assertThat(calibrationAlert).isNull(); }
@Test public void getExistingNewNotification() { // :: Setup UserNotification.create("test1", "testAlert", System.currentTimeMillis()); // :: Act UserNotification calibrationAlert = UserNotification.GetNotificationByType("testAlert"); // :: Verify assertThat(calibrationAlert).isNotNull(); assertThat(calibrationAlert.message).isEqualTo("test1"); }
private void extraCalibrationRequest() { UserNotification userNotification = UserNotification.lastExtraCalibrationAlert(); if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) { if (userNotification != null) { userNotification.delete(); } UserNotification.create("Extra Calibration Requested", "extra_calibration_alert", new Date().getTime()); String title = "Calibration Requested"; String content = "Increase performance by calibrating now" + " (@" + JoH.hourMinuteString() + ")"; //KS Intent intent = new Intent(mContext, AddCalibration.class); //KS calibrationNotificationCreate(title, content, intent, extraCalibrationNotificationId); } }
private void calibrationRequest() { UserNotification userNotification = UserNotification.lastCalibrationAlert(); if ((userNotification == null) || (userNotification.timestamp <= ((new Date().getTime()) - (60000 * calibration_snooze)))) { if (userNotification != null) { userNotification.delete(); } UserNotification.create("12 hours since last Calibration (@" + JoH.hourMinuteString() + ")", "calibration_alert", new Date().getTime()); String title = "Calibration Needed"; String content = "12 hours since last calibration"; //KS Intent intent = new Intent(mContext, AddCalibration.class); //KS calibrationNotificationCreate(title, content, intent, calibrationNotificationId); } }
UserNotification userNotification = UserNotification.GetNotificationByType(type); //"bg_unclear_readings_alert" if ((userNotification == null) || userNotification.timestamp <= new Date().getTime() ) { if (userNotification != null) { try { userNotification.delete(); } catch (NullPointerException e) { UserNotification.create(message, type, new Date().getTime() + reraiseSec * 1000);
@Test public void lastExtraCalibrationAlert() { // :: Setup UserNotification.create("test1", "extra_calibration_alert", System.currentTimeMillis()); UserNotification.create("test2", "extra_calibration_alert", System.currentTimeMillis()); // :: Act UserNotification userNotification = UserNotification.lastExtraCalibrationAlert(); // :: Verify assertThat(userNotification.extra_calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo("test2"); }
@Test public void lastDoubleCalibrationAlert() { // :: Setup UserNotification.create("test1", "double_calibration_alert", System.currentTimeMillis()); UserNotification.create("test2", "double_calibration_alert", System.currentTimeMillis()); // :: Act UserNotification userNotification = UserNotification.lastDoubleCalibrationAlert(); // :: Verify assertThat(userNotification.double_calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo("test2"); }
private long calcuatleArmTimeUnclearalert(Context ctx, long now, boolean unclearAlert) { if (!unclearAlert) { return Long.MAX_VALUE; } Long wakeTimeUnclear = Long.MAX_VALUE; UserNotification userNotification = UserNotification.GetNotificationByType("bg_unclear_readings_alert"); if (userNotification == null) { // This is the case, that we are in unclear sensor reading, but for small time, so there is no call Log.i(TAG, "No active alert exists. returning Long.MAX_VALUE"); return Long.MAX_VALUE; } else { // This alert is snoozed // reminder - userNotification.timestamp is the time that the alert should be played again wakeTimeUnclear = (long)userNotification.timestamp; } if(wakeTimeUnclear < now ) { // we should alert now, wakeTimeUnclear = now; } if( wakeTimeUnclear == Long.MAX_VALUE) { // Should not happen Log.e(TAG ,"calcuatleArmTimeUnclearalert wakeTimeUnclear bad value setting it to one minute from now " + new Date(wakeTimeUnclear) + " in " + ((wakeTimeUnclear - now)/60000d) + " minutes" ); return now + 60 * 1000; } Log.w(TAG ,"calcuatleArmTimeUnclearalert returning " + new Date(wakeTimeUnclear) + " in " + ((wakeTimeUnclear - now)/60000d) + " minutes" ); return wakeTimeUnclear; }
@Test public void lastCalibrationAlert() { // :: Setup UserNotification.create("test1", "calibration_alert", System.currentTimeMillis()); UserNotification.create("test2", "calibration_alert", System.currentTimeMillis()); // :: Act UserNotification userNotification = UserNotification.lastCalibrationAlert(); // :: Verify assertThat(userNotification.calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo("test2"); }
@Test public void lastBgAlert() { // :: Setup UserNotification.create("test1", "bg_alert", System.currentTimeMillis()); UserNotification.create("test2", "bg_alert", System.currentTimeMillis()); // :: Act UserNotification userNotification = UserNotification.lastBgAlert(); // :: Verify assertThat(userNotification.bg_alert).isTrue(); assertThat(userNotification.message).isEqualTo("test2"); }
private void clearExtraCalibrationRequest() { UserNotification userNotification = UserNotification.lastExtraCalibrationAlert(); if (userNotification != null) { userNotification.delete(); notificationDismiss(extraCalibrationNotificationId); } }
private void clearDoubleCalibrationRequest() { UserNotification userNotification = UserNotification.lastDoubleCalibrationAlert(); if (userNotification != null) { userNotification.delete(); notificationDismiss(doubleCalibrationNotificationId); } }
public static void DeleteNotificationByType(String type) { if (legacy_types.contains(type)) { UserNotification userNotification = UserNotification.GetNotificationByType(type); if (userNotification != null) { userNotification.delete(); } } else { PersistentStore.setString("UserNotification:timestamp:" + type, ""); } }