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