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

OnPhotoTapListener not called when setZoomable(false) #746

Open
AndrewRogers1994 opened this issue Feb 19, 2020 · 1 comment
Open

OnPhotoTapListener not called when setZoomable(false) #746

AndrewRogers1994 opened this issue Feb 19, 2020 · 1 comment

Comments

@AndrewRogers1994
Copy link

I'm using the PhotoView to display a camera stream which I do not want to be zoomable by the user.

I have the following code:

imageView = findViewById(R.id.overlayimageview);
imageView.setZoomable(false);

imageView.setOnPhotoTapListener(new OnPhotoTapListener()
{
     @Override
     public void onPhotoTap(ImageView view, float x, float y)
      {
      }
}

However the onPhotoTap is never called when zoomable is set to false.

Any suggestions or work arounds?

@yandroidUA
Copy link

yandroidUA commented Aug 1, 2020

Yeap, same problem. Thats because of line 335 in PhotoViewAttacher class:

@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;
    if (mZoomEnabled && Util.hasDrawable((ImageView) v)) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                ViewParent parent = v.getParent();
                // First, disable the Parent from intercepting the touch
                // event
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
                // If we're flinging, and the user presses down, cancel
                // fling
                cancelFling();
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                // If the user has zoomed less than min scale, zoom back
                // to min scale
                if (getScale() < mMinScale) {
                    RectF rect = getDisplayRect();
                    if (rect != null) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
                            rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                } else if (getScale() > mMaxScale) {
                    RectF rect = getDisplayRect();
                    if (rect != null) {
                        v.post(new AnimatedZoomRunnable(getScale(), mMaxScale,
                            rect.centerX(), rect.centerY()));
                        handled = true;
                    }
                }
                break;
        }
        // Try the Scale/Drag detector
        if (mScaleDragDetector != null) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();
            handled = mScaleDragDetector.onTouchEvent(ev);
            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();
            mBlockParentIntercept = didntScale && didntDrag;
        }
        // Check to see if the user double tapped
        if (mGestureDetector != null && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }
    return handled;
}

This line make pain: if (mZoomEnabled && Util.hasDrawable((ImageView) v))

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