Add the ability to select the number of widgets to display
This commit is contained in:
parent
946d6b493f
commit
2d1db11a49
7 changed files with 83 additions and 5 deletions
10
OsmAnd/res/menu/active_markers_menu.xml
Normal file
10
OsmAnd/res/menu/active_markers_menu.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/action_one"
|
||||
android:title="@string/shared_string_one"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_two"
|
||||
android:title="@string/shared_string_two"/>
|
||||
</menu>
|
|
@ -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
|
||||
-->
|
||||
<string name="shared_string_two">Two</string>
|
||||
<string name="shared_string_one">One</string>
|
||||
<string name="show_guide_line_descr">A line connecting your location to locations of the active markers will be shown on the map.</string>
|
||||
<string name="show_arrows_descr">One or two arrows indicating the direction to the active markers will be shown on the map.</string>
|
||||
<string name="distance_indication_descr">Choose how you\'d like to view the distance to the active markers.</string>
|
||||
|
|
|
@ -1317,6 +1317,8 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<Boolean> MARKERS_DISTANCE_INDICATION_ENABLED = new BooleanPreference("markers_distance_indication_enabled", true).makeProfile();
|
||||
|
||||
public final OsmandPreference<Integer> DISPLAYED_MARKERS_WIDGETS_COUNT = new IntPreference("displayed_markers_widgets_count", 1).makeProfile();
|
||||
|
||||
public final CommonPreference<MapMarkersMode> MAP_MARKERS_MODE =
|
||||
new EnumIntPreference<>("map_markers_mode", MapMarkersMode.TOOLBAR, MapMarkersMode.values());
|
||||
|
||||
|
|
|
@ -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<Boolean> 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);
|
||||
}
|
||||
|
|
|
@ -222,6 +222,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
Location myLoc = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
|
||||
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
|
||||
List<MapMarker> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue