Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'touch_outside_drawable'

  • Loading branch information...
commit 3a59dde42ebd5311a599b152336957392765d4fd 2 parents b8db739 + a08ae65
@goncalossilva goncalossilva authored
View
4 main/src/com/polites/android/GestureImageView.java
@@ -57,8 +57,8 @@
private boolean recycle = false;
private boolean strict = false;
- private int displayHeight;
- private int displayWidth;
+ protected int displayHeight;
+ protected int displayWidth;
private int alpha = 255;
private ColorFilter colorFilter;
View
10 main/src/com/polites/android/GestureImageViewListener.java
@@ -7,12 +7,14 @@
* @author jasonpolites
*
*/
-public interface GestureImageViewListener {
+public abstract class GestureImageViewListener {
- public void onTouch(float x, float y);
+ public void onTouch(float x, float y) { }
- public void onScale(float scale);
+ public void onScale(float scale) { }
- public void onPosition(float x, float y);
+ public void onPosition(float x, float y) { }
+
+ public void onTouchOutsideDrawable(float x, float y) { }
}
View
19 main/src/com/polites/android/GestureImageViewTouchListener.java
@@ -1,6 +1,7 @@
package com.polites.android;
import android.graphics.PointF;
+import android.graphics.Rect;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
@@ -19,6 +20,7 @@
private final VectorF pinchVector = new VectorF();
boolean touched = false;
+ boolean touchDownOutsideDrawable = false;
private float initialDistance;
private float lastScale = 1.0f;
@@ -115,7 +117,6 @@ private void stopFling() {
@Override
public boolean onTouch(View v, MotionEvent event) {
-
if(event.getPointerCount() == 1 && flingDetector.onTouchEvent(event)) {
startFling();
}
@@ -157,10 +158,15 @@ public boolean onTouch(View v, MotionEvent event) {
if(imageListener != null) {
imageListener.onScale(currentScale);
imageListener.onPosition(next.x, next.y);
- }
+
+ if(touchDownOutsideDrawable && coordinatesOutsideDrawable(event.getX(), event.getY())) {
+ imageListener.onTouchOutsideDrawable(event.getX(), event.getY());
+ }
+ }
image.redraw();
}
+
else if(event.getAction() == MotionEvent.ACTION_DOWN) {
stopFling();
@@ -169,6 +175,7 @@ else if(event.getAction() == MotionEvent.ACTION_DOWN) {
if(imageListener != null) {
imageListener.onTouch(last.x, last.y);
+ touchDownOutsideDrawable = coordinatesOutsideDrawable(last.x, last.x);
}
touched = true;
@@ -356,4 +363,12 @@ protected void calculateBoundaries() {
boundaryBottom = centerY + diff;
}
}
+
+ private boolean coordinatesOutsideDrawable(float x, float y) {
+ Rect r = image.getDrawable().getBounds();
+ return y < (centerY + r.top * currentScale) ||
+ y > (centerY + r.bottom * currentScale) ||
+ x < (centerX + r.left * currentScale) ||
+ x > (centerX + r.right * currentScale);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.