Fixes
This commit is contained in:
parent
9669fac851
commit
9dca2d0709
6 changed files with 103 additions and 91 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<MenuObject> objects = new LinkedList<>();
|
||||
private Map<Object, IContextMenuProvider> 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<MenuObject> getObjects() {
|
||||
|
@ -102,7 +106,9 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
}
|
||||
|
||||
private void createCollection(Map<Object, IContextMenuProvider> selectedObjects) {
|
||||
this.selectedObjects.clear();
|
||||
this.selectedObjects.putAll(selectedObjects);
|
||||
objects.clear();
|
||||
int order = Integer.MAX_VALUE;
|
||||
MenuObject topObject = null;
|
||||
for (Map.Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
|
||||
|
@ -147,39 +153,50 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
}
|
||||
}
|
||||
|
||||
public static void show(LatLon latLon, Map<Object, IContextMenuProvider> 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<Object, IContextMenuProvider> selectedObjects) {
|
||||
if (isVisible()) {
|
||||
hide();
|
||||
}
|
||||
|
||||
for (Map.Entry<Object, IContextMenuProvider> 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<MenuObject>) objects;
|
||||
for (MenuObject menuObject : menu.objects) {
|
||||
menuObject.mapActivity = mapActivity;
|
||||
menuObject.init();
|
||||
}
|
||||
}
|
||||
|
||||
return menu;
|
||||
selectedObjects.clear();
|
||||
}
|
||||
}
|
|
@ -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<MenuObject> 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<MenuObject> createAdapter() {
|
||||
final List<MenuObject> items = menu.getObjects();
|
||||
final List<MenuObject> items = new LinkedList<>(menu.getObjects());
|
||||
return new ArrayAdapter<MenuObject>(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 {
|
|
@ -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<LatLon> 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<Object, IContextMenuProvider> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue