Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from rarcher/feature/range-constants
Browse files Browse the repository at this point in the history
Add Range Constants
  • Loading branch information
jayschwa authored Feb 20, 2017
2 parents fd176fc + c1c7c2d commit dc26f74
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/net/jayschwa/android/preference/SliderPreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
public class SliderPreference extends DialogPreference {

public final static float MAXIMUM = 1.0f;
public final static float MINIMUM = 0.0f;
protected final static int SEEKBAR_RESOLUTION = 10000;

protected float mValue;
Expand Down Expand Up @@ -56,7 +58,7 @@ private void setup(Context context, AttributeSet attrs) {

@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getFloat(index, 0);
return a.getFloat(index, MINIMUM);
}

@Override
Expand Down Expand Up @@ -99,7 +101,7 @@ public float getValue() {
}

public void setValue(float value) {
value = Math.max(0, Math.min(value, 1)); // clamp to [0, 1]
value = Math.max(MINIMUM, Math.min(value, MAXIMUM)); // clamp to [MINIMUM, MAXIMUM]
if (shouldPersist()) {
persistFloat(value);
}
Expand Down

0 comments on commit dc26f74

Please sign in to comment.