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

custom onDragStopListener #30

Closed
vanlooverenkoen opened this issue Aug 22, 2016 · 5 comments
Closed

custom onDragStopListener #30

vanlooverenkoen opened this issue Aug 22, 2016 · 5 comments

Comments

@vanlooverenkoen
Copy link

Is there a way to get a onDragStopListener?
I need to detect when the view is placed in the right position?
because if I use setOnViewSwapListener(); the order of the views in the draglinearlayout is not committed.

if someone changes the order of the views. I need to read the correct order of the views so I can handle code for each view.

view1.print("1");
view2.print("2");
view3.print("3");

after changing the order 2 becomes 3 and 3 becomes 2. this is what I need to call

view1.print("1");
view3.print("3");
view2.print("2");

How can I do this?

@vanlooverenkoen
Copy link
Author

vanlooverenkoen commented Aug 22, 2016

    mDragLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (MotionEventCompat.getActionMasked(motionEvent) == MotionEvent.ACTION_UP) {
                updatePreviewsCallback.executeCallback();
            }
            return false;
        }
    });

this is what I found that worked, but maybe you could implement it in the api to add a dedecated listener. just a suggestion

@justasm
Copy link
Owner

justasm commented Aug 22, 2016

Hey!

The order is in fact committed when the onSwap callback is called, so it would be the proper place to update your model. Thanks for the suggestion and for posting your solution.

@justasm justasm closed this as completed Aug 22, 2016
@vanlooverenkoen
Copy link
Author

vanlooverenkoen commented Aug 24, 2016

onSwap? is this a public API? I can't find it
or do you mean the: OnViewSwapListener?

because at that point if you loop over all your views they are still in the previous position only if you let go of the draghandler the position will be changed

@justasm
Copy link
Owner

justasm commented Aug 24, 2016

I did mean the OnViewSwapListener.
You are correct that the View positions are swapped only after the callback is invoked, which in retrospect is probably not the expected behaviour. However, you have sufficient information with the initial state and the sequence of onSwap callbacks to know at any time what the current order is.

If you need to specifically detect ACTION_UP, the solution you provided is one correct way to do it.

@vanlooverenkoen
Copy link
Author

yes indeed, thanks again for your awesome lib

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

2 participants