Menu for selection object on map is in progress

This commit is contained in:
Alexey Kulish 2015-10-24 19:02:34 +03:00
parent 1620d1b0b2
commit 7860b46a5c
8 changed files with 455 additions and 229 deletions

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/expandable_list_item_background"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/context_menu_icon_layout"
android:layout_width="42dp"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/context_menu_icon_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="18dp"
android:scaleType="center"
android:src="@drawable/ic_action_building_number"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/context_menu_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/search_address_building"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"/>
<TextView
android:id="@+id/context_menu_line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="4dp"
android:text="@string/other_location"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
<LinearLayout
android:id="@+id/context_menu_close_btn_layout"
android:layout_width="32dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/close_btn_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="12dp"
android:scaleType="center"
android:src="@drawable/ic_action_remove_dark"/>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/share_fragment_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<LinearLayout
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
<ListView
android:id="@+id/list"
android:divider="@null"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</LinearLayout>
</FrameLayout>

View file

@ -161,7 +161,7 @@ public class MapActivity extends AccessibleActivity {
app = getMyApplication();
settings = app.getSettings();
app.applyTheme(this);
contextMenuOnMap = new MapContextMenu(app, this);
contextMenuOnMap = new MapContextMenu(this);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
// Full screen is not used here

View file

@ -1,57 +1,32 @@
package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import net.osmand.Location;
import net.osmand.ResultMatcher;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
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.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.details.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.details.ParkingPositionController;
import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.util.Algorithms;
public class MapContextMenu {
public class MapContextMenu extends MenuTitleController {
private OsmandApplication app;
private OsmandSettings settings;
private final MapActivity mapActivity;
private boolean active;
private LatLon latLon;
private PointDescription pointDescription;
private Object object;
MenuController menuController;
private MenuController menuController;
private LatLon mapCenter;
private int mapPosition = 0;
private int leftIconId;
private Drawable leftIcon;
private String nameStr;
private String typeStr;
private Drawable secondLineIcon;
private String streetStr;
private boolean addressUnknown;
private int favActionIconId;
private static final String KEY_CTX_MENU_OBJECT = "key_ctx_menu_object";
@ -65,6 +40,11 @@ public class MapContextMenu {
private static final String KEY_CTX_MENU_MAP_CENTER = "key_ctx_menu_map_center";
private static final String KEY_CTX_MENU_MAP_POSITION = "key_ctx_menu_map_position";
@Override
public MapActivity getMapActivity() {
return mapActivity;
}
public boolean isActive() {
return active;
}
@ -73,6 +53,7 @@ public class MapContextMenu {
return findMenuFragment() != null;
}
@Override
public LatLon getLatLon() {
return latLon;
}
@ -89,10 +70,12 @@ public class MapContextMenu {
this.mapPosition = mapPosition;
}
@Override
public PointDescription getPointDescription() {
return pointDescription;
}
@Override
public Object getObject() {
return object;
}
@ -101,10 +84,13 @@ public class MapContextMenu {
return menuController != null;
}
public MapContextMenu(OsmandApplication app, MapActivity mapActivity) {
this.app = app;
@Override
public MenuController getMenuController() {
return menuController;
}
public MapContextMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity;
settings = app.getSettings();
}
public boolean init(LatLon latLon, PointDescription pointDescription, Object object) {
@ -132,20 +118,12 @@ public class MapContextMenu {
this.latLon = latLon;
this.object = object;
leftIconId = 0;
nameStr = "";
typeStr = "";
streetStr = "";
addressUnknown = false;
active = true;
acquireMenuController();
acquireIcons();
acquireNameAndType();
if (needStreetName()) {
acquireStreetName(latLon);
}
initTitle();
if (menuController != null) {
menuController.addPlainMenuItems(typeStr, this.pointDescription);
}
@ -221,14 +199,7 @@ public class MapContextMenu {
}
}
private boolean needStreetName() {
boolean res = object != null || Algorithms.isEmpty(pointDescription.getName());
if (res && menuController != null) {
res = menuController.needStreetName();
}
return res;
}
@Override
public void refreshMenuTitle() {
MapContextMenuFragment fragment = findMenuFragment();
if (fragment != null)
@ -244,121 +215,20 @@ public class MapContextMenu {
}
}
public int getLeftIconId() {
return leftIconId;
}
public int getFavActionIconId() {
return favActionIconId;
}
public Drawable getLeftIcon() {
return leftIcon;
}
public Drawable getSecondLineIcon() {
return secondLineIcon;
}
public String getTitleStr() {
return nameStr;
}
public boolean isAddressUnknown() {
return addressUnknown;
}
public String getLocationStr() {
if (menuController != null && menuController.needTypeStr()) {
return typeStr;
} else {
if (Algorithms.isEmpty(streetStr)) {
return PointDescription.getLocationName(mapActivity,
latLon.getLatitude(), latLon.getLongitude(), true).replaceAll("\n", "");
} else {
return streetStr;
}
}
}
private void acquireIcons() {
leftIconId = 0;
leftIcon = null;
secondLineIcon = null;
favActionIconId = R.drawable.ic_action_fav_dark;
protected void acquireIcons() {
super.acquireIcons();
if (menuController != null) {
leftIconId = menuController.getLeftIconId();
leftIcon = menuController.getLeftIcon();
secondLineIcon = menuController.getSecondLineIcon();
favActionIconId = menuController.getFavActionIconId();
} else {
favActionIconId = R.drawable.ic_action_fav_dark;
}
}
private void acquireNameAndType() {
if (menuController != null) {
nameStr = menuController.getNameStr();
typeStr = menuController.getTypeStr();
}
if (Algorithms.isEmpty(nameStr)) {
nameStr = pointDescription.getName();
}
if (Algorithms.isEmpty(typeStr)) {
typeStr = pointDescription.getTypeName();
}
if (Algorithms.isEmpty(nameStr)) {
if (!Algorithms.isEmpty(typeStr)) {
nameStr = typeStr;
typeStr = "";
} else {
nameStr = app.getResources().getString(R.string.address_unknown);
addressUnknown = true;
}
}
}
private void acquireStreetName(final LatLon loc) {
Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
app.getLocationProvider().getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object != null) {
streetStr = RoutingHelper.formatStreetName(object.getName(settings.MAP_PREFERRED_LOCALE.get()),
object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
if (!Algorithms.isEmpty(streetStr)) {
if (getObject() == null) {
nameStr = streetStr;
addressUnknown = false;
streetStr = "";
}
mapActivity.runOnUiThread(new Runnable() {
public void run() {
refreshMenuTitle();
}
});
}
} else {
streetStr = "";
}
return true;
}
@Override
public boolean isCancelled() {
return false;
}
});
}
public void fabPressed() {
mapActivity.getMapActions().directionTo(latLon.getLatitude(), latLon.getLongitude());
hide();

View file

@ -0,0 +1,169 @@
package net.osmand.plus.mapcontextmenu;
import android.graphics.drawable.Drawable;
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.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.util.Algorithms;
public abstract class MenuTitleController {
protected int leftIconId;
protected Drawable leftIcon;
protected String nameStr = "";
protected String typeStr = "";
protected Drawable secondLineIcon;
protected String streetStr = "";
protected boolean addressUnknown = false;
public abstract MapActivity getMapActivity();
public abstract LatLon getLatLon();
public abstract PointDescription getPointDescription();
public abstract Object getObject();
public abstract MenuController getMenuController();
public String getTitleStr() {
return nameStr;
}
public boolean isAddressUnknown() {
return addressUnknown;
}
public int getLeftIconId() {
return leftIconId;
}
public Drawable getLeftIcon() {
return leftIcon;
}
public Drawable getSecondLineIcon() {
return secondLineIcon;
}
public String getLocationStr() {
MenuController menuController = getMenuController();
if (menuController != null && menuController.needTypeStr()) {
return typeStr;
} else {
if (Algorithms.isEmpty(streetStr)) {
return PointDescription.getLocationName(getMapActivity(),
getLatLon().getLatitude(), getLatLon().getLongitude(), true).replaceAll("\n", "");
} else {
return streetStr;
}
}
}
protected void initTitle() {
acquireIcons();
acquireNameAndType();
if (needStreetName()) {
acquireStreetName();
}
}
protected boolean needStreetName() {
MenuController menuController = getMenuController();
boolean res = getObject() != null || Algorithms.isEmpty(getPointDescription().getName());
if (res && menuController != null) {
res = menuController.needStreetName();
}
return res;
}
protected void acquireIcons() {
MenuController menuController = getMenuController();
leftIconId = 0;
leftIcon = null;
secondLineIcon = null;
if (menuController != null) {
leftIconId = menuController.getLeftIconId();
leftIcon = menuController.getLeftIcon();
secondLineIcon = menuController.getSecondLineIcon();
}
}
protected void acquireNameAndType() {
MenuController menuController = getMenuController();
PointDescription pointDescription = getPointDescription();
if (menuController != null) {
nameStr = menuController.getNameStr();
typeStr = menuController.getTypeStr();
}
if (Algorithms.isEmpty(nameStr)) {
nameStr = pointDescription.getName();
}
if (Algorithms.isEmpty(typeStr)) {
typeStr = pointDescription.getTypeName();
}
if (Algorithms.isEmpty(nameStr)) {
if (!Algorithms.isEmpty(typeStr)) {
nameStr = typeStr;
typeStr = "";
} else {
nameStr = getMapActivity().getString(R.string.address_unknown);
addressUnknown = true;
}
}
}
protected void acquireStreetName() {
Location ll = new Location("");
ll.setLatitude(getLatLon().getLatitude());
ll.setLongitude(getLatLon().getLongitude());
getMapActivity().getMyApplication().getLocationProvider()
.getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object != null) {
OsmandSettings settings = getMapActivity().getMyApplication().getSettings();
streetStr = RoutingHelper.formatStreetName(object.getName(settings.MAP_PREFERRED_LOCALE.get()),
object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
if (!Algorithms.isEmpty(streetStr)) {
if (getObject() == null) {
nameStr = streetStr;
addressUnknown = false;
streetStr = "";
}
getMapActivity().runOnUiThread(new Runnable() {
public void run() {
refreshMenuTitle();
}
});
}
} else {
streetStr = "";
}
return true;
}
@Override
public boolean isCancelled() {
return false;
}
});
}
protected abstract void refreshMenuTitle();
}

View file

@ -1,15 +1,19 @@
package net.osmand.plus.mapcontextmenu.other;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.BaseMenuController;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.MenuTitleController;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -20,39 +24,62 @@ public class ObjectSelectionMenu extends BaseMenuController {
private static final String KEY_OBJ_SEL_MENU_OBJECTS = "key_obj_sel_menu_objects";
private LatLon latLon;
private LinkedList<MenuMapObject> objects = new LinkedList<>();
private LinkedList<MenuObject> objects = new LinkedList<>();
private Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
public static class MenuMapObject implements Serializable {
public static class MenuObject extends MenuTitleController implements Serializable {
private LatLon latLon;
private PointDescription pointDescription;
private Object object;
private transient MapActivity mapActivity;
private transient MenuController controller;
public MenuMapObject(LatLon latLon, PointDescription pointDescription, Object object) {
public MenuObject(LatLon latLon, PointDescription pointDescription, Object object, MapActivity mapActivity) {
this.latLon = latLon;
this.pointDescription = pointDescription;
this.object = object;
this.mapActivity = mapActivity;
}
@Override
public LatLon getLatLon() {
return latLon;
}
@Override
public PointDescription getPointDescription() {
return pointDescription;
}
@Override
public Object getObject() {
return object;
}
public MenuController getController(MapActivity mapActivity) {
@Override
public MapActivity getMapActivity() {
return mapActivity;
}
@Override
public MenuController getMenuController() {
if (controller == null) {
controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object);
initTitle();
}
return controller;
}
@Override
protected void refreshMenuTitle() {
}
@Override
protected boolean needStreetName() {
return false;
}
}
private ObjectSelectionMenu(LatLon latLon, MapActivity mapActivity) {
@ -60,11 +87,12 @@ public class ObjectSelectionMenu extends BaseMenuController {
this.latLon = latLon;
}
public List<MenuMapObject> getObjects() {
public List<MenuObject> getObjects() {
return objects;
}
private void createCollection(Map<Object, IContextMenuProvider> selectedObjects) {
this.selectedObjects.putAll(selectedObjects);
for (Map.Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
Object selectedObj = e.getKey();
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
@ -81,14 +109,50 @@ public class ObjectSelectionMenu extends BaseMenuController {
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
}
objects.add(new MenuMapObject(ll, pointDescription, selectedObj));
MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
objects.add(menuObject);
}
}
public static void show(LatLon latLon, MapActivity mapActivity, Map<Object, IContextMenuProvider> selectedObjects) {
public static void show(LatLon latLon, Map<Object, IContextMenuProvider> selectedObjects, MapActivity mapActivity) {
ObjectSelectionMenu menu = new ObjectSelectionMenu(latLon, mapActivity);
menu.createCollection(selectedObjects);
ObjectSelectionMenuFragment.showInstance(menu);
}
public static boolean isVisible(MapActivity mapActivity) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(ObjectSelectionMenuFragment.TAG);
return fragment != null;
}
public static void hide(MapActivity mapActivity) {
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(ObjectSelectionMenuFragment.TAG);
if (fragment != null) {
ObjectSelectionMenuFragment menuFragment = (ObjectSelectionMenuFragment) fragment;
menuFragment.dismissMenu();
}
}
public void onDismiss() {
clearSelectedObjects();
}
public void openContextMenu(MenuObject menuObject) {
if (selectedObjects.containsKey(menuObject.getObject())) {
selectedObjects.remove(menuObject.getObject());
}
hide(getMapActivity());
getMapActivity().getContextMenu()
.show(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject());
}
private void clearSelectedObjects() {
for(IContextMenuProvider p : selectedObjects.values()) {
if(p instanceof ContextMenuLayer.IContextMenuProviderSelection){
((ContextMenuLayer.IContextMenuProviderSelection) p).clearSelectedObject();
}
}
}
public void saveMenu(Bundle bundle) {
@ -96,6 +160,7 @@ public class ObjectSelectionMenu extends BaseMenuController {
bundle.putSerializable(KEY_OBJ_SEL_MENU_OBJECTS, objects);
}
@SuppressWarnings("unchecked")
public static ObjectSelectionMenu restoreMenu(Bundle bundle, MapActivity mapActivity) {
LatLon latLon = null;
@ -107,7 +172,10 @@ public class ObjectSelectionMenu extends BaseMenuController {
ObjectSelectionMenu menu = new ObjectSelectionMenu(latLon, mapActivity);
if (objects != null) {
menu.objects = (LinkedList<MenuMapObject>) objects;
menu.objects = (LinkedList<MenuObject>) objects;
for (MenuObject menuObject : menu.objects) {
menuObject.mapActivity = mapActivity;
}
}
return menu;

View file

@ -1,28 +1,40 @@
package net.osmand.plus.mapcontextmenu.other;
import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.ObjectSelectionMenu.MenuMapObject;
import net.osmand.plus.mapcontextmenu.other.ObjectSelectionMenu.MenuObject;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class ObjectSelectionMenuFragment extends Fragment implements AdapterView.OnItemClickListener {
public static final String TAG = "ObjectSelectionMenuFragment";
private ArrayAdapter<MenuMapObject> listAdapter;
private ArrayAdapter<MenuObject> listAdapter;
private ObjectSelectionMenu menu;
public ObjectSelectionMenu getMenu() {
return menu;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -34,7 +46,7 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.share_menu_fragment, container, false);
View view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
ListView listView = (ListView) view.findViewById(R.id.list);
listAdapter = createAdapter();
@ -53,6 +65,7 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
@Override
public void onStop() {
super.onStop();
menu.onDismiss();
menu.getMapActivity().getContextMenu().setBaseFragmentVisibility(true);
}
@ -73,34 +86,61 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
.addToBackStack(TAG).commit();
}
private ArrayAdapter<MenuMapObject> createAdapter() {
final List<MenuMapObject> items = menu.getObjects();
return new ArrayAdapter<MenuMapObject>(menu.getMapActivity(), R.layout.share_list_item, items) {
private ArrayAdapter<MenuObject> createAdapter() {
final List<MenuObject> items = menu.getObjects();
return new ArrayAdapter<MenuObject>(menu.getMapActivity(), R.layout.menu_obj_list_item, items) {
@SuppressLint("InflateParams")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
v = menu.getMapActivity().getLayoutInflater().inflate(R.layout.share_list_item, null);
v = menu.getMapActivity().getLayoutInflater().inflate(R.layout.menu_obj_list_item, null);
}
final MenuMapObject item = getItem(position);
/*
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(menu.getMapActivity().getMyApplication()
.getIconsCache().getContentIcon(item.getIconResourceId()));
TextView name = (TextView) v.findViewById(R.id.name);
name.setText(getContext().getText(item.getTitleResourceId()));
*/
final MenuObject item = getItem(position);
buildHeader(v, item, menu.getMapActivity());
return v;
}
};
}
private void buildHeader(View view, MenuObject item, MapActivity mapActivity) {
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
boolean light = mapActivity.getMyApplication().getSettings().isLightContent();
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 = item.getLeftIcon();
int iconId = item.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);
}
// Text line 1
TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
line1.setText(item.getTitleStr());
// Text line 2
TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
line2.setText(item.getLocationStr());
Drawable slIcon = item.getSecondLineIcon();
if (slIcon != null) {
line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
line2.setCompoundDrawablePadding(dpToPx(5f));
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//menu.share(listAdapter.getItem(position));
dismissMenu();
menu.openContextMenu(listAdapter.getItem(position));
}
public void dismissMenu() {
@ -110,4 +150,13 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView
menu.getMapActivity().getSupportFragmentManager().popBackStack();
}
}
private int dpToPx(float dp) {
Resources r = getActivity().getResources();
return (int) TypedValue.applyDimension(
COMPLEX_UNIT_DIP,
dp,
r.getDisplayMetrics()
);
}
}

View file

@ -1,10 +1,5 @@
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.PointF;
import android.graphics.Rect;
@ -21,12 +16,12 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.other.ObjectSelectionMenu;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class ContextMenuLayer extends OsmandMapLayer {
@ -102,14 +97,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
this.selectOnMap = selectOnMap;
}
private void clearSelectedObjects(Map<Object, IContextMenuProvider> selectedObjects) {
for(IContextMenuProvider p : selectedObjects.values()) {
if(p instanceof IContextMenuProviderSelection){
((IContextMenuProviderSelection) p).clearSelectedObject();
}
}
}
@Override
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
if (disableLongPressOnMap()) {
@ -250,47 +237,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
}
ObjectSelectionMenu.hide(activity);
menu.onSingleTapOnMap();
return false;
}
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<>();
int i = 0;
for (Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
d[i++] = e.getValue().getObjectDescription(e.getKey());
s.add(e.getKey());
}
builder.setItems(d, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Object selectedObj = s.get(which);
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
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();
ObjectSelectionMenu.show(latLon, selectedObjects, activity);
}
@Override
@ -300,6 +253,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (menu.isVisible()) {
menu.hide();
}
if (ObjectSelectionMenu.isVisible(activity)) {
ObjectSelectionMenu.hide(activity);
}
}
return false;