diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 077075dc4d..9b7e9a86e4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -66,6 +66,7 @@ import net.osmand.plus.helpers.WakeLockHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.PointEditor; +import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; @@ -99,6 +100,7 @@ public class MapActivity extends AccessibleActivity { private static MapViewTrackingUtilities mapViewTrackingUtilities; private static MapContextMenu mapContextMenu = new MapContextMenu(); + private static MapMultiSelectionMenu mapMultiSelectionMenu; /** * Called when the activity is first created. @@ -162,7 +164,14 @@ public class MapActivity extends AccessibleActivity { settings = app.getSettings(); app.applyTheme(this); supportRequestWindowFeature(Window.FEATURE_NO_TITLE); + + if (mapMultiSelectionMenu == null) { + mapMultiSelectionMenu = new MapMultiSelectionMenu(this); + } else { + mapMultiSelectionMenu.setMapActivity(this); + } mapContextMenu.setMapActivity(this); + super.onCreate(savedInstanceState); // Full screen is not used here // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); @@ -970,6 +979,10 @@ public class MapActivity extends AccessibleActivity { return mapContextMenu; } + public MapMultiSelectionMenu getMultiSelectionMenu() { + return mapMultiSelectionMenu; + } + public FavoritePointEditor getFavoritePointEditor() { if (favoritePointEditor == null) { favoritePointEditor = new FavoritePointEditor(app, this); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java index 9cbba6ba0e..f5f5d9a08e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java @@ -19,6 +19,10 @@ public abstract class BaseMenuController { public BaseMenuController(MapActivity mapActivity) { this.mapActivity = mapActivity; + init(); + } + + private void init() { portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity); largeDevice = AndroidUiHelper.isXLargeDevice(mapActivity); light = mapActivity.getMyApplication().getSettings().isLightContent(); @@ -28,6 +32,11 @@ public abstract class BaseMenuController { return mapActivity; } + public void setMapActivity(MapActivity mapActivity) { + this.mapActivity = mapActivity; + init(); + } + public boolean isLight() { return light; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index e8a3ad67b8..0cae317312 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -68,11 +68,16 @@ public class MapDataMenuController extends MenuController { @Override public String getTypeStr() { + String res; if (region != null && region.getSuperregion() != null) { - return region.getSuperregion().getLocaleName() + "\n"; + res = region.getSuperregion().getLocaleName(); } else { - return getMapActivity().getString(R.string.shared_string_map) + "\n"; + res = getMapActivity().getString(R.string.shared_string_map); } + if (getMenuType() == MenuType.STANDARD) { + res += "\n"; + } + return res; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java similarity index 66% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index f22dc7f8ff..56f4a913bc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -1,6 +1,5 @@ package net.osmand.plus.mapcontextmenu.other; -import android.os.Bundle; import android.support.v4.app.Fragment; import net.osmand.data.LatLon; @@ -12,32 +11,30 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType; import net.osmand.plus.mapcontextmenu.MenuTitleController; import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; +import net.osmand.plus.views.OsmandMapLayer; -import java.io.Serializable; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; -public class ObjectSelectionMenu extends BaseMenuController { - - private static final String KEY_OBJ_SEL_MENU_LATLON = "key_obj_sel_menu_latlon"; - private static final String KEY_OBJ_SEL_MENU_OBJECTS = "key_obj_sel_menu_objects"; +public class MapMultiSelectionMenu extends BaseMenuController { private LatLon latLon; private LinkedList objects = new LinkedList<>(); private Map selectedObjects = new HashMap<>(); - public static class MenuObject extends MenuTitleController implements Serializable { + public static class MenuObject extends MenuTitleController { private LatLon latLon; private PointDescription pointDescription; private Object object; - private transient MapActivity mapActivity; - private transient MenuController controller; + private MapActivity mapActivity; + private MenuController controller; public MenuObject(LatLon latLon, PointDescription pointDescription, Object object, MapActivity mapActivity) { this.latLon = latLon; @@ -87,9 +84,16 @@ public class ObjectSelectionMenu extends BaseMenuController { } } - private ObjectSelectionMenu(LatLon latLon, MapActivity mapActivity) { + public MapMultiSelectionMenu(MapActivity mapActivity) { super(mapActivity); - this.latLon = latLon; + } + + public void setMapActivity(MapActivity mapActivity) { + super.setMapActivity(mapActivity); + for (MenuObject o : objects) { + o.mapActivity = mapActivity; + o.init(); + } } public List getObjects() { @@ -102,7 +106,9 @@ public class ObjectSelectionMenu extends BaseMenuController { } private void createCollection(Map selectedObjects) { + this.selectedObjects.clear(); this.selectedObjects.putAll(selectedObjects); + objects.clear(); int order = Integer.MAX_VALUE; MenuObject topObject = null; for (Map.Entry e : selectedObjects.entrySet()) { @@ -147,39 +153,50 @@ public class ObjectSelectionMenu extends BaseMenuController { } } - public static void show(LatLon latLon, Map selectedObjects, MapActivity mapActivity) { - - if (isVisible(mapActivity)) { - hide(mapActivity); - } - - ObjectSelectionMenu menu = new ObjectSelectionMenu(latLon, mapActivity); - menu.createCollection(selectedObjects); - ObjectSelectionMenuFragment.showInstance(menu); + private void clearMenu() { + clearSelectedObjects(); + objects.clear(); } - public static boolean isVisible(MapActivity mapActivity) { - Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(ObjectSelectionMenuFragment.TAG); + public void show(LatLon latLon, Map selectedObjects) { + if (isVisible()) { + hide(); + } + + for (Map.Entry e : selectedObjects.entrySet()) { + if (e.getValue() instanceof ContextMenuLayer.IContextMenuProviderSelection) { + ((ContextMenuLayer.IContextMenuProviderSelection) e.getValue()).setSelectedObject(e.getKey()); + } + } + + this.latLon = latLon; + createCollection(selectedObjects); + MapMultiSelectionMenuFragment.showInstance(getMapActivity()); + } + + public boolean isVisible() { + Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); return fragment != null; } - public static void hide(MapActivity mapActivity) { - Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(ObjectSelectionMenuFragment.TAG); + public void hide() { + clearMenu(); + Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); if (fragment != null) { - ObjectSelectionMenuFragment menuFragment = (ObjectSelectionMenuFragment) fragment; + MapMultiSelectionMenuFragment menuFragment = (MapMultiSelectionMenuFragment) fragment; menuFragment.dismissMenu(); } } - public void onDismiss() { + public void onStop() { + clearSelectedObjects(); } public void openContextMenu(MenuObject menuObject) { if (selectedObjects.containsKey(menuObject.getObject())) { selectedObjects.remove(menuObject.getObject()); } - clearSelectedObjects(); - hide(getMapActivity()); + hide(); getMapActivity().getContextMenu() .show(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject()); } @@ -190,32 +207,6 @@ public class ObjectSelectionMenu extends BaseMenuController { ((ContextMenuLayer.IContextMenuProviderSelection) p).clearSelectedObject(); } } - } - - public void saveMenu(Bundle bundle) { - bundle.putSerializable(KEY_OBJ_SEL_MENU_LATLON, latLon); - bundle.putSerializable(KEY_OBJ_SEL_MENU_OBJECTS, objects); - } - - @SuppressWarnings("unchecked") - public static ObjectSelectionMenu restoreMenu(Bundle bundle, MapActivity mapActivity) { - - LatLon latLon = null; - Object latLonObj = bundle.getSerializable(KEY_OBJ_SEL_MENU_LATLON); - if (latLonObj != null) { - latLon = (LatLon) latLonObj; - } - Object objects = bundle.getSerializable(KEY_OBJ_SEL_MENU_OBJECTS); - - ObjectSelectionMenu menu = new ObjectSelectionMenu(latLon, mapActivity); - if (objects != null) { - menu.objects = (LinkedList) objects; - for (MenuObject menuObject : menu.objects) { - menuObject.mapActivity = mapActivity; - menuObject.init(); - } - } - - return menu; + selectedObjects.clear(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenuFragment.java similarity index 85% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenuFragment.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenuFragment.java index ff3bb9dc88..8773a5f619 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenuFragment.java @@ -22,34 +22,27 @@ 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.MenuObject; +import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu.MenuObject; +import java.util.LinkedList; 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"; +public class MapMultiSelectionMenuFragment extends Fragment implements AdapterView.OnItemClickListener { + public static final String TAG = "MapMultiSelectionMenuFragment"; private View view; private ArrayAdapter listAdapter; - private ObjectSelectionMenu menu; - - public ObjectSelectionMenu getMenu() { - return menu; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (savedInstanceState != null && getActivity() instanceof MapActivity) { - menu = ObjectSelectionMenu.restoreMenu(savedInstanceState, (MapActivity) getActivity()); - } - } + private MapMultiSelectionMenu menu; + private boolean dismissing = false; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + menu = ((MapActivity) getActivity()).getMultiSelectionMenu(); + view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false); ListView listView = (ListView) view.findViewById(R.id.list); @@ -72,21 +65,19 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView @Override public void onStop() { super.onStop(); - menu.onDismiss(); + if (!dismissing) { + menu.onStop(); + } menu.getMapActivity().getContextMenu().setBaseFragmentVisibility(true); } - @Override - public void onSaveInstanceState(Bundle outState) { - menu.saveMenu(outState); - } + public static void showInstance(final MapActivity mapActivity) { + MapMultiSelectionMenu menu = mapActivity.getMultiSelectionMenu(); - public static void showInstance(ObjectSelectionMenu menu) { int slideInAnim = menu.getSlideInAnimation(); int slideOutAnim = menu.getSlideOutAnimation(); - ObjectSelectionMenuFragment fragment = new ObjectSelectionMenuFragment(); - fragment.menu = menu; + MapMultiSelectionMenuFragment fragment = new MapMultiSelectionMenuFragment(); menu.getMapActivity().getSupportFragmentManager().beginTransaction() .setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) .add(R.id.fragmentContainer, fragment, TAG) @@ -122,7 +113,7 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView } private ArrayAdapter createAdapter() { - final List items = menu.getObjects(); + final List items = new LinkedList<>(menu.getObjects()); return new ArrayAdapter(menu.getMapActivity(), R.layout.menu_obj_list_item, items) { @SuppressLint("InflateParams") @@ -175,6 +166,7 @@ public class ObjectSelectionMenuFragment extends Fragment implements AdapterView } public void dismissMenu() { + dismissing = true; if (menu.getMapActivity().getContextMenu().isVisible()) { menu.getMapActivity().getContextMenu().hide(); } else { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index b65e643153..44df467b4c 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -16,7 +16,7 @@ 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 net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import java.util.ArrayList; import java.util.HashMap; @@ -48,6 +48,7 @@ public class ContextMenuLayer extends OsmandMapLayer { private final MapActivity activity; private MapContextMenu menu; + private MapMultiSelectionMenu multiSelectionMenu; private CallbackWithObject selectOnMap = null; private ImageView contextMarker; @@ -57,6 +58,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public ContextMenuLayer(MapActivity activity){ this.activity = activity; menu = activity.getContextMenu(); + multiSelectionMenu = activity.getMultiSelectionMenu(); movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener()); } @@ -190,9 +192,9 @@ public class ContextMenuLayer extends OsmandMapLayer { l.collectObjectsFromPoint(point, tileBox, s); for (Object o : s) { selectedObjects.put(o, l); - if (l instanceof IContextMenuProviderSelection) { - ((IContextMenuProviderSelection) l).setSelectedObject(o); - } +// if (l instanceof IContextMenuProviderSelection) { +// ((IContextMenuProviderSelection) l).setSelectedObject(o); +// } } } } @@ -247,13 +249,13 @@ public class ContextMenuLayer extends OsmandMapLayer { } private void hideVisibleMenues() { - if (ObjectSelectionMenu.isVisible(activity)) { - ObjectSelectionMenu.hide(activity); + if (multiSelectionMenu.isVisible()) { + multiSelectionMenu.hide(); } } private void showContextMenuForSelectedObjects(final LatLon latLon, final Map selectedObjects) { - ObjectSelectionMenu.show(latLon, selectedObjects, activity); + multiSelectionMenu.show(latLon, selectedObjects); } @Override @@ -263,8 +265,8 @@ public class ContextMenuLayer extends OsmandMapLayer { if (menu.isVisible()) { menu.hide(); } - if (ObjectSelectionMenu.isVisible(activity)) { - ObjectSelectionMenu.hide(activity); + if (multiSelectionMenu.isVisible()) { + multiSelectionMenu.hide(); } }