|
15 | 15 | *******************************************************************************/
|
16 | 16 | package uk.co.senab.photoview;
|
17 | 17 |
|
| 18 | +import android.app.Activity; |
18 | 19 | import android.content.Context;
|
19 | 20 | import android.graphics.Matrix;
|
20 | 21 | import android.graphics.Matrix.ScaleToFit;
|
@@ -77,6 +78,30 @@ public static interface OnPhotoTapListener {
|
77 | 78 | void onPhotoTap(View view, float x, float y);
|
78 | 79 | }
|
79 | 80 |
|
| 81 | + /** |
| 82 | + * Interface definition for a callback to be invoked when the ImageView is |
| 83 | + * tapped with a single tap. |
| 84 | + * |
| 85 | + * @author Chris Banes |
| 86 | + */ |
| 87 | + public static interface OnViewTapListener |
| 88 | + { |
| 89 | + |
| 90 | + /** |
| 91 | + * A callback to receive where the user taps on a ImageView. You will |
| 92 | + * receive a callback if the user taps anywhere on the view, tapping on |
| 93 | + * 'whitespace' will not be ignored. |
| 94 | + * |
| 95 | + * @param view |
| 96 | + * - View the user tapped |
| 97 | + * @param x |
| 98 | + * - where the user tapped from the left |
| 99 | + * @param y |
| 100 | + * - where the user tapped from the top |
| 101 | + */ |
| 102 | + void onViewTap(View view, float x, float y); |
| 103 | + } |
| 104 | + |
80 | 105 | private class FlingRunnable implements Runnable {
|
81 | 106 |
|
82 | 107 | private final ScrollerProxy mScroller;
|
@@ -236,6 +261,7 @@ private static boolean isSupportedScaleType(final ScaleType scaleType) {
|
236 | 261 | // Listeners
|
237 | 262 | private OnMatrixChangedListener mMatrixChangeListener;
|
238 | 263 | private OnPhotoTapListener mPhotoTapListener;
|
| 264 | + private OnViewTapListener mViewTapListener; |
239 | 265 |
|
240 | 266 | // Saves us allocating a new float[] when getValue is called
|
241 | 267 | private final float[] mMatrixValues = new float[9];
|
@@ -296,6 +322,7 @@ public final void cleanup() {
|
296 | 322 | // Clear listeners too
|
297 | 323 | mMatrixChangeListener = null;
|
298 | 324 | mPhotoTapListener = null;
|
| 325 | + mViewTapListener = null; |
299 | 326 | }
|
300 | 327 |
|
301 | 328 | /**
|
@@ -449,6 +476,10 @@ public final boolean onSingleTapConfirmed(MotionEvent e) {
|
449 | 476 | }
|
450 | 477 | }
|
451 | 478 | }
|
| 479 | + if (null != mViewTapListener) |
| 480 | + { |
| 481 | + mViewTapListener.onViewTap(mImageView, e.getX(), e.getY()); |
| 482 | + } |
452 | 483 |
|
453 | 484 | return false;
|
454 | 485 | }
|
@@ -535,6 +566,18 @@ public final void setOnPhotoTapListener(OnPhotoTapListener listener) {
|
535 | 566 | mPhotoTapListener = listener;
|
536 | 567 | }
|
537 | 568 |
|
| 569 | + /** |
| 570 | + * Register a callback to be invoked when the View |
| 571 | + * is tapped with a single tap. |
| 572 | + * |
| 573 | + * @param listener |
| 574 | + * - Listener to be registered. |
| 575 | + */ |
| 576 | + public final void setOnPhotoTapListener(OnViewTapListener listener) |
| 577 | + { |
| 578 | + mViewTapListener = listener; |
| 579 | + } |
| 580 | + |
538 | 581 | /**
|
539 | 582 | * Allows you to enable/disable the zoom functionality on the ImageView.
|
540 | 583 | * When disable the ImageView reverts to using the FIT_CENTER matrix.
|
|
0 commit comments