1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package com.android.tv.quicksettings; 15 16 import android.content.SharedPreferences; 17 18 public class Setting { 19 20 static final int TYPE_UNKNOWN = 0; 21 static final int TYPE_INT = 1; 22 static final int TYPE_STRING = 2; 23 24 private String mTitle; 25 private String mKey; 26 private int mSettingType; 27 28 private int mMaxValue; 29 30 private final SharedPreferences mSharedPreferences; 31 32 public Setting(String title) { 33 mTitle = title; 34 mSettingType = TYPE_UNKNOWN; 35 mSharedPreferences = null; 36 } 37 38 public Setting(SharedPreferences sharedPreferences, String key, String title, int max) { 39 mSharedPreferences = sharedPreferences; 40 mTitle = title; 41 mKey = key; 42 mMaxValue = max; 43 mSettingType = TYPE_INT; 44 } 45 46 public Setting(SharedPreferences sharedPreferences, String key, String title) { 47 mSharedPreferences = sharedPreferences; 48 mTitle = title; 49 mKey = key; 50 mSettingType = TYPE_STRING; 51 } 52 53 public int getType() { 54 return mSettingType; 55 } 56 57 public String getTitle() { 58 return mTitle; 59 } 60 61 public void setTitle(String title) { 62 mTitle = title; 63 } 64 65 public String getKey() { 66 return mKey; 67 } 68 69 public int getMaxValue() { 70 return mMaxValue; 71 } 72 73 public int getIntValue() { 74 return mSharedPreferences.getInt(mKey, -1); 75 } 76 77 public String getStringValue() { 78 return mSharedPreferences.getString(mKey, ""); 79 } 80 81 public void setValue(int value) { 82 mSharedPreferences.edit().putInt(mKey, value).apply(); 83 mSettingType = TYPE_INT; 84 } 85 86 public void setValue(String value) { 87 mSharedPreferences.edit().putString(mKey, value).apply(); 88 mSettingType = TYPE_STRING; 89 } 90 } 91