Markers in process

This commit is contained in:
Alexey Kulish 2016-02-07 19:59:04 +03:00
parent 51aa200990
commit 7d11782d56
6 changed files with 181 additions and 54 deletions

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 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="active_markers">Active markers</string>
<string name="map_markers">Map markers</string> <string name="map_markers">Map markers</string>
<string name="map_marker">Map marker</string> <string name="map_marker">Map marker</string>

View file

@ -17,7 +17,6 @@ import java.util.List;
public class MapMarkersHelper { public class MapMarkersHelper {
public static final int MAP_MARKERS_COLORS_COUNT = 5; 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> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
@ -30,12 +29,7 @@ public class MapMarkersHelper {
private PointDescription pointDescription; private PointDescription pointDescription;
public int colorIndex; public int colorIndex;
public int index; public int index;
public boolean history;
public MapMarker(LatLon point, PointDescription name, int colorIndex) {
this.point = point;
this.pointDescription = name;
this.colorIndex = colorIndex;
}
public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) { public MapMarker(LatLon point, PointDescription name, int colorIndex, int index) {
this.point = point; this.point = point;
@ -61,13 +55,6 @@ public class MapMarkersHelper {
return pointDescription != null && pointDescription.isSearchingAddress(ctx); 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() { public double getLatitude() {
return point.getLatitude(); return point.getLatitude();
} }
@ -76,10 +63,6 @@ public class MapMarkersHelper {
return point.getLongitude(); return point.getLongitude();
} }
public int getColorIndex() {
return colorIndex;
}
@Override @Override
public int getColor() { public int getColor() {
return 0; return 0;
@ -105,7 +88,7 @@ public class MapMarkersHelper {
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size()); List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size()); List<Integer> colors = settings.getMapMarkersColors(ips.size());
for (int i = 0; i < ips.size(); i++) { 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); PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
mapMarkers.add(mapMarker); mapMarkers.add(mapMarker);
lookupAddress(mapMarker, false); lookupAddress(mapMarker, false);
@ -114,8 +97,9 @@ public class MapMarkersHelper {
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size()); desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size()); colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) { 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); PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colors.get(i), i);
mapMarker.history = true;
mapMarkersHistory.add(mapMarker); mapMarkersHistory.add(mapMarker);
lookupAddress(mapMarker, true); lookupAddress(mapMarker, true);
} }
@ -162,7 +146,7 @@ public class MapMarkersHelper {
} }
public List<LatLon> getActiveMarkersLatLon() { public List<LatLon> getActiveMarkersLatLon() {
List<LatLon> list = new ArrayList<LatLon>(); List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkers) { for (MapMarker m : this.mapMarkers) {
list.add(m.point); list.add(m.point);
} }
@ -170,7 +154,7 @@ public class MapMarkersHelper {
} }
public List<LatLon> getMarkersHistoryLatLon() { public List<LatLon> getMarkersHistoryLatLon() {
List<LatLon> list = new ArrayList<LatLon>(); List<LatLon> list = new ArrayList<>();
for (MapMarker m : this.mapMarkersHistory) { for (MapMarker m : this.mapMarkersHistory) {
list.add(m.point); list.add(m.point);
} }
@ -195,7 +179,7 @@ public class MapMarkersHelper {
refresh(); refresh();
} }
public void addMapMarker(final LatLon point, PointDescription historyName) { public void addMapMarker(LatLon point, PointDescription historyName) {
if (point != null) { if (point != null) {
final PointDescription pointDescription; final PointDescription pointDescription;
if (historyName == null) { if (historyName == null) {
@ -214,10 +198,66 @@ public class MapMarkersHelper {
} }
settings.insertMapMarker(point.getLatitude(), point.getLongitude(), settings.insertMapMarker(point.getLatitude(), point.getLongitude(),
pointDescription, colorIndex, mapMarkers.size()); pointDescription, colorIndex, mapMarkers.size());
}
readFromSettings(); readFromSettings();
refresh(); 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(StateChangedListener<Void> l) { public void addListener(StateChangedListener<Void> l) {
listeners.add(l); listeners.add(l);

View file

@ -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_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_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 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 MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage(); private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
@ -1562,6 +1563,16 @@ public class OsmandSettings {
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION; descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
colorsKey = MAP_MARKERS_HISTORY_COLOR; 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 { private class MapMarkersStorage extends MapPointsStorage {

View file

@ -110,7 +110,7 @@ public class MapActivityActions implements DialogProvider {
public void addMapMarker(double latitude, double longitude, PointDescription pd) { public void addMapMarker(double latitude, double longitude, PointDescription pd) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd); markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
openMapMarkersActivity(); //openMapMarkersActivity();
} }
public void editWaypoints() { public void editWaypoints() {
@ -572,7 +572,7 @@ public class MapActivityActions implements DialogProvider {
return true; return true;
} }
}).reg(); }).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() { .listen(new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {

View file

@ -1,9 +1,11 @@
package net.osmand.plus.activities; package net.osmand.plus.activities;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape; import android.graphics.drawable.shapes.Shape;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -50,6 +52,9 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
((DynamicListView) getListView()).setDynamicListViewCallbacks(this); ((DynamicListView) getListView()).setDynamicListViewCallbacks(this);
swipeDismissListener = new SwipeDismissListViewTouchListener(getListView(), swipeDismissListener = new SwipeDismissListViewTouchListener(getListView(),
new SwipeDismissListViewTouchListener.DismissCallbacks() { new SwipeDismissListViewTouchListener.DismissCallbacks() {
private List<Object> deletedMarkers = new ArrayList<>();
@Override @Override
public boolean canDismiss(int position) { public boolean canDismiss(int position) {
List<Object> activeObjects = getListAdapter().getActiveObjects(); List<Object> activeObjects = getListAdapter().getActiveObjects();
@ -59,10 +64,13 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
@Override @Override
public SwipeDismissListViewTouchListener.Undoable onDismiss(final int position) { public SwipeDismissListViewTouchListener.Undoable onDismiss(final int position) {
final Object item;
final StableArrayAdapter stableAdapter = getListAdapter(); final StableArrayAdapter stableAdapter = getListAdapter();
final int activeObjPos; 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.setNotifyOnChange(false);
stableAdapter.remove(item); stableAdapter.remove(item);
@ -75,26 +83,53 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
return new SwipeDismissListViewTouchListener.Undoable() { return new SwipeDismissListViewTouchListener.Undoable() {
@Override @Override
public void undo() { public void undo() {
if (item != null) {
stableAdapter.setNotifyOnChange(false); stableAdapter.setNotifyOnChange(false);
stableAdapter.insert(item, position); stableAdapter.insert(item, position);
stableAdapter.getObjects().add(position, item); stableAdapter.getObjects().add(position, item);
stableAdapter.getActiveObjects().add(activeObjPos, item); stableAdapter.getActiveObjects().add(activeObjPos, item);
stableAdapter.refreshData(); stableAdapter.refreshData();
} deletedMarkers.remove(item);
updateMapMarkers(stableAdapter.getActiveObjects());
reloadListAdapter();
} }
}; };
} else {
return null;
}
} }
@Override @Override
public void onHidePopup() { public void onHidePopup() {
StableArrayAdapter stableAdapter = getListAdapter(); StableArrayAdapter stableAdapter = getListAdapter();
stableAdapter.refreshData(); stableAdapter.refreshData();
// do delete updateMapMarkers(stableAdapter.getActiveObjects());
if (stableAdapter.getActiveObjects().size() == 0) { if (stableAdapter.getActiveObjects().size() == 0) {
finish(); 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(); //nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
@ -102,6 +137,16 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
setListAdapter(getMapMarkersListAdapter()); 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 @Override
public StableArrayAdapter getListAdapter() { public StableArrayAdapter getListAdapter() {
return (StableArrayAdapter) super.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) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object obj = getListAdapter().getItem(position); Object obj = getListAdapter().getItem(position);
if (obj instanceof MapMarker) { if (obj instanceof MapMarker) {
showOnMap((MapMarker) obj); MapMarker marker = (MapMarker) obj;
if (!marker.history) {
showOnMap(marker);
} else {
showHistoryOnMap(marker);
}
} }
} }
@ -247,10 +297,19 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
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(); getListAdapter().notifyDataSetInvalidated();
getMyApplication().getMapMarkersHelper().removeMarkersHistory(); getMyApplication().getMapMarkersHelper().removeMarkersHistory();
reloadListAdapter(); 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) { protected void updateMapMarkerInfoView(View localView, final MapMarker marker) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
TextView text = (TextView) localView.findViewById(R.id.waypoint_text); 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 textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
if (!marker.history) {
((ImageView) localView.findViewById(R.id.waypoint_icon)) ((ImageView) localView.findViewById(R.id.waypoint_icon))
.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex)); .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(); LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(), int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(),
@ -335,6 +403,13 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
MapActivity.launchMapActivityMoveToTop(this); 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) { protected String getHeader(int type) {
String str = getString(R.string.map_markers); String str = getString(R.string.map_markers);
switch (type) { switch (type) {
@ -358,6 +433,10 @@ public class MapMarkersActivity extends OsmandListActivity implements DynamicLis
} }
listAdapter.updateObjects(objects, getActiveObjects(objects)); listAdapter.updateObjects(objects, getActiveObjects(objects));
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
DynamicListView dynamicListView = (DynamicListView) getListView();
dynamicListView.setItemsList(listAdapter.getObjects());
dynamicListView.setActiveItemsList(listAdapter.getActiveObjects());
} }
protected List<Object> getListObjects() { protected List<Object> getListObjects() {

View file

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