Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Cherrypick vanillashake #294

Merged
merged 5 commits into from Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -3,7 +3,7 @@
import androidx.annotation.Keep;

@Keep
class Image {
public class Image {
private final byte[] buffer;
private final float pixelRatio;
private final String name;
Expand Down
Expand Up @@ -5,12 +5,6 @@
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Bundle;
import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.annotation.UiThread;
import android.text.TextUtils;
import android.view.View;

Expand Down Expand Up @@ -44,6 +38,13 @@
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.FloatRange;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
import androidx.annotation.UiThread;

/**
* The general class to interact with in the Android Mapbox SDK. It exposes the entry point for all
* methods related to the MapView. You cannot instantiate {@link MapboxMap} object directly, rather,
Expand Down Expand Up @@ -93,6 +94,13 @@ public final class MapboxMap {
this.developerAnimationStartedListeners = developerAnimationStartedListeners;
}

/**
* Trigger the mapview to repaint.
*/
public void triggerRepaint() {
nativeMapView.triggerRepaint();
}

void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
transform.initialise(this, options);
uiSettings.initialise(context, options);
Expand Down
Expand Up @@ -237,6 +237,8 @@ List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,

float getPixelRatio();

void triggerRepaint();

//
// Deprecated Annotations API
//
Expand Down
Expand Up @@ -1003,6 +1003,11 @@ public float getPixelRatio() {
return pixelRatio;
}

@Override
public void triggerRepaint() {
nativeTriggerRepaint();
}

@NonNull
@Override
public RectF getDensityDependantRectangle(final RectF rectangle) {
Expand Down Expand Up @@ -1476,6 +1481,9 @@ public long getNativePtr() {
return nativePtr;
}

@Keep
private native void nativeTriggerRepaint();

//
// Snapshot
//
Expand Down
Expand Up @@ -340,7 +340,7 @@ public void addImage(@NonNull String name, @NonNull Drawable drawable) {
*/
public void addImage(@NonNull final String name, @NonNull Bitmap bitmap, boolean sdf) {
validateState("addImage");
nativeMap.addImages(new Image[]{toImage(new Builder.ImageWrapper(name, bitmap, sdf))});
nativeMap.addImages(new Image[] {toImage(new Builder.ImageWrapper(name, bitmap, sdf))});
}

/**
Expand Down Expand Up @@ -932,23 +932,23 @@ public Builder withBitmapImages(boolean sdf, @NonNull Pair<String, Bitmap>... va
return this;
}

String getUri() {
public String getUri() {
return styleUri;
}

String getJson() {
public String getJson() {
return styleJson;
}

List<Source> getSources() {
public List<Source> getSources() {
return sources;
}

List<LayerWrapper> getLayers() {
public List<LayerWrapper> getLayers() {
return layers;
}

List<ImageWrapper> getImages() {
public List<ImageWrapper> getImages() {
return images;
}

Expand All @@ -963,18 +963,30 @@ Style build(@NonNull NativeMap nativeMap) {
return new Style(this, nativeMap);
}

static class ImageWrapper {
public static class ImageWrapper {
Bitmap bitmap;
String id;
boolean sdf;

ImageWrapper(String id, Bitmap bitmap, boolean sdf) {
public ImageWrapper(String id, Bitmap bitmap, boolean sdf) {
this.id = id;
this.bitmap = bitmap;
this.sdf = sdf;
}

static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
public Bitmap getBitmap() {
return bitmap;
}

public String getId() {
return id;
}

public boolean isSdf() {
return sdf;
}

public static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
ImageWrapper[] images = new ImageWrapper[bitmapHashMap.size()];
List<String> keyList = new ArrayList<>(bitmapHashMap.keySet());
for (int i = 0; i < bitmapHashMap.size(); i++) {
Expand All @@ -985,43 +997,59 @@ static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap,
}
}

class LayerWrapper {
public class LayerWrapper {
Layer layer;

LayerWrapper(Layer layer) {
this.layer = layer;
}

public Layer getLayer() {
return layer;
}
}

class LayerAboveWrapper extends LayerWrapper {
public class LayerAboveWrapper extends LayerWrapper {
String aboveLayer;

LayerAboveWrapper(Layer layer, String aboveLayer) {
super(layer);
this.aboveLayer = aboveLayer;
}

public String getAboveLayer() {
return aboveLayer;
}
}

class LayerBelowWrapper extends LayerWrapper {
public class LayerBelowWrapper extends LayerWrapper {
String belowLayer;

LayerBelowWrapper(Layer layer, String belowLayer) {
super(layer);
this.belowLayer = belowLayer;
}

public String getBelowLayer() {
return belowLayer;
}
}

class LayerAtWrapper extends LayerWrapper {
public class LayerAtWrapper extends LayerWrapper {
int index;

LayerAtWrapper(Layer layer, int index) {
super(layer);
this.index = index;
}

public int getIndex() {
return index;
}
}
}

private static Image toImage(Builder.ImageWrapper imageWrapper) {
public static Image toImage(Builder.ImageWrapper imageWrapper) {
Bitmap bitmap = imageWrapper.bitmap;
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
Expand Down