Search in sources :

Example 1 with OfflineRegion

use of com.mapbox.mapboxsdk.offline.OfflineRegion in project mapbox-plugins-android by mapbox.

the class OfflineDownloadService method cancelDownload.

private void cancelDownload(final OfflineDownloadOptions offlineDownload) {
    int serviceId = offlineDownload.getServiceId();
    OfflineRegion offlineRegion = regionLongSparseArray.get(serviceId);
    offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE);
    offlineRegion.setObserver(null);
    offlineRegion.delete(new OfflineRegion.OfflineRegionDeleteCallback() {

        @Override
        public void onDelete() {
        }

        @Override
        public void onError(String error) {
            OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload, error);
        }
    });
    OfflineDownloadStateReceiver.dispatchCancelBroadcast(getApplicationContext(), offlineDownload);
    notificationManager.cancel(serviceId);
    stopSelf(serviceId);
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion)

Example 2 with OfflineRegion

use of com.mapbox.mapboxsdk.offline.OfflineRegion in project mapbox-plugins-android by mapbox.

the class OfflineRegionListActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    OfflineRegion region = adapter.getItem(position);
    Intent intent = new Intent(this, OfflineRegionDetailActivity.class);
    intent.putExtra(OfflineRegionDetailActivity.KEY_REGION_ID_BUNDLE, region.getID());
    startActivity(intent);
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) Intent(android.content.Intent)

Example 3 with OfflineRegion

use of com.mapbox.mapboxsdk.offline.OfflineRegion in project mapbox-plugins-android by mapbox.

the class OfflineDownloadService method createDownload.

private void createDownload(final OfflineDownloadOptions offlineDownload) {
    final OfflineTilePyramidRegionDefinition definition = offlineDownload.definition();
    final byte[] metadata = offlineDownload.metadata();
    OfflineManager.getInstance(getApplicationContext()).createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback() {

        @Override
        public void onCreate(OfflineRegion offlineRegion) {
            offlineDownload.setRegionId(offlineRegion.getID());
            OfflineDownloadStateReceiver.dispatchStartBroadcast(getApplicationContext(), offlineDownload);
            regionLongSparseArray.put(offlineDownload.getServiceId(), offlineRegion);
            launchDownload(offlineDownload, offlineRegion);
            showNotification(offlineDownload);
        }

        @Override
        public void onError(String error) {
            OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload, error);
        }
    });
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) OfflineManager(com.mapbox.mapboxsdk.offline.OfflineManager)

Example 4 with OfflineRegion

use of com.mapbox.mapboxsdk.offline.OfflineRegion in project osm-contributor by jawg.

the class OfflineRegionDownloadService method downloadOfflineRegion.

public void downloadOfflineRegion(LatLngBounds latLngBounds, final String regionName) {
    final OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(BuildConfig.MAP_STYLE_URL, latLngBounds, MIN_ZOOM, MAX_ZOOM, this.getResources().getDisplayMetrics().density);
    // Build the notification
    buildNotification(regionName);
    offlineRegionManager.createOfflineRegion(definition, regionName, new OfflineRegionManager.OnOfflineRegionCreatedListener() {

        @Override
        public void onOfflineRegionCreated(OfflineRegion offlineRegion, String regionName) {
            // Monitor the download progress using setObserver
            offlineRegion.setObserver(getOfflineRegionObserver(regionName));
            startDownloadOfflineRegion(offlineRegion);
            eventBus.post(new OfflineRegionCreatedEvent());
        }
    });
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) OfflineTilePyramidRegionDefinition(com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition) OfflineRegionCreatedEvent(io.jawg.osmcontributor.offline.events.OfflineRegionCreatedEvent) OfflineRegionManager(io.jawg.osmcontributor.offline.OfflineRegionManager)

Example 5 with OfflineRegion

use of com.mapbox.mapboxsdk.offline.OfflineRegion in project osm-contributor by jawg.

the class OfflineRegionDownloadService method startDownloadIfNeeded.

private void startDownloadIfNeeded(Intent intent, final List<OfflineRegion> presentOfflineRegions) {
    if (intent == null) {
        return;
    }
    final int size = intent.getIntExtra(SIZE_PARAM, -1);
    if (size != -1) {
        int c = 0;
        // There is some regions to download
        for (int i = 0; i < size; i++) {
            ArrayList<String> areasString = intent.getStringArrayListExtra(LIST_PARAM + i);
            LatLngBounds bounds = convertToLatLngBounds(areasString);
            OfflineRegion presentOfflineRegion = containsInOfflineRegion(presentOfflineRegions, bounds);
            if (presentOfflineRegion == null) {
                // The region has never been downloaded
                String regionName = intent.getStringExtra(REGION_NAME_PARAM);
                regionName = regionName == null ? "Region " + (presentOfflineRegions.size() + c) : regionName;
                c++;
                downloadOfflineRegion(bounds, regionName);
            } else {
                // The region is already downloaded, we check if it was completed
                checkIfRegionDownloadIsCompleted(presentOfflineRegion);
            }
        }
    }
}
Also used : OfflineRegion(com.mapbox.mapboxsdk.offline.OfflineRegion) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds)

Aggregations

OfflineRegion (com.mapbox.mapboxsdk.offline.OfflineRegion)5 OfflineTilePyramidRegionDefinition (com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition)2 Intent (android.content.Intent)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 OfflineManager (com.mapbox.mapboxsdk.offline.OfflineManager)1 OfflineRegionManager (io.jawg.osmcontributor.offline.OfflineRegionManager)1 OfflineRegionCreatedEvent (io.jawg.osmcontributor.offline.events.OfflineRegionCreatedEvent)1