Java Code Examples for com.eveningoutpost.dexdrip.Models.ActiveBgAlert#currentlyAlerting()

The following examples show how to use com.eveningoutpost.dexdrip.Models.ActiveBgAlert#currentlyAlerting() . 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: 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 2
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);
    }
}