Home | History | Annotate | Download | only in quicksettings
      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.Intent;
     17 import android.net.Uri;
     18 import android.os.Parcel;
     19 import android.os.Parcelable;
     20 
     21 import java.util.ArrayList;
     22 import java.util.List;
     23 
     24 public class Setting implements Parcelable {
     25 
     26     static final int TYPE_UNKNOWN = 0;
     27     static final int TYPE_INT = 1;
     28     static final int TYPE_STRING = 2;
     29 
     30     private String mTitle;
     31     private int mIntValue;
     32     private String mStringValue;
     33     private int mSettingType;
     34 
     35     private int mMaxValue;
     36     private List<String> mStringChoices = new ArrayList<String>();
     37 
     38     public Setting() {
     39     }
     40 
     41     public Setting(String title) {
     42         mTitle = title;
     43         mSettingType = TYPE_UNKNOWN;
     44     }
     45 
     46     public Setting(String title, int value) {
     47         this(title, value, 0);
     48     }
     49 
     50     public Setting(String title, int value, int max) {
     51         this(title);
     52         mIntValue = value;
     53         mMaxValue = max;
     54         mSettingType = TYPE_INT;
     55     }
     56 
     57     public Setting(String title, String value) {
     58         this(title);
     59         mStringValue = value;
     60         mSettingType = TYPE_STRING;
     61     }
     62 
     63     public int getType() {
     64         return mSettingType;
     65     }
     66 
     67     public String getTitle() {
     68         return mTitle;
     69     }
     70 
     71     public void setTitle(String title) {
     72         mTitle = title;
     73     }
     74 
     75     public int getMaxValue() {
     76         return mMaxValue;
     77     }
     78 
     79     public void setMaxValue(int max) {
     80         mMaxValue = max;
     81         mSettingType = TYPE_INT;
     82     }
     83 
     84     public List<String> getStringChoices() {
     85         return mStringChoices;
     86     }
     87 
     88     public void setStringChoices(List<String> choices) {
     89         mStringChoices = choices;
     90         mSettingType = TYPE_STRING;
     91     }
     92 
     93     public void addStringChoice(String choice) {
     94         mStringChoices.add(choice);
     95     }
     96 
     97     public int getIntValue() {
     98         return mIntValue;
     99     }
    100 
    101     public String getStringValue() {
    102         return mStringValue;
    103     }
    104 
    105     public void setValue(int value) {
    106         mIntValue = value;
    107         mSettingType = TYPE_INT;
    108     }
    109 
    110     public void setValue(String value) {
    111         mStringValue = value;
    112         mSettingType = TYPE_STRING;
    113     }
    114 
    115     public static Parcelable.Creator<Setting> CREATOR = new Parcelable.Creator<Setting>() {
    116         @Override
    117         public Setting createFromParcel(Parcel source) {
    118             Setting setting = new Setting();
    119             setting.mTitle = source.readString();
    120             setting.mIntValue = source.readInt();
    121             setting.mStringValue = source.readString();
    122             setting.mSettingType = source.readInt();
    123             setting.mMaxValue = source.readInt();
    124             source.readStringList(setting.mStringChoices);
    125             return setting;
    126         }
    127 
    128         @Override
    129         public Setting[] newArray(int size) {
    130             return new Setting[size];
    131         }
    132     };
    133 
    134     @Override
    135     public int describeContents() {
    136         return 0;
    137     }
    138 
    139     @Override
    140     public void writeToParcel(Parcel dest, int flags) {
    141         dest.writeString(mTitle);
    142         dest.writeInt(mIntValue);
    143         dest.writeString(mStringValue);
    144         dest.writeInt(mSettingType);
    145         dest.writeInt(mMaxValue);
    146         dest.writeStringList(mStringChoices);
    147     }
    148 }
    149