• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16 package com.google.android.car.kitchensink.setting;
17 
18 import android.app.Dialog;
19 import android.app.DialogFragment;
20 import android.app.TimePickerDialog;
21 import android.os.Bundle;
22 import android.widget.TimePicker;
23 
24 public class TimePickerDialogFragment extends DialogFragment implements
25         TimePickerDialog.OnTimeSetListener {
26     private static final String HOUR_KEY = "hour";
27     private static final String MINUTE_KEY = "minute";
28 
29     private TimePickerDialog.OnTimeSetListener mListener;
30 
newInstance(int hourOfDay, int minute)31     public static TimePickerDialogFragment newInstance(int hourOfDay, int minute) {
32         TimePickerDialogFragment frag = new TimePickerDialogFragment();
33         Bundle args = new Bundle();
34         args.putInt(HOUR_KEY, hourOfDay);
35         args.putInt(MINUTE_KEY, minute);
36         frag.setArguments(args);
37 
38         return frag;
39     }
40 
setTimeSetListener(TimePickerDialog.OnTimeSetListener listener)41     public void setTimeSetListener(TimePickerDialog.OnTimeSetListener listener) {
42         mListener = listener;
43     }
44 
45     @Override
onCreateDialog(Bundle savedInstanceState)46     public Dialog onCreateDialog(Bundle savedInstanceState) {
47         Bundle args = getArguments();
48         int hour = args.getInt(HOUR_KEY);
49         int minute = args.getInt(MINUTE_KEY);
50         return new TimePickerDialog(getContext(), this, hour, minute, true);
51     }
52 
53     @Override
onTimeSet(TimePicker view, int hourOfDay, int minute)54     public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
55         if (mListener != null) {
56             mListener.onTimeSet(view, hourOfDay, minute);
57         }
58     }
59 }