diff options
author | Tor Lillqvist <tlillqvist@suse.com> | 2012-06-27 12:30:32 +0300 |
---|---|---|
committer | Tor Lillqvist <tlillqvist@suse.com> | 2012-06-27 12:58:37 +0300 |
commit | 5bfb819581bdc9e1f1c59e36a0d7fb21593b382b (patch) | |
tree | f1bbe2542c9e7073c0feb3f18b8f34bfccdbd500 /android | |
parent | 6263315825e01e766668b9ce5d2eb52e71e051a7 (diff) |
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
Diffstat (limited to 'android')
4 files changed, 39 insertions, 51 deletions
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(); |