diff --git a/OsmAnd/src/net/osmand/TransportIndexRepositoryBinary.java b/OsmAnd/src/net/osmand/TransportIndexRepositoryBinary.java index 3a744d4e1a..84178145d8 100644 --- a/OsmAnd/src/net/osmand/TransportIndexRepositoryBinary.java +++ b/OsmAnd/src/net/osmand/TransportIndexRepositoryBinary.java @@ -85,17 +85,20 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository * @param stop * @param format * 0} - ref, {1} - type, {2} - name, {3} - name_en - * @return + * @return null if something goes wrong */ public List getRouteDescriptionsForStop(TransportStop stop, String format) { assert acceptTransportStop(stop); long now = System.currentTimeMillis(); - List res = new ArrayList(); + MessageFormat f = new MessageFormat(format); - + List res = new ArrayList(); for(int r : stop.getReferencesToRoutes()) { try { TransportRoute route = file.getTransportRoute(r); + if(route == null){ + return null; + } res.add(f.format(new String[] { route.getRef()+"", route.getType()+"", route.getName()+"", route.getEnName()+""})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } catch (IOException e) { log.error("Disk error ", e); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/activities/DayNightHelper.java b/OsmAnd/src/net/osmand/activities/DayNightHelper.java index 42df4a28d5..47f5ab6efc 100644 --- a/OsmAnd/src/net/osmand/activities/DayNightHelper.java +++ b/OsmAnd/src/net/osmand/activities/DayNightHelper.java @@ -64,6 +64,7 @@ public class DayNightHelper implements SensorEventListener { /** * @return null if could not be determined (in case of error) + * @return true if day is supposed to be */ public Boolean getDayNightRenderer() { if (dayNightMode.isDay()) { diff --git a/OsmAnd/src/net/osmand/render/BaseOsmandRender.java b/OsmAnd/src/net/osmand/render/BaseOsmandRender.java index 1010207dc5..8a18e4493d 100644 --- a/OsmAnd/src/net/osmand/render/BaseOsmandRender.java +++ b/OsmAnd/src/net/osmand/render/BaseOsmandRender.java @@ -42,11 +42,10 @@ public class BaseOsmandRender implements RenderingRuleVisitor { log.info("Init render " + name + " for " + (System.currentTimeMillis() - time) + " ms"); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ } - public BaseOsmandRender(){ + public BaseOsmandRender() { } - public boolean isDayRender() - { + public boolean isDayRender() { return !name.endsWith(RendererRegistry.NIGHT_SUFFIX); } diff --git a/OsmAnd/src/net/osmand/render/RendererLayer.java b/OsmAnd/src/net/osmand/render/RendererLayer.java index 534aec1d9a..9b8af146f1 100644 --- a/OsmAnd/src/net/osmand/render/RendererLayer.java +++ b/OsmAnd/src/net/osmand/render/RendererLayer.java @@ -52,7 +52,7 @@ public class RendererLayer implements OsmandMapLayer { @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (view.getZoom() >= startZoom && visible) { if (!view.isZooming()){ pixRect.set(0, 0, view.getWidth(), view.getHeight()); diff --git a/OsmAnd/src/net/osmand/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/views/ContextMenuLayer.java index f8aee9f3d6..a3bd3cb746 100644 --- a/OsmAnd/src/net/osmand/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/views/ContextMenuLayer.java @@ -93,7 +93,7 @@ public class ContextMenuLayer implements OsmandMapLayer { } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if(latLon != null){ int x = view.getMapXForPoint(latLon.getLongitude()); int y = view.getMapYForPoint(latLon.getLatitude()); diff --git a/OsmAnd/src/net/osmand/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/views/FavoritesLayer.java index 2a64b5b519..440424c72d 100644 --- a/OsmAnd/src/net/osmand/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/views/FavoritesLayer.java @@ -87,7 +87,7 @@ public class FavoritesLayer implements OsmandMapLayer, ContextMenuLayer.IContext @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (view.getZoom() >= startZoom) { diff --git a/OsmAnd/src/net/osmand/views/GPXLayer.java b/OsmAnd/src/net/osmand/views/GPXLayer.java index 63429010a0..d6e8e64442 100644 --- a/OsmAnd/src/net/osmand/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/views/GPXLayer.java @@ -50,7 +50,7 @@ public class GPXLayer implements OsmandMapLayer { @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if(points.isEmpty()){ return; } diff --git a/OsmAnd/src/net/osmand/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/views/MapInfoLayer.java index f1f553d1c5..0f35b25606 100644 --- a/OsmAnd/src/net/osmand/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/views/MapInfoLayer.java @@ -190,7 +190,7 @@ public class MapInfoLayer implements OsmandMapLayer { } @Override - public void onDraw(Canvas canvas, RectF latlonBounds) { + public void onDraw(Canvas canvas, RectF latlonBounds, boolean nightMode) { // prepare data (left distance, speed) if(map.getPointToNavigate() != null){ int d = 0; diff --git a/OsmAnd/src/net/osmand/views/OsmBugsLayer.java b/OsmAnd/src/net/osmand/views/OsmBugsLayer.java index 5b623c0d70..b24ae4459c 100644 --- a/OsmAnd/src/net/osmand/views/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/views/OsmBugsLayer.java @@ -117,7 +117,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (view.getZoom() >= startZoom) { // request to load requestToLoad(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom()); diff --git a/OsmAnd/src/net/osmand/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/views/OsmandMapLayer.java index 560a28da81..a56d8d5f55 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapLayer.java @@ -9,7 +9,7 @@ public interface OsmandMapLayer { public void initLayer(OsmandMapTileView view); - public void onDraw(Canvas canvas, RectF latlonRect); + public void onDraw(Canvas canvas, RectF latlonRect, boolean nightMode); public void destroyLayer(); diff --git a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java index 0a607382e4..9a324880d9 100644 --- a/OsmAnd/src/net/osmand/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/views/OsmandMapTileView.java @@ -1,5 +1,6 @@ package net.osmand.views; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -51,6 +52,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall public static final int OVERZOOM_IN = 2; protected final int emptyTileDivisor = 16; + public interface OnTrackBallListener { public boolean onTrackBallEvent(MotionEvent e); @@ -65,7 +67,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } protected static final Log log = LogUtil.getLog(OsmandMapTileView.class); - /** + /**MapTree * zoom level - could be float to show zoomed tiles */ private float zoom = 3; @@ -112,6 +114,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall private MultiTouchSupport multiTouchSupport; Paint paintGrayFill; + Paint paintBlackFill; Paint paintWhiteFill; Paint paintCenter; Paint paintBitmap; @@ -139,6 +142,12 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall paintGrayFill.setStyle(Style.FILL); // when map rotate paintGrayFill.setAntiAlias(true); + + paintBlackFill= new Paint(); + paintBlackFill.setColor(Color.BLACK); + paintBlackFill.setStyle(Style.FILL); + // when map rotate + paintBlackFill.setAntiAlias(true); paintWhiteFill = new Paint(); paintWhiteFill.setColor(Color.WHITE); @@ -324,7 +333,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } refreshMap(); } - + public void setLatLon(double latitude, double longitude) { animatedDraggingThread.stopAnimating(); this.latitude = latitude; @@ -361,7 +370,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall // ////////////////////////////// DRAWING MAP PART ///////////////////////////////////////////// - protected void drawEmptyTile(Canvas cvs, float x, float y, float ftileSize) { + protected void drawEmptyTile(Canvas cvs, float x, float y, float ftileSize, boolean nightMode) { float tileDiv = (ftileSize / emptyTileDivisor); for (int k1 = 0; k1 < emptyTileDivisor; k1++) { for (int k2 = 0; k2 < emptyTileDivisor; k2++) { @@ -370,7 +379,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall if ((k1 + k2) % 2 == 0) { cvs.drawRect(xk, yk, xk + tileDiv, yk + tileDiv, paintGrayFill); } else { - cvs.drawRect(xk, yk, xk + tileDiv, yk + tileDiv, paintWhiteFill); + cvs.drawRect(xk, yk, xk + tileDiv, yk + tileDiv, nightMode ? paintBlackFill : paintWhiteFill); } } } @@ -391,7 +400,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall this.mapPosition = type; } - private void drawOverMap(Canvas canvas, RectF latlonRect) { + private void drawOverMap(Canvas canvas, RectF latlonRect, boolean nightMode) { int w = getCenterPointX(); int h = getCenterPointY(); canvas.restore(); @@ -403,7 +412,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall if (!layer.drawInScreenPixels()) { canvas.rotate(rotate, w, h); } - layer.onDraw(canvas, latlonRect); + layer.onDraw(canvas, latlonRect, nightMode); canvas.restore(); } catch (IndexOutOfBoundsException e) { // skip it @@ -485,6 +494,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall Canvas canvas = holder.lockCanvas(); if (canvas != null) { canvas.save(); + boolean nightMode = false; + if(application != null){ + Boolean dayNightRenderer = application.getDaynightHelper().getDayNightRenderer(); + if(dayNightRenderer != null){ + nightMode = !dayNightRenderer.booleanValue(); + } + } boundsRect.set(0, 0, getWidth(), getHeight()); canvas.rotate(rotate, w, h); try { @@ -544,7 +560,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } if (bmp == null) { - drawEmptyTile(canvas, x1, y1, ftileSize); + drawEmptyTile(canvas, x1, y1, ftileSize, nightMode); } else { int xZoom = ((left + i) % div) * tileSize / div; int yZoom = ((top + j) % div) * tileSize / div; @@ -564,11 +580,11 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall for (int j = 0; j < height; j++) { float x1 = (i + left - tileX) * ftileSize + w; float y1 = (j + top - tileY) * ftileSize + h; - drawEmptyTile(canvas, x1, y1, ftileSize); + drawEmptyTile(canvas, x1, y1, ftileSize, nightMode); } } } - drawOverMap(canvas, latlonRect); + drawOverMap(canvas, latlonRect, nightMode); } finally { holder.unlockCanvasAndPost(canvas); } @@ -631,6 +647,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall Canvas canvas = holder.lockCanvas(boundsRect); if (canvas != null) { + boolean nightMode = false; + if(application != null){ + Boolean dayNightRenderer = application.getDaynightHelper().getDayNightRenderer(); + if(dayNightRenderer != null){ + nightMode = !dayNightRenderer.booleanValue(); + } + } canvas.save(); canvas.rotate(rotate, w, h); @@ -645,13 +668,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall float y = (request.yTile - tileY) * getTileSize() + h; float tileSize = getTileSize(); if (bmp == null) { - drawEmptyTile(canvas, x, y, tileSize); + drawEmptyTile(canvas, x, y, tileSize, nightMode); } else { bitmapToZoom.set(0, 0, getSourceTileSize(), getSourceTileSize()); bitmapToDraw.set(x, y, x + tileSize, y + tileSize); canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap); } - drawOverMap(canvas, latlonRect); + drawOverMap(canvas, latlonRect, nightMode); } finally { holder.unlockCanvasAndPost(canvas); } diff --git a/OsmAnd/src/net/osmand/views/POIMapLayer.java b/OsmAnd/src/net/osmand/views/POIMapLayer.java index 6ffc799992..6f261e6e22 100644 --- a/OsmAnd/src/net/osmand/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/views/POIMapLayer.java @@ -135,7 +135,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (view.getZoom() >= startZoom) { objects.clear(); diff --git a/OsmAnd/src/net/osmand/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/views/PointLocationLayer.java index cb3e74acdc..73808b9734 100644 --- a/OsmAnd/src/net/osmand/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/views/PointLocationLayer.java @@ -82,7 +82,7 @@ public class PointLocationLayer implements OsmandMapLayer { } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (isLocationVisible(lastKnownLocation)) { int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude()); int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude()); diff --git a/OsmAnd/src/net/osmand/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/views/PointNavigationLayer.java index 5226552882..885d75d69f 100644 --- a/OsmAnd/src/net/osmand/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/views/PointNavigationLayer.java @@ -47,7 +47,7 @@ public class PointNavigationLayer implements OsmandMapLayer { @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if(pointToNavigate == null){ return; } diff --git a/OsmAnd/src/net/osmand/views/RouteInfoLayer.java b/OsmAnd/src/net/osmand/views/RouteInfoLayer.java index cfcec1468d..74cf9e84f6 100644 --- a/OsmAnd/src/net/osmand/views/RouteInfoLayer.java +++ b/OsmAnd/src/net/osmand/views/RouteInfoLayer.java @@ -166,7 +166,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener public final int shiftCenter = 55; @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if(isVisible()){ border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density, layout.getRight() - (shiftCenter - 5) * dm.density, layout.getBottom() + 4 * dm.density); diff --git a/OsmAnd/src/net/osmand/views/RouteLayer.java b/OsmAnd/src/net/osmand/views/RouteLayer.java index 2207ccd419..dd3e5501e7 100644 --- a/OsmAnd/src/net/osmand/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/views/RouteLayer.java @@ -58,7 +58,7 @@ public class RouteLayer implements OsmandMapLayer { @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { path.reset(); if (helper.hasPointsToShow()) { long time = System.currentTimeMillis(); diff --git a/OsmAnd/src/net/osmand/views/TransportInfoLayer.java b/OsmAnd/src/net/osmand/views/TransportInfoLayer.java index 11f595d333..4cfda59a79 100644 --- a/OsmAnd/src/net/osmand/views/TransportInfoLayer.java +++ b/OsmAnd/src/net/osmand/views/TransportInfoLayer.java @@ -59,7 +59,7 @@ public class TransportInfoLayer implements OsmandMapLayer { } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if(routeHelper.routeIsCalculated() && visible){ List list = routeHelper.getRoute(); for(RouteInfoLocation l : list){ diff --git a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java index 9ea9bc5b9e..4931adb422 100644 --- a/OsmAnd/src/net/osmand/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/views/TransportStopsLayer.java @@ -80,28 +80,27 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo private String getStopDescription(TransportStop n, boolean useName) { StringBuilder text = new StringBuilder(250); - text.append(view.getContext().getString(R.string.transport_Stop)).append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getSettings()))); //$NON-NLS-1$ - text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ - List reps = view.getApplication().getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude()); - - TransportIndexRepository tir = null; - for(TransportIndexRepository t : reps){ - if(t.acceptTransportStop(n)){ - tir = t; - break; - } - } - if(tir != null){ - List l; - if(!useName){ - l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$ - } else if(OsmandSettings.usingEnglishNames(view.getSettings())){ - l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {3}"); //$NON-NLS-1$ - } else { - l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {2}"); //$NON-NLS-1$ - } - for(String s : l){ - text.append("\n").append(s); //$NON-NLS-1$ + text.append(view.getContext().getString(R.string.transport_Stop)) + .append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getSettings()))); //$NON-NLS-1$ + text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ + List reps = view.getApplication().getResourceManager().searchTransportRepositories( + n.getLocation().getLatitude(), n.getLocation().getLongitude()); + + for (TransportIndexRepository t : reps) { + if (t.acceptTransportStop(n)) { + List l; + if (!useName) { + l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$ + } else if (OsmandSettings.usingEnglishNames(view.getSettings())) { + l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {3}"); //$NON-NLS-1$ + } else { + l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {2}"); //$NON-NLS-1$ + } + if (l != null) { + for (String s : l) { + text.append("\n").append(s); //$NON-NLS-1$ + } + } } } return text.toString(); @@ -123,7 +122,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (view.getZoom() >= startZoom) { objects.clear(); view.getApplication().getResourceManager().searchTransportAsync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom(), objects); diff --git a/OsmAnd/src/net/osmand/views/YandexTrafficLayer.java b/OsmAnd/src/net/osmand/views/YandexTrafficLayer.java index 25cc515e60..5497da1e6b 100644 --- a/OsmAnd/src/net/osmand/views/YandexTrafficLayer.java +++ b/OsmAnd/src/net/osmand/views/YandexTrafficLayer.java @@ -218,7 +218,7 @@ public class YandexTrafficLayer implements OsmandMapLayer { } @Override - public void onDraw(Canvas canvas, RectF latLonBounds) { + public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) { if (visible) { pixRect.set(0, 0, view.getWidth(), view.getHeight()); float tileY = (float) MapUtils.getTileEllipsoidNumberY(view.getZoom(), view.getLatitude());