Refactor context menu for objects - make it quickaction independent and special case for accessibility
This commit is contained in:
parent
43784a1260
commit
7fa56e1268
8 changed files with 199 additions and 161 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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
|
|
||||||
public void onClick(View v) {
|
|
||||||
editPoint(point);
|
|
||||||
qa.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
qa.addActionItem(edit);
|
|
||||||
|
|
||||||
ActionItem delete = new ActionItem();
|
@Override
|
||||||
delete.setTitle(getString(R.string.favourites_context_menu_delete));
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
delete.setIcon(getResources().getDrawable(R.drawable.ic_action_delete_light));
|
editPoint(point);
|
||||||
delete.setOnClickListener(new OnClickListener() {
|
}
|
||||||
@Override
|
}).reg();
|
||||||
public void onClick(View v) {
|
Item delete = qa.item(R.string.favourites_context_menu_delete).icons(R.drawable.ic_action_delete_light ,
|
||||||
deletePoint(point);
|
R.drawable.ic_action_delete_dark);
|
||||||
qa.dismiss();
|
delete.listen(
|
||||||
}
|
new OnContextMenuClick() {
|
||||||
});
|
|
||||||
qa.addActionItem(delete);
|
|
||||||
|
|
||||||
qa.show();
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
deletePoint(point);
|
||||||
|
}
|
||||||
|
}).reg();
|
||||||
|
MapActivityActions.showObjectContextMenu(qa, getActivity(), onshow);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
|
||||||
setAsDestination.setTitle(activity.getString(R.string.get_directions));
|
|
||||||
setAsDestination.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (onShow != null) {
|
|
||||||
onShow.onClick(v);
|
|
||||||
}
|
|
||||||
qa.dismiss();
|
|
||||||
MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
qa.addActionItem(setAsDestination);
|
|
||||||
|
|
||||||
ActionItem intermediate = new ActionItem();
|
Item dir = qa.item(R.string.get_directions).icons(R.drawable.ic_action_gdirections_light ,
|
||||||
if (targetPointsHelper.getPointToNavigate() != null) {
|
R.drawable.ic_action_gdirections_dark);
|
||||||
intermediate.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_flage_light));
|
dir.listen(
|
||||||
intermediate.setTitle(activity.getString(R.string.context_menu_item_intermediate_point));
|
new OnContextMenuClick() {
|
||||||
} else {
|
|
||||||
intermediate.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_flag_light));
|
|
||||||
intermediate.setTitle(activity.getString(R.string.context_menu_item_destination_point));
|
|
||||||
}
|
|
||||||
intermediate.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (onShow != null) {
|
|
||||||
onShow.onClick(v);
|
|
||||||
}
|
|
||||||
addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
|
|
||||||
qa.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
qa.addActionItem(intermediate);
|
|
||||||
|
|
||||||
ActionItem showOnMap = new ActionItem();
|
@Override
|
||||||
showOnMap.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_marker_light));
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
showOnMap.setTitle(activity.getString(R.string.show_poi_on_map));
|
MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
|
||||||
showOnMap.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (onShow != null) {
|
|
||||||
onShow.onClick(v);
|
|
||||||
}
|
|
||||||
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name,
|
|
||||||
obj); //$NON-NLS-1$
|
|
||||||
MapActivity.launchMapActivityMoveToTop(activity);
|
|
||||||
qa.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
qa.addActionItem(showOnMap);
|
|
||||||
|
|
||||||
if (favorite) {
|
|
||||||
ActionItem addToFavorite = new ActionItem();
|
|
||||||
addToFavorite.setIcon(activity.getResources().getDrawable(R.drawable.ic_action_fav_light));
|
|
||||||
addToFavorite.setTitle(activity.getString(R.string.add_to_favourite));
|
|
||||||
addToFavorite.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (onShow != null) {
|
|
||||||
onShow.onClick(v);
|
|
||||||
}
|
}
|
||||||
qa.dismiss();
|
}).reg();
|
||||||
|
Item intermediate;
|
||||||
|
if (targetPointsHelper.getPointToNavigate() != null) {
|
||||||
|
intermediate = qa.item(R.string.context_menu_item_intermediate_point).icons(R.drawable.ic_action_flage_light,
|
||||||
|
R.drawable.ic_action_flage_dark);
|
||||||
|
} else {
|
||||||
|
intermediate = qa.item(R.string.context_menu_item_destination_point).icons(R.drawable.ic_action_flag_light,
|
||||||
|
R.drawable.ic_action_flag_dark);
|
||||||
|
}
|
||||||
|
intermediate.listen(new OnContextMenuClick() {
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
|
||||||
|
}
|
||||||
|
}).reg();
|
||||||
|
|
||||||
|
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() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
app.getSettings().setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, saveHistory ? name : null, name,
|
||||||
|
obj); //$NON-NLS-1$
|
||||||
|
MapActivity.launchMapActivityMoveToTop(activity);
|
||||||
|
}
|
||||||
|
}).reg();
|
||||||
|
if (favorite) {
|
||||||
|
Item addToFavorite = qa.item(R.string.add_to_favourite).icons(R.drawable.ic_action_fav_light,
|
||||||
|
R.drawable.ic_action_fav_dark);
|
||||||
|
addToFavorite.listen(new OnContextMenuClick() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
Dialog dlg = createAddFavouriteDialog(activity, args);
|
Dialog dlg = createAddFavouriteDialog(activity, args);
|
||||||
dlg.show();
|
dlg.show();
|
||||||
prepareAddFavouriteDialog(activity, dlg, args, location.getLatitude(), location.getLongitude(), name);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
qa.addActionItem(addToFavorite);
|
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
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (onShow != null) {
|
||||||
|
onShow.onClick(v);
|
||||||
|
}
|
||||||
|
view.dismiss();
|
||||||
|
qa.getClickAdapter(ki).onContextMenuClick(qa.getItemId(ki), ki, false, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
view.addActionItem(ai);
|
||||||
|
}
|
||||||
|
view.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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> {
|
||||||
|
|
|
@ -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,57 +557,57 @@ 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() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// Build text(amenity)
|
|
||||||
|
|
||||||
// Find and format links
|
|
||||||
SpannableString spannable = new SpannableString(d);
|
|
||||||
Linkify.addLinks(spannable, Linkify.ALL);
|
|
||||||
|
|
||||||
// Create dialog
|
|
||||||
Builder bs = new AlertDialog.Builder(v.getContext());
|
|
||||||
bs.setTitle(OsmAndFormatter.getPoiSimpleFormat(amenity, getMyApplication(),
|
|
||||||
settings.USE_ENGLISH_NAMES.get()));
|
|
||||||
bs.setMessage(spannable);
|
|
||||||
AlertDialog dialog = bs.show();
|
|
||||||
|
|
||||||
// Make links clickable
|
|
||||||
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
|
|
||||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
textView.setLinksClickable(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
if(d.toString().trim().length() > 0) {
|
if(d.toString().trim().length() > 0) {
|
||||||
qa.addActionItem(poiDescription);
|
Item poiDescr = adapter.item(R.string.poi_context_menu_showdescription).icons(R.drawable.ic_action_note_light,
|
||||||
}
|
R.drawable.ic_action_note_dark);
|
||||||
if (((OsmandApplication)getApplication()).accessibilityEnabled()) {
|
poiDescr.listen(new OnContextMenuClick() {
|
||||||
ActionItem showDetails = new ActionItem();
|
|
||||||
showDetails.setTitle(getString(R.string.show_details));
|
|
||||||
showDetails.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dlg) {
|
||||||
|
// Build text(amenity)
|
||||||
|
|
||||||
|
// Find and format links
|
||||||
|
SpannableString spannable = new SpannableString(d);
|
||||||
|
Linkify.addLinks(spannable, Linkify.ALL);
|
||||||
|
|
||||||
|
// Create dialog
|
||||||
|
Builder bs = new AlertDialog.Builder(v.getContext());
|
||||||
|
bs.setTitle(OsmAndFormatter.getPoiSimpleFormat(amenity, getMyApplication(),
|
||||||
|
settings.USE_ENGLISH_NAMES.get()));
|
||||||
|
bs.setMessage(spannable);
|
||||||
|
AlertDialog dialog = bs.show();
|
||||||
|
|
||||||
|
// Make links clickable
|
||||||
|
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
|
||||||
|
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
textView.setLinksClickable(true);
|
||||||
|
}
|
||||||
|
}).reg();
|
||||||
|
}
|
||||||
|
if (((OsmandApplication)getApplication()).accessibilityEnabled()) {
|
||||||
|
Item showDetails = adapter.item(R.string.show_details);
|
||||||
|
showDetails.listen(new OnContextMenuClick() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue