package jp.gihyo.mitoma.android.s1201dialog.fragment;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import java.util.Calendar;

import jp.gihyo.mitoma.android.s1201dialog.R;

public class MyDialog07Fragment extends DialogFragment {
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Calendar calender = Calendar.getInstance();
        int hourNow = calender.get(Calendar.HOUR_OF_DAY);
        int minuteNow = calender.get(Calendar.MINUTE);
        Context context = requireActivity();
        TimePickerDialog dialog = new TimePickerDialog(context,new MyDialogListener(),hourNow,minuteNow,true);
        return dialog;
    }
    private class MyDialogListener implements TimePickerDialog.OnTimeSetListener {
        public void onTimeSet(TimePicker view, int hour, int minute) {
            EditText et = requireActivity().findViewById(R.id.etDialogData);
            String time = hour + ":" + minute;
            et.setText(time);
        }
    }
}
