oli107 / material-range-bar

Android widget for selecting a range of values.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not possible to track when I release my finger from the rangebar?

HenrikT opened this issue · comments

I want to send something to a server when I stop touching the rangebar, i.e do the same thing as onStopTrackingTouch() in the Android SeekBar. The only way I've found of doing this is to use an onTouchListener and check MotionEvent.ACTION_UP, but then the view of the RangeBar does not update until I release my finger.

I can't use onRangeBarChangeListener() for this, as I don't want to be sending information to the server on every change.

Is there any easy way of doing this? :)

Thanks in advance!

I would ask highly that this be added - very basic but important functionality to know when the seek has stopped and what is the final value (ie to save it or send to server, etc)

Been struggling with that exact same issue for a couple hours, finally I decided to get hacky and took matters into my own hands.. literally..

public class RangeBar extends com.appyvet.rangebar.RangeBar {
    public RangeBar(Context context) {
        super(context);
    }

    public RangeBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RangeBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            EventBus.getDefault().post(new PriceRangeUpdated());
            return super.onTouchEvent(event);
        }
        return super.onTouchEvent(event);
    }

    public class PriceRangeUpdated {
    }
}

As you can see, I extended his RangeBar and overridden the onTouchEventMethod, in it I notify my activity that a the user's finger is leaving the RangeBar, then in the activity, I can easily retrieve the values like this:

@Subscribe(threadMode = ThreadMode.MAIN)
    public void onPriceRangeUpdated(RangeBar.PriceRangeUpdated updateEvent) {
        String leftPin = priceRangeBar.getLeftPinValue();
        String rightPin = priceRangeBar.getRightPinValue();
        Log.d("@@@@", "onPriceRangeUpdated: leftPin: " + leftPin);
        Log.d("@@@@", "onPriceRangeUpdated: rightPin: " + rightPin);
    }