Move the ScaleGestureDetector.OnScaleGestureListener implementation over to PanZoomController rather than delegating through LayerController.

This commit is contained in:
Doug Turner 2011-11-07 14:17:01 -08:00
parent 3e0027fff3
commit b0b5b9e180
3 changed files with 9 additions and 19 deletions

View File

@ -58,7 +58,7 @@ import java.util.ArrayList;
* zooming natively by delegating to a panning/zooming controller. Touch events can be dispatched * zooming natively by delegating to a panning/zooming controller. Touch events can be dispatched
* to a higher-level view. * to a higher-level view.
*/ */
public class LayerController implements ScaleGestureDetector.OnScaleGestureListener { public class LayerController {
private Layer mRootLayer; /* The root layer. */ private Layer mRootLayer; /* The root layer. */
private LayerView mView; /* The main rendering view. */ private LayerView mView; /* The main rendering view. */
private Context mContext; /* The current context. */ private Context mContext; /* The current context. */
@ -98,8 +98,8 @@ public class LayerController implements ScaleGestureDetector.OnScaleGestureListe
else else
mPageSize = new IntSize(LayerController.TILE_WIDTH, LayerController.TILE_HEIGHT); mPageSize = new IntSize(LayerController.TILE_WIDTH, LayerController.TILE_HEIGHT);
mView = new LayerView(context, this);
mPanZoomController = new PanZoomController(this); mPanZoomController = new PanZoomController(this);
mView = new LayerView(context, this);
} }
public void setRoot(Layer layer) { mRootLayer = layer; } public void setRoot(Layer layer) { mRootLayer = layer; }
@ -121,6 +121,8 @@ public class LayerController implements ScaleGestureDetector.OnScaleGestureListe
public Bitmap getCheckerboardPattern() { return getDrawable("checkerboard"); } public Bitmap getCheckerboardPattern() { return getDrawable("checkerboard"); }
public Bitmap getShadowPattern() { return getDrawable("shadow"); } public Bitmap getShadowPattern() { return getDrawable("shadow"); }
public ScaleGestureDetector.OnScaleGestureListener getScaleGestureListener() { return mPanZoomController; }
private Bitmap getDrawable(String name) { private Bitmap getDrawable(String name) {
Resources resources = mContext.getResources(); Resources resources = mContext.getResources();
int resourceID = resources.getIdentifier(name, "drawable", mContext.getPackageName()); int resourceID = resources.getIdentifier(name, "drawable", mContext.getPackageName());
@ -256,21 +258,6 @@ public class LayerController implements ScaleGestureDetector.OnScaleGestureListe
return result; return result;
} }
@Override
public boolean onScale(ScaleGestureDetector detector) {
return mPanZoomController.onScale(detector);
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
return mPanZoomController.onScaleBegin(detector);
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
mPanZoomController.onScaleEnd(detector);
}
/** /**
* Objects that wish to listen for changes in the layer geometry (visible rect or screen size) * Objects that wish to listen for changes in the layer geometry (visible rect or screen size)
* should implement this interface and register themselves with addOnGeometryChangeListener(). * should implement this interface and register themselves with addOnGeometryChangeListener().

View File

@ -68,7 +68,7 @@ public class LayerView extends GLSurfaceView {
mController = controller; mController = controller;
mRenderer = new LayerRenderer(this); mRenderer = new LayerRenderer(this);
setRenderer(mRenderer); setRenderer(mRenderer);
mScaleGestureDetector = new ScaleGestureDetector(context, controller); mScaleGestureDetector = new ScaleGestureDetector(context, controller.getScaleGestureListener());
mInputConnectionHandler = null; mInputConnectionHandler = null;
setFocusable(true); setFocusable(true);

View File

@ -53,7 +53,7 @@ import java.util.TimerTask;
* Many ideas are from Joe Hewitt's Scrollability: * Many ideas are from Joe Hewitt's Scrollability:
* https://github.com/joehewitt/scrollability/ * https://github.com/joehewitt/scrollability/
*/ */
public class PanZoomController { public class PanZoomController implements ScaleGestureDetector.OnScaleGestureListener {
private LayerController mController; private LayerController mController;
private static final float FRICTION = 0.97f; private static final float FRICTION = 0.97f;
@ -477,6 +477,7 @@ public class PanZoomController {
/* /*
* Zooming * Zooming
*/ */
@Override
public boolean onScale(ScaleGestureDetector detector) { public boolean onScale(ScaleGestureDetector detector) {
float newZoom = detector.getCurrentSpan() / mInitialZoomSpan; float newZoom = detector.getCurrentSpan() / mInitialZoomSpan;
@ -491,6 +492,7 @@ public class PanZoomController {
return true; return true;
} }
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) { public boolean onScaleBegin(ScaleGestureDetector detector) {
IntRect initialZoomRect = (IntRect)mController.getVisibleRect().clone(); IntRect initialZoomRect = (IntRect)mController.getVisibleRect().clone();
float initialZoom = mController.getZoomFactor(); float initialZoom = mController.getZoomFactor();
@ -501,6 +503,7 @@ public class PanZoomController {
return true; return true;
} }
@Override
public void onScaleEnd(ScaleGestureDetector detector) { public void onScaleEnd(ScaleGestureDetector detector) {
// TODO // TODO
} }