exit shield in top bar

This commit is contained in:
Dmitriy Ruban 2019-12-11 15:44:17 +02:00
parent 36418d2f54
commit 55db01e9b4
8 changed files with 169 additions and 90 deletions

View file

@ -742,6 +742,28 @@ public class RouteDataObject {
return null;
}
public String getShieldColor() {
int sz = types.length;
for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals("road_shield_color_1")) {
return r.getValue();
}
}
return null;
}
public String getShieldShape() {
int sz = types.length;
for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals("road_shield_shape_1")) {
return r.getValue();
}
}
return null;
}
public int getOneway() {
int sz = types.length;
for (int i = 0; i < sz; i++) {

View file

@ -0,0 +1,45 @@
package net.osmand.router;
public class ExitInfo {
private String ref;
private String shieldName;
private String shieldIconName;
private String exitStreetName;
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref = ref;
}
public String getShieldName() {
return shieldName;
}
public void setShieldName(String shieldName) {
this.shieldName = shieldName;
}
public String getExitStreetName() {
return exitStreetName;
}
public void setExitStreetName(String exitStreetName) {
this.exitStreetName = exitStreetName;
}
public String getShieldIconName() {
return shieldIconName;
}
public void setShieldIconName(String shieldIconName) {
this.shieldIconName = shieldIconName;
}
}

View file

@ -1,9 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/active_color_primary_light" />
<corners android:radius="3dp" />
</shape>
</item>
</layer-list>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/active_color_primary_light" />
<corners android:radius="3dp" />
</shape>

View file

@ -124,22 +124,22 @@
<TextView
android:id="@+id/map_exit_ref"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/bg_topbar_shield_exit_ref"
android:textColor="@color/color_black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/map_widget_text_size"
android:textAlignment="gravity"
android:gravity="center"
android:minWidth="@dimen/map_widget_height"
android:background="@drawable/bg_topbar_shield_exit_ref"
android:textColor="@color/color_white"
android:visibility="gone"
tools:text="99"
tools:text="8"
tools:visibility="visible" />
<ImageView
android:id="@+id/map_turn_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:scaleType="center"
android:layout_width="@dimen/map_widget_height"
android:layout_height="@dimen/map_widget_height"
android:scaleType="fitCenter"
tools:src="@drawable/map_turn_right_small" />
<LinearLayout
@ -152,11 +152,11 @@
android:id="@+id/map_exit_shield_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:padding="8dp"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half"
android:padding="@dimen/content_padding_half"
android:textColor="@color/color_black"
tools:background="@drawable/h_white_octagon_bgblue_2_road_shield"
tools:background="@drawable/h_white_pillow_4_road_shield"
tools:text="S108" />
<FrameLayout

View file

@ -49,6 +49,8 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
@ -389,6 +391,11 @@ public class OsmandRenderer {
}
}
public Drawable getShieldDrawable(String shieldId){
Bitmap shield = RenderingIcons.getIcon(context, shieldId, true);
return new BitmapDrawable(context.getResources(),shield);
}
protected void drawBitmap(Canvas cv, Bitmap ico, RectF rf) {
if(ico == null) {
return;

View file

@ -14,6 +14,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
import net.osmand.router.ExitInfo;
import net.osmand.router.RouteSegmentResult;
import net.osmand.router.RoutingContext;
import net.osmand.router.TurnType;
@ -325,9 +326,28 @@ public class RouteCalculationResult {
info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(),
ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
if (s.getObject().isExitPoint() && next.getObject().isMotorWayLink()) {
info.setExitRef(next.getObject().getExitRef());
info.setExitShieldName(next.getObject().getDestinationRef(next.isForwardDirection()));
info.setExitStreetName(next.getObject().getExitName());
ExitInfo exitInfo = new ExitInfo();
exitInfo.setRef(next.getObject().getExitRef());
exitInfo.setExitStreetName(next.getObject().getExitName());
String shieldName = next.getObject().getDestinationRef(next.isForwardDirection());
exitInfo.setShieldName(shieldName);
// 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(shieldName)) {
String shieldColor = segment.getObject().getShieldColor();
String shieldShape = segment.getObject().getShieldShape();
if (shieldColor != null && shieldShape != null) {
exitInfo.setShieldIconName(shieldColor + "_" + shieldShape + "_"
+ shieldName.length() + "_" + "road_shield");
// we found it
break;
}
}
}
info.setExitInfo(exitInfo);
}
}

View file

@ -1,7 +1,10 @@
package net.osmand.plus.routing;
import android.support.annotation.Nullable;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.router.ExitInfo;
import net.osmand.router.TurnType;
public class RouteDirectionInfo {
@ -22,11 +25,8 @@ public class RouteDirectionInfo {
private String destinationName;
private String exitRef;
private String exitShieldName;
private String exitStreetName;
@Nullable
private ExitInfo exitInfo;
public String getDestinationName() {
return destinationName;
@ -113,27 +113,12 @@ public class RouteDirectionInfo {
this.distance = distance;
}
public String getExitRef() {
return exitRef;
@Nullable
public ExitInfo getExitInfo() {
return exitInfo;
}
public void setExitRef(String exitRef) {
this.exitRef = exitRef;
}
public String getExitShieldName() {
return exitShieldName;
}
public void setExitShieldName(String exitShieldName) {
this.exitShieldName = exitShieldName;
}
public String getExitStreetName() {
return exitStreetName;
}
public void setExitStreetName(String exitStreetName) {
this.exitStreetName = exitStreetName;
public void setExitInfo(@Nullable ExitInfo exitInfo) {
this.exitInfo = exitInfo;
}
}

View file

@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -51,7 +50,6 @@ 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.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.ShowAlongTheRouteBottomSheet;
import net.osmand.plus.routing.RouteCalculationResult;
@ -62,6 +60,7 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.RulerControlLayer;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WidgetState;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
import net.osmand.router.ExitInfo;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -947,6 +946,8 @@ public class MapInfoWidgetsFactory {
TextInfoWidget.updateTextColor((TextView) waypointInfoBar.findViewById(R.id.waypoint_text),
(TextView) waypointInfoBar.findViewById(R.id.waypoint_text_shadow),
textColor, textShadowColor, bold, rad / 2);
exitRefText.setTextColor(nightMode ? map.getResources().getColor(R.color.text_color_primary_dark) :
map.getResources().getColor(R.color.color_white));
ImageView all = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_more);
ImageView remove = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_close);
@ -962,36 +963,27 @@ public class MapInfoWidgetsFactory {
TurnType[] type = new TurnType[1];
boolean showNextTurn = false;
boolean showMarker = this.showMarker;
boolean showShield = false;
String exitRef = null;
String exitShieldName = null;
String exitStreetName = null;
boolean showExitInfo = false;
ExitInfo exitInfo = null;
if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
RouteCalculationResult.NextDirectionInfo nextDirectionInfo =
routingHelper.getNextRouteDirectionInfo(new RouteCalculationResult.NextDirectionInfo(), false);
if (nextDirectionInfo != null) {
RouteDirectionInfo directionInfo = nextDirectionInfo.directionInfo;
if (directionInfo != null) {
exitRef = directionInfo.getExitRef();
exitShieldName = directionInfo.getExitShieldName();
exitStreetName = directionInfo.getExitStreetName();
if (exitRef != null) {
showShield = true;
exitRefText.setText(exitRef);
AndroidUiHelper.updateVisibility(exitRefText, true);
} else {
showShield = false;
AndroidUiHelper.updateVisibility(exitRefText, false);
}
if (directionInfo != null && directionInfo.getExitInfo() != null) {
exitInfo = directionInfo.getExitInfo();
showExitInfo = true;
} else {
showExitInfo = false;
}
}
if (routingHelper.isFollowingMode()) {
if (settings.SHOW_STREET_NAME.get()) {
text = routingHelper.getCurrentName(type);
if (showShield) {
text = exitStreetName;
if (showExitInfo) {
text = exitInfo.getExitStreetName();
}
if (text == null) {
text = "";
@ -1063,29 +1055,41 @@ public class MapInfoWidgetsFactory {
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
this.showMarker = showMarker;
int h = addressText.getHeight() / 4 * 3;
if (h != turnDrawable.getBounds().bottom) {
turnDrawable.setBounds(0, 0, h, h);
if (!showExitInfo) {
int h = addressText.getHeight() / 4 * 3;
if (h != turnDrawable.getBounds().bottom) {
turnDrawable.setBounds(0, 0, h, h);
}
}
if (update) {
if (type[0] != null) {
if (showShield) {
addressTextShadow.setCompoundDrawables(null, null, null, null);
addressTextShadow.setCompoundDrawablePadding(4);
addressText.setCompoundDrawables(null, null, null, null);
addressText.setCompoundDrawablePadding(4);
exitShield.setText(exitShieldName);
turnIcon.setImageDrawable(turnDrawable);
AndroidUiHelper.updateVisibility(turnIcon, true);
AndroidUiHelper.updateVisibility(exitShield, true);
} else {
addressTextShadow.setCompoundDrawables(turnDrawable, null, null, null);
addressTextShadow.setCompoundDrawablePadding(4);
addressText.setCompoundDrawables(turnDrawable, null, null, null);
addressText.setCompoundDrawablePadding(4);
AndroidUiHelper.updateVisibility(turnIcon, false);
AndroidUiHelper.updateVisibility(exitShield, false);
if (showExitInfo) {
addressTextShadow.setCompoundDrawables(null, null, null, null);
addressText.setCompoundDrawables(null, null, null, null);
turnIcon.setImageDrawable(turnDrawable);
AndroidUiHelper.updateVisibility(turnIcon, true);
String ref = exitInfo.getRef();
if (!Algorithms.isEmpty(ref)){
exitRefText.setText(ref);
AndroidUiHelper.updateVisibility(exitRefText, true);
}
String shieldName = exitInfo.getShieldName();
if (!Algorithms.isEmpty(shieldName)){
exitShield.setText(shieldName);
AndroidUiHelper.updateVisibility(exitShield, true);
if (exitInfo.getShieldIconName() != null) {
MapRenderRepositories mapRenderRepo = map.getMyApplication().getResourceManager().getRenderer();
Drawable shield = mapRenderRepo.getRenderer().getShieldDrawable(exitInfo.getShieldIconName());
exitShield.setBackgroundDrawable(shield);
}
}
} else if (update) {
if (type[0] != null) {
addressTextShadow.setCompoundDrawables(turnDrawable, null, null, null);
addressTextShadow.setCompoundDrawablePadding(4);
addressText.setCompoundDrawables(turnDrawable, null, null, null);
addressText.setCompoundDrawablePadding(4);
AndroidUiHelper.updateVisibility(turnIcon, false);
AndroidUiHelper.updateVisibility(exitRefText, false);
AndroidUiHelper.updateVisibility(exitShield, false);
} else if (showMarker) {
Drawable marker = map.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance);
addressTextShadow.setCompoundDrawablesWithIntrinsicBounds(marker, null, null, null);