From 2d1db11a491cd3236698e08a0afe749b5d5eeed2 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 9 Nov 2017 13:58:53 +0200 Subject: [PATCH] Add the ability to select the number of widgets to display --- OsmAnd/res/menu/active_markers_menu.xml | 10 ++++ OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/OsmandSettings.java | 2 + .../DirectionIndicationDialogFragment.java | 60 ++++++++++++++++++- .../osmand/plus/views/MapMarkersLayer.java | 6 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 2 +- .../views/mapwidgets/MapWidgetRegistry.java | 6 +- 7 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 OsmAnd/res/menu/active_markers_menu.xml diff --git a/OsmAnd/res/menu/active_markers_menu.xml b/OsmAnd/res/menu/active_markers_menu.xml new file mode 100644 index 0000000000..3d70a8e87d --- /dev/null +++ b/OsmAnd/res/menu/active_markers_menu.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0b91142364..43f7b3f5d7 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Two + One A line connecting your location to locations of the active markers will be shown on the map. One or two arrows indicating the direction to the active markers will be shown on the map. Choose how you\'d like to view the distance to the active markers. diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 890dc435c1..b79ae13a91 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1317,6 +1317,8 @@ public class OsmandSettings { public final OsmandPreference MARKERS_DISTANCE_INDICATION_ENABLED = new BooleanPreference("markers_distance_indication_enabled", true).makeProfile(); + public final OsmandPreference DISPLAYED_MARKERS_WIDGETS_COUNT = new IntPreference("displayed_markers_widgets_count", 1).makeProfile(); + public final CommonPreference MAP_MARKERS_MODE = new EnumIntPreference<>("map_markers_mode", MapMarkersMode.TOOLBAR, MapMarkersMode.values()); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java index 9be4936bb4..1254697da1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/DirectionIndicationDialogFragment.java @@ -8,12 +8,17 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v4.widget.CompoundButtonCompat; import android.support.v7.widget.Toolbar; +import android.text.SpannableString; +import android.text.style.ForegroundColorSpan; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; +import android.widget.TextView; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MapMarkersMode; @@ -21,6 +26,8 @@ import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndDialogFragment; +import net.osmand.plus.widgets.IconPopupMenu; +import net.osmand.plus.widgets.IconPopupMenu.OnMenuItemClickListener; public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment { @@ -49,6 +56,34 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment } }); + final TextView menuTv = (TextView) mainView.findViewById(R.id.active_markers_text_view); + menuTv.setText(settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1 ? R.string.shared_string_one : R.string.shared_string_two); + menuTv.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null); + menuTv.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + IconPopupMenu popupMenu = new IconPopupMenu(getActivity(), menuTv); + Menu menu = popupMenu.getMenu(); + popupMenu.getMenuInflater().inflate(R.menu.active_markers_menu, menu); + setupMenuItems(menu); + popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_one: + updateDisplayedMarkersCount(1); + return true; + case R.id.action_two: + updateDisplayedMarkersCount(2); + return true; + } + return false; + } + }); + popupMenu.show(); + } + }); + final CompoundButton distanceIndicationToggle = (CompoundButton) mainView.findViewById(R.id.distance_indication_switch); distanceIndicationToggle.setChecked(settings.MARKERS_DISTANCE_INDICATION_ENABLED.get()); mainView.findViewById(R.id.distance_indication_row).setOnClickListener(new View.OnClickListener() { @@ -111,10 +146,33 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment return null; } + private void setupMenuItems(Menu menu) { + OsmandSettings settings = getSettings(); + int count = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get(); + int stringId = count == 1 ? R.string.shared_string_one : R.string.shared_string_two; + int itemId = count == 1 ? R.id.action_one : R.id.action_two; + boolean night = !settings.isLightContent(); + SpannableString title = new SpannableString(getString(stringId)); + title.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getActivity(), + night ? R.color.osmand_orange : R.color.dashboard_blue)), 0, title.length(), 0); + menu.findItem(itemId).setTitle(title); + } + + private void updateDisplayedMarkersCount(int count) { + ((TextView) mainView.findViewById(R.id.active_markers_text_view)) + .setText(count == 1 ? R.string.shared_string_one : R.string.shared_string_two); + getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.set(count); + notifyListener(); + } + private void updateChecked(OsmandPreference setting, CompoundButton button) { boolean newState = !setting.get(); setting.set(newState); button.setChecked(newState); + refreshMap(); + } + + private void refreshMap() { if (getMapActivity() != null) { getMapActivity().refreshMap(); } @@ -154,9 +212,9 @@ public class DirectionIndicationDialogFragment extends BaseOsmAndDialogFragment private void updateMarkerModeRow(int rowId, int radioButtonId, boolean checked, boolean active) { boolean night = !getSettings().isLightContent(); RadioButton rb = (RadioButton) mainView.findViewById(radioButtonId); - rb.setChecked(checked); int colorId = active ? night ? R.color.osmand_orange : R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.icon_color; + rb.setChecked(checked); CompoundButtonCompat.setButtonTintList(rb, ColorStateList.valueOf(ContextCompat.getColor(getContext(), colorId))); mainView.findViewById(rowId).setEnabled(active); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 96b6b5a886..9f69f57b63 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -222,6 +222,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); List activeMapMarkers = markersHelper.getMapMarkers(); + int displayedWidgets = map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get(); if (route != null && route.points.size() > 0) { planRouteAttrs.updatePaints(view, nightMode, tileBox); @@ -251,7 +252,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); } int[] colors = MapMarker.getColors(map); - for (int i = 0; i < activeMapMarkers.size() && i < 2; i++) { + for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) { MapMarker marker = activeMapMarkers.get(i); int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude()); int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude()); @@ -300,6 +301,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : (myLoc == null ? tileBox.getCenterLatLon() : new LatLon(myLoc.getLatitude(), myLoc.getLongitude())), tileBox.getZoom()); OsmandSettings settings = map.getMyApplication().getSettings(); + int displayedWidgets = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get(); if (tileBox.getZoom() < 3 || !settings.USE_MAP_MARKERS.get()) { return; @@ -340,7 +342,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi canvas.restore(); } i++; - if (i > 1) { + if (i > displayedWidgets - 1) { break; } } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 248bb9a54a..18a12bb0f8 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -219,7 +219,7 @@ public class MapMarkersWidgetsFactory { MapMarker marker = markers.get(0); updateUI(loc, heading, marker, arrowImg, distText, okButton, addressText, true, customLocation != null); - if (markers.size() > 1) { + if (markers.size() > 1 && map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 2) { marker = markers.get(1); if (loc != null && customLocation == null) { for (int i = 1; i < markers.size(); i++) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 5db6e73283..4ad6fbeab8 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -346,9 +346,13 @@ public class MapWidgetRegistry { public void updateMapMarkersMode(MapActivity mapActivity) { for (MapWidgetRegInfo info : rightWidgetSet) { - if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) { + if ("map_marker_1st".equals(info.key)) { setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets() && settings.MARKERS_DISTANCE_INDICATION_ENABLED.get(), false); + } else if ("map_marker_2nd".equals(info.key)) { + setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets() + && settings.MARKERS_DISTANCE_INDICATION_ENABLED.get() + && settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 2, false); } } MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();