Search in sources :

Example 1 with BaseMapLayer

use of net.osmand.plus.views.BaseMapLayer in project Osmand by osmandapp.

the class MapActivityActions method createReloadTitleDialog.

private Dialog createReloadTitleDialog(final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity);
    builder.setMessage(R.string.context_menu_item_update_map_confirm);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    final OsmandMapTileView mapView = mapActivity.getMapView();
    builder.setPositiveButton(R.string.context_menu_item_update_map, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int zoom = args.getInt(KEY_ZOOM);
            BaseMapLayer mainLayer = mapView.getMainLayer();
            if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
            if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
                Toast.makeText(mapActivity, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
                return;
            }
            final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
            final QuadRect tilesRect = tb.getTileBounds();
            int left = (int) Math.floor(tilesRect.left);
            int top = (int) Math.floor(tilesRect.top);
            int width = (int) (Math.ceil(tilesRect.right) - left);
            int height = (int) (Math.ceil(tilesRect.bottom) - top);
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    ((OsmandApplication) mapActivity.getApplication()).getResourceManager().clearTileForMap(null, mapSource, i + left, j + top, zoom);
                }
            }
            mapView.refreshMap();
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) QuadRect(net.osmand.data.QuadRect) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView)

Example 2 with BaseMapLayer

use of net.osmand.plus.views.BaseMapLayer in project Osmand by osmandapp.

the class DownloadTilesDialog method openDialog.

public void openDialog() {
    BaseMapLayer mainLayer = mapView.getMainLayer();
    if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
    }
    final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
    if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
        Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
        return;
    }
    final RotatedTileBox rb = mapView.getCurrentRotatedTileBox();
    final int max = mapSource.getMaximumZoomSupported();
    // get narrow zoom
    final int zoom = rb.getZoom();
    // calculate pixel rectangle
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.download_tiles, null);
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MinZoom)).setText(zoom + "");
    // $NON-NLS-1$
    ((TextView) view.findViewById(R.id.MaxZoom)).setText(max + "");
    final SeekBar seekBar = (SeekBar) view.findViewById(R.id.ZoomToDownload);
    seekBar.setMax(max - zoom);
    seekBar.setProgress((max - zoom) / 2);
    final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
    final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
    updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, seekBar.getProgress());
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            run(zoom, seekBar.getProgress(), rb.getLatLonBounds(), mapSource);
        }
    });
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setView(view);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseMapLayer(net.osmand.plus.views.BaseMapLayer) RotatedTileBox(net.osmand.data.RotatedTileBox) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) MapTileLayer(net.osmand.plus.views.MapTileLayer) ITileSource(net.osmand.map.ITileSource) TextView(android.widget.TextView)

Aggregations

DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 RotatedTileBox (net.osmand.data.RotatedTileBox)2 ITileSource (net.osmand.map.ITileSource)2 BaseMapLayer (net.osmand.plus.views.BaseMapLayer)2 MapTileLayer (net.osmand.plus.views.MapTileLayer)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 QuadRect (net.osmand.data.QuadRect)1 ItemBuilder (net.osmand.plus.ContextMenuItem.ItemBuilder)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 GPXRouteParamsBuilder (net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder)1