From 24f59ca8abdaffe133d2a5cd8068e71a8b481125 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 27 Jul 2020 23:02:29 +0300 Subject: [PATCH] Add ruler widgets --- OsmAnd/res/layout-land/map_hud_bottom.xml | 40 +-------- OsmAnd/res/layout/map_hud_bottom.xml | 7 +- OsmAnd/res/layout/map_ruler.xml | 4 +- OsmAnd/res/layout/track_appearance.xml | 37 ++++++-- .../ChooseRouteFragment.java | 12 +-- .../plus/track/TrackAppearanceFragment.java | 74 +++++++++------- .../osmand/plus/views/MapControlsLayer.java | 8 +- .../net/osmand/plus/views/MapInfoLayer.java | 84 +++++++++++++------ .../mapwidgets/RouteInfoWidgetsFactory.java | 18 ++-- .../views/mapwidgets/widgets/RulerWidget.java | 25 +++--- 10 files changed, 170 insertions(+), 139 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_bottom.xml b/OsmAnd/res/layout-land/map_hud_bottom.xml index e2c6d8556f..cf61fd4d76 100644 --- a/OsmAnd/res/layout-land/map_hud_bottom.xml +++ b/OsmAnd/res/layout-land/map_hud_bottom.xml @@ -133,45 +133,7 @@ - - - - - - - - - - - + diff --git a/OsmAnd/res/layout/map_hud_bottom.xml b/OsmAnd/res/layout/map_hud_bottom.xml index f9f2e7ec30..e76a504d47 100644 --- a/OsmAnd/res/layout/map_hud_bottom.xml +++ b/OsmAnd/res/layout/map_hud_bottom.xml @@ -117,7 +117,12 @@ tools:src="@drawable/ic_action_remove_dark" android:contentDescription="@string/snap_to_road" /> - + diff --git a/OsmAnd/res/layout/map_ruler.xml b/OsmAnd/res/layout/map_ruler.xml index 62f2b1cca4..8f6a66596d 100644 --- a/OsmAnd/res/layout/map_ruler.xml +++ b/OsmAnd/res/layout/map_ruler.xml @@ -3,9 +3,7 @@ android:id="@+id/map_ruler_layout" android:layout_width="@dimen/map_ruler_width" android:layout_height="wrap_content" - android:layout_gravity="bottom" - android:layout_marginStart="@dimen/map_button_margin" - android:layout_marginLeft="@dimen/map_button_margin"> + android:layout_gravity="bottom"> - + android:layout_gravity="bottom"> + + + + + + buttonIds) { - for (Iterator iterator = controls.iterator(); iterator.hasNext(); ) { + List hudButtons = new ArrayList<>(controls); + for (Iterator iterator = hudButtons.iterator(); iterator.hasNext(); ) { MapHudButton mapHudButton = iterator.next(); if (buttonIds.contains(mapHudButton.id)) { iterator.remove(); } } + controls = hudButtons; } public void showMapControlsIfHidden() { diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 27cb7c9e28..9a4ad3b74c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -13,13 +13,13 @@ import androidx.core.content.ContextCompat; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.views.mapwidgets.LanesControl; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; -import net.osmand.plus.views.mapwidgets.widgetstates.CompassRulerWidgetState; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopCoordinatesView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -28,15 +28,18 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; -import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; -import net.osmand.plus.views.mapwidgets.widgets.NextTurnWidget; import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.widgets.AlarmWidget; -import net.osmand.plus.views.mapwidgets.widgetstates.BearingWidgetState; -import net.osmand.plus.views.mapwidgets.LanesControl; +import net.osmand.plus.views.mapwidgets.widgets.NextTurnWidget; import net.osmand.plus.views.mapwidgets.widgets.RulerWidget; -import net.osmand.plus.views.mapwidgets.widgetstates.TimeWidgetState; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; +import net.osmand.plus.views.mapwidgets.widgetstates.BearingWidgetState; +import net.osmand.plus.views.mapwidgets.widgetstates.CompassRulerWidgetState; +import net.osmand.plus.views.mapwidgets.widgetstates.TimeWidgetState; +import net.osmand.plus.views.mapwidgets.widgetstates.WidgetState; + +import java.util.ArrayList; +import java.util.List; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_ALTITUDE; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_BATTERY; @@ -58,18 +61,20 @@ import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_SPEED; import static net.osmand.plus.views.mapwidgets.MapWidgetRegistry.WIDGET_TIME; public class MapInfoLayer extends OsmandMapLayer { + private final MapActivity map; private final RouteLayer routeLayer; private OsmandMapTileView view; - + // groups private LinearLayout rightStack; private LinearLayout leftStack; - private ImageButton expand; + private ImageButton expand; + private View mapRulerLayout; private static boolean expanded = false; private LanesControl lanesControl; private AlarmWidget alarmControl; - private RulerWidget rulerControl; + private List rulerWidgets; private MapWidgetRegistry mapInfoControls; private OsmandSettings settings; @@ -96,9 +101,11 @@ public class MapInfoLayer extends OsmandMapLayer { public void initLayer(final OsmandMapTileView view) { this.view = view; mapInfoControls = map.getMapLayers().getMapWidgetRegistry() ; - leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel); - rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel); - expand = (ImageButton) map.findViewById(R.id.map_collapse_button); + leftStack = map.findViewById(R.id.map_left_widgets_panel); + rightStack = map.findViewById(R.id.map_right_widgets_panel); + expand = map.findViewById(R.id.map_collapse_button); + mapRulerLayout = map.findViewById(R.id.map_ruler_layout); + // update and create controls registerAllControls(); map.getMyApplication().getAidlApi().registerWidgetControls(map); @@ -159,11 +166,12 @@ public class MapInfoLayer extends OsmandMapLayer { } public void registerAllControls(){ + rulerWidgets = new ArrayList<>(); RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory(); MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory(); MapMarkersWidgetsFactory mwf = map.getMapLayers().getMapMarkersLayer().getWidgetsFactory(); OsmandApplication app = view.getApplication(); - lanesControl = ric.createLanesControl(map, view); + lanesControl = RouteInfoWidgetsFactory.createLanesControl(map, view); TextState ts = calculateTextState(); streetNameView = new TopTextView(map.getMyApplication(), map); @@ -175,12 +183,11 @@ public class MapInfoLayer extends OsmandMapLayer { topToolbarView = new TopToolbarView(map); updateTopToolbar(false); - alarmControl = ric.createAlarmInfoControl(app, map); + alarmControl = RouteInfoWidgetsFactory.createAlarmInfoControl(app, map); alarmControl.setVisibility(false); - - rulerControl = ric.createRulerControl(app, map); - rulerControl.setVisibility(false); - + + setupRulerWidget(mapRulerLayout); + // register left stack registerSideWidget(null, R.drawable.ic_action_compass, R.string.map_widget_compass, WIDGET_COMPASS, true, 4); @@ -236,7 +243,7 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.populateStackControl(rightStack, settings.getApplicationMode(), false, expanded); rightStack.requestLayout(); - expand.setVisibility(mapInfoControls.hasCollapsibles(settings.getApplicationMode())? + expand.setVisibility(mapInfoControls.hasCollapsibles(settings.getApplicationMode())? View.VISIBLE : View.GONE); Drawable expandIcon = map.getMyApplication().getUIUtilities().getMapIcon(expanded ? R.drawable.ic_action_arrow_up : R.drawable.ic_action_arrow_down, true); @@ -252,15 +259,34 @@ public class MapInfoLayer extends OsmandMapLayer { }); } + public RulerWidget setupRulerWidget(View mapRulerView) { + RulerWidget rulerWidget = RouteInfoWidgetsFactory.createRulerControl(map, mapRulerView); + rulerWidget.setVisibility(false); + + TextState ts = calculateTextState(); + boolean nightMode = drawSettings != null && drawSettings.isNightMode(); + rulerWidget.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity())); + + rulerWidgets.add(rulerWidget); + + return rulerWidget; + } + + public void removeRulerWidgets(List rulers) { + List widgetList = new ArrayList<>(rulerWidgets); + widgetList.removeAll(rulers); + rulerWidgets = widgetList; + } + public void setTrackChartPoints(TrackChartPoints trackChartPoints) { routeLayer.setTrackChartPoints(trackChartPoints); } private static class TextState { - boolean textBold ; + boolean textBold; boolean night; - int textColor ; - int textShadowColor ; + int textColor; + int textShadowColor; int boxTop; int rightRes; int leftRes; @@ -269,7 +295,6 @@ public class MapInfoLayer extends OsmandMapLayer { int textShadowRadius; } - private int themeId = -1; public void updateColorShadowsOfText() { boolean transparent = view.getSettings().TRANSPARENT_MAP_THEME.get(); @@ -290,12 +315,15 @@ public class MapInfoLayer extends OsmandMapLayer { updateTopCoordinates(nightMode, ts); updateTopToolbar(nightMode); lanesControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius / 2); - rulerControl.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity())); int padding = expand.getPaddingLeft(); expand.setBackgroundResource(ts.expand); expand.setPadding(padding, padding, padding, padding); rightStack.invalidate(); leftStack.invalidate(); + + for (RulerWidget rulerWidget : rulerWidgets) { + rulerWidget.updateTextSize(nightMode, ts.textColor, ts.textShadowColor, (int) (2 * view.getDensity())); + } } } @@ -371,9 +399,11 @@ public class MapInfoLayer extends OsmandMapLayer { topToolbarView.updateInfo(); topCoordinatesView.updateInfo(); alarmControl.updateInfo(drawSettings); - rulerControl.updateInfo(tileBox, drawSettings); lanesControl.updateInfo(drawSettings); - + + for (RulerWidget rulerWidget : rulerWidgets) { + rulerWidget.updateInfo(tileBox, drawSettings); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 3fb7a90e70..e3a16e5975 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -190,7 +190,7 @@ public class RouteInfoWidgetsFactory { if (DateFormat.is24HourFormat(ctx)) { setText(DateFormat.format("k:mm", toFindTime).toString(), null); //$NON-NLS-1$ } else { - setText(DateFormat.format("h:mm", toFindTime).toString(), + setText(DateFormat.format("h:mm", toFindTime).toString(), DateFormat.format("aa", toFindTime).toString()); //$NON-NLS-1$ } return true; @@ -551,10 +551,6 @@ public class RouteInfoWidgetsFactory { return bearingControl; } - public LanesControl createLanesControl(final MapActivity map, final OsmandMapTileView view) { - return new LanesControl(map, view); - } - public static boolean distChanged(int oldDist, int dist) { return oldDist == 0 || Math.abs(oldDist - dist) >= 10; } @@ -563,11 +559,15 @@ public class RouteInfoWidgetsFactory { return Math.abs(oldDegrees - degrees) >= 1; } - public AlarmWidget createAlarmInfoControl(OsmandApplication app, MapActivity map) { + public static LanesControl createLanesControl(final MapActivity map, final OsmandMapTileView view) { + return new LanesControl(map, view); + } + + public static AlarmWidget createAlarmInfoControl(OsmandApplication app, MapActivity map) { return new AlarmWidget(app, map); } - - public RulerWidget createRulerControl(OsmandApplication app, MapActivity map) { - return new RulerWidget(app, map); + + public static RulerWidget createRulerControl(MapActivity map, View view) { + return new RulerWidget(map, view); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java index 1952df87e8..8d576c72cf 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/widgets/RulerWidget.java @@ -7,38 +7,37 @@ import android.widget.TextView; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; public class RulerWidget { + private MapActivity mapActivity; + private OsmandPreference mapDensity; + private View layout; private ImageView icon; private TextView text; private TextView textShadow; - private MapActivity mapActivity; + private String cacheRulerText; private int maxWidth; - private float cacheMapDensity; - private OsmandSettings.OsmandPreference mapDensity; private int cacheRulerZoom; + private float cacheMapDensity; private double cacheRulerTileX; private double cacheRulerTileY; - private boolean orientationPortrait; - public RulerWidget(OsmandApplication app, MapActivity mapActivity) { + public RulerWidget(MapActivity mapActivity, View view) { this.mapActivity = mapActivity; - layout = mapActivity.findViewById(R.id.map_ruler_layout); - icon = mapActivity.findViewById(R.id.map_ruler_image); - text = mapActivity.findViewById(R.id.map_ruler_text); - textShadow = mapActivity.findViewById(R.id.map_ruler_text_shadow); - maxWidth = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); - orientationPortrait = AndroidUiHelper.isOrientationPortrait(mapActivity); + layout = view.findViewById(R.id.map_ruler_layout); + icon = view.findViewById(R.id.map_ruler_image); + text = view.findViewById(R.id.map_ruler_text); + textShadow = view.findViewById(R.id.map_ruler_text_shadow); + maxWidth = view.getResources().getDimensionPixelSize(R.dimen.map_ruler_width); mapDensity = mapActivity.getMyApplication().getSettings().MAP_DENSITY; cacheMapDensity = mapDensity.get(); }