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

Instrumented unit tests, add map tests, refactor gen layer tests #13443

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ final class NativeMapView {
private ViewCallback viewCallback;

// Used for map change callbacks
@Nullable
private StateCallback stateCallback;

// Device density
Expand Down Expand Up @@ -311,6 +312,10 @@ public double getPitch() {
return nativeGetPitch();
}

public void setPitch(double pitch) {
setPitch(pitch, 0);
}

public void setPitch(double pitch, long duration) {
if (checkState("setPitch")) {
return;
Expand Down Expand Up @@ -382,17 +387,31 @@ public void rotateBy(double sx, double sy, double ex, double ey,
nativeRotateBy(sx / pixelRatio, sy / pixelRatio, ex, ey, duration);
}

public void setContentPadding(int[] padding) {
public void setContentPadding(float[] padding) {
if (checkState("setContentPadding")) {
return;
}
// TopLeftBottomRight
nativeSetContentPadding(
padding[1] / pixelRatio,
padding[0] / pixelRatio,
padding[3] / pixelRatio,
padding[2] / pixelRatio);
}

public float[] getContentPadding() {
if (checkState("getContentPadding")) {
return new float[] {0, 0, 0, 0};
}
float[] topLeftBottomRight = nativeGetContentPadding();
return new float[]{
topLeftBottomRight[1] * pixelRatio,
topLeftBottomRight[0] * pixelRatio,
topLeftBottomRight[3] * pixelRatio,
topLeftBottomRight[2] * pixelRatio
};
}

public void setBearing(double degrees) {
if (checkState("setBearing")) {
return;
Expand Down Expand Up @@ -922,62 +941,86 @@ RectF getDensityDependantRectangle(final RectF rectangle) {

@Keep
private void onCameraWillChange(boolean animated) {
stateCallback.onCameraWillChange(animated);
if (stateCallback != null) {
stateCallback.onCameraWillChange(animated);
}
}

@Keep
private void onCameraIsChanging() {
stateCallback.onCameraIsChanging();
if (stateCallback != null) {
stateCallback.onCameraIsChanging();
}
}

@Keep
private void onCameraDidChange(boolean animated) {
stateCallback.onCameraDidChange(animated);
if (stateCallback != null) {
stateCallback.onCameraDidChange(animated);
}
}

@Keep
private void onWillStartLoadingMap() {
stateCallback.onWillStartLoadingMap();
if (stateCallback != null) {
stateCallback.onWillStartLoadingMap();
}
}

@Keep
private void onDidFinishLoadingMap() {
stateCallback.onDidFinishLoadingMap();
if (stateCallback != null) {
stateCallback.onDidFinishLoadingMap();
}
}

@Keep
private void onDidFailLoadingMap(String error) {
stateCallback.onDidFailLoadingMap(error);
if (stateCallback != null) {
stateCallback.onDidFailLoadingMap(error);
}
}

@Keep
private void onWillStartRenderingFrame() {
stateCallback.onWillStartRenderingFrame();
if (stateCallback != null) {
stateCallback.onWillStartRenderingFrame();
}
}

@Keep
private void onDidFinishRenderingFrame(boolean fully) {
stateCallback.onDidFinishRenderingFrame(fully);
if (stateCallback != null) {
stateCallback.onDidFinishRenderingFrame(fully);
}
}

@Keep
private void onWillStartRenderingMap() {
stateCallback.onWillStartRenderingMap();
if (stateCallback != null) {
stateCallback.onWillStartRenderingMap();
}
}

@Keep
private void onDidFinishRenderingMap(boolean fully) {
stateCallback.onDidFinishRenderingMap(fully);
if (stateCallback != null) {
stateCallback.onDidFinishRenderingMap(fully);
}
}

@Keep
private void onDidFinishLoadingStyle() {
stateCallback.onDidFinishLoadingStyle();
if (stateCallback != null) {
stateCallback.onDidFinishLoadingStyle();
}
}

@Keep
private void onSourceChanged(String sourceId) {
stateCallback.onSourceChanged(sourceId);
if (stateCallback != null) {
stateCallback.onSourceChanged(sourceId);
}
}

@Keep
Expand Down Expand Up @@ -1086,7 +1129,10 @@ private native CameraPosition nativeGetCameraForGeometry(
private native void nativeRotateBy(double sx, double sy, double ex, double ey, long duration);

@Keep
private native void nativeSetContentPadding(double top, double left, double bottom, double right);
private native void nativeSetContentPadding(float top, float left, float bottom, float right);

@Keep
private native float[] nativeGetContentPadding();

@Keep
private native void nativeSetBearing(double degrees, long duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.graphics.PointF;
import android.support.annotation.FloatRange;
import android.support.annotation.NonNull;

import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.constants.GeometryConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
Expand Down Expand Up @@ -32,7 +31,11 @@ public class Projection {

void setContentPadding(int[] contentPadding) {
this.contentPadding = contentPadding;
nativeMapView.setContentPadding(contentPadding);
float[] output = new float[contentPadding.length];
for (int i = 0; i < contentPadding.length; i++) {
output[i] = contentPadding[i];
}
nativeMapView.setContentPadding(output);
}

int[] getContentPadding() {
Expand Down Expand Up @@ -121,10 +124,10 @@ public VisibleRegion getVisibleRegion(boolean ignorePadding) {
top = 0;
bottom = nativeMapView.getHeight();
} else {
left = contentPadding[0];
right = nativeMapView.getWidth() - contentPadding[2];
top = contentPadding[1];
bottom = nativeMapView.getHeight() - contentPadding[3];
left = (float) contentPadding[0];
right = (float) (nativeMapView.getWidth() - contentPadding[2]);
top = (float) contentPadding[1];
bottom = (float) (nativeMapView.getHeight() - contentPadding[3]);
}

LatLng center = fromScreenLocation(new PointF(left + (right - left) / 2, top + (bottom - top) / 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mapbox.mapboxsdk.maps

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.style.layers.Layer
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
abstract class BaseLayerTest {
private lateinit var nativeMapView: NativeMapView

companion object {
const val WIDTH = 500
const val HEIGHT = WIDTH
}

fun before() {
val context = InstrumentationRegistry.getContext()
nativeMapView = NativeMapView(context, false, null, null, NativeMapViewTest.DummyRenderer(context))
nativeMapView.resizeView(WIDTH, HEIGHT)
}

fun setupLayer(layer: Layer) {
nativeMapView.addLayer(layer)
}
}
Loading