1 /*
2  * Copyright (C) 2017 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 
17 package com.android.tv.settings.system;
18 
19 import android.content.Context;
20 import android.content.res.TypedArray;
21 import android.util.AttributeSet;
22 
23 import androidx.core.content.res.TypedArrayUtils;
24 import androidx.preference.DialogPreference;
25 
26 import com.android.tv.settings.R;
27 
28 
29 /**
30  * A {@link DialogPreference} used inside {@link DateTimeFragment} for setting date or time. When
31  * clicked, this preference opens a dialog enabling the user to set the date or time.
32  */
33 public class LeanbackPickerDialogPreference extends DialogPreference {
34 
35     // the picker preference type: can be either 'date' or 'time'
36     private final String mPreferenceType;
37 
LeanbackPickerDialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)38     public LeanbackPickerDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
39                               int defStyleRes) {
40         super(context, attrs, defStyleAttr, defStyleRes);
41         final TypedArray a = context.obtainStyledAttributes(attrs,
42                 R.styleable.LeanbackPickerDialogPreference, 0, 0);
43         mPreferenceType = a.getString(R.styleable.LeanbackPickerDialogPreference_pickerType);
44 
45         a.recycle();
46     }
47 
LeanbackPickerDialogPreference(Context context, AttributeSet attrs, int defStyleAttr)48     public LeanbackPickerDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
49         this(context, attrs, defStyleAttr, 0);
50     }
51 
LeanbackPickerDialogPreference(Context context, AttributeSet attrs)52     public LeanbackPickerDialogPreference(Context context, AttributeSet attrs) {
53         this(context, attrs, TypedArrayUtils.getAttr(context, R.attr.dialogPreferenceStyle,
54                 android.R.attr.dialogPreferenceStyle));
55     }
56 
LeanbackPickerDialogPreference(Context context)57     public LeanbackPickerDialogPreference(Context context) {
58         this(context, null);
59     }
60 
getType()61     public String getType() {
62         return mPreferenceType;
63     }
64 }
65