Add text info

This commit is contained in:
Victor Shcherb 2012-07-23 20:12:02 +02:00
parent fc1617e573
commit 0cdd7ce9b7
5 changed files with 86 additions and 26 deletions

View file

@ -19,6 +19,7 @@ import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.voice.CommandPlayer;
import net.osmand.router.Interruptable;
import net.osmand.router.RouteSegmentResult;
import android.content.Context;
import android.location.Location;
import android.os.Handler;
@ -484,6 +485,27 @@ public class RoutingHelper {
return route.getMostImportantAlarm(lastFixedLocation, speedAlarm);
}
public String formatStreetName(String name, String ref) {
if(name != null && name.length() > 0){
if(ref != null && ref.length() > 0) {
name += "(" + ref +")";
}
return name;
} else {
return ref;
}
}
public synchronized String getCurrentName(){
RouteSegmentResult rs = route.getCurrentSegmentResult();
if(rs != null) {
String nm = rs.getObject().getName();
String rf = rs.getObject().getRef();
return formatStreetName(nm, rf);
}
return null;
}
public synchronized NextDirectionInfo getNextRouteDirectionInfoAfter(NextDirectionInfo previous, NextDirectionInfo to, boolean toSpeak){
NextDirectionInfo i = route.getNextRouteDirectionInfoAfter(previous, to, toSpeak);
if(i != null) {

View file

@ -189,15 +189,15 @@ public class MapControlsLayer extends OsmandMapLayer {
private void drawZoomLevel(Canvas canvas) {
ShadowText zoomText = ShadowText.create(view.getZoom() + "");
float length = zoomTextPaint.measureText(zoomText.getText());
String zoomText = view.getZoom() + "";
float length = zoomTextPaint.measureText(zoomText);
if (zoomShadow.getBounds().width() == 0) {
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(),
zoomInButton.getBottom());
}
zoomShadow.draw(canvas);
zoomText.draw(canvas, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2,
ShadowText.draw(zoomText, canvas, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2,
zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint);
}

View file

@ -46,7 +46,7 @@ public abstract class MapInfoControl extends View {
}
protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) {
ShadowText.create(text).draw(cv, centerX, centerY, textPaint);
ShadowText.draw(text, cv, centerX, centerY, textPaint);
}
@Override

View file

@ -25,8 +25,10 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.text.TextPaint;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.MeasureSpec;
@ -71,11 +73,6 @@ public class MapInfoLayer extends OsmandMapLayer {
private MapInfoControl alarmControl;
private TextView topText;
public MapInfoLayer(MapActivity map, RouteLayer layer){
this.map = map;
this.routeLayer = layer;
@ -243,12 +240,14 @@ public class MapInfoLayer extends OsmandMapLayer {
int color = !nightMode.isNightMode() ? Color.BLACK : Color.BLACK;
if(paintText.getColor() != color) {
paintText.setColor(color);
topText.setTextColor(color);
paintSubText.setColor(color);
paintSmallText.setColor(color);
paintSmallSubText.setColor(color);
}
if(paintText.isFakeBoldText() != bold) {
paintText.setFakeBoldText(bold);
topText.getPaint().setFakeBoldText(bold);
paintSubText.setFakeBoldText(bold);
paintSmallText.setFakeBoldText(bold);
paintSmallSubText.setFakeBoldText(bold);
@ -262,15 +261,44 @@ public class MapInfoLayer extends OsmandMapLayer {
}
lanesControl.updateInfo();
alarmControl.updateInfo();
// topText.setTextColor(color);
// String text = "Пр.Независимости";
// float ts = topText.getPaint().measureText(text);
// int wth = topText.getRight() /*- compassView.getRight()*/;
// while(ts > wth && topText.getTextSize() - 1 > 5) {
// topText.setTextSize(topText.getTextSize() - 1);
// ts = topText.getPaint().measureText(text);
// }
// topText.setText(text);
updateTopText();
}
private void updateTopText() {
String text = null;
RoutingHelper helper = routeLayer.getHelper();
if (routeLayer != null && helper.isRouteCalculated()) {
if (helper.isFollowingMode()) {
text = helper.getCurrentName();
} else {
int di = map.getMapLayers().getRouteInfoLayer().getDirectionInfo();
if (di >= 0 && map.getMapLayers().getRouteInfoLayer().isVisible()) {
RouteDirectionInfo next = helper.getRouteDirections().get(di);
text = helper.formatStreetName(next.getStreetName(), next.getRef());
}
}
}
if(text == null) {
text = "";
}
if (!text.equals(topText.getText().toString())) {
TextPaint pp = new TextPaint(topText.getPaint());
if (!text.equals("")) {
pp.setTextSize(25 * scaleCoefficient);
float ts = pp.measureText(text);
int wth = topText.getWidth();
while (ts > wth && pp.getTextSize() > 7) {
pp.setTextSize(pp.getTextSize() - 1);
ts = pp.measureText(text);
}
topText.setTextSize(TypedValue.COMPLEX_UNIT_PX, pp.getTextSize());
} else {
topText.setTextSize(TypedValue.COMPLEX_UNIT_PX, 7);
}
topText.setText(text);
topText.invalidate();
}
}
@Override
@ -757,8 +785,15 @@ public class MapInfoLayer extends OsmandMapLayer {
// Space (future text)
params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1);
topText = new TextView(view.getContext());
topText.setGravity(Gravity.RIGHT);
topText = new TextView(view.getContext()) {
@Override
protected void onDraw(Canvas canvas) {
ShadowText.draw(getText().toString(), canvas, topText.getWidth() / 2, topText.getHeight(), topText.getPaint());
}
};
topText.setGravity(Gravity.CENTER);
topText.setTextColor(Color.BLACK);
statusBar.addView(topText, params);
// Map and progress icon

View file

@ -6,18 +6,21 @@ import android.graphics.Paint;
import android.graphics.Paint.Style;
public class ShadowText {
private final String text;
ShadowText(String text) {
private String text;
public ShadowText(String text) {
this.text = text;
}
public static ShadowText create(String text) {
return new ShadowText(text);
}
protected void draw(Canvas cv, float centerX, float centerY, Paint textPaint) {
public void draw(Canvas cv, float centerX, float centerY, Paint textPaint) {
draw(text, cv, centerX, centerY, textPaint);
}
public static void draw(String text, Canvas cv, float centerX, float centerY, Paint textPaint) {
int c = textPaint.getColor();
textPaint.setStyle(Style.STROKE);
textPaint.setColor(Color.WHITE);