- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19
03 SeekBarPreference
The preference, which is implemented in the class SeekBarPreference, does provides the possibility to select a Float or Integer value from a continous range via a SeekBar. The SeekBar is shown within a dialog and the selected value only becomes persisted when the user closes the dialog affirmatively. The preference allows to specify a minimum and maximum value and the number of decimals of the Float values, which can be selected by the SeekBar. If integer values should be selected by the preference, the number of decimals can be set to 0. Furthermore, the step size, the value is increased or decreased by, when the SeekBar is moved, can be specified. Optionally, the currently selected value, using a customizable unit, can be shown within the dialog.
When a SeekBarPreference is instantiated programmatically, its properties can be set or retrieved by using the setter and getter methods, which are listed in the table below. As the class is extended from the class DialogPreference, the methods, which have been already discussed in the previous section, are also available.
| Getter and setter methods | Description | Default value | Restrictions | 
|---|---|---|---|
| getValue():floatsetValue(float):void | Returns or sets the currently persisted value of the preference. If a value is set, it is instantly persisted. If a step size is set, the value will be eventually rounded. | 0.0 | none | 
| getMinValue():intsetMinValue(int):void | Returns or sets the minimum value of the preference. | 0.0 | The value must be less than the maximum value. | 
| getMaxValue():intsetMaxValue(int):void | Returns or sets the maximum value of the preference. | 100.0 | The value must be greater than the minimum value. | 
| getRange():int | Returns the range of values, the preference allows to choose from (maximum value - minimum value). | 100.0 | none | 
| getStepSize():intsetStepSize(int):void | Returns or sets the step size, the value is increased or decreased by, when the user moves the preference's seek bar. | -1 | The value must be -1, if no step size should be used, or it must be at minimum 1 and at maximum the value of the method getRange(). | 
| getDecimals():intsetDecimals(int):void | Returns or sets the number of decimals of the floating point numbers, which can be chosen by using the preference. | 1 | The value must be at least 0. | 
| getUnit():CharSequencesetUnit(CharSequence):voidsetUnit(int):void | Returns or sets the unit, which is appended to the preference's currently chosen value for textual representation. It the unit is set to null, no unit is appended. | null | none | 
| getFloatingPointSeparator():CharSequencesetFloatingPointSeparator(CharSequence):voidsetFloatingPointSeparator(int):void | Returns or sets the symbol, which is used to separate floating point numbers for textual representation. If the separator is set to null, the default symbol, depending on the device's locale, is used. | null | If not null, the string must have a size of 1. | 
| isProgressShown():booleanshowProgress(boolean):void | Returns or sets, whether the currently chosen value of the preference's seek bar is shown, or not. | true | none | 
| getSummaries():CharSequence[]setSummaries(CharSequence[]):void | Returns or sets the summaries, which should be shown as the preference's summary, depending on the currently persisted value. For example, if the array's dimension is 2, the first summary will be shown if the value is between 0% and 49% of the whole range and the second summary will be shown if the value is between 50% and 100% of the range. If the array is set to null, no summaries will be shown depending on the currently persisted value. | null | none | 
If a SeekBarPreference is created by beeing specified within a XML resource file, XML attributes can be used to customize the preference's behaviour and appearance. Besides the inherited attributes, which are defined by the Android API, the library does provide various custom attributes, which can be used to set the same attributes as the setter methods mentioned in the previous section. The custom attributes, respectively the inherited attributes, whose semantic is modified by the library, are defined within the file /res/values/attrs.xml. In the following two sections all custom attributes and the most important inherited attributes will be introduced. The following table shows the custom attributes of the preference.
| XML attribute | Description | Format | 
|---|---|---|
| android:defaultValue | The preference's default value. If a step size is set, the value will be eventually rounded. | float | 
| android:max | The maximum value of the preference. | integer | 
| custom:min | The minimum value of the preference. | integer | 
| custom:decimals | The number of decimals of the floating point numbers which can be chosen by using the preference. If the value is set to 0, only integer values can be chosen. | integer | 
| custom:stepSize | The step size the preference's current value is increased or decreased by, when the user moves the seek bar. If the value is set to -1 no step size is used. | integer | 
| custom:unit | The unit, which is appended to the preference's current value for textual representation. If the unit is null, no unit is appended. | string | 
| custom:floatingPointSeparator | The symbol, which is used to separate floating point numbers for textual representation. If the string is null, the default separator, depending on the system's locale, is used. | string | 
| custom:showProgress | Defines, whether the current chosen value of the preference's seek bar should be shown, or not. | boolean |