diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-02-17 18:04:07 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-02-20 14:36:27 +0100 |
commit | 9ad29af400c6172dc13ce1b18a73a47e8fb66e28 (patch) | |
tree | feba976d46b2bdfa6fe38d275b36ae4a3eadeac4 /platform/android/MapboxGLAndroidSDK/src/main/java | |
parent | c86e38e303cf12dc1bb10d70437b5a3957bea43e (diff) | |
download | qtlocation-mapboxgl-9ad29af400c6172dc13ce1b18a73a47e8fb66e28.tar.gz |
[android] OfflineManager#setResourceTransform to allow transforming URLs prior to internet requests
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java')
2 files changed, 86 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java index d2371fcc2f..09acda792c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java @@ -10,6 +10,7 @@ import android.support.annotation.NonNull; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.storage.Resource; import java.io.File; @@ -81,6 +82,22 @@ public class OfflineManager { void onError(String error); } + /** + * This callback allows implementors to transform URLs before they are requested + * from the internet. This can be used add or remove custom parameters, or reroute + * certain requests to other servers or endpoints. + */ + public interface ResourceTransformCallback { + /** + * Called whenever a URL needs to be transformed. + * + * @param kind The kind of URL to be transformed. + * @param offlineRegions The original URL to be transformed. + * @return A URL that will now be downloaded. + */ + String onURL(@Resource.Kind int kind, String url); + } + /* * Constructors */ @@ -265,6 +282,18 @@ public class OfflineManager { }); } + /** + * Sets a callback for transforming URLs requested from the internet + * <p> + * The callback will be executed on the main thread once for every requested URL. + * </p> + * + * @param callback the callback to be invoked + */ + public void setResourceTransform(@NonNull final ResourceTransformCallback callback) { + setResourceTransform(mDefaultFileSourcePtr, callback); + } + /* * Changing or bypassing this limit without permission from Mapbox is prohibited * by the Mapbox Terms of Service. @@ -291,6 +320,9 @@ public class OfflineManager { long defaultFileSourcePtr, OfflineRegionDefinition definition, byte[] metadata, CreateOfflineRegionCallback callback); + private native void setResourceTransform( + long defaultFileSourcePtr, ResourceTransformCallback callback); + private native void setOfflineMapboxTileCountLimit( long defaultFileSourcePtr, long limit); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java new file mode 100644 index 0000000000..af98a46a9b --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java @@ -0,0 +1,54 @@ +package com.mapbox.mapboxsdk.storage; + +import android.support.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public final class Resource { + // Note: Keep this in sync with include/mbgl/storage/resource.hpp + + @IntDef( {UNKNOWN, STYLE, SOURCE, TILE, GLYPHS, SPRITE_IMAGE, SPRITE_JSON}) + @Retention(RetentionPolicy.SOURCE) + public @interface Kind { + } + + /** + * Unknown type + */ + public static final int UNKNOWN = 0; + + /** + * Style sheet JSON file + */ + public static final int STYLE = 1; + + /** + * TileJSON file as specified in https://www.mapbox.com/mapbox-gl-js/style-spec/#root-sources + */ + public static final int SOURCE = 2; + + /** + * A vector or raster tile as described in the style sheet at + * https://www.mapbox.com/mapbox-gl-js/style-spec/#sources + */ + public static final int TILE = 3; + + /** + * Signed distance field glyphs for text rendering. These are the URLs specified in the style + * in https://www.mapbox.com/mapbox-gl-js/style-spec/#root-glyphs + */ + public static final int GLYPHS = 4; + + /** + * Image part of a sprite sheet. It is constructed of the prefix in + * https://www.mapbox.com/mapbox-gl-js/style-spec/#root-sprite and a PNG file extension. + */ + public static final int SPRITE_IMAGE = 5; + + /** + * JSON part of a sprite sheet. It is constructed of the prefix in + * https://www.mapbox.com/mapbox-gl-js/style-spec/#root-sprite and a JSON file extension. + */ + public static final int SPRITE_JSON = 6; +} |