Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-02-14 10:15:16 +01:00
commit 54b41afe2f
29 changed files with 2619 additions and 137 deletions

View file

@ -3,8 +3,192 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
android:orientation="vertical">
<FrameLayout
android:id="@+id/map_markers_top_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="@dimen/map_address_height"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/markers_top_bar_background"
android:minHeight="@dimen/map_address_height">
<LinearLayout
android:id="@+id/map_marker_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow"
android:layout_width="60dp"
android:layout_height="30dp"
android:src="@drawable/map_arrow_to_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/map_marker_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="500 m"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
<TextView
android:id="@+id/map_marker_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Dmitrievskaya st., 45"
android:textColor="@color/marker_top_2nd_line_color"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</LinearLayout>
<ImageButton
android:id="@+id/marker_btn_ok"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
<ImageButton
android:id="@+id/marker_btn_more"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar_2nd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/markers_top_bar_2nd_background"
android:minHeight="@dimen/map_address_height"
android:visibility="visible">
<LinearLayout
android:id="@+id/map_marker_row_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow_2nd"
android:layout_width="60dp"
android:layout_height="30dp"
android:src="@drawable/map_arrow_to_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/map_marker_dist_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="500 m"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
<TextView
android:id="@+id/map_marker_address_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:maxLines="1"
android:text="Dmitrievskaya st., 45"
android:textColor="@color/marker_top_2nd_line_color"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</LinearLayout>
<ImageButton
android:id="@+id/marker_btn_ok_2dn"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
<ImageButton
android:id="@+id/marker_btn_more_2nd"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<View
android:id="@+id/map_route_land_left_margin"
@ -282,4 +466,5 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -139,10 +139,180 @@
android:id="@+id/waypoint_close"
android:layout_width="@dimen/map_address_height"
android:layout_height="@dimen/map_address_height"
android:background="@drawable/btn_circle_transparent"
android:background="@drawable/bottom_shadow"
android:src="@drawable/ic_action_test_light"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:minHeight="@dimen/map_address_height"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height"
android:background="@color/markers_top_bar_background">
<LinearLayout
android:id="@+id/map_marker_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow"
android:layout_width="60dp"
android:layout_height="40dp"
android:src="@drawable/map_arrow_to_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/map_marker_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="26sp"
android:textColor="@color/color_white"
android:text="500 m"/>
<TextView
android:id="@+id/map_marker_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textColor="@color/marker_top_2nd_line_color"
android:textStyle="bold"
android:maxLines="1"
android:ellipsize="end"
android:textSize="@dimen/default_list_text_size"
android:text="Dmitrievskaya st., 45"/>
</LinearLayout>
<ImageButton
android:id="@+id/marker_btn_ok"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
<ImageButton
android:id="@+id/marker_btn_more"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/map_address_height"
android:background="@color/markers_top_bar_2nd_background"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
<LinearLayout
android:id="@+id/map_marker_row_2nd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/map_marker_arrow_2nd"
android:layout_width="60dp"
android:layout_height="30dp"
android:src="@drawable/map_arrow_to_destination"/>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/map_marker_dist_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="500 m"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size_large"
android:textStyle="bold"/>
<TextView
android:id="@+id/map_marker_address_2nd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/map_marker_dist_2nd"
android:layout_toRightOf="@+id/map_marker_dist_2nd"
android:ellipsize="end"
android:maxLines="1"
android:text=" • Dmitr"
android:textColor="@color/marker_top_2nd_line_color"
android:textSize="@dimen/default_list_text_size"
android:textStyle="bold"/>
</RelativeLayout>
<ImageButton
android:id="@+id/marker_btn_ok_2dn"
android:layout_width="50dp"
android:layout_height="48dp"
android:background="?attr/dashboard_button"
android:src="@drawable/ic_action_done"/>
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/map_markers_top_bar_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"/>
</LinearLayout>
</FrameLayout>
<!-- Widgets -->
<FrameLayout

View file

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/view_transparent_selection"
android:id="@+id/package_delivered_layout"
android:minHeight="50dp"
android:descendantFocusability="blocksDescendants">
<ImageView
android:id="@+id/waypoint_icon"
android:src="@drawable/ic_action_fav_dark"
android:layout_height="25dp"
android:layout_width="56dp"
android:layout_gravity="center_vertical" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/waypoint_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:textSize="@dimen/default_list_text_size" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:src="@drawable/ic_destination_arrow_white"
android:visibility="gone"/>
<TextView
android:id="@+id/waypoint_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textColor="@color/color_myloc_distance"
android:maxLines="1"
android:textSize="@dimen/default_sub_text_size"/>
<TextView
android:id="@+id/waypoint_deviation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textColor="@color/secondary_text_dark"
android:layout_marginLeft="6dp"
android:drawablePadding="2dp"
android:maxLines="1"
android:textSize="@dimen/default_sub_text_size"/>
<TextView
android:id="@+id/waypoint_desc_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:ellipsize="end"
android:layout_gravity="bottom"
android:layout_weight="1"
android:textColor="@color/secondary_text_dark"
android:textSize="@dimen/default_sub_text_size" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="@+id/all_points"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_more"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
android:visibility="gone"
android:focusable="false"
android:scaleType="center"
style="@style/Widget.AppCompat.ActionButton"
android:src="@drawable/map_overflow_menu_white" />
<ImageButton
android:id="@+id/info_close"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/shared_string_close"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
style="@style/Widget.AppCompat.ActionButton"
android:focusable="false"
android:scaleType="center"
android:src="@drawable/ic_action_remove_dark" />
<ImageView
android:id="@+id/info_move"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="2dp"
android:focusable="false"
android:clickable="false"
android:scaleType="center"
android:src="@drawable/ic_flat_list_dark"
android:visibility="gone"/>
</LinearLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<net.osmand.plus.views.controls.DynamicListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:drawSelectorOnTop="true"
tools:listitem="@layout/waypoint_reached"/>
</LinearLayout>

View file

@ -32,4 +32,15 @@
<include layout="@layout/check_item_rel"/>
<Button
android:id="@+id/header_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_marginRight="-16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/shared_string_clear"
android:visibility="gone"/>
</LinearLayout>

View file

@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="markers_top_bar_background">#145256</color>
<color name="markers_top_bar_2nd_background">#0e3b3e</color>
<color name="marker_top_2nd_line_color">#588689</color>
<color name="marker_blue">#2196f3</color>
<color name="marker_green">#73b825</color>
<color name="marker_orange">#ff9800</color>
<color name="marker_red">#e53935</color>
<color name="marker_yellow">#FDD835</color>
<color name="marker_teal">#26a69a</color>
<color name="marker_purple">#ab47bc</color>
<color name="popup_bg_color">#EE666666</color>
<color name="popup_separator_color">#BBBBBB</color>
<color name="popup_text_color">#FFFFFF</color>

View file

@ -1,4 +1,4 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version='1.0' encoding='utf-8'?>
<resources>
<!--
Disclaimer:
@ -9,6 +9,13 @@
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="show_map_markers">Map Markers</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>
<string name="map_markers">Map markers</string>
<string name="map_marker">Map marker</string>
<string name="rendering_attr_showMtbRoutes_name">Show MTB routes</string>
<string name="show_polygons">Show polygons</string>
<!-- string name="underlay_transparency">Underlay transparency</string -->

View file

@ -38,6 +38,7 @@ public class PointDescription {
public static final String POINT_TYPE_MY_LOCATION = "my_location";
public static final String POINT_TYPE_ALARM = "alarm";
public static final String POINT_TYPE_TARGET = "destination";
public static final String POINT_TYPE_MAP_MARKER = "map_marker";
public static final String POINT_TYPE_OSM_BUG = "bug";
public static final String POINT_TYPE_WORLD_REGION = "world_region";
public static final String POINT_TYPE_GPX_ITEM = "gpx_item";
@ -191,6 +192,10 @@ public class PointDescription {
return POINT_TYPE_TARGET.equals(type);
}
public boolean isMapMarker() {
return POINT_TYPE_MAP_MARKER.equals(type);
}
public boolean isParking() {
return POINT_TYPE_PARKING_MARKER.equals(type);
}

View file

@ -342,6 +342,7 @@ public class AppInitializer implements IProgress {
app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class);
app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class);
app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class);
app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
}

View file

@ -0,0 +1,309 @@
package net.osmand.plus;
import android.content.Context;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
public class MapMarkersHelper {
public static final int MAP_MARKERS_COLORS_COUNT = 7;
private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private OsmandSettings settings;
private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private OsmandApplication ctx;
public interface MapMarkerChangedListener {
void onMapMarkerChanged(MapMarker mapMarker);
void onMapMarkersChanged();
}
public static class MapMarker implements LocationPoint {
public LatLon point;
private PointDescription pointDescription;
public int colorIndex;
public int index;
public boolean history;
public int dist;
public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) {
this.point = point;
this.pointDescription = name;
this.colorIndex = colorIndex;
this.index = index;
}
public PointDescription getPointDescription(Context ctx) {
return new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, ctx.getString(R.string.map_marker, ""),
getOnlyName());
}
public PointDescription getOriginalPointDescription() {
return pointDescription;
}
public String getOnlyName() {
return pointDescription == null ? "" : pointDescription.getName();
}
public boolean isSearchingAddress(Context ctx) {
return pointDescription != null && pointDescription.isSearchingAddress(ctx);
}
public double getLatitude() {
return point.getLatitude();
}
public double getLongitude() {
return point.getLongitude();
}
@Override
public int getColor() {
return 0;
}
@Override
public boolean isVisible() {
return false;
}
}
public MapMarkersHelper(OsmandApplication ctx) {
this.ctx = ctx;
this.settings = ctx.getSettings();
readFromSettings();
}
private void readFromSettings() {
mapMarkers.clear();
mapMarkersHistory.clear();
List<LatLon> ips = settings.getMapMarkersPoints();
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
mapMarkers.add(mapMarker);
lookupAddress(mapMarker, false);
}
ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
mapMarker.history = true;
mapMarkersHistory.add(mapMarker);
lookupAddress(mapMarker, true);
}
}
private void lookupAddress(final MapMarker mapMarker, final boolean history) {
if (mapMarker != null && mapMarker.pointDescription.isSearchingAddress(ctx)) {
cancelPointAddressRequests(mapMarker.point);
GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(mapMarker.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
if (Algorithms.isEmpty(address)) {
mapMarker.pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx));
} else {
mapMarker.pointDescription.setName(address);
}
if (history) {
settings.updateMapMarkerHistory(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex);
} else {
settings.updateMapMarker(mapMarker.point.getLatitude(), mapMarker.point.getLongitude(),
mapMarker.pointDescription, mapMarker.colorIndex);
}
updateMarker(mapMarker);
}
}, null);
ctx.getGeocodingLookupService().lookupAddress(lookupRequest);
}
}
public void removeMapMarker(int index) {
settings.deleteMapMarker(index);
MapMarker mapMarker = mapMarkers.remove(index);
cancelPointAddressRequests(mapMarker.point);
int ind = 0;
for (MapMarker marker : mapMarkers) {
marker.index = ind++;
}
refresh();
}
public List<MapMarker> getActiveMapMarkers() {
return mapMarkers;
}
public List<MapMarker> getMapMarkersHistory() {
return mapMarkersHistory;
}
public List<LatLon> getActiveMarkersLatLon() {
List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) {
list.add(m.point);
}
return list;
}
public List<LatLon> getMarkersHistoryLatLon() {
List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkersHistory) {
list.add(m.point);
}
return list;
}
public void removeActiveMarkers() {
cancelAddressRequests();
settings.clearActiveMapMarkers();
mapMarkers.clear();
readFromSettings();
refresh();
}
public void removeMarkersHistory() {
cancelAddressRequests();
settings.clearMapMarkersHistory();
mapMarkersHistory.clear();
readFromSettings();
refresh();
}
public void addMapMarker(LatLon point, PointDescription historyName) {
if (point != null) {
final PointDescription pointDescription;
if (historyName == null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
} else {
pointDescription = historyName;
}
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
}
int colorIndex;
if (mapMarkers.size() > 0) {
colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
settings.insertMapMarker(point.getLatitude(), point.getLongitude(),
pointDescription, colorIndex, mapMarkers.size());
readFromSettings();
refresh();
}
}
public void removeMapMarker(MapMarker marker) {
if (marker != null) {
settings.deleteMapMarker(marker.index);
readFromSettings();
refresh();
}
}
public void addMapMarkerHistory(MapMarker marker) {
if (marker != null) {
settings.insertMapMarkerHistory(marker.getLatitude(), marker.getLongitude(), marker.pointDescription, marker.colorIndex, 0);
readFromSettings();
refresh();
}
}
public void removeMapMarkerHistory(MapMarker marker) {
if (marker != null) {
settings.deleteMapMarkerHistory(marker.index);
readFromSettings();
refresh();
}
}
public void saveMapMarkers(List<MapMarker> markers, List<MapMarker> markersHistory) {
if (markers != null) {
List<LatLon> ls = new ArrayList<>(markers.size());
List<String> names = new ArrayList<>(markers.size());
List<Integer> colors = new ArrayList<>(markers.size());
for (MapMarker marker : markers) {
ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex);
}
settings.saveMapMarkers(ls, names, colors);
}
if (markersHistory != null) {
List<LatLon> ls = new ArrayList<>(markersHistory.size());
List<String> names = new ArrayList<>(markersHistory.size());
List<Integer> colors = new ArrayList<>(markersHistory.size());
for (MapMarker marker : markersHistory) {
ls.add(marker.point);
names.add(PointDescription.serializeToString(marker.pointDescription));
colors.add(marker.colorIndex);
}
settings.saveMapMarkersHistory(ls, names, colors);
}
if (markers != null || markersHistory != null) {
readFromSettings();
refresh();
}
}
public void addListener(MapMarkerChangedListener l) {
if (!listeners.contains(l)) {
listeners.add(l);
}
}
public void removeListener(MapMarkerChangedListener l) {
listeners.remove(l);
}
private void updateMarker(MapMarker marker) {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkerChanged(marker);
}
}
private void updateMarkers() {
for (MapMarkerChangedListener l : listeners) {
l.onMapMarkersChanged();
}
}
public void refresh() {
updateMarkers();
}
private void cancelAddressRequests() {
List<LatLon> list = getActiveMarkersLatLon();
for (LatLon latLon : list) {
cancelPointAddressRequests(latLon);
}
list = getMarkersHistoryLatLon();
for (LatLon latLon : list) {
cancelPointAddressRequests(latLon);
}
}
private void cancelPointAddressRequests(LatLon latLon) {
if (latLon != null) {
ctx.getGeocodingLookupService().cancel(latLon);
}
}
}

View file

@ -1,9 +1,6 @@
package net.osmand.plus;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
@ -19,7 +16,11 @@ import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.views.OsmandMapTileView;
import android.app.Activity;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class OsmAndAppCustomization {
@ -67,7 +68,6 @@ public class OsmAndAppCustomization {
return FavoritesActivity.class;
}
public Class<? extends Activity> getDownloadIndexActivity() {
return DownloadActivity.class;
}

View file

@ -91,6 +91,7 @@ public class OsmandApplication extends MultiDexApplication {
NotificationHelper notificationHelper;
LiveMonitoringHelper liveMonitoringHelper;
TargetPointsHelper targetPointsHelper;
MapMarkersHelper mapMarkersHelper;
WaypointHelper waypointHelper;
DownloadIndexesThread downloadIndexesThread;
AvoidSpecificRoads avoidSpecificRoads;
@ -540,6 +541,10 @@ public class OsmandApplication extends MultiDexApplication {
return targetPointsHelper;
}
public MapMarkersHelper getMapMarkersHelper() {
return mapMarkersHelper;
}
public void showShortToastMessage(final int msgId, final Object... args) {
uiHandler.post(new Runnable() {
@Override

View file

@ -1101,6 +1101,8 @@ 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 ITileSource getMapTileSource(boolean warnWhenSelected) {
String tileName = MAP_TILE_SOURCES.get();
if (tileName != null) {
@ -1472,8 +1474,20 @@ public class OsmandSettings {
public final static String START_POINT_LAT = "start_point_lat"; //$NON-NLS-1$
public final static String START_POINT_LON = "start_point_lon"; //$NON-NLS-1$
public final static String START_POINT_DESCRIPTION = "start_point_description"; //$NON-NLS-1$
public final static String INTERMEDIATE_POINTS = "intermediate_points"; //$NON-NLS-1$
public final static String INTERMEDIATE_POINTS_DESCRIPTION = "intermediate_points_description"; //$NON-NLS-1$
private IntermediatePointsStorage intermediatePointsStorage = new IntermediatePointsStorage();
public final static String MAP_MARKERS_POINT = "map_markers_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
public final static int MAP_MARKERS_HISTORY_LIMIT = 30;
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
public LatLon getPointToNavigate() {
float lat = settingsAPI.getFloat(globalPreferences,POINT_NAVIGATE_LAT, 0);
@ -1518,95 +1532,346 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences).remove(INTERMEDIATE_POINTS).remove(INTERMEDIATE_POINTS_DESCRIPTION).commit();
}
public boolean clearActiveMapMarkers() {
return settingsAPI.edit(globalPreferences)
.remove(MAP_MARKERS_POINT)
.remove(MAP_MARKERS_DESCRIPTION)
.remove(MAP_MARKERS_COLOR).commit();
}
public boolean clearMapMarkersHistory() {
return settingsAPI.edit(globalPreferences)
.remove(MAP_MARKERS_HISTORY_POINT)
.remove(MAP_MARKERS_HISTORY_DESCRIPTION)
.remove(MAP_MARKERS_HISTORY_COLOR).commit();
}
public final CommonPreference<Boolean> USE_INTERMEDIATE_POINTS_NAVIGATION =
new BooleanPreference("use_intermediate_points_navigation", false).makeGlobal().cache();
private class IntermediatePointsStorage extends MapPointsStorage {
public IntermediatePointsStorage() {
pointsKey = INTERMEDIATE_POINTS;
descriptionsKey = INTERMEDIATE_POINTS_DESCRIPTION;
}
}
private class MapMarkersHistoryStorage extends MapMarkersStorage {
public MapMarkersHistoryStorage() {
pointsKey = MAP_MARKERS_HISTORY_POINT;
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
colorsKey = MAP_MARKERS_HISTORY_COLOR;
}
@Override
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs) {
if (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
ps.remove(ps.size() - 1);
ds.remove(ds.size() - 1);
cs.remove(cs.size() - 1);
}
return super.savePoints(ps, ds, cs);
}
}
private class MapMarkersStorage extends MapPointsStorage {
protected String colorsKey;
public MapMarkersStorage() {
pointsKey = MAP_MARKERS_POINT;
descriptionsKey = MAP_MARKERS_DESCRIPTION;
colorsKey = MAP_MARKERS_COLOR;
}
public List<Integer> getColors(int sz) {
List<Integer> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, colorsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String colorStr = tok.nextToken();
list.add(Integer.parseInt(colorStr));
}
}
return list;
}
public boolean insertPoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs);
}
public boolean updatePoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
int i = ps.indexOf(new LatLon(latitude, longitude));
ds.set(i, PointDescription.serializeToString(historyDescription));
cs.set(i, colorIndex);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs);
}
@Override
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
ps.remove(index);
ds.remove(index);
cs.remove(index);
return savePoints(ps, ds, cs);
}
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
StringBuilder cb = new StringBuilder();
for (int i = 0; i < cs.size(); i++) {
if (i > 0) {
cb.append(",");
}
cb.append(Integer.toString(cs.get(i)));
}
return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString())
.commit();
}
@Override
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
return false;
}
@Override
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
return false;
}
@Override
public boolean savePoints(List<LatLon> ps, List<String> ds) {
return false;
}
}
private abstract class MapPointsStorage {
protected String pointsKey;
protected String descriptionsKey;
public MapPointsStorage() {
}
public List<String> getPointDescriptions(int sz) {
List<String> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, descriptionsKey, "");
if (ip.trim().length() > 0) {
list.addAll(Arrays.asList(ip.split("--")));
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add("");
}
return list;
}
public List<LatLon> getPoints() {
List<LatLon> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, pointsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String lat = tok.nextToken();
if (!tok.hasMoreTokens()) {
break;
}
String lon = tok.nextToken();
list.add(new LatLon(Float.parseFloat(lat), Float.parseFloat(lon)));
}
}
return list;
}
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription));
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds);
}
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
int i = ps.indexOf(new LatLon(latitude, longitude));
ds.set(i, PointDescription.serializeToString(historyDescription));
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds);
}
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
ps.remove(index);
ds.remove(index);
return savePoints(ps, ds);
}
public boolean savePoints(List<LatLon> ps, List<String> ds) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.commit();
}
}
public List<String> getIntermediatePointDescriptions(int sz) {
List<String> list = new ArrayList<String>();
String ip = settingsAPI.getString(globalPreferences,INTERMEDIATE_POINTS_DESCRIPTION, "");
if (ip.trim().length() > 0) {
list.addAll(Arrays.asList(ip.split("--")));
}
while(list.size() > sz) {
list.remove(list.size() - 1);
}
while(list.size() < sz) {
list.add("");
}
return list;
return intermediatePointsStorage.getPointDescriptions(sz);
}
public List<LatLon> getIntermediatePoints() {
List<LatLon> list = new ArrayList<LatLon>();
String ip = settingsAPI.getString(globalPreferences,INTERMEDIATE_POINTS, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String lat = tok.nextToken();
if (!tok.hasMoreTokens()) {
break;
}
String lon = tok.nextToken();
list.add(new LatLon(Float.parseFloat(lat), Float.parseFloat(lon)));
}
}
return list;
return intermediatePointsStorage.getPoints();
}
public boolean insertIntermediatePoint(double latitude, double longitude, PointDescription historyDescription, int index) {
List<LatLon> ps = getIntermediatePoints();
List<String> ds = getIntermediatePointDescriptions(ps.size());
ps.add(index, new LatLon(latitude, longitude));
ds.add(index, PointDescription.serializeToString(historyDescription));
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return saveIntermediatePoints(ps,ds);
return intermediatePointsStorage.insertPoint(latitude, longitude, historyDescription, index);
}
public boolean updateIntermediatePoint(double latitude, double longitude, PointDescription historyDescription) {
List<LatLon> ps = getIntermediatePoints();
List<String> ds = getIntermediatePointDescriptions(ps.size());
int i = ps.indexOf(new LatLon(latitude, longitude));
ds.set(i, PointDescription.serializeToString(historyDescription));
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return saveIntermediatePoints(ps,ds);
return intermediatePointsStorage.updatePoint(latitude, longitude, historyDescription);
}
public boolean deleteIntermediatePoint( int index) {
List<LatLon> ps = getIntermediatePoints();
List<String> ds = getIntermediatePointDescriptions(ps.size());
ps.remove(index);
ds.remove(index);
return saveIntermediatePoints(ps,ds);
public boolean deleteIntermediatePoint(int index) {
return intermediatePointsStorage.deletePoint(index);
}
public boolean saveIntermediatePoints(List<LatLon> ps, List<String> ds) {
StringBuilder sb = new StringBuilder();
for(int i=0; i<ps.size(); i++) {
if(i > 0){
sb.append(",");
}
sb.append(((float)ps.get(i).getLatitude()+"")).append(",").append(((float)ps.get(i).getLongitude()+""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
return settingsAPI.edit(globalPreferences).putString(INTERMEDIATE_POINTS, sb.toString()).
putString(INTERMEDIATE_POINTS_DESCRIPTION, tb.toString()).
commit();
return intermediatePointsStorage.savePoints(ps, ds);
}
public List<String> getMapMarkersPointDescriptions(int sz) {
return mapMarkersStorage.getPointDescriptions(sz);
}
public List<Integer> getMapMarkersColors(int sz) {
return mapMarkersStorage.getColors(sz);
}
public List<LatLon> getMapMarkersPoints() {
return mapMarkersStorage.getPoints();
}
public boolean insertMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int index) {
return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, index);
}
public boolean updateMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) {
return mapMarkersStorage.updatePoint(latitude, longitude, historyDescription, colorIndex);
}
public boolean deleteMapMarker(int index) {
return mapMarkersStorage.deletePoint(index);
}
public boolean saveMapMarkers(List<LatLon> ps, List<String> ds, List<Integer> cs) {
return mapMarkersStorage.savePoints(ps, ds, cs);
}
public List<String> getMapMarkersHistoryPointDescriptions(int sz) {
return mapMarkersHistoryStorage.getPointDescriptions(sz);
}
public List<Integer> getMapMarkersHistoryColors(int sz) {
return mapMarkersHistoryStorage.getColors(sz);
}
public List<LatLon> getMapMarkersHistoryPoints() {
return mapMarkersHistoryStorage.getPoints();
}
public boolean insertMapMarkerHistory(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int index) {
return mapMarkersHistoryStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, index);
}
public boolean updateMapMarkerHistory(double latitude, double longitude,
PointDescription historyDescription, int colorIndex) {
return mapMarkersHistoryStorage.updatePoint(latitude, longitude, historyDescription, colorIndex);
}
public boolean deleteMapMarkerHistory(int index) {
return mapMarkersHistoryStorage.deletePoint(index);
}
public boolean saveMapMarkersHistory(List<LatLon> ps, List<String> ds, List<Integer> cs) {
return mapMarkersHistoryStorage.savePoints(ps, ds, cs);
}
public boolean clearPointToNavigate() {
return settingsAPI.edit(globalPreferences).remove(POINT_NAVIGATE_LAT).remove(POINT_NAVIGATE_LON).
remove(POINT_NAVIGATE_DESCRIPTION).commit();

View file

@ -33,6 +33,7 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -98,7 +99,6 @@ public class MapActivityActions implements DialogProvider {
openIntermediateEditPointsDialog();
}
*/
public void addAsTarget(double latitude, double longitude, PointDescription pd) {
TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size() + 1,
@ -106,6 +106,12 @@ public class MapActivityActions implements DialogProvider {
openIntermediatePointsDialog();
}
public void addMapMarker(double latitude, double longitude, PointDescription pd) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
}
public void editWaypoints() {
openIntermediatePointsDialog();
}
@ -565,15 +571,27 @@ public class MapActivityActions implements DialogProvider {
return true;
}
}).reg();
optionsMenuHelper.item(R.string.waypoints).iconColor(R.drawable.ic_action_intermediate)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
return false;
}
}).reg();
if (settings.USE_MAP_MARKERS.get()) {
optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_flag_dark)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.MAP_MARKERS);
return false;
}
}).reg();
} else {
optionsMenuHelper.item(R.string.waypoints).iconColor(R.drawable.ic_action_intermediate)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
return false;
}
}).reg();
}
optionsMenuHelper.item(R.string.get_directions).iconColor(R.drawable.ic_action_gdirections_dark)
.listen(new OnContextMenuClick() {
@Override
@ -739,17 +757,10 @@ public class MapActivityActions implements DialogProvider {
return optionsMenuHelper;
}
public void openIntermediatePointsDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
}
/*
public void openIntermediateEditPointsDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
}
*/
public void openRoutePreferencesDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.ROUTE_PREFERENCES);
}

View file

@ -38,6 +38,7 @@ import net.osmand.plus.views.GPXLayer;
import net.osmand.plus.views.ImpassableRoadsLayer;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.MapMarkersLayer;
import net.osmand.plus.views.MapTextLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
@ -72,6 +73,7 @@ public class MapActivityLayers {
private TransportInfoLayer transportInfoLayer;
private PointLocationLayer locationLayer;
private PointNavigationLayer navigationLayer;
private MapMarkersLayer mapMarkersLayer;
private ImpassableRoadsLayer impassableRoadsLayer;
private MapInfoLayer mapInfoLayer;
private MapTextLayer mapTextLayer;
@ -143,6 +145,11 @@ public class MapActivityLayers {
// 7. point navigation layer
navigationLayer = new PointNavigationLayer(activity);
mapView.addLayer(navigationLayer, 7);
// 7.3 map markers layer
if (app.getSettings().USE_MAP_MARKERS.get()) {
mapMarkersLayer = new MapMarkersLayer(activity);
mapView.addLayer(mapMarkersLayer, 7.3f);
}
// 7.5 Impassible roads
impassableRoadsLayer = new ImpassableRoadsLayer(activity);
mapView.addLayer(impassableRoadsLayer, 7.5f);
@ -460,6 +467,9 @@ public class MapActivityLayers {
return mapControlsLayer;
}
public MapMarkersLayer getMapMarkersLayer() {
return mapMarkersLayer;
}
public MapTileLayer getMapTileLayer() {
return mapTileLayer;

View file

@ -3,11 +3,14 @@ package net.osmand.plus.base;
import android.content.Context;
import android.view.WindowManager;
import net.osmand.FloatMath;
import net.osmand.Location;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.data.RotatedTileBox;
import net.osmand.map.IMapLocationListener;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
@ -17,10 +20,8 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.AutoZoomMap;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.AnimateDraggingMapThread;
@ -29,7 +30,8 @@ import net.osmand.util.MapUtils;
import java.util.List;
public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, OsmAndCompassListener, IRouteInformationListener {
public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener,
OsmAndCompassListener, IRouteInformationListener, MapMarkerChangedListener {
private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4;
private long lastTimeAutoZooming = 0;
@ -46,13 +48,17 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private boolean isUserZoomed = false;
private String locationProvider;
private boolean showRouteFinishDialog = false;
private Location myLocation;
private Float heading;
public MapViewTrackingUtilities(OsmandApplication app){
this.app = app;
settings = app.getSettings();
myLocation = app.getLocationProvider().getLastKnownLocation();
app.getLocationProvider().addLocationListener(this);
app.getLocationProvider().addCompassListener(this);
addTargetPointListener(app);
addMapMarkersListener(app);
app.getRoutingHelper().addListener(this);
}
@ -67,7 +73,22 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
}
});
}
private void addMapMarkersListener(OsmandApplication app) {
app.getMapMarkersHelper().addListener(this);
}
@Override
public void onMapMarkerChanged(MapMarkersHelper.MapMarker mapMarker) {
}
@Override
public void onMapMarkersChanged() {
if (mapView != null) {
mapView.refreshMap();
}
}
public void setMapView(OsmandMapTileView mapView) {
this.mapView = mapView;
if(mapView != null) {
@ -78,12 +99,21 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
}
}
public Location getMyLocation() {
return myLocation;
}
public Float getHeading() {
return heading;
}
public String getLocationProvider() {
return locationProvider;
}
@Override
public void updateCompassValue(float val) {
heading = val;
if (mapView != null) {
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode) {
if (Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -val)) > 1) {
@ -111,6 +141,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
@Override
public void updateLocation(Location location) {
myLocation = location;
showViewAngle = false;
if (location != null) {
locationProvider = location.getProvider();

View file

@ -41,6 +41,9 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
@ -54,6 +57,7 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.RasterMapMenu;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointDialogHelper.WaypointDialogHelperCallbacks;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
@ -68,6 +72,7 @@ import net.osmand.plus.views.controls.DynamicListView;
import net.osmand.plus.views.controls.DynamicListViewCallbacks;
import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.DismissCallbacks;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.Undoable;
import java.lang.ref.WeakReference;
@ -83,7 +88,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
/**
*/
public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks,
IRouteInformationListener, WaypointDialogHelperCallbacks {
IRouteInformationListener, WaypointDialogHelperCallbacks, MapMarkerChangedListener {
private static final org.apache.commons.logging.Log LOG =
PlatformUtil.getLog(DashboardOnMap.class);
private static final String TAG = "DashboardOnMap";
@ -141,6 +146,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
int baseColor;
private WaypointDialogHelper waypointDialogHelper;
private MapMarkerDialogHelper mapMarkerDialogHelper;
private final int[] running = new int[]{-1};
private List<LocationPointWrapper> deletedPoints = new ArrayList<>();
private Drawable gradientToolbar;
@ -159,7 +165,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
ROUTE_PREFERENCES,
DASHBOARD,
OVERLAY_MAP,
UNDERLAY_MAP
UNDERLAY_MAP,
MAP_MARKERS
}
private Map<DashboardActionButtonType, DashboardActionButton> actionButtons = new HashMap<>();
@ -184,6 +191,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
baseColor = mapActivity.getResources().getColor(R.color.osmand_orange) & 0x00ffffff;
waypointDialogHelper = new WaypointDialogHelper(mapActivity);
waypointDialogHelper.setWaypointDialogHelperCallbacks(this);
mapMarkerDialogHelper = new MapMarkerDialogHelper(mapActivity);
landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity);
dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard);
final View.OnClickListener listener = new View.OnClickListener() {
@ -204,11 +212,14 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
// the pressed state (the list selector), handling list item clicks, etc.
swipeDismissListener = new SwipeDismissListViewTouchListener(
listView,
new SwipeDismissListViewTouchListener.DismissCallbacks() {
new DismissCallbacks() {
private List<Object> deletedMarkers = new ArrayList<>();
@Override
public boolean canDismiss(int position) {
boolean res = false;
if (visibleType == DashboardType.WAYPOINTS && listAdapter instanceof StableArrayAdapter) {
if (listAdapter instanceof StableArrayAdapter) {
List<Object> activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects();
Object obj = listAdapter.getItem(position);
res = activeObjects.contains(obj);
@ -225,6 +236,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
stableAdapter = (StableArrayAdapter) listAdapter;
item = stableAdapter.getItem(position);
if (visibleType == DashboardType.MAP_MARKERS) {
if (!((MapMarker) item).history) {
deletedMarkers.add(item);
}
}
stableAdapter.setNotifyOnChange(false);
stableAdapter.remove(item);
stableAdapter.getObjects().remove(item);
@ -247,13 +264,19 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
stableAdapter.getObjects().add(position, item);
stableAdapter.getActiveObjects().add(activeObjPos, item);
stableAdapter.refreshData();
onItemsSwapped(stableAdapter.getActiveObjects());
if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
onItemsSwapped(stableAdapter.getActiveObjects());
} else if (visibleType == DashboardType.MAP_MARKERS) {
deletedMarkers.remove(item);
updateMapMarkers(stableAdapter.getActiveObjects());
reloadAdapter();
}
}
}
@Override
public String getTitle() {
if (visibleType == DashboardType.WAYPOINTS
if ((visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT)
&& (getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode())
&& item != null
&& stableAdapter.getActiveObjects().size() == 0) {
@ -270,14 +293,45 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
if (listAdapter instanceof StableArrayAdapter) {
StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
stableAdapter.refreshData();
onItemsSwapped(stableAdapter.getActiveObjects());
if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
onItemsSwapped(stableAdapter.getActiveObjects());
} else if (visibleType == DashboardType.MAP_MARKERS) {
updateMapMarkers(stableAdapter.getActiveObjects());
}
if (stableAdapter.getActiveObjects().size() == 0) {
hideDashboard();
mapActivity.getMapActions().stopNavigationWithoutConfirm();
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
mapActivity.getMapActions().stopNavigationWithoutConfirm();
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
}
} else {
if (visibleType == DashboardType.MAP_MARKERS) {
reloadAdapter();
}
}
}
}
private void updateMapMarkers(List<Object> objects) {
List<MapMarker> markers = new ArrayList<>();
List<MapMarker> markersHistory = new ArrayList<>();
for (Object obj : objects) {
MapMarker marker = (MapMarker) obj;
if (!marker.history) {
markers.add(marker);
} else {
markersHistory.add(marker);
}
}
for (int i = deletedMarkers.size() - 1; i >= 0; i--) {
markersHistory.add(0, (MapMarker) deletedMarkers.get(i));
}
deletedMarkers.clear();
getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, markersHistory);
}
});
gradientToolbar = mapActivity.getResources().getDrawable(R.drawable.gradient_toolbar).mutate();
@ -320,6 +374,16 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
dashboardView.addView(actionButton);
}
@Override
public void onMapMarkerChanged(MapMarker mapMarker) {
if (visible && visibleType == DashboardType.MAP_MARKERS) {
mapMarkerDialogHelper.updateMarkerView(listView, mapMarker);
}
}
@Override
public void onMapMarkersChanged() {
}
private void updateListBackgroundHeight() {
@ -358,6 +422,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
tv.setText(R.string.map_underlay);
} else if (visibleType == DashboardType.OVERLAY_MAP) {
tv.setText(R.string.map_overlay);
} else if (visibleType == DashboardType.MAP_MARKERS) {
tv.setText(R.string.map_markers);
}
ImageView edit = (ImageView) dashboardView.findViewById(R.id.toolbar_edit);
edit.setVisibility(View.GONE);
@ -399,17 +465,19 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
});
}
}
// if (waypointsEdit) {
// ok.setVisibility(View.VISIBLE);
// ok.setOnClickListener(new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// mapActivity.getMyApplication().getWaypointHelper().removeVisibleLocationPoint(deletedPoints);
// hideDashboard();
// }
// });
// }
if (visibleType == DashboardType.MAP_MARKERS
&& getMyApplication().getMapMarkersHelper().getActiveMapMarkers().size() > 0) {
sort.setVisibility(View.VISIBLE);
sort.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapMarkerDialogHelper.setSorted(!mapMarkerDialogHelper.isSorted());
reloadAdapter();
}
});
}
if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) {
settingsButton.setVisibility(View.VISIBLE);
settingsButton.setOnClickListener(new View.OnClickListener() {
@ -625,6 +693,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
updateListBackgroundHeight();
}
applyDayNightMode();
if (visibleType == DashboardType.MAP_MARKERS) {
getMyApplication().getMapMarkersHelper().addListener(this);
}
}
mapActivity.findViewById(R.id.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE);
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE);
@ -642,6 +714,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
// addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this);
} else {
if (visibleType == DashboardType.MAP_MARKERS) {
getMyApplication().getMapMarkersHelper().removeListener(this);
}
if (swipeDismissListener != null) {
swipeDismissListener.discardUndo();
}
@ -672,7 +747,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else {
listView.setBackgroundColor(mapActivity.getResources().getColor(R.color.ctx_menu_info_view_bg_dark));
}
if (visibleType != DashboardType.WAYPOINTS) {
if (visibleType != DashboardType.WAYPOINTS && visibleType != DashboardType.MAP_MARKERS) {
Drawable d = new ColorDrawable(mapActivity.getResources().getColor(R.color.dashboard_divider_dark));
listView.setDivider(d);
listView.setDividerHeight(dpToPx(1f));
@ -685,7 +760,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} else {
listView.setBackgroundColor(mapActivity.getResources().getColor(R.color.ctx_menu_info_view_bg_light));
}
if (visibleType != DashboardType.WAYPOINTS) {
if (visibleType != DashboardType.WAYPOINTS && visibleType != DashboardType.MAP_MARKERS) {
Drawable d = new ColorDrawable(mapActivity.getResources().getColor(R.color.dashboard_divider_light));
listView.setDivider(d);
listView.setDividerHeight(dpToPx(1f));
@ -703,6 +778,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
private void updateListAdapter() {
ContextMenuAdapter cm = null;
if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
StableArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running,
DashboardType.WAYPOINTS_FLAT == visibleType, nightMode);
OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running,
@ -714,7 +790,20 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
updateListAdapter(listAdapter, listener);
} else if (DashboardType.MAP_MARKERS == visibleType) {
mapMarkerDialogHelper.setNightMode(nightMode);
StableArrayAdapter listAdapter = mapMarkerDialogHelper.getMapMarkersListAdapter();
OnItemClickListener listener = mapMarkerDialogHelper.getItemClickListener(listAdapter);
DynamicListView dynamicListView = (DynamicListView) listView;
dynamicListView.setItemsList(listAdapter.getObjects());
dynamicListView.setActiveItemsList(listAdapter.getActiveObjects());
updateListAdapter(listAdapter, listener);
} else {
if (DashboardType.CONFIGURE_SCREEN == visibleType) {
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
} else if (DashboardType.CONFIGURE_MAP == visibleType) {
@ -749,7 +838,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
}
public void refreshContent(boolean force) {
if (visibleType == DashboardType.WAYPOINTS || force) {
if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.MAP_MARKERS || force) {
updateListAdapter();
} else if (visibleType == DashboardType.CONFIGURE_MAP || visibleType == DashboardType.ROUTE_PREFERENCES) {
int index = listView.getFirstVisiblePosition();
@ -941,6 +1030,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
((DashLocationFragment) df.get()).updateLocation(centerChanged, locationChanged, compassChanged);
}
}
if (visibleType == DashboardType.MAP_MARKERS) {
mapMarkerDialogHelper.updateLocation(listView, compassChanged);
}
}
});
@ -1254,10 +1346,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
@Override
public void reloadAdapter() {
if ((DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType)
&& listAdapter != null && listAdapter instanceof StableArrayAdapter) {
if (listAdapter != null && listAdapter instanceof StableArrayAdapter) {
StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
waypointDialogHelper.reloadListAdapter(stableAdapter);
if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
waypointDialogHelper.reloadListAdapter(stableAdapter);
} else if (DashboardType.MAP_MARKERS == visibleType) {
mapMarkerDialogHelper.reloadListAdapter(stableAdapter);
}
if (listView instanceof DynamicListView) {
DynamicListView dynamicListView = (DynamicListView) listView;
dynamicListView.setItemsList(stableAdapter.getObjects());

View file

@ -63,7 +63,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
firstRunPreference.setSummary(R.string.simulate_initial_startup_descr);
firstRunPreference.setSelectable(true);
firstRunPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@Override
public boolean onPreferenceClick(Preference preference) {
getMyApplication().getAppInitializer().resetFirstTimeRun();
getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false);
@ -77,6 +77,10 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
R.string.show_free_version_banner,
R.string.show_free_version_banner_description));
cat.addPreference(createCheckBoxPreference(settings.USE_MAP_MARKERS,
R.string.show_map_markers,
R.string.show_map_markers_description));
Preference pref = new Preference(this);
final Preference simulate = pref;
final OsmAndLocationSimulation sim = getMyApplication().getLocationProvider().getLocationSimulation();

View file

@ -61,13 +61,17 @@ public class DirectionsDialogs {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
closeContextMenu(act);
} else if (which == 1) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true,
targetPointsHelper.getIntermediatePoints().size() + 1, name);
closeContextMenu(act);
} else if (which == 2) {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, 0, name);
closeContextMenu(act);
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size(), name);
closeContextMenu(act);
}
MapActivity.launchMapActivityMoveToTop(act);
}
@ -75,10 +79,17 @@ public class DirectionsDialogs {
builder.show();
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
closeContextMenu(act);
MapActivity.launchMapActivityMoveToTop(act);
}
}
private static void closeContextMenu(Activity act) {
if (act instanceof MapActivity) {
((MapActivity) act).getContextMenu().close();
}
}
public static void setupPopUpMenuIcon(PopupMenu menu){
try {
Field[] fields = menu.getClass().getDeclaredFields();

View file

@ -0,0 +1,574 @@
package net.osmand.plus.helpers;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
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.dashboard.DashLocationFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.views.DirectionDrawable;
import net.osmand.plus.views.controls.ListDividerShape;
import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class MapMarkerDialogHelper {
public static final int ACTIVE_MARKERS = 0;
public static final int MARKERS_HISTORY = 1;
private MapActivity mapActivity;
private OsmandApplication app;
private MapMarkersHelper markersHelper;
private boolean sorted;
private boolean nightMode;
private boolean useCenter;
private LatLon loc;
private Float heading;
private int screenOrientation;
private boolean reloading;
private long lastUpdateTime;
public MapMarkerDialogHelper(MapActivity mapActivity) {
this.mapActivity = mapActivity;
app = mapActivity.getMyApplication();
markersHelper = app.getMapMarkersHelper();
}
public boolean isNightMode() {
return nightMode;
}
public void setNightMode(boolean nightMode) {
this.nightMode = nightMode;
}
public boolean isSorted() {
return sorted;
}
public void setSorted(boolean sorted) {
this.sorted = sorted;
}
public AdapterView.OnItemClickListener getItemClickListener(final ArrayAdapter<Object> listAdapter) {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
Object obj = listAdapter.getItem(item);
if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
if (!marker.history) {
showMarkerOnMap(mapActivity, marker);
} else {
showHistoryOnMap(marker);
}
}
}
};
}
public StableArrayAdapter getMapMarkersListAdapter() {
screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
calculateLocationParams();
final List<Object> objects = getListObjects();
List<Object> activeObjects = getActiveObjects(objects);
final StableArrayAdapter listAdapter = new StableArrayAdapter(mapActivity,
R.layout.map_marker_item, R.id.title, objects, activeObjects) {
@Override
public void buildDividers() {
dividers = getCustomDividers(getObjects());
}
@Override
public boolean isEnabled(int position) {
Object obj = getItem(position);
return obj instanceof MapMarker;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
Object obj = getItem(position);
boolean labelView = (obj instanceof Integer);
boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
if (labelView) {
v = createItemForCategory(this, (Integer) obj);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
} else if (topDividerView) {
v = mapActivity.getLayoutInflater().inflate(R.layout.card_top_divider, null);
} else if (bottomDividerView) {
v = mapActivity.getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
} else if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
v = updateMapMarkerItemView(v, marker);
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
}
return v;
}
};
return listAdapter;
}
private List<Drawable> getCustomDividers(List<Object> points) {
int color;
if (nightMode) {
color = mapActivity.getResources().getColor(R.color.dashboard_divider_dark);
} else {
color = mapActivity.getResources().getColor(R.color.dashboard_divider_light);
}
Shape fullDividerShape = new ListDividerShape(color, 0);
Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(mapActivity, 56f));
final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
int divHeight = AndroidUtils.dpToPx(mapActivity, 1f);
fullDivider.setIntrinsicHeight(divHeight);
halfDivider.setIntrinsicHeight(divHeight);
List<Drawable> res = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
Object obj = points.get(i);
Object objNext = i + 1 < points.size() ? points.get(i + 1) : null;
if (objNext == null) {
break;
}
boolean bottomDividerViewNext = (objNext instanceof Boolean) && !((Boolean) objNext);
boolean mapMarker = (obj instanceof MapMarker);
boolean mapMarkerNext = (objNext instanceof MapMarker);
Drawable d = null;
if (mapMarkerNext) {
if (mapMarker) {
d = halfDivider;
} else {
d = fullDivider;
}
} else if (mapMarker && !bottomDividerViewNext) {
d = fullDivider;
}
res.add(d);
}
return res;
}
protected View createItemForCategory(final ArrayAdapter<Object> listAdapter, final int type) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_header, null);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
v.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? mapActivity.getResources().getColor(R.color.map_widget_blue)
: mapActivity.getResources().getColor(R.color.osmand_orange));
btn.setText(mapActivity.getString(R.string.shared_string_clear));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type == MARKERS_HISTORY) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setMessage(mapActivity.getString(R.string.clear_markers_history_q))
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated();
markersHelper.removeMarkersHistory();
if (markersHelper.getActiveMapMarkers().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else {
reloadListAdapter(listAdapter);
}
}
})
.setNegativeButton(R.string.shared_string_no, null)
.show();
} else if (type == ACTIVE_MARKERS) {
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
builder.setMessage(mapActivity.getString(R.string.clear_active_markers_q))
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listAdapter.notifyDataSetInvalidated();
markersHelper.removeActiveMarkers();
if (markersHelper.getMapMarkersHistory().size() == 0) {
mapActivity.getDashboard().hideDashboard();
} else {
reloadListAdapter(listAdapter);
}
}
})
.setNegativeButton(R.string.shared_string_no, null)
.show();
}
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getHeader(type));
return v;
}
protected View updateMapMarkerItemView(View v, final MapMarker marker) {
if (v == null || v.findViewById(R.id.info_close) == null) {
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
}
updateMapMarkerInfoView(v, marker);
final View more = v.findViewById(R.id.all_points);
final View move = v.findViewById(R.id.info_move);
final View remove = v.findViewById(R.id.info_close);
remove.setVisibility(View.GONE);
move.setVisibility(View.GONE);
more.setVisibility(View.GONE);
return v;
}
protected void updateMapMarkerInfoView(View localView, final MapMarker marker) {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
ImageView waypointIcon = (ImageView) localView.findViewById(R.id.waypoint_icon);
TextView waypointDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
if (text == null || textDist == null || arrow == null || waypointIcon == null
|| waypointDeviation == null || descText == null) {
return;
}
float[] mes = new float[2];
if (loc != null && marker.point != null) {
Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
}
boolean newImage = false;
int arrowResId = R.drawable.ic_destination_arrow_white;
DirectionDrawable dd;
if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
newImage = true;
dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight());
} else {
dd = (DirectionDrawable) arrow.getDrawable();
}
if (!marker.history) {
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
} else {
dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light);
}
if (loc == null || heading == null || marker.point == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - heading + 180 + screenOrientation);
}
if (newImage) {
arrow.setImageDrawable(dd);
}
arrow.setVisibility(View.VISIBLE);
arrow.invalidate();
if (!marker.history) {
waypointIcon.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
AndroidUtils.setTextPrimaryColor(mapActivity, text, nightMode);
textDist.setTextColor(mapActivity.getResources()
.getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance));
} else {
waypointIcon.setImageDrawable(app.getIconsCache()
.getContentIcon(R.drawable.ic_action_flag_dark, !nightMode));
AndroidUtils.setTextSecondaryColor(mapActivity, text, nightMode);
AndroidUtils.setTextSecondaryColor(mapActivity, textDist, nightMode);
}
int dist = (int) mes[0];
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
waypointDeviation.setVisibility(View.GONE);
String descr;
PointDescription pd = marker.getPointDescription(app);
if (Algorithms.isEmpty(pd.getName())) {
descr = pd.getTypeName();
} else {
descr = pd.getName();
}
if (textShadow != null) {
textShadow.setText(descr);
}
text.setText(descr);
descText.setVisibility(View.GONE);
/*
String pointDescription = "";
if (descText != null) {
AndroidUtils.setTextSecondaryColor(this, descText, nightMode);
pointDescription = marker.getPointDescription(this).getTypeName();
}
if (descr.equals(pointDescription)) {
pointDescription = "";
}
if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
pointDescription = "" + pointDescription;
}
if (descText != null) {
descText.setText(pointDescription);
}
*/
}
protected void updateMapMarkerArrowDistanceView(View localView, final MapMarker marker) {
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
if (textDist == null || arrow == null) {
return;
}
float[] mes = new float[2];
if (loc != null && marker.point != null) {
Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
}
boolean newImage = false;
int arrowResId = R.drawable.ic_destination_arrow_white;
DirectionDrawable dd;
if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
newImage = true;
dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight());
} else {
dd = (DirectionDrawable) arrow.getDrawable();
}
if (!marker.history) {
dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
} else {
dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light);
}
if (loc == null || heading == null || marker.point == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - heading + 180 + screenOrientation);
}
if (newImage) {
arrow.setImageDrawable(dd);
}
arrow.invalidate();
int dist = (int) mes[0];
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
}
public static void showMarkerOnMap(MapActivity mapActivity, MapMarker marker) {
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker);
MapActivity.launchMapActivityMoveToTop(mapActivity);
}
public void showHistoryOnMap(MapMarker marker) {
app.getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION,
marker.getPointDescription(mapActivity).getName()),
false, null);
MapActivity.launchMapActivityMoveToTop(mapActivity);
}
protected String getHeader(int type) {
String str = mapActivity.getString(R.string.map_markers);
switch (type) {
case ACTIVE_MARKERS:
str = mapActivity.getString(R.string.active_markers);
break;
case MARKERS_HISTORY:
str = mapActivity.getString(R.string.shared_string_history);
break;
}
return str;
}
public void reloadListAdapter(ArrayAdapter<Object> listAdapter) {
reloading = true;
listAdapter.setNotifyOnChange(false);
listAdapter.clear();
List<Object> objects = getListObjects();
for (Object point : objects) {
listAdapter.add(point);
}
if (listAdapter instanceof StableArrayAdapter) {
((StableArrayAdapter) listAdapter).updateObjects(objects, getActiveObjects(objects));
}
listAdapter.notifyDataSetChanged();
reloading = false;
}
public void calcDistance(LatLon anchor, List<MapMarker> markers) {
for (MapMarker m : markers) {
m.dist = (int) (MapUtils.getDistance(m.getLatitude(), m.getLongitude(),
anchor.getLatitude(), anchor.getLongitude()));
}
}
protected List<Object> getListObjects() {
final List<Object> objects = new ArrayList<>();
LatLon mapLocation =
new LatLon(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude());
List<MapMarker> activeMarkers = new ArrayList<>(markersHelper.getActiveMapMarkers());
calcDistance(mapLocation, activeMarkers);
if (sorted) {
Collections.sort(activeMarkers, new Comparator<MapMarker>() {
@Override
public int compare(MapMarker lhs, MapMarker rhs) {
return lhs.dist < rhs.dist ? -1 : (lhs.dist == rhs.dist ? 0 : 1);
}
});
}
if (activeMarkers.size() > 0) {
objects.add(ACTIVE_MARKERS);
objects.addAll(activeMarkers);
objects.add(false);
}
List<MapMarker> markersHistory = new ArrayList<>(markersHelper.getMapMarkersHistory());
calcDistance(mapLocation, markersHistory);
if (markersHistory.size() > 0) {
if (activeMarkers.size() > 0) {
objects.add(true);
}
objects.add(MARKERS_HISTORY);
objects.addAll(markersHistory);
objects.add(false);
}
return objects;
}
private List<Object> getActiveObjects(List<Object> objects) {
List<Object> activeObjects = new ArrayList<>();
for (Object obj : objects) {
if (obj instanceof MapMarker) {
activeObjects.add(obj);
}
}
return activeObjects;
}
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, getMapMarkerColorId(colorIndex));
}
public static int getMapMarkerColorId(int colorIndex) {
int colorId;
switch (colorIndex) {
case 0:
colorId = R.color.marker_blue;
break;
case 1:
colorId = R.color.marker_green;
break;
case 2:
colorId = R.color.marker_orange;
break;
case 3:
colorId = R.color.marker_red;
break;
case 4:
colorId = R.color.marker_yellow;
break;
case 5:
colorId = R.color.marker_teal;
break;
case 6:
colorId = R.color.marker_purple;
break;
default:
colorId = R.color.marker_blue;
}
return colorId;
}
public void updateLocation(ListView listView, boolean compassChanged) {
if ((compassChanged && !mapActivity.getDashboard().isMapLinkedToLocation())
|| reloading || System.currentTimeMillis() - lastUpdateTime < 100) {
return;
}
lastUpdateTime = System.currentTimeMillis();
try {
calculateLocationParams();
for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) {
Object obj = listView.getItemAtPosition(i);
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
if (obj instanceof MapMarker && v != null) {
updateMapMarkerArrowDistanceView(v, (MapMarker) obj);
}
}
} catch (Exception e) {
}
}
public void updateMarkerView(ListView listView, MapMarker marker) {
try {
for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) {
Object obj = listView.getItemAtPosition(i);
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
if (obj == marker) {
updateMapMarkerInfoView(v, (MapMarker) obj);
}
}
} catch (Exception e) {
}
}
private void calculateLocationParams() {
DashboardOnMap d = mapActivity.getDashboard();
if (d == null) {
return;
}
float head = d.getHeading();
float mapRotation = d.getMapRotation();
LatLon mw = d.getMapViewLocation();
Location l = d.getMyLocation();
boolean mapLinked = d.isMapLinkedToLocation() && l != null;
LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
useCenter = !mapLinked;
loc = (useCenter ? mw : myLoc);
heading = useCenter ? -mapRotation : head;
}
}

View file

@ -19,9 +19,13 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
@ -41,9 +45,11 @@ import net.osmand.util.MapUtils;
import java.lang.ref.WeakReference;
import java.util.List;
public class MapContextMenu extends MenuTitleController implements StateChangedListener<ApplicationMode> {
public class MapContextMenu extends MenuTitleController implements StateChangedListener<ApplicationMode>,
MapMarkerChangedListener {
private MapActivity mapActivity;
private OsmandSettings settings;
private MapMultiSelectionMenu mapMultiSelectionMenu;
private FavoritePointEditor favoritePointEditor;
@ -77,6 +83,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
settings = mapActivity.getMyApplication().getSettings();
if (!appModeListenerAdded) {
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.addListener(this);
appModeListenerAdded = true;
@ -255,6 +262,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.refreshMap();
if (object instanceof MapMarker) {
mapActivity.getMyApplication().getMapMarkersHelper().addListener(this);
}
return true;
}
@ -307,6 +318,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void close() {
if (active) {
active = false;
if (object instanceof MapMarker) {
mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this);
}
if (this.object != null) {
clearSelectedObject(this.object);
}
@ -333,6 +347,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
}
}
@Override
public void onMapMarkerChanged(MapMarker mapMarker) {
if (object == mapMarker) {
String address = ((MapMarker) object).getOnlyName();
nameStr = address;
pointDescription.setName(address);
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null)
fragmentRef.get().refreshTitle();
}
}
@Override
public void onMapMarkersChanged() {
}
@Override
public void stateChanged(ApplicationMode change) {
appModeChanged = active;
@ -435,6 +465,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} else if (targets.getIntermediatePoints().isEmpty()) {
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
close();
} else {
Builder bld = new AlertDialog.Builder(mapActivity);
bld.setTitle(R.string.new_directions_point_dialog);
@ -456,9 +487,11 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
targets.removeAllWayPoints(false);
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
close();
} else {
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
close();
}
}
});
@ -470,6 +503,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void buttonWaypointPressed() {
if (pointDescription.isDestination()) {
mapActivity.getMapActions().editWaypoints();
} else if (settings.USE_MAP_MARKERS.get()) {
if (pointDescription.isMapMarker()) {
hide();
MapActivity.clearPrevActivityIntent();
mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS);
} else {
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForTarget());
}
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForTarget());

View file

@ -387,8 +387,13 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
});
final ImageButton buttonWaypoint = (ImageButton) view.findViewById(R.id.context_menu_route_button);
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoint,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
if (getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_flag_dark,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
} else {
buttonWaypoint.setImageDrawable(iconsCache.getIcon(R.drawable.map_action_waypoint,
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
}
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode);
buttonWaypoint.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -11,6 +11,8 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -24,6 +26,7 @@ import net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController;
import net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
@ -101,6 +104,8 @@ public abstract class MenuController extends BaseMenuController {
menuController = new OsmBugMenuController(app, mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof GpxDisplayItem) {
menuController = new GpxItemMenuController(app, mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof MapMarker) {
menuController = new MapMarkerMenuController(app, mapActivity, pointDescription, (MapMarker) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);

View file

@ -0,0 +1,76 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.util.Algorithms;
public class MapMarkerMenuController extends MenuController {
private MapMarker mapMarker;
public MapMarkerMenuController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.mapMarker = mapMarker;
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.removeMapMarker(getMapMarker().index);
markersHelper.addMapMarkerHistory(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_remove);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
}
@Override
protected void setObject(Object object) {
if (object instanceof MapMarker) {
this.mapMarker = (MapMarker) object;
}
}
public MapMarker getMapMarker() {
return mapMarker;
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN;
}
@Override
public boolean needTypeStr() {
return !Algorithms.isEmpty(getNameStr());
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public Drawable getLeftIcon() {
return MapMarkerDialogHelper.getMapMarkerIcon(getMapActivity().getMyApplication(), mapMarker.colorIndex);
}
@Override
public String getTypeStr() {
return mapMarker.getPointDescription(getMapActivity()).getTypeName();
}
@Override
public boolean needStreetName() {
return !needTypeStr();
}
}

View file

@ -0,0 +1,273 @@
package net.osmand.plus.views;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.mapwidgets.MapMarkersWidget;
import java.util.ArrayList;
import java.util.List;
public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
protected final static int DIST_TO_SHOW = 80;
private final MapActivity map;
private OsmandMapTileView view;
private MapMarkersWidget widget;
private Paint bitmapPaint;
private Bitmap markerBitmapBlue;
private Bitmap markerBitmapGreen;
private Bitmap markerBitmapOrange;
private Bitmap markerBitmapRed;
private Bitmap markerBitmapYellow;
private Bitmap markerBitmapTeal;
private Bitmap markerBitmapPurple;
private Paint bitmapPaintDestBlue;
private Paint bitmapPaintDestGreen;
private Paint bitmapPaintDestOrange;
private Paint bitmapPaintDestRed;
private Paint bitmapPaintDestYellow;
private Paint bitmapPaintDestTeal;
private Paint bitmapPaintDestPurple;
private Bitmap arrowToDestination;
private float[] calculations = new float[2];
public MapMarkersLayer(MapActivity map) {
this.map = map;
}
private void initUI() {
bitmapPaint = new Paint();
bitmapPaint.setDither(true);
bitmapPaint.setAntiAlias(true);
bitmapPaint.setFilterBitmap(true);
markerBitmapBlue = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_blue);
markerBitmapGreen = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_green);
markerBitmapOrange = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_orange);
markerBitmapRed = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_red);
markerBitmapYellow = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_yellow);
markerBitmapTeal = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_red);
markerBitmapPurple = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_green);
arrowToDestination = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_arrow_to_destination);
bitmapPaintDestBlue = createPaintDest(R.color.marker_blue);
bitmapPaintDestGreen = createPaintDest(R.color.marker_green);
bitmapPaintDestOrange = createPaintDest(R.color.marker_orange);
bitmapPaintDestRed = createPaintDest(R.color.marker_red);
bitmapPaintDestYellow = createPaintDest(R.color.marker_yellow);
bitmapPaintDestTeal = createPaintDest(R.color.marker_teal);
bitmapPaintDestPurple = createPaintDest(R.color.marker_purple);
widget = new MapMarkersWidget(map);
}
private Paint createPaintDest(int colorId) {
Paint paint = new Paint();
paint.setDither(true);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
int color = map.getResources().getColor(colorId);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
return paint;
}
private Paint getMarkerDestPaint(int colorIndex) {
switch (colorIndex) {
case 0:
return bitmapPaintDestBlue;
case 1:
return bitmapPaintDestGreen;
case 2:
return bitmapPaintDestOrange;
case 3:
return bitmapPaintDestRed;
case 4:
return bitmapPaintDestYellow;
case 5:
return bitmapPaintDestTeal;
case 6:
return bitmapPaintDestPurple;
default:
return bitmapPaintDestBlue;
}
}
private Bitmap getMapMarkerBitmap(int colorIndex) {
switch (colorIndex) {
case 0:
return markerBitmapBlue;
case 1:
return markerBitmapGreen;
case 2:
return markerBitmapOrange;
case 3:
return markerBitmapRed;
case 4:
return markerBitmapYellow;
case 5:
return markerBitmapTeal;
case 6:
return markerBitmapPurple;
default:
return markerBitmapBlue;
}
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
initUI();
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
widget.updateInfo(tb.getZoom());
if (tb.getZoom() < 3) {
return;
}
List<MapMarker> hiddenMarkers = new ArrayList<>();
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
for (MapMarker marker : markersHelper.getActiveMapMarkers()) {
if (isLocationVisible(tb, marker)) {
Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
int marginX = bmp.getWidth() / 6;
int marginY = bmp.getHeight();
int locationX = tb.getPixXFromLonNoRot(marker.getLongitude());
int locationY = tb.getPixYFromLatNoRot(marker.getLatitude());
canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(bmp, locationX - marginX, locationY - marginY, bitmapPaint);
canvas.rotate(tb.getRotate(), locationX, locationY);
} else {
hiddenMarkers.add(marker);
}
}
for (MapMarker marker : hiddenMarkers) {
boolean show = true;
if (show) {
canvas.save();
net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(),
marker.getLatitude(), marker.getLongitude(), calculations);
float bearing = calculations[1] - 90;
float radiusBearing = DIST_TO_SHOW * tb.getDensity();
final QuadPoint cp = tb.getCenterPixelPoint();
canvas.rotate(bearing, cp.x, cp.y);
canvas.translate(-24 * tb.getDensity() + radiusBearing, -22 * tb.getDensity());
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, getMarkerDestPaint(marker.colorIndex));
canvas.restore();
}
}
}
public boolean isLocationVisible(RotatedTileBox tb, MapMarker marker) {
if (marker == null || tb == null) {
return false;
}
return tb.containsLatLon(marker.getLatitude(), marker.getLongitude());
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> markers = markersHelper.getActiveMapMarkers();
int r = getRadiusPoi(tileBox);
for (int i = 0; i < markers.size(); i++) {
MapMarker marker = markers.get(i);
LatLon latLon = marker.point;
if (latLon != null) {
int ex = (int) point.x;
int ey = (int) point.y;
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) {
o.add(marker);
}
}
}
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return Math.abs(objx - ex) <= radius && (ey - objy) <= radius && (objy - ey) <= 2.5 * radius;
}
public int getRadiusPoi(RotatedTileBox tb) {
int r;
final double zoom = tb.getZoom();
if (zoom <= 15) {
r = 10;
} else if (zoom <= 16) {
r = 14;
} else if (zoom <= 17) {
r = 16;
} else {
r = 18;
}
return (int) (r * tb.getDensity());
}
@Override
public LatLon getObjectLocation(Object o) {
if (o instanceof MapMarker) {
return ((MapMarker) o).point;
}
return null;
}
@Override
public String getObjectDescription(Object o) {
if (o instanceof MapMarker) {
return ((MapMarker) o).getPointDescription(view.getContext()).getFullPlainName(view.getContext());
}
return null;
}
@Override
public PointDescription getObjectName(Object o) {
if (o instanceof MapMarker) {
return ((MapMarker) o).getPointDescription(view.getContext());
}
return null;
}
}

View file

@ -8,6 +8,7 @@ import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.PointF;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
@ -78,7 +79,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
if(tb.getZoom() < 3) {
if (tb.getZoom() < 3) {
return;
}

View file

@ -2,12 +2,8 @@ package net.osmand.plus.views.controls;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

View file

@ -102,6 +102,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
//private List<PendingDismissData> mPendingDismisses = new ArrayList<PendingDismissData>();
private int mDismissAnimationRefCount = 0;
private float mDownX;
private float mDownY;
private boolean mSwiping;
private VelocityTracker mVelocityTracker;
private int mDownPosition;
@ -601,6 +602,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount();
if (mCallbacks == null || mCallbacks.canDismiss(position)) {
mDownX = ev.getRawX();
mDownY = ev.getRawY();
mDownPosition = position;
mVelocityTracker = VelocityTracker.obtain();
@ -629,6 +631,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
mVelocityTracker.recycle();
mVelocityTracker = null;
mDownX = 0;
mDownY = 0;
mSwipeDownView = mSwipeDownChild = null;
mDownPosition = ListView.INVALID_POSITION;
mSwiping = false;
@ -669,6 +672,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
}
mVelocityTracker = null;
mDownX = 0;
mDownY = 0;
mSwipeDownView = null;
mSwipeDownChild = null;
mDownPosition = AbsListView.INVALID_POSITION;
@ -683,6 +687,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
mVelocityTracker.addMovement(ev);
float deltaX = ev.getRawX() - mDownX;
float deltaY = ev.getRawY() - mDownY;
// Only start swipe in correct direction
if (isSwipeDirectionValid(deltaX)) {
ViewParent parent = mListView.getParent();
@ -691,7 +696,7 @@ public class SwipeDismissListViewTouchListener implements View.OnTouchListener {
// otherwise swipe would not be working.
parent.requestDisallowInterceptTouchEvent(true);
}
if (Math.abs(deltaX) > mSlop) {
if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
mSwiping = true;
mListView.requestDisallowInterceptTouchEvent(true);

View file

@ -0,0 +1,233 @@
package net.osmand.plus.views.mapwidgets;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.Location;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
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.util.Algorithms;
import java.util.List;
public class MapMarkersWidget {
public static final int MIN_DIST_OK_VISIBLE = 50;
private final MapActivity map;
private MapMarkersHelper helper;
private int screenOrientation;
private boolean portraitMode;
private boolean largeDevice;
private View topBar;
private View topBar2nd;
private View rowView;
private View rowView2nd;
private ImageView arrowImg;
private ImageView arrowImg2nd;
private TextView distText;
private TextView distText2nd;
private TextView addressText;
private TextView addressText2nd;
private ImageButton okButton;
private ImageButton okButton2nd;
private ImageButton moreButton;
private ImageButton moreButton2nd;
public MapMarkersWidget(final MapActivity map) {
this.map = map;
helper = map.getMyApplication().getMapMarkersHelper();
screenOrientation = DashLocationFragment.getScreenOrientation(map);
portraitMode = AndroidUiHelper.isOrientationPortrait(map);
largeDevice = AndroidUiHelper.isXLargeDevice(map);
topBar = map.findViewById(R.id.map_markers_top_bar);
topBar2nd = map.findViewById(R.id.map_markers_top_bar_2nd);
rowView = map.findViewById(R.id.map_marker_row);
rowView2nd = map.findViewById(R.id.map_marker_row_2nd);
arrowImg = (ImageView) map.findViewById(R.id.map_marker_arrow);
arrowImg2nd = (ImageView) map.findViewById(R.id.map_marker_arrow_2nd);
distText = (TextView) map.findViewById(R.id.map_marker_dist);
distText2nd = (TextView) map.findViewById(R.id.map_marker_dist_2nd);
addressText = (TextView) map.findViewById(R.id.map_marker_address);
addressText2nd = (TextView) map.findViewById(R.id.map_marker_address_2nd);
okButton = (ImageButton) map.findViewById(R.id.marker_btn_ok);
okButton2nd = (ImageButton) map.findViewById(R.id.marker_btn_ok_2dn);
moreButton = (ImageButton) map.findViewById(R.id.marker_btn_more);
moreButton2nd = (ImageButton) map.findViewById(R.id.marker_btn_more_2nd);
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMarkerOnMap(0);
}
});
rowView2nd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMarkerOnMap(1);
}
});
IconsCache iconsCache = map.getMyApplication().getIconsCache();
if (isLandscapeLayout()) {
moreButton.setVisibility(View.GONE);
} else {
moreButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
moreButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity.clearPrevActivityIntent();
map.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS);
}
});
}
if (moreButton2nd != null) {
moreButton2nd.setImageDrawable(iconsCache.getIcon(R.drawable.ic_overflow_menu_white, R.color.marker_top_2nd_line_color));
moreButton2nd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity.clearPrevActivityIntent();
map.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAP_MARKERS);
}
});
}
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeMarker(0);
}
});
okButton2nd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
removeMarker(1);
}
});
updateVisibility(false);
}
private void removeMarker(int index) {
if (helper.getActiveMapMarkers().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index);
helper.removeMapMarker(marker.index);
helper.addMapMarkerHistory(marker);
}
}
private void showMarkerOnMap(int index) {
if (helper.getActiveMapMarkers().size() > index) {
MapMarker marker = helper.getActiveMapMarkers().get(index);
MapMarkerDialogHelper.showMarkerOnMap(map, marker);
}
}
public boolean updateVisibility(boolean visible) {
return updateVisibility(topBar, visible);
}
public boolean updateVisibility(View v, boolean visible) {
if (visible != (v.getVisibility() == View.VISIBLE)) {
if (visible) {
v.setVisibility(View.VISIBLE);
} else {
v.setVisibility(View.GONE);
}
v.invalidate();
return true;
}
return false;
}
public void updateInfo(int zoom) {
List<MapMarker> markers = helper.getActiveMapMarkers();
if (zoom < 3 || markers.size() == 0 || map.getMyApplication().getRoutingHelper().isFollowingMode()
|| map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible()) {
updateVisibility(false);
return;
}
Location loc = map.getMapViewTrackingUtilities().getMyLocation();
Float heading = map.getMapViewTrackingUtilities().getHeading();
MapMarker marker = markers.get(0);
updateUI(loc, heading, marker, arrowImg, distText, okButton, addressText, true);
if (markers.size() > 1) {
marker = markers.get(1);
updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false);
updateVisibility(topBar2nd, true);
} else {
updateVisibility(topBar2nd, false);
}
updateVisibility(true);
}
private void updateUI(Location loc, Float heading, MapMarker marker, ImageView arrowImg,
TextView distText, ImageButton okButton, TextView addressText, boolean firstLine) {
float[] mes = new float[2];
if (loc != null && marker.point != null) {
Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
}
boolean newImage = false;
DirectionDrawable dd;
if (!(arrowImg.getDrawable() instanceof DirectionDrawable)) {
newImage = true;
dd = new DirectionDrawable(map, arrowImg.getWidth(), arrowImg.getHeight());
} else {
dd = (DirectionDrawable) arrowImg.getDrawable();
}
dd.setImage(R.drawable.map_arrow_to_destination, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex));
if (loc == null || heading == null || marker.point == null) {
dd.setAngle(0);
} else {
dd.setAngle(mes[1] - heading + 90 + screenOrientation);
}
if (newImage) {
arrowImg.setImageDrawable(dd);
}
arrowImg.invalidate();
int dist = (int) mes[0];
if (loc != null) {
distText.setText(OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication()));
} else {
distText.setText("" + map.getString(R.string.m));
}
updateVisibility(okButton, loc != null && dist < MIN_DIST_OK_VISIBLE);
String descr;
PointDescription pd = marker.getPointDescription(map);
if (Algorithms.isEmpty(pd.getName())) {
descr = pd.getTypeName();
} else {
descr = pd.getName();
}
if (!firstLine && !isLandscapeLayout()) {
descr = "" + descr;
}
addressText.setText(descr);
}
public boolean isLandscapeLayout() {
return !portraitMode && !largeDevice;
}
}