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);
}
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);
}
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());
}
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;
}
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();
});
}
Aggregations