Search in sources :

Example 11 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class DownloadResources method findIndexItemsAt.

public static List<IndexItem> findIndexItemsAt(OsmandApplication app, LatLon latLon, DownloadActivityType type) throws IOException {
    List<IndexItem> res = new ArrayList<>();
    OsmandRegions regions = app.getRegions();
    DownloadIndexesThread downloadThread = app.getDownloadThread();
    int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
    int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
    List<BinaryMapDataObject> mapDataObjects;
    try {
        mapDataObjects = regions.queryBbox(point31x, point31x, point31y, point31y);
    } catch (IOException e) {
        throw new IOException("Error while calling queryBbox");
    }
    if (mapDataObjects != null) {
        Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
        while (it.hasNext()) {
            BinaryMapDataObject o = it.next();
            if (o.getTypes() != null) {
                boolean isRegion = true;
                for (int i = 0; i < o.getTypes().length; i++) {
                    BinaryMapIndexReader.TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                    if ("boundary".equals(tp.value)) {
                        isRegion = false;
                        break;
                    }
                }
                WorldRegion downloadRegion = regions.getRegionData(regions.getFullName(o));
                if (downloadRegion != null && isRegion && regions.contain(o, point31x, point31y)) {
                    if (!isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
                        addIndexItem(downloadThread, type, downloadRegion, res);
                    }
                }
            }
        }
    }
    return res;
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) IOException(java.io.IOException) AssetIndexItem(net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject)

Example 12 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class DownloadResourceGroup method addGroup.

public void addGroup(DownloadResourceGroup g) {
    if (type.isScreen()) {
        if (!g.type.isHeader()) {
            throw new UnsupportedOperationException("Trying to add " + g.getUniqueId() + " to " + getUniqueId());
        }
    }
    if (type.isHeader()) {
        if (!g.type.isScreen()) {
            throw new UnsupportedOperationException("Trying to add " + g.getUniqueId() + " to " + getUniqueId());
        }
    }
    groups.add(g);
    if (g.individualResources != null) {
        final net.osmand.Collator collator = OsmAndCollator.primaryCollator();
        final OsmandApplication app = getRoot().app;
        final OsmandRegions osmandRegions = app.getRegions();
        Collections.sort(g.individualResources, new Comparator<IndexItem>() {

            @Override
            public int compare(IndexItem lhs, IndexItem rhs) {
                int lli = lhs.getType().getOrderIndex();
                int rri = rhs.getType().getOrderIndex();
                if (lli < rri) {
                    return -1;
                } else if (lli > rri) {
                    return 1;
                }
                return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions), rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
            }
        });
    }
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) OsmandApplication(net.osmand.plus.OsmandApplication)

Example 13 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class DownloadedRegionsLayer method getWorldRegionFromPoint.

private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super DownloadMapObject> dataObjects) {
    int zoom = tb.getZoom();
    if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION && data.results != null && osmandRegions.isInitialized()) {
        LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
        int point31x = MapUtils.get31TileNumberX(pointLatLon.getLongitude());
        int point31y = MapUtils.get31TileNumberY(pointLatLon.getLatitude());
        List<BinaryMapDataObject> result = new LinkedList<>(data.results);
        Iterator<BinaryMapDataObject> it = result.iterator();
        while (it.hasNext()) {
            BinaryMapDataObject o = it.next();
            boolean isRegion = true;
            for (int i = 0; i < o.getTypes().length; i++) {
                TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                if ("boundary".equals(tp.value)) {
                    isRegion = false;
                    break;
                }
            }
            if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                it.remove();
            }
        }
        OsmandRegions osmandRegions = app.getRegions();
        for (BinaryMapDataObject o : result) {
            String fullName = osmandRegions.getFullName(o);
            WorldRegion region = osmandRegions.getRegionData(fullName);
            if (region != null && region.isRegionMapDownload()) {
                List<IndexItem> indexItems = app.getDownloadThread().getIndexes().getIndexItems(region);
                List<IndexItem> dataItems = new LinkedList<>();
                IndexItem regularMapItem = null;
                for (IndexItem item : indexItems) {
                    if (item.isDownloaded() || app.getDownloadThread().isDownloading(item)) {
                        dataItems.add(item);
                        if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                            regularMapItem = item;
                        }
                    }
                }
                if (dataItems.isEmpty() && regularMapItem != null) {
                    dataItems.add(regularMapItem);
                }
                if (!dataItems.isEmpty()) {
                    for (IndexItem item : dataItems) {
                        dataObjects.add(new DownloadMapObject(o, region, item, null));
                    }
                } else {
                    String downloadName = osmandRegions.getDownloadName(o);
                    List<LocalIndexInfo> infos = helper.getLocalIndexInfos(downloadName);
                    if (infos.size() == 0) {
                        dataObjects.add(new DownloadMapObject(o, region, null, null));
                    } else {
                        for (LocalIndexInfo info : infos) {
                            dataObjects.add(new DownloadMapObject(o, region, null, info));
                        }
                    }
                }
            }
        }
    }
}
Also used : WorldRegion(net.osmand.map.WorldRegion) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) LinkedList(java.util.LinkedList) IndexItem(net.osmand.plus.download.IndexItem) LatLon(net.osmand.data.LatLon) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo)

Example 14 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class MenuController method buildMapDownloadButtonAndSizeInfo.

public void buildMapDownloadButtonAndSizeInfo(final LatLon latLon) {
    new AsyncTask<Void, Void, BinaryMapDataObject>() {

        ResourceManager rm;

        OsmandRegions osmandRegions;

        String selectedFullName = "";

        @Override
        protected void onPreExecute() {
            rm = getMapActivity().getMyApplication().getResourceManager();
            osmandRegions = rm.getOsmandRegions();
        }

        @Override
        protected BinaryMapDataObject doInBackground(Void... voids) {
            int point31x = MapUtils.get31TileNumberX(latLon.getLongitude());
            int point31y = MapUtils.get31TileNumberY(latLon.getLatitude());
            List<BinaryMapDataObject> mapDataObjects = null;
            try {
                mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
            } catch (IOException e) {
                e.printStackTrace();
            }
            BinaryMapDataObject binaryMapDataObject = null;
            if (mapDataObjects != null) {
                Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
                while (it.hasNext()) {
                    BinaryMapDataObject o = it.next();
                    if (o.getTypes() != null) {
                        boolean isRegion = true;
                        for (int i = 0; i < o.getTypes().length; i++) {
                            TagValuePair tp = o.getMapIndex().decodeType(o.getTypes()[i]);
                            if ("boundary".equals(tp.value)) {
                                isRegion = false;
                                break;
                            }
                        }
                        if (!isRegion || !osmandRegions.contain(o, point31x, point31y)) {
                            it.remove();
                        }
                    }
                }
                double smallestArea = -1;
                for (BinaryMapDataObject o : mapDataObjects) {
                    String downloadName = osmandRegions.getDownloadName(o);
                    if (!Algorithms.isEmpty(downloadName)) {
                        boolean downloaded = checkIfObjectDownloaded(rm, downloadName);
                        if (downloaded) {
                            binaryMapDataObject = null;
                            break;
                        } else {
                            String fullName = osmandRegions.getFullName(o);
                            WorldRegion region = osmandRegions.getRegionData(fullName);
                            if (region != null && region.isRegionMapDownload()) {
                                double area = OsmandRegions.getArea(o);
                                if (smallestArea == -1) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                } else if (area < smallestArea) {
                                    smallestArea = area;
                                    selectedFullName = fullName;
                                    binaryMapDataObject = o;
                                }
                            }
                        }
                    }
                }
            }
            return binaryMapDataObject;
        }

        @Override
        protected void onPostExecute(BinaryMapDataObject binaryMapDataObject) {
            downloadMapDataObject = binaryMapDataObject;
            downloaded = downloadMapDataObject == null;
            if (!downloaded) {
                downloadThread = getMapActivity().getMyApplication().getDownloadThread();
                downloadRegion = osmandRegions.getRegionData(selectedFullName);
                if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                    List<IndexItem> indexItems = downloadThread.getIndexes().getIndexItems(downloadRegion);
                    for (IndexItem item : indexItems) {
                        if (item.getType() == DownloadActivityType.NORMAL_FILE && (item.isDownloaded() || downloadThread.isDownloading(item))) {
                            indexItem = item;
                        }
                    }
                }
                leftDownloadButtonController = new TitleButtonController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            if (indexItem.getType() == DownloadActivityType.NORMAL_FILE) {
                                new DownloadValidationManager(getMapActivity().getMyApplication()).startDownload(getMapActivity(), indexItem);
                            }
                        }
                    }
                };
                leftDownloadButtonController.caption = downloadRegion != null ? downloadRegion.getLocaleName() : getMapActivity().getString(R.string.shared_string_download);
                leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
                titleProgressController = new TitleProgressController() {

                    @Override
                    public void buttonPressed() {
                        if (indexItem != null) {
                            downloadThread.cancelDownload(indexItem);
                        }
                    }
                };
                if (!downloadThread.getIndexes().isDownloadedFromInternet) {
                    if (getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable()) {
                        downloadThread.runReloadIndexFiles();
                    }
                }
                if (mapContextMenu != null) {
                    mapContextMenu.updateMenuUI();
                }
            }
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : WorldRegion(net.osmand.map.WorldRegion) ResourceManager(net.osmand.plus.resources.ResourceManager) SpannableString(android.text.SpannableString) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) OsmandRegions(net.osmand.map.OsmandRegions) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TagValuePair(net.osmand.binary.BinaryMapIndexReader.TagValuePair) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager)

Example 15 with OsmandRegions

use of net.osmand.map.OsmandRegions in project Osmand by osmandapp.

the class UpdatesIndexFragment method invalidateListView.

public void invalidateListView(Activity a) {
    DownloadResources indexes = getMyApplication().getDownloadThread().getIndexes();
    List<IndexItem> indexItems = indexes.getItemsToUpdate();
    final OsmandRegions osmandRegions = getMyApplication().getResourceManager().getOsmandRegions();
    OsmandSettings settings = getMyApplication().getSettings();
    listAdapter = new UpdateIndexAdapter(a, R.layout.download_index_list_item, indexItems, !settings.LIVE_UPDATES_PURCHASED.get() || settings.SHOULD_SHOW_FREE_VERSION_BANNER.get());
    listAdapter.sort(new Comparator<IndexItem>() {

        @Override
        public int compare(IndexItem indexItem, IndexItem indexItem2) {
            return indexItem.getVisibleName(getMyApplication(), osmandRegions).compareTo(indexItem2.getVisibleName(getMyApplication(), osmandRegions));
        }
    });
    setListAdapter(listAdapter);
    updateErrorMessage();
}
Also used : DownloadResources(net.osmand.plus.download.DownloadResources) OsmandRegions(net.osmand.map.OsmandRegions) IndexItem(net.osmand.plus.download.IndexItem) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

OsmandRegions (net.osmand.map.OsmandRegions)20 File (java.io.File)10 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)8 WorldRegion (net.osmand.map.WorldRegion)8 LinkedList (java.util.LinkedList)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)5 IndexItem (net.osmand.plus.download.IndexItem)4 FileOutputStream (java.io.FileOutputStream)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)2 AssetIndexItem (net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem)2