From 5bfb819581bdc9e1f1c59e36a0d7fb21593b382b Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 27 Jun 2012 12:30:32 +0300 Subject: Use GestureImageView again but still do handle page changes Make the GestureImageView constructors take a OnGestureListener, and store that, Move the FlingListener class into GestureImageViewTouchListener so that FlingListener has access to the fields of GestureImageViewTouchListener. If the image is fully zoomed out and can't be dragged, pass flings on up, to DocumentLoader's gestureListener. Change-Id: I574280de23bdab2772a361833f561dff3e182bcd --- .../src/com/polites/android/FlingListener.java | 45 ---------------------- .../src/com/polites/android/GestureImageView.java | 14 +++++-- .../android/GestureImageViewTouchListener.java | 25 ++++++++++++ .../android/examples/DocumentLoader.java | 6 ++- 4 files changed, 39 insertions(+), 51 deletions(-) delete mode 100644 android/experimental/DocumentLoader/src/com/polites/android/FlingListener.java (limited to 'android') diff --git a/android/experimental/DocumentLoader/src/com/polites/android/FlingListener.java b/android/experimental/DocumentLoader/src/com/polites/android/FlingListener.java deleted file mode 100644 index ab3007a14b00..000000000000 --- a/android/experimental/DocumentLoader/src/com/polites/android/FlingListener.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2012 Jason Polites - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.polites.android; - -import android.view.GestureDetector.SimpleOnGestureListener; -import android.view.MotionEvent; - - -/** - * @author Jason Polites - * - */ -public class FlingListener extends SimpleOnGestureListener { - - private float velocityX; - private float velocityY; - - @Override - public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - this.velocityX = velocityX; - this.velocityY = velocityY; - return true; - } - - public float getVelocityX() { - return velocityX; - } - - public float getVelocityY() { - return velocityY; - } -} diff --git a/android/experimental/DocumentLoader/src/com/polites/android/GestureImageView.java b/android/experimental/DocumentLoader/src/com/polites/android/GestureImageView.java index 1cde6e4b4889..4b9278c1cf35 100644 --- a/android/experimental/DocumentLoader/src/com/polites/android/GestureImageView.java +++ b/android/experimental/DocumentLoader/src/com/polites/android/GestureImageView.java @@ -32,6 +32,7 @@ import android.net.Uri; import android.provider.MediaStore; import android.util.AttributeSet; import android.util.Log; +import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; @@ -88,13 +89,16 @@ public class GestureImageView extends ImageView { private OnTouchListener customOnTouchListener; private OnClickListener onClickListener; - public GestureImageView(Context context, AttributeSet attrs, int defStyle) { - this(context, attrs); + GestureDetector.OnGestureListener overflowGestureListener; + + public GestureImageView(Context context, GestureDetector.OnGestureListener overflowGestureListener, AttributeSet attrs, int defStyle) { + this(context, overflowGestureListener, attrs); } - public GestureImageView(Context context, AttributeSet attrs) { + public GestureImageView(Context context, GestureDetector.OnGestureListener overflowGestureListener, AttributeSet attrs) { super(context, attrs); + this.overflowGestureListener = overflowGestureListener; String scaleType = attrs.getAttributeValue(GLOBAL_NS, "scaleType"); if(scaleType == null || scaleType.trim().length() == 0) { @@ -121,8 +125,10 @@ public class GestureImageView extends ImageView { initImage(); } - public GestureImageView(Context context) { + public GestureImageView(Context context, GestureDetector.OnGestureListener overflowGestureListener) { super(context); + + this.overflowGestureListener = overflowGestureListener; setScaleType(ScaleType.CENTER_INSIDE); initImage(); } diff --git a/android/experimental/DocumentLoader/src/com/polites/android/GestureImageViewTouchListener.java b/android/experimental/DocumentLoader/src/com/polites/android/GestureImageViewTouchListener.java index 76751d145b58..f39840b60a79 100644 --- a/android/experimental/DocumentLoader/src/com/polites/android/GestureImageViewTouchListener.java +++ b/android/experimental/DocumentLoader/src/com/polites/android/GestureImageViewTouchListener.java @@ -81,6 +81,31 @@ public class GestureImageViewTouchListener implements OnTouchListener { private GestureDetector flingDetector; private GestureImageViewListener imageListener; + class FlingListener extends SimpleOnGestureListener { + + private float velocityX; + private float velocityY; + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + this.velocityX = velocityX; + this.velocityY = velocityY; + if (image.overflowGestureListener != null && !canDragX && !canDragY) { + return image.overflowGestureListener.onFling(e1, e2, velocityX, velocityY); + } + + return true; + } + + public float getVelocityX() { + return velocityX; + } + + public float getVelocityY() { + return velocityY; + } + } + public GestureImageViewTouchListener(final GestureImageView image, int displayWidth, int displayHeight) { super(); diff --git a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java index d4079321c82a..25878577cc7d 100644 --- a/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java +++ b/android/experimental/DocumentLoader/src/org/libreoffice/android/examples/DocumentLoader.java @@ -124,6 +124,7 @@ public class DocumentLoader int pageCount; XRenderable renderable; + GestureDetector.OnGestureListener gestureListener; GestureDetector gestureDetector; ViewGroup.LayoutParams matchParent; @@ -368,7 +369,7 @@ public class DocumentLoader if (result == -1) return; - ImageView imageView = new ImageView(DocumentLoader.this); + GestureImageView imageView = new GestureImageView(DocumentLoader.this, gestureListener); imageView.setImageBitmap(bm); imageView.setScaleY(-1); @@ -541,7 +542,8 @@ public class DocumentLoader extras = getIntent().getExtras(); - gestureDetector = new GestureDetector(this, new GestureListener()); + gestureListener = new GestureListener(); + gestureDetector = new GestureDetector(this, gestureListener); try { long t0 = System.currentTimeMillis(); -- cgit