oli107 / material-range-bar

Android widget for selecting a range of values.
Apache License 2.0
1.68k stars 370 forks source link

Pin value for string length greater than 4 is not giving the correct value #102

Open shubhams opened 7 years ago

shubhams commented 7 years ago

I set the tickEnd and tickStart values as:

rangeBar.setTickEnd(10000);
rangeBar.setTickStart(1000);
rangeBar.setTickInterval(1000);

Now, to get the pin values I was using the setOnRangeBarChangeListener. The left pin value was coming out to be correct as 1000, however the right pin value was also coming out to be 1000.

So, I peeked into the method of getPinValue(int tickIndex) and I noticed that before returning the value, mPinTextFormatter is used to format the pin value. The mPinTextFormatter is defined as:

private PinTextFormatter mPinTextFormatter = new PinTextFormatter() {
        @Override
        public String getText(String value) {
            if (value.length() > 4) {
                return value.substring(0, 4);
            } else {
                return value;
            }
        }
    };

The if condition to check if length is greater than 4, returns the substring upto the length 4.

Although I fixed the issue by setting by own PinTextFormatter that returns the string value as it is, and it might make sense to return the "substring" when showing the value in the pin bubble.

However, a simple rangeBar.getRightPinValue() would also give the wrong value in this case.

shreyan007 commented 7 years ago

<com.appyvet.rangebar.RangeBar xmlns:custom="http://schemas.android.com/apk/res-auto" android:id="@+id/rangebar1" android:layout_width="match_parent" android:layout_height="72dp" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" custom:pinMaxFont="10sp" custom:selectorBoundaryColor="@color/accent" custom:selectorBoundarySize="2dp" custom:selectorSize="10dp" custom:temporaryPins="false" custom:tickEnd="80000" custom:tickInterval="1000" custom:tickStart="1000"/> not working

shubhams commented 7 years ago

You can do it programmatically, like this:

rangeBar.setPinTextFormatter(new RangeBar.PinTextFormatter() {
            @Override
            public String getText(String value) {
                return value;
            }
        });