Ever wanted to use a range bar in your android shared preferences. This library will help with that. Simply add straight into your preferences.xml and you're away.
Add this to your module dependencies:
compile 'com.nfx.android:range-bar-preference:0.0.6'
Now just add the preference to to your preference xml file like any other preference
<com.nfx.android.rangebarpreference.RangeBarPreference
android:key="your_pref_key"
android:title="Preference Key"
android:summary="A summary of the preference"
app:rbp_measurementUnit="unit text"
app:rbp_tickStart="1"
app:rbp_tickEnd="100"
app:rbp_tickInterval="1"
app:rbp_view_defaultLowValue="40"
app:rbp_view_defaultHighValue="60"/>
If you have to support API-v7+, this lib provides also RangeBarPreferenceCompat that works with preference-v7.
<com.nfx.android.rangebarpreference.RangeBarPreferenceCompat
android:key="your_pref_key"
android:title="Preference Key"
android:summary="A summary of the preference"
app:rbp_measurementUnit="unit text"
app:rbp_tickStart="1"
app:rbp_tickEnd="100"
app:rbp_tickInterval="1"
app:rbp_view_defaultLowValue="40"
app:rbp_view_defaultHighValue="60"/>
Also, the two classes provide methods to modify the preference at runtime
public float getTickEnd();
public void setTickEnd(float tickEnd);
public float getTickStart();
public void setTickStart(int tickStart);
public float getTickInterval();
public void setTickInterval(int tickInterval);
public float getCurrentLowValue();
public void setCurrentLowValue(float currentLowValue);
public float getCurrentHighValue();
public void setCurrentHighValue(float currentHighValue);
public String getMeasurementUnit();
public void setMeasurementUnit(String measurementUnit);
public boolean isDialogEnabled();
public void setDialogEnabled(boolean dialogEnabled);
public void setDialogStyle(int dialogStyle);
As there are 2 values stored as shared preferences, they are stored as a JSON string. It follows the format below.
{"lowValue":"LOW_VALUE", "highValue":"HIGH_VALUE"}
This can be a little troublesome to parse therefore a static helper class exists to mitigate these problems. Use the following examples for guidance
String jsonString = RangeBarHelper.convertValuesToJsonString(LOW_VALUE, HIGH_VALUE);
RangeBarHelper.getLowValueFromJsonString(jsonString);
RangeBarHelper.getHighValueFromJsonString(jsonString);
SemVer is used for versioning. For the versions available, see the tags on this repository.
- Nicholas Winder - Preference adaptation work - nfxdevelopment
Licenced under Apache2 licence, so you can do whatever you want with it. Please push back changes to help the library mature.
- Thanks to oli107 for the orignal range bar library.