Search in sources :

Example 1 with UserNotification

use of com.eveningoutpost.dexdrip.Models.UserNotification in project xDrip by NightscoutFoundation.

the class Notifications method doubleCalibrationRequest.

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);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification) Date(java.util.Date)

Example 2 with UserNotification

use of com.eveningoutpost.dexdrip.Models.UserNotification in project xDrip by NightscoutFoundation.

the class Notifications method extraCalibrationRequest.

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);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification) Date(java.util.Date)

Example 3 with UserNotification

use of com.eveningoutpost.dexdrip.Models.UserNotification in project xDrip-plus by jamorham.

the class MissedReadingService method checkBackAfterSnoozeTime.

private void checkBackAfterSnoozeTime(Context context, long now) {
    // This is not 100% acurate, need to take in account also the time of when this alert was snoozed.
    UserNotification userNotification = UserNotification.GetNotificationByType("bg_missed_alerts");
    if (userNotification == null) {
        // No active alert exists, should not happen, we have just created it.
        Log.wtf(TAG, "No active alert exists.");
        setAlarm(getOtherAlertReraiseSec(context, "bg_missed_alerts") * 1000, false);
    } else {
        // we have an alert that should be re-raised on userNotification.timestamp
        long alarmIn = (long) userNotification.timestamp - now;
        if (alarmIn < 0) {
            alarmIn = 0;
        }
        setAlarm(alarmIn, true);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification)

Example 4 with UserNotification

use of com.eveningoutpost.dexdrip.Models.UserNotification in project xDrip-plus by jamorham.

the class Notifications method clearCalibrationRequest.

private void clearCalibrationRequest() {
    UserNotification userNotification = UserNotification.lastCalibrationAlert();
    if (userNotification != null) {
        userNotification.delete();
        notificationDismiss(calibrationNotificationId);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification)

Example 5 with UserNotification

use of com.eveningoutpost.dexdrip.Models.UserNotification in project xDrip-plus by jamorham.

the class Notifications method OtherAlert.

private static void OtherAlert(Context context, String type, String message, int notificatioId, boolean addDeleteIntent, long reraiseSec) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String otherAlertsSound = prefs.getString(type + "_sound", prefs.getString("other_alerts_sound", "content://settings/system/notification_sound"));
    Boolean otherAlertsOverrideSilent = prefs.getBoolean("other_alerts_override_silent", false);
    Log.d(TAG, "OtherAlert called " + type + " " + message + " reraiseSec = " + reraiseSec);
    // "bg_unclear_readings_alert"
    UserNotification userNotification = UserNotification.GetNotificationByType(type);
    if ((userNotification == null) || userNotification.timestamp <= new Date().getTime()) {
        if (userNotification != null) {
            try {
                userNotification.delete();
            } catch (NullPointerException e) {
            // ignore null pointer exception during delete as we emulate database records
            }
            Log.d(TAG, "Delete");
        }
        UserNotification.create(message, type, new Date().getTime() + reraiseSec * 1000);
        // KS
        boolean localOnly = false;
        if (notificatioId == persistentHighAlertNotificationId) {
            localOnly = (Home.get_forced_wear() && bg_notifications && bg_persistent_high_alert_enabled);
        }
        Log.d(TAG, "OtherAlert forced_wear localOnly=" + localOnly);
        Intent intent = new Intent(context, Home.class);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(// KS ic_action_communication_invert_colors_on
        R.drawable.ic_launcher).setContentTitle(message).setContentText(message).setLocalOnly(// KS
        localOnly).setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        if (addDeleteIntent) {
            Intent deleteIntent = new Intent(context, SnoozeOnNotificationDismissService.class);
            deleteIntent.putExtra("alertType", type);
            mBuilder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        }
        mBuilder.setVibrate(vibratePattern);
        mBuilder.setLights(0xff00ff00, 300, 1000);
        if (AlertPlayer.notSilencedDueToCall()) {
            if (otherAlertsOverrideSilent) {
                mBuilder.setSound(Uri.parse(otherAlertsSound), AudioAttributes.USAGE_ALARM);
            } else {
                mBuilder.setSound(Uri.parse(otherAlertsSound));
            }
        }
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // mNotifyMgr.cancel(notificatioId);
        // Log.d(TAG, "Notify");
        Log.ueh("Other Alert", message);
        mNotifyMgr.notify(notificatioId, mBuilder.build());
    }
}
Also used : NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Date(java.util.Date)

Aggregations

UserNotification (com.eveningoutpost.dexdrip.Models.UserNotification)18 Date (java.util.Date)10 NotificationManager (android.app.NotificationManager)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 NotificationCompat (android.support.v4.app.NotificationCompat)2