fix logic and shields
This commit is contained in:
parent
9e9b3e3bbb
commit
45c8df4c63
5 changed files with 178 additions and 168 deletions
|
@ -132,7 +132,11 @@
|
|||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/map_widget_text_size"
|
||||
android:visibility="gone"
|
||||
android:paddingLeft="@dimen/text_margin_small"
|
||||
android:paddingRight="@dimen/text_margin_small"
|
||||
android:textStyle="bold"
|
||||
tools:text="8"
|
||||
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageView
|
||||
|
@ -140,13 +144,15 @@
|
|||
android:layout_width="@dimen/map_widget_height"
|
||||
android:layout_height="@dimen/map_widget_height"
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/map_turn_right_small" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/map_shield_icon"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="@dimen/map_widget_height"
|
||||
android:layout_height="@dimen/map_widget_height"
|
||||
android:scaleType="fitCenter"
|
||||
android:visibility="gone"
|
||||
tools:src="@drawable/h_white_pillow_2_road_shield" />
|
||||
|
||||
<FrameLayout
|
||||
|
|
|
@ -95,6 +95,30 @@ public class TextRenderer {
|
|||
}
|
||||
textOrder = render.getIntPropertyValue(render.ALL.R_TEXT_ORDER, 100);
|
||||
}
|
||||
|
||||
public float getCenterX() {
|
||||
return centerX;
|
||||
}
|
||||
|
||||
public void setCenterX(float centerX) {
|
||||
this.centerX = centerX;
|
||||
}
|
||||
|
||||
public float getCenterY() {
|
||||
return centerY;
|
||||
}
|
||||
|
||||
public void setCenterY(float centerY) {
|
||||
this.centerY = centerY;
|
||||
}
|
||||
|
||||
public String getShieldResIcon() {
|
||||
return shieldResIcon;
|
||||
}
|
||||
|
||||
public void setShieldResIcon(String shieldResIcon) {
|
||||
this.shieldResIcon = shieldResIcon;
|
||||
}
|
||||
}
|
||||
|
||||
public TextRenderer(Context context) {
|
||||
|
@ -293,8 +317,8 @@ public class TextRenderer {
|
|||
float coef = rc.getDensityValue(rc.screenDensityRatio * rc.textScale);
|
||||
Bitmap ico = RenderingIcons.getIcon(context, sr, true);
|
||||
if (ico != null) {
|
||||
float left = text.centerX - ico.getWidth() / 2 * coef - 0.5f;
|
||||
float top = text.centerY - ico.getHeight() / 2 * coef - paintText.descent() - 0.5f;
|
||||
float left = text.centerX - ico.getWidth() / 2 * coef;// - 0.5f;
|
||||
float top = text.centerY - ico.getHeight() / 2 * coef - paintText.descent() * 1.5f;
|
||||
if(rc.screenDensityRatio != 1f){
|
||||
RectF rf = new RectF(left, top, left + ico.getWidth() * coef,
|
||||
top + ico.getHeight() * coef);
|
||||
|
|
|
@ -342,29 +342,6 @@ public class RouteCalculationResult {
|
|||
exitInfo.setExitStreetName(next.getObject().getExitName());
|
||||
info.setExitInfo(exitInfo);
|
||||
}
|
||||
|
||||
String highwayTag = s.getObject().getHighway();
|
||||
// Search for nearest shield properties
|
||||
for (int j = lind; j < list.size(); j++) {
|
||||
RouteSegmentResult segment = list.get(j);
|
||||
String segmentRef = segment.getObject().getRef("", false,
|
||||
segment.isForwardDirection());
|
||||
// if it's the same road
|
||||
if (segmentRef != null && segmentRef.equals(ref)) {
|
||||
BinaryMapIndexReader.TagValuePair colorPair = segment.getObject().getShieldColor();
|
||||
BinaryMapIndexReader.TagValuePair shapePair = segment.getObject().getShieldShape();
|
||||
if (colorPair != null || shapePair != null) {
|
||||
info.setShieldColorValue(colorPair != null ? colorPair.value : "white");
|
||||
info.setShieldShapeValue(shapePair != null ? shapePair.value : "square");
|
||||
if (colorPair != null) {
|
||||
info.setShieldIconName(getShieldIconName(ctx, ref, highwayTag, colorPair));
|
||||
} else {
|
||||
info.setShieldIconName(getShieldIconName(ctx, ref, highwayTag, shapePair));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(),
|
||||
|
@ -385,6 +362,7 @@ public class RouteCalculationResult {
|
|||
prevDirectionDistance = 0;
|
||||
prevDirectionTime = 0;
|
||||
}
|
||||
info.setRouteDataObject(s.getObject());
|
||||
directions.add(info);
|
||||
}
|
||||
prevDirectionDistance += s.getDistance();
|
||||
|
@ -396,32 +374,6 @@ public class RouteCalculationResult {
|
|||
}
|
||||
return segmentsToPopulate;
|
||||
}
|
||||
|
||||
private static String getShieldIconName(OsmandApplication ctx, String ref, String highwayTag,
|
||||
BinaryMapIndexReader.TagValuePair pair) {
|
||||
String shieldId = null;
|
||||
RenderingRulesStorage currentRenderer = ctx.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
MapRenderRepositories maps = ctx.getResourceManager().getRenderer();
|
||||
boolean nightMode = ctx.getDaynightHelper().isNightMode();
|
||||
RenderingRuleSearchRequest request = maps.getSearchRequestWithAppliedCustomRules(currentRenderer, nightMode);
|
||||
request.setInitialTagValueZoom("highway", highwayTag, 10, null);
|
||||
request.setIntFilter(request.ALL.R_TEXT_LENGTH, ref.length());
|
||||
request.setStringFilter(request.ALL.R_NAME_TAG, "road_ref_1");
|
||||
request.setStringFilter(request.ALL.R_ADDITIONAL,
|
||||
pair.tag + "=" + pair.value);
|
||||
if (request.search(RenderingRulesStorage.TEXT_RULES)) {
|
||||
if (request.getFloatPropertyValue(request.ALL.R_TEXT_SIZE) > 0) {
|
||||
if (request.isSpecified(request.ALL.R_TEXT_SHIELD)) {
|
||||
shieldId = request.getStringPropertyValue(request.ALL.R_TEXT_SHIELD);
|
||||
}
|
||||
if (request.isSpecified(request.ALL.R_ICON)) {
|
||||
shieldId = request.getStringPropertyValue(request.ALL.R_ICON);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("Shield name: " + shieldId);
|
||||
return shieldId;
|
||||
}
|
||||
|
||||
protected static void addMissingTurnsToRoute(List<Location> locations,
|
||||
List<RouteDirectionInfo> originalDirections, Location start, LatLon end, ApplicationMode mode, Context ctx,
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.routing;
|
|||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.router.ExitInfo;
|
||||
|
@ -18,18 +19,14 @@ public class RouteDirectionInfo {
|
|||
private String descriptionRoute = ""; //$NON-NLS-1$
|
||||
// Speed after the action till next turn
|
||||
private float averageSpeed;
|
||||
|
||||
|
||||
private String ref;
|
||||
|
||||
|
||||
private String streetName;
|
||||
|
||||
|
||||
private String destinationName;
|
||||
|
||||
private String shieldColorValue;
|
||||
|
||||
private String shieldShapeValue;
|
||||
|
||||
private String shieldIconName;
|
||||
private RouteDataObject routeDataObject;
|
||||
|
||||
@Nullable
|
||||
private ExitInfo exitInfo;
|
||||
|
@ -47,14 +44,22 @@ public class RouteDirectionInfo {
|
|||
this.averageSpeed = averageSpeed == 0 ? 1 : averageSpeed;
|
||||
this.turnType = turnType;
|
||||
}
|
||||
|
||||
|
||||
public RouteDataObject getRouteDataObject() {
|
||||
return routeDataObject;
|
||||
}
|
||||
|
||||
public void setRouteDataObject(RouteDataObject routeDataObject) {
|
||||
this.routeDataObject = routeDataObject;
|
||||
}
|
||||
|
||||
public String getDescriptionRoute(OsmandApplication ctx) {
|
||||
if (!descriptionRoute.endsWith(OsmAndFormatter.getFormattedDistance(distance, ctx))) {
|
||||
descriptionRoute += " " + OsmAndFormatter.getFormattedDistance(distance, ctx);
|
||||
}
|
||||
return descriptionRoute.trim();
|
||||
}
|
||||
|
||||
|
||||
public String getDescriptionRoute(OsmandApplication ctx, int collectedDistance) {
|
||||
if (!descriptionRoute.endsWith(OsmAndFormatter.getFormattedDistance(collectedDistance, ctx))) {
|
||||
descriptionRoute += " " + OsmAndFormatter.getFormattedDistance(collectedDistance, ctx);
|
||||
|
@ -81,7 +86,7 @@ public class RouteDirectionInfo {
|
|||
public void setStreetName(String streetName) {
|
||||
this.streetName = streetName;
|
||||
}
|
||||
|
||||
|
||||
public void setDescriptionRoute(String descriptionRoute) {
|
||||
this.descriptionRoute = descriptionRoute;
|
||||
}
|
||||
|
@ -99,11 +104,11 @@ public class RouteDirectionInfo {
|
|||
return (int) Math.round(distance / averageSpeed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TurnType getTurnType() {
|
||||
return turnType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// calculated vars
|
||||
// after action (excluding expectedTime)
|
||||
|
@ -116,7 +121,7 @@ public class RouteDirectionInfo {
|
|||
}
|
||||
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -127,28 +132,4 @@ public class RouteDirectionInfo {
|
|||
public void setExitInfo(@Nullable ExitInfo exitInfo) {
|
||||
this.exitInfo = exitInfo;
|
||||
}
|
||||
|
||||
public String getShieldColorValue() {
|
||||
return shieldColorValue;
|
||||
}
|
||||
|
||||
public void setShieldColorValue(String shieldColorValue) {
|
||||
this.shieldColorValue = shieldColorValue;
|
||||
}
|
||||
|
||||
public String getShieldShapeValue() {
|
||||
return shieldShapeValue;
|
||||
}
|
||||
|
||||
public void setShieldShapeValue(String shieldShapeValue) {
|
||||
this.shieldShapeValue = shieldShapeValue;
|
||||
}
|
||||
|
||||
public String getShieldIconName() {
|
||||
return shieldIconName;
|
||||
}
|
||||
|
||||
public void setShieldIconName(String shieldIconName) {
|
||||
this.shieldIconName = shieldIconName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,9 +5,10 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
|
@ -20,8 +21,10 @@ import android.support.v4.content.ContextCompat;
|
|||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.ClipboardManager;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -34,7 +37,7 @@ import com.jwetherell.openmap.common.UTMPoint;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.LocationConvert;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapRouteReaderAdapter;
|
||||
import net.osmand.binary.RouteDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -53,7 +56,6 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
|
||||
import net.osmand.plus.render.MapRenderRepositories;
|
||||
import net.osmand.plus.render.OsmandRenderer;
|
||||
import net.osmand.plus.render.TextRenderer;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
|
@ -968,53 +970,74 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
String text = null;
|
||||
String ref = null;
|
||||
TurnType[] type = new TurnType[1];
|
||||
boolean showNextTurn = false;
|
||||
boolean showMarker = this.showMarker;
|
||||
boolean showExitInfo = false;
|
||||
ExitInfo exitInfo = null;
|
||||
|
||||
if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
|
||||
|
||||
if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
|
||||
if (routingHelper.isFollowingMode()) {
|
||||
RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo(
|
||||
new RouteCalculationResult.NextDirectionInfo(), true);
|
||||
|
||||
if (nextDirInfo != null) {
|
||||
RouteDirectionInfo directionInfo = nextDirInfo.directionInfo;
|
||||
|
||||
if (directionInfo != null && directionInfo.getExitInfo() != null) {
|
||||
exitInfo = directionInfo.getExitInfo();
|
||||
showExitInfo = true;
|
||||
if (settings.SHOW_STREET_NAME.get()) {
|
||||
text = routingHelper.getCurrentName(type, nextDirInfo);
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
showExitInfo = false;
|
||||
if (type[0] == null) {
|
||||
showMarker = true;
|
||||
} else {
|
||||
turnDrawable.setColor(R.color.nav_arrow);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.SHOW_STREET_NAME.get()) {
|
||||
text = routingHelper.getCurrentName(type, nextDirInfo);
|
||||
if (nextDirInfo != null) {
|
||||
RouteDirectionInfo directionInfo = nextDirInfo.directionInfo;
|
||||
|
||||
if (directionInfo != null && directionInfo.getExitInfo() != null) {
|
||||
exitInfo = directionInfo.getExitInfo();
|
||||
showExitInfo = true;
|
||||
} else {
|
||||
showExitInfo = false;
|
||||
}
|
||||
|
||||
if (showExitInfo) {
|
||||
text = exitInfo.getExitStreetName();
|
||||
}
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
if (type[0] == null) {
|
||||
showMarker = true;
|
||||
} else {
|
||||
ref = directionInfo != null ? directionInfo.getRef() : null;
|
||||
if (ref != null) {
|
||||
setShield(shieldIcon, assembleShieldString(directionInfo.getShieldColorValue(),
|
||||
directionInfo.getShieldShapeValue(), ref.length()), ref);
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
|
||||
}
|
||||
|
||||
if (nextDirInfo != null && nextDirInfo.directionInfo.getRouteDataObject() != null) {
|
||||
RouteDataObject object = nextDirInfo.directionInfo.getRouteDataObject();
|
||||
String nameTag = null;
|
||||
String name = null;
|
||||
StringBuilder additional = new StringBuilder();
|
||||
if (object != null) {
|
||||
if (object.nameIds != null) {
|
||||
for (int i = 0; i < object.nameIds.length; i++) {
|
||||
String key = object.region.routeEncodingRules.get(object.nameIds[i]).getTag();
|
||||
String val = object.names.get(object.nameIds[i]);
|
||||
if (key.equals("road_ref_1")) {
|
||||
nameTag = key;
|
||||
name = val;
|
||||
} else {
|
||||
additional.append(key).append("=").append(val).append(";");
|
||||
}
|
||||
}
|
||||
turnDrawable.setColor(R.color.nav_arrow);
|
||||
}
|
||||
if (name != null && setRoadShield(shieldIcon, object, nameTag, name, additional)) {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
int di = MapRouteInfoMenu.getDirectionInfo();
|
||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() &&
|
||||
|
@ -1024,21 +1047,7 @@ public class MapInfoWidgetsFactory {
|
|||
type[0] = next.getTurnType();
|
||||
turnDrawable.setColor(R.color.nav_arrow_distant);
|
||||
text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
||||
ref = next.getRef();
|
||||
// if (next.distance > 0) {
|
||||
// text += " " + OsmAndFormatter.getFormattedDistance(next.distance, map.getMyApplication());
|
||||
// }
|
||||
if (text == null) {
|
||||
text = "";
|
||||
}
|
||||
if (ref != null) {
|
||||
setShield(shieldIcon, assembleShieldString(next.getShieldColorValue(),
|
||||
next.getShieldShapeValue(),
|
||||
ref.length()), ref);
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
}
|
||||
|
||||
} else {
|
||||
text = null;
|
||||
}
|
||||
|
@ -1048,24 +1057,14 @@ public class MapInfoWidgetsFactory {
|
|||
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
||||
if (rt != null) {
|
||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||
ref = rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation));
|
||||
//ref = rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation));
|
||||
text = RoutingHelper.formatStreetName(
|
||||
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
|
||||
null,
|
||||
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
|
||||
"»");
|
||||
}
|
||||
if (ref != null) {
|
||||
BinaryMapIndexReader.TagValuePair colorPair = rt.getShieldColor();
|
||||
BinaryMapIndexReader.TagValuePair shapePair = rt.getShieldShape();
|
||||
setShield(shieldIcon, assembleShieldString(
|
||||
colorPair != null ? colorPair.value : null,
|
||||
shapePair != null ? shapePair.value : null,
|
||||
ref.length()), ref);
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
}else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
}
|
||||
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
|
@ -1128,36 +1127,84 @@ public class MapInfoWidgetsFactory {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void setShield(ImageView view, String shield, String ref) {
|
||||
private boolean setRoadShield(ImageView view, RouteDataObject object, String nameTag, String name, StringBuilder additional) {
|
||||
Context context = topBar.getContext();
|
||||
Bitmap bitmap = Bitmap.createBitmap(100, 50, Bitmap.Config.ARGB_4444);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
|
||||
MapRenderRepositories mapRenderRepo = map.getMyApplication().getResourceManager().getRenderer();
|
||||
int[] tps = object.getTypes();
|
||||
OsmandApplication app = ((OsmandApplication) context.getApplicationContext());
|
||||
RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
|
||||
boolean nightMode = app.getDaynightHelper().isNightMode();
|
||||
RenderingRuleSearchRequest renderingReq =
|
||||
mapRenderRepo.getSearchRequestWithAppliedCustomRules(storage, nightMode);
|
||||
renderingReq.setInitialTagValueZoom("highway", "secondary", 15, null);
|
||||
renderingReq.setIntFilter(renderingReq.ALL.R_TEXT_LENGTH, ref.length());
|
||||
renderingReq.setStringFilter(renderingReq.ALL.R_NAME_TAG, "ref");
|
||||
renderingReq.search(RenderingRulesStorage.POINT_RULES);
|
||||
RenderingRuleSearchRequest rreq = map.getMyApplication().getResourceManager()
|
||||
.getRenderer().getSearchRequestWithAppliedCustomRules(storage, nightMode);
|
||||
|
||||
for (int i : tps) {
|
||||
BinaryMapRouteReaderAdapter.RouteTypeRule tp = object.region.quickGetEncodingRule(i);
|
||||
if (tp.getTag().equals("highway")) {
|
||||
rreq.setInitialTagValueZoom(tp.getTag(), tp.getValue(), 15, null);
|
||||
} else {
|
||||
additional.append(tp.getTag()).append("=").append(tp.getValue()).append(";");
|
||||
}
|
||||
}
|
||||
|
||||
rreq.setIntFilter(rreq.ALL.R_TEXT_LENGTH, name.length());
|
||||
rreq.setStringFilter(rreq.ALL.R_NAME_TAG, nameTag);
|
||||
rreq.setStringFilter(rreq.ALL.R_ADDITIONAL, additional.toString());
|
||||
rreq.search(RenderingRulesStorage.TEXT_RULES);
|
||||
|
||||
OsmandRenderer.RenderingContext rc = new OsmandRenderer.RenderingContext(context);
|
||||
|
||||
TextRenderer textRenderer = new TextRenderer(context);
|
||||
TextRenderer.TextDrawInfo text = new TextRenderer.TextDrawInfo(ref);
|
||||
text.fillProperties(rc,renderingReq , 50, 25);
|
||||
textRenderer.drawShieldIcon(rc, canvas, text, shield);
|
||||
textRenderer.drawWrappedText(canvas, text, (float) 20);
|
||||
TextRenderer.TextDrawInfo text = new TextRenderer.TextDrawInfo(name);
|
||||
|
||||
BitmapDrawable shieldDrawable = new BitmapDrawable(context.getResources(), bitmap);
|
||||
view.setImageDrawable(shieldDrawable);
|
||||
}
|
||||
|
||||
private String assembleShieldString(String color, String shape, int length) {
|
||||
return (color != null ? color : "white") + "_"
|
||||
+ (shape != null ? shape : "square") + "_" + length + "_" + "road_shield";
|
||||
Paint p = textRenderer.getPaintText();
|
||||
p.setTypeface(Typeface.create("Droid Serif", Typeface.BOLD));
|
||||
|
||||
int shieldRes = -1;
|
||||
|
||||
if (rreq.isSpecified(rreq.ALL.R_TEXT_SHIELD)) {
|
||||
text.setShieldResIcon(rreq.getStringPropertyValue(rreq.ALL.R_TEXT_SHIELD));
|
||||
shieldRes = app.getResources().getIdentifier("h_"+text.getShieldResIcon(),
|
||||
"drawable", app.getPackageName());
|
||||
}
|
||||
|
||||
if (rreq.isSpecified(rreq.ALL.R_TEXT_COLOR)) {
|
||||
p.setColor(rreq.getIntPropertyValue(rreq.ALL.R_TEXT_COLOR));
|
||||
}
|
||||
|
||||
if (rreq.isSpecified(rreq.ALL.R_TEXT_SIZE)) {
|
||||
float ts = rreq.getFloatPropertyValue(rreq.ALL.R_TEXT_SIZE);
|
||||
textRenderer.getPaintText().setTextSize(
|
||||
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, ts,
|
||||
app.getResources().getDisplayMetrics()));
|
||||
}
|
||||
|
||||
if (shieldRes != -1) {
|
||||
float xSize;
|
||||
float ySize;
|
||||
Bitmap shield;
|
||||
shield = BitmapFactory.decodeResource(app.getResources(), shieldRes);
|
||||
ySize = shield.getHeight();
|
||||
xSize = shield.getWidth();
|
||||
float xyRatio = xSize/ySize;
|
||||
//setting view propotions (height is fixed by toolbar size - 48dp);
|
||||
int viewHeightPx = AndroidUtils.dpToPx(context, 48);
|
||||
int viewWidthPx = (int) (viewHeightPx * xyRatio);
|
||||
|
||||
ViewGroup.LayoutParams params = view.getLayoutParams();
|
||||
params.width = viewWidthPx;
|
||||
view.setLayoutParams(params);
|
||||
|
||||
//creating bitmap according to size of resource
|
||||
Bitmap bitmap = Bitmap.createBitmap((int) xSize, (int) ySize, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
text.fillProperties(rc, rreq, xSize/2, ySize/2 - p.getFontMetrics().ascent/2f);
|
||||
textRenderer.drawShieldIcon(rc, canvas, text, text.getShieldResIcon());
|
||||
textRenderer.drawWrappedText(canvas, text, 20);
|
||||
|
||||
view.setImageBitmap(bitmap);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateWaypoint() {
|
||||
|
|
Loading…
Reference in a new issue