1. fix small issue with transport index

2. add night mode param to map view (now full night mode could be designed)


git-svn-id: https://osmand.googlecode.com/svn/trunk@869 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2011-01-03 14:49:27 +00:00
parent dad4a1276f
commit 2549407cc1
19 changed files with 79 additions and 54 deletions

View file

@ -85,17 +85,20 @@ public class TransportIndexRepositoryBinary implements TransportIndexRepository
* @param stop * @param stop
* @param format * @param format
* 0} - ref, {1} - type, {2} - name, {3} - name_en * 0} - ref, {1} - type, {2} - name, {3} - name_en
* @return * @return null if something goes wrong
*/ */
public List<String> getRouteDescriptionsForStop(TransportStop stop, String format) { public List<String> getRouteDescriptionsForStop(TransportStop stop, String format) {
assert acceptTransportStop(stop); assert acceptTransportStop(stop);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
List<String> res = new ArrayList<String>();
MessageFormat f = new MessageFormat(format); MessageFormat f = new MessageFormat(format);
List<String> res = new ArrayList<String>();
for(int r : stop.getReferencesToRoutes()) { for(int r : stop.getReferencesToRoutes()) {
try { try {
TransportRoute route = file.getTransportRoute(r); 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$ 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) { } catch (IOException e) {
log.error("Disk error ", e); //$NON-NLS-1$ log.error("Disk error ", e); //$NON-NLS-1$

View file

@ -64,6 +64,7 @@ public class DayNightHelper implements SensorEventListener {
/** /**
* @return null if could not be determined (in case of error) * @return null if could not be determined (in case of error)
* @return true if day is supposed to be
*/ */
public Boolean getDayNightRenderer() { public Boolean getDayNightRenderer() {
if (dayNightMode.isDay()) { if (dayNightMode.isDay()) {

View file

@ -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$ 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); return !name.endsWith(RendererRegistry.NIGHT_SUFFIX);
} }

View file

@ -52,7 +52,7 @@ public class RendererLayer implements OsmandMapLayer {
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (view.getZoom() >= startZoom && visible) { if (view.getZoom() >= startZoom && visible) {
if (!view.isZooming()){ if (!view.isZooming()){
pixRect.set(0, 0, view.getWidth(), view.getHeight()); pixRect.set(0, 0, view.getWidth(), view.getHeight());

View file

@ -93,7 +93,7 @@ public class ContextMenuLayer implements OsmandMapLayer {
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if(latLon != null){ if(latLon != null){
int x = view.getMapXForPoint(latLon.getLongitude()); int x = view.getMapXForPoint(latLon.getLongitude());
int y = view.getMapYForPoint(latLon.getLatitude()); int y = view.getMapYForPoint(latLon.getLatitude());

View file

@ -87,7 +87,7 @@ public class FavoritesLayer implements OsmandMapLayer, ContextMenuLayer.IContext
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (view.getZoom() >= startZoom) { if (view.getZoom() >= startZoom) {

View file

@ -50,7 +50,7 @@ public class GPXLayer implements OsmandMapLayer {
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if(points.isEmpty()){ if(points.isEmpty()){
return; return;
} }

View file

@ -190,7 +190,7 @@ public class MapInfoLayer implements OsmandMapLayer {
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latlonBounds) { public void onDraw(Canvas canvas, RectF latlonBounds, boolean nightMode) {
// prepare data (left distance, speed) // prepare data (left distance, speed)
if(map.getPointToNavigate() != null){ if(map.getPointToNavigate() != null){
int d = 0; int d = 0;

View file

@ -117,7 +117,7 @@ public class OsmBugsLayer implements OsmandMapLayer, ContextMenuLayer.IContextMe
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (view.getZoom() >= startZoom) { if (view.getZoom() >= startZoom) {
// request to load // request to load
requestToLoad(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom()); requestToLoad(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom());

View file

@ -9,7 +9,7 @@ public interface OsmandMapLayer {
public void initLayer(OsmandMapTileView view); public void initLayer(OsmandMapTileView view);
public void onDraw(Canvas canvas, RectF latlonRect); public void onDraw(Canvas canvas, RectF latlonRect, boolean nightMode);
public void destroyLayer(); public void destroyLayer();

View file

@ -1,5 +1,6 @@
package net.osmand.views; package net.osmand.views;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -51,6 +52,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
public static final int OVERZOOM_IN = 2; public static final int OVERZOOM_IN = 2;
protected final int emptyTileDivisor = 16; protected final int emptyTileDivisor = 16;
public interface OnTrackBallListener { public interface OnTrackBallListener {
public boolean onTrackBallEvent(MotionEvent e); 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); protected static final Log log = LogUtil.getLog(OsmandMapTileView.class);
/** /**MapTree
* zoom level - could be float to show zoomed tiles * zoom level - could be float to show zoomed tiles
*/ */
private float zoom = 3; private float zoom = 3;
@ -112,6 +114,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private MultiTouchSupport multiTouchSupport; private MultiTouchSupport multiTouchSupport;
Paint paintGrayFill; Paint paintGrayFill;
Paint paintBlackFill;
Paint paintWhiteFill; Paint paintWhiteFill;
Paint paintCenter; Paint paintCenter;
Paint paintBitmap; Paint paintBitmap;
@ -139,6 +142,12 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
paintGrayFill.setStyle(Style.FILL); paintGrayFill.setStyle(Style.FILL);
// when map rotate // when map rotate
paintGrayFill.setAntiAlias(true); paintGrayFill.setAntiAlias(true);
paintBlackFill= new Paint();
paintBlackFill.setColor(Color.BLACK);
paintBlackFill.setStyle(Style.FILL);
// when map rotate
paintBlackFill.setAntiAlias(true);
paintWhiteFill = new Paint(); paintWhiteFill = new Paint();
paintWhiteFill.setColor(Color.WHITE); paintWhiteFill.setColor(Color.WHITE);
@ -324,7 +333,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
} }
refreshMap(); refreshMap();
} }
public void setLatLon(double latitude, double longitude) { public void setLatLon(double latitude, double longitude) {
animatedDraggingThread.stopAnimating(); animatedDraggingThread.stopAnimating();
this.latitude = latitude; this.latitude = latitude;
@ -361,7 +370,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// ////////////////////////////// DRAWING MAP PART ///////////////////////////////////////////// // ////////////////////////////// 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); float tileDiv = (ftileSize / emptyTileDivisor);
for (int k1 = 0; k1 < emptyTileDivisor; k1++) { for (int k1 = 0; k1 < emptyTileDivisor; k1++) {
for (int k2 = 0; k2 < emptyTileDivisor; k2++) { for (int k2 = 0; k2 < emptyTileDivisor; k2++) {
@ -370,7 +379,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if ((k1 + k2) % 2 == 0) { if ((k1 + k2) % 2 == 0) {
cvs.drawRect(xk, yk, xk + tileDiv, yk + tileDiv, paintGrayFill); cvs.drawRect(xk, yk, xk + tileDiv, yk + tileDiv, paintGrayFill);
} else { } 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; this.mapPosition = type;
} }
private void drawOverMap(Canvas canvas, RectF latlonRect) { private void drawOverMap(Canvas canvas, RectF latlonRect, boolean nightMode) {
int w = getCenterPointX(); int w = getCenterPointX();
int h = getCenterPointY(); int h = getCenterPointY();
canvas.restore(); canvas.restore();
@ -403,7 +412,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (!layer.drawInScreenPixels()) { if (!layer.drawInScreenPixels()) {
canvas.rotate(rotate, w, h); canvas.rotate(rotate, w, h);
} }
layer.onDraw(canvas, latlonRect); layer.onDraw(canvas, latlonRect, nightMode);
canvas.restore(); canvas.restore();
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
// skip it // skip it
@ -485,6 +494,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
Canvas canvas = holder.lockCanvas(); Canvas canvas = holder.lockCanvas();
if (canvas != null) { if (canvas != null) {
canvas.save(); 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()); boundsRect.set(0, 0, getWidth(), getHeight());
canvas.rotate(rotate, w, h); canvas.rotate(rotate, w, h);
try { try {
@ -544,7 +560,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
} }
if (bmp == null) { if (bmp == null) {
drawEmptyTile(canvas, x1, y1, ftileSize); drawEmptyTile(canvas, x1, y1, ftileSize, nightMode);
} else { } else {
int xZoom = ((left + i) % div) * tileSize / div; int xZoom = ((left + i) % div) * tileSize / div;
int yZoom = ((top + j) % 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++) { for (int j = 0; j < height; j++) {
float x1 = (i + left - tileX) * ftileSize + w; float x1 = (i + left - tileX) * ftileSize + w;
float y1 = (j + top - tileY) * ftileSize + h; 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 { } finally {
holder.unlockCanvasAndPost(canvas); holder.unlockCanvasAndPost(canvas);
} }
@ -631,6 +647,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
Canvas canvas = holder.lockCanvas(boundsRect); Canvas canvas = holder.lockCanvas(boundsRect);
if (canvas != null) { if (canvas != null) {
boolean nightMode = false;
if(application != null){
Boolean dayNightRenderer = application.getDaynightHelper().getDayNightRenderer();
if(dayNightRenderer != null){
nightMode = !dayNightRenderer.booleanValue();
}
}
canvas.save(); canvas.save();
canvas.rotate(rotate, w, h); canvas.rotate(rotate, w, h);
@ -645,13 +668,13 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
float y = (request.yTile - tileY) * getTileSize() + h; float y = (request.yTile - tileY) * getTileSize() + h;
float tileSize = getTileSize(); float tileSize = getTileSize();
if (bmp == null) { if (bmp == null) {
drawEmptyTile(canvas, x, y, tileSize); drawEmptyTile(canvas, x, y, tileSize, nightMode);
} else { } else {
bitmapToZoom.set(0, 0, getSourceTileSize(), getSourceTileSize()); bitmapToZoom.set(0, 0, getSourceTileSize(), getSourceTileSize());
bitmapToDraw.set(x, y, x + tileSize, y + tileSize); bitmapToDraw.set(x, y, x + tileSize, y + tileSize);
canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap); canvas.drawBitmap(bmp, bitmapToZoom, bitmapToDraw, paintBitmap);
} }
drawOverMap(canvas, latlonRect); drawOverMap(canvas, latlonRect, nightMode);
} finally { } finally {
holder.unlockCanvasAndPost(canvas); holder.unlockCanvasAndPost(canvas);
} }

View file

@ -135,7 +135,7 @@ public class POIMapLayer implements OsmandMapLayer, ContextMenuLayer.IContextMen
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (view.getZoom() >= startZoom) { if (view.getZoom() >= startZoom) {
objects.clear(); objects.clear();

View file

@ -82,7 +82,7 @@ public class PointLocationLayer implements OsmandMapLayer {
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (isLocationVisible(lastKnownLocation)) { if (isLocationVisible(lastKnownLocation)) {
int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude()); int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude());
int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude()); int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude());

View file

@ -47,7 +47,7 @@ public class PointNavigationLayer implements OsmandMapLayer {
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if(pointToNavigate == null){ if(pointToNavigate == null){
return; return;
} }

View file

@ -166,7 +166,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
public final int shiftCenter = 55; public final int shiftCenter = 55;
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if(isVisible()){ if(isVisible()){
border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density, border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density,
layout.getRight() - (shiftCenter - 5) * dm.density, layout.getBottom() + 4 * dm.density); layout.getRight() - (shiftCenter - 5) * dm.density, layout.getBottom() + 4 * dm.density);

View file

@ -58,7 +58,7 @@ public class RouteLayer implements OsmandMapLayer {
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
path.reset(); path.reset();
if (helper.hasPointsToShow()) { if (helper.hasPointsToShow()) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();

View file

@ -59,7 +59,7 @@ public class TransportInfoLayer implements OsmandMapLayer {
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if(routeHelper.routeIsCalculated() && visible){ if(routeHelper.routeIsCalculated() && visible){
List<RouteInfoLocation> list = routeHelper.getRoute(); List<RouteInfoLocation> list = routeHelper.getRoute();
for(RouteInfoLocation l : list){ for(RouteInfoLocation l : list){

View file

@ -80,28 +80,27 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
private String getStopDescription(TransportStop n, boolean useName) { private String getStopDescription(TransportStop n, boolean useName) {
StringBuilder text = new StringBuilder(250); 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(view.getContext().getString(R.string.transport_Stop))
text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ .append(" : ").append(n.getName(OsmandSettings.usingEnglishNames(view.getSettings()))); //$NON-NLS-1$
List<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude()); text.append("\n").append(view.getContext().getString(R.string.transport_Routes)).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$
List<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(
TransportIndexRepository tir = null; n.getLocation().getLatitude(), n.getLocation().getLongitude());
for(TransportIndexRepository t : reps){
if(t.acceptTransportStop(n)){ for (TransportIndexRepository t : reps) {
tir = t; if (t.acceptTransportStop(n)) {
break; List<String> l;
} if (!useName) {
} l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$
if(tir != null){ } else if (OsmandSettings.usingEnglishNames(view.getSettings())) {
List<String> l; l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {3}"); //$NON-NLS-1$
if(!useName){ } else {
l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$ l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {2}"); //$NON-NLS-1$
} else if(OsmandSettings.usingEnglishNames(view.getSettings())){ }
l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {3}"); //$NON-NLS-1$ if (l != null) {
} else { for (String s : l) {
l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0} - {2}"); //$NON-NLS-1$ text.append("\n").append(s); //$NON-NLS-1$
} }
for(String s : l){ }
text.append("\n").append(s); //$NON-NLS-1$
} }
} }
return text.toString(); return text.toString();
@ -123,7 +122,7 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (view.getZoom() >= startZoom) { if (view.getZoom() >= startZoom) {
objects.clear(); objects.clear();
view.getApplication().getResourceManager().searchTransportAsync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom(), objects); view.getApplication().getResourceManager().searchTransportAsync(latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, view.getZoom(), objects);

View file

@ -218,7 +218,7 @@ public class YandexTrafficLayer implements OsmandMapLayer {
} }
@Override @Override
public void onDraw(Canvas canvas, RectF latLonBounds) { public void onDraw(Canvas canvas, RectF latLonBounds, boolean nightMode) {
if (visible) { if (visible) {
pixRect.set(0, 0, view.getWidth(), view.getHeight()); pixRect.set(0, 0, view.getWidth(), view.getHeight());
float tileY = (float) MapUtils.getTileEllipsoidNumberY(view.getZoom(), view.getLatitude()); float tileY = (float) MapUtils.getTileEllipsoidNumberY(view.getZoom(), view.getLatitude());