use of com.wdullaer.materialdatetimepicker.time.Timepoint in project MaterialDateTimePicker by wdullaer.
the class TimePickerFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.timepicker_layout, container, false);
// Find our View instances
timeTextView = view.findViewById(R.id.time_textview);
Button timeButton = view.findViewById(R.id.time_button);
mode24Hours = view.findViewById(R.id.mode_24_hours);
modeDarkTime = view.findViewById(R.id.mode_dark_time);
modeCustomAccentTime = view.findViewById(R.id.mode_custom_accent_time);
vibrateTime = view.findViewById(R.id.vibrate_time);
dismissTime = view.findViewById(R.id.dismiss_time);
titleTime = view.findViewById(R.id.title_time);
enableSeconds = view.findViewById(R.id.enable_seconds);
limitSelectableTimes = view.findViewById(R.id.limit_times);
disableSpecificTimes = view.findViewById(R.id.disable_times);
showVersion2 = view.findViewById(R.id.show_version_2);
view.findViewById(R.id.original_button).setOnClickListener(view1 -> {
Calendar now = Calendar.getInstance();
new android.app.TimePickerDialog(getActivity(), (view11, hour, minute) -> Log.d("Original", "Got clicked"), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), mode24Hours.isChecked()).show();
});
// Show a timepicker when the timeButton is clicked
timeButton.setOnClickListener(v -> {
Calendar now = Calendar.getInstance();
/*
It is recommended to always create a new instance whenever you need to show a Dialog.
The sample app is reusing them because it is useful when looking for regressions
during testing
*/
if (tpd == null) {
tpd = TimePickerDialog.newInstance(TimePickerFragment.this, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), mode24Hours.isChecked());
} else {
tpd.initialize(TimePickerFragment.this, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND), mode24Hours.isChecked());
}
tpd.setThemeDark(modeDarkTime.isChecked());
tpd.vibrate(vibrateTime.isChecked());
tpd.dismissOnPause(dismissTime.isChecked());
tpd.enableSeconds(enableSeconds.isChecked());
tpd.setVersion(showVersion2.isChecked() ? TimePickerDialog.Version.VERSION_2 : TimePickerDialog.Version.VERSION_1);
if (modeCustomAccentTime.isChecked()) {
tpd.setAccentColor(Color.parseColor("#9C27B0"));
}
if (titleTime.isChecked()) {
tpd.setTitle("TimePicker Title");
}
if (limitSelectableTimes.isChecked()) {
if (enableSeconds.isChecked()) {
tpd.setTimeInterval(3, 5, 10);
} else {
tpd.setTimeInterval(3, 5, 60);
}
}
if (disableSpecificTimes.isChecked()) {
Timepoint[] disabledTimes = { new Timepoint(10), new Timepoint(10, 30), new Timepoint(11), new Timepoint(12, 30) };
tpd.setDisabledTimes(disabledTimes);
}
tpd.setOnCancelListener(dialogInterface -> {
Log.d("TimePicker", "Dialog was cancelled");
tpd = null;
});
tpd.show(requireFragmentManager(), "Timepickerdialog");
});
return view;
}
Aggregations