Search in sources :

Example 11 with UserNotification

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

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)

Example 12 with UserNotification

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

the class Notifications method clearExtraCalibrationRequest.

private void clearExtraCalibrationRequest() {
    UserNotification userNotification = UserNotification.lastExtraCalibrationAlert();
    if (userNotification != null) {
        userNotification.delete();
        notificationDismiss(extraCalibrationNotificationId);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification)

Example 13 with UserNotification

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

the class Notifications method clearDoubleCalibrationRequest.

private void clearDoubleCalibrationRequest() {
    UserNotification userNotification = UserNotification.lastDoubleCalibrationAlert();
    if (userNotification != null) {
        userNotification.delete();
        notificationDismiss(doubleCalibrationNotificationId);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification)

Example 14 with UserNotification

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

the class Notifications method calibrationRequest.

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

Example 15 with UserNotification

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

the class Notifications method clearDoubleCalibrationRequest.

private void clearDoubleCalibrationRequest() {
    UserNotification userNotification = UserNotification.lastDoubleCalibrationAlert();
    if (userNotification != null) {
        userNotification.delete();
        notificationDismiss(doubleCalibrationNotificationId);
    }
}
Also used : UserNotification(com.eveningoutpost.dexdrip.Models.UserNotification)

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