Markers in process
This commit is contained in:
parent
51aa200990
commit
7d11782d56
6 changed files with 181 additions and 54 deletions
|
@ -9,6 +9,7 @@
|
|||
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="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>
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.List;
|
|||
|
||||
public class MapMarkersHelper {
|
||||
public static final int MAP_MARKERS_COLORS_COUNT = 5;
|
||||
public static final int MAP_MARKERS_HISTORY_LIMIT = 30;
|
||||
|
||||
private List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
private List<MapMarker> mapMarkersHistory = new ArrayList<>();
|
||||
|
@ -30,12 +29,7 @@ public class MapMarkersHelper {
|
|||
private PointDescription pointDescription;
|
||||
public int colorIndex;
|
||||
public int index;
|
||||
|
||||
public MapMarker(LatLon point, PointDescription name, int colorIndex) {
|
||||
this.point = point;
|
||||
this.pointDescription = name;
|
||||
this.colorIndex = colorIndex;
|
||||
}
|
||||
public boolean history;
|
||||
|
||||
public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) {
|
||||
this.point = point;
|
||||
|
@ -61,13 +55,6 @@ public class MapMarkersHelper {
|
|||
return pointDescription != null && pointDescription.isSearchingAddress(ctx);
|
||||
}
|
||||
|
||||
public static MapMarker create(LatLon point, PointDescription name, int color) {
|
||||
if (point != null) {
|
||||
return new MapMarker(point, name, color);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return point.getLatitude();
|
||||
}
|
||||
|
@ -76,10 +63,6 @@ public class MapMarkersHelper {
|
|||
return point.getLongitude();
|
||||
}
|
||||
|
||||
public int getColorIndex() {
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return 0;
|
||||
|
@ -105,7 +88,7 @@ public class MapMarkersHelper {
|
|||
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
|
||||
List<Integer> colors = settings.getMapMarkersColors(ips.size());
|
||||
for (int i = 0; i < ips.size(); i++) {
|
||||
final MapMarker mapMarker = new MapMarker(ips.get(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);
|
||||
|
@ -114,8 +97,9 @@ public class MapMarkersHelper {
|
|||
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
|
||||
colors = settings.getMapMarkersHistoryColors(ips.size());
|
||||
for (int i = 0; i < ips.size(); i++) {
|
||||
final MapMarker mapMarker = new MapMarker(ips.get(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);
|
||||
}
|
||||
|
@ -162,7 +146,7 @@ public class MapMarkersHelper {
|
|||
}
|
||||
|
||||
public List<LatLon> getActiveMarkersLatLon() {
|
||||
List<LatLon> list = new ArrayList<LatLon>();
|
||||
List<LatLon> list = new ArrayList<>();
|
||||
for (MapMarker m : this.mapMarkers) {
|
||||
list.add(m.point);
|
||||
}
|
||||
|
@ -170,7 +154,7 @@ public class MapMarkersHelper {
|
|||
}
|
||||
|
||||
public List<LatLon> getMarkersHistoryLatLon() {
|
||||
List<LatLon> list = new ArrayList<LatLon>();
|
||||
List<LatLon> list = new ArrayList<>();
|
||||
for (MapMarker m : this.mapMarkersHistory) {
|
||||
list.add(m.point);
|
||||
}
|
||||
|
@ -195,7 +179,7 @@ public class MapMarkersHelper {
|
|||
refresh();
|
||||
}
|
||||
|
||||
public void addMapMarker(final LatLon point, PointDescription historyName) {
|
||||
public void addMapMarker(LatLon point, PointDescription historyName) {
|
||||
if (point != null) {
|
||||
final PointDescription pointDescription;
|
||||
if (historyName == null) {
|
||||
|
@ -214,9 +198,65 @@ public class MapMarkersHelper {
|
|||
}
|
||||
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();
|
||||
}
|
||||
readFromSettings();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void addListener(StateChangedListener<Void> l) {
|
||||
|
|
|
@ -1483,6 +1483,7 @@ public class OsmandSettings {
|
|||
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();
|
||||
|
||||
|
@ -1562,6 +1563,16 @@ public class OsmandSettings {
|
|||
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 {
|
||||
|
|
|
@ -110,7 +110,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
public void addMapMarker(double latitude, double longitude, PointDescription pd) {
|
||||
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
|
||||
openMapMarkersActivity();
|
||||
//openMapMarkersActivity();
|
||||
}
|
||||
|
||||
public void editWaypoints() {
|
||||
|
@ -572,7 +572,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
return true;
|
||||
}
|
||||
}).reg();
|
||||
optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_waypoint)
|
||||
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) {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.Shape;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -50,6 +52,9 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
((DynamicListView) getListView()).setDynamicListViewCallbacks(this);
|
||||
swipeDismissListener = new SwipeDismissListViewTouchListener(getListView(),
|
||||
new SwipeDismissListViewTouchListener.DismissCallbacks() {
|
||||
|
||||
private List<Object> deletedMarkers = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean canDismiss(int position) {
|
||||
List<Object> activeObjects = getListAdapter().getActiveObjects();
|
||||
|
@ -59,42 +64,72 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
|
||||
@Override
|
||||
public SwipeDismissListViewTouchListener.Undoable onDismiss(final int position) {
|
||||
final Object item;
|
||||
final StableArrayAdapter stableAdapter = getListAdapter();
|
||||
final int activeObjPos;
|
||||
item = stableAdapter.getItem(position);
|
||||
final Object item = stableAdapter.getItem(position);
|
||||
if (item != null) {
|
||||
if (!((MapMarker) item).history) {
|
||||
deletedMarkers.add(item);
|
||||
}
|
||||
|
||||
stableAdapter.setNotifyOnChange(false);
|
||||
stableAdapter.remove(item);
|
||||
stableAdapter.getObjects().remove(item);
|
||||
activeObjPos = stableAdapter.getActiveObjects().indexOf(item);
|
||||
stableAdapter.getActiveObjects().remove(item);
|
||||
stableAdapter.refreshData();
|
||||
stableAdapter.notifyDataSetChanged();
|
||||
stableAdapter.setNotifyOnChange(false);
|
||||
stableAdapter.remove(item);
|
||||
stableAdapter.getObjects().remove(item);
|
||||
activeObjPos = stableAdapter.getActiveObjects().indexOf(item);
|
||||
stableAdapter.getActiveObjects().remove(item);
|
||||
stableAdapter.refreshData();
|
||||
stableAdapter.notifyDataSetChanged();
|
||||
|
||||
return new SwipeDismissListViewTouchListener.Undoable() {
|
||||
@Override
|
||||
public void undo() {
|
||||
if (item != null) {
|
||||
return new SwipeDismissListViewTouchListener.Undoable() {
|
||||
@Override
|
||||
public void undo() {
|
||||
stableAdapter.setNotifyOnChange(false);
|
||||
stableAdapter.insert(item, position);
|
||||
stableAdapter.getObjects().add(position, item);
|
||||
stableAdapter.getActiveObjects().add(activeObjPos, item);
|
||||
stableAdapter.refreshData();
|
||||
deletedMarkers.remove(item);
|
||||
updateMapMarkers(stableAdapter.getActiveObjects());
|
||||
reloadListAdapter();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHidePopup() {
|
||||
StableArrayAdapter stableAdapter = getListAdapter();
|
||||
stableAdapter.refreshData();
|
||||
// do delete
|
||||
updateMapMarkers(stableAdapter.getActiveObjects());
|
||||
if (stableAdapter.getActiveObjects().size() == 0) {
|
||||
finish();
|
||||
} else {
|
||||
reloadListAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
//nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
|
@ -102,6 +137,16 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
setListAdapter(getMapMarkersListAdapter());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (nightMode) {
|
||||
getListView().setBackgroundColor(getResources().getColor(R.color.ctx_menu_info_view_bg_dark));
|
||||
} else {
|
||||
getListView().setBackgroundColor(getResources().getColor(R.color.ctx_menu_info_view_bg_light));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StableArrayAdapter getListAdapter() {
|
||||
return (StableArrayAdapter) super.getListAdapter();
|
||||
|
@ -111,7 +156,12 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object obj = getListAdapter().getItem(position);
|
||||
if (obj instanceof MapMarker) {
|
||||
showOnMap((MapMarker) obj);
|
||||
MapMarker marker = (MapMarker) obj;
|
||||
if (!marker.history) {
|
||||
showOnMap(marker);
|
||||
} else {
|
||||
showHistoryOnMap(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,9 +297,18 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
btn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getListAdapter().notifyDataSetInvalidated();
|
||||
getMyApplication().getMapMarkersHelper().removeMarkersHistory();
|
||||
reloadListAdapter();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MapMarkersActivity.this);
|
||||
builder.setMessage(getString(R.string.clear_markers_history_q))
|
||||
.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getListAdapter().notifyDataSetInvalidated();
|
||||
getMyApplication().getMapMarkersHelper().removeMarkersHistory();
|
||||
reloadListAdapter();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.shared_string_no, null)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -277,11 +336,20 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
protected void updateMapMarkerInfoView(View localView, final MapMarker marker) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
|
||||
AndroidUtils.setTextPrimaryColor(this, text, nightMode);
|
||||
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
|
||||
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
|
||||
((ImageView) localView.findViewById(R.id.waypoint_icon))
|
||||
.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
|
||||
if (!marker.history) {
|
||||
((ImageView) localView.findViewById(R.id.waypoint_icon))
|
||||
.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
|
||||
AndroidUtils.setTextPrimaryColor(this, text, nightMode);
|
||||
textDist.setTextColor(getResources().getColor(R.color.color_myloc_distance));
|
||||
} else {
|
||||
((ImageView) localView.findViewById(R.id.waypoint_icon))
|
||||
.setImageDrawable(getMyApplication().getIconsCache()
|
||||
.getContentIcon(R.drawable.ic_action_flag_dark, !nightMode));
|
||||
AndroidUtils.setTextSecondaryColor(this, text, nightMode);
|
||||
AndroidUtils.setTextSecondaryColor(this, textDist, nightMode);
|
||||
}
|
||||
|
||||
LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation();
|
||||
int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(),
|
||||
|
@ -335,6 +403,13 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
MapActivity.launchMapActivityMoveToTop(this);
|
||||
}
|
||||
|
||||
public void showHistoryOnMap(MapMarker marker) {
|
||||
getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
|
||||
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION, marker.getPointDescription(this).getName()),
|
||||
false, null);
|
||||
MapActivity.launchMapActivityMoveToTop(this);
|
||||
}
|
||||
|
||||
protected String getHeader(int type) {
|
||||
String str = getString(R.string.map_markers);
|
||||
switch (type) {
|
||||
|
@ -358,6 +433,10 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
|
|||
}
|
||||
listAdapter.updateObjects(objects, getActiveObjects(objects));
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
||||
DynamicListView dynamicListView = (DynamicListView) getListView();
|
||||
dynamicListView.setItemsList(listAdapter.getObjects());
|
||||
dynamicListView.setActiveItemsList(listAdapter.getActiveObjects());
|
||||
}
|
||||
|
||||
protected List<Object> getListObjects() {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue