Search in sources :

Example 1 with Timepoint

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;
}
Also used : Timepoint(com.wdullaer.materialdatetimepicker.time.Timepoint) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) LayoutInflater(android.view.LayoutInflater) TimePickerDialog(com.wdullaer.materialdatetimepicker.time.TimePickerDialog) ViewGroup(android.view.ViewGroup) Color(android.graphics.Color) TextView(android.widget.TextView) Calendar(java.util.Calendar) CheckBox(android.widget.CheckBox) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) Log(android.util.Log) Button(android.widget.Button) Calendar(java.util.Calendar) TextView(android.widget.TextView) View(android.view.View) Timepoint(com.wdullaer.materialdatetimepicker.time.Timepoint)

Aggregations

Color (android.graphics.Color)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 CheckBox (android.widget.CheckBox)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Fragment (androidx.fragment.app.Fragment)1 TimePickerDialog (com.wdullaer.materialdatetimepicker.time.TimePickerDialog)1 Timepoint (com.wdullaer.materialdatetimepicker.time.Timepoint)1 Calendar (java.util.Calendar)1