Context menu: download map in progress

This commit is contained in:
Alexey Kulish 2015-11-02 13:10:24 +03:00
parent 3e69b1b5f7
commit a34eb35a42
11 changed files with 200 additions and 46 deletions

View file

@ -129,6 +129,7 @@
</LinearLayout>
<View
android:id="@+id/buttons_top_border"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>

View file

@ -39,6 +39,7 @@ 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, "");

View file

@ -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) {

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<Object> 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<? super WorldRegion> 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<BinaryMapDataObject> result;
try {
result = osmandRegions.queryBbox(left, right, top, bottom);
} catch (IOException e) {
return;
}
Iterator<BinaryMapDataObject> 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);
}
}
}
}