Skip to content

Commit

Permalink
Animated zoom reset
Browse files Browse the repository at this point in the history
  • Loading branch information
jventrib committed Dec 24, 2012
1 parent 0caf461 commit 22179ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/com/hexagon/map/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/hexagon/map/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/com/hexagon/map/Viewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 22179ca

Please sign in to comment.