Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HenrikT opened this issue Jun 24, 2016 · 2 comments
Open

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

HenrikT opened this issue Jun 24, 2016 · 2 comments

Comments

@HenrikT
Copy link

HenrikT commented Jun 24, 2016

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!

@campaignium
Copy link

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)

@MahmoudAlyuDeen
Copy link

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);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants