diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 0f4fe7cb0a..dd6d5878f3 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -19,8 +19,7 @@ public class ToDoConstants { // 60. Audio guidance for routing ! // 68. Implement service to app work with screen offline // (introduce special settings how often update location to monitoring & audio guidance) - // 69. Multitouch zoom, animated zoom, animate map shift! - // check everywhere float zoom + // 69. Multitouch zoom, animated zoom, animate map shift (when select some point to see)! // Improvement : Show stops in the transport route on the map // Not clear if it is really needed diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 1fbc13d379..d76db287c8 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -228,7 +228,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso zoomControls.setOnZoomInClickListener(new OnClickListener() { @Override public void onClick(View v) { - mapView.setZoom(mapView.getZoom() + 1); + mapView.getAnimatedDraggingThread().startZooming(mapView.getZoom(), mapView.getZoom() + 1); showAndHideMapPosition(); // user can preview map manually switch off auto zoom while user don't press back to location if(OsmandSettings.isAutoZoomEnabled(MapActivity.this)){ @@ -239,7 +239,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso zoomControls.setOnZoomOutClickListener(new OnClickListener() { @Override public void onClick(View v) { - mapView.setZoom(mapView.getZoom() - 1); + mapView.getAnimatedDraggingThread().startZooming(mapView.getZoom(), mapView.getZoom() - 1); showAndHideMapPosition(); // user can preview map manually switch off auto zoom while user don't press back to location if(OsmandSettings.isAutoZoomEnabled(MapActivity.this)){ diff --git a/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java b/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java index 0f0c55e416..87a39472c6 100644 --- a/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/com/osmand/views/AnimateDraggingMapThread.java @@ -6,9 +6,15 @@ package com.osmand.views; */ public class AnimateDraggingMapThread implements Runnable { public interface AnimateDraggingCallback { + public void dragTo(float curX, float curY, float newX, float newY); + public void zoomTo(float zoom); + } + private int endZ; + private float curZ; + private int timeZ; private float curX; private float curY; @@ -18,6 +24,7 @@ public class AnimateDraggingMapThread implements Runnable { private float ay; private byte dirX; private byte dirY; + private byte dirZ; private long time; private volatile boolean stopped; private final float a = 0.001f; @@ -30,20 +37,42 @@ public class AnimateDraggingMapThread implements Runnable { public void run() { currentThread = Thread.currentThread(); try { - while (!stopped && (vx > 0 || vy > 0)) { - Thread.sleep((long) (40d / (Math.max(vx, vy) + 0.45))); + while (!stopped && (vx > 0 || vy > 0 || curZ != endZ)) { + // calculate sleep + long sleep = 0; + if(vx > 0 || vy > 0){ + sleep = (long) (40d / (Math.max(vx, vy) + 0.45)); + } else { + sleep = 80; + } + Thread.sleep(sleep); long curT = System.currentTimeMillis(); int dt = (int) (curT - time); float newX = vx > 0 ? curX + dirX * vx * dt : curX; float newY = vy > 0 ? curY + dirY * vy * dt : curY; + + float newZ = curZ; + if(timeZ > 0){ + newZ = newZ + dirZ * (float)dt / timeZ; + if(dirZ > 0 == newZ > endZ){ + newZ = endZ; + } + } if (!stopped && callback != null) { callback.dragTo(curX, curY, newX, newY); + if(newZ > 0){ + callback.zoomTo(newZ); + } } vx -= ax * dt; vy -= ay * dt; time = curT; curX = newX; curY = newY; + curZ = newZ; + } + if(curZ != endZ && endZ > 0){ + callback.zoomTo(endZ); } } catch (InterruptedException e) { } @@ -54,14 +83,14 @@ public class AnimateDraggingMapThread implements Runnable { /** * Stop dragging async */ - public void stopDragging(){ + public void stopAnimating(){ stopped = true; } /** * Stop dragging sync */ - public void stopDraggingSync(){ + public void stopAnimatingSync(){ // wait until current thread != null stopped = true; while(currentThread != null){ @@ -72,6 +101,22 @@ public class AnimateDraggingMapThread implements Runnable { } } + public void startZooming(int zoomStart, int zoomEnd){ + stopAnimatingSync(); + if(zoomStart < zoomEnd){ + dirZ = 1; + } else { + dirZ = -1; + } + curZ = zoomStart; + endZ = zoomEnd; + timeZ = 600; + time = System.currentTimeMillis(); + stopped = false; + Thread thread = new Thread(this,"Animatable dragging"); //$NON-NLS-1$ + thread.start(); + } + public void startDragging(float dTime, float startX, float startY, float endX, float endY){ vx = Math.abs((endX - startX)/dTime); vy = Math.abs((endY - startY)/dTime); @@ -79,7 +124,7 @@ public class AnimateDraggingMapThread implements Runnable { } public void startDragging(float velocityX, float velocityY, float startX, float startY, float endX, float endY){ - stopDraggingSync(); + stopAnimatingSync(); vx = velocityX; vy = velocityY; dirX = (byte) (endX > startX ? 1 : -1); diff --git a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java index 332a24009d..0751563fba 100644 --- a/OsmAnd/src/com/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/com/osmand/views/OsmandMapTileView.java @@ -218,17 +218,24 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall public void setZoom(float zoom){ if (map == null || (map.getMaximumZoomSupported() >= zoom && map.getMinimumZoomSupported() <= zoom)) { - animatedDraggingThread.stopDragging(); + animatedDraggingThread.stopAnimating(); this.zoom = zoom; refreshMap(); } } + // for internal usage + @Override + public void zoomTo(float zoom) { + this.zoom = zoom; + refreshMap(); + } + public void setRotate(float rotate) { float dif = this.rotate - rotate; if (dif > 2 || dif < -2) { this.rotate = rotate; - animatedDraggingThread.stopDragging(); + animatedDraggingThread.stopAnimating(); refreshMap(); } } @@ -262,7 +269,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } public void setLatLon(double latitude, double longitude){ - animatedDraggingThread.stopDragging(); + animatedDraggingThread.stopAnimating(); this.latitude = latitude; this.longitude = longitude; refreshMap(); @@ -631,7 +638,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ - animatedDraggingThread.stopDragging(); + animatedDraggingThread.stopAnimating(); } if (!multiTouchSupport.onTouchEvent(event)) { /* return */gestureDetector.onTouchEvent(event); @@ -671,7 +678,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall @Override public boolean onDown(MotionEvent e) { - animatedDraggingThread.stopDragging(); + animatedDraggingThread.stopAnimating(); return false; } @@ -701,6 +708,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall animatedDraggingThread.startDragging(Math.abs(velocityX/1000), Math.abs(velocityY/1000), e1.getX(), e1.getY(), e2.getX(), e2.getY()); return true; } + + public AnimateDraggingMapThread getAnimatedDraggingThread() { + return animatedDraggingThread; + } @Override public void onLongPress(MotionEvent e) {