Refactor context menu for objects - make it quickaction independent and special case for accessibility

This commit is contained in:
Victor Shcherb 2014-07-06 03:01:37 +02:00
parent 43784a1260
commit 7fa56e1268
8 changed files with 199 additions and 161 deletions

View file

@ -22,6 +22,7 @@ public class ContextMenuAdapter {
} }
private final Context ctx; private final Context ctx;
private View anchor;
final TIntArrayList items = new TIntArrayList(); final TIntArrayList items = new TIntArrayList();
final ArrayList<String> itemNames = new ArrayList<String>(); final ArrayList<String> itemNames = new ArrayList<String>();
final ArrayList<OnContextMenuClick> listeners = new ArrayList<ContextMenuAdapter.OnContextMenuClick>(); final ArrayList<OnContextMenuClick> listeners = new ArrayList<ContextMenuAdapter.OnContextMenuClick>();
@ -33,6 +34,14 @@ public class ContextMenuAdapter {
this.ctx = ctx; this.ctx = ctx;
} }
public void setAnchor(View anchor) {
this.anchor = anchor;
}
public View getAnchor() {
return anchor;
}
public int length(){ public int length(){
return items.size(); return items.size();
} }

View file

@ -6,9 +6,9 @@ package net.osmand.plus.activities;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import net.londatiga.android.QuickAction;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -103,7 +103,6 @@ public class FavouritesListFragment extends SherlockListFragment implements Sear
public void onListItemClick(ListView l, View v, int position, long id) { public void onListItemClick(ListView l, View v, int position, long id) {
if (!isSelectFavoriteMode()) { if (!isSelectFavoriteMode()) {
QuickAction qa = new QuickAction(v);
FavouritePoint point = favouritesAdapter.getItem(position); FavouritePoint point = favouritesAdapter.getItem(position);
String name = getString(R.string.favorite) + ": " + point.getName(); String name = getString(R.string.favorite) + ": " + point.getName();
LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
@ -114,9 +113,11 @@ public class FavouritesListFragment extends SherlockListFragment implements Sear
settings.SHOW_FAVORITES.set(true); settings.SHOW_FAVORITES.set(true);
} }
}; };
ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), getActivity(), MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), getActivity(),
true, onshow, false); true, false);
qa.show(); MapActivityActions.showObjectContextMenu(qa, getActivity(), onshow);
} else { } else {
Intent intent = getActivity().getIntent(); Intent intent = getActivity().getIntent();
intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position)); intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position));

View file

@ -12,11 +12,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
@ -155,7 +156,8 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
} }
updateSelectionMode(actionMode); updateSelectionMode(actionMode);
} else { } else {
final QuickAction qa = new QuickAction(v); ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
final OsmandSettings settings = getMyApplication().getSettings(); final OsmandSettings settings = getMyApplication().getSettings();
final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition); final FavouritePoint point = (FavouritePoint) favouritesAdapter.getChild(groupPosition, childPosition);
String name = getString(R.string.favorite) + ": " + point.getName(); String name = getString(R.string.favorite) + ": " + point.getName();
@ -167,32 +169,28 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
} }
}; };
MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(), MapActivityActions.createDirectionsActions(qa, location, point, name, settings.getLastKnownMapZoom(),
getActivity(), true, onshow, false); getActivity(), true, false);
ActionItem edit = new ActionItem(); Item edit = qa.item(R.string.favourites_context_menu_edit).icons(R.drawable.ic_action_edit_light ,
edit.setIcon(getResources().getDrawable(R.drawable.ic_action_edit_light)); R.drawable.ic_action_edit_dark);
edit.setTitle(getString(R.string.favourites_context_menu_edit)); edit.listen(
edit.setOnClickListener(new OnClickListener() { new OnContextMenuClick() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
editPoint(point); editPoint(point);
qa.dismiss();
} }
}); }).reg();
qa.addActionItem(edit); Item delete = qa.item(R.string.favourites_context_menu_delete).icons(R.drawable.ic_action_delete_light ,
R.drawable.ic_action_delete_dark);
delete.listen(
new OnContextMenuClick() {
ActionItem delete = new ActionItem();
delete.setTitle(getString(R.string.favourites_context_menu_delete));
delete.setIcon(getResources().getDrawable(R.drawable.ic_action_delete_light));
delete.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
deletePoint(point); deletePoint(point);
qa.dismiss();
} }
}); }).reg();
qa.addActionItem(delete); MapActivityActions.showObjectContextMenu(qa, getActivity(), onshow);
qa.show();
} }
return true; return true;
} }

View file

@ -24,6 +24,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
@ -64,7 +65,6 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
@ -1022,88 +1022,116 @@ public class MapActivityActions implements DialogProvider {
menu.show(); menu.show();
} }
public static void createDirectionsActions(final QuickAction qa , final LatLon location, final Object obj, final String name, public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory, final OnClickListener onShow) { final int z, final Activity activity, final boolean saveHistory) {
createDirectionsActions(qa, location, obj, name, z, activity, saveHistory, onShow, true); createDirectionsActions(qa, location, obj, name, z, activity, saveHistory, true);
} }
public static void createDirectionsActions(final QuickAction qa , final LatLon location, final Object obj, final String name, public static void createDirectionsActions(final ContextMenuAdapter qa , final LatLon location, final Object obj, final String name,
final int z, final Activity activity, final boolean saveHistory, final OnClickListener onShow, boolean favorite) { final int z, final Activity activity, final boolean saveHistory, boolean favorite) {
final OsmandApplication app = ((OsmandApplication) activity.getApplication()); final OsmandApplication app = ((OsmandApplication) activity.getApplication());
final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
ActionItem setAsDestination = new ActionItem();
setAsDestination.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_gdirections_light)); Item dir = qa.item(R.string.get_directions).icons(R.drawable.ic_action_gdirections_light ,
setAsDestination.setTitle(activity.getString(R.string.get_directions)); R.drawable.ic_action_gdirections_dark);
setAsDestination.setOnClickListener(new OnClickListener() { dir.listen(
new OnContextMenuClick() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (onShow != null) {
onShow.onClick(v);
}
qa.dismiss();
MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name); MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
} }
}); }).reg();
qa.addActionItem(setAsDestination); Item intermediate;
ActionItem intermediate = new ActionItem();
if (targetPointsHelper.getPointToNavigate() != null) { if (targetPointsHelper.getPointToNavigate() != null) {
intermediate.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_flage_light)); intermediate = qa.item(R.string.context_menu_item_intermediate_point).icons(R.drawable.ic_action_flage_light,
intermediate.setTitle(activity.getString(R.string.context_menu_item_intermediate_point)); R.drawable.ic_action_flage_dark);
} else { } else {
intermediate.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_flag_light)); intermediate = qa.item(R.string.context_menu_item_destination_point).icons(R.drawable.ic_action_flag_light,
intermediate.setTitle(activity.getString(R.string.context_menu_item_destination_point)); R.drawable.ic_action_flag_dark);
} }
intermediate.setOnClickListener(new OnClickListener() { intermediate.listen(new OnContextMenuClick() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (onShow != null) {
onShow.onClick(v);
}
addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name); addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
qa.dismiss();
} }
}); }).reg();
qa.addActionItem(intermediate);
Item showOnMap = qa.item(R.string.show_poi_on_map).icons(R.drawable.ic_action_marker_light ,
R.drawable.ic_action_marker_dark);
showOnMap.listen(
new OnContextMenuClick() {
ActionItem showOnMap = new ActionItem();
showOnMap.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_marker_light));
showOnMap.setTitle(activity.getString(R.string.show_poi_on_map));
showOnMap.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (onShow != null) {
onShow.onClick(v);
}
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name, app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name,
obj); //$NON-NLS-1$ obj); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(activity); MapActivity.launchMapActivityMoveToTop(activity);
qa.dismiss();
} }
}); }).reg();
qa.addActionItem(showOnMap);
if (favorite) { if (favorite) {
ActionItem addToFavorite = new ActionItem(); Item addToFavorite = qa.item(R.string.add_to_favourite).icons(R.drawable.ic_action_fav_light,
addToFavorite.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_fav_light)); R.drawable.ic_action_fav_dark);
addToFavorite.setTitle(activity.getString(R.string.add_to_favourite)); addToFavorite.listen(new OnContextMenuClick() {
addToFavorite.setOnClickListener(new OnClickListener() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
Bundle args = new Bundle();
Dialog dlg = createAddFavouriteDialog(activity, args);
dlg.show();
prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(),
name);
}
}).reg();
}
}
public static void showObjectContextMenu(final ContextMenuAdapter qa, final Activity activity,
final OnClickListener onShow) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
if(app.accessibilityEnabled()) {
Builder builder = new AlertDialog.Builder(activity);
String[] values = qa.getItemNames();
builder.setItems(values, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OnContextMenuClick clk = qa.getClickAdapter(which);
if (clk != null) {
clk.onContextMenuClick(qa.getItemId(which), which, false, dialog);
}
}
});
builder.show();
} else {
final QuickAction view = new QuickAction(qa.getAnchor());
for (int i = 0; i < qa.length(); i++) {
ActionItem ai = new ActionItem();
int id = qa.getImageId(0, true);
if (id != 0) {
ai.setIcon(activity.getResources().getDrawable(id));
}
final int ki = i;
ai.setTitle(qa.getItemName(i));
ai.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (onShow != null) { if (onShow != null) {
onShow.onClick(v); onShow.onClick(v);
} }
qa.dismiss(); view.dismiss();
Bundle args = new Bundle(); qa.getClickAdapter(ki).onContextMenuClick(qa.getItemId(ki), ki, false, null);
Dialog dlg = createAddFavouriteDialog(activity, args);
dlg.show();
prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(), name);
} }
}); });
qa.addActionItem(addToFavorite); view.addActionItem(ai);
}
view.show();
} }
} }

View file

@ -6,7 +6,6 @@ import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.londatiga.android.QuickAction;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
@ -595,13 +594,14 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
GpxDisplayItem child = adapter.getChild(groupPosition, childPosition); GpxDisplayItem child = adapter.getChild(groupPosition, childPosition);
if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS || if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS ||
child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) { child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
QuickAction qa = new QuickAction(v); ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
String name = getString(R.string.favorite) + ": " + child.name; String name = getString(R.string.favorite) + ": " + child.name;
LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon); LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon);
OsmandSettings settings = getMyApplication().getSettings(); OsmandSettings settings = getMyApplication().getSettings();
MapActivityActions.createDirectionsActions(qa, location, child.locationStart, name, settings.getLastKnownMapZoom(), getActivity(), MapActivityActions.createDirectionsActions(qa, location, child.locationStart, name, settings.getLastKnownMapZoom(), getActivity(),
true, null, false); true, false);
qa.show(); MapActivityActions.showObjectContextMenu(qa, getActivity(), null);
} else { } else {
child.expanded = !child.expanded; child.expanded = !child.expanded;
adapter.notifyDataSetInvalidated(); adapter.notifyDataSetInvalidated();

View file

@ -8,10 +8,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import net.londatiga.android.QuickAction;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -228,11 +228,12 @@ public class SearchAddressOnlineFragment extends SherlockFragment implements Sea
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Place item = adapter.getItem(position); Place item = adapter.getItem(position);
QuickAction qa = new QuickAction(view); ContextMenuAdapter qa = new ContextMenuAdapter(view.getContext());
qa.setAnchor(view);
MapActivityActions.createDirectionsActions(qa, new LatLon(item.lat, item.lon), item, MapActivityActions.createDirectionsActions(qa, new LatLon(item.lat, item.lon), item,
getString(R.string.address)+ " : " + item.displayName, Math.max(15, settings.getLastKnownMapZoom()), getString(R.string.address)+ " : " + item.displayName, Math.max(15, settings.getLastKnownMapZoom()),
getActivity(), true, null); getActivity(), true);
qa.show(); MapActivityActions.showObjectContextMenu(qa, getActivity(), null);
} }
private static class Place { private static class Place {

View file

@ -2,8 +2,8 @@ package net.osmand.plus.activities.search;
import java.util.List; import java.util.List;
import net.londatiga.android.QuickAction;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -109,7 +109,8 @@ public class SearchHistoryFragment extends SherlockListFragment implements Sear
} }
private void selectModel(final HistoryEntry model, View v) { private void selectModel(final HistoryEntry model, View v) {
QuickAction qa = new QuickAction(v); ContextMenuAdapter qa = new ContextMenuAdapter(v.getContext());
qa.setAnchor(v);
String name = model.getName(); String name = model.getName();
OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings(); OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
OnClickListener onShow = new View.OnClickListener() { OnClickListener onShow = new View.OnClickListener() {
@ -119,8 +120,8 @@ public class SearchHistoryFragment extends SherlockListFragment implements Sear
} }
}; };
MapActivityActions.createDirectionsActions(qa, new LatLon(model.getLat(), model.getLon()), MapActivityActions.createDirectionsActions(qa, new LatLon(model.getLat(), model.getLon()),
model, name, settings.getLastKnownMapZoom(), getActivity(), false, onShow); model, name, settings.getLastKnownMapZoom(), getActivity(), false);
qa.show(); MapActivityActions.showObjectContextMenu(qa, getActivity(), onShow);
} }
class HistoryAdapter extends ArrayAdapter<HistoryEntry> { class HistoryAdapter extends ArrayAdapter<HistoryEntry> {

View file

@ -15,8 +15,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.londatiga.android.ActionItem;
import net.londatiga.android.QuickAction;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.access.NavigationInfo; import net.osmand.access.NavigationInfo;
@ -24,11 +22,14 @@ import net.osmand.data.Amenity;
import net.osmand.data.AmenityType; import net.osmand.data.AmenityType;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapRenderingTypes;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.NameFinderPoiFilter; import net.osmand.plus.NameFinderPoiFilter;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.PoiFilter; import net.osmand.plus.PoiFilter;
@ -70,9 +71,8 @@ import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
@ -557,21 +557,26 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
@Override @Override
public void onListItemClick(ListView parent, View v, int position, long id) { public void onListItemClick(ListView parent, final View v, int position, long id) {
final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position); final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
final QuickAction qa = new QuickAction(v); ContextMenuAdapter adapter = new ContextMenuAdapter(v.getContext());
adapter.setAnchor(v);
String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, getMyApplication(), settings.usingEnglishNames()); String poiSimpleFormat = OsmAndFormatter.getPoiSimpleFormat(amenity, getMyApplication(), settings.usingEnglishNames());
String name = poiSimpleFormat; String name = poiSimpleFormat;
int z = Math.max(16, settings.getLastKnownMapZoom()); int z = Math.max(16, settings.getLastKnownMapZoom());
MapActivityActions.createDirectionsActions(qa, amenity.getLocation(), amenity, name, z, this, true , null);
ActionItem poiDescription = new ActionItem();
poiDescription.setIcon(getResources().getDrawable(R.drawable.ic_action_note_light));
poiDescription.setTitle(getString(R.string.poi_context_menu_showdescription));
MapActivityActions.createDirectionsActions(adapter, amenity.getLocation(), amenity, name, z, this, true );
final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false); final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false);
poiDescription.setOnClickListener(new OnClickListener() { if(d.toString().trim().length() > 0) {
Item poiDescr = adapter.item(R.string.poi_context_menu_showdescription).icons(R.drawable.ic_action_note_light,
R.drawable.ic_action_note_dark);
poiDescr.listen(new OnContextMenuClick() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dlg) {
// Build text(amenity) // Build text(amenity)
// Find and format links // Find and format links
@ -590,24 +595,19 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setLinksClickable(true); textView.setLinksClickable(true);
} }
}).reg();
});
if(d.toString().trim().length() > 0) {
qa.addActionItem(poiDescription);
} }
if (((OsmandApplication)getApplication()).accessibilityEnabled()) { if (((OsmandApplication)getApplication()).accessibilityEnabled()) {
ActionItem showDetails = new ActionItem(); Item showDetails = adapter.item(R.string.show_details);
showDetails.setTitle(getString(R.string.show_details)); showDetails.listen(new OnContextMenuClick() {
showDetails.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dlg) {
showPOIDetails(amenity, settings.usingEnglishNames()); showPOIDetails(amenity, settings.usingEnglishNames());
} }
}); }).reg();
qa.addActionItem(showDetails);
} }
qa.show(); MapActivityActions.showObjectContextMenu(adapter, this, null);
} }