Add warnings and ruler control

This commit is contained in:
Victor Shcherb 2015-03-15 20:29:26 +01:00
parent fb55113c38
commit 14d772a214
15 changed files with 283 additions and 271 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -22,7 +22,6 @@
android:id="@+id/MapView" android:id="@+id/MapView"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/btn_flat"
android:contentDescription="@string/shared_string_map" android:contentDescription="@string/shared_string_map"
android:visibility="gone" /> android:visibility="gone" />

View file

@ -9,6 +9,29 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" > android:layout_height="wrap_content" >
<FrameLayout
android:id="@+id/map_alarm_warning"
android:layout_gravity="bottom|left"
android:layout_marginBottom="@dimen/map_button_shadow_height"
android:layout_marginLeft="@dimen/map_button_shadow_margin"
android:layout_width="@dimen/map_alarm_size"
android:layout_height="@dimen/map_alarm_size">
<ImageView
android:id="@+id/map_alarm_warning_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/warnings_limit" />
<TextView
android:id="@+id/map_alarm_warning_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textStyle="bold"
android:textColor="@color/color_black"
android:textSize="@dimen/map_alarm_text_size"
android:text="60"/>
</FrameLayout>
<FrameLayout <FrameLayout
android:id="@+id/map_app_mode_shadow" android:id="@+id/map_app_mode_shadow"
android:layout_width="@dimen/map_button_shadow_width" android:layout_width="@dimen/map_button_shadow_width"
@ -38,7 +61,6 @@
<LinearLayout <LinearLayout
android:id="@+id/map_transparency_layout" android:id="@+id/map_transparency_layout"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="bottom|center" android:layout_gravity="bottom|center"
android:layout_marginBottom="@dimen/map_button_size" android:layout_marginBottom="@dimen/map_button_size"
@ -81,6 +103,31 @@
android:layout_marginLeft="@dimen/map_button_spacing" android:layout_marginLeft="@dimen/map_button_spacing"
android:background="@drawable/btn_round" android:background="@drawable/btn_round"
android:src="@drawable/ic_action_remove_light" /> android:src="@drawable/ic_action_remove_light" />
<FrameLayout
android:id="@+id/map_ruler_layout"
android:layout_width="@dimen/map_ruler_width"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/map_button_margin">
<TextView
android:id="@+id/map_ruler_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="@dimen/map_ruler_bottom_margin"
android:text="100 m"
android:gravity="center_horizontal"
android:layout_gravity="bottom"
android:textSize="@dimen/map_widget_text_size_small"
/>
<ImageView
android:id="@+id/map_ruler_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/ruler"
/>
</FrameLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -58,7 +58,11 @@
<dimen name="map_route_buttons_height">54dp</dimen> <dimen name="map_route_buttons_height">54dp</dimen>
<dimen name="map_address_height">40dp</dimen> <dimen name="map_address_height">40dp</dimen>
<dimen name="map_button_size">48dp</dimen> <dimen name="map_button_size">48dp</dimen>
<dimen name="map_ruler_width">100dp</dimen>
<dimen name="map_ruler_bottom_margin">7dp</dimen>
<dimen name="map_button_shadow_width">52dp</dimen> <dimen name="map_button_shadow_width">52dp</dimen>
<dimen name="map_alarm_size">78dp</dimen>
<dimen name="map_alarm_text_size">25sp</dimen>
<dimen name="map_button_shadow_height">85dp</dimen> <dimen name="map_button_shadow_height">85dp</dimen>
<dimen name="map_widget_icon">24dp</dimen> <dimen name="map_widget_icon">24dp</dimen>
<dimen name="map_widget_height">32dp</dimen> <dimen name="map_widget_height">32dp</dimen>

View file

@ -43,12 +43,15 @@ public class OsmAndFormatter {
int generator = 1; int generator = 1;
byte pointer = 1; byte pointer = 1;
double point = mainUnitInMeter; double point = mainUnitInMeter;
double roundDist = 1;
while (distInMeters * point > generator) { while (distInMeters * point > generator) {
roundDist = (generator / point);
if (pointer++ % 3 == 2) { if (pointer++ % 3 == 2) {
generator = generator * 5 / 2; generator = generator * 5 / 2;
} else { } else {
generator *= 2; generator *= 2;
} }
if (point == mainUnitInMeter && metersInSecondUnit * mainUnitInMeter * 0.9f <= generator) { if (point == mainUnitInMeter && metersInSecondUnit * mainUnitInMeter * 0.9f <= generator) {
point = 1 / metersInSecondUnit; point = 1 / metersInSecondUnit;
generator = 1; generator = 1;
@ -56,7 +59,7 @@ public class OsmAndFormatter {
} }
} }
return (generator / point); return roundDist;
} }
public static String getFormattedRoundDistanceKm(float meters, int digits, OsmandApplication ctx) { public static String getFormattedRoundDistanceKm(float meters, int digits, OsmandApplication ctx) {

View file

@ -92,9 +92,6 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override @Override
public void initLayer(final OsmandMapTileView view) { public void initLayer(final OsmandMapTileView view) {
// TODO
// rulerControl = init(new RulerControl(zoomControls, mapActivity, showUIHandler, scaleCoefficient), parent,
// rightGravity);
showUIHandler = new Handler(); showUIHandler = new Handler();
initTopControls(); initTopControls();
initTransparencyBar(); initTransparencyBar();
@ -182,8 +179,6 @@ public class MapControlsLayer extends OsmandMapLayer {
}); });
View compass = mapActivity.findViewById(R.id.map_compass_button); View compass = mapActivity.findViewById(R.id.map_compass_button);
// protected void onDraw(Canvas canvas) {
// }
compassHud = createHudButton((ImageView) compass, R.drawable.map_compass).setIconColorId(0).setBg( compassHud = createHudButton((ImageView) compass, R.drawable.map_compass).setIconColorId(0).setBg(
R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night); R.drawable.btn_inset_circle, R.drawable.btn_inset_circle_night);
compassHud.compass = true; compassHud.compass = true;
@ -555,6 +550,9 @@ public class MapControlsLayer extends OsmandMapLayer {
transparencyBar.setMax(255); transparencyBar.setMax(255);
if (settingsToTransparency != null) { if (settingsToTransparency != null) {
transparencyBar.setProgress(settingsToTransparency.get()); transparencyBar.setProgress(settingsToTransparency.get());
transparencyBarLayout.setVisibility(View.VISIBLE);
} else {
transparencyBarLayout.setVisibility(View.GONE);
} }
transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

View file

@ -19,17 +19,17 @@ import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget; import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.AlarmWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory.RulerWidget;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
public class MapInfoLayer extends OsmandMapLayer { public class MapInfoLayer extends OsmandMapLayer {
@ -44,7 +44,8 @@ public class MapInfoLayer extends OsmandMapLayer {
private ImageButton expand; private ImageButton expand;
private static boolean expanded = false; private static boolean expanded = false;
private BaseMapWidget lanesControl; private BaseMapWidget lanesControl;
private BaseMapWidget alarmControl; private AlarmWidget alarmControl;
private RulerWidget rulerControl;
private MapWidgetRegistry mapInfoControls; private MapWidgetRegistry mapInfoControls;
private OsmandSettings settings; private OsmandSettings settings;
@ -74,12 +75,9 @@ public class MapInfoLayer extends OsmandMapLayer {
leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel); leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel);
rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel); rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel);
expand = (ImageButton) map.findViewById(R.id.map_collapse_button); expand = (ImageButton) map.findViewById(R.id.map_collapse_button);
// update and create controls // update and create controls
registerAllControls(); registerAllControls();
alarmControl.setVisibility(View.GONE);
lanesControl.setVisibility(View.GONE);
recreateControls(); recreateControls();
} }
@ -95,11 +93,17 @@ public class MapInfoLayer extends OsmandMapLayer {
OsmandApplication app = view.getApplication(); OsmandApplication app = view.getApplication();
lanesControl = ric.createLanesControl(map, view); lanesControl = ric.createLanesControl(map, view);
lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free)); lanesControl.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
lanesControl.setVisibility(View.GONE);
streetNameView = new MapInfoWidgetsFactory.TopTextView(map.getMyApplication(), map); streetNameView = new MapInfoWidgetsFactory.TopTextView(map.getMyApplication(), map);
updateStreetName(calculateTextState()); updateStreetName(calculateTextState());
alarmControl = ric.createAlarmInfoControl(app, map); alarmControl = ric.createAlarmInfoControl(app, map);
alarmControl.setVisibility(false);
rulerControl = ric.createRulerControl(app, map);
rulerControl.setVisibility(false);
// register left stack // register left stack
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false); NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5); registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
@ -159,6 +163,7 @@ public class MapInfoLayer extends OsmandMapLayer {
int leftRes; int leftRes;
int expand; int expand;
int boxFree; int boxFree;
int textShadowRadius;
} }
@ -179,6 +184,7 @@ public class MapInfoLayer extends OsmandMapLayer {
updateReg(ts, reg); updateReg(ts, reg);
} }
updateStreetName(ts); updateStreetName(ts);
rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textShadowRadius);
this.expand.setBackgroundResource(ts.expand); this.expand.setBackgroundResource(ts.expand);
rightStack.invalidate(); rightStack.invalidate();
leftStack.invalidate(); leftStack.invalidate();
@ -187,14 +193,14 @@ public class MapInfoLayer extends OsmandMapLayer {
private void updateStreetName(TextState ts) { private void updateStreetName(TextState ts) {
streetNameView.setBackgroundResource(ts.boxTop); streetNameView.setBackgroundResource(ts.boxTop);
streetNameView.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold); streetNameView.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
} }
private void updateReg(TextState ts, MapWidgetRegInfo reg) { private void updateReg(TextState ts, MapWidgetRegInfo reg) {
View v = reg.widget.getView().findViewById(R.id.widget_bg); View v = reg.widget.getView().findViewById(R.id.widget_bg);
if(v != null) { if(v != null) {
v.setBackgroundResource(reg.left ? ts.leftRes : ts.rightRes); v.setBackgroundResource(reg.left ? ts.leftRes : ts.rightRes);
reg.widget.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold); reg.widget.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
} }
} }
@ -211,6 +217,7 @@ public class MapInfoLayer extends OsmandMapLayer {
if (!transparent && !nightMode) { if (!transparent && !nightMode) {
ts.textShadowColor = Color.TRANSPARENT; ts.textShadowColor = Color.TRANSPARENT;
} }
ts.textShadowRadius = ts.textShadowColor == 0 ? 0 : 8;
if (transparent) { if (transparent) {
ts.boxTop = R.drawable.btn_flat_trans; ts.boxTop = R.drawable.btn_flat_trans;
ts.rightRes = R.drawable.btn_left_round_trans; ts.rightRes = R.drawable.btn_left_round_trans;
@ -243,9 +250,10 @@ public class MapInfoLayer extends OsmandMapLayer {
updateColorShadowsOfText(); updateColorShadowsOfText();
mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded); mapInfoControls.updateInfo(settings.getApplicationMode(), drawSettings, expanded);
streetNameView.updateInfo(drawSettings); streetNameView.updateInfo(drawSettings);
alarmControl.updateInfo(drawSettings);
rulerControl.updateInfo(tileBox, drawSettings);
// TODO // TODO
// lanesControl.updateInfo(drawSettings); // lanesControl.updateInfo(drawSettings);
// alarmControl.updateInfo(drawSettings);
} }

View file

@ -1,97 +0,0 @@
package net.osmand.plus.views.controls;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.ShadowText;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.text.TextPaint;
import android.view.View;
public class RulerControl {
//ruler and ruler label appeareance:
// Day view: color black, shadowColor white (transpparent skin or not)
// Night view: color widgettext_night, shadowColor always use widgettext_shadow_night, same as widget background color for non-transparent night skin (from box_night_free_simple.9.png)
ShadowText cacheRulerText = null;
double cacheRulerZoom = 0;
double cacheRulerTileX = 0;
double cacheRulerTileY = 0;
float cacheRulerTextLen = 0;
Drawable rulerDrawable;
TextPaint rulerTextPaint;
final static double screenRulerPercent = 0.25;
boolean isNightRemembered = false;
private MapActivity mapActivity;
private float scaleCoefficient;
public RulerControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
this.mapActivity = mapActivity;
this.scaleCoefficient = scaleCoefficient;
rulerTextPaint = new TextPaint();
rulerTextPaint.setTextSize(20 * scaleCoefficient);
rulerTextPaint.setAntiAlias(true);
rulerDrawable = mapActivity.getResources().getDrawable(R.drawable.ruler);
}
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if (!mapActivity.getMyApplication().getSettings().SHOW_RULER.get()) {
return;
}
OsmandMapTileView view = mapActivity.getMapView();
boolean isNight = nightMode == null ? false : nightMode.isNightMode();
// update cache
if (view.isZooming()) {
cacheRulerText = null;
} else if (((isNight != isNightRemembered) || (tb.getZoom() != cacheRulerZoom) || Math.abs(tb.getCenterTileX()
- cacheRulerTileX)
+ Math.abs(tb.getCenterTileY() - cacheRulerTileY) > 1)
&& tb.getPixWidth() > 0) {
cacheRulerZoom = (tb.getZoom());
cacheRulerTileX = tb.getCenterTileX();
cacheRulerTileY = tb.getCenterTileY();
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
double pixDensity = tb.getPixWidth() / dist;
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getApplication());
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist,
view.getApplication()));
cacheRulerTextLen = rulerTextPaint.measureText(cacheRulerText.getText());
rulerDrawable = (isNight ? mapActivity.getResources().getDrawable(R.drawable.ruler_night) : mapActivity
.getResources().getDrawable(R.drawable.ruler));
Rect bounds = rulerDrawable.getBounds();
// TODO
// bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
bounds.left = bounds.right - cacheRulerDistPix;
rulerDrawable.setBounds(bounds);
rulerDrawable.invalidateSelf();
}
if (cacheRulerText != null) {
Rect bounds = rulerDrawable.getBounds();
// int bottom = (int) (view.getHeight() );
// if (bounds.bottom != bottom) {
// bounds.bottom = bottom;
// bounds.top = bounds.bottom - rulerDrawable.getMinimumHeight();
// rulerDrawable.setBounds(bounds);
// rulerDrawable.invalidateSelf();
// }
rulerDrawable.draw(canvas);
int shadowColor = isNight == true ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night)
: Color.WHITE;
cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8
* scaleCoefficient, rulerTextPaint, shadowColor);
}
isNightRemembered = isNight;
}
}

View file

@ -311,15 +311,15 @@ public class MapInfoWidgetsFactory {
return false; return false;
} }
public void updateTextColor(int textColor, int textShadowColor, boolean bold) { public void updateTextColor(int textColor, int textShadowColor, boolean bold, int rad) {
updateTextColor(addressText, textColor, textShadowColor, bold); updateTextColor(addressText, textColor, textShadowColor, bold, rad);
updateTextColor((TextView) waypointInfoBar.findViewById(R.id.waypoint_text), updateTextColor((TextView) waypointInfoBar.findViewById(R.id.waypoint_text),
textColor, textShadowColor, bold); textColor, textShadowColor, bold, rad);
} }
private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold) { private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold, int rad) {
tv.setTextColor(textColor); tv.setTextColor(textColor);
tv.setShadowLayer(textShadowColor == 0 ? 0 : 8, 0, 0, textShadowColor); tv.setShadowLayer(rad, 0, 0, textShadowColor);
tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL); tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
} }

View file

@ -208,14 +208,14 @@ public class MapWidgetRegistry {
} }
private void resetDefaultAppearance(ApplicationMode appMode) { private void resetDefaultAppearance(ApplicationMode appMode) {
settings.SHOW_RULER.resetToDefault(); // settings.SHOW_RULER.resetToDefault();
settings.SHOW_DESTINATION_ARROW.resetToDefault(); settings.SHOW_DESTINATION_ARROW.resetToDefault();
settings.TRANSPARENT_MAP_THEME.resetToDefault(); settings.TRANSPARENT_MAP_THEME.resetToDefault();
settings.CENTER_POSITION_ON_MAP.resetToDefault(); settings.CENTER_POSITION_ON_MAP.resetToDefault();
} }
public void addControlsAppearance(final MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) { public void addControlsAppearance(final MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER); // addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER);
addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW); addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW);
addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME); addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP); addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);

View file

@ -8,6 +8,7 @@ import java.util.List;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -31,20 +32,21 @@ import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.controls.MapRouteInfoControl; import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.router.RouteResultPreparation; import net.osmand.router.RouteResultPreparation;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import android.app.Activity; import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class RouteInfoWidgetsFactory { public class RouteInfoWidgetsFactory {
@ -630,35 +632,89 @@ public class RouteInfoWidgetsFactory {
return laneStraight; return laneStraight;
} }
public static class RulerWidget {
public BaseMapWidget createAlarmInfoControl(final OsmandApplication app, MapActivity ma) { private View layout;
final RoutingHelper rh = app.getRoutingHelper(); private ImageView icon;
final WaypointHelper wh = app.getWaypointHelper(); private TextView text;
final OsmandSettings settings = app.getSettings(); private MapActivity ma;
final OsmAndLocationProvider locationProvider = app.getLocationProvider(); private String cacheRulerText;
final MapViewTrackingUtilities trackingUtilities = ma.getMapViewTrackingUtilities(); private int maxWidth;
final Paint paintCircle = new Paint(); private int cacheRulerZoom;
final float th = 11 * scaleCoefficient; private double cacheRulerTileX;
paintCircle.setColor(Color.rgb(225, 15, 15)); private double cacheRulerTileY;
paintCircle.setStrokeWidth(11 * scaleCoefficient);
paintCircle.setStyle(Style.STROKE);
paintCircle.setAntiAlias(true);
paintCircle.setDither(true);
final Paint content = new Paint();
content.setColor(Color.WHITE);
content.setStyle(Style.FILL);
final Paint ptext = new Paint();
ptext.setTextSize(27 * scaleCoefficient);
ptext.setFakeBoldText(true);
ptext.setAntiAlias(true);
ptext.setTextAlign(Align.CENTER);
final BaseMapWidget alarm = new BaseMapWidget(ma) { public RulerWidget(final OsmandApplication app, MapActivity ma) {
private int textDy = 0; this.ma = ma;
private String text = ""; layout = ma.findViewById(R.id.map_ruler_layout);
private Bitmap img = null; icon = (ImageView) ma.findViewById(R.id.map_ruler_image);
text = (TextView) ma.findViewById(R.id.map_ruler_text);
maxWidth = ma.getResources().getDimensionPixelSize(R.dimen.map_ruler_width);
}
public void updateTextSize(boolean isNight, int textColor, int textShadowColor, int shadowRadius) {
text.setTextColor(textColor);
text.setShadowLayer(shadowRadius, 0, 0, textShadowColor);
icon.setBackgroundResource(isNight ? R.drawable.ruler_night : R.drawable.ruler);
}
public boolean updateInfo(RotatedTileBox tb, DrawSettings nightMode) {
boolean visible = true;
OsmandMapTileView view = ma.getMapView();
// update cache
if (view.isZooming()) {
visible = false;
} else if ((tb.getZoom() != cacheRulerZoom || Math.abs(tb.getCenterTileX() - cacheRulerTileX) > 1 || Math
.abs(tb.getCenterTileY() - cacheRulerTileY) > 1) && tb.getPixWidth() > 0 && maxWidth > 0) {
cacheRulerZoom = tb.getZoom();
cacheRulerTileX = tb.getCenterTileX();
cacheRulerTileY = tb.getCenterTileY();
final double dist = tb.getDistance(0, tb.getPixHeight() / 2, tb.getPixWidth(), tb.getPixHeight() / 2);
double pixDensity = tb.getPixWidth() / dist;
double roundedDist = OsmAndFormatter.calculateRoundedDist(maxWidth /
pixDensity, view.getApplication());
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
cacheRulerText = OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getApplication());
text.setText(cacheRulerText);
LinearLayout.LayoutParams lp = (LayoutParams) layout.getLayoutParams();
lp.width = cacheRulerDistPix;
layout.setLayoutParams(lp);
layout.requestLayout();
}
updateVisibility(layout, visible);
return true;
}
public void setVisibility(boolean visibility) {
layout.setVisibility(visibility ? View.VISIBLE : View.GONE);
}
}
public static class AlarmWidget {
private View layout;
private ImageView icon;
private TextView text;
private OsmandSettings settings;
private RoutingHelper rh;
private MapViewTrackingUtilities trackingUtilities;
private OsmAndLocationProvider locationProvider;
private WaypointHelper wh;
private int imgId; private int imgId;
@Override private String textString;
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);
settings = app.getSettings();
rh = ma.getRoutingHelper();
trackingUtilities = ma.getMapViewTrackingUtilities();
locationProvider = app.getLocationProvider();
wh = app.getWaypointHelper();
}
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
boolean trafficWarnings = settings.SHOW_TRAFFIC_WARNINGS.get(); boolean trafficWarnings = settings.SHOW_TRAFFIC_WARNINGS.get();
boolean cams = settings.SHOW_CAMERAS.get(); boolean cams = settings.SHOW_CAMERAS.get();
@ -679,49 +735,42 @@ public class RouteInfoWidgetsFactory {
} }
} }
if(alarm != null) { if(alarm != null) {
int locimgId = 0; int locimgId = R.drawable.warnings_limit;
int textDy = 0; String text = "";
String text = null;
if(alarm.getType() == AlarmInfoType.SPEED_LIMIT) { if(alarm.getType() == AlarmInfoType.SPEED_LIMIT) {
if(settings.DRIVING_REGION.get().americanSigns){ if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_speed_limit_us; locimgId = R.drawable.warnings_speed_limit_us;
textDy = (int) (-12 * scaleCoefficient);
//else case is done by drawing red ring //else case is done by drawing red ring
} }
text = alarm.getIntValue() +""; text = alarm.getIntValue() +"";
} else if(alarm.getType() == AlarmInfoType.SPEED_CAMERA) { } else if(alarm.getType() == AlarmInfoType.SPEED_CAMERA) {
locimgId = R.drawable.warnings_speed_camera; locimgId = R.drawable.warnings_speed_camera;
text = "";
} else if(alarm.getType() == AlarmInfoType.BORDER_CONTROL) { } else if(alarm.getType() == AlarmInfoType.BORDER_CONTROL) {
locimgId = R.drawable.warnings_border_control; locimgId = R.drawable.warnings_border_control;
text = "";
} else if(alarm.getType() == AlarmInfoType.TOLL_BOOTH) { } else if(alarm.getType() == AlarmInfoType.TOLL_BOOTH) {
//image done by drawing red ring //image done by drawing red ring
text = "$";
} else if(alarm.getType() == AlarmInfoType.TRAFFIC_CALMING) { } else if(alarm.getType() == AlarmInfoType.TRAFFIC_CALMING) {
if(settings.DRIVING_REGION.get().americanSigns){ if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_traffic_calming_us; locimgId = R.drawable.warnings_traffic_calming_us;
} else { } else {
locimgId = R.drawable.warnings_traffic_calming; locimgId = R.drawable.warnings_traffic_calming;
} }
text = "";
} else if(alarm.getType() == AlarmInfoType.STOP) { } else if(alarm.getType() == AlarmInfoType.STOP) {
locimgId = R.drawable.warnings_stop; locimgId = R.drawable.warnings_stop;
text = "";
} else if(alarm.getType() == AlarmInfoType.RAILWAY) { } else if(alarm.getType() == AlarmInfoType.RAILWAY) {
if(settings.DRIVING_REGION.get().americanSigns){ if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_railways_us; locimgId = R.drawable.warnings_railways_us;
} else { } else {
locimgId = R.drawable.warnings_railways; locimgId = R.drawable.warnings_railways;
} }
text = "";
} else if(alarm.getType() == AlarmInfoType.PEDESTRIAN) { } else if(alarm.getType() == AlarmInfoType.PEDESTRIAN) {
if(settings.DRIVING_REGION.get().americanSigns){ if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_pedestrian_us; locimgId = R.drawable.warnings_pedestrian_us;
} else { } else {
locimgId = R.drawable.warnings_pedestrian; locimgId = R.drawable.warnings_pedestrian;
} }
text = ""; } else {
text = null;
} }
visible = (text != null && text.length() > 0) || (locimgId != 0); visible = (text != null && text.length() > 0) || (locimgId != 0);
if (visible) { if (visible) {
@ -736,44 +785,24 @@ public class RouteInfoWidgetsFactory {
if(visible) { if(visible) {
if(locimgId != imgId) { if(locimgId != imgId) {
imgId = locimgId; imgId = locimgId;
if(imgId == 0) { icon.setImageResource(locimgId);
img = null;
} else {
img = BitmapFactory.decodeResource(getResources(), locimgId);
} }
invalidate(); if (!Algorithms.objectEquals(text, this.textString)) {
} textString = text;
if(text != null && !text.equals(this.text)) { this.text.setText(this.textString);
this.text = text;
this.textDy = textDy;
invalidate();
} }
} }
} }
} }
updateVisibility(visible); updateVisibility(layout, visible);
return true; return true;
} }
@Override public void setVisibility(boolean visibility) {
protected void onDraw(Canvas canvas) { layout.setVisibility(visibility ? View.VISIBLE : View.GONE);
if(img == null) {
RectF f = new RectF(th / 2, th / 2, getWidth() - th / 2, getHeight() - th / 2);
canvas.drawOval(f, content);
canvas.drawOval(f, paintCircle);
} else {
canvas.drawBitmap(img, 0, 0, paintCircle);
}
if(text.length() > 0) {
canvas.drawText(text, getWidth() / 2 , getHeight() / 2 + ptext.descent() + 3 * scaleCoefficient - textDy, ptext);
} }
} }
};
// initial state
// nextTurnInfo.setVisibility(View.GONE);
return alarm;
}
public static boolean distChanged(int oldDist, int dist){ public static boolean distChanged(int oldDist, int dist){
@ -782,4 +811,25 @@ public class RouteInfoWidgetsFactory {
} }
return true; return true;
} }
public AlarmWidget createAlarmInfoControl(OsmandApplication app, MapActivity map) {
return new AlarmWidget(app, map);
}
public RulerWidget createRulerControl(OsmandApplication app, MapActivity map) {
return new RulerWidget(app, map);
}
protected static boolean updateVisibility(View view, boolean visible) {
if (visible != (view.getVisibility() == View.VISIBLE)) {
if (visible) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
view.invalidate();
return true;
}
return false;
}
} }

View file

@ -143,14 +143,14 @@ public class TextInfoWidget {
return explicitlyVisible; return explicitlyVisible;
} }
public void updateTextColor(int textColor, int textShadowColor, boolean bold) { public void updateTextColor(int textColor, int textShadowColor, boolean bold, int rad) {
updateTextColor(smallTextView, textColor, textShadowColor, bold); updateTextColor(smallTextView, textColor, textShadowColor, bold, rad);
updateTextColor(textView, textColor, textShadowColor, bold); updateTextColor(textView, textColor, textShadowColor, bold, rad);
} }
private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold) { private void updateTextColor(TextView tv, int textColor, int textShadowColor, boolean textBold, int rad) {
tv.setTextColor(textColor); tv.setTextColor(textColor);
tv.setShadowLayer(textShadowColor == 0 ? 0 : 8, 0, 0, textShadowColor); tv.setShadowLayer(rad, 0, 0, textShadowColor);
tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL); tv.setTypeface(Typeface.DEFAULT, textBold ? Typeface.BOLD : Typeface.NORMAL);
} }