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 format
* 0} - ref, {1} - type, {2} - name, {3} - name_en
* @return
* @return null if something goes wrong
*/
public List<String> getRouteDescriptionsForStop(TransportStop stop, String format) {
assert acceptTransportStop(stop);
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()) {
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$

View file

@ -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()) {

View file

@ -45,8 +45,7 @@ public class BaseOsmandRender implements RenderingRuleVisitor {
public BaseOsmandRender() {
}
public boolean isDayRender()
{
public boolean isDayRender() {
return !name.endsWith(RendererRegistry.NIGHT_SUFFIX);
}

View file

@ -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());

View file

@ -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());

View file

@ -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) {

View file

@ -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;
}

View file

@ -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;

View file

@ -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());

View file

@ -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();

View file

@ -1,5 +1,6 @@
package net.osmand.views;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -52,6 +53,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
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;
@ -140,6 +143,12 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
// 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);
paintWhiteFill.setStyle(Style.FILL);
@ -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);
}

View file

@ -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();

View file

@ -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());

View file

@ -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;
}

View file

@ -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);

View file

@ -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();

View file

@ -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<RouteInfoLocation> list = routeHelper.getRoute();
for(RouteInfoLocation l : list){

View file

@ -80,18 +80,14 @@ 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(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<TransportIndexRepository> reps = view.getApplication().getResourceManager().searchTransportRepositories(n.getLocation().getLatitude(), n.getLocation().getLongitude());
List<TransportIndexRepository> 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<String> l;
if (!useName) {
l = reps.get(0).getRouteDescriptionsForStop(n, "{1} {0}"); //$NON-NLS-1$
@ -100,10 +96,13 @@ public class TransportStopsLayer implements OsmandMapLayer, ContextMenuLayer.ICo
} 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);

View file

@ -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());