summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-01-18 14:50:52 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2018-01-18 14:50:52 +0100
commit2fd4615996b33c39e83ee5d5be29d8d8c68a8d9d (patch)
treea9894f60b0d2494896608bf93e49561d2f2b2b56
parent2c8add184a03ef4166ee085b9bd18d8ff417f778 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-style-concept.tar.gz
add native methodsupstream/tvn-style-concept
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java2
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java44
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/Style.java149
3 files changed, 93 insertions, 102 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
index b2f6cef3b0..dc45e71df7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
@@ -1,6 +1,6 @@
package com.mapbox.mapboxsdk.maps;
-class Image {
+public class Image {
private final byte[] buffer;
private final float pixelRatio;
private final String name;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index f1635c898f..03d398776a 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -1132,49 +1132,5 @@ final class NativeMapView {
// Image conversion
//
- private static class BitmapImageConversionTask extends AsyncTask<HashMap<String, Bitmap>, Void, List<Image>> {
- private NativeMapView nativeMapView;
-
- BitmapImageConversionTask(NativeMapView nativeMapView) {
- this.nativeMapView = nativeMapView;
- }
-
- @Override
- protected List<Image> doInBackground(HashMap<String, Bitmap>... params) {
- HashMap<String, Bitmap> bitmapHashMap = params[0];
-
- List<Image> images = new ArrayList<>();
- ByteBuffer buffer;
- String name;
- Bitmap bitmap;
-
- for (Map.Entry<String, Bitmap> stringBitmapEntry : bitmapHashMap.entrySet()) {
- name = stringBitmapEntry.getKey();
- bitmap = stringBitmapEntry.getValue();
-
- if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
- bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
- }
-
- buffer = ByteBuffer.allocate(bitmap.getByteCount());
- bitmap.copyPixelsToBuffer(buffer);
-
- float density = bitmap.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : bitmap.getDensity();
- float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT;
-
- images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight()));
- }
-
- return images;
- }
-
- @Override
- protected void onPostExecute(List<Image> images) {
- super.onPostExecute(images);
- if (nativeMapView != null && !nativeMapView.isDestroyedOn("nativeAddImages")) {
- nativeMapView.nativeAddImages(images.toArray(new Image[images.size()]));
- }
- }
- }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/Style.java
index 1bf5d25b4a..442850f0e4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/Style.java
@@ -1,111 +1,146 @@
package com.mapbox.mapboxsdk.style;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.util.DisplayMetrics;
import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.maps.Image;
+import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.style.light.Light;
+import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
import com.mapbox.mapboxsdk.style.sources.Source;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
public class Style {
- void loadJson(String json) {
+ private Style(){
}
- void loadURL(String url) {
-
+ public static Style fromJson(String json){
+ return new Style();
}
- String getJson() {
- return "";
+ public static Style fromUrl(String url) {
+ return new Style();
}
- String getURL() {
- return "";
+ public void addImage(String id, Bitmap image){
+ if (image.getConfig() != Bitmap.Config.ARGB_8888) {
+ image = image.copy(Bitmap.Config.ARGB_8888, false);
+ }
+ float pixelRatio = image.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
+ ByteBuffer buffer = ByteBuffer.allocate(image.getByteCount());
+ image.copyPixelsToBuffer(buffer);
+ nativeAddImage(id, image.getWidth(), image.getHeight(), pixelRatio, buffer.array());
}
- String getName() {
- return "";
+ public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) {
+ //noinspection unchecked
+ new BitmapImageConversionTask(this).execute(bitmapHashMap);
}
- CameraPosition getDefaultCamera() {
- return null;
- }
+ public native String getJson();
- TransitionOptions getTransitionOptions() {
- return null;
- }
+ public native String getURL();
- void setTransitionOptions(TransitionOptions options) {
- }
+ public native String getName();
- void setLight(Light light) {
- }
+ public native CameraPosition getDefaultCamera();
- Light getLight() {
- return null;
- }
+ public native TransitionOptions getTransitionOptions();
- Bitmap getImage(String image) {
- return null;
- }
+ public native void setTransitionOptions(TransitionOptions options);
- void addImage(String id, Bitmap bitmap) {
+ public native void setLight(Light light);
- }
+ public native void getLight();
- void removeImage(String id) {
+ public native Bitmap getImage(String image);
- }
+ private native void nativeAddImage(String name, int width, int height, float pixelRatio, byte[] array);
- //@NonNull
- List<Source> getSources() {
- return null;
- }
+ private native void nativeAddImages(Image[] images);
- @Nullable
- Source getSource(String id) {
- return null;
- }
+ public native void removeImage(String id);
- void addSource(Source source) {
+ private native Layer nativeGetLayer(String layerId);
- }
+ private native void nativeAddLayer(long layerPtr, String before) throws CannotAddLayerException;
- void removeSource(Source source) {
+ private native void nativeAddLayerAbove(long layerPtr, String above) throws CannotAddLayerException;
- }
+ private native void nativeAddLayerAt(long layerPtr, int index) throws CannotAddLayerException;
- List<Layer> getLayers() {
- return null;
- }
+ private native Layer nativeRemoveLayerById(String layerId);
- @Nullable
- Layer getLayer(String layerId) {
- return null;
- }
+ private native void nativeRemoveLayer(long layerId);
- public void addLayer(@NonNull Layer layer) {
- }
+ private native Layer nativeRemoveLayerAt(int index);
- public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
- }
+ private native Source[] nativeGetSources();
- public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
- }
+ private native Source nativeGetSource(String sourceId);
- public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
- }
+ private native void nativeAddSource(Source source, long sourcePtr) throws CannotAddSourceException;
+
+ private native void nativeRemoveSource(Source source, long sourcePtr);
+
+ private static class BitmapImageConversionTask extends AsyncTask<HashMap<String, Bitmap>, Void, List<Image>> {
+
+ private Style style;
+
+ BitmapImageConversionTask(Style style) {
+ this.style = style;
+ }
+
+ @Override
+ protected List<Image> doInBackground(HashMap<String, Bitmap>... params) {
+ HashMap<String, Bitmap> bitmapHashMap = params[0];
+
+ List<Image> images = new ArrayList<>();
+ ByteBuffer buffer;
+ String name;
+ Bitmap bitmap;
+
+ for (Map.Entry<String, Bitmap> stringBitmapEntry : bitmapHashMap.entrySet()) {
+ name = stringBitmapEntry.getKey();
+ bitmap = stringBitmapEntry.getValue();
+
+ if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
+ bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
+ }
+
+ buffer = ByteBuffer.allocate(bitmap.getByteCount());
+ bitmap.copyPixelsToBuffer(buffer);
+
+ float density = bitmap.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : bitmap.getDensity();
+ float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT;
+
+ images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight()));
+ }
- void removeLayer(String id) {
+ return images;
+ }
+ @Override
+ protected void onPostExecute(List<Image> images) {
+ super.onPostExecute(images);
+ if (style != null) {
+ style.nativeAddImages(images.toArray(new Image[images.size()]));
+ }
+ }
}
}