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

How to dismiss PopupWindow by swipe to top while using ZoomageView inside it? #107

Open
Gkemon opened this issue Mar 9, 2021 · 6 comments

Comments

@Gkemon
Copy link

Gkemon commented Mar 9, 2021

COPIED FROM MY ORIGINAL StackOverflow QUESTION

I'm using the ZoomageView library in PopupWindows to show an image with zoomable capacity. But the problem is that I want to dismiss it by a swipe to the top but can't because ZoomageView has its own ScaleGestureDetector. I added my own custom touchListener to detect top swipe by the following approach -

 zoomageView.setOnTouchListener(new OnSwipeTouchListener(zoomageView.getContext()){
                        public void onSwipeTop() {
                            pw.dismiss()
                        }
                    });
class OnSwipeTouchListener implements View.OnTouchListener {
        private final GestureDetector gestureDetector;

        public OnSwipeTouchListener(Context ctx) {
            gestureDetector = new GestureDetector(ctx, new GestureListener());
        }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }

    private final class GestureListener extends GestureDetector.SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 200;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            boolean result = false;
            try {
                float diffY = e2.getY() - e1.getY();
                    if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                    if (diffY < 0) {
                        onSwipeTop();
                    } 
                    result = true;
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return result;
        }
    }
    public void onSwipeTop() {
    }

But it conflicts with ZoomageView's zooming attitude because while the image is being zoomed then if the user swipe to top for moving the image (because when the image is zoomed then the user may move the image in any directions) then onSwipeTop is called which dismiss the popup.

I just want to dismiss popup while the image is not zoomed and while the image is zoomed then ignore the onSwipeTop.

@varun7952
Copy link

Yes swipe up and down is common interface in almost all apps these days. Any solution for that??

@jsibbold
Copy link
Owner

Do you mean while actively zooming, or while an image is already zoomed in (ie a larger scale than 1)?

@varun7952
Copy link

@jsibbold same like reddit, WhatsApp, Twitter etc. All worked when image is zoomed out to our original size and swipe up or down dismissed the popup

@varun7952
Copy link

Any update on this ?

@jsibbold
Copy link
Owner

jsibbold commented Apr 7, 2022

Currently a bit swamped with other things, best thing to do for now is just adjust the source to your needs.

@varun7952
Copy link

@jsibbold I will post my update on this. I have already added this feature. I will post my code later. Thanks for the great and effective code for imageview.

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