use of com.eveningoutpost.dexdrip.Models.ActiveBgAlert in project xDrip by NightscoutFoundation.
the class SnoozeActivity method setOnClickListenerOnDisableButton.
/**
* Functionality used at least three times moved to a function. Adds an onClickListener that will disable the identified alert<br>
* Depending on type of disable, also active alarms will be set to inactive<br>
* - if alert = "alerts_disabled_until" then the active bg alert will be deleted if any<br>
* - if alert = "low_alerts_disabled_until" and if active low bg alert exists then it will be deleted<br>
* - if alert = "high_alerts_disabled_until" and if active high bg alert exists then it will be deleted<br>
* @param button to which onclicklistener should be added
* @param alert identifies the alert, the text string used in the preferences ie alerts_disabled_until, low_alerts_disabled_until or high_alerts_disabled_until
*/
private void setOnClickListenerOnDisableButton(Button button, String alert) {
final String disableType = alert;
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Dialog d = new Dialog(SnoozeActivity.this);
d.setTitle(R.string.default_snooze);
d.setTitle(R.string.default_snooze);
d.setContentView(R.layout.snooze_picker);
Button b1 = (Button) d.findViewById(R.id.button1);
Button b2 = (Button) d.findViewById(R.id.button2);
final NumberPicker snoozeValue = (NumberPicker) d.findViewById(R.id.numberPicker1);
// don't use SetSnoozePickerValues because an additional value must be added
// adding place for "until you re-enable"
String[] values = new String[snoozeValues.length + 1];
for (int i = 0; i < values.length - 1; i++) values[i] = getNameFromTime(snoozeValues[i]);
values[values.length - 1] = getString(R.string.until_you_reenable);
snoozeValue.setMaxValue(values.length - 1);
snoozeValue.setMinValue(0);
snoozeValue.setDisplayedValues(values);
snoozeValue.setWrapSelectorWheel(false);
snoozeValue.setValue(getSnoozeLocatoin(60));
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Long disableUntil = new Date().getTime() + (snoozeValue.getValue() == snoozeValue.getMaxValue() ? infiniteSnoozeValueInMinutes : +(SnoozeActivity.getTimeFromSnoozeValue(snoozeValue.getValue()))) * 1000 * 60;
prefs.edit().putLong(disableType, disableUntil).apply();
// check if active bg alert exists and delete it depending on type of alert
ActiveBgAlert aba = ActiveBgAlert.getOnly();
if (aba != null) {
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
if (disableType.equalsIgnoreCase("alerts_disabled_until") || (activeBgAlert.above && disableType.equalsIgnoreCase("high_alerts_disabled_until")) || (!activeBgAlert.above && disableType.equalsIgnoreCase("low_alerts_disabled_until"))) {
// active bg alert exists which is a type that is being disabled so let's remove it completely from the database
ActiveBgAlert.ClearData();
}
}
if (disableType.equalsIgnoreCase("alerts_disabled_until")) {
// disabling all , after the Snooze time set, all alarms will be re-enabled, inclusive low and high bg alarms
prefs.edit().putLong("high_alerts_disabled_until", 0).apply();
prefs.edit().putLong("low_alerts_disabled_until", 0).apply();
}
d.dismiss();
// also make sure the text in the Activity is changed
displayStatus();
showDisableEnableButtons();
recheckAlerts();
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
d.dismiss();
showDisableEnableButtons();
}
});
d.show();
}
});
}
use of com.eveningoutpost.dexdrip.Models.ActiveBgAlert in project xDrip by NightscoutFoundation.
the class SnoozeActivity method displayStatus.
void displayStatus() {
ActiveBgAlert aba = ActiveBgAlert.getOnly();
AlertType activeBgAlert = ActiveBgAlert.alertTypegetOnly();
// aba and activeBgAlert should both either exist ot not exist. all other cases are a bug in another place
if (aba == null && activeBgAlert != null) {
Log.wtf(TAG, "ERRRO displayStatus: aba == null, but activeBgAlert != null exiting...");
return;
}
if (aba != null && activeBgAlert == null) {
Log.wtf(TAG, "ERRRO displayStatus: aba != null, but activeBgAlert == null exiting...");
return;
}
long now = new Date().getTime();
if (activeBgAlert == null) {
sendRemoteSnooze.setVisibility(Pref.getBooleanDefaultFalse("send_snooze_to_remote") ? View.VISIBLE : View.GONE);
if (prefs.getLong("alerts_disabled_until", 0) > now || (prefs.getLong("low_alerts_disabled_until", 0) > now && prefs.getLong("high_alerts_disabled_until", 0) > now)) {
// not useful to show now that there's no active alert because either all alerts are disabled or high and low alerts are disabled
// there can not be any active alert
status = "";
} else {
status = getString(R.string.no_active_alert_exists);
}
buttonSnooze.setVisibility(View.GONE);
snoozeValue.setVisibility(View.GONE);
} else {
sendRemoteSnooze.setVisibility(View.GONE);
if (!aba.ready_to_alarm()) {
status = "Active alert exists named \"" + activeBgAlert.name + (aba.is_snoozed ? "\" Alert snoozed until " : "\" Alert will rerise at ") + DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(aba.next_alert_at)) + " (" + (aba.next_alert_at - now) / 60000 + " minutes left)";
} else {
status = getString(R.string.active_alert_exists_named) + " \"" + activeBgAlert.name + "\" " + getString(R.string.bracket_not_snoozed);
}
SetSnoozePickerValues(snoozeValue, activeBgAlert.above, activeBgAlert.default_snooze);
}
// check if there are disabled alerts and if yes add warning
if (prefs.getLong("alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("alerts_disabled_until", 0)));
status = getString(R.string.all_alerts_disabled_until) + textToAdd;
} else {
if (prefs.getLong("low_alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("low_alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if low alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("low_alerts_disabled_until", 0)));
status += "\n\n" + getString(R.string.low_alerts_disabled_until) + textToAdd;
}
if (prefs.getLong("high_alerts_disabled_until", 0) > now) {
String textToAdd = (prefs.getLong("high_alerts_disabled_until", 0) > now + (infiniteSnoozeValueInMinutes - 365 * 24 * 60) * 60 * 1000) ? // if high alerts would have been disabled "until you re-enable", and this test is done less than 365 * 24 * 60 minutes later, then this test will give true
"you re-enable" : DateFormat.getTimeInstance(DateFormat.MEDIUM).format(new Date(prefs.getLong("high_alerts_disabled_until", 0)));
status += "\n\n" + getString(R.string.high_alerts_disabled_until) + textToAdd;
}
}
alertStatus.setText(status);
}
use of com.eveningoutpost.dexdrip.Models.ActiveBgAlert in project xDrip by NightscoutFoundation.
the class AlertPlayer method Snooze.
public synchronized void Snooze(Context ctx, int repeatTime, boolean from_interactive) {
Log.i(TAG, "Snooze called repeatTime = " + repeatTime);
stopAlert(ctx, false, false);
ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
if (activeBgAlert == null) {
Log.e(TAG, "Error, snooze was called but no alert is active.");
// KS TODO if (from_interactive) GcmActivity.sendSnoozeToRemote();
return;
}
if (repeatTime == -1) {
// try to work out default
AlertType alert = ActiveBgAlert.alertTypegetOnly();
if (alert != null) {
repeatTime = alert.default_snooze;
Log.d(TAG, "Selecting default snooze time: " + repeatTime);
} else {
// pick a number if we cannot even find the default
repeatTime = 30;
Log.e(TAG, "Cannot even find default snooze time so going with: " + repeatTime);
}
}
activeBgAlert.snooze(repeatTime);
// KS if (from_interactive) GcmActivity.sendSnoozeToRemote();
}
use of com.eveningoutpost.dexdrip.Models.ActiveBgAlert in project xDrip by NightscoutFoundation.
the class Notifications method calcuatleArmTimeBg.
// This is the absolute time, not time from now.
private long calcuatleArmTimeBg(long now) {
Long wakeTimeBg = Long.MAX_VALUE;
ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
if (activeBgAlert != null) {
AlertType alert = AlertType.get_alert(activeBgAlert.alert_uuid);
if (alert != null) {
wakeTimeBg = activeBgAlert.next_alert_at;
Log.d(TAG, "ArmTimer BG alert -waking at: " + new Date(wakeTimeBg) + " in " + (wakeTimeBg - now) / 60000d + " minutes");
if (wakeTimeBg < now) {
// next alert should be at least one minute from now.
wakeTimeBg = now + 60000;
Log.w(TAG, "setting next alert to 1 minute from now (no problem right now, but needs a fix someplace else)");
}
}
}
Log.d("Notifications", "calcuatleArmTimeBg returning: " + new Date(wakeTimeBg) + " in " + (wakeTimeBg - now) / 60000d + " minutes");
return wakeTimeBg;
}
use of com.eveningoutpost.dexdrip.Models.ActiveBgAlert in project xDrip by NightscoutFoundation.
the class Home method onKeyDown.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(event.getKeyCode()) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_VOLUME_MUTE:
if (JoH.quietratelimit("button-press", 5)) {
if (Pref.getBooleanDefaultFalse("buttons_silence_alert")) {
final ActiveBgAlert activeBgAlert = ActiveBgAlert.getOnly();
if (activeBgAlert != null) {
AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1);
final String msg = "Snoozing alert due to volume button press";
JoH.static_toast_long(msg);
UserError.Log.ueh(TAG, msg);
} else {
if (d)
UserError.Log.d(TAG, "no active alert to snooze");
}
} else {
if (d)
UserError.Log.d(TAG, "No action as preference is disabled");
}
}
break;
}
if (d)
Log.d(TAG, "Keydown event: " + keyCode + " event: " + event.toString());
return super.onKeyDown(keyCode, event);
}
Aggregations