Search in sources :

Example 31 with NumberPicker

use of android.widget.NumberPicker in project xDrip-plus by jamorham.

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 snoozeType = ALL_ALERTS then the active bg alert will be deleted if any<br>
 * - if snoozeType = LOW_ALERTS and if active low bg alert exists then it will be deleted<br>
 * - if snoozeType = HIGH_ALERTS and if active high bg alert exists then it will be deleted<br>
 * @param button to which onclicklistener should be added
 * @param snoozeType identifies the alert, an enum value of SnoozeType
 */
private void setOnClickListenerOnDisableButton(Button button, SnoozeType snoozeType) {
    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final Dialog d = new Dialog(SnoozeActivity.this);
            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(getSnoozeLocation(60));
            b1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    long minutes;
                    if (snoozeValue.getValue() == snoozeValue.getMaxValue()) {
                        minutes = infiniteSnoozeValueInMinutes;
                    } else {
                        minutes = SnoozeActivity.getTimeFromSnoozeValue(snoozeValue.getValue());
                    }
                    snoozeForType(minutes, snoozeType, prefs);
                    d.dismiss();
                    // also make sure the text in the Activity is changed
                    displayStatus();
                    showDisableEnableButtons();
                }
            });
            b2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    d.dismiss();
                    showDisableEnableButtons();
                }
            });
            d.show();
        }
    });
}
Also used : NumberPicker(android.widget.NumberPicker) Button(android.widget.Button) Dialog(android.app.Dialog) TextView(android.widget.TextView) View(android.view.View)

Example 32 with NumberPicker

use of android.widget.NumberPicker in project xDrip-plus by jamorham.

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();
        }
    });
}
Also used : AlertType(com.eveningoutpost.dexdrip.Models.AlertType) NumberPicker(android.widget.NumberPicker) Button(android.widget.Button) Dialog(android.app.Dialog) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) ActiveBgAlert(com.eveningoutpost.dexdrip.Models.ActiveBgAlert)

Aggregations

NumberPicker (android.widget.NumberPicker)32 View (android.view.View)19 TextView (android.widget.TextView)14 DialogInterface (android.content.DialogInterface)12 Dialog (android.app.Dialog)10 Button (android.widget.Button)10 AlertDialog (android.app.AlertDialog)8 LayoutInflater (android.view.LayoutInflater)6 Paint (android.graphics.Paint)5 NonNull (android.support.annotation.NonNull)5 AlertDialog (android.support.v7.app.AlertDialog)5 CompoundButton (android.widget.CompoundButton)5 FrameLayout (android.widget.FrameLayout)5 OnClick (butterknife.OnClick)5 TimePickerDialog (android.app.TimePickerDialog)4 ListView (android.widget.ListView)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 ImageView (android.widget.ImageView)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3