1 /* 2 * Copyright (C) 2020 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.android.tv.settings.widget; 17 18 import android.content.Context; 19 import android.content.res.TypedArray; 20 import android.util.AttributeSet; 21 22 import androidx.preference.Preference; 23 24 import com.android.tv.settings.R; 25 26 /** Augmented preference for TvSettings **/ 27 public class TsPreference extends Preference { 28 private boolean mUpdatableFromGoogleSettings; 29 TsPreference(Context context, AttributeSet attrs)30 public TsPreference(Context context, AttributeSet attrs) { 31 super(context, attrs); 32 initStyleAttributes(attrs); 33 } 34 TsPreference(Context context)35 public TsPreference(Context context) { 36 super(context); 37 initStyleAttributes(null); 38 } 39 40 initStyleAttributes(AttributeSet attrs)41 private void initStyleAttributes(AttributeSet attrs) { 42 if (attrs != null) { 43 final TypedArray a = getContext().obtainStyledAttributes( 44 attrs, R.styleable.TsPreference); 45 for (int i = a.getIndexCount() - 1; i >= 0; i--) { 46 int attr = a.getIndex(i); 47 if (attr == R.styleable.TsPreference_updatableFromGoogleSettings) { 48 mUpdatableFromGoogleSettings = a.getBoolean(attr, false); 49 break; 50 } 51 } 52 } 53 } 54 setUpdatableFromGoogleSettings(boolean updatableFromGoogleSettings)55 public void setUpdatableFromGoogleSettings(boolean updatableFromGoogleSettings) { 56 mUpdatableFromGoogleSettings = updatableFromGoogleSettings; 57 } 58 updatableFromGoogleSettings()59 public boolean updatableFromGoogleSettings() { 60 return mUpdatableFromGoogleSettings; 61 } 62 } 63