Photoview: Allow the use of custom OnTouchListener

Created on 21 Aug 2016  路  4Comments  路  Source: Baseflow/PhotoView

In https://github.com/davemorrissey/subsampling-scale-image-view it is possible to assign a custom GestureDetector that works parallel to the gesture functions of the library.

Therefore it is possible to use code like this:

mImageView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event){
                // detect swipe gestures or any other gesture
            }
        })

However, this is not possible with PhotoView, since it assigns its own OnTouchListener directly in the PhotoViewAttacher constructor.

I know that there are some helper methods like mAttacher.setOnSingleFlingListener(); or mAttacher.setOnDoubleTapListener();, but if would be much more convenient if the standard interface could be used.

Is there any plan to solve this issue?

Most helpful comment

How to use this MyPhotoAttacher?

All 4 comments

may be you should try this

public class MyPhotoAttacher extends PhotoViewAttacher implements View.OnLongClickListener,View.OnTouchListener {
    public MyPhotoAttacher(ImageView imageView) {
        super(imageView);
    }

    @Override
    public boolean onLongClick(View v) {
        return false;
    }

    public boolean onTouch(View view, MotionEvent event) {
        Log.d("Touch","touch happened -"+event.getAction());
        return super.onTouch(view, event);
    }

}

Thanks I will try it out

How to use this MyPhotoAttacher?

I extended the PhotoView class and copied all the methods.
If the devs change the class fields and the init method to "protected" maybe it will be simple to extend.
In this case, you can extend the class and override the init method and change the attacher field with your custom PhotoViewAttacher:
`
public class PhotoView {

protected PhotoViewAttacher attacher;
protected ScaleType pendingScaleType;
....
protected void init() {
     .....

`

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macpraveen picture macpraveen  路  4Comments

Thien658jjh picture Thien658jjh  路  4Comments

keeblebogdan picture keeblebogdan  路  5Comments

AnthonyKoueik picture AnthonyKoueik  路  9Comments

imyyq-star picture imyyq-star  路  7Comments