Added right widgets for Map markers. Added Map markers settings to configure screen
This commit is contained in:
parent
cbcccdc9da
commit
d460940314
7 changed files with 149 additions and 22 deletions
|
@ -9,12 +9,16 @@
|
|||
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="add_points_to_map_markers_q">Do you want to add all points to Map Markers?</string>
|
||||
<string name="shared_string_add_to_map_markers">Add to Map Markers</string>
|
||||
<string name="select_map_markers">Select Map Markers</string>
|
||||
<string name="show_map_markers_topbar">Show Map markers topbar</string>
|
||||
<string name="map_marker_1st">First Map marker</string>
|
||||
<string name="map_marker_2nd">Second Map marker</string>
|
||||
<string name="shared_string_toolbar">Toolbar</string>
|
||||
<string name="shared_string_widgets">Widgets</string>
|
||||
<string name="add_points_to_map_markers_q">Do you want to add all points to Map markers?</string>
|
||||
<string name="shared_string_add_to_map_markers">Add to Map markers</string>
|
||||
<string name="select_map_markers">Select Map markers</string>
|
||||
<string name="shared_string_reverse_order">Reverse order</string>
|
||||
<string name="show_map_markers">Map Markers</string>
|
||||
<string name="show_map_markers_description">Activate Map Markers feature</string>
|
||||
<string name="show_map_markers_description">Activate Map markers feature</string>
|
||||
<string name="clear_active_markers_q">Do you want to delete all active markers?</string>
|
||||
<string name="clear_markers_history_q">Do you want to clear markers history?</string>
|
||||
<string name="active_markers">Active markers</string>
|
||||
|
|
|
@ -1102,6 +1102,7 @@ public class OsmandSettings {
|
|||
public final OsmandPreference<Boolean> SHOULD_SHOW_FREE_VERSION_BANNER = new BooleanPreference("should_show_free_version_banner", false).makeGlobal().cache();
|
||||
|
||||
public final OsmandPreference<Boolean> USE_MAP_MARKERS = new BooleanPreference("use_map_markers", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> SHOW_MAP_MARKERS_TOOLBAR = new BooleanPreference("show_map_markers_toolbar", true).makeGlobal().cache();
|
||||
|
||||
public ITileSource getMapTileSource(boolean warnWhenSelected) {
|
||||
String tileName = MAP_TILE_SOURCES.get();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
R.string.show_free_version_banner_description));
|
||||
|
||||
cat.addPreference(createCheckBoxPreference(settings.USE_MAP_MARKERS,
|
||||
R.string.show_map_markers,
|
||||
R.string.map_markers,
|
||||
R.string.show_map_markers_description));
|
||||
|
||||
Preference pref = new Preference(this);
|
||||
|
|
|
@ -11,6 +11,7 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
|
||||
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.NextTurnInfoWidget;
|
||||
|
@ -76,12 +77,12 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
recreateControls();
|
||||
}
|
||||
|
||||
public void registerSideWidget(TextInfoWidget widget, int drawableMenu,
|
||||
public void registerSideWidget(TextInfoWidget widget, int drawableMenu,
|
||||
int messageId, String key, boolean left, int priorityOrder) {
|
||||
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableMenu, messageId, key, left, priorityOrder);
|
||||
updateReg(calculateTextState(), reg);
|
||||
}
|
||||
|
||||
|
||||
public <T extends TextInfoWidget> T getSideWidget(Class<T> cl) {
|
||||
return mapInfoControls.getSideWidget(cl);
|
||||
}
|
||||
|
@ -93,6 +94,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
public void registerAllControls(){
|
||||
RouteInfoWidgetsFactory ric = new RouteInfoWidgetsFactory();
|
||||
MapInfoWidgetsFactory mic = new MapInfoWidgetsFactory();
|
||||
MapMarkersWidgetsFactory mwf = map.getMapLayers().getMapMarkersLayer().getWidgetsFactory();
|
||||
OsmandApplication app = view.getApplication();
|
||||
lanesControl = ric.createLanesControl(map, view);
|
||||
|
||||
|
@ -107,7 +109,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
|
||||
// register left stack
|
||||
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
|
||||
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
|
||||
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, "next_turn", true, 5);
|
||||
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
|
||||
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
|
||||
10);
|
||||
|
@ -120,6 +122,14 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, "distance", false, 5);
|
||||
TextInfoWidget time = ric.createTimeControl(map);
|
||||
registerSideWidget(time, R.drawable.ic_action_time, R.string.map_widget_time, "time", false, 10);
|
||||
|
||||
if (settings.USE_MAP_MARKERS.get()) {
|
||||
TextInfoWidget marker = mwf.createMapMarkerControl(map);
|
||||
registerSideWidget(marker, R.drawable.ic_action_flag_dark, R.string.map_marker_1st, "map_marker_1st", false, 11);
|
||||
TextInfoWidget marker2nd = mwf.createMapMarkerControl2nd(map);
|
||||
registerSideWidget(marker2nd, R.drawable.ic_action_flag_dark, R.string.map_marker_2nd, "map_marker_2nd", false, 12);
|
||||
}
|
||||
|
||||
TextInfoWidget speed = ric.createSpeedControl(map);
|
||||
registerSideWidget(speed, R.drawable.ic_action_speed, R.string.map_widget_speed, "speed", false, 15);
|
||||
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map);
|
||||
|
|
|
@ -21,7 +21,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
|
|||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.views.mapwidgets.MapMarkersWidget;
|
||||
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -34,7 +34,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
private final MapActivity map;
|
||||
private OsmandMapTileView view;
|
||||
|
||||
private MapMarkersWidget widget;
|
||||
private MapMarkersWidgetsFactory widgetsFactory;
|
||||
|
||||
private Paint bitmapPaint;
|
||||
private Bitmap markerBitmapBlue;
|
||||
|
@ -66,6 +66,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
this.map = map;
|
||||
}
|
||||
|
||||
public MapMarkersWidgetsFactory getWidgetsFactory() {
|
||||
return widgetsFactory;
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
bitmapPaint = new Paint();
|
||||
bitmapPaint.setDither(true);
|
||||
|
@ -88,7 +92,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
bitmapPaintDestTeal = createPaintDest(R.color.marker_teal);
|
||||
bitmapPaintDestPurple = createPaintDest(R.color.marker_purple);
|
||||
|
||||
widget = new MapMarkersWidget(map);
|
||||
widgetsFactory = new MapMarkersWidgetsFactory(map);
|
||||
}
|
||||
|
||||
private Paint createPaintDest(int colorId) {
|
||||
|
@ -184,7 +188,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
|
||||
|
||||
widget.updateInfo(useFingerLocation ? fingerLocation : null, tb.getZoom());
|
||||
widgetsFactory.updateInfo(useFingerLocation ? fingerLocation : null, tb.getZoom());
|
||||
|
||||
if (tb.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
|
||||
return;
|
||||
|
@ -237,8 +241,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
|
||||
public boolean containsLatLon(RotatedTileBox tb, double lat, double lon) {
|
||||
double widgetHeight = 0;
|
||||
if (widget.isTopBarVisible()) {
|
||||
widgetHeight = widget.getTopBarHeight();
|
||||
if (widgetsFactory.isTopBarVisible()) {
|
||||
widgetHeight = widgetsFactory.getTopBarHeight();
|
||||
}
|
||||
double tx = tb.getPixXFromLatLon(lat, lon);
|
||||
double ty = tb.getPixYFromLatLon(lat, lon);
|
||||
|
|
|
@ -19,11 +19,12 @@ import net.osmand.plus.dashboard.DashboardOnMap;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.MapMarkerDialogHelper;
|
||||
import net.osmand.plus.views.DirectionDrawable;
|
||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MapMarkersWidget {
|
||||
public class MapMarkersWidgetsFactory {
|
||||
|
||||
public static final int MIN_DIST_OK_VISIBLE = 40;
|
||||
|
||||
|
@ -48,7 +49,12 @@ public class MapMarkersWidget {
|
|||
private ImageButton moreButton;
|
||||
private ImageButton moreButton2nd;
|
||||
|
||||
public MapMarkersWidget(final MapActivity map) {
|
||||
private int markerColorIndex = -1;
|
||||
private String markerDistText;
|
||||
private int markerColorIndex2nd = -1;
|
||||
private String markerDistText2nd;
|
||||
|
||||
public MapMarkersWidgetsFactory(final MapActivity map) {
|
||||
this.map = map;
|
||||
helper = map.getMyApplication().getMapMarkersHelper();
|
||||
screenOrientation = DashLocationFragment.getScreenOrientation(map);
|
||||
|
@ -168,7 +174,9 @@ public class MapMarkersWidget {
|
|||
}
|
||||
|
||||
List<MapMarker> markers = helper.getActiveMapMarkers();
|
||||
if (zoom < 3 || markers.size() == 0 || map.getMyApplication().getRoutingHelper().isFollowingMode()
|
||||
if (zoom < 3 || markers.size() == 0
|
||||
|| !map.getMyApplication().getSettings().SHOW_MAP_MARKERS_TOOLBAR.get()
|
||||
|| map.getMyApplication().getRoutingHelper().isFollowingMode()
|
||||
|| map.getMyApplication().getRoutingHelper().isRoutePlanningMode()
|
||||
|| map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible()) {
|
||||
updateVisibility(false);
|
||||
|
@ -225,11 +233,13 @@ public class MapMarkersWidget {
|
|||
arrowImg.invalidate();
|
||||
|
||||
int dist = (int) mes[0];
|
||||
String txt;
|
||||
if (loc != null) {
|
||||
distText.setText(OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication()));
|
||||
txt = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
|
||||
} else {
|
||||
distText.setText("— " + map.getString(R.string.m));
|
||||
txt = "— " + map.getString(R.string.m);
|
||||
}
|
||||
distText.setText(txt);
|
||||
updateVisibility(okButton, loc != null && dist < MIN_DIST_OK_VISIBLE);
|
||||
|
||||
String descr;
|
||||
|
@ -244,10 +254,106 @@ public class MapMarkersWidget {
|
|||
}
|
||||
|
||||
addressText.setText(descr);
|
||||
|
||||
if (firstLine) {
|
||||
markerColorIndex = marker.colorIndex;
|
||||
markerDistText = txt;
|
||||
} else {
|
||||
markerColorIndex2nd = marker.colorIndex;
|
||||
markerDistText2nd = txt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public TextInfoWidget createMapMarkerControl(final MapActivity map) {
|
||||
final TextInfoWidget mapMarkerControl = new TextInfoWidget(map) {
|
||||
private int cachedMarkerColorIndex = -1;
|
||||
private String cachedMarkerDistText;
|
||||
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
if (markerColorIndex != -1 && markerDistText != null) {
|
||||
boolean res = false;
|
||||
if (markerColorIndex != cachedMarkerColorIndex) {
|
||||
setImageDrawable(map.getMyApplication().getIconsCache()
|
||||
.getIcon(R.drawable.widget_intermediate_day,
|
||||
MapMarkerDialogHelper.getMapMarkerColorId(markerColorIndex)));
|
||||
res = true;
|
||||
}
|
||||
if (!markerDistText.equals(cachedMarkerDistText)) {
|
||||
int ls = markerDistText.lastIndexOf(' ');
|
||||
if (ls == -1) {
|
||||
setText(markerDistText, null);
|
||||
} else {
|
||||
setText(markerDistText.substring(0, ls), markerDistText.substring(ls + 1));
|
||||
}
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
||||
} else if (cachedMarkerDistText != null) {
|
||||
cachedMarkerDistText = null;
|
||||
setText(null, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
mapMarkerControl.setText(null, null);
|
||||
mapMarkerControl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showMarkerOnMap(0);
|
||||
}
|
||||
});
|
||||
return mapMarkerControl;
|
||||
}
|
||||
|
||||
public TextInfoWidget createMapMarkerControl2nd(final MapActivity map) {
|
||||
final TextInfoWidget mapMarkerControl = new TextInfoWidget(map) {
|
||||
private int cachedMarkerColorIndex = -1;
|
||||
private String cachedMarkerDistText;
|
||||
|
||||
@Override
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
if (markerColorIndex2nd != -1 && markerDistText2nd != null) {
|
||||
boolean res = false;
|
||||
if (markerColorIndex2nd != cachedMarkerColorIndex) {
|
||||
setImageDrawable(map.getMyApplication().getIconsCache()
|
||||
.getIcon(R.drawable.widget_intermediate_day,
|
||||
MapMarkerDialogHelper.getMapMarkerColorId(markerColorIndex2nd)));
|
||||
res = true;
|
||||
}
|
||||
if (!markerDistText2nd.equals(cachedMarkerDistText)) {
|
||||
int ls = markerDistText2nd.lastIndexOf(' ');
|
||||
if (ls == -1) {
|
||||
setText(markerDistText2nd, null);
|
||||
} else {
|
||||
setText(markerDistText2nd.substring(0, ls), markerDistText2nd.substring(ls + 1));
|
||||
}
|
||||
res = true;
|
||||
}
|
||||
return res;
|
||||
|
||||
} else if (cachedMarkerDistText != null) {
|
||||
cachedMarkerDistText = null;
|
||||
setText(null, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
mapMarkerControl.setText(null, null);
|
||||
mapMarkerControl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showMarkerOnMap(1);
|
||||
}
|
||||
});
|
||||
return mapMarkerControl;
|
||||
}
|
||||
|
||||
public boolean isLandscapeLayout() {
|
||||
return !portraitMode && !largeDevice;
|
||||
}
|
||||
|
||||
}
|
|
@ -255,7 +255,9 @@ public class MapWidgetRegistry {
|
|||
if(mode != ApplicationMode.DEFAULT) {
|
||||
addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
|
||||
}
|
||||
|
||||
if (settings.USE_MAP_MARKERS.get()) {
|
||||
addControlId(map, cm, R.string.show_map_markers_topbar, settings.SHOW_MAP_MARKERS_TOOLBAR);
|
||||
}
|
||||
}
|
||||
|
||||
private void addControlId(final MapActivity map, ContextMenuAdapter cm, int stringId, OsmandPreference<Boolean> pref) {
|
||||
|
|
Loading…
Reference in a new issue