Search in sources :

Example 11 with IndexItem

use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.

the class FirstUsageWizardFragment method startDownload.

private boolean startDownload(int itemIndex) {
    boolean downloadStarted = false;
    if (itemIndex == 0 && indexItems.size() > 0) {
        IndexItem indexItem = indexItems.get(0);
        if (!downloadThread.isDownloading(indexItem) && !indexItem.isDownloaded() && !firstMapDownloadCancelled) {
            validationManager.startDownload(getActivity(), indexItem);
            downloadStarted = true;
        }
    } else if (itemIndex == 1 && indexItems.size() > 1) {
        IndexItem indexItem = indexItems.get(1);
        if (!downloadThread.isDownloading(indexItem) && !indexItem.isDownloaded() && !secondMapDownloadCancelled) {
            validationManager.startDownload(getActivity(), indexItem);
            downloadStarted = true;
        }
    }
    return downloadStarted;
}
Also used : IndexItem(net.osmand.plus.download.IndexItem)

Example 12 with IndexItem

use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.

the class FirstUsageWizardFragment method downloadInProgress.

@Override
public void downloadInProgress() {
    IndexItem indexItem = downloadThread.getCurrentDownloadingItem();
    if (indexItem != null && !indexItem.isDownloaded()) {
        int progress = downloadThread.getCurrentDownloadingItemProgress();
        double mb = indexItem.getArchiveSizeMB();
        String v;
        if (progress != -1) {
            v = getString(R.string.value_downloaded_of_max, mb * progress / 100, mb);
        } else {
            v = getString(R.string.file_size_in_mb, mb);
        }
        int index = indexItems.indexOf(indexItem);
        if (index == 0) {
            if (!firstMapDownloadCancelled) {
                final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map_downloading_desc);
                ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.map_download_progress_bar);
                mapDescriptionTextView.setText(v);
                progressBar.setProgress(progress < 0 ? 0 : progress);
            }
        } else if (index == 1) {
            if (!secondMapDownloadCancelled) {
                final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map2_downloading_desc);
                ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.map2_download_progress_bar);
                mapDescriptionTextView.setText(v);
                progressBar.setProgress(progress < 0 ? 0 : progress);
            }
        }
    }
    updateDownloadedItems();
}
Also used : TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) IndexItem(net.osmand.plus.download.IndexItem)

Example 13 with IndexItem

use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.

the class FirstUsageWizardFragment method updateDownloadedItems.

private void updateDownloadedItems() {
    int i = 0;
    final View firstRowLayout = view.findViewById(R.id.map_downloading_layout);
    final View secondRowLayout = view.findViewById(R.id.map2_downloading_layout);
    final View progressLayout = view.findViewById(R.id.map_download_progress_layout);
    final View progressLayout2 = view.findViewById(R.id.map2_download_progress_layout);
    final ImageButton redownloadButton = (ImageButton) view.findViewById(R.id.map_redownload_button);
    final ImageButton redownloadButton2 = (ImageButton) view.findViewById(R.id.map2_redownload_button);
    for (IndexItem indexItem : indexItems) {
        if (indexItem.isDownloaded()) {
            if (i == 0 && progressLayout.getVisibility() == View.VISIBLE) {
                final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map_downloading_desc);
                mapDescriptionTextView.setText(indexItem.getSizeDescription(getContext()));
                view.findViewById(R.id.map_download_padding).setVisibility(View.VISIBLE);
                progressLayout.setVisibility(View.GONE);
                firstRowLayout.setClickable(true);
                final LatLon mapCenter = getMapCenter(indexItem);
                final int mapZoom = getMapZoom(indexItem);
                firstRowLayout.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        showOnMap(mapCenter, mapZoom);
                    }
                });
            } else if (i == 1 && progressLayout2.getVisibility() == View.VISIBLE) {
                final TextView mapDescriptionTextView = (TextView) view.findViewById(R.id.map2_downloading_desc);
                mapDescriptionTextView.setText(indexItem.getSizeDescription(getContext()));
                view.findViewById(R.id.map2_download_padding).setVisibility(View.VISIBLE);
                progressLayout2.setVisibility(View.GONE);
                secondRowLayout.setClickable(true);
                final LatLon mapCenter = getMapCenter(indexItem);
                final int mapZoom = getMapZoom(indexItem);
                secondRowLayout.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        showOnMap(mapCenter, mapZoom);
                    }
                });
            }
        } else {
            if (downloadThread.isDownloading(indexItem)) {
                if (i == 0 && !firstMapDownloadCancelled) {
                    if (progressLayout.getVisibility() == View.GONE) {
                        progressLayout.setVisibility(View.VISIBLE);
                    }
                    if (redownloadButton.getVisibility() == View.VISIBLE) {
                        redownloadButton.setVisibility(View.GONE);
                    }
                }
                if (i == 1 && !secondMapDownloadCancelled) {
                    if (progressLayout2.getVisibility() == View.GONE) {
                        progressLayout2.setVisibility(View.VISIBLE);
                    }
                    if (redownloadButton2.getVisibility() == View.VISIBLE) {
                        redownloadButton2.setVisibility(View.GONE);
                    }
                }
            }
        }
        i++;
    }
}
Also used : LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) IndexItem(net.osmand.plus.download.IndexItem)

Example 14 with IndexItem

use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.

the class FirstUsageWizardFragment method searchMap.

private void searchMap() {
    if (location != null) {
        int point31x = MapUtils.get31TileNumberX(location.getLongitude());
        int point31y = MapUtils.get31TileNumberY(location.getLatitude());
        ResourceManager rm = getMyApplication().getResourceManager();
        OsmandRegions osmandRegions = rm.getOsmandRegions();
        List<BinaryMapDataObject> mapDataObjects = null;
        try {
            mapDataObjects = osmandRegions.queryBbox(point31x, point31x, point31y, point31y);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String selectedFullName = "";
        if (mapDataObjects != null) {
            Iterator<BinaryMapDataObject> it = mapDataObjects.iterator();
            while (it.hasNext()) {
                BinaryMapDataObject o = it.next();
                if (!osmandRegions.contain(o, point31x, point31y)) {
                    it.remove();
                }
            }
            for (BinaryMapDataObject o : mapDataObjects) {
                String fullName = osmandRegions.getFullName(o);
                if (fullName.length() > selectedFullName.length()) {
                    selectedFullName = fullName;
                }
            }
        }
        if (!Algorithms.isEmpty(selectedFullName)) {
            WorldRegion downloadRegion = osmandRegions.getRegionData(selectedFullName);
            if (downloadRegion != null && downloadRegion.isRegionMapDownload()) {
                localDownloadRegion = downloadRegion;
                List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
                for (IndexItem item : indexItems) {
                    if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                        localMapIndexItem = item;
                        break;
                    }
                }
            }
        }
        baseMapIndexItem = downloadThread.getIndexes().getWorldBaseMapItem();
        if (localMapIndexItem != null || baseMapIndexItem != null) {
            showMapFoundFragment(getActivity());
        } else {
            closeWizard();
        }
    } else {
        showNoLocationFragment(getActivity());
    }
}
Also used : OsmandRegions(net.osmand.map.OsmandRegions) WorldRegion(net.osmand.map.WorldRegion) BinaryMapDataObject(net.osmand.binary.BinaryMapDataObject) ResourceManager(net.osmand.plus.resources.ResourceManager) IOException(java.io.IOException) IndexItem(net.osmand.plus.download.IndexItem) LinkedList(java.util.LinkedList)

Example 15 with IndexItem

use of net.osmand.plus.download.IndexItem in project Osmand by osmandapp.

the class MenuController method updateData.

public void updateData() {
    if (downloadMapDataObject != null) {
        if (indexItem == null) {
            List<IndexItem> indexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
            for (IndexItem item : indexItems) {
                if (item.getType() == DownloadActivityType.NORMAL_FILE) {
                    indexItem = item;
                    break;
                }
            }
        }
        if (indexItem != null) {
            downloaded = indexItem.isDownloaded();
        }
        leftDownloadButtonController.visible = !downloaded;
        leftDownloadButtonController.leftIconId = R.drawable.ic_action_import;
        boolean internetConnectionAvailable = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable();
        boolean downloadIndexes = internetConnectionAvailable && !downloadThread.getIndexes().isDownloadedFromInternet && !downloadThread.getIndexes().downloadFromInternetFailed;
        boolean isDownloading = indexItem != null && downloadThread.isDownloading(indexItem);
        if (isDownloading) {
            titleProgressController.setMapDownloadMode();
            if (downloadThread.getCurrentDownloadingItem() == indexItem) {
                titleProgressController.indeterminate = false;
                titleProgressController.progress = downloadThread.getCurrentDownloadingItemProgress();
            } else {
                titleProgressController.indeterminate = true;
                titleProgressController.progress = 0;
            }
            double mb = indexItem.getArchiveSizeMB();
            String v;
            if (titleProgressController.progress != -1) {
                v = getMapActivity().getString(R.string.value_downloaded_of_max, mb * titleProgressController.progress / 100, mb);
            } else {
                v = getMapActivity().getString(R.string.file_size_in_mb, mb);
            }
            if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                titleProgressController.caption = indexItem.getType().getString(getMapActivity()) + " • " + v;
            } else {
                titleProgressController.caption = v;
            }
            titleProgressController.visible = true;
        } else if (downloadIndexes) {
            titleProgressController.setIndexesDownloadMode();
            titleProgressController.visible = true;
        } else if (!internetConnectionAvailable) {
            titleProgressController.setNoInternetConnectionMode();
            titleProgressController.visible = true;
        } else {
            titleProgressController.visible = false;
        }
    }
}
Also used : SpannableString(android.text.SpannableString) IndexItem(net.osmand.plus.download.IndexItem) LinkedList(java.util.LinkedList)

Aggregations

IndexItem (net.osmand.plus.download.IndexItem)27 View (android.view.View)9 TextView (android.widget.TextView)8 OnClickListener (android.view.View.OnClickListener)6 ContextMenuItem (net.osmand.plus.ContextMenuItem)5 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)4 LatLon (net.osmand.data.LatLon)4 OsmandRegions (net.osmand.map.OsmandRegions)4 WorldRegion (net.osmand.map.WorldRegion)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 OsmandSettings (net.osmand.plus.OsmandSettings)4 DownloadIndexesThread (net.osmand.plus.download.DownloadIndexesThread)4 Intent (android.content.Intent)3 ArrayAdapter (android.widget.ArrayAdapter)3 ExpandableListView (android.widget.ExpandableListView)3 ImageView (android.widget.ImageView)3 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)3 DownloadResources (net.osmand.plus.download.DownloadResources)3