Merge pull request #9378 from osmandapp/Canada_speed_limit

Fix #9192 [Feature request] add new icons for the Canadian road signs
This commit is contained in:
Vitaliy 2020-07-03 17:40:59 +03:00 committed by GitHub
commit d0db94c132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View file

@ -25,9 +25,10 @@
<dimen name="map_alarm_size">116dp</dimen>
<dimen name="map_alarm_bottom_text_margin">12dp</dimen>
<dimen name="map_alarm_text_size">35sp</dimen>
<dimen name="map_alarm_text_top_padding">30dp</dimen>
<dimen name="map_alarm_bottom_text_size">22sp</dimen>
<dimen name="map_alarm_bottom_margin">140dp</dimen>
<dimen name="map_alarm_bottom_si_text_size">12sp</dimen>
<dimen name="map_alarm_bottom_margin">131dp</dimen>
<dimen name="map_alarm_bottom_margin_land">81dp</dimen>
<dimen name="map_widget_icon">36dp</dimen>

View file

@ -141,15 +141,14 @@
<dimen name="map_route_planning_land_width_minus_shadow">306dp</dimen>
<dimen name="map_route_planning_max_height">330dp</dimen>
<dimen name="map_minwidth_widget">100dp</dimen>
<dimen name="map_widget_text_size">23sp</dimen>
<dimen name="map_top_widget_text_size">22sp</dimen>
<dimen name="map_widget_text_size_small">15sp</dimen>
<dimen name="map_button_text_size">18sp</dimen>
<dimen name="map_alarm_text_size">25sp</dimen>
<dimen name="map_alarm_text_top_padding">20dp</dimen>
<dimen name="map_alarm_bottom_text_size">16sp</dimen>
<dimen name="map_alarm_bottom_si_text_size">8sp</dimen>
<dimen name="map_widget_text_bottom_margin">1sp</dimen>
<dimen name="map_widget_text_small_bottom_margin">3sp</dimen>
<dimen name="map_widget_icon_margin">2dp</dimen>

View file

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
@ -24,7 +25,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
@ -62,6 +62,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_PX;
public class RouteInfoWidgetsFactory {
public NextTurnInfoWidget createNextInfoControl(final Activity activity,
@ -1236,26 +1238,26 @@ public class RouteInfoWidgetsFactory {
}
}
public static class AlarmWidget {
public static class AlarmWidget {
private View layout;
private ImageView icon;
private TextView text;
private TextView bottomText;
private TextView widgetText;
private TextView widgetBottomText;
private OsmandSettings settings;
private RoutingHelper rh;
private MapViewTrackingUtilities trackingUtilities;
private OsmAndLocationProvider locationProvider;
private WaypointHelper wh;
private int imgId;
private String textString;
private String bottomTextString;
private String cachedText;
private String cachedBottomText;
public AlarmWidget(final OsmandApplication app, MapActivity ma) {
layout = ma.findViewById(R.id.map_alarm_warning);
icon = (ImageView) ma.findViewById(R.id.map_alarm_warning_icon);
text = (TextView) ma.findViewById(R.id.map_alarm_warning_text);
bottomText = (TextView) ma.findViewById(R.id.map_alarm_warning_text_bottom);
widgetText = (TextView) ma.findViewById(R.id.map_alarm_warning_text);
widgetBottomText = (TextView) ma.findViewById(R.id.map_alarm_warning_text_bottom);
settings = app.getSettings();
rh = ma.getRoutingHelper();
trackingUtilities = ma.getMapViewTrackingUtilities();
@ -1292,15 +1294,17 @@ public class RouteInfoWidgetsFactory {
String bottomText = "";
OsmandSettings.DrivingRegion region = settings.DRIVING_REGION.get();
boolean americanType = region.isAmericanTypeSigns();
if(alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
if(region == OsmandSettings.DrivingRegion.CANADA) {
boolean isCanadianRegion = region == OsmandSettings.DrivingRegion.CANADA;
if (alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
if (isCanadianRegion) {
locimgId = R.drawable.warnings_speed_limit_ca;
} else if(americanType){
bottomText = settings.SPEED_SYSTEM.get().toShortString(settings.getContext());
} else if (americanType) {
locimgId = R.drawable.warnings_speed_limit_us;
//else case is done by drawing red ring
//else case is done by drawing red ring
}
text = alarm.getIntValue() +"";
} else if(alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
text = alarm.getIntValue() + "";
} else if (alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
locimgId = R.drawable.warnings_speed_camera;
} else if(alarm.getType() == AlarmInfoType.BORDER_CONTROL) {
locimgId = R.drawable.warnings_border_control;
@ -1357,23 +1361,33 @@ public class RouteInfoWidgetsFactory {
}
}
if(visible) {
if(locimgId != imgId) {
if (locimgId != imgId) {
imgId = locimgId;
icon.setImageResource(locimgId);
}
if (!Algorithms.objectEquals(text, this.textString)) {
textString = text;
this.text.setText(this.textString);
if (alarm.getType() == AlarmInfoType.SPEED_LIMIT && americanType) {
this.text.setPadding(0, AndroidUtils.dpToPx(layout.getContext(), 20f), 0, 0);
Resources res = layout.getContext().getResources();
if (!Algorithms.objectEquals(text, cachedText)) {
cachedText = text;
widgetText.setText(cachedText);
if (alarm.getType() == AlarmInfoType.SPEED_LIMIT && americanType && !isCanadianRegion) {
int topPadding = res.getDimensionPixelSize(R.dimen.map_alarm_text_top_padding);
widgetText.setPadding(0, topPadding, 0, 0);
} else {
this.text.setPadding(0, 0, 0, 0);
widgetText.setPadding(0, 0, 0, 0);
}
}
if (!Algorithms.objectEquals(bottomText, this.bottomTextString)) {
bottomTextString = bottomText;
this.bottomText.setText(this.bottomTextString);
this.bottomText.setTextColor(ContextCompat.getColor(layout.getContext(),
if (!Algorithms.objectEquals(bottomText, cachedBottomText)) {
cachedBottomText = bottomText;
widgetBottomText.setText(cachedBottomText);
if (alarm.getType() == AlarmInfoType.SPEED_LIMIT && isCanadianRegion) {
int bottomPadding = res.getDimensionPixelSize(R.dimen.map_button_margin);
widgetBottomText.setPadding(0, 0, 0, bottomPadding);
widgetBottomText.setTextSize(COMPLEX_UNIT_PX, res.getDimensionPixelSize(R.dimen.map_alarm_bottom_si_text_size));
} else {
widgetBottomText.setPadding(0, 0, 0, 0);
widgetBottomText.setTextSize(COMPLEX_UNIT_PX, res.getDimensionPixelSize(R.dimen.map_alarm_bottom_text_size));
}
widgetBottomText.setTextColor(ContextCompat.getColor(layout.getContext(),
americanType ? R.color.color_black : R.color.color_white));
}
}