Context menu refactoring done

This commit is contained in:
Alexey Kulish 2015-10-13 16:38:38 +03:00
parent 6e096461f7
commit 914e7a35c1
27 changed files with 546 additions and 927 deletions

View file

@ -28,21 +28,6 @@ public class MapAccessibilityActions implements AccessibilityActionsProvider {
@Override @Override
public boolean onLongClick(PointF point, RotatedTileBox tileBox) { public boolean onLongClick(PointF point, RotatedTileBox tileBox) {
if ((Build.VERSION.SDK_INT >= 14) && activity.getMyApplication().accessibilityEnabled()) {
final OsmandMapTileView mapView = activity.getMapView();
final double lat = tileBox.getLatFromPixel((int)point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int)point.x, (int) point.y);
ContextMenuLayer cm = activity.getMapLayers().getContextMenuLayer();
LatLon loc = cm.selectObjectsForContextMenu(tileBox, point);
if (cm.getSelectedObjectName() != null) {
cm.showContextMenuForSelectedObjects(loc);
} else {
activity.getMapActions().contextMenuPoint(lat, lon);
}
// activity.getMapActions().contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true;
}
return false; return false;
} }

View file

@ -42,69 +42,16 @@ public class MapExplorer extends SimpleOnGestureListener implements IContextMenu
} }
// Compare two lists by content.
private boolean different(Object l1, Object l2) {
if(l1 == null || l2 == null) {
return l1 != l2;
}
return l1.equals(l2);
}
// Find touched objects if any and emit accessible toast message
// with it's brief description.
private void describePointedObjects(RotatedTileBox tb, MotionEvent event) {
PointF point = new PointF(event.getX(), event.getY());
List<Object> ns = new ArrayList<Object>();
Map<Object, IContextMenuProvider> newSelectedObjects = new LinkedHashMap<Object, ContextMenuLayer.IContextMenuProvider>();
for (OsmandMapLayer layer : mapView.getLayers()) {
if (layer instanceof IContextMenuProvider) {
ns.clear();
((IContextMenuProvider) layer).collectObjectsFromPoint(point, tb , ns);
for(Object o : ns) {
newSelectedObjects.put(o, (IContextMenuProvider) layer);
}
}
}
if (newSelectedObjects.isEmpty()) {
ns.clear();
collectObjectsFromPoint(point, tb, ns);
for(Object o : ns) {
newSelectedObjects.put(o, this);
}
}
if (different(newSelectedObjects, selectedObjects)) {
ContextMenuLayer contextMenuLayer = mapView.getLayerByClass(ContextMenuLayer.class);
if (contextMenuLayer != null) {
contextMenuLayer.setSelections(newSelectedObjects);
if (!ns.isEmpty())
mapView.showMessage(mapView.getSettings().USE_SHORT_OBJECT_NAMES.get() ?
contextMenuLayer.getSelectedObjectName() :
contextMenuLayer.getSelectedObjectDescription());
}
selectedObjects = newSelectedObjects;
}
}
// OnGestureListener interface implementation. // OnGestureListener interface implementation.
@Override @Override
public boolean onDown(MotionEvent e) { public boolean onDown(MotionEvent e) {
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get()) return fallback.onDown(e);
return fallback.onDown(e);
ContextMenuLayer contextMenuLayer = mapView.getLayerByClass(ContextMenuLayer.class);
if (contextMenuLayer != null)
contextMenuLayer.setSelections(null);
selectedObjects = null;
describePointedObjects(mapView.getCurrentRotatedTileBox(), e);
return false;
} }
@Override @Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get()) return fallback.onFling(e1, e2, velocityX / 3, velocityY / 3);
return fallback.onFling(e1, e2, velocityX/3, velocityY/3);
return true;
} }
@Override @Override
@ -114,18 +61,12 @@ public class MapExplorer extends SimpleOnGestureListener implements IContextMenu
@Override @Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get()) { return fallback.onScroll(e1, e2, distanceX, distanceY);
return fallback.onScroll(e1, e2, distanceX, distanceY);
} else {
describePointedObjects(mapView.getCurrentRotatedTileBox(), e2);
}
return true;
} }
@Override @Override
public void onShowPress(MotionEvent e) { public void onShowPress(MotionEvent e) {
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get()) fallback.onShowPress(e);
fallback.onShowPress(e);
} }
@Override @Override

View file

@ -43,18 +43,6 @@ public class PointDescription implements Serializable {
public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, "");
public String getType() {
return type;
}
public double getLat() {
return lat;
}
public double getLon() {
return lon;
}
public PointDescription(double lat, double lon) { public PointDescription(double lat, double lon) {
this(POINT_TYPE_LOCATION, ""); this(POINT_TYPE_LOCATION, "");
this.lat = lat; this.lat = lat;
@ -141,11 +129,7 @@ public class PointDescription implements Serializable {
} }
} }
public String getLocationName(Context ctx, boolean shortText) { public static String getLocationName(Context ctx, double lat, double lon, boolean sh) {
return getLocationName(ctx, lat, lon, shortText);
}
private String getLocationName(Context ctx, double lat, double lon, boolean sh) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings(); OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get(); int f = st.COORDINATES_FORMAT.get();
if (f == PointDescription.UTM_FORMAT) { if (f == PointDescription.UTM_FORMAT) {

View file

@ -5,7 +5,6 @@ package net.osmand.plus.activities;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -20,6 +19,7 @@ import android.widget.TextView;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -28,7 +28,6 @@ import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.util.Comparator; import java.util.Comparator;
@ -133,7 +132,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
if (!isSelectFavoriteMode()) { if (!isSelectFavoriteMode()) {
FavouritePoint point = favouritesAdapter.getItem(position); FavouritePoint point = favouritesAdapter.getItem(position);
showItemPopupOptionsMenu(point, getActivity(), v); showOnMap(point, getActivity());
} else { } else {
Intent intent = getActivity().getIntent(); Intent intent = getActivity().getIntent();
intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position)); intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position));
@ -212,7 +211,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
options.setOnClickListener(new View.OnClickListener() { options.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showItemPopupOptionsMenu(favorite, activity, v); showOnMap(favorite, activity);
} }
}); });
} }
@ -254,13 +253,17 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
} }
} }
public static void showItemPopupOptionsMenu(FavouritePoint point, Activity activity, View view) { public static void showOnMap(FavouritePoint point, Activity activity) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
final OsmandSettings settings = app.getSettings();
LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
final PopupMenu optionsMenu = new PopupMenu(activity, view);
DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
point, point.getPointDescription(), settings.getLastKnownMapZoom(),
((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
activity, true, false); true,
optionsMenu.show(); point); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity);
} }
} }

View file

@ -17,7 +17,6 @@ import android.os.Handler;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -52,7 +51,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
@ -182,8 +180,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
} }
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} else { } else {
final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition); final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
showItemPopupOptionsMenu(point, v); showOnMap(point);
} }
return true; return true;
} }
@ -802,7 +800,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
options.setOnClickListener(new View.OnClickListener() { options.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showItemPopupOptionsMenu(model, v); showOnMap(model);
} }
}); });
} }
@ -908,40 +906,15 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
} }
} }
public void showItemPopupOptionsMenu(final FavouritePoint point, final View view) { public void showOnMap(final FavouritePoint point) {
final OsmandSettings settings = getMyApplication().getSettings(); final OsmandSettings settings = getMyApplication().getSettings();
LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, point, settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
settings.getLastKnownMapZoom(), settings.getLastKnownMapZoom(),
getActivity(), true, false); new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
true,
MenuItem item = optionsMenu.getMenu().add(R.string.favourites_context_menu_edit) point); //$NON-NLS-1$
.setIcon(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_edit_dark)); MapActivity.launchMapActivityMoveToTop(getActivity());
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
editPoint(getActivity(), point, new Runnable() {
public void run() {
favouritesAdapter.synchronizeGroups();
}
});
return true;
}
});
item = optionsMenu.getMenu().add(R.string.favourites_context_menu_delete)
.setIcon(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_delete_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
deletePoint(point);
return true;
}
});
optionsMenu.show();
} }
} }

View file

@ -545,13 +545,8 @@ public class MapActivity extends AccessibleActivity {
dashboardOnMap.hideDashboard(); dashboardOnMap.hideDashboard();
} }
if (mapLabelToShow != null) { if (mapLabelToShow != null) {
mapLayers.getContextMenuLayer().setSelectedObject(toShow); contextMenuOnMap.show(latLonToShow, mapLabelToShow, toShow);
// if (toShow instanceof FavouritePoint) { //mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow.getFullPlainName(this));
// mapLayers.getContextMenuLayer().showContextMenuForSelectedObjects(latLonToShow);
// } else {
mapLayers.getContextMenuLayer().setLocation(latLonToShow,
mapLabelToShow.getFullPlainName(this));
// }
} }
if (!latLonToShow.equals(cur)) { if (!latLonToShow.equals(cur)) {
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(),

View file

@ -90,17 +90,6 @@ public class MapActivityActions implements DialogProvider {
settings = mapActivity.getMyApplication().getSettings(); settings = mapActivity.getMyApplication().getSettings();
routingHelper = mapActivity.getMyApplication().getRoutingHelper(); routingHelper = mapActivity.getMyApplication().getRoutingHelper();
} }
public void addFavouritePoint(final double latitude, final double longitude){
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
enhance(dialogBundle, latitude, longitude, name);
mapActivity.showDialog(DIALOG_ADD_FAVORITE);
}
public void editFavoritePoint(final FavouritePoint a) {
FavoritesTreeFragment.editPoint(mapActivity.getMapView().getContext(), a, null);
}
public void shareLocation(double latitude, double longitude) { public void shareLocation(double latitude, double longitude) {
enhance(dialogBundle,latitude,longitude,mapActivity.getMapView().getZoom()); enhance(dialogBundle,latitude,longitude,mapActivity.getMapView().getZoom());
@ -143,15 +132,14 @@ public class MapActivityActions implements DialogProvider {
targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, null); targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, null);
enterRoutePlanningMode(null, null, false); enterRoutePlanningMode(null, null, false);
} else if (standardId == R.string.context_menu_item_directions_from) { } else if (standardId == R.string.context_menu_item_directions_from) {
List<PointDescription> nms = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectNames(); enterRoutePlanningMode(new LatLon(latitude, longitude),
enterRoutePlanningMode(new LatLon(latitude, longitude), nms.isEmpty() ? null : nms.get(0), false); mapActivity.getContextMenu().getPointDescription(), false);
} else if (standardId == R.string.context_menu_item_intermediate_point || } else if (standardId == R.string.context_menu_item_intermediate_point ||
standardId == R.string.context_menu_item_destination_point) { standardId == R.string.context_menu_item_destination_point) {
boolean dest = standardId == R.string.context_menu_item_destination_point; boolean dest = standardId == R.string.context_menu_item_destination_point;
List<PointDescription> nms = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectNames();
targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.navigateToPoint(new LatLon(latitude, longitude), true,
dest ? -1 : targets.getIntermediatePoints().size(), nms.size() == 0?null : dest ? -1 : targets.getIntermediatePoints().size(),
nms.get(0)); mapActivity.getContextMenu().getPointDescription());
if(targets.getIntermediatePoints().size() > 0) { if(targets.getIntermediatePoints().size() > 0) {
openIntermediatePointsDialog(); openIntermediatePointsDialog();
} }
@ -176,8 +164,8 @@ public class MapActivityActions implements DialogProvider {
} }
public void addWaypoint(final double latitude, final double longitude){ public void addWaypoint(final double latitude, final double longitude) {
String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName(); String name = mapActivity.getContextMenu().getPointDescription().getFullPlainName(mapActivity);
enhance(dialogBundle,latitude,longitude, name); enhance(dialogBundle,latitude,longitude, name);
mapActivity.showDialog(DIALOG_ADD_WAYPOINT); mapActivity.showDialog(DIALOG_ADD_WAYPOINT);
} }

View file

@ -17,6 +17,7 @@ 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;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -230,11 +231,14 @@ public class SearchAddressOnlineFragment extends Fragment implements SearchActiv
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Place item = adapter.getItem(position); Place item = adapter.getItem(position);
final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, new LatLon(item.lat, item.lon), item, LatLon location = new LatLon(item.lat, item.lon);
new PointDescription(PointDescription.POINT_TYPE_ADDRESS, item.displayName), Math.max(15, settings.getLastKnownMapZoom()), settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
getActivity(), true); Math.max(15, settings.getLastKnownMapZoom()),
optionsMenu.show(); new PointDescription(PointDescription.POINT_TYPE_ADDRESS, item.displayName),
true,
item); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
} }
private static class Place { private static class Place {

View file

@ -1,22 +1,5 @@
package net.osmand.plus.activities.search; package net.osmand.plus.activities.search;
import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.util.MapUtils;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -24,11 +7,9 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
@ -41,6 +22,24 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.BufferType; import android.widget.TextView.BufferType;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.util.MapUtils;
import java.util.List;
public class SearchHistoryFragment extends OsmAndListFragment implements SearchActivityChild, OsmAndCompassListener { public class SearchHistoryFragment extends OsmAndListFragment implements SearchActivityChild, OsmAndCompassListener {
private LatLon location; private LatLon location;
@ -174,28 +173,21 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
HistoryEntry model = ((HistoryAdapter) getListAdapter()).getItem(position); HistoryEntry model = ((HistoryAdapter) getListAdapter()).getItem(position);
selectModel(model, v); selectModel(model);
} }
private void selectModel(final HistoryEntry model, View v) { private void selectModel(final HistoryEntry model) {
PointDescription name = model.getName(); PointDescription name = model.getName();
boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightContent();
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings(); OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, new LatLon(model.getLat(), model.getLon()),
model, name, settings.getLastKnownMapZoom(), getActivity(), true); LatLon location = new LatLon(model.getLat(), model.getLon());
MenuItem item = optionsMenu.getMenu().add(
R.string.shared_string_delete).setIcon( settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_delete_dark)); settings.getLastKnownMapZoom(),
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { name,
@Override true,
public boolean onMenuItemClick(MenuItem item) { model); //$NON-NLS-1$
helper.remove(model); MapActivity.launchMapActivityMoveToTop(getActivity());
historyAdapter.remove(model);
return true;
}
});
optionsMenu.show();
} }
class HistoryAdapter extends ArrayAdapter<HistoryEntry> { class HistoryAdapter extends ArrayAdapter<HistoryEntry> {
@ -230,7 +222,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
options.setOnClickListener(new View.OnClickListener() { options.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
selectModel(historyEntry, v); selectModel(historyEntry);
} }
}); });
return row; return row;

View file

@ -550,36 +550,14 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
app.getSettings().MAP_PREFERRED_LOCALE.get()); app.getSettings().MAP_PREFERRED_LOCALE.get());
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat); PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
int z = Math.max(16, settings.getLastKnownMapZoom()); int z = Math.max(16, settings.getLastKnownMapZoom());
final PopupMenu optionsMenu = new PopupMenu(this, view);
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, amenity.getLocation(), amenity, name, z, this, LatLon location = amenity.getLocation();
true); settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false); z,
if (d.toString().trim().length() > 0 || amenity.getType().isWiki()) { name,
MenuItem item = optionsMenu true,
.getMenu() amenity); //$NON-NLS-1$
.add(R.string.poi_context_menu_showdescription) MapActivity.launchMapActivityMoveToTop(this);
.setIcon(
getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_note_dark));
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// Build text(amenity)
POIMapLayer.showDescriptionDialog(SearchPOIActivity.this, app, amenity);
return true;
}
});
}
if (((OsmandApplication) getApplication()).accessibilityEnabled()) {
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_details);
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
showPOIDetails(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get());
return true;
}
});
}
optionsMenu.show();
} }

View file

@ -1130,7 +1130,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
recordingByFileName = newMap; recordingByFileName = newMap;
Algorithms.removeAllFiles(r.file); Algorithms.removeAllFiles(r.file);
if (activity != null) { if (activity != null) {
activity.getMapLayers().getContextMenuLayer().setLocation(null, ""); activity.getContextMenu().close();
activity.getMapView().refreshMap(); activity.getMapView().refreshMap();
} }
} }

View file

@ -3,15 +3,11 @@ package net.osmand.plus.dialogs;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
@ -51,75 +47,6 @@ public class DirectionsDialogs {
} }
} }
public static void createDirectionsActionsPopUpMenu(final PopupMenu optionsMenu , final LatLon location, final Object obj, final PointDescription name,
final int z, final Activity activity, final boolean saveHistory) {
createDirectionActionsPopUpMenu(optionsMenu, location, obj, name, z, activity, saveHistory, true);
}
public static void createDirectionActionsPopUpMenu(final PopupMenu optionsMenu, final LatLon location, final Object obj, final PointDescription name,
final int z, final Activity activity, final boolean saveHistory, boolean favorite) {
setupPopUpMenuIcon(optionsMenu);
final OsmandApplication app = ((OsmandApplication) activity.getApplication());
IconsCache iconsCache = app.getIconsCache();
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
MenuItem item = optionsMenu.getMenu().add(
R.string.context_menu_item_directions_to).setIcon(iconsCache.getContentIcon((R.drawable.ic_action_gdirections_dark)));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DirectionsDialogs.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
optionsMenu.dismiss();
return true;
}
});
if (targetPointsHelper.getPointToNavigate() != null) {
item = optionsMenu.getMenu().add(
R.string.context_menu_item_intermediate_point).setIcon(
iconsCache.getContentIcon(R.drawable.ic_action_flage_dark));
} else {
item = optionsMenu.getMenu().add(
R.string.context_menu_item_destination_point).setIcon(
iconsCache.getContentIcon(R.drawable.ic_action_flag_dark));
}
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DirectionsDialogs.addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
optionsMenu.dismiss();
return true;
}
});
item = optionsMenu.getMenu().add(
R.string.shared_string_show_on_map).setIcon(iconsCache.getContentIcon(R.drawable.ic_action_marker_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, name, saveHistory,
obj); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity);
return true;
}
});
if (favorite) {
item = optionsMenu.getMenu().add(
R.string.shared_string_add_to_favorites).setIcon(iconsCache.getContentIcon(R.drawable.ic_action_fav_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Bundle args = new Bundle();
Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(activity, args);
dlg.show();
FavoriteDialogs.prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(),
name);
return true;
}
});
}
}
public static void addWaypointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final PointDescription name) { public static void addWaypointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final PointDescription name) {
final OsmandApplication ctx = (OsmandApplication) act.getApplication(); final OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();

View file

@ -1,23 +1,5 @@
package net.osmand.plus.helpers; package net.osmand.plus.helpers;
import java.util.ArrayList;
import java.util.List;
import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.ResultMatcher;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -29,6 +11,25 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.CallbackWithObject;
import net.osmand.Location;
import net.osmand.ResultMatcher;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.List;
public class AvoidSpecificRoads { public class AvoidSpecificRoads {
private List<RouteDataObject> missingRoads; private List<RouteDataObject> missingRoads;
private OsmandApplication app; private OsmandApplication app;
@ -114,7 +115,7 @@ public class AvoidSpecificRoads {
RouteDataObject obj = getMissingRoads().get(which); RouteDataObject obj = getMissingRoads().get(which);
double lat = MapUtils.get31LatitudeY(obj.getPoint31YTile(0)); double lat = MapUtils.get31LatitudeY(obj.getPoint31YTile(0));
double lon = MapUtils.get31LongitudeX(obj.getPoint31XTile(0)); double lon = MapUtils.get31LongitudeX(obj.getPoint31XTile(0));
showOnMap(app, mapActivity, lat, lon, getText(obj), dialog); showOnMap(mapActivity, lat, lon, getText(obj), dialog);
} }
}); });
@ -172,12 +173,8 @@ public class AvoidSpecificRoads {
}); });
} }
public static void showOnMap(OsmandApplication app, Activity a, double lat, double lon, String name, private void showOnMap(MapActivity ctx, double lat, double lon, String name,
DialogInterface dialog) { DialogInterface dialog) {
if (!(a instanceof MapActivity)) {
return;
}
MapActivity ctx = (MapActivity) a;
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread(); AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom(); int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
if (thread.isAnimating()) { if (thread.isAnimating()) {
@ -186,7 +183,7 @@ public class AvoidSpecificRoads {
} else { } else {
thread.startMoving(lat, lon, fZoom, true); thread.startMoving(lat, lon, fZoom, true);
} }
ctx.getMapLayers().getContextMenuLayer().showMapContextMenu(new LatLon(lat, lon), name); ctx.getContextMenu().show(new LatLon(lat, lon), new PointDescription("", name), null);
dialog.dismiss(); dialog.dismiss();
} }

View file

@ -423,16 +423,17 @@ public class WaypointDialogHelper {
} }
if(ctx.getDashboard().isVisible()) { if(ctx.getDashboard().isVisible()) {
ctx.getDashboard().hideDashboard(); ctx.getDashboard().hideDashboard();
ctx.getContextMenu().show(
new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
locationPoint.getPointDescription(ctx),
locationPoint);
/*
ctx.getMapLayers().getContextMenuLayer().setSelectedObject(locationPoint); ctx.getMapLayers().getContextMenuLayer().setSelectedObject(locationPoint);
// if (locationPoint instanceof FavouritePoint) { ctx.getMapLayers()
// ctx.getMapLayers().getContextMenuLayer() .getContextMenuLayer()
// .showContextMenuForSelectedObjects(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude())); .setLocation(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
// } else { PointDescription.getSimpleName(locationPoint, ctx));
ctx.getMapLayers() */
.getContextMenuLayer()
.setLocation(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
PointDescription.getSimpleName(locationPoint, ctx));
// }
} }
} }
} }

View file

@ -3,7 +3,7 @@ package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log; import android.view.View;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
@ -21,6 +21,7 @@ import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.details.MenuController; import net.osmand.plus.mapcontextmenu.details.MenuController;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -30,6 +31,8 @@ public class MapContextMenu {
private OsmandSettings settings; private OsmandSettings settings;
private final MapActivity mapActivity; private final MapActivity mapActivity;
private boolean active;
private LatLon latLon;
private PointDescription pointDescription; private PointDescription pointDescription;
private Object object; private Object object;
MenuController menuController; MenuController menuController;
@ -42,15 +45,25 @@ public class MapContextMenu {
private String streetStr; private String streetStr;
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object"; private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
private static final String KEY_CTX_MENU_ACTIVE = "key_ctx_menu_active";
private static final String KEY_CTX_MENU_LATLON = "key_ctx_menu_latlon";
private static final String KEY_CTX_MENU_POINT_DESC = "key_ctx_menu_point_desc"; private static final String KEY_CTX_MENU_POINT_DESC = "key_ctx_menu_point_desc";
private static final String KEY_CTX_MENU_NAME_STR = "key_ctx_menu_name_str"; private static final String KEY_CTX_MENU_NAME_STR = "key_ctx_menu_name_str";
private static final String KEY_CTX_MENU_TYPE_STR = "key_ctx_menu_type_str"; private static final String KEY_CTX_MENU_TYPE_STR = "key_ctx_menu_type_str";
private static final String KEY_CTX_MENU_STREET_STR = "key_ctx_menu_street_str"; private static final String KEY_CTX_MENU_STREET_STR = "key_ctx_menu_street_str";
public boolean isMenuVisible() { public boolean isActive() {
return active;
}
public boolean isVisible() {
return findMenuFragment() != null; return findMenuFragment() != null;
} }
public LatLon getLatLon() {
return latLon;
}
public PointDescription getPointDescription() { public PointDescription getPointDescription() {
return pointDescription; return pointDescription;
} }
@ -59,8 +72,8 @@ public class MapContextMenu {
return object; return object;
} }
public MenuController getMenuController() { public boolean isExtended() {
return menuController; return menuController != null;
} }
public MapContextMenu(OsmandApplication app, MapActivity mapActivity) { public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
@ -69,12 +82,12 @@ public class MapContextMenu {
settings = app.getSettings(); settings = app.getSettings();
} }
public boolean init(PointDescription pointDescription, Object object) { public boolean init(LatLon latLon, PointDescription pointDescription, Object object) {
return init(pointDescription, object, false); return init(latLon, pointDescription, object, false);
} }
public boolean init(PointDescription pointDescription, Object object, boolean reload) { public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean reload) {
if (!reload && isMenuVisible()) { if (!reload && isVisible()) {
if (this.object == null || !this.object.equals(object)) { if (this.object == null || !this.object.equals(object)) {
hide(); hide();
} else { } else {
@ -82,46 +95,66 @@ public class MapContextMenu {
} }
} }
this.pointDescription = pointDescription; if (this.object != null) {
clearSelectedObject(this.object);
}
if (pointDescription == null) {
this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
} else {
this.pointDescription = pointDescription;
}
this.latLon = latLon;
this.object = object; this.object = object;
leftIconId = 0; leftIconId = 0;
nameStr = ""; nameStr = "";
typeStr = ""; typeStr = "";
streetStr = ""; streetStr = "";
active = true;
acquireMenuController(); acquireMenuController();
acquireIcons(); acquireIcons();
acquireNameAndType(); acquireNameAndType();
if (needStreetName()) { if (needStreetName()) {
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon())); acquireStreetName(latLon);
} }
if (menuController != null) { if (menuController != null) {
menuController.addPlainMenuItems(typeStr, this.pointDescription); menuController.addPlainMenuItems(typeStr, this.pointDescription);
} }
mapActivity.getMapView().refreshMap();
return true; return true;
} }
public void show() { public void show() {
if (!isMenuVisible()) { if (!isVisible()) {
MapContextMenuFragment.showInstance(mapActivity); MapContextMenuFragment.showInstance(mapActivity);
} }
} }
public void show(PointDescription pointDescription, Object object) { public void show(LatLon latLon, PointDescription pointDescription, Object object) {
if (init(pointDescription, object)) { if (init(latLon, pointDescription, object)) {
MapContextMenuFragment.showInstance(mapActivity); MapContextMenuFragment.showInstance(mapActivity);
} }
} }
public void refreshMenu(PointDescription pointDescription, Object object) { public void refreshMenu(LatLon latLon, PointDescription pointDescription, Object object) {
MapContextMenuFragment fragment = findMenuFragment(); MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null) { if (fragment != null) {
init(pointDescription, object, true); init(latLon, pointDescription, object, true);
fragment.rebuildMenu(); fragment.rebuildMenu();
} }
} }
public void close() {
active = false;
hide();
mapActivity.getMapView().refreshMap();
}
public void hide() { public void hide() {
MapContextMenuFragment fragment = findMenuFragment(); MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null) { if (fragment != null) {
@ -129,13 +162,28 @@ public class MapContextMenu {
} }
} }
private void clearSelectedObject(Object object) {
if (object != null) {
for (OsmandMapLayer l : mapActivity.getMapView().getLayers()) {
if (l instanceof ContextMenuLayer.IContextMenuProvider) {
PointDescription pointDescription = ((ContextMenuLayer.IContextMenuProvider) l).getObjectName(object);
if (pointDescription != null) {
if (l instanceof ContextMenuLayer.IContextMenuProviderSelection) {
((ContextMenuLayer.IContextMenuProviderSelection) l).setSelectedObject(object);
}
}
}
}
}
}
private void acquireMenuController() { private void acquireMenuController() {
menuController = null; menuController = null;
if (object != null) { if (object != null) {
if (object instanceof Amenity) { if (object instanceof Amenity) {
menuController = new AmenityMenuController(app, mapActivity, (Amenity)object); menuController = new AmenityMenuController(app, mapActivity, (Amenity) object);
} else if (object instanceof FavouritePoint) { } else if (object instanceof FavouritePoint) {
menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint)object); menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object);
} }
} }
} }
@ -160,7 +208,7 @@ public class MapContextMenu {
fragment.refreshTitle(); fragment.refreshTitle();
} }
private MapContextMenuFragment findMenuFragment() { public MapContextMenuFragment findMenuFragment() {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapContextMenuFragment.TAG); Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapContextMenuFragment.TAG);
if (fragment != null) { if (fragment != null) {
return (MapContextMenuFragment) fragment; return (MapContextMenuFragment) fragment;
@ -190,7 +238,8 @@ public class MapContextMenu {
return typeStr; return typeStr;
} else { } else {
if (Algorithms.isEmpty(streetStr)) { if (Algorithms.isEmpty(streetStr)) {
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", ""); return PointDescription.getLocationName(mapActivity,
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "");
} else { } else {
return streetStr; return streetStr;
} }
@ -270,19 +319,19 @@ public class MapContextMenu {
} }
public void buttonNavigatePressed() { public void buttonNavigatePressed() {
mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon()); mapActivity.getMapActions().showNavigationContextMenuPoint(latLon.getLatitude(), latLon.getLongitude());
} }
public void buttonFavoritePressed() { public void buttonFavoritePressed() {
if (object != null && object instanceof FavouritePoint) { if (object != null && object instanceof FavouritePoint) {
mapActivity.getFavoritePointEditor().edit((FavouritePoint)object); mapActivity.getFavoritePointEditor().edit((FavouritePoint) object);
} else { } else {
mapActivity.getFavoritePointEditor().add(pointDescription); mapActivity.getFavoritePointEditor().add(latLon, getTitleStr());
} }
} }
public void buttonSharePressed() { public void buttonSharePressed() {
mapActivity.getMapActions().shareLocation(pointDescription.getLat(), pointDescription.getLon()); mapActivity.getMapActions().shareLocation(latLon.getLatitude(), latLon.getLongitude());
} }
public void buttonMorePressed() { public void buttonMorePressed() {
@ -293,13 +342,15 @@ public class MapContextMenu {
} }
} }
mapActivity.getMapActions().contextMenuPoint(pointDescription.getLat(), pointDescription.getLon(), menuAdapter, object); mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, object);
} }
public void saveMenuState(Bundle bundle) { public void saveMenuState(Bundle bundle) {
if (menuController != null) { if (menuController != null) {
menuController.saveEntityState(bundle, KEY_CTX_MENU_OBJECT); menuController.saveEntityState(bundle, KEY_CTX_MENU_OBJECT);
} }
bundle.putString(KEY_CTX_MENU_ACTIVE, Boolean.toString(active));
bundle.putSerializable(KEY_CTX_MENU_LATLON, latLon);
bundle.putSerializable(KEY_CTX_MENU_POINT_DESC, pointDescription); bundle.putSerializable(KEY_CTX_MENU_POINT_DESC, pointDescription);
bundle.putString(KEY_CTX_MENU_NAME_STR, nameStr); bundle.putString(KEY_CTX_MENU_NAME_STR, nameStr);
bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr); bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr);
@ -314,10 +365,88 @@ public class MapContextMenu {
} }
acquireMenuController(); acquireMenuController();
active = Boolean.parseBoolean(bundle.getString(KEY_CTX_MENU_ACTIVE));
Object latLonObj = bundle.getSerializable(KEY_CTX_MENU_LATLON);
if (latLonObj != null) {
latLon = (LatLon) latLonObj;
} else {
active = false;
}
nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR); nameStr = bundle.getString(KEY_CTX_MENU_NAME_STR);
typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR); typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR);
streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR); streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR);
acquireIcons(); acquireIcons();
if (menuController != null) {
menuController.addPlainMenuItems(typeStr, this.pointDescription);
}
} }
}
public void setBaseFragmentVisibility(boolean visible) {
MapContextMenuFragment menuFragment = findMenuFragment();
if (menuFragment != null) {
menuFragment.setFragmentVisibility(visible);
}
}
public boolean isLandscapeLayout() {
return menuController != null && menuController.isLandscapeLayout();
}
public float getLandscapeWidthDp() {
if (menuController != null) {
return menuController.getLandscapeWidthDp();
} else {
return 0f;
}
}
public boolean slideUp() {
return menuController != null && menuController.slideUp();
}
public boolean slideDown() {
return menuController != null && menuController.slideDown();
}
public void build(View rootView) {
if (menuController != null) {
menuController.build(rootView);
}
}
public int getCurrentMenuState() {
if (menuController != null) {
return menuController.getCurrentMenuState();
} else {
return MenuController.MenuState.HEADER_ONLY;
}
}
public float getHalfScreenMaxHeightKoef() {
if (menuController != null) {
return menuController.getHalfScreenMaxHeightKoef();
} else {
return 0f;
}
}
public int getSlideInAnimation() {
if (menuController != null) {
return menuController.getSlideInAnimation();
} else {
return 0;
}
}
public int getSlideOutAnimation() {
if (menuController != null) {
return menuController.getSlideOutAnimation();
} else {
return 0;
}
}
}

View file

@ -10,7 +10,6 @@ import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener; import android.view.GestureDetector.OnGestureListener;
@ -28,6 +27,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -52,13 +52,11 @@ public class MapContextMenuFragment extends Fragment {
private View view; private View view;
private View mainView; private View mainView;
MenuController menuController; MapContextMenu menu;
private int menuTopHeight;
private int menuTopShadowHeight; private int menuTopShadowHeight;
private int menuTopShadowAllHeight; private int menuTopShadowAllHeight;
private int menuTitleHeight; private int menuTitleHeight;
private int menuButtonsHeight;
private int menuBottomViewHeight; private int menuBottomViewHeight;
private int menuFullHeight; private int menuFullHeight;
private int menuFullHeightMax; private int menuFullHeightMax;
@ -101,7 +99,7 @@ public class MapContextMenuFragment extends Fragment {
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
getCtxMenu().saveMenuState(outState); menu.saveMenuState(outState);
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @TargetApi(Build.VERSION_CODES.HONEYCOMB)
@ -109,46 +107,20 @@ public class MapContextMenuFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
if (savedInstanceState != null) menu = getMapActivity().getContextMenu();
getCtxMenu().restoreMenuState(savedInstanceState); if (savedInstanceState != null) {
menu.restoreMenuState(savedInstanceState);
}
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false); view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
mainView = view.findViewById(R.id.context_menu_main); mainView = view.findViewById(R.id.context_menu_main);
menuController = getCtxMenu().getMenuController(); if (menu.isLandscapeLayout()) {
if (menuController != null && menuController.isLandscapeLayout()) { mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menu.getLandscapeWidthDp()),
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menuController.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT)); ViewGroup.LayoutParams.MATCH_PARENT));
} }
ViewTreeObserver vto = view.getViewTreeObserver(); runLayoutListener();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
menuTopHeight = view.findViewById(R.id.context_menu_top_view).getHeight();
menuTopShadowHeight = view.findViewById(R.id.context_menu_top_shadow).getHeight();
menuTopShadowAllHeight = view.findViewById(R.id.context_menu_top_shadow_all).getHeight();
menuButtonsHeight = view.findViewById(R.id.context_menu_buttons).getHeight();
menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight;
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
recalculateFullHeightMax();
ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
doLayoutMenu();
}
});
final GestureDetector singleTapDetector = new GestureDetector(view.getContext(), new SingleTapConfirm()); final GestureDetector singleTapDetector = new GestureDetector(view.getContext(), new SingleTapConfirm());
@ -168,7 +140,7 @@ public class MapContextMenuFragment extends Fragment {
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (singleTapDetector.onTouchEvent(event)) { if (singleTapDetector.onTouchEvent(event)) {
showOnMap(getCtxMenu().getPointDescription().getLat(), getCtxMenu().getPointDescription().getLon()); showOnMap(menu.getLatLon());
if (hasMoved) { if (hasMoved) {
applyPosY(getViewY()); applyPosY(getViewY());
@ -176,7 +148,7 @@ public class MapContextMenuFragment extends Fragment {
return true; return true;
} }
if (menuController != null && menuController.isLandscapeLayout()) { if (menu.isLandscapeLayout()) {
return true; return true;
} }
@ -222,11 +194,11 @@ public class MapContextMenuFragment extends Fragment {
velocity.recycle(); velocity.recycle();
if (menuController != null) { if (menu.isExtended()) {
if (menuBottomViewHeight > 0 && slidingUp) { if (menuBottomViewHeight > 0 && slidingUp) {
menuController.slideUp(); menu.slideUp();
} else if (slidingDown) { } else if (slidingDown) {
menuController.slideDown(); menu.slideDown();
} }
} }
@ -296,8 +268,7 @@ public class MapContextMenuFragment extends Fragment {
closeButtonView.setOnClickListener(new View.OnClickListener() { closeButtonView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
((MapActivity) getActivity()).getMapLayers().getContextMenuLayer().hideMapContextMenuMarker(); getMapActivity().getContextMenu().close();
dismissMenu();
} }
}); });
@ -308,7 +279,7 @@ public class MapContextMenuFragment extends Fragment {
buttonNavigate.setOnClickListener(new View.OnClickListener() { buttonNavigate.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonNavigatePressed(); menu.buttonNavigatePressed();
} }
}); });
@ -318,7 +289,7 @@ public class MapContextMenuFragment extends Fragment {
buttonFavorite.setOnClickListener(new View.OnClickListener() { buttonFavorite.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonFavoritePressed(); menu.buttonFavoritePressed();
} }
}); });
@ -328,7 +299,7 @@ public class MapContextMenuFragment extends Fragment {
buttonShare.setOnClickListener(new View.OnClickListener() { buttonShare.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonSharePressed(); menu.buttonSharePressed();
} }
}); });
@ -338,7 +309,7 @@ public class MapContextMenuFragment extends Fragment {
buttonMore.setOnClickListener(new View.OnClickListener() { buttonMore.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getCtxMenu().buttonMorePressed(); menu.buttonMorePressed();
} }
}); });
@ -359,13 +330,15 @@ public class MapContextMenuFragment extends Fragment {
final View iconLayout = view.findViewById(R.id.context_menu_icon_layout); final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view); final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
Drawable icon = getCtxMenu().getLeftIcon(); Drawable icon = menu.getLeftIcon();
int iconId = getCtxMenu().getLeftIconId(); int iconId = menu.getLeftIconId();
if (icon != null) { if (icon != null) {
iconView.setImageDrawable(icon); iconView.setImageDrawable(icon);
iconLayout.setVisibility(View.VISIBLE);
} else if (iconId != 0) { } else if (iconId != 0) {
iconView.setImageDrawable(iconsCache.getIcon(iconId, iconView.setImageDrawable(iconsCache.getIcon(iconId,
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f)); light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
iconLayout.setVisibility(View.VISIBLE);
} else { } else {
iconLayout.setVisibility(View.GONE); iconLayout.setVisibility(View.GONE);
} }
@ -374,14 +347,14 @@ public class MapContextMenuFragment extends Fragment {
private void buildBottomView() { private void buildBottomView() {
View bottomView = view.findViewById(R.id.context_menu_bottom_view); View bottomView = view.findViewById(R.id.context_menu_bottom_view);
if (menuController != null) { if (menu.isExtended()) {
bottomView.setOnTouchListener(new View.OnTouchListener() { bottomView.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
return true; return true;
} }
}); });
menuController.build(bottomView); menu.build(bottomView);
} }
} }
@ -398,15 +371,45 @@ public class MapContextMenuFragment extends Fragment {
bottomLayout.removeAllViews(); bottomLayout.removeAllViews();
buildBottomView(); buildBottomView();
recalculateFullHeightMax(); runLayoutListener();
} }
private void showOnMap(double latitude, double longitude) { private void runLayoutListener() {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
menuTopShadowHeight = view.findViewById(R.id.context_menu_top_shadow).getHeight();
menuTopShadowAllHeight = view.findViewById(R.id.context_menu_top_shadow_all).getHeight();
menuFullHeight = view.findViewById(R.id.context_menu_main).getHeight();
menuTitleHeight = menuTopShadowHeight + menuTopShadowAllHeight;
menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight();
recalculateFullHeightMax();
ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
doLayoutMenu();
}
});
}
private void showOnMap(LatLon latLon) {
MapActivity ctx = getMapActivity(); MapActivity ctx = getMapActivity();
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread(); AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
int fZoom = ctx.getMapView().getZoom(); int fZoom = ctx.getMapView().getZoom();
double flat = latitude; double flat = latLon.getLatitude();
double flon = longitude; double flon = latLon.getLongitude();
RotatedTileBox cp = ctx.getMapView().getCurrentRotatedTileBox().copy(); RotatedTileBox cp = ctx.getMapView().getCurrentRotatedTileBox().copy();
cp.setCenterLocation(0.5f, ctx.getMapView().getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f); cp.setCenterLocation(0.5f, ctx.getMapView().getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
@ -420,12 +423,12 @@ public class MapContextMenuFragment extends Fragment {
private void setAddressLocation() { private void setAddressLocation() {
// Text line 1 // Text line 1
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1); TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
line1.setText(getCtxMenu().getTitleStr()); line1.setText(menu.getTitleStr());
// Text line 2 // Text line 2
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2); TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(getCtxMenu().getLocationStr()); line2.setText(menu.getLocationStr());
Drawable icon = getCtxMenu().getSecondLineIcon(); Drawable icon = menu.getSecondLineIcon();
if (icon != null) { if (icon != null) {
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
line2.setCompoundDrawablePadding(dpToPx(5f)); line2.setCompoundDrawablePadding(dpToPx(5f));
@ -435,9 +438,9 @@ public class MapContextMenuFragment extends Fragment {
private int getPosY() { private int getPosY() {
int destinationState; int destinationState;
int minHalfY; int minHalfY;
if (menuController != null) { if (menu.isExtended()) {
destinationState = menuController.getCurrentMenuState(); destinationState = menu.getCurrentMenuState();
minHalfY = view.getHeight() - (int)(view.getHeight() * menuController.getHalfScreenMaxHeightKoef()); minHalfY = view.getHeight() - (int)(view.getHeight() * menu.getHalfScreenMaxHeightKoef());
} else { } else {
destinationState = MenuController.MenuState.HEADER_ONLY; destinationState = MenuController.MenuState.HEADER_ONLY;
minHalfY = view.getHeight(); minHalfY = view.getHeight();
@ -508,6 +511,14 @@ public class MapContextMenuFragment extends Fragment {
setAddressLocation(); setAddressLocation();
} }
public void setFragmentVisibility(boolean visible) {
if (visible) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
}
public OsmandApplication getMyApplication() { public OsmandApplication getMyApplication() {
if (getActivity() == null) { if (getActivity() == null) {
return null; return null;
@ -520,10 +531,10 @@ public class MapContextMenuFragment extends Fragment {
int slideInAnim = R.anim.slide_in_bottom; int slideInAnim = R.anim.slide_in_bottom;
int slideOutAnim = R.anim.slide_out_bottom; int slideOutAnim = R.anim.slide_out_bottom;
MenuController menuController = mapActivity.getContextMenu().getMenuController(); MapContextMenu menu = mapActivity.getContextMenu();
if (menuController != null) { if (menu.isExtended()) {
slideInAnim = menuController.getSlideInAnimation(); slideInAnim = menu.getSlideInAnimation();
slideOutAnim = menuController.getSlideOutAnimation(); slideOutAnim = menu.getSlideOutAnimation();
} }
MapContextMenuFragment fragment = new MapContextMenuFragment(); MapContextMenuFragment fragment = new MapContextMenuFragment();
@ -533,27 +544,10 @@ public class MapContextMenuFragment extends Fragment {
.addToBackStack(TAG).commit(); .addToBackStack(TAG).commit();
} }
private MapContextMenu getCtxMenu() {
return getMapActivity().getContextMenu();
}
private MapActivity getMapActivity() { private MapActivity getMapActivity() {
return (MapActivity)getActivity(); return (MapActivity)getActivity();
} }
// Utils
private int getScreenHeight() {
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
return dm.heightPixels;
}
private int getScreenWidth() {
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
return dm.widthPixels;
}
private int dpToPx(float dp) { private int dpToPx(float dp) {
Resources r = getActivity().getResources(); Resources r = getActivity().getResources();
return (int) TypedValue.applyDimension( return (int) TypedValue.applyDimension(

View file

@ -79,7 +79,8 @@ public class AmenityMenuController extends MenuController {
addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr); addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
} }
if (pointDescription != null) { if (pointDescription != null) {
addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(getMapActivity(), true).replaceAll("\n", "")); addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(),
amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", ""));
} }
} }

View file

@ -77,7 +77,8 @@ public class FavouritePointMenuController extends MenuController {
@Override @Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription) { public void addPlainMenuItems(String typeStr, PointDescription pointDescription) {
if (pointDescription != null) { if (pointDescription != null) {
addPlainMenuItem(R.drawable.map_my_location, pointDescription.getLocationName(getMapActivity(), true).replaceAll("\n", "")); addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(),
fav.getLatitude(), fav.getLongitude(), true).replaceAll("\n", ""));
} }
} }

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.editors;
import android.os.Bundle; import android.os.Bundle;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -41,12 +42,13 @@ public class FavoritePointEditor extends PointEditor {
return favorite; return favorite;
} }
public void add(PointDescription point) { public void add(LatLon latLon, String title) {
if (point == null) { if (latLon == null) {
return; return;
} }
isNew = true; isNew = true;
favorite = new FavouritePoint(point.getLat(), point.getLon(), point.getName(), app.getSettings().LAST_FAV_CATEGORY_ENTERED.get()); favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title,
app.getSettings().LAST_FAV_CATEGORY_ENTERED.get());
favorite.setDescription(""); favorite.setDescription("");
FavoritePointEditorFragment.showInstance(mapActivity); FavoritePointEditorFragment.showInstance(mapActivity);
} }

View file

@ -9,6 +9,7 @@ import android.os.Bundle;
import android.util.Log; import android.util.Log;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
@ -127,11 +128,12 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
} }
MapContextMenu menu = getMapActivity().getContextMenu(); MapContextMenu menu = getMapActivity().getContextMenu();
if (menu.getObject() == favorite) { LatLon latLon = new LatLon(favorite.getLatitude(), favorite.getLongitude());
if (menu.getLatLon().equals(latLon)) {
PointDescription pointDescription = favorite.getPointDescription(); PointDescription pointDescription = favorite.getPointDescription();
pointDescription.setLat(favorite.getLatitude()); pointDescription.setLat(favorite.getLatitude());
pointDescription.setLon(favorite.getLongitude()); pointDescription.setLon(favorite.getLongitude());
menu.refreshMenu(pointDescription, favorite); menu.refreshMenu(latLon, pointDescription, favorite);
} }
} }

View file

@ -25,6 +25,7 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.editors.dialogs.SelectCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.dialogs.SelectCategoryDialogFragment;
import net.osmand.plus.widgets.AutoCompleteTextViewEx; import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -139,6 +140,18 @@ public abstract class PointEditorFragment extends Fragment {
light ? R.color.icon_color : R.color.icon_color_light); light ? R.color.icon_color : R.color.icon_color_light);
} }
@Override
public void onStart() {
super.onStart();
getMapActivity().getContextMenu().setBaseFragmentVisibility(false);
}
@Override
public void onStop() {
super.onStop();
getMapActivity().getContextMenu().setBaseFragmentVisibility(true);
}
@Override @Override
public void onDestroyView() { public void onDestroyView() {
if (!wasSaved() && !getEditor().isNew()) { if (!wasSaved() && !getEditor().isNew()) {
@ -199,8 +212,7 @@ public abstract class PointEditorFragment extends Fragment {
if (includingMenu) { if (includingMenu) {
//getMapActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); //getMapActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
getMapActivity().getSupportFragmentManager().popBackStack(); getMapActivity().getSupportFragmentManager().popBackStack();
getMapActivity().getMapLayers().getContextMenuLayer().hideMapContextMenuMarker(); getMapActivity().getContextMenu().close();
getMapActivity().getContextMenu().hide();
} else { } else {
getMapActivity().getSupportFragmentManager().popBackStack(); getMapActivity().getSupportFragmentManager().popBackStack();
} }

View file

@ -1,37 +1,6 @@
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import gnu.trove.list.array.TIntArrayList;
import java.io.File;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.Algorithms;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -58,6 +27,38 @@ import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmAndListFragment;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.Algorithms;
import java.io.File;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import gnu.trove.list.array.TIntArrayList;
public class SelectedGPXFragment extends OsmAndListFragment { public class SelectedGPXFragment extends OsmAndListFragment {
public static final String ARG_TO_EXPAND_TRACK_INFO = "ARG_TO_EXPAND_TRACK_INFO"; public static final String ARG_TO_EXPAND_TRACK_INFO = "ARG_TO_EXPAND_TRACK_INFO";
@ -475,7 +476,19 @@ public class SelectedGPXFragment extends OsmAndListFragment {
@Override @Override
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
GpxDisplayItem child = adapter.getItem(position); GpxDisplayItem child = adapter.getItem(position);
final OsmandSettings settings = app.getSettings();
LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon);
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(),
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, Html.fromHtml(child.name).toString()),
false,
child.locationStart); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
/*
// if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS || // if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS ||
// child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) { // child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext()); ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
@ -491,5 +504,6 @@ public class SelectedGPXFragment extends OsmAndListFragment {
// child.expanded = !child.expanded; // child.expanded = !child.expanded;
// adapter.notifyDataSetInvalidated(); // adapter.notifyDataSetInvalidated();
// } // }
*/
} }
} }

View file

@ -347,11 +347,11 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
boolean sameId = Algorithms.objectEquals(followTrackerId, device.trackerId); boolean sameId = Algorithms.objectEquals(followTrackerId, device.trackerId);
if(sameId && !schedule && l != null) { if(sameId && !schedule && l != null) {
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer(); ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
final boolean sameObject; final boolean sameObject;
if(cl.getFirstSelectedObject() instanceof OsMoDevice && cl.isVisible()) { if (map.getContextMenu().getObject() instanceof OsMoDevice && cl.isVisible()) {
sameObject = Algorithms.objectEquals(device.trackerId, ((OsMoDevice) cl.getFirstSelectedObject()).trackerId) ; sameObject = Algorithms.objectEquals(device.trackerId, ((OsMoDevice) map.getContextMenu().getObject()).trackerId);
} else{ } else {
sameObject = false; sameObject = false;
} }
LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude()); LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude());
final boolean centered = followMapLocation != null && MapUtils.getDistance(mapLoc, followMapLocation) < 1; final boolean centered = followMapLocation != null && MapUtils.getDistance(mapLoc, followMapLocation) < 1;
@ -373,10 +373,10 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
public void run() { public void run() {
schedule = false; schedule = false;
if (sameObject) { if (sameObject) {
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
Location l = device.getLastLocation(); Location l = device.getLastLocation();
cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device)); map.getContextMenu().show(new LatLon(l.getLatitude(), l.getLongitude()), getObjectName(device), device);
cl.setSelectedObject(device); //cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device));
//cl.setSelectedObject(device);
} }
if (centered) { if (centered) {
map.getMapView().setLatLon(loc.getLatitude(), map.getMapView().setLatLon(loc.getLatitude(),
@ -408,7 +408,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
} }
@Override @Override
public void clearSelectedObjects() { public void clearSelectedObject() {
LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude()); LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude());
final boolean centered = Algorithms.objectEquals(followMapLocation, mapLoc); final boolean centered = Algorithms.objectEquals(followMapLocation, mapLoc);
if(!centered && followTrackerId != null) { if(!centered && followTrackerId != null) {

View file

@ -3,19 +3,16 @@ package net.osmand.plus.views;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build; import android.support.annotation.NonNull;
import android.text.Html;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.Gravity;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.FrameLayout.LayoutParams; import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -23,110 +20,58 @@ import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
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.mapcontextmenu.MapContextMenu;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
public class ContextMenuLayer extends OsmandMapLayer { public class ContextMenuLayer extends OsmandMapLayer {
public interface IContextMenuProvider { public interface IContextMenuProvider {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o); void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o);
public LatLon getObjectLocation(Object o); LatLon getObjectLocation(Object o);
String getObjectDescription(Object o);
PointDescription getObjectName(Object o);
// todo: remove boolean disableSingleTap();
public String getObjectDescription(Object o); boolean disableLongPressOnMap();
public PointDescription getObjectName(Object o);
public boolean disableSingleTap();
public boolean disableLongPressOnMap();
} }
public interface IContextMenuProviderSelection { public interface IContextMenuProviderSelection {
public void setSelectedObject(Object o); void setSelectedObject(Object o);
void clearSelectedObject();
public void clearSelectedObjects();
} }
private static final String KEY_LAT_LAN = "context_menu_lat_lon";
private static final String KEY_DESCRIPTION = "context_menu_description";
private static final String KEY_SELECTED_OBJECTS = "context_menu_selected_objects";
private LatLon latLon;
private String description;
private Map<Object, IContextMenuProvider> selectedObjects = new ConcurrentHashMap<Object, IContextMenuProvider>();
private TextView textView;
private ImageView closeButton;
private OsmandMapTileView view; private OsmandMapTileView view;
private int BASE_TEXT_SIZE = 170;
private final MapActivity activity; private final MapActivity activity;
private float scaleCoefficient = 1; private MapContextMenu menu;
private CallbackWithObject<LatLon> selectOnMap = null; private CallbackWithObject<LatLon> selectOnMap = null;
private boolean showContextMarker;
private ImageView contextMarker; private ImageView contextMarker;
private GestureDetector movementListener; private GestureDetector movementListener;
public ContextMenuLayer(MapActivity activity){ public ContextMenuLayer(MapActivity activity){
this.activity = activity; this.activity = activity;
menu = activity.getContextMenu();
movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener()); movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener());
if(activity.getLastNonConfigurationInstanceByKey(KEY_LAT_LAN) != null) {
latLon = (LatLon) activity.getLastNonConfigurationInstanceByKey(KEY_LAT_LAN);
description = (String) activity.getLastNonConfigurationInstanceByKey(KEY_DESCRIPTION);
if(activity.getLastNonConfigurationInstanceByKey(KEY_SELECTED_OBJECTS) != null) {
selectedObjects = (Map<Object, IContextMenuProvider>) activity.getLastNonConfigurationInstanceByKey(KEY_SELECTED_OBJECTS);
}
}
} }
@Override @Override
public void destroyLayer() { public void destroyLayer() {
} }
public Object getFirstSelectedObject() {
if(!selectedObjects.isEmpty()) {
return selectedObjects.keySet().iterator().next();
}
return null;
}
@Override @Override
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
scaleCoefficient = view.getDensity();
BASE_TEXT_SIZE = (int) (BASE_TEXT_SIZE * scaleCoefficient);
textView = new TextView(view.getContext());
LayoutParams lp = new LayoutParams(BASE_TEXT_SIZE, LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(lp);
textView.setTextSize(15);
textView.setTextColor(Color.argb(255, 0, 0, 0));
textView.setMinLines(1);
// textView.setMaxLines(15);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setClickable(true);
textView.setBackgroundDrawable(view.getResources().getDrawable(R.drawable.box_free));
textView.setTextColor(Color.WHITE);
closeButton = new ImageView(view.getContext());
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
closeButton.setLayoutParams(lp);
closeButton.setImageDrawable(view.getResources().getDrawable(R.drawable.headliner_close));
closeButton.setClickable(true);
showContextMarker = false;
contextMarker = new ImageView(view.getContext()); contextMarker = new ImageView(view.getContext());
contextMarker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); contextMarker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
contextMarker.setImageDrawable(view.getResources().getDrawable(R.drawable.map_pin_context_menu)); contextMarker.setImageDrawable(view.getResources().getDrawable(R.drawable.map_pin_context_menu));
@ -134,146 +79,39 @@ public class ContextMenuLayer extends OsmandMapLayer {
int minw = contextMarker.getDrawable().getMinimumWidth(); int minw = contextMarker.getDrawable().getMinimumWidth();
int minh = contextMarker.getDrawable().getMinimumHeight(); int minh = contextMarker.getDrawable().getMinimumHeight();
contextMarker.layout(0, 0, minw, minh); contextMarker.layout(0, 0, minw, minh);
if(latLon != null){
setLocation(latLon, description);
}
} }
public boolean isVisible() { public boolean isVisible() {
return latLon != null; return menu.isActive();
} }
@Override @Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) { public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
if(latLon != null){ if(menu.isActive()) {
LatLon latLon = menu.getLatLon();
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
if (showContextMarker) { contextMarker.draw(canvas);
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
contextMarker.draw(canvas);
}
textView.setTextColor(nightMode != null && nightMode.isNightMode() ? Color.GRAY : Color.WHITE);
if (textView.getText().length() > 0) {
canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight());
int c = textView.getLineCount();
textView.draw(canvas);
//textView.getHeight() - closeButton.getHeight()
canvas.translate(textView.getWidth() - closeButton.getWidth(), 0);
closeButton.draw(canvas);
if (c == 0) {
// special case relayout after on draw method
layoutText();
view.refreshMap();
} else if (c == 1) {
// make 2 line description
String des = textView.getText() + "\n ";
textView.setText(des);
layoutText();
view.refreshMap();
}
}
} }
} }
public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) { public void setSelectOnMap(CallbackWithObject<LatLon> selectOnMap) {
hideMapContextMenuMarker();
this.selectOnMap = selectOnMap; this.selectOnMap = selectOnMap;
} }
private void layoutText() {
Rect padding = new Rect();
if (textView.getLineCount() > 0) {
textView.getBackground().getPadding(padding);
}
int w = BASE_TEXT_SIZE;
int h = (int) ((textView.getPaint().getTextSize() * 1.3f) * textView.getLineCount());
textView.layout(0, 0, w, h + padding.top + padding.bottom);
int minw = closeButton.getDrawable().getMinimumWidth();
int minh = closeButton.getDrawable().getMinimumHeight();
closeButton.layout(0, 0, minw, minh);
}
public void showMapContextMenuMarker() { private void clearSelectedObjects(Map<Object, IContextMenuProvider> selectedObjects) {
showContextMarker = true; for(IContextMenuProvider p : selectedObjects.values()) {
view.refreshMap();
}
public void showMapContextMenuMarker(LatLon latLon) {
activity.getContextMenu().hide();
this.latLon = latLon;
showMapContextMenuMarker();
}
public void hideMapContextMenuMarker() {
if (showContextMarker) {
showContextMarker = false;
view.refreshMap();
}
}
// Opens black box menu
// todo: needs to be removed (exchanged completly by new context menu)
public void setLocation(LatLon loc, String description){
latLon = loc;
if(latLon != null){
if(description == null){
description = new PointDescription(loc.getLatitude(), loc.getLongitude()).getFullPlainName(activity);
}
textView.setText(Html.fromHtml(description.replace("\n", "<br/>")));
} else {
textView.setText(""); //$NON-NLS-1$
}
layoutText();
}
public void setSelections(Map<Object, IContextMenuProvider> selections) {
clearSelectedObjects();
if (selections != null) {
selectedObjects = selections;
}
if (!selectedObjects.isEmpty()) {
Entry<Object, IContextMenuProvider> e = selectedObjects.entrySet().iterator().next();
latLon = e.getValue().getObjectLocation(e.getKey());
if(e.getValue() instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) e.getValue()).setSelectedObject(e.getKey());
}
}
}
private void clearSelectedObjects() {
for(IContextMenuProvider p : this.selectedObjects.values()) {
if(p instanceof IContextMenuProviderSelection){ if(p instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) p).clearSelectedObjects(); ((IContextMenuProviderSelection) p).clearSelectedObject();
} }
} }
selectedObjects.clear();
} }
@Override @Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if ((Build.VERSION.SDK_INT < 14) && !view.getSettings().SCROLL_MAP_BY_GESTURES.get()) {
if (!selectedObjects.isEmpty())
view.showMessage(activity.getMyApplication().getLocationProvider().getNavigationHint(latLon));
return true;
}
if(pressedInTextView(tileBox, point.x, point.y) > 0){
setLocation(null, ""); //$NON-NLS-1$
view.refreshMap();
return true;
}
if (disableLongPressOnMap()) { if (disableLongPressOnMap()) {
return false; return false;
} }
@ -289,29 +127,43 @@ public class ContextMenuLayer extends OsmandMapLayer {
return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation); return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation);
} }
public boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) { private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
LatLon latLon = selectObjectsForContextMenu(tileBox, point); Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point);
if (latLon != null) { if (selectedObjects.size() == 1) {
if (selectedObjects.size() == 1) { Object selectedObj = selectedObjects.keySet().iterator().next();
setLocation(null, ""); IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
Object selectedObj = selectedObjects.keySet().iterator().next(); LatLon latLon = null;
IContextMenuProvider contextObject = selectedObjects.get(selectedObj); PointDescription pointDescription = null;
showMapContextMenu(latLon, selectedObj, contextObject); if (contextObject != null) {
return true; latLon = contextObject.getObjectLocation(selectedObj);
} else if (selectedObjects.size() > 1) { pointDescription = contextObject.getObjectName(selectedObj);
showContextMenuForSelectedObjects(latLon);
return true;
} }
if (latLon == null) {
latLon = getLatLon(point, tileBox);
}
menu.show(latLon, pointDescription, selectedObj);
return true;
} else if (selectedObjects.size() > 1) {
showContextMenuForSelectedObjects(getLatLon(point, tileBox), selectedObjects);
return true;
} else if (showUnknownLocation) { } else if (showUnknownLocation) {
setLocation(null, ""); menu.show(getLatLon(point, tileBox), null, null);
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
showMapContextMenu(new LatLon(lat, lon));
return true; return true;
} }
return false; return false;
} }
@NonNull
private LatLon getLatLon(PointF point, RotatedTileBox tileBox) {
LatLon latLon;
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
latLon = new LatLon(lat, lon);
return latLon;
}
public boolean disableSingleTap() { public boolean disableSingleTap() {
boolean res = false; boolean res = false;
for(OsmandMapLayer lt : view.getLayers()){ for(OsmandMapLayer lt : view.getLayers()){
@ -338,55 +190,33 @@ public class ContextMenuLayer extends OsmandMapLayer {
return res; return res;
} }
public LatLon selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) { private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
clearSelectedObjects(); Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
List<Object> s = new ArrayList<Object>(); List<Object> s = new ArrayList<>();
LatLon latLon = null; for (OsmandMapLayer lt : view.getLayers()) {
for(OsmandMapLayer lt : view.getLayers()){ if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
if(lt instanceof ContextMenuLayer.IContextMenuProvider){
s.clear(); s.clear();
final IContextMenuProvider l = (ContextMenuLayer.IContextMenuProvider) lt; final IContextMenuProvider l = (ContextMenuLayer.IContextMenuProvider) lt;
l.collectObjectsFromPoint(point, tileBox, s); l.collectObjectsFromPoint(point, tileBox, s);
for(Object o : s) { for (Object o : s) {
selectedObjects.put(o, l); selectedObjects.put(o, l);
if(l instanceof IContextMenuProviderSelection){ if (l instanceof IContextMenuProviderSelection) {
((IContextMenuProviderSelection) l).setSelectedObject(o); ((IContextMenuProviderSelection) l).setSelectedObject(o);
} }
if(latLon == null) {
latLon = l.getObjectLocation(o);
}
} }
} }
} }
return latLon; return selectedObjects;
} }
@Override @Override
public boolean drawInScreenPixels() { public boolean drawInScreenPixels() {
return true; return true;
} }
public int pressedInTextView(RotatedTileBox tb, float px, float py) {
if (latLon != null && textView.getText().length() > 0) {
Rect bs = textView.getBackground().getBounds();
Rect closes = closeButton.getDrawable().getBounds();
int dx = (int) (px - tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
int dy = (int) (py - tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
int bx = dx + bs.width() / 2;
int by = dy + bs.height();
int dclosex = bx - bs.width() ;
int dclosey = by;
if (dclosex >= -closes.width() && dclosey >= 0 && dclosex <= 0 && dclosey <= closes.height()) {
return 2;
} else if (bs.contains(bx, by)) {
return 1;
}
}
return 0;
}
public boolean pressedContextMarker(RotatedTileBox tb, float px, float py) { public boolean pressedContextMarker(RotatedTileBox tb, float px, float py) {
if (latLon != null && showContextMarker) { if (menu.isActive()) {
LatLon latLon = menu.getLatLon();
Rect bs = contextMarker.getDrawable().getBounds(); Rect bs = contextMarker.getDrawable().getBounds();
int dx = (int) (px - tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude())); int dx = (int) (px - tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
int dy = (int) (py - tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude())); int dy = (int) (py - tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
@ -397,218 +227,84 @@ public class ContextMenuLayer extends OsmandMapLayer {
return false; return false;
} }
public String getSelectedObjectName(){
return getSelectedObjectInfo(true);
}
public List<PointDescription> getSelectedObjectNames() {
List<PointDescription> list = new ArrayList<PointDescription>();
Iterator<Entry<Object, IContextMenuProvider>> it = selectedObjects.entrySet().iterator();
while (it.hasNext()) {
Entry<Object, IContextMenuProvider> e = it.next();
PointDescription onames = e.getValue().getObjectName(e.getKey());
if (onames != null) {
list.add(onames);
}
}
return list;
}
public String getSelectedObjectDescription(){
return getSelectedObjectInfo(false);
}
private String getSelectedObjectInfo(boolean name){
if(!selectedObjects.isEmpty()){
StringBuilder description = new StringBuilder();
if (selectedObjects.size() > 1) {
description.append("1. ");
}
Iterator<Entry<Object, IContextMenuProvider>> it = selectedObjects.entrySet().iterator();
int i = 0;
while(it.hasNext()) {
Entry<Object, IContextMenuProvider> e = it.next();
if( i > 0) {
description.append("\n" + (i + 1) + ". ");
}
if(name) {
PointDescription nm = e.getValue().getObjectName(e.getKey());
description.append(nm.getFullPlainName(activity));
} else {
description.append(e.getValue().getObjectDescription(e.getKey()));
}
i++;
}
return description.toString();
}
return null;
}
@Override @Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (pressedContextMarker(tileBox, point.x, point.y)) { if (pressedContextMarker(tileBox, point.x, point.y)) {
showMapContextMenu(); menu.show();
return true; return true;
} }
boolean nativeMode = (Build.VERSION.SDK_INT >= 14) || view.getSettings().SCROLL_MAP_BY_GESTURES.get();
int val = pressedInTextView(tileBox, point.x, point.y);
if(selectOnMap != null) { if(selectOnMap != null) {
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y); LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
CallbackWithObject<LatLon> cb = selectOnMap; CallbackWithObject<LatLon> cb = selectOnMap;
cb.processResult(latlon); cb.processResult(latlon);
showMapContextMenu(latlon); menu.init(latlon, null, null);
selectOnMap = null; selectOnMap = null;
return true; return true;
} }
if (val == 2) {
setLocation(null, ""); //$NON-NLS-1$ if (!disableSingleTap()) {
view.refreshMap();
return true;
} else if (val == 1 || !nativeMode) {
if (!selectedObjects.isEmpty()) {
showContextMenuForSelectedObjects(latLon);
} else if (nativeMode) {
activity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude());
}
return true;
} else if (!disableSingleTap()) {
boolean res = showContextMenu(point, tileBox, false); boolean res = showContextMenu(point, tileBox, false);
if (res) { if (res) {
return true; return true;
} }
} }
activity.getContextMenu().onSingleTapOnMap(); menu.onSingleTapOnMap();
return false; return false;
} }
public void showContextMenuForSelectedObjects(final LatLon l) { private void showContextMenuForSelectedObjects(final LatLon latLon, final Map<Object, IContextMenuProvider> selectedObjects) {
if (selectedObjects.size() > 1) { Builder builder = new AlertDialog.Builder(view.getContext());
Builder builder = new AlertDialog.Builder(view.getContext()); String[] d = new String[selectedObjects.size()];
String[] d = new String[selectedObjects.size()]; final List<Object> s = new ArrayList<>();
final List<Object> s = new ArrayList<Object>(); int i = 0;
int i = 0; for (Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
Iterator<Entry<Object, IContextMenuProvider>> it = selectedObjects.entrySet().iterator(); d[i++] = e.getValue().getObjectDescription(e.getKey());
while(it.hasNext()) { s.add(e.getKey());
Entry<Object, IContextMenuProvider> e = it.next(); }
d[i++] = e.getValue().getObjectDescription(e.getKey()); builder.setItems(d, new OnClickListener() {
s.add(e.getKey()); @Override
} public void onClick(DialogInterface dialog, int which) {
builder.setItems(d, new OnClickListener() { Object selectedObj = s.get(which);
@Override IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
public void onClick(DialogInterface dialog, int which) { LatLon ll = null;
Object selectedObj = s.get(which); PointDescription pointDescription = null;
IContextMenuProvider contextObject = selectedObjects.get(selectedObj); if (contextObject != null) {
showMapContextMenu(l, selectedObj, contextObject); ll = contextObject.getObjectLocation(selectedObj);
pointDescription = contextObject.getObjectName(selectedObj);
} }
}); if (ll == null) {
builder.show(); ll = latLon;
} else { }
Object selectedObj = selectedObjects.keySet().iterator().next(); menu.show(ll, pointDescription, selectedObj);
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(l, selectedObj, contextObject);
}
}
public void showMapContextMenu() { selectedObjects.remove(selectedObj);
activity.getContextMenu().show(); clearSelectedObjects(selectedObjects);
}
public void showMapContextMenu(LatLon latLon) {
showMapContextMenu(latLon, null);
}
public void showMapContextMenu(LatLon latLon, String title) {
showMapContextMenu(latLon, title, null, null);
}
public void showMapContextMenu(LatLon latLon, Object selectedObj, IContextMenuProvider contextObject) {
showMapContextMenu(latLon, null, selectedObj, contextObject);
}
public void showMapContextMenu(LatLon latLon, String title, Object selectedObj, IContextMenuProvider contextObject) {
PointDescription pointDescription;
if (selectedObj != null && contextObject != null) {
pointDescription = contextObject.getObjectName(selectedObj);
LatLon objLocation = contextObject.getObjectLocation(selectedObj);
pointDescription.setLat(objLocation.getLatitude());
pointDescription.setLon(objLocation.getLongitude());
} else {
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
if (title != null) {
pointDescription.setName(title);
} }
} });
this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon()); builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
clearSelectedObjects(selectedObjects);
}
});
showMapContextMenuMarker(); builder.show();
if (selectOnMap != null) {
activity.getContextMenu().init(pointDescription, selectedObj);
} else {
activity.getContextMenu().show(pointDescription, selectedObj);
}
} }
@Override @Override
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (movementListener.onTouchEvent(event)) { if (movementListener.onTouchEvent(event)) {
if (activity.getContextMenu().isMenuVisible()) { if (menu.isVisible()) {
activity.getContextMenu().hide(); menu.hide();
} }
} }
if (latLon != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
int vl = pressedInTextView(tileBox, event.getX(), event.getY());
if(vl == 1){
textView.setPressed(true);
view.refreshMap();
} else if(vl == 2){
closeButton.setPressed(true);
view.refreshMap();
}
}
}
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
if(textView.isPressed()) {
textView.setPressed(false);
view.refreshMap();
}
if(closeButton.isPressed()) {
closeButton.setPressed(false);
view.refreshMap();
}
}
return false; return false;
} }
public void setSelectedObject(Object toShow) {
clearSelectedObjects();
if(toShow != null){
for(OsmandMapLayer l : view.getLayers()){
if(l instanceof ContextMenuLayer.IContextMenuProvider){
String des = ((ContextMenuLayer.IContextMenuProvider) l).getObjectDescription(toShow);
if(des != null) {
selectedObjects.put(toShow, (IContextMenuProvider) l);
if(l instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) l).setSelectedObject(toShow);
}
}
}
}
}
}
@Override
public void onRetainNonConfigurationInstance(Map<String, Object> map) {
map.put(KEY_LAT_LAN, latLon);
map.put(KEY_SELECTED_OBJECTS, selectedObjects);
map.put(KEY_DESCRIPTION, textView.getText().toString());
}
private class MenuLayerOnGestureListener extends GestureDetector.SimpleOnGestureListener { private class MenuLayerOnGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override @Override

View file

@ -233,8 +233,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}); });
mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(), mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity, this);
mapActivity, this);
View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button); View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button);
controls.add(createHudButton((ImageView) waypointsButton, R.drawable.map_action_waypoints).setBg( controls.add(createHudButton((ImageView) waypointsButton, R.drawable.map_action_waypoints).setBg(

View file

@ -232,7 +232,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
targetPointsHelper.removeWayPoint(true, -1); targetPointsHelper.removeWayPoint(true, -1);
} }
} }
map.getMapLayers().getContextMenuLayer().setLocation(null, ""); map.getContextMenu().close();
return true; return true;
} }
}; };

View file

@ -36,10 +36,10 @@ import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.activities.search.SearchAddressActivity; import net.osmand.plus.activities.search.SearchAddressActivity;
import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.dialogs.FavoriteDialogs; import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapControlsLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.controls.MapRoutePreferencesControl.RoutePrepareDialog; import net.osmand.plus.views.controls.MapRoutePreferencesControl.RoutePrepareDialog;
@ -52,7 +52,7 @@ import java.util.Set;
public class MapRouteInfoControl implements IRouteInformationListener { public class MapRouteInfoControl implements IRouteInformationListener {
public static int directionInfo = -1; public static int directionInfo = -1;
public static boolean controlVisible = false; public static boolean controlVisible = false;
private final ContextMenuLayer contextMenu; private final MapContextMenu contextMenu;
private final RoutingHelper routingHelper; private final RoutingHelper routingHelper;
private OsmandMapTileView mapView; private OsmandMapTileView mapView;
private Dialog dialog; private Dialog dialog;
@ -64,11 +64,10 @@ public class MapRouteInfoControl implements IRouteInformationListener {
private MapControlsLayer mapControlsLayer; private MapControlsLayer mapControlsLayer;
public static final String TARGET_SELECT = "TARGET_SELECT"; public static final String TARGET_SELECT = "TARGET_SELECT";
public MapRouteInfoControl(ContextMenuLayer contextMenu, public MapRouteInfoControl(MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
this.contextMenu = contextMenu;
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
this.mapControlsLayer = mapControlsLayer; this.mapControlsLayer = mapControlsLayer;
contextMenu = mapActivity.getContextMenu();
routingHelper = mapActivity.getRoutingHelper(); routingHelper = mapActivity.getRoutingHelper();
mapView = mapActivity.getMapView(); mapView = mapActivity.getMapView();
routingHelper.addListener(this); routingHelper.addListener(this);
@ -83,7 +82,7 @@ public class MapRouteInfoControl implements IRouteInformationListener {
} else { } else {
getTargets().setStartPoint(latlon, true, null); getTargets().setStartPoint(latlon, true, null);
} }
contextMenu.setLocation(latlon, null); contextMenu.show(latlon, null, null);
showDialog(); showDialog();
return true; return true;
} }
@ -340,8 +339,9 @@ public class MapRouteInfoControl implements IRouteInformationListener {
if (routingHelper.getRouteDirections().size() > directionInfo) { if (routingHelper.getRouteDirections().size() > directionInfo) {
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), contextMenu.show(new LatLon(l.getLatitude(), l.getLongitude()), null, info);
info.getDescriptionRoute(ctx)); // contextMenuLayer.setLocation(new LatLon(l.getLatitude(), l.getLongitude()),
// info.getDescriptionRoute(ctx));
mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(),
mapView.getZoom(), true); mapView.getZoom(), true);
} }
@ -364,7 +364,8 @@ public class MapRouteInfoControl implements IRouteInformationListener {
directionInfo++; directionInfo++;
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
contextMenu.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx)); contextMenu.show(new LatLon(l.getLatitude(), l.getLongitude()), null, info);
// contextMenuLayer.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), info.getDescriptionRoute(ctx));
mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), mapView.getZoom(), true); mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), mapView.getZoom(), true);
} }
mapView.refreshMap(); mapView.refreshMap();