loupe
loupe copied to clipboard
provide imageview single touch callback
when user just touch the imageview with single finger provide the callback as onClickListener()
I see that there is already a PR for this issue since a year. Any progress on this?
As a workaround I registered an own TouchListener to the imageview container (overriding the one registered by Loupe). This Listener forwards all events to Loupe, but it also uses a second GestureDetector instance to detect single taps.
A crude workaround though. I really hope this PR gets merged through.
My code (sorry, it is Java...)
final Loupe loupe = new Loupe(binding.imageFull, binding.imageviewViewroot);
loupe.setOnViewTranslateListener(new Loupe.OnViewTranslateListener() {
@Override
public void onStart(@NonNull final ImageView imageView) {
//empty on purpose
}
@Override
public void onViewTranslate(@NonNull final ImageView imageView, final float v) {
//empty on purpose
}
@Override
public void onDismiss(@NonNull final ImageView imageView) {
//close detail view on "fling down"
finish();
}
@Override
public void onRestore(@NonNull final ImageView imageView) {
//empty on purpose
}
});
//Loupe is unable to detect single clicks (see https://github.com/igreenwood/loupe/issues/25)
//As a workaround we register a second GestureDetector on top of the one installed by Loupe to detect single taps
//Workaround START
final GestureDetector singleTapDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(final MotionEvent e) {
//Logic to happen on single tap:
inverseFullImageView(binding);
return true;
}
});
//Registering an own touch listener overrides the TouchListener registered by Loupe
binding.imageviewViewroot.setOnTouchListener((v, event) -> {
//perform singleTap detection
singleTapDetector.onTouchEvent(event);
//pass through event to Loupe so it handles all other gestures correctly
return loupe.onTouch(v, event);
});
//Workaround END