• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Setting(String title)32     public Setting(String title) {
33         mTitle = title;
34         mSettingType = TYPE_UNKNOWN;
35         mSharedPreferences = null;
36     }
37 
Setting(SharedPreferences sharedPreferences, String key, String title, int max)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 
Setting(SharedPreferences sharedPreferences, String key, String title)46     public Setting(SharedPreferences sharedPreferences, String key, String title) {
47         mSharedPreferences = sharedPreferences;
48         mTitle = title;
49         mKey = key;
50         mSettingType = TYPE_STRING;
51     }
52 
getType()53     public int getType() {
54         return mSettingType;
55     }
56 
getTitle()57     public String getTitle() {
58         return mTitle;
59     }
60 
setTitle(String title)61     public void setTitle(String title) {
62         mTitle = title;
63     }
64 
getKey()65     public String getKey() {
66         return mKey;
67     }
68 
getMaxValue()69     public int getMaxValue() {
70         return mMaxValue;
71     }
72 
getIntValue()73     public int getIntValue() {
74         return mSharedPreferences.getInt(mKey, -1);
75     }
76 
getStringValue()77     public String getStringValue() {
78         return mSharedPreferences.getString(mKey, "");
79     }
80 
setValue(int value)81     public void setValue(int value) {
82         mSharedPreferences.edit().putInt(mKey, value).apply();
83         mSettingType = TYPE_INT;
84     }
85 
setValue(String value)86     public void setValue(String value) {
87         mSharedPreferences.edit().putString(mKey, value).apply();
88         mSettingType = TYPE_STRING;
89     }
90 }
91