Search in sources :

Example 56 with TimePickerDialog

use of android.app.TimePickerDialog in project xDrip-plus by jamorham.

the class EditAlertActivity method addListenerOnButtons.

public void addListenerOnButtons() {
    buttonSave.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // Check that values are ok.
            double threshold = parseDouble(alertThreshold.getText().toString());
            if (Double.isNaN(threshold))
                return;
            threshold = unitsConvertFromDisp(threshold);
            int alertReraise = 1;
            Integer alterReraiseInt = parseInt(reraise.getText().toString());
            if (alterReraiseInt == null)
                return;
            alertReraise = alterReraiseInt;
            int defaultSnooze = safeGetDefaultSnooze();
            if (alertReraise < 1) {
                Toast.makeText(getApplicationContext(), "Reraise Value must be 1 minute or greater", Toast.LENGTH_LONG).show();
                return;
            } else if (alertReraise >= defaultSnooze) {
                Toast.makeText(getApplicationContext(), "Reraise Value must be less than snooze length", Toast.LENGTH_LONG).show();
                return;
            }
            int timeStart = AlertType.toTime(startHour, startMinute);
            int timeEnd = AlertType.toTime(endHour, endMinute);
            boolean allDay = checkboxAllDay.isChecked();
            // if 23:59 was set, we increase it to 24:00
            if (timeStart == AlertType.toTime(23, 59)) {
                timeStart++;
            }
            if (timeEnd == AlertType.toTime(23, 59)) {
                timeEnd++;
            }
            if (timeStart == AlertType.toTime(0, 0) && timeEnd == AlertType.toTime(24, 0)) {
                allDay = true;
            }
            if (timeStart == timeEnd && (allDay == false)) {
                Toast.makeText(getApplicationContext(), "start time and end time of alert can not be equal", Toast.LENGTH_LONG).show();
                return;
            }
            boolean disabled = checkboxDisabled.isChecked();
            if (!disabled && !verifyThreshold(threshold, allDay, timeStart, timeEnd)) {
                return;
            }
            boolean vibrate = checkboxVibrate.isChecked();
            boolean overrideSilentMode = checkboxAlertOverride.isChecked();
            String mp3_file = audioPath;
            if (uuid != null) {
                AlertType.update_alert(uuid, alertText.getText().toString(), above, threshold, allDay, alertReraise, mp3_file, timeStart, timeEnd, overrideSilentMode, defaultSnooze, vibrate, !disabled);
            } else {
                AlertType.add_alert(null, alertText.getText().toString(), above, threshold, allDay, alertReraise, mp3_file, timeStart, timeEnd, overrideSilentMode, defaultSnooze, vibrate, !disabled);
            }
            startWatchUpdaterService(mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, TAG);
            Intent returnIntent = new Intent();
            setResult(RESULT_OK, returnIntent);
            finish();
        }
    });
    buttonRemove.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (uuid == null) {
                Log.wtf(TAG, "Error remove pressed, while we were adding an alert");
            } else {
                AlertType.remove_alert(uuid);
                startWatchUpdaterService(mContext, WatchUpdaterService.ACTION_SYNC_ALERTTYPE, TAG);
            }
            Intent returnIntent = new Intent();
            setResult(RESULT_OK, returnIntent);
            finish();
        }
    });
    buttonTest.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            testAlert();
        }
    });
    buttonalertMp3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle("What type of Alert?").setItems(R.array.alertType, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    if (which == 0) {
                        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select tone for Alerts:");
                        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
                        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
                        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALL);
                        startActivityForResult(intent, 999);
                    } else if (which == 1) {
                        if (checkPermissions()) {
                            chooseFile();
                        }
                    } else {
                        // Xdrip default was chossen, we live the file name as empty.
                        audioPath = "";
                        alertMp3File.setText(shortPath(audioPath));
                    }
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
    // - See more at: http://blog.kerul.net/2011/12/pick-file-using-intentactiongetcontent.html#sthash.c8xtIr1Y.dpuf
    checkboxAllDay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllDayControls();
        }
    });
    checkboxDisabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            setDisabledView();
        }
    });
    checkboxAlertOverride.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableVibrateControls();
        }
    });
    // Register Liseners to modify start and end time
    View.OnClickListener startTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    startHour = selectedHour;
                    startMinute = selectedMinute;
                    setTimeRanges();
                }
            }, startHour, startMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select Time");
            mTimePicker.show();
        }
    };
    View.OnClickListener endTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    endHour = selectedHour;
                    endMinute = selectedMinute;
                    setTimeRanges();
                }
            }, endHour, endMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select Time");
            mTimePicker.show();
        }
    };
    viewTimeStart.setOnClickListener(startTimeListener);
    timeInstructionsStart.setOnClickListener(startTimeListener);
    viewTimeEnd.setOnClickListener(endTimeListener);
    timeInstructionsEnd.setOnClickListener(endTimeListener);
}
Also used : AlertDialog(android.app.AlertDialog) TimePicker(android.widget.TimePicker) DialogInterface(android.content.DialogInterface) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder) Intent(android.content.Intent) TimePickerDialog(android.app.TimePickerDialog) View(android.view.View) TextView(android.widget.TextView) Paint(android.graphics.Paint) CompoundButton(android.widget.CompoundButton)

Example 57 with TimePickerDialog

use of android.app.TimePickerDialog in project xDrip-plus by jamorham.

the class MissedReadingActivity method addListenerOnButtons.

public void addListenerOnButtons() {
    checkboxAllDay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    checkboxEnableAlert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    checkboxEnableReraise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    View.OnClickListener startTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    startHour = selectedHour;
                    startMinute = selectedMinute;
                    setTimeRanges();
                }
            }, startHour, startMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select start time");
            mTimePicker.show();
        }
    };
    View.OnClickListener endTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    endHour = selectedHour;
                    endMinute = selectedMinute;
                    setTimeRanges();
                }
            }, endHour, endMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select end time");
            mTimePicker.show();
        }
    };
    viewTimeStart.setOnClickListener(startTimeListener);
    timeInstructionsStart.setOnClickListener(startTimeListener);
    viewTimeEnd.setOnClickListener(endTimeListener);
    timeInstructionsEnd.setOnClickListener(endTimeListener);
}
Also used : TimePicker(android.widget.TimePicker) TimePickerDialog(android.app.TimePickerDialog) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Example 58 with TimePickerDialog

use of android.app.TimePickerDialog in project collect by opendatakit.

the class CustomTimePickerDialog method onResume.

@Override
public void onResume() {
    super.onResume();
    // Needed because the TimePickerDialog doesn't pick up theme colors properly for some reason
    TimePickerDialog dialog = (TimePickerDialog) getDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(new ThemeUtils(getContext()).getColorPrimary());
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(new ThemeUtils(getContext()).getColorPrimary());
}
Also used : ThemeUtils(org.odk.collect.android.utilities.ThemeUtils) TimePickerDialog(android.app.TimePickerDialog)

Example 59 with TimePickerDialog

use of android.app.TimePickerDialog in project collect by opendatakit.

the class CustomTimePickerDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    TimePickerDialog dialog = new TimePickerDialog(requireContext(), viewModel.getDialogTheme(), viewModel.getTimeSetListener(), viewModel.getLocalDateTime().getHourOfDay(), viewModel.getLocalDateTime().getMinuteOfHour(), DateFormat.is24HourFormat(requireContext()));
    dialog.setTitle(requireContext().getString(R.string.select_time));
    fixSpinner(requireContext(), dialog, viewModel.getLocalDateTime().getHourOfDay(), viewModel.getLocalDateTime().getMinuteOfHour(), DateFormat.is24HourFormat(requireContext()));
    return dialog;
}
Also used : TimePickerDialog(android.app.TimePickerDialog) NonNull(androidx.annotation.NonNull)

Example 60 with TimePickerDialog

use of android.app.TimePickerDialog in project Ruisi by freedom10086.

the class ThemeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_theme);
    if (savedInstanceState != null) {
        currentSelect = savedInstanceState.getInt("position", 0);
    }
    initToolBar(true, "主题设置");
    addToolbarMenu(R.drawable.ic_done_black_24dp).setOnClickListener(v -> {
        boolean isChange = false;
        int curr = AppCompatDelegate.getDefaultNightMode();
        int to = curr;
        if (App.getCustomTheme(this) != themeIds[currentSelect]) {
            App.setCustomTheme(this, themeIds[currentSelect]);
            isChange = true;
            if (themeIds[currentSelect] == THEME_NIGHT) {
                to = AppCompatDelegate.MODE_NIGHT_YES;
            } else {
                to = AppCompatDelegate.MODE_NIGHT_NO;
            }
        }
        if (themeIds[currentSelect] != THEME_NIGHT) {
            // 黑主题 自动主题无效
            if (App.isAutoDarkMode(this)) {
                int[] time = App.getDarkModeTime(this);
                int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                if ((hour >= time[0] || hour < time[1])) {
                    // 自动切换
                    to = AppCompatDelegate.MODE_NIGHT_YES;
                } else {
                    to = AppCompatDelegate.MODE_NIGHT_NO;
                }
            } else {
                to = AppCompatDelegate.MODE_NIGHT_NO;
            }
        }
        if (curr != to) {
            AppCompatDelegate.setDefaultNightMode(to);
            isChange = true;
        }
        if (isChange) {
            showToast("已更改主题");
            setResult(RESULT_OK);
        }
        finish();
    });
    GridView gridView = findViewById(R.id.commons_colors);
    adapter = new ColorAdapter();
    gridView.setAdapter(adapter);
    gridView.setOnItemClickListener(this);
    auto = findViewById(R.id.auto_dark_mode);
    boolean isAuto = App.isAutoDarkMode(this);
    auto.setChecked(isAuto);
    startView = findViewById(R.id.start_time);
    endView = findViewById(R.id.end_time);
    nightViews = findViewById(R.id.night_views);
    startText = findViewById(R.id.start_time_text);
    endText = findViewById(R.id.end_time_text);
    currentTheme = App.getCustomTheme(this);
    currentSelect = getSelect();
    if (currentSelect == THEME_NIGHT) {
        nightViews.setVisibility(View.GONE);
    } else {
        nightViews.setVisibility(View.VISIBLE);
    }
    startText.setText(App.getDarkModeTime(this)[0] + ":00");
    endText.setText(App.getDarkModeTime(this)[1] + ":00");
    auto.setOnCheckedChangeListener((buttonView, isChecked) -> {
        App.setAutoDarkMode(this, isChecked);
    });
    startView.setOnClickListener(v -> {
        new TimePickerDialog(this, (view, hourOfDay, minute) -> {
            startText.setText(hourOfDay + ":00");
            App.setDarkModeTime(this, true, hourOfDay);
            Log.d("==", hourOfDay + "");
        }, App.getDarkModeTime(this)[0], 0, true).show();
    });
    endView.setOnClickListener(v -> {
        new TimePickerDialog(this, (view, hourOfDay, minute) -> {
            endText.setText(hourOfDay + ":00");
            Log.d("==", hourOfDay + "");
            App.setDarkModeTime(this, false, hourOfDay);
        }, App.getDarkModeTime(this)[1], 0, true).show();
    });
}
Also used : TimePickerDialog(android.app.TimePickerDialog) Bundle(android.os.Bundle) GridView(android.widget.GridView) MyCircleView(me.yluo.ruisiapp.widget.MyCircleView) WindowManager(android.view.WindowManager) ColorDrawable(android.graphics.drawable.ColorDrawable) AppCompatDelegate(android.support.v7.app.AppCompatDelegate) ViewGroup(android.view.ViewGroup) R(me.yluo.ruisiapp.R) TextView(android.widget.TextView) Calendar(java.util.Calendar) BaseAdapter(android.widget.BaseAdapter) CheckBox(android.widget.CheckBox) View(android.view.View) AdapterView(android.widget.AdapterView) Build(android.os.Build) Window(android.view.Window) Log(android.util.Log) App(me.yluo.ruisiapp.App) TimePickerDialog(android.app.TimePickerDialog) GridView(android.widget.GridView)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)66 TimePicker (android.widget.TimePicker)30 Calendar (java.util.Calendar)26 View (android.view.View)23 TextView (android.widget.TextView)16 DatePickerDialog (android.app.DatePickerDialog)15 DialogInterface (android.content.DialogInterface)12 Context (android.content.Context)11 AlertDialog (android.app.AlertDialog)9 Button (android.widget.Button)8 CompoundButton (android.widget.CompoundButton)8 Bundle (android.os.Bundle)7 DatePicker (android.widget.DatePicker)6 LocalTime (java.time.LocalTime)6 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)5 Date (java.util.Date)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (android.support.annotation.Nullable)4 LinearLayout (android.widget.LinearLayout)4