Java Code Examples for com.eveningoutpost.dexdrip.Models.UserError.Log#ueh()

The following examples show how to use com.eveningoutpost.dexdrip.Models.UserError.Log#ueh() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void persistentHighAlert(Context context, boolean on, String msg) {
    final String type = "persistent_high_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("high_alerts_disabled_until", 0) < JoH.tsl())) {
            int snooze_time = 20;
            try {
                snooze_time = Integer.parseInt(Pref.getString("persistent_high_repeat_mins", "20"));
            } catch (NumberFormatException e) {
                Log.e(TAG, "Invalid snooze time for persistent high");
            }
            if (snooze_time < 1) snooze_time = 1;       // not less than 1 minute
            if (snooze_time > 1440) snooze_time = 1440; // not more than 1 day
            OtherAlert(context, type, msg, persistentHighAlertNotificationId, false, snooze_time * 60);
        } else {
            Log.ueh(TAG, "Not persistent high alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(persistentHighAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 2
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public static void persistentHighAlert(Context context, boolean on, String msg) {
    final String type = "persistent_high_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("high_alerts_disabled_until", 0) < JoH.tsl())) {
            int snooze_time = 20;
            try {
                snooze_time = Integer.parseInt(Pref.getString("persistent_high_repeat_mins", "20"));
            } catch (NumberFormatException e) {
                Log.e(TAG, "Invalid snooze time for persistent high");
            }
            if (snooze_time < 1) snooze_time = 1;       // not less than 1 minute
            if (snooze_time > 1440) snooze_time = 1440; // not more than 1 day
            OtherAlert(context, type, msg, persistentHighAlertNotificationId, false, snooze_time * 60);
        } else {
            Log.ueh(TAG, "Not persistent high alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(persistentHighAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 3
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public static void lowPredictAlert(Context context, boolean on, String msg) {
    final String type = "bg_predict_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("low_alerts_disabled_until", 0) < JoH.tsl())) {
            OtherAlert(context, type, msg, lowPredictAlertNotificationId, NotificationChannels.BG_PREDICTED_LOW_CHANNEL, false, 20 * 60);
            if (Pref.getBooleanDefaultFalse("speak_alerts")) {
               if (JoH.pratelimit("low-predict-speak", 1800)) SpeechUtil.say(msg, 4000);
            }
        } else {
            Log.ueh(TAG, "Not Low predict alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(lowPredictAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 4
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void Vibrate(Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) {
    //KS Watch currently only supports Vibration, no audio; Use VibrateAudio to support audio
    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && Pref.getBooleanDefaultFalse("bg_notifications"));//KS
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder  builder = new NotificationCompat.Builder(ctx)//KS Notification
            .setSmallIcon(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(notificationIntent(ctx, intent))
            .setLocalOnly(localOnly)//KS
            .setDeleteIntent(snoozeIntent(ctx));
    builder.setVibrate(Notifications.vibratePattern);
    Log.ueh("Alerting",content);
    NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());
    if (Pref.getBooleanDefaultFalse("alert_use_sounds")) {
        try {
            if (JoH.ratelimit("wear-alert-sound", 10)) {
                JoH.playResourceAudio(R.raw.warning);
            }
        } catch (Exception e) {
            //
        }
    }
}
 
Example 5
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void lowPredictAlert(Context context, boolean on, String msg) {
    final String type = "bg_predict_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("low_alerts_disabled_until", 0) < JoH.tsl())) {
            OtherAlert(context, type, msg, lowPredictAlertNotificationId, false,  20 * 60);
        } else {
            Log.ueh(TAG, "Not Low predict alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(lowPredictAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 6
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void lowPredictAlert(Context context, boolean on, String msg) {
    final String type = "bg_predict_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("low_alerts_disabled_until", 0) < JoH.tsl())) {
            OtherAlert(context, type, msg, lowPredictAlertNotificationId, false,  20 * 60);
        } else {
            Log.ueh(TAG, "Not Low predict alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(lowPredictAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 7
Source File: Calibration.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized void invalidateAllForSensor() {
    final List<Calibration> cals = allForSensorLimited(9999999);
    if (cals != null) {
        for (Calibration cal : cals) {
            cal.invalidate();
        }
    }
    JoH.clearCache();
    String msg = "Deleted all calibrations for sensor";
    Log.ueh(TAG, msg);
    JoH.static_toast_long(msg);
}
 
Example 8
Source File: Calibration.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized void invalidateAllForSensor() {
    final List<Calibration> cals = allForSensorLimited(9999999);
    if (cals != null) {
        for (Calibration cal : cals) {
            cal.invalidate();
        }
    }
    JoH.clearCache();
    String msg = "Deleted all calibrations for sensor";
    Log.ueh(TAG, msg);
    JoH.static_toast_long(msg);
}
 
Example 9
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void persistentHighAlert(Context context, boolean on, String msg) {
    final String type = "persistent_high_alert";
    if (on) {
        if ((Pref.getLong("alerts_disabled_until", 0) < JoH.tsl()) && (Pref.getLong("high_alerts_disabled_until", 0) < JoH.tsl())) {
            int snooze_time = 20;
            try {
                snooze_time = Integer.parseInt(Pref.getString("persistent_high_repeat_mins", "20"));
            } catch (NumberFormatException e) {
                Log.e(TAG, "Invalid snooze time for persistent high");
            }
            if (snooze_time < 1) snooze_time = 1;       // not less than 1 minute
            if (snooze_time > 1440) snooze_time = 1440; // not more than 1 day
            OtherAlert(context, type, msg, persistentHighAlertNotificationId, NotificationChannels.BG_PERSISTENT_HIGH_CHANNEL, false, snooze_time * 60);
            if (Pref.getBooleanDefaultFalse("speak_alerts")) {
                if (JoH.pratelimit("persist-high-speak", 1800)) {
                    SpeechUtil.say(msg, 4000);
                }
            }
        } else {
            Log.ueh(TAG, "Not persistent high alerting due to snooze: " + msg);
        }
    } else {
        NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotifyMgr.cancel(persistentHighAlertNotificationId);
        UserNotification.DeleteNotificationByType(type);
    }
}
 
Example 10
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void Vibrate(Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) {
    //KS Watch currently only supports Vibration, no audio; Use VibrateAudio to support audio
    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && Pref.getBooleanDefaultFalse("bg_notifications"));//KS
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder  builder = new NotificationCompat.Builder(ctx)//KS Notification
            .setSmallIcon(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
            .setContentTitle(title)
            .setContentText(content)
            .setContentIntent(notificationIntent(ctx, intent))
            .setLocalOnly(localOnly)//KS
            .setDeleteIntent(snoozeIntent(ctx));
    builder.setVibrate(Notifications.vibratePattern);
    Log.ueh("Alerting",content);
    NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());
    if (Pref.getBooleanDefaultFalse("alert_use_sounds")) {
        try {
            if (JoH.ratelimit("wear-alert-sound", 10)) {
                JoH.playResourceAudio(R.raw.warning);
            }
        } catch (Exception e) {
            //
        }
    }
}
 
Example 11
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private static void OtherAlert(Context context, String type, String title, String message, int notificatioId, String channelId, 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);
    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) {
                // ignore null pointer exception during delete as we emulate database records
            }
            Log.d(TAG, "Delete");
        }
        UserNotification.create(message, type, new Date().getTime() + reraiseSec * 1000);


        boolean localOnly =false;
        if (notificatioId == persistentHighAlertNotificationId) {
            localOnly = (Home.get_forced_wear() && bg_notifications_watch && bg_persistent_high_alert_enabled_watch);
        }
        Log.d(TAG,"OtherAlert forced_wear localOnly=" + localOnly);
        Intent intent = new Intent(context, Home.class);
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context, channelId)
                        .setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE)
                        .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setLocalOnly(localOnly)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                        .setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        if (addDeleteIntent) {
            Intent deleteIntent = new Intent(context, SnoozeOnNotificationDismissService.class);
            deleteIntent.putExtra("alertType", type);
            deleteIntent.putExtra("raisedTimeStamp", JoH.tsl());
            mBuilder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        }
        mBuilder.setVibrate(vibratePattern);
        mBuilder.setLights(0xff00ff00, 300, 1000);
        if (AlertPlayer.notSilencedDueToCall()) {
            if (otherAlertsOverrideSilent && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                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, XdripNotificationCompat.build(mBuilder));

        if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")
                && Pref.getBooleanDefaultFalse("pref_amazfit_other_alert_enable_key")) {
            Amazfitservice.start("xDrip_Otheralert", message, 30);
        }
    }
}
 
Example 12
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void VibrateNotifyMakeNoise(Context context, AlertType alert, String bgValue, int minsFromStartPlaying) {
    Log.d(TAG, "VibrateNotifyMakeNoise called minsFromStartedPlaying = " + minsFromStartPlaying);
    Log.d("ALARM", "setting vibrate alarm");
    int profile = getAlertProfile(context);
    if (alert.uuid.equals(AlertType.LOW_ALERT_55)) {
        // boost alerts...
        if (profile == ALERT_PROFILE_VIBRATE_ONLY) {
            profile = ALERT_PROFILE_ASCENDING;
        }
    }

    // We use timeFromStartPlaying as a way to force vibrating/ non vibrating...
    if (profile != ALERT_PROFILE_ASCENDING) {
        // We start from the non ascending part...
        minsFromStartPlaying = MAX_ASCENDING_MINUTES;
    }
    final String highlow = (alert.above ? context.getString(R.string.high) : context.getString(R.string.low)).toUpperCase();
    String title = bgValue + " " + alert.name;
    String content = "BG " + highlow + " ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    final Intent intent = new Intent(context, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && PersistentStore.getBoolean("bg_notifications_watch"));
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.BG_ALERT_CHANNEL)//KS Notification
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setContentTitle(title)
            .setContentText(content)
            //.addAction(R.drawable.ic_action_communication_invert_colors_on, "SNOOZE", notificationIntent(context, intent))
            .setContentIntent(notificationIntent(context, intent))
            .setLocalOnly(localOnly)
            .setGroup("xDrip level alert")
            .setPriority(Pref.getBooleanDefaultFalse("high_priority_notifications") ? Notification.PRIORITY_MAX : Notification.PRIORITY_HIGH)
            .setDeleteIntent(snoozeIntent(context, minsFromStartPlaying));

    if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) {
        if (minsFromStartPlaying >= MAX_VIBRATING_MINUTES) {
            // Before this, we only vibrate...
            float volumeFrac = (float) (minsFromStartPlaying - MAX_VIBRATING_MINUTES) / (MAX_ASCENDING_MINUTES - MAX_VIBRATING_MINUTES);
            volumeFrac = Math.min(volumeFrac, 1);
            if (profile == ALERT_PROFILE_MEDIUM) {
                volumeFrac = (float) 0.7;
            }
            Log.d(TAG, "VibrateNotifyMakeNoise volumeFrac = " + volumeFrac);
            boolean overrideSilent = alert.override_silent_mode;
            boolean forceSpeaker = alert.force_speaker;
            if (notSilencedDueToCall()) {
                if (overrideSilent || isLoudPhone(context)) {
                    playFile(context, alert.mp3_file, volumeFrac, forceSpeaker, overrideSilent);
                }
            } else {
                Log.i(TAG, "Silenced Alert Noise due to ongoing call");
            }
        }
    }
    if (profile != ALERT_PROFILE_SILENT && alert.vibrate) {
        if (notSilencedDueToCall()) {
            builder.setVibrate(Notifications.vibratePattern);
        } else {
            Log.i(TAG, "Vibration silenced due to ongoing call");
        }
    } else {
        // In order to still show on all android wear watches, either a sound or a vibrate pattern
        // seems to be needed. This pattern basically does not vibrate:
        builder.setVibrate(new long[]{1, 0});
    }
    Log.ueh("Alerting", content);
    final NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, XdripNotificationCompat.build(builder));

    // send to bluejay
    BlueJayEntry.sendAlertIfEnabled((alert.above ? "High" : "Low") + " Alert " + bgValue + " " + alert.name); // string text is used to determine alert type

    // send alert to pebble
    if (Pref.getBooleanDefaultFalse("broadcast_to_pebble") && (Pref.getBooleanDefaultFalse("pebble_vibe_alerts"))) {
        if (JoH.ratelimit("pebble_vibe_start", 59)) {
            JoH.startService(PebbleWatchSync.class);
        }
    }

    //send alert to amazfit
    if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")
            && Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) {
        Amazfitservice.start("xDrip_Alarm", alert.name, alert.default_snooze);
    }

    if (LeFunEntry.areAlertsEnabled() && ActiveBgAlert.currentlyAlerting()) {
        LeFun.sendAlert(highlow, bgValue);
    }

    if (MiBandEntry.areAlertsEnabled() && ActiveBgAlert.currentlyAlerting()) {
        MiBand.sendAlert(alert.name, highlow + " " + bgValue, alert.default_snooze);
    }

    // speak alert
    if (Pref.getBooleanDefaultFalse("speak_alerts")) {
        SpeechUtil.say(highlow + ", " + bgValue, 3000);
    }
}
 
Example 13
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void VibrateAudio(Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) {
    Log.d(TAG, "Vibrate called timeFromStartPlaying = " + timeFromStartPlaying);
    Log.d("ALARM", "setting vibrate alarm");
    int profile = getAlertProfile(ctx);
    if(alert.uuid.equals(AlertType.LOW_ALERT_55)) {
        // boost alerts...
        if(profile == ALERT_PROFILE_VIBRATE_ONLY) {
            profile = ALERT_PROFILE_ASCENDING;
        }
    }

    // We use timeFromStartPlaying as a way to force vibrating/ non vibrating...
    if (profile != ALERT_PROFILE_ASCENDING) {
        // We start from the non ascending part...
        timeFromStartPlaying = MAX_ASCENDING;
    }

    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && Pref.getBooleanDefaultFalse("bg_notifications"));//KS
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder  builder = new NotificationCompat.Builder(ctx)//KS Notification
        .setSmallIcon(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
        .setContentTitle(title)
        .setContentText(content)
        .setContentIntent(notificationIntent(ctx, intent))
        .setLocalOnly(localOnly)//KS
        .setDeleteIntent(snoozeIntent(ctx));

    if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) {
        if (timeFromStartPlaying >= MAX_VIBRATING) {
            // Before this, we only vibrate...
            float volumeFrac = (float)(timeFromStartPlaying - MAX_VIBRATING) / (MAX_ASCENDING - MAX_VIBRATING);
            volumeFrac = Math.min(volumeFrac, 1);
            if(profile == ALERT_PROFILE_MEDIUM) {
                volumeFrac = (float)0.7;
            }
            Log.d(TAG, "Vibrate volumeFrac = " + volumeFrac);
            boolean isRingTone = true;//KS TODO EditAlertActivity.isPathRingtone(ctx, alert.mp3_file);

            if (notSilencedDueToCall()) {
                if (isRingTone && !overrideSilent) {
                    builder.setSound(Uri.parse(alert.mp3_file));
                } else {
                    if (overrideSilent || isLoudPhone(ctx)) {
                        PlayFile(ctx, alert.mp3_file, volumeFrac);
                    }
                }
            } else {
                Log.i(TAG,"Silenced Alert Noise due to ongoing call");
            }
        }
    }
    if (profile != ALERT_PROFILE_SILENT && alert.vibrate) {
        if (notSilencedDueToCall()) {
            builder.setVibrate(Notifications.vibratePattern);
        } else {
            Log.i(TAG, "Vibration silenced due to ongoing call");
        }
    } else {
        // In order to still show on all android wear watches, either a sound or a vibrate pattern
        // seems to be needed. This pattern basically does not vibrate:
        //KS ADD:
        // This code snippet will cause the phone to vibrate "SOS" in Morse Code
        // In Morse Code, "s" = "dot-dot-dot", "o" = "dash-dash-dash"
        // There are pauses to separate dots/dashes, letters, and words
        // The following numbers represent millisecond lengths
        int dot = 200;      // Length of a Morse Code "dot" in milliseconds
        int dash = 500;     // Length of a Morse Code "dash" in milliseconds
        int short_gap = 200;    // Length of Gap Between dots/dashes
        int medium_gap = 500;   // Length of Gap Between Letters
        int long_gap = 1000;    // Length of Gap Between Words
        long[] pattern = {
                0,  // Start immediately
                dot, short_gap, dot, short_gap, dot,    // s
                medium_gap,
                dash, short_gap, dash, short_gap, dash, // o
                medium_gap,
                dot, short_gap, dot, short_gap, dot,    // s
                long_gap
        };
        // Only perform this pattern one time (-1 means "do not repeat")
        //mVibrator.vibrate(pattern, -1);
        builder.setVibrate(pattern);
        //builder.setVibrate(new long[]{1, 0});
    }
    Log.ueh("Alerting",content);
    NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());

    /* //KS not used on watch
    if (Pref.getBooleanDefaultFalse("broadcast_to_pebble") && (Pref.getBooleanDefaultFalse("pebble_vibe_alerts"))) {
        if (JoH.ratelimit("pebble_vibe_start", 59)) {
            ctx.startService(new Intent(ctx, PebbleWatchSync.class));
        }
    }*/
}
 
Example 14
Source File: ActiveBgAlert.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public void snooze(int minutes) {
    next_alert_at = new Date().getTime() + minutes * 60000;
    is_snoozed = true;
    Log.ueh("Snoozed Alert","Snoozed until: "+JoH.dateTimeText(next_alert_at));
    save();
}
 
Example 15
Source File: ActiveBgAlert.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public void snooze(int minutes) {
    next_alert_at = new Date().getTime() + minutes * 60000;
    is_snoozed = true;
    Log.ueh("Snoozed Alert","Snoozed until: "+JoH.dateTimeText(next_alert_at));
    save();
}
 
Example 16
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static void OtherAlert(Context context, String type, String title, String message, int notificatioId, String channelId, 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);
    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) {
                // ignore null pointer exception during delete as we emulate database records
            }
            Log.d(TAG, "Delete");
        }
        UserNotification.create(message, type, new Date().getTime() + reraiseSec * 1000);


        boolean localOnly =false;
        if (notificatioId == persistentHighAlertNotificationId) {
            localOnly = (Home.get_forced_wear() && bg_notifications_watch && bg_persistent_high_alert_enabled_watch);
        }
        Log.d(TAG,"OtherAlert forced_wear localOnly=" + localOnly);
        Intent intent = new Intent(context, Home.class);
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context, channelId)
                        .setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE)
                        .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setLocalOnly(localOnly)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                        .setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        if (addDeleteIntent) {
            Intent deleteIntent = new Intent(context, SnoozeOnNotificationDismissService.class);
            deleteIntent.putExtra("alertType", type);
            deleteIntent.putExtra("raisedTimeStamp", JoH.tsl());
            mBuilder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        }
        mBuilder.setVibrate(vibratePattern);
        mBuilder.setLights(0xff00ff00, 300, 1000);
        if (AlertPlayer.notSilencedDueToCall()) {
            if (otherAlertsOverrideSilent && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                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, XdripNotificationCompat.build(mBuilder));

        if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")
                && Pref.getBooleanDefaultFalse("pref_amazfit_other_alert_enable_key")) {
            Amazfitservice.start("xDrip_Otheralert", message, 30);
        }
    }
}
 
Example 17
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private void VibrateNotifyMakeNoise(Context context, AlertType alert, String bgValue, int minsFromStartPlaying) {
    Log.d(TAG, "VibrateNotifyMakeNoise called minsFromStartedPlaying = " + minsFromStartPlaying);
    Log.d("ALARM", "setting vibrate alarm");
    int profile = getAlertProfile(context);
    if (alert.uuid.equals(AlertType.LOW_ALERT_55)) {
        // boost alerts...
        if (profile == ALERT_PROFILE_VIBRATE_ONLY) {
            profile = ALERT_PROFILE_ASCENDING;
        }
    }

    // We use timeFromStartPlaying as a way to force vibrating/ non vibrating...
    if (profile != ALERT_PROFILE_ASCENDING) {
        // We start from the non ascending part...
        minsFromStartPlaying = MAX_ASCENDING_MINUTES;
    }
    final String highlow = (alert.above ? context.getString(R.string.high) : context.getString(R.string.low)).toUpperCase();
    String title = bgValue + " " + alert.name;
    String content = "BG " + highlow + " ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    final Intent intent = new Intent(context, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && PersistentStore.getBoolean("bg_notifications_watch"));
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, NotificationChannels.BG_ALERT_CHANNEL)//KS Notification
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
            .setContentTitle(title)
            .setContentText(content)
            //.addAction(R.drawable.ic_action_communication_invert_colors_on, "SNOOZE", notificationIntent(context, intent))
            .setContentIntent(notificationIntent(context, intent))
            .setLocalOnly(localOnly)
            .setGroup("xDrip level alert")
            .setPriority(Pref.getBooleanDefaultFalse("high_priority_notifications") ? Notification.PRIORITY_MAX : Notification.PRIORITY_HIGH)
            .setDeleteIntent(snoozeIntent(context, minsFromStartPlaying));

    if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) {
        if (minsFromStartPlaying >= MAX_VIBRATING_MINUTES) {
            // Before this, we only vibrate...
            float volumeFrac = (float) (minsFromStartPlaying - MAX_VIBRATING_MINUTES) / (MAX_ASCENDING_MINUTES - MAX_VIBRATING_MINUTES);
            volumeFrac = Math.min(volumeFrac, 1);
            if (profile == ALERT_PROFILE_MEDIUM) {
                volumeFrac = (float) 0.7;
            }
            Log.d(TAG, "VibrateNotifyMakeNoise volumeFrac = " + volumeFrac);
            boolean overrideSilent = alert.override_silent_mode;
            boolean forceSpeaker = alert.force_speaker;
            if (notSilencedDueToCall()) {
                if (overrideSilent || isLoudPhone(context)) {
                    playFile(context, alert.mp3_file, volumeFrac, forceSpeaker, overrideSilent);
                }
            } else {
                Log.i(TAG, "Silenced Alert Noise due to ongoing call");
            }
        }
    }
    if (profile != ALERT_PROFILE_SILENT && alert.vibrate) {
        if (notSilencedDueToCall()) {
            builder.setVibrate(Notifications.vibratePattern);
        } else {
            Log.i(TAG, "Vibration silenced due to ongoing call");
        }
    } else {
        // In order to still show on all android wear watches, either a sound or a vibrate pattern
        // seems to be needed. This pattern basically does not vibrate:
        builder.setVibrate(new long[]{1, 0});
    }
    Log.ueh("Alerting", content);
    final NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, XdripNotificationCompat.build(builder));

    // send to bluejay
    BlueJayEntry.sendAlertIfEnabled((alert.above ? "High" : "Low") + " Alert " + bgValue + " " + alert.name); // string text is used to determine alert type

    // send alert to pebble
    if (Pref.getBooleanDefaultFalse("broadcast_to_pebble") && (Pref.getBooleanDefaultFalse("pebble_vibe_alerts"))) {
        if (JoH.ratelimit("pebble_vibe_start", 59)) {
            JoH.startService(PebbleWatchSync.class);
        }
    }

    //send alert to amazfit
    if (Pref.getBooleanDefaultFalse("pref_amazfit_enable_key")
            && Pref.getBooleanDefaultFalse("pref_amazfit_BG_alert_enable_key")) {
        Amazfitservice.start("xDrip_Alarm", alert.name, alert.default_snooze);
    }

    if (LeFunEntry.areAlertsEnabled() && ActiveBgAlert.currentlyAlerting()) {
        LeFun.sendAlert(highlow, bgValue);
    }

    if (MiBandEntry.areAlertsEnabled() && ActiveBgAlert.currentlyAlerting()) {
        MiBand.sendAlert(alert.name, highlow + " " + bgValue, alert.default_snooze);
    }

    // speak alert
    if (Pref.getBooleanDefaultFalse("speak_alerts")) {
        SpeechUtil.say(highlow + ", " + bgValue, 3000);
    }
}
 
Example 18
Source File: Notifications.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
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);
    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) {
                // ignore null pointer exception during delete as we emulate database records
            }
            Log.d(TAG, "Delete");
        }
        UserNotification.create(message, type, new Date().getTime() + reraiseSec * 1000);


        boolean localOnly =false;//KS
        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(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
                        .setContentTitle(message)
                        .setContentText(message)
                        .setLocalOnly(localOnly)//KS
                        .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());
    }
}
 
Example 19
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private void VibrateAudio(Context ctx, AlertType alert, String bgValue, Boolean overrideSilent, int timeFromStartPlaying) {
    Log.d(TAG, "Vibrate called timeFromStartPlaying = " + timeFromStartPlaying);
    Log.d("ALARM", "setting vibrate alarm");
    int profile = getAlertProfile(ctx);
    if(alert.uuid.equals(AlertType.LOW_ALERT_55)) {
        // boost alerts...
        if(profile == ALERT_PROFILE_VIBRATE_ONLY) {
            profile = ALERT_PROFILE_ASCENDING;
        }
    }

    // We use timeFromStartPlaying as a way to force vibrating/ non vibrating...
    if (profile != ALERT_PROFILE_ASCENDING) {
        // We start from the non ascending part...
        timeFromStartPlaying = MAX_ASCENDING;
    }

    String title = bgValue + " " + alert.name;
    String content = "BG LEVEL ALERT: " + bgValue + "  (@" + JoH.hourMinuteString() + ")";
    Intent intent = new Intent(ctx, SnoozeActivity.class);

    boolean localOnly = (Home.get_forced_wear() && Pref.getBooleanDefaultFalse("bg_notifications"));//KS
    Log.d(TAG, "NotificationCompat.Builder localOnly=" + localOnly);
    NotificationCompat.Builder  builder = new NotificationCompat.Builder(ctx)//KS Notification
        .setSmallIcon(R.drawable.ic_launcher)//KS ic_action_communication_invert_colors_on
        .setContentTitle(title)
        .setContentText(content)
        .setContentIntent(notificationIntent(ctx, intent))
        .setLocalOnly(localOnly)//KS
        .setDeleteIntent(snoozeIntent(ctx));

    if (profile != ALERT_PROFILE_VIBRATE_ONLY && profile != ALERT_PROFILE_SILENT) {
        if (timeFromStartPlaying >= MAX_VIBRATING) {
            // Before this, we only vibrate...
            float volumeFrac = (float)(timeFromStartPlaying - MAX_VIBRATING) / (MAX_ASCENDING - MAX_VIBRATING);
            volumeFrac = Math.min(volumeFrac, 1);
            if(profile == ALERT_PROFILE_MEDIUM) {
                volumeFrac = (float)0.7;
            }
            Log.d(TAG, "Vibrate volumeFrac = " + volumeFrac);
            boolean isRingTone = true;//KS TODO EditAlertActivity.isPathRingtone(ctx, alert.mp3_file);

            if (notSilencedDueToCall()) {
                if (isRingTone && !overrideSilent) {
                    builder.setSound(Uri.parse(alert.mp3_file));
                } else {
                    if (overrideSilent || isLoudPhone(ctx)) {
                        PlayFile(ctx, alert.mp3_file, volumeFrac);
                    }
                }
            } else {
                Log.i(TAG,"Silenced Alert Noise due to ongoing call");
            }
        }
    }
    if (profile != ALERT_PROFILE_SILENT && alert.vibrate) {
        if (notSilencedDueToCall()) {
            builder.setVibrate(Notifications.vibratePattern);
        } else {
            Log.i(TAG, "Vibration silenced due to ongoing call");
        }
    } else {
        // In order to still show on all android wear watches, either a sound or a vibrate pattern
        // seems to be needed. This pattern basically does not vibrate:
        //KS ADD:
        // This code snippet will cause the phone to vibrate "SOS" in Morse Code
        // In Morse Code, "s" = "dot-dot-dot", "o" = "dash-dash-dash"
        // There are pauses to separate dots/dashes, letters, and words
        // The following numbers represent millisecond lengths
        int dot = 200;      // Length of a Morse Code "dot" in milliseconds
        int dash = 500;     // Length of a Morse Code "dash" in milliseconds
        int short_gap = 200;    // Length of Gap Between dots/dashes
        int medium_gap = 500;   // Length of Gap Between Letters
        int long_gap = 1000;    // Length of Gap Between Words
        long[] pattern = {
                0,  // Start immediately
                dot, short_gap, dot, short_gap, dot,    // s
                medium_gap,
                dash, short_gap, dash, short_gap, dash, // o
                medium_gap,
                dot, short_gap, dot, short_gap, dot,    // s
                long_gap
        };
        // Only perform this pattern one time (-1 means "do not repeat")
        //mVibrator.vibrate(pattern, -1);
        builder.setVibrate(pattern);
        //builder.setVibrate(new long[]{1, 0});
    }
    Log.ueh("Alerting",content);
    NotificationManager mNotifyMgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(Notifications.exportAlertNotificationId); // this appears to confuse android wear version 2.0.0.141773014.gms even though it shouldn't - can we survive without this?
    mNotifyMgr.notify(Notifications.exportAlertNotificationId, builder.build());

    /* //KS not used on watch
    if (Pref.getBooleanDefaultFalse("broadcast_to_pebble") && (Pref.getBooleanDefaultFalse("pebble_vibe_alerts"))) {
        if (JoH.ratelimit("pebble_vibe_start", 59)) {
            ctx.startService(new Intent(ctx, PebbleWatchSync.class));
        }
    }*/
}
 
Example 20
Source File: ActiveBgAlert.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public void snooze(int minutes) {
    next_alert_at = new Date().getTime() + minutes * 60000;
    is_snoozed = true;
    Log.ueh("Snoozed Alert","Snoozed until: "+JoH.dateTimeText(next_alert_at));
    save();
}