implement addition layer for info

git-svn-id: https://osmand.googlecode.com/svn/trunk@95 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-05-29 10:02:09 +00:00
parent 4de363414d
commit 635625e813
9 changed files with 202 additions and 11 deletions

View file

@ -21,10 +21,7 @@ public class ToDoConstants {
// 24. Implement ResourceManager, load cities/streets/buildings on Low memory (clear previous all addresses cities).
// 5. Search for city/streets/buildings
// 15. Investigate interruption of any long running operation & implement where it is needed
// 11. Print out additional info speed, altitude, number of satellites
// 19. Show how map is rotated where north/south on map (do not consider compass)
// 21. Implement zooming tile (if tile doesn't exist local, we can zoom in previous tile).
// 8. Enable change POI directly on map (requires OSM login)
@ -55,10 +52,12 @@ public class ToDoConstants {
// DONE ANDROID :
// 11. Print out additional info speed, altitude, number of satellites
// 19. Show how map is rotated where north/south on map (do not consider compass)
// 23. Implement moving point from center to bottom (for rotating map)
// 17. Enable go to location by specifying coordinates
// 9. Configure file log & see log from file (when exception happened to see from device)
// 2. Showing compass on the map : use device compass if exists(?)
// 2. Showing compass on the map : use device compass if exists(?)
// 18. Implement go to point

View file

@ -1,5 +1,6 @@
package com.osmand.osm;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -194,4 +195,16 @@ public class MapUtils {
});
}
public static String getFormattedDistance(int meters){
if(meters >= 100000){
return meters / 1000 + " km";
} else if(meters >= 10000){
return MessageFormat.format("{0, number, #.#} km", ((float) meters) / 1000);
} else if(meters > 1500){
return MessageFormat.format("{0, number, #.##} km", ((float) meters) / 1000);
} else {
return meters + " m";
}
}
}

View file

@ -34,6 +34,7 @@ import com.osmand.ResourceManager;
import com.osmand.data.preparation.MapTileDownloader;
import com.osmand.map.IMapLocationListener;
import com.osmand.osm.LatLon;
import com.osmand.views.MapInfoLayer;
import com.osmand.views.OsmandMapTileView;
import com.osmand.views.POIMapLayer;
import com.osmand.views.PointLocationLayer;
@ -51,6 +52,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
private PointLocationLayer locationLayer;
private PointNavigationLayer navigationLayer;
private POIMapLayer poiMapLayer;
private MapInfoLayer mapInfoLayer;
private WakeLock wakeLock;
private boolean sensorRegistered = false;
@ -83,6 +85,11 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
mapView.addLayer(navigationLayer);
locationLayer = new PointLocationLayer();
mapView.addLayer(locationLayer);
mapInfoLayer = new MapInfoLayer(this);
mapView.addLayer(mapInfoLayer);
SharedPreferences lprefs = getPreferences(MODE_WORLD_READABLE);
if(lprefs.contains(POINT_NAVIGATE_LAT)){
navigationLayer.setPointToNavigate(new LatLon(lprefs.getFloat(POINT_NAVIGATE_LAT, 0),
@ -162,6 +169,7 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
}
public void setLocation(Location location){
// TODO remove that !!
if(location != null){
location.setSpeed(30);
location.setBearing(90);
@ -374,4 +382,5 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
}
}
}

View file

@ -0,0 +1,148 @@
package com.osmand.views;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.location.Location;
import android.view.MotionEvent;
import com.osmand.activities.MapActivity;
import com.osmand.osm.MapUtils;
public class MapInfoLayer implements OsmandMapLayer {
private OsmandMapTileView view;
private final MapActivity map;
private Paint paintBlack;
private Path pathForCompass;
private Path pathForCompass2;
private Paint fillBlack;
private Paint fillRed;
private RectF boundsForCompass;
private RectF boundsForDist;
private RectF boundsForSpeed;
private Paint paintAlphaGray;
private float[] calculations = new float[1];
private String cachedDistString = null;
private int cachedMeters = 0;
private String cachedSpeedString = null;
private int cachedSpeed = 0;
public MapInfoLayer(MapActivity map){
this.map = map;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK);
paintBlack.setTextSize(18);
paintBlack.setAntiAlias(true);
paintAlphaGray = new Paint();
paintAlphaGray.setStyle(Style.FILL_AND_STROKE);
paintAlphaGray.setColor(Color.LTGRAY);
paintAlphaGray.setAlpha(150);
fillBlack = new Paint();
fillBlack.setStyle(Style.FILL_AND_STROKE);
fillBlack.setColor(Color.BLACK);
fillBlack.setAntiAlias(true);
fillRed = new Paint();
fillRed.setStyle(Style.FILL_AND_STROKE);
fillRed.setColor(Color.RED);
fillRed.setAntiAlias(true);
boundsForCompass = new RectF(0, 0, 32, 32);
boundsForDist = new RectF(32, 0, 110, 32);
boundsForSpeed = new RectF(0, 32, 110, 64);
pathForCompass = new Path();
pathForCompass.moveTo(9, 15.5f);
pathForCompass.lineTo(22f, 15.5f);
pathForCompass.lineTo(15.5f, 30f);
pathForCompass.lineTo(9, 15.5f);
pathForCompass2 = new Path();
pathForCompass2.moveTo(9, 15.5f);
pathForCompass2.lineTo(22f, 15.5f);
pathForCompass2.lineTo(15.5f, 2f);
pathForCompass2.lineTo(9, 15);
}
public boolean distChanged(int oldDist, int dist){
if(oldDist != 0 && Math.abs(((float) dist - oldDist)/oldDist) < 0.01){
return false;
}
return true;
}
@Override
public void onDraw(Canvas canvas) {
if(map.getPointToNavigate() != null){
Location.distanceBetween(view.getLatitude(), view.getLongitude(), map.getPointToNavigate().getLatitude(),
map.getPointToNavigate().getLongitude(), calculations);
if(distChanged(cachedMeters, (int)calculations[0])){
cachedMeters = (int)calculations[0];
if(cachedMeters <= 20){
cachedMeters = 0;
cachedDistString = null;
} else {
cachedDistString = MapUtils.getFormattedDistance(cachedMeters);
boundsForDist.right = paintBlack.measureText(cachedDistString) + 25 + boundsForDist.left;
boundsForSpeed.right = boundsForDist.right;
}
}
}
if(map.getLastKnownLocation() != null && map.getLastKnownLocation().hasSpeed()){
if(cachedSpeed != (int) map.getLastKnownLocation().getSpeed()){
cachedSpeed = (int) map.getLastKnownLocation().getSpeed();
cachedSpeedString = ((int) (cachedSpeed * 3.6d)) + " km/h";
}
if(cachedSpeed > 0){
canvas.drawRoundRect(boundsForSpeed, 3, 3, paintAlphaGray);
canvas.drawText(cachedSpeedString, boundsForSpeed.left + 5, boundsForSpeed.bottom - 9, paintBlack);
}
}
if(cachedDistString != null){
canvas.drawRoundRect(boundsForDist, 3, 3, paintAlphaGray);
canvas.drawCircle(boundsForDist.left + 8, boundsForDist.bottom - 15, 4, fillRed);
canvas.drawText(cachedDistString, boundsForDist.left + 15, boundsForDist.bottom - 9, paintBlack);
}
// draw the last because it use rotating
canvas.drawRoundRect(boundsForCompass, 3, 3, paintAlphaGray);
canvas.rotate(view.getRotate(), 15, 15);
canvas.drawPath(pathForCompass2, fillRed);
canvas.drawPath(pathForCompass, fillBlack);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return true;
}
}

View file

@ -14,4 +14,6 @@ public interface OsmandMapLayer {
public boolean onTouchEvent(MotionEvent event);
public boolean drawInScreenPixels();
}

View file

@ -273,9 +273,17 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
private void drawOverMap(Canvas canvas){
canvas.drawCircle(getCenterPointX(), getCenterPointY(), 3, paintBlack);
canvas.drawCircle(getCenterPointX(), getCenterPointY(), 6, paintBlack);
for(OsmandMapLayer layer : layers){
int w = getCenterPointX();
int h = getCenterPointY();
canvas.drawCircle(w, h, 3, paintBlack);
canvas.drawCircle(w, h, 6, paintBlack);
for (OsmandMapLayer layer : layers) {
canvas.restore();
canvas.save();
if (!layer.drawInScreenPixels()) {
canvas.rotate(rotate, w, h);
}
layer.onDraw(canvas);
}
}
@ -332,7 +340,7 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall
if (canvas != null) {
ResourceManager mgr = ResourceManager.getResourceManager();
boolean useInternet = OsmandSettings.isUsingInternetToDownloadTiles(getContext());
canvas.save();
canvas.rotate(rotate, w , h);
boundsRect.set(0, 0, getWidth(), getHeight());
calculateTileRectangle(boundsRect, w, h, tileX, tileY, tilesRect);

View file

@ -105,4 +105,9 @@ public class POIMapLayer implements OsmandMapLayer {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
}

View file

@ -155,6 +155,11 @@ public class PointLocationLayer implements OsmandMapLayer {
}
@Override
public boolean drawInScreenPixels() {
return false;
}

View file

@ -98,7 +98,9 @@ public class PointNavigationLayer implements OsmandMapLayer {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
}