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