Merge pull request #4794 from osmandapp/markers_empty_states

Markers icons and context menu
This commit is contained in:
Alexey 2017-11-22 19:34:52 +03:00 committed by GitHub
commit 08122c430f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 356 additions and 94 deletions

View file

@ -74,6 +74,8 @@ public class MapMarkersHelper {
public String nextKey; public String nextKey;
public String groupKey; public String groupKey;
public String groupName; public String groupName;
public WptPt wptPt;
public FavouritePoint favouritePoint;
public MapMarker(LatLon point, PointDescription name, int colorIndex, public MapMarker(LatLon point, PointDescription name, int colorIndex,
boolean selected, int index) { boolean selected, int index) {
@ -455,19 +457,19 @@ public class MapMarkersHelper {
} }
} }
public void syncGroupAsync(MarkersSyncGroup group) { public void syncGroupAsync(@NonNull MarkersSyncGroup group) {
syncGroupAsync(group, true, null); syncGroupAsync(group, true, null);
} }
public void syncGroupAsync(MarkersSyncGroup group, boolean enabled) { public void syncGroupAsync(@NonNull MarkersSyncGroup group, boolean enabled) {
syncGroupAsync(group, enabled, null); syncGroupAsync(group, enabled, null);
} }
public void syncGroupAsync(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) { public void syncGroupAsync(@NonNull MarkersSyncGroup group, @Nullable OnGroupSyncedListener groupSyncedListener) {
syncGroupAsync(group, true, groupSyncedListener); syncGroupAsync(group, true, groupSyncedListener);
} }
private void syncGroupAsync(final MarkersSyncGroup group, final boolean enabled, final OnGroupSyncedListener groupSyncedListener) { private void syncGroupAsync(@NonNull final MarkersSyncGroup group, final boolean enabled, @Nullable final OnGroupSyncedListener groupSyncedListener) {
ctx.runInUIThread(new Runnable() { ctx.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -517,7 +519,7 @@ public class MapMarkersHelper {
} }
for (FavouritePoint fp : favGroup.points) { for (FavouritePoint fp : favGroup.points) {
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled, fp, null);
} }
removeOldMarkersIfNeeded(dbMarkers); removeOldMarkersIfNeeded(dbMarkers);
@ -540,7 +542,7 @@ public class MapMarkersHelper {
int defColor = ContextCompat.getColor(ctx, R.color.marker_red); int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) { for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor)); group.setColor(pt.getColor(defColor));
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled); addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled, null, pt);
} }
removeOldMarkersIfNeeded(dbMarkers); removeOldMarkersIfNeeded(dbMarkers);
@ -560,19 +562,62 @@ public class MapMarkersHelper {
} }
} }
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled) { public boolean isSynced(SelectedGpxFile gpxFile) {
GPXFile gpx = gpxFile.getGpxFile();
List<WptPt> gpxPoints = gpx.getPoints();
for (WptPt wptPt : gpxPoints) {
MapMarker mapMarker = getMapMarker(wptPt);
if (mapMarker != null) {
return true;
}
}
return false;
}
public boolean isSynced(FavouritePoint favouritePoint) {
MapMarker mapMarker = getMapMarker(favouritePoint);
return mapMarker != null;
}
public MapMarker getMapMarker(WptPt wptPt) {
for (MapMarker marker : mapMarkers) {
if (marker.wptPt == wptPt) {
return marker;
}
}
return null;
}
public MapMarker getMapMarker(FavouritePoint favouritePoint) {
for (MapMarker marker : mapMarkers) {
if (marker.favouritePoint == favouritePoint) {
return marker;
}
}
return null;
}
private void addNewMarkerIfNeeded(@NonNull MarkersSyncGroup group,
@NonNull List<MapMarker> markers,
@NonNull LatLon latLon,
@NonNull String name,
boolean enabled,
@Nullable FavouritePoint favouritePoint,
@Nullable WptPt wptPt) {
boolean exists = false; boolean exists = false;
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
if (marker.id.equals(group.getId() + name)) { if (marker.id.equals(group.getId() + name)) {
exists = true; exists = true;
if (!marker.history && (!marker.point.equals(latLon))) { for (MapMarker m : mapMarkers) {
for (MapMarker m : mapMarkers) { if (m.id.equals(marker.id)) {
if (m.id.equals(marker.id)) { m.favouritePoint = favouritePoint;
m.wptPt = wptPt;
if (!marker.history && !marker.point.equals(latLon)) {
m.point = latLon; m.point = latLon;
updateMapMarker(m, true); updateMapMarker(m, true);
break;
} }
break;
} }
} }
markers.remove(marker); markers.remove(marker);
@ -582,7 +627,8 @@ public class MapMarkersHelper {
if (!exists) { if (!exists) {
addMarkers(Collections.singletonList(latLon), addMarkers(Collections.singletonList(latLon),
Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, name)), group, enabled); Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, name)),
group, enabled, Collections.singletonList(favouritePoint), Collections.singletonList(wptPt));
} }
} }
@ -840,7 +886,7 @@ public class MapMarkersHelper {
markersDbHelper.removeDisabledGroups(); markersDbHelper.removeDisabledGroups();
} }
public void updateGroupDisabled(MapMarkersGroup group, boolean disabled) { public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
String id = group.getGroupKey(); String id = group.getGroupKey();
if (id != null) { if (id != null) {
markersDbHelper.updateSyncGroupDisabled(id, disabled); markersDbHelper.updateSyncGroupDisabled(id, disabled);
@ -848,7 +894,7 @@ public class MapMarkersHelper {
} }
} }
private void updateSyncGroupDisabled(MapMarkersGroup group, boolean disabled) { private void updateSyncGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
List<MapMarker> groupMarkers = group.getMarkers(); List<MapMarker> groupMarkers = group.getMarkers();
for (MapMarker marker : groupMarkers) { for (MapMarker marker : groupMarkers) {
if (marker.history) { if (marker.history) {
@ -886,21 +932,28 @@ public class MapMarkersHelper {
} }
} }
public void addMapMarker(LatLon point, PointDescription historyName) { public void addMapMarker(@NonNull LatLon point, @Nullable PointDescription historyName) {
addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true); addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true);
} }
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) { public void addMapMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
addMarkers(points, historyNames, group, true); addMarkers(points, historyNames, group, true);
} }
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, boolean enabled) { private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group, boolean enabled) {
addMarkers(points, historyNames, group, enabled, null, null);
}
private void addMarkers(@NonNull List<LatLon> points, @NonNull List<PointDescription> historyNames, @Nullable MarkersSyncGroup group,
boolean enabled, @Nullable List<FavouritePoint> favouritePoints, @Nullable List<WptPt> wptPts) {
if (points.size() > 0) { if (points.size() > 0) {
int colorIndex = -1; int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>(); List<MapMarker> addedMarkers = new ArrayList<>();
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
LatLon point = points.get(i); LatLon point = points.get(i);
PointDescription historyName = historyNames.get(i); PointDescription historyName = historyNames.get(i);
FavouritePoint favouritePoint = favouritePoints == null ? null : favouritePoints.get(i);
WptPt wptPt = wptPts == null ? null : wptPts.get(i);
final PointDescription pointDescription; final PointDescription pointDescription;
if (historyName == null) { if (historyName == null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""); pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
@ -931,6 +984,8 @@ public class MapMarkersHelper {
} }
marker.history = false; marker.history = false;
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
marker.favouritePoint = favouritePoint;
marker.wptPt = wptPt;
markersDbHelper.addMarker(marker); markersDbHelper.addMarker(marker);
if (enabled) { if (enabled) {
addToMapMarkersList(0, marker); addToMapMarkersList(0, marker);
@ -1143,7 +1198,7 @@ public class MapMarkersHelper {
} }
} }
private void addMarkersToGroups(List<MapMarker> markers, boolean enabled) { private void addMarkersToGroups(@NonNull List<MapMarker> markers, boolean enabled) {
List<MapMarkersGroup> groups = new ArrayList<>(); List<MapMarkersGroup> groups = new ArrayList<>();
for (int i = 0; i < markers.size(); i++) { for (int i = 0; i < markers.size(); i++) {
MapMarkersGroup group = addMarkerToGroup(markers.get(i)); MapMarkersGroup group = addMarkerToGroup(markers.get(i));
@ -1178,7 +1233,7 @@ public class MapMarkersHelper {
return null; return null;
} }
private MapMarkersGroup createMapMarkerGroup(MapMarker marker) { private MapMarkersGroup createMapMarkerGroup(@NonNull MapMarker marker) {
MapMarkersGroup group = new MapMarkersGroup(); MapMarkersGroup group = new MapMarkersGroup();
if (marker.groupName != null) { if (marker.groupName != null) {
group.setName(marker.groupName); group.setName(marker.groupName);
@ -1197,7 +1252,7 @@ public class MapMarkersHelper {
return group; return group;
} }
private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) { private void createHeaderAndHistoryButtonInGroup(@NonNull MapMarkersGroup group) {
if (group.getName() != null) { if (group.getName() != null) {
GroupHeader header = new GroupHeader(); GroupHeader header = new GroupHeader();
int type = group.getType(); int type = group.getType();

View file

@ -25,14 +25,20 @@ public class FavoriteImageDrawable extends Drawable {
private Paint paintBackground; private Paint paintBackground;
private Bitmap favIcon; private Bitmap favIcon;
private Bitmap favBackground; private Bitmap favBackground;
private Bitmap syncedStroke;
private Bitmap syncedColor;
private Bitmap syncedShadow;
private Bitmap syncedIcon;
private Resources resources; private Resources resources;
private boolean withShadow; private boolean withShadow;
private boolean synced;
private Paint paintOuter; private Paint paintOuter;
private Paint paintInnerCircle; private Paint paintInnerCircle;
private Drawable listDrawable; private Drawable listDrawable;
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow) { public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced) {
this.withShadow = withShadow; this.withShadow = withShadow;
this.synced = synced;
this.resources = ctx.getResources(); this.resources = ctx.getResources();
this.color = color; this.color = color;
paintBackground = new Paint(); paintBackground = new Paint();
@ -41,6 +47,10 @@ public class FavoriteImageDrawable extends Drawable {
paintIcon = new Paint(); paintIcon = new Paint();
favIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_favorite); favIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_favorite);
favBackground = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_white_favorite_shield); favBackground = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_white_favorite_shield);
syncedStroke = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_shield_marker_point_stroke);
syncedColor = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_shield_marker_point_color);
syncedShadow = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_shield_marker_point_shadow);
syncedIcon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.map_marker_point_14dp);
listDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_fav_dark, null).mutate(); listDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_fav_dark, null).mutate();
paintOuter = new Paint(); paintOuter = new Paint();
@ -58,7 +68,7 @@ public class FavoriteImageDrawable extends Drawable {
protected void onBoundsChange(Rect bounds) { protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds); super.onBoundsChange(bounds);
if (!withShadow) { if (!withShadow && !synced) {
Rect bs = new Rect(bounds); Rect bs = new Rect(bounds);
//bs.inset((int) (4 * density), (int) (4 * density)); //bs.inset((int) (4 * density), (int) (4 * density));
bs.inset(bs.width() / 4, bs.height() / 4); bs.inset(bs.width() / 4, bs.height() / 4);
@ -68,12 +78,12 @@ public class FavoriteImageDrawable extends Drawable {
@Override @Override
public int getIntrinsicHeight() { public int getIntrinsicHeight() {
return favBackground.getHeight(); return synced ? syncedShadow.getHeight() : favBackground.getHeight();
} }
@Override @Override
public int getIntrinsicWidth() { public int getIntrinsicWidth() {
return favBackground.getWidth(); return synced ? syncedShadow.getWidth() : favBackground.getWidth();
} }
public int getColor() { public int getColor() {
@ -87,7 +97,12 @@ public class FavoriteImageDrawable extends Drawable {
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
Rect bs = getBounds(); Rect bs = getBounds();
if(withShadow) { if (synced) {
canvas.drawBitmap(syncedShadow, bs.exactCenterX() - syncedShadow.getWidth() / 2f, bs.exactCenterY() - syncedShadow.getHeight() / 2f, paintBackground);
canvas.drawBitmap(syncedColor, bs.exactCenterX() - syncedColor.getWidth() / 2f, bs.exactCenterY() - syncedColor.getHeight() / 2f, paintBackground);
canvas.drawBitmap(syncedStroke, bs.exactCenterX() - syncedStroke.getWidth() / 2f, bs.exactCenterY() - syncedStroke.getHeight() / 2f, paintBackground);
canvas.drawBitmap(syncedIcon, bs.exactCenterX() - syncedIcon.getWidth() / 2f, bs.exactCenterY() - syncedIcon.getHeight() / 2f, paintIcon);
} else if (withShadow) {
canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground); canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground);
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon); canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
} else { } else {
@ -133,15 +148,23 @@ public class FavoriteImageDrawable extends Drawable {
private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>(); private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>();
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) { private static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced) {
color = color | 0xff000000; color = color | 0xff000000;
int hash = (color << 2) + (withShadow ? 1 : 0); int hash = (color << 2) + (withShadow ? 1 : 0) + (synced ? 3 : 0);
FavoriteImageDrawable drawable = cache.get(hash); FavoriteImageDrawable drawable = cache.get(hash);
if (drawable == null) { if (drawable == null) {
drawable = new FavoriteImageDrawable(a, color, withShadow); drawable = new FavoriteImageDrawable(a, color, withShadow, synced);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
cache.put(hash, drawable); cache.put(hash, drawable);
} }
return drawable; return drawable;
} }
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow) {
return getOrCreate(a, color, withShadow, false);
}
public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color) {
return getOrCreate(a, color, false, true);
}
} }

View file

@ -718,6 +718,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point; ? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
} }
public boolean isButtonWaypointEnabled() {
if (menuController != null) {
return menuController.isWaypointButtonEnabled();
}
return true;
}
protected void acquireIcons() { protected void acquireIcons() {
super.acquireIcons(); super.acquireIcons();
if (menuController != null) { if (menuController != null) {

View file

@ -30,9 +30,12 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -459,12 +462,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
!nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark)); !nightMode ? R.color.icon_color : R.color.dashboard_subheader_text_dark));
buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId())); buttonWaypoint.setContentDescription(getString(menu.getWaypointActionStringId()));
AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode); AndroidUtils.setDashButtonBackground(getMapActivity(), buttonWaypoint, nightMode);
buttonWaypoint.setOnClickListener(new View.OnClickListener() { if (menu.isButtonWaypointEnabled()) {
@Override buttonWaypoint.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { @Override
menu.buttonWaypointPressed(); public void onClick(View v) {
} menu.buttonWaypointPressed();
}); }
});
} else {
deactivate(buttonWaypoint);
}
final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button); final ImageButton buttonShare = (ImageButton) view.findViewById(R.id.context_menu_share_button);
buttonShare.setImageDrawable(getIcon(R.drawable.map_action_gshare_dark, buttonShare.setImageDrawable(getIcon(R.drawable.map_action_gshare_dark,
@ -514,6 +521,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
return view; return view;
} }
private void deactivate(View view) {
view.setEnabled(false);
view.setAlpha(0.5f);
}
@Override @Override
public int getStatusBarColorId() { public int getStatusBarColorId() {
if (menu != null && (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout())) { if (menu != null && (menu.getCurrentMenuState() == MenuState.FULL_SCREEN || menu.isLandscapeLayout())) {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu; package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -23,6 +24,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -95,6 +97,7 @@ public abstract class MenuController extends BaseMenuController {
private PointDescription pointDescription; private PointDescription pointDescription;
private LatLon latLon; private LatLon latLon;
private boolean active; private boolean active;
private Drawable showOnTopBarIcon;
protected TitleButtonController leftTitleButtonController; protected TitleButtonController leftTitleButtonController;
protected TitleButtonController rightTitleButtonController; protected TitleButtonController rightTitleButtonController;
@ -311,6 +314,10 @@ public abstract class MenuController extends BaseMenuController {
this.currentMenuState = currentMenuState; this.currentMenuState = currentMenuState;
} }
public void setLeftTitleButtonController(TitleButtonController leftDownloadButtonController) {
this.leftTitleButtonController = leftDownloadButtonController;
}
public TitleButtonController getLeftTitleButtonController() { public TitleButtonController getLeftTitleButtonController() {
return leftTitleButtonController; return leftTitleButtonController;
} }
@ -323,6 +330,10 @@ public abstract class MenuController extends BaseMenuController {
return topRightTitleButtonController; return topRightTitleButtonController;
} }
public void setLeftSubtitleButtonController(TitleButtonController leftSubtitleButtonController) {
this.leftSubtitleButtonController = leftSubtitleButtonController;
}
public TitleButtonController getLeftSubtitleButtonController() { public TitleButtonController getLeftSubtitleButtonController() {
return leftSubtitleButtonController; return leftSubtitleButtonController;
} }
@ -421,6 +432,21 @@ public abstract class MenuController extends BaseMenuController {
? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point; ? R.string.shared_string_add_to_map_markers : R.string.context_menu_item_destination_point;
} }
public boolean isWaypointButtonEnabled() {
return true;
}
public Drawable getShowOnTopBarIcon() {
if (showOnTopBarIcon == null) {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
showOnTopBarIcon = new LayerDrawable(new Drawable[]{background, topbar});
}
return showOnTopBarIcon;
}
public String getTypeStr() { public String getTypeStr() {
return ""; return "";
} }

View file

@ -111,4 +111,4 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
} }
return null; return null;
} }
} }

View file

@ -76,4 +76,3 @@ public class WptPtMenuBuilder extends MenuBuilder {
buildPlainMenuItems(view); buildPlainMenuItems(view);
} }
} }

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.controllers; package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
@ -8,6 +9,9 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
@ -24,6 +28,13 @@ public class FavouritePointMenuController extends MenuController {
public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) { public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) {
super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity); super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity);
this.fav = fav; this.fav = fav;
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
final MapMarker mapMarker = markersHelper.getMapMarker(fav);
if (mapMarker != null) {
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker);
}
} }
@Override @Override
@ -68,6 +79,11 @@ public class FavouritePointMenuController extends MenuController {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), false); return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), fav.getColor(), false);
} }
@Override
public boolean isWaypointButtonEnabled() {
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(fav) == null;
}
@Override @Override
public Drawable getSecondLineTypeIcon() { public Drawable getSecondLineTypeIcon() {
return getIcon(R.drawable.map_small_group); return getIcon(R.drawable.map_small_group);

View file

@ -22,36 +22,7 @@ public class MapMarkerMenuController extends MenuController {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
this.mapMarker = mapMarker; this.mapMarker = mapMarker;
builder.setShowNearestWiki(true); builder.setShowNearestWiki(true);
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); createMarkerButtons(this, mapActivity, mapMarker);
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(getMapMarker());
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
} }
@Override @Override
@ -104,4 +75,31 @@ public class MapMarkerMenuController extends MenuController {
public int getWaypointActionStringId() { public int getWaypointActionStringId() {
return R.string.rename_marker; return R.string.rename_marker;
} }
public static void createMarkerButtons(MenuController menuController, final MapActivity mapActivity, final MapMarker mapMarker) {
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
TitleButtonController leftTitleButtonController = menuController.new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
mapActivity.getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = mapActivity.getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = menuController.isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
menuController.setLeftTitleButtonController(leftTitleButtonController);
TitleButtonController leftSubtitleButtonController = menuController.new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
mapActivity.getContextMenu().close();
}
};
leftSubtitleButtonController.caption = mapActivity.getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = menuController.getShowOnTopBarIcon();
menuController.setLeftSubtitleButtonController(leftSubtitleButtonController);
}
} }

View file

@ -1,10 +1,14 @@
package net.osmand.plus.mapcontextmenu.controllers; package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
@ -19,6 +23,13 @@ public class WptPtMenuController extends MenuController {
public WptPtMenuController(MapActivity mapActivity, PointDescription pointDescription, WptPt wpt) { public WptPtMenuController(MapActivity mapActivity, PointDescription pointDescription, WptPt wpt) {
super(new WptPtMenuBuilder(mapActivity, wpt), pointDescription, mapActivity); super(new WptPtMenuBuilder(mapActivity, wpt), pointDescription, mapActivity);
this.wpt = wpt; this.wpt = wpt;
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
final MapMarker mapMarker = markersHelper.getMapMarker(wpt);
if (mapMarker != null) {
MapMarkerMenuController.createMarkerButtons(this, mapActivity, mapMarker);
}
} }
@Override @Override
@ -70,6 +81,11 @@ public class WptPtMenuController extends MenuController {
} }
} }
@Override
public boolean isWaypointButtonEnabled() {
return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(wpt) == null;
}
@Override @Override
public String getTypeStr() { public String getTypeStr() {
return wpt.category != null ? wpt.category : ""; return wpt.category != null ? wpt.category : "";

View file

@ -13,7 +13,10 @@ import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
@ -60,8 +63,22 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
return; return;
} }
MapMarker marker = adapter.getItem(pos); MapMarker marker = adapter.getItem(pos);
WptPt wptPt = marker.wptPt;
FavouritePoint favouritePoint = marker.favouritePoint;
Object objectToShow;
PointDescription pointDescription;
if (wptPt != null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, wptPt.name);
objectToShow = wptPt;
} else if (favouritePoint != null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, favouritePoint.getName());
objectToShow = favouritePoint;
} else {
pointDescription = marker.getPointDescription(mapActivity);
objectToShow = marker;
}
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker); 15, pointDescription, true, objectToShow);
MapActivity.launchMapActivityMoveToTop(mapActivity); MapActivity.launchMapActivityMoveToTop(mapActivity);
((DialogFragment) getParentFragment()).dismiss(); ((DialogFragment) getParentFragment()).dismiss();
} }

View file

@ -23,8 +23,10 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.MapMarkersHelper; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
@ -70,6 +72,10 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
if (addGroupFragment != null) { if (addGroupFragment != null) {
((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener()); ((AddGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
} }
Fragment historyMarkerMenuFragment = getChildFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
if (historyMarkerMenuFragment != null) {
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
}
final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list); final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
@ -224,10 +230,37 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
Object item = adapter.getItem(pos); Object item = adapter.getItem(pos);
if (item instanceof MapMarker) { if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item; MapMarker marker = (MapMarker) item;
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), if (!marker.history) {
15, marker.getPointDescription(mapActivity), true, marker); WptPt wptPt = marker.wptPt;
MapActivity.launchMapActivityMoveToTop(mapActivity); FavouritePoint favouritePoint = marker.favouritePoint;
((DialogFragment) getParentFragment()).dismiss(); Object objectToShow;
PointDescription pointDescription;
if (wptPt != null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, wptPt.name);
objectToShow = wptPt;
} else if (favouritePoint != null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, favouritePoint.getName());
objectToShow = favouritePoint;
} else {
pointDescription = marker.getPointDescription(mapActivity);
objectToShow = marker;
}
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, pointDescription, true, objectToShow);
MapActivity.launchMapActivityMoveToTop(mapActivity);
((DialogFragment) getParentFragment()).dismiss();
} else {
HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
Bundle arguments = new Bundle();
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
fragment.setArguments(arguments);
fragment.setListener(createHistoryMarkerMenuListener());
fragment.show(getChildFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
}
} }
} }
}); });
@ -277,6 +310,32 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
return mainView; return mainView;
} }
private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() {
return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() {
@Override
public void onMakeMarkerActive(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
if (getMyApplication() != null) {
getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
}
updateAdapter();
}
}
@Override
public void onDeleteMarker(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
if (getMyApplication() != null) {
getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
}
updateAdapter();
}
}
};
}
void setGroupIdToOpen(String groupIdToOpen) { void setGroupIdToOpen(String groupIdToOpen) {
this.groupIdToOpen = groupIdToOpen; this.groupIdToOpen = groupIdToOpen;
} }

View file

@ -20,6 +20,7 @@ import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree; import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
@ -37,6 +38,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
protected OsmandMapTileView view; protected OsmandMapTileView view;
private Paint paint; private Paint paint;
private FavouritesDbHelper favorites; private FavouritesDbHelper favorites;
private MapMarkersHelper mapMarkersHelper;
protected List<FavouritePoint> cache = new ArrayList<>(); protected List<FavouritePoint> cache = new ArrayList<>();
private MapTextLayer textLayer; private MapTextLayer textLayer;
private Paint paintIcon; private Paint paintIcon;
@ -54,7 +56,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
protected List<? extends FavouritePoint> getPoints() { protected List<? extends FavouritePoint> getPoints() {
return favorites.getFavouritePoints(); return favorites.getFavouritePoints();
} }
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
@ -64,6 +66,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
paint.setDither(true); paint.setDither(true);
settings = view.getApplication().getSettings(); settings = view.getApplication().getSettings();
favorites = view.getApplication().getFavorites(); favorites = view.getApplication().getFavorites();
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
textLayer = view.getLayerByClass(MapTextLayer.class); textLayer = view.getLayerByClass(MapTextLayer.class);
paintIcon = new Paint(); paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
@ -93,8 +96,13 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) { if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject(); FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject();
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), FavoriteImageDrawable fid;
objectInMotion.getColor(), true); if (mapMarkersHelper.isSynced(objectInMotion)) {
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), objectInMotion.getColor());
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(),
objectInMotion.getColor(), true);
}
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox); PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
fid.drawBitmapInCenter(canvas, pf.x, pf.y); fid.drawBitmapInCenter(canvas, pf.x, pf.y);
} }
@ -134,7 +142,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
} }
for (FavouritePoint o : fullObjects) { for (FavouritePoint o : fullObjects) {
if (o != contextMenuLayer.getMoveableObject()) { if (o != contextMenuLayer.getMoveableObject()) {
drawPoint(canvas, tileBox, latLonBounds, o); boolean syncedPoint = mapMarkersHelper.isSynced(o);
drawPoint(canvas, tileBox, latLonBounds, o, syncedPoint);
} }
} }
this.fullObjectsLatLon = fullObjectsLatLon; this.fullObjectsLatLon = fullObjectsLatLon;
@ -147,14 +156,18 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
} }
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o, boolean synced) {
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o) {
if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left
&& o.getLongitude() <= latLonBounds.right ) { && o.getLongitude() <= latLonBounds.right ) {
cache.add(o); cache.add(o);
int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); int x = (int) tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true); FavoriteImageDrawable fid;
if (synced) {
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), o.getColor());
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true);
}
fid.drawBitmapInCenter(canvas, x, y); fid.drawBitmapInCenter(canvas, x, y);
} }
} }

View file

@ -35,6 +35,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.CommonPreference;
@ -80,6 +81,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private GpxSelectionHelper selectedGpxHelper; private GpxSelectionHelper selectedGpxHelper;
private MapMarkersHelper mapMarkersHelper;
private Paint paintBmp; private Paint paintBmp;
private List<WptPt> cache = new ArrayList<>(); private List<WptPt> cache = new ArrayList<>();
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>(); private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
@ -108,6 +110,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
selectedGpxHelper = view.getApplication().getSelectedGpxHelper(); selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer(); osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
initUI(); initUI();
} }
@ -179,7 +182,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox); PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
SelectedGpxFile gpxFile = pointFileMap.get(objectInMotion); SelectedGpxFile gpxFile = pointFileMap.get(objectInMotion);
if (gpxFile != null) { if (gpxFile != null) {
drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y); drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y, isSynced(gpxFile));
} }
} }
} }
@ -382,10 +385,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
} }
pointFileMap.put(o, g); pointFileMap.put(o, g);
} }
boolean synced = isSynced(g);
for (WptPt o : fullObjects) { for (WptPt o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.lat, o.lon); float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
float y = tileBox.getPixYFromLatLon(o.lat, o.lon); float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
drawBigPoint(canvas, o, fileColor, x, y); drawBigPoint(canvas, o, fileColor, x, y, synced);
} }
} }
if (trackChartPoints != null) { if (trackChartPoints != null) {
@ -450,9 +454,14 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return g.getColor() == 0 ? defPointColor : g.getColor(); return g.getColor() == 0 ? defPointColor : g.getColor();
} }
private void drawBigPoint(Canvas canvas, WptPt o, int fileColor, float x, float y) { private void drawBigPoint(Canvas canvas, WptPt o, int fileColor, float x, float y, boolean synced) {
int pointColor = getPointColor(o, fileColor); int pointColor = getPointColor(o, fileColor);
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true); FavoriteImageDrawable fid;
if (synced) {
fid = FavoriteImageDrawable.getOrCreateSyncedIcon(view.getContext(), pointColor);
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true);
}
fid.drawBitmapInCenter(canvas, x, y); fid.drawBitmapInCenter(canvas, x, y);
} }
@ -519,6 +528,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return g.getGpxFile().getPoints(); return g.getGpxFile().getPoints();
} }
private boolean isSynced(SelectedGpxFile g) {
return mapMarkersHelper.isSynced(g);
}
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2); return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2);
// return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ;
@ -648,7 +661,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
File gpx = new File(gpxFile.path); File gpx = new File(gpxFile.path);
if (gpx.exists()) { if (gpx.exists()) {
view.getApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(), mapMarkersHelper.syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE)); AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
} }
} }

View file

@ -34,6 +34,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback; import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
@ -326,7 +327,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
for (MapMarker marker : markersHelper.getMapMarkers()) { for (MapMarker marker : markersHelper.getMapMarkers()) {
if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker) if (isLocationVisible(tileBox, marker) && !overlappedByWaypoint(marker)
&& !isInMotion(marker)) { && !isInMotion(marker) && !isSynced(marker)) {
Bitmap bmp = getMapMarkerBitmap(marker.colorIndex); Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
int marginX = bmp.getWidth() / 6; int marginX = bmp.getWidth() / 6;
int marginY = bmp.getHeight(); int marginY = bmp.getHeight();
@ -365,17 +366,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
if (contextMenuLayer.getMoveableObject() instanceof MapMarker) { if (contextMenuLayer.getMoveableObject() instanceof MapMarker) {
MapMarker objectInMotion = (MapMarker) contextMenuLayer.getMoveableObject(); MapMarker objectInMotion = (MapMarker) contextMenuLayer.getMoveableObject();
Bitmap bitmap = getMapMarkerBitmap(objectInMotion.colorIndex);
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox); PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
Bitmap bitmap = getMapMarkerBitmap(objectInMotion.colorIndex);
int marginX = bitmap.getWidth() / 6; int marginX = bitmap.getWidth() / 6;
int marginY = bitmap.getHeight(); int marginY = bitmap.getHeight();
float locationX = pf.x; float locationX = pf.x;
float locationY = pf.y; float locationY = pf.y;
canvas.rotate(-tileBox.getRotate(), locationX, locationY); canvas.rotate(-tileBox.getRotate(), locationX, locationY);
canvas.drawBitmap(bitmap, locationX - marginX, locationY - marginY, bitmapPaint); canvas.drawBitmap(bitmap, locationX - marginX, locationY - marginY, bitmapPaint);
} }
} }
private boolean isSynced(@NonNull MapMarker marker) {
return marker.wptPt != null || marker.favouritePoint != null;
}
private boolean isInMotion(@NonNull MapMarker marker) { private boolean isInMotion(@NonNull MapMarker marker) {
return marker.equals(contextMenuLayer.getMoveableObject()); return marker.equals(contextMenuLayer.getMoveableObject());
} }
@ -515,14 +521,16 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
int r = getRadiusPoi(tileBox); int r = getRadiusPoi(tileBox);
for (int i = 0; i < markers.size(); i++) { for (int i = 0; i < markers.size(); i++) {
MapMarker marker = markers.get(i); MapMarker marker = markers.get(i);
LatLon latLon = marker.point; if (!isSynced(marker)) {
if (latLon != null) { LatLon latLon = marker.point;
int ex = (int) point.x; if (latLon != null) {
int ey = (int) point.y; int ex = (int) point.x;
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int ey = (int) point.y;
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) { int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
o.add(marker); if (calculateBelongs(ex, ey, x, y, r)) {
o.add(marker);
}
} }
} }
} }