Context menu refactoring done
This commit is contained in:
parent
6e096461f7
commit
914e7a35c1
27 changed files with 546 additions and 927 deletions
|
@ -28,21 +28,6 @@ public class MapAccessibilityActions implements AccessibilityActionsProvider {
|
|||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get())
|
||||
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
|
||||
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 true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,17 +61,11 @@ public class MapExplorer extends SimpleOnGestureListener implements IContextMenu
|
|||
|
||||
@Override
|
||||
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);
|
||||
} else {
|
||||
describePointedObjects(mapView.getCurrentRotatedTileBox(), e2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPress(MotionEvent e) {
|
||||
if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get())
|
||||
fallback.onShowPress(e);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,18 +43,6 @@ public class PointDescription implements Serializable {
|
|||
|
||||
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) {
|
||||
this(POINT_TYPE_LOCATION, "");
|
||||
this.lat = lat;
|
||||
|
@ -141,11 +129,7 @@ public class PointDescription implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public String getLocationName(Context ctx, boolean shortText) {
|
||||
return getLocationName(ctx, lat, lon, shortText);
|
||||
}
|
||||
|
||||
private String getLocationName(Context ctx, double lat, double lon, boolean sh) {
|
||||
public static String getLocationName(Context ctx, double lat, double lon, boolean sh) {
|
||||
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
|
||||
int f = st.COORDINATES_FORMAT.get();
|
||||
if (f == PointDescription.UTM_FORMAT) {
|
||||
|
|
|
@ -5,7 +5,6 @@ package net.osmand.plus.activities;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
@ -20,6 +19,7 @@ import android.widget.TextView;
|
|||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
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.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -133,7 +132,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA
|
|||
|
||||
if (!isSelectFavoriteMode()) {
|
||||
FavouritePoint point = favouritesAdapter.getItem(position);
|
||||
showItemPopupOptionsMenu(point, getActivity(), v);
|
||||
showOnMap(point, getActivity());
|
||||
} else {
|
||||
Intent intent = getActivity().getIntent();
|
||||
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() {
|
||||
@Override
|
||||
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());
|
||||
final PopupMenu optionsMenu = new PopupMenu(activity, view);
|
||||
DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location,
|
||||
point, point.getPointDescription(),
|
||||
((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapZoom(),
|
||||
activity, true, false);
|
||||
optionsMenu.show();
|
||||
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
|
||||
settings.getLastKnownMapZoom(),
|
||||
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
|
||||
true,
|
||||
point); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(activity);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import android.os.Handler;
|
|||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -52,7 +51,6 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
|
@ -182,8 +180,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
updateSelectionMode(actionMode);
|
||||
} else {
|
||||
final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition);
|
||||
showItemPopupOptionsMenu(point, v);
|
||||
final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
|
||||
showOnMap(point);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -802,7 +800,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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();
|
||||
LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
|
||||
DirectionsDialogs.createDirectionActionsPopUpMenu(optionsMenu, location, point,
|
||||
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
|
||||
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
|
||||
settings.getLastKnownMapZoom(),
|
||||
getActivity(), true, false);
|
||||
|
||||
MenuItem item = optionsMenu.getMenu().add(R.string.favourites_context_menu_edit)
|
||||
.setIcon(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_edit_dark));
|
||||
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();
|
||||
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
|
||||
true,
|
||||
point); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -545,13 +545,8 @@ public class MapActivity extends AccessibleActivity {
|
|||
dashboardOnMap.hideDashboard();
|
||||
}
|
||||
if (mapLabelToShow != null) {
|
||||
mapLayers.getContextMenuLayer().setSelectedObject(toShow);
|
||||
// if (toShow instanceof FavouritePoint) {
|
||||
// mapLayers.getContextMenuLayer().showContextMenuForSelectedObjects(latLonToShow);
|
||||
// } else {
|
||||
mapLayers.getContextMenuLayer().setLocation(latLonToShow,
|
||||
mapLabelToShow.getFullPlainName(this));
|
||||
// }
|
||||
contextMenuOnMap.show(latLonToShow, mapLabelToShow, toShow);
|
||||
//mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow.getFullPlainName(this));
|
||||
}
|
||||
if (!latLonToShow.equals(cur)) {
|
||||
mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(),
|
||||
|
|
|
@ -91,17 +91,6 @@ public class MapActivityActions implements DialogProvider {
|
|||
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) {
|
||||
enhance(dialogBundle,latitude,longitude,mapActivity.getMapView().getZoom());
|
||||
new ShareLocation(mapActivity).run();
|
||||
|
@ -143,15 +132,14 @@ public class MapActivityActions implements DialogProvider {
|
|||
targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, null);
|
||||
enterRoutePlanningMode(null, null, false);
|
||||
} else if (standardId == R.string.context_menu_item_directions_from) {
|
||||
List<PointDescription> nms = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectNames();
|
||||
enterRoutePlanningMode(new LatLon(latitude, longitude), nms.isEmpty() ? null : nms.get(0), false);
|
||||
enterRoutePlanningMode(new LatLon(latitude, longitude),
|
||||
mapActivity.getContextMenu().getPointDescription(), false);
|
||||
} else if (standardId == R.string.context_menu_item_intermediate_point ||
|
||||
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,
|
||||
dest ? -1 : targets.getIntermediatePoints().size(), nms.size() == 0?null :
|
||||
nms.get(0));
|
||||
dest ? -1 : targets.getIntermediatePoints().size(),
|
||||
mapActivity.getContextMenu().getPointDescription());
|
||||
if(targets.getIntermediatePoints().size() > 0) {
|
||||
openIntermediatePointsDialog();
|
||||
}
|
||||
|
@ -177,7 +165,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
|
||||
|
||||
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);
|
||||
mapActivity.showDialog(DIALOG_ADD_WAYPOINT);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -230,11 +231,14 @@ public class SearchAddressOnlineFragment extends Fragment implements SearchActiv
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Place item = adapter.getItem(position);
|
||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
|
||||
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, new LatLon(item.lat, item.lon), item,
|
||||
new PointDescription(PointDescription.POINT_TYPE_ADDRESS, item.displayName), Math.max(15, settings.getLastKnownMapZoom()),
|
||||
getActivity(), true);
|
||||
optionsMenu.show();
|
||||
|
||||
LatLon location = new LatLon(item.lat, item.lon);
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
|
||||
Math.max(15, settings.getLastKnownMapZoom()),
|
||||
new PointDescription(PointDescription.POINT_TYPE_ADDRESS, item.displayName),
|
||||
true,
|
||||
item); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
||||
private static class Place {
|
||||
|
|
|
@ -1,22 +1,5 @@
|
|||
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.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -24,11 +7,9 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
@ -41,6 +22,24 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
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 {
|
||||
private LatLon location;
|
||||
|
@ -174,28 +173,21 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
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();
|
||||
boolean light = ((OsmandApplication) getActivity().getApplication()).getSettings().isLightContent();
|
||||
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
|
||||
OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
|
||||
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, new LatLon(model.getLat(), model.getLon()),
|
||||
model, name, settings.getLastKnownMapZoom(), getActivity(), true);
|
||||
MenuItem item = optionsMenu.getMenu().add(
|
||||
R.string.shared_string_delete).setIcon(
|
||||
getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_delete_dark));
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
helper.remove(model);
|
||||
historyAdapter.remove(model);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
optionsMenu.show();
|
||||
|
||||
LatLon location = new LatLon(model.getLat(), model.getLon());
|
||||
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
|
||||
settings.getLastKnownMapZoom(),
|
||||
name,
|
||||
true,
|
||||
model); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
||||
class HistoryAdapter extends ArrayAdapter<HistoryEntry> {
|
||||
|
@ -230,7 +222,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectModel(historyEntry, v);
|
||||
selectModel(historyEntry);
|
||||
}
|
||||
});
|
||||
return row;
|
||||
|
|
|
@ -550,36 +550,14 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
|||
app.getSettings().MAP_PREFERRED_LOCALE.get());
|
||||
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
|
||||
int z = Math.max(16, settings.getLastKnownMapZoom());
|
||||
final PopupMenu optionsMenu = new PopupMenu(this, view);
|
||||
DirectionsDialogs.createDirectionsActionsPopUpMenu(optionsMenu, amenity.getLocation(), amenity, name, z, this,
|
||||
true);
|
||||
final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false);
|
||||
if (d.toString().trim().length() > 0 || amenity.getType().isWiki()) {
|
||||
MenuItem item = optionsMenu
|
||||
.getMenu()
|
||||
.add(R.string.poi_context_menu_showdescription)
|
||||
.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();
|
||||
|
||||
LatLon location = amenity.getLocation();
|
||||
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(),
|
||||
z,
|
||||
name,
|
||||
true,
|
||||
amenity); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1130,7 +1130,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
recordingByFileName = newMap;
|
||||
Algorithms.removeAllFiles(r.file);
|
||||
if (activity != null) {
|
||||
activity.getMapLayers().getContextMenuLayer().setLocation(null, "");
|
||||
activity.getContextMenu().close();
|
||||
activity.getMapView().refreshMap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,11 @@ package net.osmand.plus.dialogs;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
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) {
|
||||
final OsmandApplication ctx = (OsmandApplication) act.getApplication();
|
||||
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
|
||||
|
|
|
@ -1,23 +1,5 @@
|
|||
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.Builder;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -29,6 +11,25 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
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 {
|
||||
private List<RouteDataObject> missingRoads;
|
||||
private OsmandApplication app;
|
||||
|
@ -114,7 +115,7 @@ public class AvoidSpecificRoads {
|
|||
RouteDataObject obj = getMissingRoads().get(which);
|
||||
double lat = MapUtils.get31LatitudeY(obj.getPoint31YTile(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) {
|
||||
if (!(a instanceof MapActivity)) {
|
||||
return;
|
||||
}
|
||||
MapActivity ctx = (MapActivity) a;
|
||||
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
|
||||
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
|
||||
if (thread.isAnimating()) {
|
||||
|
@ -186,7 +183,7 @@ public class AvoidSpecificRoads {
|
|||
} else {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -423,16 +423,17 @@ public class WaypointDialogHelper {
|
|||
}
|
||||
if(ctx.getDashboard().isVisible()) {
|
||||
ctx.getDashboard().hideDashboard();
|
||||
ctx.getContextMenu().show(
|
||||
new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
|
||||
locationPoint.getPointDescription(ctx),
|
||||
locationPoint);
|
||||
/*
|
||||
ctx.getMapLayers().getContextMenuLayer().setSelectedObject(locationPoint);
|
||||
// if (locationPoint instanceof FavouritePoint) {
|
||||
// ctx.getMapLayers().getContextMenuLayer()
|
||||
// .showContextMenuForSelectedObjects(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()));
|
||||
// } else {
|
||||
ctx.getMapLayers()
|
||||
.getContextMenuLayer()
|
||||
.setLocation(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
|
||||
PointDescription.getSimpleName(locationPoint, ctx));
|
||||
// }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.osmand.plus.mapcontextmenu;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.Location;
|
||||
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.MenuController;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -30,6 +31,8 @@ public class MapContextMenu {
|
|||
private OsmandSettings settings;
|
||||
private final MapActivity mapActivity;
|
||||
|
||||
private boolean active;
|
||||
private LatLon latLon;
|
||||
private PointDescription pointDescription;
|
||||
private Object object;
|
||||
MenuController menuController;
|
||||
|
@ -42,15 +45,25 @@ public class MapContextMenu {
|
|||
private String streetStr;
|
||||
|
||||
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_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_STREET_STR = "key_ctx_menu_street_str";
|
||||
|
||||
public boolean isMenuVisible() {
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return findMenuFragment() != null;
|
||||
}
|
||||
|
||||
public LatLon getLatLon() {
|
||||
return latLon;
|
||||
}
|
||||
|
||||
public PointDescription getPointDescription() {
|
||||
return pointDescription;
|
||||
}
|
||||
|
@ -59,8 +72,8 @@ public class MapContextMenu {
|
|||
return object;
|
||||
}
|
||||
|
||||
public MenuController getMenuController() {
|
||||
return menuController;
|
||||
public boolean isExtended() {
|
||||
return menuController != null;
|
||||
}
|
||||
|
||||
public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
|
||||
|
@ -69,12 +82,12 @@ public class MapContextMenu {
|
|||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
public boolean init(PointDescription pointDescription, Object object) {
|
||||
return init(pointDescription, object, false);
|
||||
public boolean init(LatLon latLon, PointDescription pointDescription, Object object) {
|
||||
return init(latLon, pointDescription, object, false);
|
||||
}
|
||||
|
||||
public boolean init(PointDescription pointDescription, Object object, boolean reload) {
|
||||
if (!reload && isMenuVisible()) {
|
||||
public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean reload) {
|
||||
if (!reload && isVisible()) {
|
||||
if (this.object == null || !this.object.equals(object)) {
|
||||
hide();
|
||||
} else {
|
||||
|
@ -82,46 +95,66 @@ public class MapContextMenu {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
leftIconId = 0;
|
||||
nameStr = "";
|
||||
typeStr = "";
|
||||
streetStr = "";
|
||||
|
||||
active = true;
|
||||
|
||||
acquireMenuController();
|
||||
acquireIcons();
|
||||
acquireNameAndType();
|
||||
if (needStreetName()) {
|
||||
acquireStreetName(new LatLon(pointDescription.getLat(), pointDescription.getLon()));
|
||||
acquireStreetName(latLon);
|
||||
}
|
||||
if (menuController != null) {
|
||||
menuController.addPlainMenuItems(typeStr, this.pointDescription);
|
||||
}
|
||||
|
||||
mapActivity.getMapView().refreshMap();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (!isMenuVisible()) {
|
||||
if (!isVisible()) {
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(PointDescription pointDescription, Object object) {
|
||||
if (init(pointDescription, object)) {
|
||||
public void show(LatLon latLon, PointDescription pointDescription, Object object) {
|
||||
if (init(latLon, pointDescription, object)) {
|
||||
MapContextMenuFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshMenu(PointDescription pointDescription, Object object) {
|
||||
public void refreshMenu(LatLon latLon, PointDescription pointDescription, Object object) {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null) {
|
||||
init(pointDescription, object, true);
|
||||
init(latLon, pointDescription, object, true);
|
||||
fragment.rebuildMenu();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
active = false;
|
||||
hide();
|
||||
mapActivity.getMapView().refreshMap();
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
MapContextMenuFragment fragment = findMenuFragment();
|
||||
if (fragment != null) {
|
||||
|
@ -129,6 +162,21 @@ 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() {
|
||||
menuController = null;
|
||||
if (object != null) {
|
||||
|
@ -160,7 +208,7 @@ public class MapContextMenu {
|
|||
fragment.refreshTitle();
|
||||
}
|
||||
|
||||
private MapContextMenuFragment findMenuFragment() {
|
||||
public MapContextMenuFragment findMenuFragment() {
|
||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapContextMenuFragment.TAG);
|
||||
if (fragment != null) {
|
||||
return (MapContextMenuFragment) fragment;
|
||||
|
@ -190,7 +238,8 @@ public class MapContextMenu {
|
|||
return typeStr;
|
||||
} else {
|
||||
if (Algorithms.isEmpty(streetStr)) {
|
||||
return pointDescription.getLocationName(mapActivity, true).replaceAll("\n", "");
|
||||
return PointDescription.getLocationName(mapActivity,
|
||||
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "");
|
||||
} else {
|
||||
return streetStr;
|
||||
}
|
||||
|
@ -270,19 +319,19 @@ public class MapContextMenu {
|
|||
}
|
||||
|
||||
public void buttonNavigatePressed() {
|
||||
mapActivity.getMapActions().showNavigationContextMenuPoint(pointDescription.getLat(), pointDescription.getLon());
|
||||
mapActivity.getMapActions().showNavigationContextMenuPoint(latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
|
||||
public void buttonFavoritePressed() {
|
||||
if (object != null && object instanceof FavouritePoint) {
|
||||
mapActivity.getFavoritePointEditor().edit((FavouritePoint) object);
|
||||
} else {
|
||||
mapActivity.getFavoritePointEditor().add(pointDescription);
|
||||
mapActivity.getFavoritePointEditor().add(latLon, getTitleStr());
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonSharePressed() {
|
||||
mapActivity.getMapActions().shareLocation(pointDescription.getLat(), pointDescription.getLon());
|
||||
mapActivity.getMapActions().shareLocation(latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
|
||||
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) {
|
||||
if (menuController != null) {
|
||||
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.putString(KEY_CTX_MENU_NAME_STR, nameStr);
|
||||
bundle.putString(KEY_CTX_MENU_TYPE_STR, typeStr);
|
||||
|
@ -314,10 +365,88 @@ public class MapContextMenu {
|
|||
}
|
||||
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);
|
||||
typeStr = bundle.getString(KEY_CTX_MENU_TYPE_STR);
|
||||
streetStr = bundle.getString(KEY_CTX_MENU_STREET_STR);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,6 @@ import android.os.Bundle;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.OnGestureListener;
|
||||
|
@ -28,6 +27,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -52,13 +52,11 @@ public class MapContextMenuFragment extends Fragment {
|
|||
private View view;
|
||||
private View mainView;
|
||||
|
||||
MenuController menuController;
|
||||
MapContextMenu menu;
|
||||
|
||||
private int menuTopHeight;
|
||||
private int menuTopShadowHeight;
|
||||
private int menuTopShadowAllHeight;
|
||||
private int menuTitleHeight;
|
||||
private int menuButtonsHeight;
|
||||
private int menuBottomViewHeight;
|
||||
private int menuFullHeight;
|
||||
private int menuFullHeightMax;
|
||||
|
@ -101,7 +99,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
getCtxMenu().saveMenuState(outState);
|
||||
menu.saveMenuState(outState);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
|
@ -109,46 +107,20 @@ public class MapContextMenuFragment extends Fragment {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
if (savedInstanceState != null)
|
||||
getCtxMenu().restoreMenuState(savedInstanceState);
|
||||
menu = getMapActivity().getContextMenu();
|
||||
if (savedInstanceState != null) {
|
||||
menu.restoreMenuState(savedInstanceState);
|
||||
}
|
||||
|
||||
view = inflater.inflate(R.layout.map_context_menu_fragment, container, false);
|
||||
mainView = view.findViewById(R.id.context_menu_main);
|
||||
|
||||
menuController = getCtxMenu().getMenuController();
|
||||
if (menuController != null && menuController.isLandscapeLayout()) {
|
||||
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menuController.getLandscapeWidthDp()), ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
if (menu.isLandscapeLayout()) {
|
||||
mainView.setLayoutParams(new FrameLayout.LayoutParams(dpToPx(menu.getLandscapeWidthDp()),
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
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();
|
||||
}
|
||||
|
||||
});
|
||||
runLayoutListener();
|
||||
|
||||
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) {
|
||||
|
||||
if (singleTapDetector.onTouchEvent(event)) {
|
||||
showOnMap(getCtxMenu().getPointDescription().getLat(), getCtxMenu().getPointDescription().getLon());
|
||||
showOnMap(menu.getLatLon());
|
||||
|
||||
if (hasMoved) {
|
||||
applyPosY(getViewY());
|
||||
|
@ -176,7 +148,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (menuController != null && menuController.isLandscapeLayout()) {
|
||||
if (menu.isLandscapeLayout()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -222,11 +194,11 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
velocity.recycle();
|
||||
|
||||
if (menuController != null) {
|
||||
if (menu.isExtended()) {
|
||||
if (menuBottomViewHeight > 0 && slidingUp) {
|
||||
menuController.slideUp();
|
||||
menu.slideUp();
|
||||
} else if (slidingDown) {
|
||||
menuController.slideDown();
|
||||
menu.slideDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,8 +268,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
closeButtonView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((MapActivity) getActivity()).getMapLayers().getContextMenuLayer().hideMapContextMenuMarker();
|
||||
dismissMenu();
|
||||
getMapActivity().getContextMenu().close();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -308,7 +279,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonNavigate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonNavigatePressed();
|
||||
menu.buttonNavigatePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -318,7 +289,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonFavorite.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonFavoritePressed();
|
||||
menu.buttonFavoritePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -328,7 +299,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonShare.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getCtxMenu().buttonSharePressed();
|
||||
menu.buttonSharePressed();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -338,7 +309,7 @@ public class MapContextMenuFragment extends Fragment {
|
|||
buttonMore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
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 ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
|
||||
Drawable icon = getCtxMenu().getLeftIcon();
|
||||
int iconId = getCtxMenu().getLeftIconId();
|
||||
Drawable icon = menu.getLeftIcon();
|
||||
int iconId = menu.getLeftIconId();
|
||||
if (icon != null) {
|
||||
iconView.setImageDrawable(icon);
|
||||
iconLayout.setVisibility(View.VISIBLE);
|
||||
} else if (iconId != 0) {
|
||||
iconView.setImageDrawable(iconsCache.getIcon(iconId,
|
||||
light ? R.color.osmand_orange : R.color.osmand_orange_dark, 0.75f));
|
||||
iconLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
iconLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -374,14 +347,14 @@ public class MapContextMenuFragment extends Fragment {
|
|||
|
||||
private void buildBottomView() {
|
||||
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
|
||||
if (menuController != null) {
|
||||
if (menu.isExtended()) {
|
||||
bottomView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
menuController.build(bottomView);
|
||||
menu.build(bottomView);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -398,15 +371,45 @@ public class MapContextMenuFragment extends Fragment {
|
|||
bottomLayout.removeAllViews();
|
||||
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();
|
||||
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
|
||||
int fZoom = ctx.getMapView().getZoom();
|
||||
double flat = latitude;
|
||||
double flon = longitude;
|
||||
double flat = latLon.getLatitude();
|
||||
double flon = latLon.getLongitude();
|
||||
|
||||
RotatedTileBox cp = ctx.getMapView().getCurrentRotatedTileBox().copy();
|
||||
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() {
|
||||
// Text line 1
|
||||
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
|
||||
line1.setText(getCtxMenu().getTitleStr());
|
||||
line1.setText(menu.getTitleStr());
|
||||
|
||||
// Text line 2
|
||||
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
|
||||
line2.setText(getCtxMenu().getLocationStr());
|
||||
Drawable icon = getCtxMenu().getSecondLineIcon();
|
||||
line2.setText(menu.getLocationStr());
|
||||
Drawable icon = menu.getSecondLineIcon();
|
||||
if (icon != null) {
|
||||
line2.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||
line2.setCompoundDrawablePadding(dpToPx(5f));
|
||||
|
@ -435,9 +438,9 @@ public class MapContextMenuFragment extends Fragment {
|
|||
private int getPosY() {
|
||||
int destinationState;
|
||||
int minHalfY;
|
||||
if (menuController != null) {
|
||||
destinationState = menuController.getCurrentMenuState();
|
||||
minHalfY = view.getHeight() - (int)(view.getHeight() * menuController.getHalfScreenMaxHeightKoef());
|
||||
if (menu.isExtended()) {
|
||||
destinationState = menu.getCurrentMenuState();
|
||||
minHalfY = view.getHeight() - (int)(view.getHeight() * menu.getHalfScreenMaxHeightKoef());
|
||||
} else {
|
||||
destinationState = MenuController.MenuState.HEADER_ONLY;
|
||||
minHalfY = view.getHeight();
|
||||
|
@ -508,6 +511,14 @@ public class MapContextMenuFragment extends Fragment {
|
|||
setAddressLocation();
|
||||
}
|
||||
|
||||
public void setFragmentVisibility(boolean visible) {
|
||||
if (visible) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
if (getActivity() == null) {
|
||||
return null;
|
||||
|
@ -520,10 +531,10 @@ public class MapContextMenuFragment extends Fragment {
|
|||
int slideInAnim = R.anim.slide_in_bottom;
|
||||
int slideOutAnim = R.anim.slide_out_bottom;
|
||||
|
||||
MenuController menuController = mapActivity.getContextMenu().getMenuController();
|
||||
if (menuController != null) {
|
||||
slideInAnim = menuController.getSlideInAnimation();
|
||||
slideOutAnim = menuController.getSlideOutAnimation();
|
||||
MapContextMenu menu = mapActivity.getContextMenu();
|
||||
if (menu.isExtended()) {
|
||||
slideInAnim = menu.getSlideInAnimation();
|
||||
slideOutAnim = menu.getSlideOutAnimation();
|
||||
}
|
||||
|
||||
MapContextMenuFragment fragment = new MapContextMenuFragment();
|
||||
|
@ -533,27 +544,10 @@ public class MapContextMenuFragment extends Fragment {
|
|||
.addToBackStack(TAG).commit();
|
||||
}
|
||||
|
||||
private MapContextMenu getCtxMenu() {
|
||||
return getMapActivity().getContextMenu();
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
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) {
|
||||
Resources r = getActivity().getResources();
|
||||
return (int) TypedValue.applyDimension(
|
||||
|
|
|
@ -79,7 +79,8 @@ public class AmenityMenuController extends MenuController {
|
|||
addPlainMenuItem(R.drawable.ic_action_info_dark, typeStr);
|
||||
}
|
||||
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", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,8 @@ public class FavouritePointMenuController extends MenuController {
|
|||
@Override
|
||||
public void addPlainMenuItems(String typeStr, PointDescription pointDescription) {
|
||||
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", ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.editors;
|
|||
import android.os.Bundle;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -41,12 +42,13 @@ public class FavoritePointEditor extends PointEditor {
|
|||
return favorite;
|
||||
}
|
||||
|
||||
public void add(PointDescription point) {
|
||||
if (point == null) {
|
||||
public void add(LatLon latLon, String title) {
|
||||
if (latLon == null) {
|
||||
return;
|
||||
}
|
||||
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("");
|
||||
FavoritePointEditorFragment.showInstance(mapActivity);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.os.Bundle;
|
|||
import android.util.Log;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
|
@ -127,11 +128,12 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
}
|
||||
|
||||
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.setLat(favorite.getLatitude());
|
||||
pointDescription.setLon(favorite.getLongitude());
|
||||
menu.refreshMenu(pointDescription, favorite);
|
||||
menu.refreshMenu(latLon, pointDescription, favorite);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.osmand.plus.IconsCache;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
|
||||
import net.osmand.plus.mapcontextmenu.editors.dialogs.SelectCategoryDialogFragment;
|
||||
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
getMapActivity().getContextMenu().setBaseFragmentVisibility(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
getMapActivity().getContextMenu().setBaseFragmentVisibility(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (!wasSaved() && !getEditor().isNew()) {
|
||||
|
@ -199,8 +212,7 @@ public abstract class PointEditorFragment extends Fragment {
|
|||
if (includingMenu) {
|
||||
//getMapActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
getMapActivity().getSupportFragmentManager().popBackStack();
|
||||
getMapActivity().getMapLayers().getContextMenuLayer().hideMapContextMenuMarker();
|
||||
getMapActivity().getContextMenu().hide();
|
||||
getMapActivity().getContextMenu().close();
|
||||
} else {
|
||||
getMapActivity().getSupportFragmentManager().popBackStack();
|
||||
}
|
||||
|
|
|
@ -1,37 +1,6 @@
|
|||
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.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -58,6 +27,38 @@ import android.widget.ListView;
|
|||
import android.widget.Spinner;
|
||||
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 static final String ARG_TO_EXPAND_TRACK_INFO = "ARG_TO_EXPAND_TRACK_INFO";
|
||||
|
@ -475,7 +476,19 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
|
||||
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 ||
|
||||
// child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
|
||||
ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
|
||||
|
@ -491,5 +504,6 @@ public class SelectedGPXFragment extends OsmAndListFragment {
|
|||
// child.expanded = !child.expanded;
|
||||
// adapter.notifyDataSetInvalidated();
|
||||
// }
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,8 +348,8 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
if(sameId && !schedule && l != null) {
|
||||
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
|
||||
final boolean sameObject;
|
||||
if(cl.getFirstSelectedObject() instanceof OsMoDevice && cl.isVisible()) {
|
||||
sameObject = Algorithms.objectEquals(device.trackerId, ((OsMoDevice) cl.getFirstSelectedObject()).trackerId) ;
|
||||
if (map.getContextMenu().getObject() instanceof OsMoDevice && cl.isVisible()) {
|
||||
sameObject = Algorithms.objectEquals(device.trackerId, ((OsMoDevice) map.getContextMenu().getObject()).trackerId);
|
||||
} else {
|
||||
sameObject = false;
|
||||
}
|
||||
|
@ -373,10 +373,10 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
public void run() {
|
||||
schedule = false;
|
||||
if (sameObject) {
|
||||
ContextMenuLayer cl = map.getMapLayers().getContextMenuLayer();
|
||||
Location l = device.getLastLocation();
|
||||
cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device));
|
||||
cl.setSelectedObject(device);
|
||||
map.getContextMenu().show(new LatLon(l.getLatitude(), l.getLongitude()), getObjectName(device), device);
|
||||
//cl.setLocation(new LatLon(l.getLatitude(), l.getLongitude()), getObjectDescription(device));
|
||||
//cl.setSelectedObject(device);
|
||||
}
|
||||
if (centered) {
|
||||
map.getMapView().setLatLon(loc.getLatitude(),
|
||||
|
@ -408,7 +408,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clearSelectedObjects() {
|
||||
public void clearSelectedObject() {
|
||||
LatLon mapLoc = new LatLon(map.getMapView().getLatitude(), map.getMapView().getLongitude());
|
||||
final boolean centered = Algorithms.objectEquals(followMapLocation, mapLoc);
|
||||
if(!centered && followTrackerId != null) {
|
||||
|
|
|
@ -3,19 +3,16 @@ package net.osmand.plus.views;
|
|||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout.LayoutParams;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -23,110 +20,58 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ContextMenuLayer extends OsmandMapLayer {
|
||||
|
||||
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
|
||||
public String getObjectDescription(Object o);
|
||||
|
||||
public PointDescription getObjectName(Object o);
|
||||
|
||||
public boolean disableSingleTap();
|
||||
|
||||
public boolean disableLongPressOnMap();
|
||||
boolean disableSingleTap();
|
||||
boolean disableLongPressOnMap();
|
||||
}
|
||||
|
||||
public interface IContextMenuProviderSelection {
|
||||
|
||||
public void setSelectedObject(Object o);
|
||||
|
||||
public void clearSelectedObjects();
|
||||
|
||||
void setSelectedObject(Object o);
|
||||
void clearSelectedObject();
|
||||
}
|
||||
|
||||
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 int BASE_TEXT_SIZE = 170;
|
||||
|
||||
private final MapActivity activity;
|
||||
private float scaleCoefficient = 1;
|
||||
private MapContextMenu menu;
|
||||
private CallbackWithObject<LatLon> selectOnMap = null;
|
||||
|
||||
private boolean showContextMarker;
|
||||
private ImageView contextMarker;
|
||||
|
||||
private GestureDetector movementListener;
|
||||
|
||||
public ContextMenuLayer(MapActivity activity){
|
||||
this.activity = activity;
|
||||
menu = activity.getContextMenu();
|
||||
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
|
||||
public void destroyLayer() {
|
||||
}
|
||||
|
||||
public Object getFirstSelectedObject() {
|
||||
if(!selectedObjects.isEmpty()) {
|
||||
return selectedObjects.keySet().iterator().next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView 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.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
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 minh = contextMarker.getDrawable().getMinimumHeight();
|
||||
contextMarker.layout(0, 0, minw, minh);
|
||||
|
||||
if(latLon != null){
|
||||
setLocation(latLon, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean isVisible() {
|
||||
return latLon != null;
|
||||
return menu.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
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 y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
|
||||
if (showContextMarker) {
|
||||
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) {
|
||||
hideMapContextMenuMarker();
|
||||
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() {
|
||||
showContextMarker = true;
|
||||
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()) {
|
||||
private void clearSelectedObjects(Map<Object, IContextMenuProvider> selectedObjects) {
|
||||
for(IContextMenuProvider p : selectedObjects.values()) {
|
||||
if(p instanceof IContextMenuProviderSelection){
|
||||
((IContextMenuProviderSelection) p).clearSelectedObjects();
|
||||
((IContextMenuProviderSelection) p).clearSelectedObject();
|
||||
}
|
||||
}
|
||||
selectedObjects.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
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()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -289,29 +127,43 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation);
|
||||
}
|
||||
|
||||
public boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
||||
LatLon latLon = selectObjectsForContextMenu(tileBox, point);
|
||||
if (latLon != null) {
|
||||
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
||||
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point);
|
||||
if (selectedObjects.size() == 1) {
|
||||
setLocation(null, "");
|
||||
Object selectedObj = selectedObjects.keySet().iterator().next();
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(latLon, selectedObj, contextObject);
|
||||
return true;
|
||||
} else if (selectedObjects.size() > 1) {
|
||||
showContextMenuForSelectedObjects(latLon);
|
||||
return true;
|
||||
LatLon latLon = null;
|
||||
PointDescription pointDescription = null;
|
||||
if (contextObject != null) {
|
||||
latLon = contextObject.getObjectLocation(selectedObj);
|
||||
pointDescription = contextObject.getObjectName(selectedObj);
|
||||
}
|
||||
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) {
|
||||
setLocation(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));
|
||||
menu.show(getLatLon(point, tileBox), null, null);
|
||||
return true;
|
||||
}
|
||||
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() {
|
||||
boolean res = false;
|
||||
for(OsmandMapLayer lt : view.getLayers()){
|
||||
|
@ -338,10 +190,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
return res;
|
||||
}
|
||||
|
||||
public LatLon selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
|
||||
clearSelectedObjects();
|
||||
List<Object> s = new ArrayList<Object>();
|
||||
LatLon latLon = null;
|
||||
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) {
|
||||
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
|
||||
List<Object> s = new ArrayList<>();
|
||||
for (OsmandMapLayer lt : view.getLayers()) {
|
||||
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
|
||||
s.clear();
|
||||
|
@ -352,13 +203,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
if (l instanceof IContextMenuProviderSelection) {
|
||||
((IContextMenuProviderSelection) l).setSelectedObject(o);
|
||||
}
|
||||
if(latLon == null) {
|
||||
latLon = l.getObjectLocation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return latLon;
|
||||
return selectedObjects;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -366,27 +214,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
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) {
|
||||
if (latLon != null && showContextMarker) {
|
||||
if (menu.isActive()) {
|
||||
LatLon latLon = menu.getLatLon();
|
||||
Rect bs = contextMarker.getDrawable().getBounds();
|
||||
int dx = (int) (px - tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
|
||||
int dy = (int) (py - tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()));
|
||||
|
@ -397,101 +227,39 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
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
|
||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if (pressedContextMarker(tileBox, point.x, point.y)) {
|
||||
showMapContextMenu();
|
||||
menu.show();
|
||||
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) {
|
||||
LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y);
|
||||
CallbackWithObject<LatLon> cb = selectOnMap;
|
||||
cb.processResult(latlon);
|
||||
showMapContextMenu(latlon);
|
||||
menu.init(latlon, null, null);
|
||||
selectOnMap = null;
|
||||
return true;
|
||||
}
|
||||
if (val == 2) {
|
||||
setLocation(null, ""); //$NON-NLS-1$
|
||||
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()) {
|
||||
|
||||
if (!disableSingleTap()) {
|
||||
boolean res = showContextMenu(point, tileBox, false);
|
||||
if (res) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
activity.getContextMenu().onSingleTapOnMap();
|
||||
menu.onSingleTapOnMap();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showContextMenuForSelectedObjects(final LatLon l) {
|
||||
if (selectedObjects.size() > 1) {
|
||||
private void showContextMenuForSelectedObjects(final LatLon latLon, final Map<Object, IContextMenuProvider> selectedObjects) {
|
||||
Builder builder = new AlertDialog.Builder(view.getContext());
|
||||
String[] d = new String[selectedObjects.size()];
|
||||
final List<Object> s = new ArrayList<Object>();
|
||||
final List<Object> s = new ArrayList<>();
|
||||
int i = 0;
|
||||
Iterator<Entry<Object, IContextMenuProvider>> it = selectedObjects.entrySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
Entry<Object, IContextMenuProvider> e = it.next();
|
||||
for (Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
|
||||
d[i++] = e.getValue().getObjectDescription(e.getKey());
|
||||
s.add(e.getKey());
|
||||
}
|
||||
|
@ -500,115 +268,43 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
Object selectedObj = s.get(which);
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l, selectedObj, contextObject);
|
||||
LatLon ll = null;
|
||||
PointDescription pointDescription = null;
|
||||
if (contextObject != null) {
|
||||
ll = contextObject.getObjectLocation(selectedObj);
|
||||
pointDescription = contextObject.getObjectName(selectedObj);
|
||||
}
|
||||
if (ll == null) {
|
||||
ll = latLon;
|
||||
}
|
||||
menu.show(ll, pointDescription, selectedObj);
|
||||
|
||||
selectedObjects.remove(selectedObj);
|
||||
clearSelectedObjects(selectedObjects);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
clearSelectedObjects(selectedObjects);
|
||||
}
|
||||
});
|
||||
|
||||
builder.show();
|
||||
} else {
|
||||
Object selectedObj = selectedObjects.keySet().iterator().next();
|
||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||
showMapContextMenu(l, selectedObj, contextObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void showMapContextMenu() {
|
||||
activity.getContextMenu().show();
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
showMapContextMenuMarker();
|
||||
if (selectOnMap != null) {
|
||||
activity.getContextMenu().init(pointDescription, selectedObj);
|
||||
} else {
|
||||
activity.getContextMenu().show(pointDescription, selectedObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
|
||||
|
||||
if (movementListener.onTouchEvent(event)) {
|
||||
if (activity.getContextMenu().isMenuVisible()) {
|
||||
activity.getContextMenu().hide();
|
||||
if (menu.isVisible()) {
|
||||
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;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -233,8 +233,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
|
||||
|
||||
});
|
||||
mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity.getMapLayers().getContextMenuLayer(),
|
||||
mapActivity, this);
|
||||
mapRouteInfoControlDialog = new MapRouteInfoControl(mapActivity, this);
|
||||
|
||||
View waypointsButton = mapActivity.findViewById(R.id.map_waypoints_route_button);
|
||||
controls.add(createHudButton((ImageView) waypointsButton, R.drawable.map_action_waypoints).setBg(
|
||||
|
|
|
@ -232,7 +232,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
|
|||
targetPointsHelper.removeWayPoint(true, -1);
|
||||
}
|
||||
}
|
||||
map.getMapLayers().getContextMenuLayer().setLocation(null, "");
|
||||
map.getContextMenu().close();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -36,10 +36,10 @@ import net.osmand.plus.activities.actions.AppModeDialog;
|
|||
import net.osmand.plus.activities.search.SearchAddressActivity;
|
||||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.controls.MapRoutePreferencesControl.RoutePrepareDialog;
|
||||
|
@ -52,7 +52,7 @@ import java.util.Set;
|
|||
public class MapRouteInfoControl implements IRouteInformationListener {
|
||||
public static int directionInfo = -1;
|
||||
public static boolean controlVisible = false;
|
||||
private final ContextMenuLayer contextMenu;
|
||||
private final MapContextMenu contextMenu;
|
||||
private final RoutingHelper routingHelper;
|
||||
private OsmandMapTileView mapView;
|
||||
private Dialog dialog;
|
||||
|
@ -64,11 +64,10 @@ public class MapRouteInfoControl implements IRouteInformationListener {
|
|||
private MapControlsLayer mapControlsLayer;
|
||||
public static final String TARGET_SELECT = "TARGET_SELECT";
|
||||
|
||||
public MapRouteInfoControl(ContextMenuLayer contextMenu,
|
||||
MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
|
||||
this.contextMenu = contextMenu;
|
||||
public MapRouteInfoControl(MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
|
||||
this.mapActivity = mapActivity;
|
||||
this.mapControlsLayer = mapControlsLayer;
|
||||
contextMenu = mapActivity.getContextMenu();
|
||||
routingHelper = mapActivity.getRoutingHelper();
|
||||
mapView = mapActivity.getMapView();
|
||||
routingHelper.addListener(this);
|
||||
|
@ -83,7 +82,7 @@ public class MapRouteInfoControl implements IRouteInformationListener {
|
|||
} else {
|
||||
getTargets().setStartPoint(latlon, true, null);
|
||||
}
|
||||
contextMenu.setLocation(latlon, null);
|
||||
contextMenu.show(latlon, null, null);
|
||||
showDialog();
|
||||
return true;
|
||||
}
|
||||
|
@ -340,8 +339,9 @@ public class MapRouteInfoControl implements IRouteInformationListener {
|
|||
if (routingHelper.getRouteDirections().size() > directionInfo) {
|
||||
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
|
||||
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);
|
||||
}
|
||||
|
@ -364,7 +364,8 @@ public class MapRouteInfoControl implements IRouteInformationListener {
|
|||
directionInfo++;
|
||||
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
|
||||
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.refreshMap();
|
||||
|
|
Loading…
Reference in a new issue