diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index e69691ad56..7d8d2fcef9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -40,10 +40,11 @@ import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback; -import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.controllers.MapViewController; +import net.osmand.plus.views.controllers.JavaViewController; +import net.osmand.plus.views.controllers.MapViewBaseController; +import net.osmand.plus.views.controllers.NativeViewController; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; import android.app.Dialog; @@ -100,7 +101,7 @@ public class MapActivity extends AccessibleActivity { private StateChangedListener applicationModeListener; private FrameLayout lockView; private GpxImportHelper gpxImportHelper; - private MapViewController mapViewController; + private MapViewBaseController mapViewController; private Notification getNotification() { @@ -135,13 +136,13 @@ public class MapActivity extends AccessibleActivity { if (settings.USE_NATIVE_RENDER.get()){ setContentView(R.layout.activity_gl); - mapViewController = new MapViewController((GLSurfaceView) findViewById(R.id.glSurfaceView), this); + mapViewController = new NativeViewController((GLSurfaceView) findViewById(R.id.glSurfaceView), this); } else { setContentView(R.layout.main); - mapViewController = new MapViewController((OsmandMapTileView) findViewById(R.id.MapView), this); + mapViewController = new JavaViewController((OsmandMapTileView) findViewById(R.id.MapView), this); } - mapViewController.setTrackBallDelegate(new MapViewController.OnTrackBallListener(){ + mapViewController.setTrackBallDelegate(new JavaViewController.OnTrackBallListener(){ @Override public boolean onTrackBallEvent(MotionEvent e) { showAndHideMapPosition(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index ffc7df1de9..adf8a9176d 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -26,7 +26,7 @@ import net.osmand.plus.R; import net.osmand.plus.helpers.SimpleTwoFingerTapDetector; import net.osmand.plus.views.MultiTouchSupport.MultiTouchZoomListener; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; -import net.osmand.plus.views.controllers.MapViewController; +import net.osmand.plus.views.controllers.JavaViewController; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -109,7 +109,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private OnClickListener onClickListener; - private MapViewController.OnTrackBallListener trackBallDelegate; + private JavaViewController.OnTrackBallListener trackBallDelegate; private AccessibilityActionsProvider accessibilityActions; @@ -745,7 +745,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall return super.onTrackballEvent(event); } - public void setTrackBallDelegate(MapViewController.OnTrackBallListener trackBallDelegate) { + public void setTrackBallDelegate(JavaViewController.OnTrackBallListener trackBallDelegate) { this.trackBallDelegate = trackBallDelegate; } diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/MapViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java similarity index 50% rename from OsmAnd/src/net/osmand/plus/views/controllers/MapViewController.java rename to OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java index bf498dd2af..191b4217e2 100644 --- a/OsmAnd/src/net/osmand/plus/views/controllers/MapViewController.java +++ b/OsmAnd/src/net/osmand/plus/views/controllers/JavaViewController.java @@ -23,188 +23,122 @@ import java.util.List; /** * Created by Натали on 29.09.2014. */ -public class MapViewController { +public class JavaViewController extends MapViewBaseController { private GLSurfaceView glSurfaceView; private OsmandMapTileView mapTileView; private OsmandSettings settings; private MapActivity mapActivity; - private boolean isNative = false; private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1; - - public void setAccessibilityActions(MapAccessibilityActions accessibilityActions) { - if (isNative){ - - } else { - mapTileView.setAccessibilityActions(accessibilityActions); - } - } - + @Override public void refreshMap(boolean b) { - if (isNative){ - - } else { - mapTileView.refreshMap(b); - } + mapTileView.refreshMap(b); } - public void createLayers(MapActivityLayers mapLayers) { - if (isNative) { + @Override + public void setAccessibilityActions(MapAccessibilityActions accessibilityActions) { + mapTileView.setAccessibilityActions(accessibilityActions); + } - } else { - mapLayers.createLayers(mapTileView); - } + @Override + public void createLayers(MapActivityLayers mapLayers) { + mapLayers.createLayers(mapTileView); } public void setLatLon(double latitude, double longitude) { - if (isNative){ - - } else { - mapTileView.setLatLon(latitude, longitude); - } + mapTileView.setLatLon(latitude, longitude); } + @Override public void setIntZoom(int i) { - if (isNative) { - - } else { - mapTileView.setIntZoom(i); - } + mapTileView.setIntZoom(i); } + @Override public void addView(FrameLayout view) { - if (isNative) { - - } else { - ((FrameLayout)mapTileView.getParent()).addView(view); - } + ((FrameLayout) mapTileView.getParent()).addView(view); } + @Override public void setTrackingUtilities(MapViewTrackingUtilities mapViewTrackingUtilities) { - if (isNative) { + mapViewTrackingUtilities.setMapView(mapTileView); - } else { - mapViewTrackingUtilities.setMapView(mapTileView); - } } + @Override public void tileDownloaded(MapTileDownloader.DownloadRequest request) { - if (isNative) { - - } else { - mapTileView.tileDownloaded(request); - } + mapTileView.tileDownloaded(request); } + @Override public ViewParent getParentView() { - if (isNative) { - return glSurfaceView.getParent(); - } else { - return mapTileView.getParent(); - } + return mapTileView.getParent(); } + @Override public List getLayers() { - if (isNative) { - - } else { - return mapTileView.getLayers(); - } - return null; + return mapTileView.getLayers(); } + @Override public double getLatitude() { - if (isNative){ - - } else { - return mapTileView.getLatitude(); - } - return 0; + return mapTileView.getLatitude(); } + @Override public double getLongitude() { - if (isNative){ + return mapTileView.getLongitude(); - } else { - return mapTileView.getLongitude(); - } - return 0; } + @Override public void startMoving(double latitude, double longitude, int mapZoomToShow, boolean b) { - if (isNative){ - - } else { - mapTileView.getAnimatedDraggingThread().startMoving(latitude, longitude, - settings.getMapZoomToShow(), true); - } - + mapTileView.getAnimatedDraggingThread().startMoving(latitude, longitude, + settings.getMapZoomToShow(), true); } + @Override public int getZoom() { - if (isNative) { - - } else { - return mapTileView.getZoom(); - } - return 0; + return mapTileView.getZoom(); } + @Override public void startZooming(int newZoom, boolean changeLocation) { - if (isNative){ - - } else { - mapTileView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation); - } + mapTileView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation); } + @Override public boolean isZooming() { - if (isNative){ - - } else { - return mapTileView.isZooming(); - } - return false; + return mapTileView.isZooming(); } + @Override public RotatedTileBox getCurrentRotatedTileBox() { - if (isNative) { + return mapTileView.getCurrentRotatedTileBox(); - } else { - return mapTileView.getCurrentRotatedTileBox(); - } - return null; } + @Override public void onPause() { - if (isNative) { - - } else { - AnimateDraggingMapThread animatedThread = mapTileView.getAnimatedDraggingThread(); - if(animatedThread.isAnimating() && animatedThread.getTargetIntZoom() != 0){ - settings.setMapLocationToShow(animatedThread.getTargetLatitude(), animatedThread.getTargetLongitude(), - animatedThread.getTargetIntZoom()); - } + AnimateDraggingMapThread animatedThread = mapTileView.getAnimatedDraggingThread(); + if (animatedThread.isAnimating() && animatedThread.getTargetIntZoom() != 0) { + settings.setMapLocationToShow(animatedThread.getTargetLatitude(), animatedThread.getTargetLongitude(), + animatedThread.getTargetIntZoom()); } } + @Override public void updateLayers(MapActivityLayers mapLayers) { - if (isNative) { - - } else { - mapLayers.updateLayers(mapTileView); - } + mapLayers.updateLayers(mapTileView); } + @Override public void setComplexZoom() { - if (isNative) { - - } else { - mapTileView.setComplexZoom(mapTileView.getZoom(), mapTileView.getSettingsZoomScale()); - } + mapTileView.setComplexZoom(mapTileView.getZoom(), mapTileView.getSettingsZoomScale()); } + @Override public void showAndHideMapPosition() { mapTileView.setShowMapPosition(true); mapActivity.getMyApplication().runMessageInUIThreadAndCancelPrevious(SHOW_POSITION_MSG_ID, new Runnable() { @@ -218,41 +152,20 @@ public class MapViewController { }, 2500); } + @Override public OsmandMapTileView getMapTileView() { - if (isNative) { - - } else { - return mapTileView; - } - return null; + return mapTileView; } - - public interface OnTrackBallListener { - public boolean onTrackBallEvent(MotionEvent e); - } - - public MapViewController(GLSurfaceView surfaceView, MapActivity activity){ - this.glSurfaceView = surfaceView; - this.settings = activity.getMyApplication().getSettings(); - this.mapActivity = activity; - isNative = true; - - } - - public MapViewController(OsmandMapTileView mapTileView, MapActivity activity){ + public JavaViewController(OsmandMapTileView mapTileView, MapActivity activity) { this.mapTileView = mapTileView; this.settings = activity.getMyApplication().getSettings(); this.mapActivity = activity; - isNative = false; } + @Override public void setTrackBallDelegate(OnTrackBallListener trackBallDelegate) { - if (isNative){ - - } else { - mapTileView.setTrackBallDelegate(trackBallDelegate); - } + mapTileView.setTrackBallDelegate(trackBallDelegate); } } diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/MapViewBaseController.java b/OsmAnd/src/net/osmand/plus/views/controllers/MapViewBaseController.java new file mode 100644 index 0000000000..3603aed8cb --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/controllers/MapViewBaseController.java @@ -0,0 +1,102 @@ +package net.osmand.plus.views.controllers; + +import android.view.MotionEvent; +import android.view.ViewParent; +import android.widget.FrameLayout; +import net.osmand.access.MapAccessibilityActions; +import net.osmand.data.RotatedTileBox; +import net.osmand.map.MapTileDownloader; +import net.osmand.plus.activities.MapActivityLayers; +import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.OsmandMapLayer; +import net.osmand.plus.views.OsmandMapTileView; + +import java.util.List; + +/** + * Created by Denis on 01.10.2014. + */ +public abstract class MapViewBaseController { + + public void setAccessibilityActions(MapAccessibilityActions accessibilityActions) { + } + + public void refreshMap(boolean b) { + } + + public void createLayers(MapActivityLayers mapLayers) { + } + + public void setLatLon(double latitude, double longitude) { + } + + public void setIntZoom(int i) { + } + + public void addView(FrameLayout view) { + } + + public void setTrackingUtilities(MapViewTrackingUtilities mapViewTrackingUtilities) { + } + + public void tileDownloaded(MapTileDownloader.DownloadRequest request) { + } + + public ViewParent getParentView() { + return null; + } + + public List getLayers() { + return null; + } + + public double getLatitude() { + return 0; + } + + public double getLongitude() { + return 0; + } + + public void startMoving(double latitude, double longitude, int mapZoomToShow, boolean b) { + } + + public int getZoom() { + return 0; + } + + public void startZooming(int newZoom, boolean changeLocation) { + } + + public boolean isZooming() { + return false; + } + + public RotatedTileBox getCurrentRotatedTileBox() { + return null; + } + + public void onPause() { + } + + public void updateLayers(MapActivityLayers mapLayers) { + } + + public void setComplexZoom() { + } + + public void showAndHideMapPosition() { + } + + public OsmandMapTileView getMapTileView() { + return null; + } + + public void setTrackBallDelegate(OnTrackBallListener trackBallDelegate) { + } + + public interface OnTrackBallListener { + public boolean onTrackBallEvent(MotionEvent e); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java new file mode 100644 index 0000000000..48b94c364a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/controllers/NativeViewController.java @@ -0,0 +1,147 @@ +package net.osmand.plus.views.controllers; + +import android.opengl.GLSurfaceView; +import android.view.ViewParent; +import android.widget.FrameLayout; +import net.osmand.access.MapAccessibilityActions; +import net.osmand.data.RotatedTileBox; +import net.osmand.map.MapTileDownloader; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.MapActivityLayers; +import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.views.OsmandMapLayer; +import net.osmand.plus.views.OsmandMapTileView; + +import java.util.List; + +/** + * Created by Denis on 01.10.2014. + */ +public class NativeViewController extends MapViewBaseController { + private GLSurfaceView glSurfaceView; + private OsmandSettings settings; + private MapActivity mapActivity; + + + public NativeViewController(GLSurfaceView surfaceView, MapActivity activity) { + this.glSurfaceView = surfaceView; + this.settings = activity.getMyApplication().getSettings(); + this.mapActivity = activity; + } + + @Override + public void setTrackBallDelegate(OnTrackBallListener trackBallDelegate) { + super.setTrackBallDelegate(trackBallDelegate); + } + + @Override + public void setAccessibilityActions(MapAccessibilityActions accessibilityActions) { + super.setAccessibilityActions(accessibilityActions); + } + + @Override + public void refreshMap(boolean b) { + super.refreshMap(b); + } + + @Override + public void createLayers(MapActivityLayers mapLayers) { + super.createLayers(mapLayers); + } + + @Override + public void setLatLon(double latitude, double longitude) { + super.setLatLon(latitude, longitude); + } + + @Override + public void setIntZoom(int i) { + super.setIntZoom(i); + } + + @Override + public void addView(FrameLayout view) { + super.addView(view); + } + + @Override + public void setTrackingUtilities(MapViewTrackingUtilities mapViewTrackingUtilities) { + super.setTrackingUtilities(mapViewTrackingUtilities); + } + + @Override + public void tileDownloaded(MapTileDownloader.DownloadRequest request) { + super.tileDownloaded(request); + } + + @Override + public ViewParent getParentView() { + return super.getParentView(); + } + + @Override + public List getLayers() { + return super.getLayers(); + } + + @Override + public double getLatitude() { + return super.getLatitude(); + } + + @Override + public double getLongitude() { + return super.getLongitude(); + } + + @Override + public void startMoving(double latitude, double longitude, int mapZoomToShow, boolean b) { + super.startMoving(latitude, longitude, mapZoomToShow, b); + } + + @Override + public int getZoom() { + return super.getZoom(); + } + + @Override + public void startZooming(int newZoom, boolean changeLocation) { + super.startZooming(newZoom, changeLocation); + } + + @Override + public boolean isZooming() { + return super.isZooming(); + } + + @Override + public RotatedTileBox getCurrentRotatedTileBox() { + return super.getCurrentRotatedTileBox(); + } + + @Override + public void onPause() { + super.onPause(); + } + + @Override + public void updateLayers(MapActivityLayers mapLayers) { + super.updateLayers(mapLayers); + } + + @Override + public void setComplexZoom() { + super.setComplexZoom(); + } + + @Override + public void showAndHideMapPosition() { + super.showAndHideMapPosition(); + } + + @Override + public OsmandMapTileView getMapTileView() { + return super.getMapTileView(); + } +}