Added my location to map markers list
This commit is contained in:
parent
aba5f639a7
commit
bb9c30780a
5 changed files with 150 additions and 19 deletions
|
@ -21,6 +21,7 @@ public class MapMarkersHelper {
|
|||
private OsmandSettings settings;
|
||||
private List<MapMarkerChangedListener> listeners = new ArrayList<>();
|
||||
private OsmandApplication ctx;
|
||||
private boolean startFromMyLocation;
|
||||
|
||||
public interface MapMarkerChangedListener {
|
||||
void onMapMarkerChanged(MapMarker mapMarker);
|
||||
|
@ -87,6 +88,14 @@ public class MapMarkersHelper {
|
|||
readFromSettings();
|
||||
}
|
||||
|
||||
public boolean isStartFromMyLocation() {
|
||||
return startFromMyLocation;
|
||||
}
|
||||
|
||||
public void setStartFromMyLocation(boolean startFromMyLocation) {
|
||||
this.startFromMyLocation = startFromMyLocation;
|
||||
}
|
||||
|
||||
private void readFromSettings() {
|
||||
mapMarkers.clear();
|
||||
mapMarkersHistory.clear();
|
||||
|
|
|
@ -721,6 +721,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
|
||||
mapActivity.disableDrawer();
|
||||
dashboardView.setVisibility(View.VISIBLE);
|
||||
if (visibleType == DashboardType.MAP_MARKERS || previousVisibleType == DashboardType.MAP_MARKERS_SELECTION) {
|
||||
if (mapActivity.getMapLayers().getMapMarkersLayer().clearRoute()) {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
if (isActionButtonVisible()) {
|
||||
setActionButton(visibleType);
|
||||
actionButton.setVisibility(View.VISIBLE);
|
||||
|
@ -1394,9 +1399,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
} else if (visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS_SELECTION) {
|
||||
List<MapMarker> markers = (List<MapMarker>) (Object) items;
|
||||
getMyApplication().getMapMarkersHelper().saveMapMarkers(markers, null);
|
||||
if (visibleType == DashboardType.MAP_MARKERS_SELECTION) {
|
||||
showMarkersRouteOnMap();
|
||||
}
|
||||
reloadAdapter();
|
||||
}
|
||||
|
||||
if (swipeDismissListener != null) {
|
||||
|
@ -1472,6 +1475,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
OsmandMapTileView mapView = mapActivity.getMapView();
|
||||
double left = 0, right = 0;
|
||||
double top = 0, bottom = 0;
|
||||
if (getMyApplication().getMapMarkersHelper().isStartFromMyLocation() && myLocation != null) {
|
||||
left = myLocation.getLongitude();
|
||||
right = myLocation.getLongitude();
|
||||
top = myLocation.getLatitude();
|
||||
bottom = myLocation.getLatitude();
|
||||
}
|
||||
for (LatLon l : points) {
|
||||
if (left == 0) {
|
||||
left = l.getLongitude();
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
|
@ -56,7 +57,8 @@ import java.util.Locale;
|
|||
|
||||
public class MapMarkerDialogHelper {
|
||||
public static final int ACTIVE_MARKERS = 0;
|
||||
public static final int MARKERS_HISTORY = 1;
|
||||
public static final int MY_LOCATION = 10;
|
||||
public static final int MARKERS_HISTORY = 100;
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private OsmandApplication app;
|
||||
|
@ -67,6 +69,7 @@ public class MapMarkerDialogHelper {
|
|||
private boolean selectionMode;
|
||||
|
||||
private boolean useCenter;
|
||||
private LatLon myLoc;
|
||||
private LatLon loc;
|
||||
private Float heading;
|
||||
private int screenOrientation;
|
||||
|
@ -76,7 +79,9 @@ public class MapMarkerDialogHelper {
|
|||
|
||||
public interface MapMarkersDialogHelperCallbacks {
|
||||
void reloadAdapter();
|
||||
|
||||
void deleteMapMarker(int position);
|
||||
|
||||
void showMarkersRouteOnMap();
|
||||
}
|
||||
|
||||
|
@ -136,6 +141,13 @@ public class MapMarkerDialogHelper {
|
|||
showHistoryOnMap(marker);
|
||||
}
|
||||
}
|
||||
} else if (obj instanceof Integer && (Integer) obj == MY_LOCATION && selectionMode) {
|
||||
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
checkBox.setChecked(!checkBox.isChecked());
|
||||
markersHelper.setStartFromMyLocation(checkBox.isChecked());
|
||||
if (helperCallbacks != null) {
|
||||
helperCallbacks.showMarkersRouteOnMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -169,7 +181,8 @@ public class MapMarkerDialogHelper {
|
|||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
Object obj = getItem(position);
|
||||
return obj instanceof MapMarker;
|
||||
return obj instanceof MapMarker
|
||||
|| (obj instanceof Integer && (Integer) obj == MY_LOCATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -181,7 +194,11 @@ public class MapMarkerDialogHelper {
|
|||
boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
|
||||
boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
|
||||
if (labelView) {
|
||||
v = createItemForCategory(this, (Integer) obj);
|
||||
if ((Integer) obj == MY_LOCATION) {
|
||||
v = updateMyLocationView(v);
|
||||
} else {
|
||||
v = createItemForCategory(this, (Integer) obj);
|
||||
}
|
||||
AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
|
||||
} else if (topDividerView) {
|
||||
v = mapActivity.getLayoutInflater().inflate(R.layout.card_top_divider, null);
|
||||
|
@ -301,6 +318,7 @@ public class MapMarkerDialogHelper {
|
|||
for (MapMarker marker : markers) {
|
||||
marker.selected = !allSelected;
|
||||
}
|
||||
markersHelper.setStartFromMyLocation(!allSelected);
|
||||
allSelected = !allSelected;
|
||||
if (helperCallbacks != null) {
|
||||
helperCallbacks.reloadAdapter();
|
||||
|
@ -392,8 +410,8 @@ public class MapMarkerDialogHelper {
|
|||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
updateMapMarkerInfoView(mapActivity, v, loc, heading, useCenter, nightMode, screenOrientation,
|
||||
selectionMode, marker);
|
||||
updateMapMarkerInfo(mapActivity, v, loc, heading, useCenter, nightMode, screenOrientation,
|
||||
selectionMode, helperCallbacks, 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);
|
||||
|
@ -434,10 +452,11 @@ public class MapMarkerDialogHelper {
|
|||
return v;
|
||||
}
|
||||
|
||||
public static void updateMapMarkerInfoView(Context ctx, View localView, LatLon loc,
|
||||
Float heading, boolean useCenter, boolean nightMode,
|
||||
int screenOrientation, boolean selectionMode,
|
||||
final MapMarker marker) {
|
||||
public static void updateMapMarkerInfo(final Context ctx, View localView, LatLon loc,
|
||||
Float heading, boolean useCenter, boolean nightMode,
|
||||
int screenOrientation, boolean selectionMode,
|
||||
final MapMarkersDialogHelperCallbacks helperCallbacks,
|
||||
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);
|
||||
|
@ -523,6 +542,11 @@ public class MapMarkerDialogHelper {
|
|||
public void onClick(View v) {
|
||||
marker.selected = checkBox.isChecked();
|
||||
app.getMapMarkersHelper().updateMapMarker(marker, false);
|
||||
if (helperCallbacks != null) {
|
||||
helperCallbacks.showMarkersRouteOnMap();
|
||||
} else if (ctx instanceof MapActivity) {
|
||||
((MapActivity) ctx).refreshMap();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -587,6 +611,73 @@ public class MapMarkerDialogHelper {
|
|||
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
|
||||
}
|
||||
|
||||
protected View updateMyLocationView(View v) {
|
||||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
updateMyLocationInfo(mapActivity, v, nightMode, selectionMode, helperCallbacks);
|
||||
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);
|
||||
more.setVisibility(View.GONE);
|
||||
move.setVisibility(View.GONE);
|
||||
move.setTag(null);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void updateMyLocationInfo(final Context ctx, View localView, boolean nightMode,
|
||||
boolean selectionMode,
|
||||
final MapMarkersDialogHelperCallbacks helperCallbacks) {
|
||||
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
|
||||
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);
|
||||
final CheckBox checkBox = (CheckBox) localView.findViewById(R.id.checkbox);
|
||||
|
||||
if (text == null || textDist == null || arrow == null || waypointIcon == null
|
||||
|| waypointDeviation == null || descText == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
arrow.setVisibility(View.GONE);
|
||||
textDist.setVisibility(View.GONE);
|
||||
waypointDeviation.setVisibility(View.GONE);
|
||||
|
||||
final OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
|
||||
|
||||
ApplicationMode appMode = app.getSettings().getApplicationMode();
|
||||
waypointIcon.setImageDrawable(ctx.getResources().getDrawable(appMode.getResourceLocationDay()));
|
||||
|
||||
text.setText(ctx.getString(R.string.shared_string_my_location));
|
||||
descText.setText(ctx.getResources().getString(R.string.starting_point));
|
||||
descText.setVisibility(View.VISIBLE);
|
||||
|
||||
AndroidUtils.setTextPrimaryColor(ctx, text, nightMode);
|
||||
AndroidUtils.setTextSecondaryColor(ctx, descText, nightMode);
|
||||
|
||||
if (selectionMode) {
|
||||
checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
|
||||
checkBox.setVisibility(View.VISIBLE);
|
||||
checkBox.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getMapMarkersHelper().setStartFromMyLocation(checkBox.isChecked());
|
||||
if (helperCallbacks != null) {
|
||||
helperCallbacks.showMarkersRouteOnMap();
|
||||
} else if (ctx instanceof MapActivity) {
|
||||
((MapActivity) ctx).refreshMap();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
checkBox.setVisibility(View.GONE);
|
||||
checkBox.setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showMarkerOnMap(MapActivity mapActivity, MapMarker marker) {
|
||||
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
|
||||
15, marker.getPointDescription(mapActivity), true, marker);
|
||||
|
@ -654,6 +745,9 @@ public class MapMarkerDialogHelper {
|
|||
}
|
||||
if (activeMarkers.size() > 0) {
|
||||
objects.add(ACTIVE_MARKERS);
|
||||
if (selectionMode) {
|
||||
objects.add(MY_LOCATION);
|
||||
}
|
||||
objects.addAll(activeMarkers);
|
||||
objects.add(false);
|
||||
}
|
||||
|
@ -727,6 +821,7 @@ public class MapMarkerDialogHelper {
|
|||
lastUpdateTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
LatLon prevMyLoc = myLoc;
|
||||
calculateLocationParams();
|
||||
|
||||
for (int i = listView.getFirstVisiblePosition(); i <= listView.getLastVisiblePosition(); i++) {
|
||||
|
@ -736,6 +831,14 @@ public class MapMarkerDialogHelper {
|
|||
updateMapMarkerArrowDistanceView(v, (MapMarker) obj);
|
||||
}
|
||||
}
|
||||
|
||||
if (markersHelper.isStartFromMyLocation() && prevMyLoc == null && myLoc != null) {
|
||||
if (helperCallbacks != null) {
|
||||
helperCallbacks.showMarkersRouteOnMap();
|
||||
} else {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
@ -746,8 +849,8 @@ public class MapMarkerDialogHelper {
|
|||
Object obj = listView.getItemAtPosition(i);
|
||||
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
|
||||
if (obj == marker) {
|
||||
updateMapMarkerInfoView(mapActivity, v, loc, heading, useCenter, nightMode,
|
||||
screenOrientation, selectionMode, marker);
|
||||
updateMapMarkerInfo(mapActivity, v, loc, heading, useCenter, nightMode,
|
||||
screenOrientation, selectionMode, helperCallbacks, marker);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -765,7 +868,7 @@ public class MapMarkerDialogHelper {
|
|||
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());
|
||||
myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
|
||||
useCenter = !mapLinked;
|
||||
loc = (useCenter ? mw : myLoc);
|
||||
heading = useCenter ? -mapRotation : head;
|
||||
|
|
|
@ -123,8 +123,8 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment {
|
|||
if (convertView == null) {
|
||||
convertView = getMapActivity().getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
MapMarkerDialogHelper.updateMapMarkerInfoView(getContext(), convertView, loc, heading,
|
||||
useCenter, nightMode, screenOrientation, false, marker);
|
||||
MapMarkerDialogHelper.updateMapMarkerInfo(getContext(), convertView, loc, heading,
|
||||
useCenter, nightMode, screenOrientation, false, null, marker);
|
||||
final View remove = convertView.findViewById(R.id.info_close);
|
||||
remove.setVisibility(View.GONE);
|
||||
AndroidUtils.setListItemBackground(getMapActivity(), convertView, nightMode);
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.Message;
|
|||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadPoint;
|
||||
|
@ -169,8 +170,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
route.addAll(points);
|
||||
}
|
||||
|
||||
public void clearRoute() {
|
||||
public boolean clearRoute() {
|
||||
boolean res = route.size() > 0;
|
||||
route.clear();
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -220,9 +223,17 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
return;
|
||||
}
|
||||
|
||||
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
|
||||
if (route.size() > 0) {
|
||||
path.reset();
|
||||
boolean first = true;
|
||||
Location myLocation = map.getMapViewTrackingUtilities().getMyLocation();
|
||||
if (markersHelper.isStartFromMyLocation() && myLocation != null) {
|
||||
int locationX = tb.getPixXFromLonNoRot(myLocation.getLongitude());
|
||||
int locationY = tb.getPixYFromLatNoRot(myLocation.getLatitude());
|
||||
path.moveTo(locationX, locationY);
|
||||
first = false;
|
||||
}
|
||||
for (LatLon point : route) {
|
||||
int locationX = tb.getPixXFromLonNoRot(point.getLongitude());
|
||||
int locationY = tb.getPixYFromLatNoRot(point.getLatitude());
|
||||
|
@ -236,7 +247,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
|
|||
canvas.drawPath(path, paint);
|
||||
}
|
||||
|
||||
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
|
||||
List<MapMarker> activeMapMarkers = markersHelper.getActiveMapMarkers();
|
||||
for (int i = 0; i < activeMapMarkers.size(); i++) {
|
||||
MapMarker marker = activeMapMarkers.get(i);
|
||||
|
|
Loading…
Reference in a new issue