• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
15 package android.support.v17.leanback.widget.picker;
16 
17 /**
18  * Picker column class used by {@link Picker}, defines a contiguous value ranges and associated
19  * labels.  A PickerColumn has a minValue and maxValue to choose between.  The Picker column has
20  * a current value.
21  * The labels can be dynamically generated from value by {@link #setLabelFormat(String)} or
22  * a list of static labels set by {@link #setStaticLabels(CharSequence[])}.
23  */
24 public class PickerColumn {
25 
26     private int mCurrentValue;
27     private int mMinValue;
28     private int mMaxValue;
29     private CharSequence[] mStaticLabels;
30     private String mLabelFormat;
31 
PickerColumn()32     public PickerColumn() {
33     }
34 
35     /**
36      * Set string format (see {@link String#format}) to display label for an
37      * integer value.  {@link #setStaticLabels(CharSequence[])} overrides the format.
38      *
39      * @param labelFormat String format to display label for value between minValue and maxValue.
40      */
setLabelFormat(String labelFormat)41     public void setLabelFormat(String labelFormat) {
42         mLabelFormat = labelFormat;
43     }
44 
45     /**
46      * Return string format (see {@link String#format}) to display label for
47      * value.
48      * @return String format to display label for value.
49      */
getLabelFormat()50     public String getLabelFormat() {
51         return mLabelFormat;
52     }
53 
54     /**
55      * Set static labels for each value, minValue maps to labels[0], maxValue maps to
56      * labels[labels.length - 1].
57      * @param labels Static labels for each value between minValue and maxValue.
58      */
setStaticLabels(CharSequence[] labels)59     public void setStaticLabels(CharSequence[] labels) {
60         mStaticLabels = labels;
61     }
62 
63     /**
64      * Returns static labels for each value, minValue maps to labels[0], maxValue maps to
65      * labels[labels.length - 1].  When null, {@link #getLabelFormat()} will be used.
66      */
getStaticLabels()67     public CharSequence[] getStaticLabels() {
68         return mStaticLabels;
69     }
70 
71     /**
72      * Get a label for value. The label can be static {@link #setStaticLabels(CharSequence[])}
73      * or dynamically generated {@link #setLabelFormat(String)} when static labels is null.
74      *
75      * @param value Value between minValue and maxValue.
76      * @return Label for the value.
77      */
getLabelFor(int value)78     public CharSequence getLabelFor(int value) {
79         if (mStaticLabels == null) {
80             return String.format(mLabelFormat, value);
81         }
82         return mStaticLabels[value];
83     }
84 
85     /**
86      * Returns current value of the Column.
87      * @return Current value of the Column.
88      */
getCurrentValue()89     public int getCurrentValue() {
90         return mCurrentValue;
91     }
92 
93     /**
94      * Sets current value of the Column.
95      */
setCurrentValue(int value)96     public void setCurrentValue(int value) {
97         mCurrentValue = value;
98     }
99 
100     /**
101      * Get total items count between minValue and maxValue.
102      * @return Total items count between minValue and maxValue.
103      */
getCount()104     public int getCount() {
105         return mMaxValue - mMinValue + 1;
106     }
107 
108     /**
109      * Returns minimal value of the Column.
110      * @return Minimal value of the Column.
111      */
getMinValue()112     public int getMinValue() {
113         return mMinValue;
114     }
115 
116     /**
117      * Returns maximum value of the Column.
118      * @return Maximum value of the Column.
119      */
getMaxValue()120     public int getMaxValue() {
121         return mMaxValue;
122     }
123 
124     /**
125      * Sets minimal value of the Column.
126      * @param minValue New minimal value to set.
127      */
setMinValue(int minValue)128     public void setMinValue(int minValue) {
129         mMinValue = minValue;
130     }
131 
132     /**
133      * Sets maximum value of the Column.
134      * @param maxValue New maximum value to set.
135      */
setMaxValue(int maxValue)136     public void setMaxValue(int maxValue) {
137         mMaxValue = maxValue;
138     }
139 
140 }
141