From a34eb35a4213410a972fd07dfa936bc7b60bbc3e Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 2 Nov 2015 13:10:24 +0300 Subject: [PATCH] Context menu: download map in progress --- .../res/layout/map_context_menu_fragment.xml | 1 + .../src/net/osmand/data/PointDescription.java | 3 +- .../plus/download/DownloadResourceGroup.java | 25 ------ .../plus/mapcontextmenu/MapContextMenu.java | 8 ++ .../MapContextMenuFragment.java | 23 +++-- .../plus/mapcontextmenu/MenuController.java | 10 ++- .../WorldRegionMenuController.java | 89 +++++++++++++++++++ .../EditCategoryDialogFragment.java | 5 +- .../editors/PointEditorFragment.java | 1 - .../SelectCategoryDialogFragment.java | 4 +- .../plus/views/DownloadedRegionsLayer.java | 77 ++++++++++++++-- 11 files changed, 200 insertions(+), 46 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java rename OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/{dialogs => }/EditCategoryDialogFragment.java (96%) rename OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/{dialogs => }/SelectCategoryDialogFragment.java (96%) diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index 5d5f9e06d8..7c51abffe8 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -129,6 +129,7 @@ diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index ffc39c34a8..d29c0a1feb 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -39,7 +39,8 @@ public class PointDescription { public static final String POINT_TYPE_ALARM = "alarm"; public static final String POINT_TYPE_TARGET = "destination"; public static final String POINT_TYPE_OSM_BUG = "bug"; - + public static final String POINT_TYPE_WORLD_REGION = "world_region"; + public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java index a9646b40f5..f678997253 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResourceGroup.java @@ -100,11 +100,6 @@ public class DownloadResourceGroup { this.parentGroup = parentGroup; } - public WorldRegion getIndexItemRegion(IndexItem item) { - DownloadResourceGroup group = getIndexItemGroup(item); - return getRegion(group); - } - public static WorldRegion getRegion(DownloadResourceGroup group) { if (group != null) { if (group.getRegion() != null) { @@ -119,26 +114,6 @@ public class DownloadResourceGroup { } } - public DownloadResourceGroup getIndexItemGroup(IndexItem item) { - DownloadResourceGroup res = null; - for (DownloadResourceGroup group : getGroups()) { - if (group.getIndividualResources() != null) { - for (IndexItem i : group.getIndividualResources()) { - if (i == item) { - res = group; - break; - } - } - } else { - res = group.getIndexItemGroup(item); - if (res != null) { - break; - } - } - } - return res; - } - public void trimEmptyGroups() { if(groups != null) { for(DownloadResourceGroup gr : groups) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index e65f61d32a..4f0baee064 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -365,4 +365,12 @@ public class MapContextMenu extends MenuTitleController { return null; } } + + public boolean fabVisible() { + return menuController == null || menuController.fabVisible(); + } + + public boolean buttonsVisible() { + return menuController == null || menuController.buttonsVisible(); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 95617d27c6..fe92ccec4f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -345,12 +345,23 @@ public class MapContextMenuFragment extends Fragment { // FAB fabView = (ImageView)view.findViewById(R.id.context_menu_fab_view); - fabView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - menu.fabPressed(); - } - }); + if (menu.fabVisible()) { + fabView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + menu.fabPressed(); + } + }); + } else { + fabView.setVisibility(View.GONE); + } + + if (!menu.buttonsVisible()) { + View buttonsTopBorder = view.findViewById(R.id.buttons_top_border); + View buttons = view.findViewById(R.id.context_menu_buttons); + buttonsTopBorder.setVisibility(View.GONE); + buttons.setVisibility(View.GONE); + } // Action buttons final ImageButton buttonFavorite = (ImageButton) view.findViewById(R.id.context_menu_fav_button); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index e0cfd3e0cb..84ee23fb6e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -7,6 +7,7 @@ import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.map.WorldRegion; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -24,6 +25,7 @@ import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController; import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController; import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; +import net.osmand.plus.mapcontextmenu.controllers.WorldRegionMenuController; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.osmedit.OsmPoint; @@ -109,6 +111,8 @@ public abstract class MenuController extends BaseMenuController { menuController = new EditPOIMenuController(app, mapActivity, pointDescription, (OsmPoint) object); } else if (object instanceof WptPt) { menuController = new WptPtMenuController(app, mapActivity, (WptPt) object); + } else if (object instanceof WorldRegion) { + menuController = new WorldRegionMenuController(app, mapActivity, (WorldRegion) object); } else if (object instanceof LatLon) { if (pointDescription.isParking()) { menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription); @@ -204,7 +208,11 @@ public abstract class MenuController extends BaseMenuController { return titleButtonController; } - public boolean shouldShowButtons() { + public boolean fabVisible() { + return true; + } + + public boolean buttonsVisible() { return true; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java new file mode 100644 index 0000000000..6baacc37b7 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java @@ -0,0 +1,89 @@ +package net.osmand.plus.mapcontextmenu.controllers; + +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.util.Log; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.map.WorldRegion; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.download.DownloadResourceGroup; +import net.osmand.plus.download.DownloadResources; +import net.osmand.plus.download.IndexItem; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; + +public class WorldRegionMenuController extends MenuController { + private WorldRegion region; + + public WorldRegionMenuController(OsmandApplication app, MapActivity mapActivity, final WorldRegion region) { + super(new MenuBuilder(app), mapActivity); + this.region = region; + titleButtonController = new TitleButtonController() { + @Override + public void buttonPressed() { + getMapActivity().getContextMenu().close(); + + final Intent intent = new Intent(getMapActivity(), getMapActivity().getMyApplication() + .getAppCustomization().getDownloadIndexActivity()); + intent.putExtra(DownloadActivity.FILTER_KEY, region.getLocaleName()); + intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); + getMapActivity().startActivity(intent); + } + }; + titleButtonController.caption = getMapActivity().getString(R.string.shared_string_download_map); + titleButtonController.leftIconId = R.drawable.ic_action_import; + } + + @Override + protected int getSupportedMenuStatesPortrait() { + return MenuState.HEADER_ONLY; + } + + @Override + public boolean needTypeStr() { + return true; + } + + @Override + public Drawable getLeftIcon() { + return getIcon(R.drawable.ic_map, R.color.osmand_orange_dark, R.color.osmand_orange); + } + + @Override + public String getNameStr() { + return region.getLocaleName(); + } + + @Override + public String getTypeStr() { + if (region.getSuperregion() != null) { + return region.getSuperregion().getLocaleName() + "\n"; + } else { + return getMapActivity().getString(R.string.shared_string_map) + "\n"; + } + } + + @Override + public boolean needStreetName() { + return false; + } + + @Override + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + } + + @Override + public boolean fabVisible() { + return false; + } + + @Override + public boolean buttonsVisible() { + return false; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/EditCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/EditCategoryDialogFragment.java similarity index 96% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/EditCategoryDialogFragment.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/EditCategoryDialogFragment.java index 204df79cb7..b52679ff42 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/EditCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/EditCategoryDialogFragment.java @@ -1,4 +1,4 @@ -package net.osmand.plus.mapcontextmenu.editors.dialogs; +package net.osmand.plus.mapcontextmenu.editors; import android.app.AlertDialog; import android.app.Dialog; @@ -6,7 +6,6 @@ import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; -import android.support.v4.app.Fragment; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -19,8 +18,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.ColorDialogs; -import net.osmand.plus.mapcontextmenu.MapContextMenuFragment; -import net.osmand.plus.mapcontextmenu.editors.PointEditor; import net.osmand.util.Algorithms; import gnu.trove.list.array.TIntArrayList; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java index f756b9c0ad..86f1ae3bdf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java @@ -33,7 +33,6 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenuFragment; -import net.osmand.plus.mapcontextmenu.editors.dialogs.SelectCategoryDialogFragment; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.widgets.AutoCompleteTextViewEx; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/SelectCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java similarity index 96% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/SelectCategoryDialogFragment.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java index 87f4134ac0..70548697ad 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/dialogs/SelectCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java @@ -1,4 +1,4 @@ -package net.osmand.plus.mapcontextmenu.editors.dialogs; +package net.osmand.plus.mapcontextmenu.editors; import android.app.Activity; import android.app.AlertDialog; @@ -19,8 +19,6 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.mapcontextmenu.editors.PointEditor; -import net.osmand.plus.mapcontextmenu.editors.PointEditorFragment; import java.util.List; diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index 5a18878844..b18be10b31 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -9,7 +9,9 @@ import java.util.TreeSet; import net.osmand.IndexConstants; import net.osmand.binary.BinaryMapDataObject; +import net.osmand.data.Amenity; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.map.OsmandRegions; import net.osmand.map.WorldRegion; @@ -30,7 +32,7 @@ import android.text.TextPaint; import android.util.DisplayMetrics; import android.view.WindowManager; -public class DownloadedRegionsLayer extends OsmandMapLayer { +public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final int ZOOM_THRESHOLD = 2; @@ -278,10 +280,6 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { return filter.toString(); } - - - - @Override public boolean drawInScreenPixels() { return false; @@ -299,4 +297,73 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { } + // IContextMenuProvider + @Override + public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List objects) { + getWorldRegionFromPoint(tileBox, point, objects); + } + + @Override + public LatLon getObjectLocation(Object o) { + if (o instanceof WorldRegion) { + return ((WorldRegion) o).getRegionCenter(); + } + return null; + } + + @Override + public String getObjectDescription(Object o) { + return view.getContext().getString(R.string.shared_string_map); + } + + @Override + public PointDescription getObjectName(Object o) { + return new PointDescription(PointDescription.POINT_TYPE_WORLD_REGION, + view.getContext().getString(R.string.shared_string_map), ""); + } + + @Override + public boolean disableSingleTap() { + return false; + } + + @Override + public boolean disableLongPressOnMap() { + return false; + } + + private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List regions) { + int zoom = tb.getZoom(); + if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS && osmandRegions.isInitialized()) { + LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y); + int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude()); + int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude()); + + int left = MapUtils.get31TileNumberX(tb.getLeftTopLatLon().getLongitude()); + int right = MapUtils.get31TileNumberX(tb.getRightBottomLatLon().getLongitude()); + int top = MapUtils.get31TileNumberY(tb.getLeftTopLatLon().getLatitude()); + int bottom = MapUtils.get31TileNumberY(tb.getRightBottomLatLon().getLatitude()); + + List result; + try { + result = osmandRegions.queryBbox(left, right, top, bottom); + } catch (IOException e) { + return; + } + + Iterator it = result.iterator(); + while (it.hasNext()) { + BinaryMapDataObject o = it.next(); + if (!osmandRegions.isDownloadOfType(o, OsmandRegions.MAP_TYPE) || !osmandRegions.contain(o, point31x, point31y)) { + it.remove(); + } + } + + if (result.size() > 0) { + String fullName = osmandRegions.getFullName(result.get(0)); + WorldRegion region = osmandRegions.getRegionData(fullName); + regions.add(region); + } + } + } }