Main map on top in multi menu

This commit is contained in:
Alexey Kulish 2015-11-02 19:05:42 +03:00
parent 325ed39df8
commit 86c4a85e7b
6 changed files with 57 additions and 4 deletions

View file

@ -158,4 +158,13 @@ public class WorldRegion {
rd.superregion = this;
}
public int getLevel() {
int res = 0;
WorldRegion parent = superregion;
while (parent != null) {
parent = parent.superregion;
res++;
}
return res;
}
}

View file

@ -17,6 +17,7 @@ import net.osmand.plus.mapcontextmenu.MenuController;
public class MapDataMenuController extends MenuController {
private WorldRegion region;
private String regionName;
public MapDataMenuController(OsmandApplication app, MapActivity mapActivity, final BinaryMapDataObject dataObject) {
super(new MenuBuilder(app), mapActivity);
@ -24,6 +25,11 @@ public class MapDataMenuController extends MenuController {
String fullName = osmandRegions.getFullName(dataObject);
final WorldRegion region = osmandRegions.getRegionData(fullName);
this.region = region;
if (region != null) {
regionName = region.getLocaleName();
} else {
regionName = dataObject.getName();
}
titleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
@ -31,7 +37,7 @@ public class MapDataMenuController extends MenuController {
final Intent intent = new Intent(getMapActivity(), getMapActivity().getMyApplication()
.getAppCustomization().getDownloadIndexActivity());
intent.putExtra(DownloadActivity.FILTER_KEY, region.getLocaleName());
intent.putExtra(DownloadActivity.FILTER_KEY, regionName);
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
getMapActivity().startActivity(intent);
}
@ -57,12 +63,12 @@ public class MapDataMenuController extends MenuController {
@Override
public String getNameStr() {
return region.getLocaleName();
return regionName;
}
@Override
public String getTypeStr() {
if (region.getSuperregion() != null) {
if (region != null && region.getSuperregion() != null) {
return region.getSuperregion().getLocaleName() + "\n";
} else {
return getMapActivity().getString(R.string.shared_string_map) + "\n";

View file

@ -103,11 +103,14 @@ public class ObjectSelectionMenu extends BaseMenuController {
private void createCollection(Map<Object, IContextMenuProvider> selectedObjects) {
this.selectedObjects.putAll(selectedObjects);
int order = Integer.MAX_VALUE;
MenuObject topObject = null;
for (Map.Entry<Object, IContextMenuProvider> e : selectedObjects.entrySet()) {
Object selectedObj = e.getKey();
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
LatLon ll = null;
PointDescription pointDescription = null;
if (contextObject != null) {
ll = contextObject.getObjectLocation(selectedObj);
pointDescription = contextObject.getObjectName(selectedObj);
@ -121,13 +124,27 @@ public class ObjectSelectionMenu extends BaseMenuController {
MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
objects.add(menuObject);
if (contextObject instanceof ContextMenuLayer.IContextMenuProviderSelection) {
int i = ((ContextMenuLayer.IContextMenuProviderSelection) contextObject).getOrder(selectedObj);
if (i < order) {
topObject = menuObject;
order = i;
}
}
}
Collections.sort(objects, new Comparator<MenuObject>() {
@Override
public int compare(MenuObject obj1, MenuObject obj2) {
return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr());
}
});
if (topObject != null) {
objects.remove(topObject);
objects.add(0, topObject);
}
}
public static void show(LatLon latLon, Map<Object, IContextMenuProvider> selectedObjects, MapActivity mapActivity) {

View file

@ -400,6 +400,11 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
}, 350);
}
@Override
public int getOrder(Object o) {
return 0;
}
@Override
public void setSelectedObject(Object o) {
if(o instanceof OsMoDevice) {

View file

@ -39,6 +39,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
public interface IContextMenuProviderSelection {
int getOrder(Object o);
void setSelectedObject(Object o);
void clearSelectedObject();
}

View file

@ -403,10 +403,25 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
}
}
@Override
public int getOrder(Object o) {
if (o instanceof BinaryMapDataObject) {
String fullName = osmandRegions.getFullName((BinaryMapDataObject) o);
final WorldRegion region = osmandRegions.getRegionData(fullName);
if (region != null) {
return region.getLevel();
}
}
return 0;
}
@Override
public void setSelectedObject(Object o) {
if (o instanceof BinaryMapDataObject) {
List<BinaryMapDataObject> list = new LinkedList<>();
if (selectedObjects != null) {
list.addAll(selectedObjects);
}
list.add((BinaryMapDataObject) o);
selectedObjects = list;
}