From 22179cab480efa593dc9b7d83352442f40da2da0 Mon Sep 17 00:00:00 2001 From: jventribout Date: Mon, 24 Dec 2012 11:56:45 +0100 Subject: [PATCH] Animated zoom reset --- src/com/hexagon/map/MapActivity.java | 23 +++++++++++++++-------- src/com/hexagon/map/Tile.java | 2 +- src/com/hexagon/map/Viewport.java | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/com/hexagon/map/MapActivity.java b/src/com/hexagon/map/MapActivity.java index 8b6d1ec..b2e5f7d 100755 --- a/src/com/hexagon/map/MapActivity.java +++ b/src/com/hexagon/map/MapActivity.java @@ -540,14 +540,7 @@ protected void onSaveInstanceState(Bundle outState) { @Override public boolean onTouchEvent(MotionEvent me) { - if (me.getAction() == MotionEvent.ACTION_POINTER_UP - || me.getAction() == MotionEvent.ACTION_UP) { - pinchDone = false; - } mScaleDetector.onTouchEvent(me); - if (pinchDone) { - return true; - } viewport.resetInertiaScroll(); // zoom control are reset to visible at each touch on the screen controller.setVisible(true); @@ -769,8 +762,23 @@ public class TouchUpReScaleGestureListener implements public void onScaleEnd(ScaleGestureDetector detector) { int zoomOffset = Math.round(viewport.zoomScale) - 1; zoom(zoomOffset); + if (zoomOffset == 0) { + viewport.zoomReset(null); + } + float oldScale = viewport.zoomScale; + if (viewport.zoomScale < 0.5f) { + oldScale = viewport.zoomScale * 2; + + } else if (viewport.zoomScale < 2.0f) { + oldScale = viewport.zoomScale / 2; + } viewport.zoomScale = 1.0f; viewport.refresh(); + if (zoomOffset != 0) { + viewport.zoomReset(oldScale); + } + + pinchDone = true; } @Override @@ -783,7 +791,6 @@ public boolean onScale(ScaleGestureDetector detector) { Log.d(TAG, "zoom ongoing, scale: " + detector.getScaleFactor()); viewport.zoomScale = detector.getScaleFactor(); pinchDone = true; - return false; } diff --git a/src/com/hexagon/map/Tile.java b/src/com/hexagon/map/Tile.java index 5137b0a..5cbddff 100755 --- a/src/com/hexagon/map/Tile.java +++ b/src/com/hexagon/map/Tile.java @@ -69,7 +69,7 @@ public void draw(Canvas canvas, Matrix scaleM, Paint paint) { if (visible && Preferences.drawMap) { m = new Matrix(scaleM); m.preTranslate(posx, posy); - if (image != null && image.bmp != null) { + if (image != null && image.bmp != null && m != null) { if (image.alpha < 255) { Paint paintAlpha = new Paint(paint); canvas.drawBitmap(layer.noSrcBmp, m, paint); diff --git a/src/com/hexagon/map/Viewport.java b/src/com/hexagon/map/Viewport.java index 412d2fe..8df2a6e 100755 --- a/src/com/hexagon/map/Viewport.java +++ b/src/com/hexagon/map/Viewport.java @@ -554,6 +554,20 @@ public void zoomOutAnimated() { screenZoomAnimation.start(); } + public void zoomReset(Float oldScale) { + if (oldScale != null) { + screenZoomAnimation.initialZoom = oldScale; + } else { + screenZoomAnimation.initialZoom = zoomScale; + } + screenZoomAnimation.finalZoom = Math.round(zoomScale); + if (screenZoomAnimation.finalZoom < 0.5f) screenZoomAnimation.finalZoom = 0.5f; + if (screenZoomAnimation.finalZoom > 2.0f) screenZoomAnimation.finalZoom = 2.0f; + screenZoomAnimation.initialize(0, 0, 0, 0); + screenZoomAnimation.start(); + } + + public void moveToLastLocation() { moveToLocation(getCurrentBestLocation()); }