Markers in progress

This commit is contained in:
Alexey Kulish 2016-02-07 13:22:38 +03:00
parent 1dac5f92d4
commit 51aa200990
8 changed files with 178 additions and 47 deletions

View file

@ -10,5 +10,7 @@
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:drawSelectorOnTop="true"
tools:listitem="@layout/waypoint_reached"/>
</LinearLayout>

View file

@ -192,6 +192,10 @@ public class PointDescription {
return POINT_TYPE_TARGET.equals(type);
}
public boolean isMapMarker() {
return POINT_TYPE_MAP_MARKER.equals(type);
}
public boolean isParking() {
return POINT_TYPE_PARKING_MARKER.equals(type);
}

View file

@ -10,11 +10,15 @@ import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
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<>();
private OsmandSettings settings;
@ -176,7 +180,7 @@ public class MapMarkersHelper {
public void removeActiveMarkers() {
cancelAddressRequests();
settings.clearIntermediatePoints();
settings.clearActiveMapMarkers();
mapMarkers.clear();
readFromSettings();
refresh();
@ -185,12 +189,36 @@ public class MapMarkersHelper {
public void removeMarkersHistory() {
cancelAddressRequests();
settings.clearIntermediatePoints();
settings.clearMapMarkersHistory();
mapMarkersHistory.clear();
readFromSettings();
refresh();
}
public void addMapMarker(final LatLon point, PointDescription historyName) {
if (point != null) {
final PointDescription pointDescription;
if (historyName == null) {
pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
} else {
pointDescription = historyName;
}
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
}
int colorIndex;
if (mapMarkers.size() > 0) {
colorIndex = (mapMarkers.get(mapMarkers.size() - 1).colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
} else {
colorIndex = 0;
}
settings.insertMapMarker(point.getLatitude(), point.getLongitude(),
pointDescription, colorIndex, mapMarkers.size());
}
readFromSettings();
refresh();
}
public void addListener(StateChangedListener<Void> l) {
listeners.add(l);
}

View file

@ -1529,6 +1529,20 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences).remove(INTERMEDIATE_POINTS).remove(INTERMEDIATE_POINTS_DESCRIPTION).commit();
}
public boolean clearActiveMapMarkers() {
return settingsAPI.edit(globalPreferences)
.remove(MAP_MARKERS_POINT)
.remove(MAP_MARKERS_DESCRIPTION)
.remove(MAP_MARKERS_COLOR).commit();
}
public boolean clearMapMarkersHistory() {
return settingsAPI.edit(globalPreferences)
.remove(MAP_MARKERS_HISTORY_POINT)
.remove(MAP_MARKERS_HISTORY_DESCRIPTION)
.remove(MAP_MARKERS_HISTORY_COLOR).commit();
}
public final CommonPreference<Boolean> USE_INTERMEDIATE_POINTS_NAVIGATION =
new BooleanPreference("use_intermediate_points_navigation", false).makeGlobal().cache();

View file

@ -33,6 +33,7 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -97,7 +98,6 @@ public class MapActivityActions implements DialogProvider {
openIntermediateEditPointsDialog();
}
*/
public void addAsTarget(double latitude, double longitude, PointDescription pd) {
TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
@ -105,6 +105,13 @@ public class MapActivityActions implements DialogProvider {
pd);
openIntermediatePointsDialog();
}
*/
public void addMapMarker(double latitude, double longitude, PointDescription pd) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
markersHelper.addMapMarker(new LatLon(latitude, longitude), pd);
openMapMarkersActivity();
}
public void editWaypoints() {
openIntermediatePointsDialog();
@ -570,11 +577,8 @@ public class MapActivityActions implements DialogProvider {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
MapActivity.clearPrevActivityIntent();
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getMapMarkersActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(newIntent);
return false;
openMapMarkersActivity();
return true;
}
}).reg();
optionsMenuHelper.item(R.string.get_directions).iconColor(R.drawable.ic_action_gdirections_dark)
@ -742,17 +746,17 @@ public class MapActivityActions implements DialogProvider {
return optionsMenuHelper;
}
public void openMapMarkersActivity() {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getMapMarkersActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(newIntent);
}
public void openIntermediatePointsDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
}
/*
public void openIntermediateEditPointsDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS_EDIT);
}
*/
public void openRoutePreferencesDialog() {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.ROUTE_PREFERENCES);
}

View file

@ -21,19 +21,23 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.views.controls.DynamicListView;
import net.osmand.plus.views.controls.DynamicListViewCallbacks;
import net.osmand.plus.views.controls.ListDividerShape;
import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.plus.views.controls.SwipeDismissListViewTouchListener;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
public class MapMarkersActivity extends OsmandListActivity {
public class MapMarkersActivity extends OsmandListActivity implements DynamicListViewCallbacks {
public static final int ACTIVE_MARKERS = 0;
public static final int MARKERS_HISTORY = 1;
private SwipeDismissListViewTouchListener swipeDismissListener;
private boolean nightMode;
@Override
@ -43,6 +47,56 @@ public class MapMarkersActivity extends OsmandListActivity {
setContentView(R.layout.map_markers);
getSupportActionBar().setTitle(R.string.map_markers);
((DynamicListView) getListView()).setDynamicListViewCallbacks(this);
swipeDismissListener = new SwipeDismissListViewTouchListener(getListView(),
new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
List<Object> activeObjects = getListAdapter().getActiveObjects();
Object obj = getListAdapter().getItem(position);
return activeObjects.contains(obj);
}
@Override
public SwipeDismissListViewTouchListener.Undoable onDismiss(final int position) {
final Object item;
final StableArrayAdapter stableAdapter = getListAdapter();
final int activeObjPos;
item = stableAdapter.getItem(position);
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) {
stableAdapter.setNotifyOnChange(false);
stableAdapter.insert(item, position);
stableAdapter.getObjects().add(position, item);
stableAdapter.getActiveObjects().add(activeObjPos, item);
stableAdapter.refreshData();
}
}
};
}
@Override
public void onHidePopup() {
StableArrayAdapter stableAdapter = getListAdapter();
stableAdapter.refreshData();
// do delete
if (stableAdapter.getActiveObjects().size() == 0) {
finish();
}
}
});
//nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
nightMode = !getMyApplication().getSettings().isLightContent();
setListAdapter(getMapMarkersListAdapter());
@ -55,8 +109,10 @@ public class MapMarkersActivity extends OsmandListActivity {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
getListAdapter().getItem(position);
//
Object obj = getListAdapter().getItem(position);
if (obj instanceof MapMarker) {
showOnMap((MapMarker) obj);
}
}
@Override
@ -78,6 +134,12 @@ public class MapMarkersActivity extends OsmandListActivity {
dividers = getCustomDividers(getObjects());
}
@Override
public boolean isEnabled(int position) {
Object obj = getItem(position);
return obj instanceof MapMarker;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
@ -176,18 +238,21 @@ public class MapMarkersActivity extends OsmandListActivity {
v.findViewById(R.id.check_item).setVisibility(View.GONE);
v.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue)
: getResources().getColor(R.color.osmand_orange));
btn.setText(getString(R.string.shared_string_clear));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getListAdapter().notifyDataSetInvalidated();
reloadListAdapter();
}
});
if (type == MARKERS_HISTORY) {
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue)
: getResources().getColor(R.color.osmand_orange));
btn.setText(getString(R.string.shared_string_clear));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getListAdapter().notifyDataSetInvalidated();
getMyApplication().getMapMarkersHelper().removeMarkersHistory();
reloadListAdapter();
}
});
}
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(this, tv, nightMode);
@ -214,26 +279,19 @@ public class MapMarkersActivity extends OsmandListActivity {
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
AndroidUtils.setTextPrimaryColor(this, text, nightMode);
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap(marker);
}
});
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon))
.setImageDrawable(getMapMarkerIcon(marker.colorIndex));
.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
} else {
textDist.setText("");
}
//if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
//} else {
// textDist.setText("");
//}
localView.findViewById(R.id.waypoint_deviation).setVisibility(View.GONE);
@ -250,6 +308,8 @@ public class MapMarkersActivity extends OsmandListActivity {
}
text.setText(descr);
localView.findViewById(R.id.waypoint_desc_text).setVisibility(View.GONE);
/*
String pointDescription = "";
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
if (descText != null) {
@ -266,6 +326,7 @@ public class MapMarkersActivity extends OsmandListActivity {
if (descText != null) {
descText.setText(pointDescription);
}
*/
}
public void showOnMap(MapMarker marker) {
@ -332,8 +393,8 @@ public class MapMarkersActivity extends OsmandListActivity {
return activeObjects;
}
private Drawable getMapMarkerIcon(int colorIndex) {
IconsCache iconsCache = getMyApplication().getIconsCache();
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
IconsCache iconsCache = app.getIconsCache();
switch (colorIndex) {
case 0:
return iconsCache.getIcon(R.drawable.map_marker_blue);
@ -349,4 +410,19 @@ public class MapMarkersActivity extends OsmandListActivity {
return iconsCache.getIcon(R.drawable.map_marker_blue);
}
}
@Override
public void onWindowVisibilityChanged(int visibility) {
if (visibility != View.VISIBLE && swipeDismissListener != null) {
swipeDismissListener.discardUndo();
}
}
@Override
public void onItemsSwapped(List<Object> items) {
}
@Override
public void onItemSwapping(int position) {
}
}

View file

@ -470,9 +470,11 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void buttonWaypointPressed() {
if (pointDescription.isDestination()) {
mapActivity.getMapActions().editWaypoints();
} else if (pointDescription.isMapMarker()) {
mapActivity.getMapActions().openMapMarkersActivity();
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
getPointDescriptionForTarget());
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
pointDescription);
}
close();
}

View file

@ -8,6 +8,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapMarkersActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.util.Algorithms;
@ -59,7 +60,7 @@ public class MapMarkerMenuController extends MenuController {
@Override
public Drawable getLeftIcon() {
return getIconOrig(R.drawable.list_intermediate);
return MapMarkersActivity.getMapMarkerIcon(getMapActivity().getMyApplication(), mapMarker.colorIndex);
}
@Override