1 /* 2 * Copyright (C) 2019 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.common.feature; 18 19 import android.content.Context; 20 21 import com.android.tv.common.dev.DeveloperPreference; 22 23 /** A {@link Feature} based on {@link DeveloperPreference<Boolean>}. */ 24 public class DeveloperPreferenceFeature implements Feature { 25 26 private final DeveloperPreference<Boolean> mPreference; 27 28 /** 29 * Create a developer preference feature. 30 * 31 * @param key the developer setting key. 32 * @param defaultValue the value to return if the setting is undefined or empty. 33 */ create(String key, boolean defaultValue)34 public static DeveloperPreferenceFeature create(String key, boolean defaultValue) { 35 return from(DeveloperPreference.create(key, defaultValue)); 36 } 37 38 /** 39 * Create a developer preference feature from an exiting {@link DeveloperPreference<Boolean>}. 40 */ from( DeveloperPreference<Boolean> developerPreference)41 public static DeveloperPreferenceFeature from( 42 DeveloperPreference<Boolean> developerPreference) { 43 return new DeveloperPreferenceFeature(developerPreference); 44 } 45 DeveloperPreferenceFeature(DeveloperPreference<Boolean> mPreference)46 private DeveloperPreferenceFeature(DeveloperPreference<Boolean> mPreference) { 47 this.mPreference = mPreference; 48 } 49 50 @Override isEnabled(Context context)51 public boolean isEnabled(Context context) { 52 return mPreference.get(context); 53 } 54 55 @Override toString()56 public String toString() { 57 return mPreference.toString(); 58 } 59 } 60