Kaydet (Commit) 5bfb8195 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 62633158
/*
* 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;
}
}
......@@ -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();
}
......
......@@ -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();
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment