Add text info
This commit is contained in:
parent
fc1617e573
commit
0cdd7ce9b7
5 changed files with 86 additions and 26 deletions
|
@ -19,6 +19,7 @@ import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import net.osmand.plus.voice.CommandPlayer;
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.router.Interruptable;
|
import net.osmand.router.Interruptable;
|
||||||
|
import net.osmand.router.RouteSegmentResult;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
@ -484,6 +485,27 @@ public class RoutingHelper {
|
||||||
return route.getMostImportantAlarm(lastFixedLocation, speedAlarm);
|
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){
|
public synchronized NextDirectionInfo getNextRouteDirectionInfoAfter(NextDirectionInfo previous, NextDirectionInfo to, boolean toSpeak){
|
||||||
NextDirectionInfo i = route.getNextRouteDirectionInfoAfter(previous, to, toSpeak);
|
NextDirectionInfo i = route.getNextRouteDirectionInfoAfter(previous, to, toSpeak);
|
||||||
if(i != null) {
|
if(i != null) {
|
||||||
|
|
|
@ -189,15 +189,15 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
|
||||||
private void drawZoomLevel(Canvas canvas) {
|
private void drawZoomLevel(Canvas canvas) {
|
||||||
ShadowText zoomText = ShadowText.create(view.getZoom() + "");
|
String zoomText = view.getZoom() + "";
|
||||||
float length = zoomTextPaint.measureText(zoomText.getText());
|
float length = zoomTextPaint.measureText(zoomText);
|
||||||
if (zoomShadow.getBounds().width() == 0) {
|
if (zoomShadow.getBounds().width() == 0) {
|
||||||
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(),
|
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(),
|
||||||
zoomInButton.getBottom());
|
zoomInButton.getBottom());
|
||||||
}
|
}
|
||||||
zoomShadow.draw(canvas);
|
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);
|
zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public abstract class MapInfoControl extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) {
|
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
|
@Override
|
||||||
|
|
|
@ -25,8 +25,10 @@ import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.text.TextPaint;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.MeasureSpec;
|
import android.view.View.MeasureSpec;
|
||||||
|
@ -71,11 +73,6 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
private MapInfoControl alarmControl;
|
private MapInfoControl alarmControl;
|
||||||
private TextView topText;
|
private TextView topText;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
public MapInfoLayer(MapActivity map, RouteLayer layer){
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.routeLayer = layer;
|
this.routeLayer = layer;
|
||||||
|
@ -243,12 +240,14 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
int color = !nightMode.isNightMode() ? Color.BLACK : Color.BLACK;
|
int color = !nightMode.isNightMode() ? Color.BLACK : Color.BLACK;
|
||||||
if(paintText.getColor() != color) {
|
if(paintText.getColor() != color) {
|
||||||
paintText.setColor(color);
|
paintText.setColor(color);
|
||||||
|
topText.setTextColor(color);
|
||||||
paintSubText.setColor(color);
|
paintSubText.setColor(color);
|
||||||
paintSmallText.setColor(color);
|
paintSmallText.setColor(color);
|
||||||
paintSmallSubText.setColor(color);
|
paintSmallSubText.setColor(color);
|
||||||
}
|
}
|
||||||
if(paintText.isFakeBoldText() != bold) {
|
if(paintText.isFakeBoldText() != bold) {
|
||||||
paintText.setFakeBoldText(bold);
|
paintText.setFakeBoldText(bold);
|
||||||
|
topText.getPaint().setFakeBoldText(bold);
|
||||||
paintSubText.setFakeBoldText(bold);
|
paintSubText.setFakeBoldText(bold);
|
||||||
paintSmallText.setFakeBoldText(bold);
|
paintSmallText.setFakeBoldText(bold);
|
||||||
paintSmallSubText.setFakeBoldText(bold);
|
paintSmallSubText.setFakeBoldText(bold);
|
||||||
|
@ -262,15 +261,44 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
lanesControl.updateInfo();
|
lanesControl.updateInfo();
|
||||||
alarmControl.updateInfo();
|
alarmControl.updateInfo();
|
||||||
// topText.setTextColor(color);
|
updateTopText();
|
||||||
// String text = "Пр.Независимости";
|
}
|
||||||
// float ts = topText.getPaint().measureText(text);
|
|
||||||
// int wth = topText.getRight() /*- compassView.getRight()*/;
|
private void updateTopText() {
|
||||||
// while(ts > wth && topText.getTextSize() - 1 > 5) {
|
String text = null;
|
||||||
// topText.setTextSize(topText.getTextSize() - 1);
|
RoutingHelper helper = routeLayer.getHelper();
|
||||||
// ts = topText.getPaint().measureText(text);
|
if (routeLayer != null && helper.isRouteCalculated()) {
|
||||||
// }
|
if (helper.isFollowingMode()) {
|
||||||
// topText.setText(text);
|
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
|
@Override
|
||||||
|
@ -757,8 +785,15 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
// Space (future text)
|
// Space (future text)
|
||||||
params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1);
|
params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT, 1);
|
||||||
topText = new TextView(view.getContext());
|
topText = new TextView(view.getContext()) {
|
||||||
topText.setGravity(Gravity.RIGHT);
|
|
||||||
|
@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);
|
statusBar.addView(topText, params);
|
||||||
|
|
||||||
// Map and progress icon
|
// Map and progress icon
|
||||||
|
|
|
@ -6,18 +6,21 @@ import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
|
|
||||||
public class ShadowText {
|
public class ShadowText {
|
||||||
|
private String text;
|
||||||
|
|
||||||
private final String text;
|
public ShadowText(String text) {
|
||||||
|
|
||||||
ShadowText(String text) {
|
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShadowText create(String text) {
|
public static ShadowText create(String text) {
|
||||||
return new ShadowText(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();
|
int c = textPaint.getColor();
|
||||||
textPaint.setStyle(Style.STROKE);
|
textPaint.setStyle(Style.STROKE);
|
||||||
textPaint.setColor(Color.WHITE);
|
textPaint.setColor(Color.WHITE);
|
||||||
|
|
Loading…
Reference in a new issue