diff --git a/OsmAnd/src/net/osmand/plus/ClientContext.java b/OsmAnd/src/net/osmand/plus/ClientContext.java index 558828e037..48cbd8c6b4 100644 --- a/OsmAnd/src/net/osmand/plus/ClientContext.java +++ b/OsmAnd/src/net/osmand/plus/ClientContext.java @@ -5,7 +5,6 @@ import java.io.File; import net.osmand.Location; import net.osmand.plus.api.ExternalServiceAPI; import net.osmand.plus.api.InternalOsmAndAPI; -import net.osmand.plus.api.InternalToDoAPI; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.render.RendererRegistry; @@ -35,8 +34,6 @@ public interface ClientContext { public ExternalServiceAPI getExternalServiceAPI(); - public InternalToDoAPI getTodoAPI(); - public InternalOsmAndAPI getInternalAPI(); public SQLiteAPI getSQLiteAPI(); diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 27aac2c31e..5389e6c2e2 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -17,14 +17,14 @@ public class CurrentPositionHelper { private Location lastAskedLocation = null; private Thread calculatingThread = null; private RoutingContext ctx; - private ClientContext app; + private OsmandApplication app; private ApplicationMode am; - public CurrentPositionHelper(ClientContext app) { + public CurrentPositionHelper(OsmandApplication app) { this.app = app; } - private void initCtx(ClientContext app) { + private void initCtx(OsmandApplication app) { am = app.getSettings().getApplicationMode(); GeneralRouterProfile p ; if (am.isDerivedRoutingFrom(ApplicationMode.BICYCLE)) { @@ -37,7 +37,7 @@ public class CurrentPositionHelper { return; } RoutingConfiguration cfg = RoutingConfiguration.getDefault().build(p.name().toLowerCase(), 10); - ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getTodoAPI().getRoutingMapFiles()); + ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles()); } private RouteDataObject runUpdateInThread(Location loc) { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index f6982b1d5e..e47dbda2fc 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -28,7 +28,6 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.api.ExternalServiceAPI; import net.osmand.plus.api.InternalOsmAndAPI; -import net.osmand.plus.api.InternalToDoAPI; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.api.SettingsAPI; @@ -107,7 +106,6 @@ public class OsmandApplication extends Application implements ClientContext { SettingsAPI settingsAPI; ExternalServiceAPI externalServiceAPI; - InternalToDoAPI internalToDoAPI; InternalOsmAndAPI internalOsmAndAPI; SQLiteAPI sqliteAPI; BRouterServiceConnection bRouterServiceConnection; @@ -128,7 +126,6 @@ public class OsmandApplication extends Application implements ClientContext { settingsAPI = new net.osmand.plus.api.SettingsAPIImpl(this); externalServiceAPI = new net.osmand.plus.api.ExternalServiceAPIImpl(this); - internalToDoAPI = new net.osmand.plus.api.InternalToDoAPIImpl(this); internalOsmAndAPI = new net.osmand.plus.api.InternalOsmAndAPIImpl(this); sqliteAPI = new SQLiteAPIImpl(this); @@ -696,11 +693,6 @@ public class OsmandApplication extends Application implements ClientContext { return externalServiceAPI; } - @Override - public InternalToDoAPI getTodoAPI() { - return internalToDoAPI; - } - @Override public InternalOsmAndAPI getInternalAPI() { return internalOsmAndAPI; diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index ef5f3af74a..3099a28ae8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -916,7 +916,7 @@ public class OsmandSettings { if (!dir.exists()) { return checkAmongAvailableTileSources(dir, knownTemplates); } else if (tileName.endsWith(IndexConstants.SQLITE_EXT)) { - return ctx.getTodoAPI().newSqliteTileSource(dir, knownTemplates); + return new SQLiteTileSource(ctx, dir, knownTemplates); } else if (dir.isDirectory() && !dir.getName().startsWith(".")) { TileSourceTemplate t = TileSourceManager.createTileSourceTemplate(dir); if (warnWhenSelected && !t.isRuleAcceptable()) { diff --git a/OsmAnd/src/net/osmand/plus/api/InternalToDoAPI.java b/OsmAnd/src/net/osmand/plus/api/InternalToDoAPI.java deleted file mode 100644 index 21b1f3a186..0000000000 --- a/OsmAnd/src/net/osmand/plus/api/InternalToDoAPI.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.osmand.plus.api; - -import java.io.File; -import java.util.List; - -import net.osmand.binary.BinaryMapIndexReader; -import net.osmand.map.ITileSource; -import net.osmand.map.TileSourceManager.TileSourceTemplate; - -public interface InternalToDoAPI { - - public BinaryMapIndexReader[] getRoutingMapFiles(); - - public ITileSource newSqliteTileSource(File dir, List knownTemplates); - - -} diff --git a/OsmAnd/src/net/osmand/plus/api/InternalToDoAPIImpl.java b/OsmAnd/src/net/osmand/plus/api/InternalToDoAPIImpl.java deleted file mode 100644 index 21b0b90f99..0000000000 --- a/OsmAnd/src/net/osmand/plus/api/InternalToDoAPIImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package net.osmand.plus.api; - -import java.io.File; -import java.util.List; - -import net.osmand.binary.BinaryMapIndexReader; -import net.osmand.map.ITileSource; -import net.osmand.map.TileSourceManager.TileSourceTemplate; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.SQLiteTileSource; - -public class InternalToDoAPIImpl implements InternalToDoAPI { - - private OsmandApplication app; - - public InternalToDoAPIImpl(OsmandApplication app) { - this.app = app; - } - - @Override - public BinaryMapIndexReader[] getRoutingMapFiles() { - return app.getResourceManager().getRoutingMapFiles(); - } - - @Override - public ITileSource newSqliteTileSource(File dir, List knownTemplates) { - return new SQLiteTileSource(app, dir, knownTemplates); - } - -} diff --git a/OsmAnd/src/net/osmand/plus/api/RendererAPI.java b/OsmAnd/src/net/osmand/plus/api/RendererAPI.java deleted file mode 100644 index f95f15fa9c..0000000000 --- a/OsmAnd/src/net/osmand/plus/api/RendererAPI.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.osmand.plus.api; - -import net.osmand.plus.api.render.Paint; - -public interface RendererAPI { - - public Paint newPaint(); - -} diff --git a/OsmAnd/src/net/osmand/plus/api/render/Canvas.java b/OsmAnd/src/net/osmand/plus/api/render/Canvas.java deleted file mode 100644 index e767e66c61..0000000000 --- a/OsmAnd/src/net/osmand/plus/api/render/Canvas.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.osmand.plus.api.render; - -public interface Canvas { - -} diff --git a/OsmAnd/src/net/osmand/plus/api/render/Color.java b/OsmAnd/src/net/osmand/plus/api/render/Color.java deleted file mode 100644 index 5df8aad7fc..0000000000 --- a/OsmAnd/src/net/osmand/plus/api/render/Color.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.osmand.plus.api.render; - -public class Color { - public static final int BLACK = 0xFF000000; - public static final int DKGRAY = 0xFF444444; - public static final int GRAY = 0xFF888888; - public static final int LTGRAY = 0xFFCCCCCC; - public static final int WHITE = 0xFFFFFFFF; - public static final int RED = 0xFFFF0000; - public static final int GREEN = 0xFF00FF00; - public static final int BLUE = 0xFF0000FF; - public static final int YELLOW = 0xFFFFFF00; - public static final int CYAN = 0xFF00FFFF; - public static final int MAGENTA = 0xFFFF00FF; - public static final int TRANSPARENT = 0; - - public static int rgb(int red, int green, int blue) { - return (0xFF << 24) | (red << 16) | (green << 8) | blue; - } - - public static int argb(int alpha, int red, int green, int blue) { - return (alpha << 24) | (red << 16) | (green << 8) | blue; - } -} diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java index 7eda974098..ed95bc19ba 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java @@ -5,7 +5,7 @@ import java.util.List; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.ClientContext; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.router.RouteCalculationProgress; @@ -16,7 +16,7 @@ public class RouteCalculationParams { public LatLon end; public List intermediates; - public ClientContext ctx; + public OsmandApplication ctx; public ApplicationMode mode; public RouteService type; public GPXRouteParams gpxRoute; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 4374a2ce9c..7113106661 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -431,7 +431,7 @@ public class RouteProvider { } protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params, boolean calcGPXRoute) throws IOException { - BinaryMapIndexReader[] files = params.ctx.getTodoAPI().getRoutingMapFiles(); + BinaryMapIndexReader[] files = params.ctx.getResourceManager().getRoutingMapFiles(); RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false); OsmandSettings settings = params.ctx.getSettings(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 32d79603ef..606f63099d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -5,6 +5,7 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.views.controls.MapControls; import net.osmand.plus.views.controls.MapMenuControls; import net.osmand.plus.views.controls.MapZoomControls; import android.graphics.Canvas; @@ -26,14 +27,13 @@ import android.widget.SeekBar; public class MapControlsLayer extends OsmandMapLayer { private static final int HOVER_COLOR = 0xffC8C8C8; - + private static final int TIMEOUT_TO_SHOW_BUTTONS = 5000; private final MapActivity mapActivity; - - private int shadowColor = Color.WHITE; + private int shadowColor; private MapZoomControls zoomControls; private MapMenuControls mapMenuControls; - + private RulerControl rulerControl; private float scaleCoefficient; @@ -41,16 +41,13 @@ public class MapControlsLayer extends OsmandMapLayer { private LinearLayout transparencyBarLayout; private static CommonPreference settingsToTransparency; - private Drawable rulerDrawable; - private TextPaint rulerTextPaint; - private final static double screenRulerPercent = 0.25; + public MapControlsLayer(MapActivity activity){ this.mapActivity = activity; } - @Override public boolean drawInScreenPixels() { return true; @@ -65,10 +62,9 @@ public class MapControlsLayer extends OsmandMapLayer { zoomControls.init(parent); mapMenuControls = new MapMenuControls(mapActivity, showUIHandler, scaleCoefficient); mapMenuControls.init(parent); - mapMenuControls.show(parent); - initRuler(view, parent); + rulerControl = new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient); + rulerControl.init(parent); initTransparencyBar(view, parent); - } @Override @@ -84,34 +80,47 @@ public class MapControlsLayer extends OsmandMapLayer { if(shadowColor != sh) { shadowColor = sh; int textColor = sh == Color.WHITE ? Color.BLACK : HOVER_COLOR; - rulerTextPaint.setColor(textColor); + rulerControl.setShadowColor(textColor, sh); zoomControls.setShadowColor(textColor, sh); mapMenuControls.setShadowColor(textColor, sh); } - boolean showZooms = !mapActivity.getRoutingHelper().isRouteCalculated(); - if(showZooms != zoomControls.isVisible()){ - if(showZooms) { - zoomControls.show((FrameLayout) mapActivity.getMapView().getParent()); - } else { - zoomControls.hide((FrameLayout) mapActivity.getMapView().getParent()); - } - } - if(showZooms) { - zoomControls.onDraw(canvas, tileBox, nightMode); - } - mapMenuControls.onDraw(canvas, tileBox, nightMode); - drawRuler(canvas, tileBox, nightMode); + boolean showZooms = false; //!mapActivity.getRoutingHelper().isRouteCalculated() && !mapActivity.getRoutingHelper().isFollowingMode(); + checkVisibilityAndDraw(showZooms, zoomControls, canvas, tileBox, nightMode); + + boolean showMenu = false;// !mapActivity.getRoutingHelper().isFollowingMode(); + checkVisibilityAndDraw(showMenu, mapMenuControls, canvas, tileBox, nightMode); + + checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode); } + private void checkVisibilityAndDraw(boolean visibility, MapControls controls, Canvas canvas, + RotatedTileBox tileBox, DrawSettings nightMode) { + if(visibility != controls.isVisible()){ + if(visibility) { + controls.show((FrameLayout) mapActivity.getMapView().getParent()); + } else { + controls.hide((FrameLayout) mapActivity.getMapView().getParent()); + } + } + if(controls.isVisible()) { + controls.onDraw(canvas, tileBox, nightMode); + } + } + + @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { - if(mapMenuControls.onSingleTap(point, tileBox)) { - return true; - } - if(zoomControls.isVisible() && zoomControls.onSingleTap(point, tileBox)) { + zoomControls.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS); + mapMenuControls.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS); + if(mapMenuControls.isVisible() && mapMenuControls.onSingleTap(point, tileBox)) { return true; } + if(zoomControls.isVisible() ) { + if(zoomControls.onSingleTap(point, tileBox)) { + return true; + } + } return false; } @@ -183,54 +192,89 @@ public class MapControlsLayer extends OsmandMapLayer { /////////////////////// Ruler /////////////////// // cache values for ruler - ShadowText cacheRulerText = null; - float cacheRulerZoom = 0; - double cacheRulerTileX = 0; - double cacheRulerTileY = 0; - float cacheRulerTextLen = 0; + public static class RulerControl extends MapControls { - private void initRuler(OsmandMapTileView view, FrameLayout parent) { - rulerTextPaint = new TextPaint(); - rulerTextPaint.setTextSize(20 * scaleCoefficient); - rulerTextPaint.setAntiAlias(true); - rulerDrawable = view.getResources().getDrawable(R.drawable.ruler); - } - - private void drawRuler(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { - if( (zoomControls.isVisible() && zoomControls.isShowZoomLevel()) || !mapActivity.getMyApplication().getSettings().SHOW_RULER.get()){ - return; + ShadowText cacheRulerText = null; + float cacheRulerZoom = 0; + double cacheRulerTileX = 0; + double cacheRulerTileY = 0; + float cacheRulerTextLen = 0; + MapZoomControls zoomControls; + Drawable rulerDrawable; + TextPaint rulerTextPaint; + final static double screenRulerPercent = 0.25; + + public RulerControl(MapZoomControls zoomControls, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { + super(mapActivity, showUIHandler, scaleCoefficient); + this.zoomControls = zoomControls; } - OsmandMapTileView view = mapActivity.getMapView(); - // update cache - if (view.isZooming()) { - cacheRulerText = null; - } else if((tb.getZoom() + tb.getZoomScale()) != cacheRulerZoom || - Math.abs(tb.getCenterTileX() - cacheRulerTileX) + Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1){ - cacheRulerZoom = (tb.getZoom() + tb.getZoomScale()); - cacheRulerTileX = tb.getCenterTileX(); - cacheRulerTileY = tb.getCenterTileY(); - final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); - double pixDensity = tb.getPixWidth() / dist; + + @Override + public int getWidth() { + return 0; + } + + @Override + protected void hideControls(FrameLayout layout) { + } + + @Override + public void setShadowColor(int textColor, int shadowColor) { + super.setShadowColor(textColor, shadowColor); + rulerTextPaint.setColor(textColor); + } + + @Override + protected void showControls(FrameLayout layout) { + rulerTextPaint = new TextPaint(); + rulerTextPaint.setTextSize(20 * scaleCoefficient); + rulerTextPaint.setAntiAlias(true); + rulerDrawable = mapActivity.getResources().getDrawable(R.drawable.ruler); + } + + @Override + public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { + if( (zoomControls.isVisible() && zoomControls.isShowZoomLevel()) || !mapActivity.getMyApplication().getSettings().SHOW_RULER.get()){ + return; + } + OsmandMapTileView view = mapActivity.getMapView(); + // update cache + if (view.isZooming()) { + cacheRulerText = null; + } else if((tb.getZoom() + tb.getZoomScale()) != cacheRulerZoom || + Math.abs(tb.getCenterTileX() - cacheRulerTileX) + Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1){ + cacheRulerZoom = (tb.getZoom() + tb.getZoomScale()); + cacheRulerTileX = tb.getCenterTileX(); + cacheRulerTileY = tb.getCenterTileY(); + final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); + double pixDensity = tb.getPixWidth() / dist; + + double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication()); + + int cacheRulerDistPix = (int) (pixDensity * roundedDist); + cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication())); + cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText()); + Rect bounds = rulerDrawable.getBounds(); + bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient); + bounds.bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight())); + bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight(); + bounds.left = bounds.right - cacheRulerDistPix; + rulerDrawable.setBounds(bounds); + } - double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication()); - - int cacheRulerDistPix = (int) (pixDensity * roundedDist); - cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication())); - cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText()); - - Rect bounds = rulerDrawable.getBounds(); - bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient); - bounds.bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight())); - bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight(); - bounds.left = bounds.right - cacheRulerDistPix; - rulerDrawable.setBounds(bounds); - } - if (cacheRulerText != null) { - rulerDrawable.draw(canvas); - Rect bounds = rulerDrawable.getBounds(); - cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient, - rulerTextPaint, shadowColor); + + if (cacheRulerText != null) { + Rect bounds = rulerDrawable.getBounds(); + int bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight())); + if(bounds.bottom != bottom) { + bounds.bottom = bottom; + rulerDrawable.setBounds(bounds); + } + rulerDrawable.draw(canvas); + cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient, + rulerTextPaint, shadowColor); + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java index 95a02afe00..28f46000d0 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java @@ -16,6 +16,7 @@ public abstract class MapControls { protected Handler showUIHandler; protected int shadowColor; private boolean visible; + private long delayTime; public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { this.mapActivity = mapActivity; @@ -36,9 +37,38 @@ public abstract class MapControls { showControls(layout); } + public final void showWithDelay(final FrameLayout layout, final long delay) { + this.delayTime = System.currentTimeMillis() + delay; + if(!visible) { + visible = true; + showControls(layout); + runWithDelay(layout, delay); + mapActivity.getMapView().refreshMap(); + } + } + + private void runWithDelay(final FrameLayout layout, final long delay) { + showUIHandler.postDelayed(new Runnable() { + @Override + public void run() { + long ctime = System.currentTimeMillis(); + if(MapControls.this.delayTime <= ctime) { + MapControls.this.delayTime = 0; + visible = false; + hideControls(layout); + mapActivity.getMapView().refreshMap(); + } else { + runWithDelay(layout, MapControls.this.delayTime - ctime); + } + } + }, delay); + } + public final void hide(FrameLayout layout) { - visible = false; - hideControls(layout); + if(this.delayTime == 0) { + visible = false; + hideControls(layout); + } } public boolean isVisible() { diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java index 9e3b6ca3ef..e50dcf894a 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java @@ -73,6 +73,7 @@ public class MapMenuControls extends MapControls { @Override public void hideControls(FrameLayout layout) { + layout.removeView(backToMenuButton); mapActivity.accessibleContent.remove(backToMenuButton); } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java index 70ad2c2054..4432d2f203 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapZoomControls.java @@ -116,15 +116,12 @@ public class MapZoomControls extends MapControls { } - @Override - public int getWidth() { - return 0; // TODO - } - @Override public void hideControls(FrameLayout layout) { mapActivity.accessibleContent.remove(zoomInButton); mapActivity.accessibleContent.remove(zoomOutButton); + layout.removeView(zoomInButton); + layout.removeView(zoomOutButton); } private void drawZoomLevel(Canvas canvas, RotatedTileBox tb, boolean drawZoomLevel) { @@ -234,5 +231,11 @@ public class MapZoomControls extends MapControls { Drawable buttonDrawable = view.getResources().getDrawable(R.drawable.map_zoom_in); return buttonDrawable.getMinimumHeight(); } + + @Override + public int getWidth() { + Drawable buttonDrawable = view.getResources().getDrawable(R.drawable.map_zoom_in); + return buttonDrawable.getMinimumWidth() + buttonDrawable.getMinimumWidth(); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/controls/RulerControl.java b/OsmAnd/src/net/osmand/plus/views/controls/RulerControl.java new file mode 100644 index 0000000000..99bf9b05d6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/controls/RulerControl.java @@ -0,0 +1,100 @@ +package net.osmand.plus.views.controls; + +import net.osmand.data.RotatedTileBox; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.views.OsmandMapLayer.DrawSettings; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.ShadowText; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.os.Handler; +import android.text.TextPaint; +import android.widget.FrameLayout; + +public class RulerControl extends MapControls { + + ShadowText cacheRulerText = null; + float cacheRulerZoom = 0; + double cacheRulerTileX = 0; + double cacheRulerTileY = 0; + float cacheRulerTextLen = 0; + MapZoomControls zoomControls; + Drawable rulerDrawable; + TextPaint rulerTextPaint; + final static double screenRulerPercent = 0.25; + + public RulerControl(MapZoomControls zoomControls, MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { + super(mapActivity, showUIHandler, scaleCoefficient); + this.zoomControls = zoomControls; + } + + @Override + public int getWidth() { + return 0; + } + + @Override + protected void hideControls(FrameLayout layout) { + } + + @Override + public void setShadowColor(int textColor, int shadowColor) { + super.setShadowColor(textColor, shadowColor); + rulerTextPaint.setColor(textColor); + } + + @Override + protected void showControls(FrameLayout layout) { + rulerTextPaint = new TextPaint(); + rulerTextPaint.setTextSize(20 * scaleCoefficient); + rulerTextPaint.setAntiAlias(true); + rulerDrawable = mapActivity.getResources().getDrawable(R.drawable.ruler); + } + + @Override + public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { + if( (zoomControls.isVisible() && zoomControls.isShowZoomLevel()) || !mapActivity.getMyApplication().getSettings().SHOW_RULER.get()){ + return; + } + OsmandMapTileView view = mapActivity.getMapView(); + // update cache + if (view.isZooming()) { + cacheRulerText = null; + } else if((tb.getZoom() + tb.getZoomScale()) != cacheRulerZoom || + Math.abs(tb.getCenterTileX() - cacheRulerTileX) + Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1){ + cacheRulerZoom = (tb.getZoom() + tb.getZoomScale()); + cacheRulerTileX = tb.getCenterTileX(); + cacheRulerTileY = tb.getCenterTileY(); + final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2); + double pixDensity = tb.getPixWidth() / dist; + + double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication()); + + int cacheRulerDistPix = (int) (pixDensity * roundedDist); + cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication())); + cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText()); + Rect bounds = rulerDrawable.getBounds(); + bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient); + bounds.bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight())); + bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight(); + bounds.left = bounds.right - cacheRulerDistPix; + rulerDrawable.setBounds(bounds); + } + + + if (cacheRulerText != null) { + Rect bounds = rulerDrawable.getBounds(); + int bottom = (int) (view.getHeight() - (!zoomControls.isVisible() ? 0 : zoomControls.getHeight())); + if(bounds.bottom != bottom) { + bounds.bottom = bottom; + rulerDrawable.setBounds(bounds); + } + rulerDrawable.draw(canvas); + cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient, + rulerTextPaint, shadowColor); + } + } + } \ No newline at end of file