Skip to content

Commit c6fc342

Browse files
committed
- added possibility to use OnViewTapListener which ignores loaded photo
bounds and processed touches from whole the view
1 parent 4ee118c commit c6fc342

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

library/src/uk/co/senab/photoview/PhotoView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import uk.co.senab.photoview.PhotoViewAttacher.OnMatrixChangedListener;
1919
import uk.co.senab.photoview.PhotoViewAttacher.OnPhotoTapListener;
20+
import uk.co.senab.photoview.PhotoViewAttacher.OnViewTapListener;
2021
import android.content.Context;
2122
import android.graphics.RectF;
2223
import android.graphics.drawable.Drawable;
@@ -121,6 +122,18 @@ public void setOnPhotoTapListener(OnPhotoTapListener listener) {
121122
mAttacher.setOnPhotoTapListener(listener);
122123
}
123124

125+
/**
126+
* Register a callback to be invoked when the View
127+
* is tapped with a single tap.
128+
*
129+
* @param listener
130+
* - Listener to be registered.
131+
*/
132+
public void setOnViewTapListener(OnViewTapListener listener)
133+
{
134+
mAttacher.setOnPhotoTapListener(listener);
135+
}
136+
124137
@Override
125138
public void setScaleType(ScaleType scaleType) {
126139
mAttacher.setScaleType(scaleType);

library/src/uk/co/senab/photoview/PhotoViewAttacher.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*******************************************************************************/
1616
package uk.co.senab.photoview;
1717

18+
import android.app.Activity;
1819
import android.content.Context;
1920
import android.graphics.Matrix;
2021
import android.graphics.Matrix.ScaleToFit;
@@ -77,6 +78,30 @@ public static interface OnPhotoTapListener {
7778
void onPhotoTap(View view, float x, float y);
7879
}
7980

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+
80105
private class FlingRunnable implements Runnable {
81106

82107
private final ScrollerProxy mScroller;
@@ -236,6 +261,7 @@ private static boolean isSupportedScaleType(final ScaleType scaleType) {
236261
// Listeners
237262
private OnMatrixChangedListener mMatrixChangeListener;
238263
private OnPhotoTapListener mPhotoTapListener;
264+
private OnViewTapListener mViewTapListener;
239265

240266
// Saves us allocating a new float[] when getValue is called
241267
private final float[] mMatrixValues = new float[9];
@@ -296,6 +322,7 @@ public final void cleanup() {
296322
// Clear listeners too
297323
mMatrixChangeListener = null;
298324
mPhotoTapListener = null;
325+
mViewTapListener = null;
299326
}
300327

301328
/**
@@ -449,6 +476,10 @@ public final boolean onSingleTapConfirmed(MotionEvent e) {
449476
}
450477
}
451478
}
479+
if (null != mViewTapListener)
480+
{
481+
mViewTapListener.onViewTap(mImageView, e.getX(), e.getY());
482+
}
452483

453484
return false;
454485
}
@@ -535,6 +566,18 @@ public final void setOnPhotoTapListener(OnPhotoTapListener listener) {
535566
mPhotoTapListener = listener;
536567
}
537568

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+
538581
/**
539582
* Allows you to enable/disable the zoom functionality on the ImageView.
540583
* When disable the ImageView reverts to using the FIT_CENTER matrix.

0 commit comments

Comments
 (0)