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

Create device independent tests for camera position testing #12304

Merged
merged 1 commit into from
Jul 4, 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 @@ -310,15 +310,19 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
addView(glSurfaceView, 0);
}

nativeMapView = new NativeMapView(getContext(), this, mapRenderer);
nativeMapView.addOnMapChangedListener(new OnMapChangedListener() {
@Override
public void onMapChanged(int change) {
// dispatch events to external listeners
if (!onMapChangedListeners.isEmpty()) {
for (OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
onMapChangedListener.onMapChanged(change);
}
// check is user defined his own pixel ratio value
float pixelRatio = mapboxMapOptions.getPixelRatio();
if (pixelRatio == 0) {
// if not, get the one defined by the system
pixelRatio = getResources().getDisplayMetrics().density;
}

nativeMapView = new NativeMapView(getContext(), pixelRatio, this, mapRenderer);
nativeMapView.addOnMapChangedListener(change -> {
// dispatch events to external listeners
if (!onMapChangedListeners.isEmpty()) {
for (OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
onMapChangedListener.onMapChanged(change);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.support.v4.content.res.ResourcesCompat;
import android.util.AttributeSet;
import android.view.Gravity;

import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
Expand Down Expand Up @@ -76,6 +75,8 @@ public class MapboxMapOptions implements Parcelable {

private String style;

private float pixelRatio;

/**
* Creates a new MapboxMapOptions object.
*/
Expand Down Expand Up @@ -122,6 +123,7 @@ private MapboxMapOptions(Parcel in) {
prefetchesTiles = in.readByte() != 0;
zMediaOverlay = in.readByte() != 0;
localIdeographFontFamily = in.readString();
pixelRatio = in.readFloat();
}

/**
Expand Down Expand Up @@ -218,6 +220,8 @@ public static MapboxMapOptions createFromAttributes(@NonNull Context context, @N
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false));
mapboxMapOptions.localIdeographFontFamily(
typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
mapboxMapOptions.pixelRatio(
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_pixelRatio, 0));
} finally {
typedArray.recycle();
}
Expand Down Expand Up @@ -545,6 +549,18 @@ public MapboxMapOptions localIdeographFontFamily(String fontFamily) {
return this;
}

/**
* Set the custom pixel ratio configuration to override the default value from resources.
* This ratio will be used to initialise the map with.
*
* @param pixelRatio the custom pixel ratio of the map under construction
* @return This
*/
public MapboxMapOptions pixelRatio(float pixelRatio) {
this.pixelRatio = pixelRatio;
return this;
}

/**
* Check whether tile pre-fetching is enabled.
*
Expand Down Expand Up @@ -813,6 +829,15 @@ public String getLocalIdeographFontFamily() {
return localIdeographFontFamily;
}

/**
* Return the custom configured pixel ratio, returns 0 if not configured.
*
* @return the pixel ratio used by the map under construction
*/
public float getPixelRatio() {
return pixelRatio;
}

public static final Parcelable.Creator<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
Expand Down Expand Up @@ -866,6 +891,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
dest.writeString(localIdeographFontFamily);
dest.writeFloat(pixelRatio);
}

@Override
Expand Down Expand Up @@ -959,7 +985,10 @@ public boolean equals(Object o) {
if (zMediaOverlay != options.zMediaOverlay) {
return false;
}
if (localIdeographFontFamily != options.localIdeographFontFamily) {
if (!localIdeographFontFamily.equals(options.localIdeographFontFamily)) {
return false;
}
if (pixelRatio != options.pixelRatio) {
return false;
}

Expand Down Expand Up @@ -1001,6 +1030,7 @@ public int hashCode() {
result = 31 * result + (prefetchesTiles ? 1 : 0);
result = 31 * result + (zMediaOverlay ? 1 : 0);
result = 31 * result + (localIdeographFontFamily != null ? localIdeographFontFamily.hashCode() : 0);
result = 31 * result + (int) pixelRatio;
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<public name="mapbox_styleUrl" type="attr" />
<public name="mapbox_apiBaseUrl" type="attr" />
<public name="mapbox_localIdeographFontFamily" type="attr" />
<public name="mapbox_pixelRatio" type="float" />

<!--Camera-->
<public name="mapbox_cameraTargetLng" type="attr" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@

<attr name="mapbox_enableTilePrefetch" format="boolean"/>
<attr name="mapbox_enableZMediaOverlay" format="boolean"/>
<attr name="mapbox_pixelRatio" format="float"/>

</declare-styleable>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;

import org.junit.Ignore;
import org.junit.Test;

import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
Expand All @@ -20,11 +19,10 @@ public class CameraAnimateTest extends BaseActivityTest {

@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
return DeviceIndependentTestActivity.class;
}

@Test
@Ignore
public void testAnimateToCameraPositionTarget() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -45,7 +43,6 @@ public void testAnimateToCameraPositionTarget() {
}

@Test
@Ignore
public void testAnimateToCameraPositionTargetZoom() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -63,7 +60,6 @@ public void testAnimateToCameraPositionTargetZoom() {
}

@Test
@Ignore
public void testAnimateToCameraPosition() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand Down Expand Up @@ -93,7 +89,6 @@ public void testAnimateToCameraPosition() {
}

@Test
@Ignore
public void testAnimateToBounds() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -118,7 +113,6 @@ public void testAnimateToBounds() {
}

@Test
@Ignore
public void testAnimateToMoveBy() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -137,7 +131,6 @@ public void testAnimateToMoveBy() {
}

@Test
@Ignore
public void testAnimateToZoomIn() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -151,7 +144,6 @@ public void testAnimateToZoomIn() {
}

@Test
@Ignore
public void testAnimateToZoomOut() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -167,7 +159,6 @@ public void testAnimateToZoomOut() {
}

@Test
@Ignore
public void testAnimateToZoomBy() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -182,7 +173,6 @@ public void testAnimateToZoomBy() {
}

@Test
@Ignore
public void testAnimateToZoomTo() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.activity.espresso.DeviceIndependentTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;

import org.junit.Ignore;
import org.junit.Test;

import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
Expand All @@ -20,11 +19,10 @@ public class CameraEaseTest extends BaseActivityTest {

@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
return DeviceIndependentTestActivity.class;
}

@Test
@Ignore
public void testEaseToCameraPositionTarget() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -45,7 +43,6 @@ public void testEaseToCameraPositionTarget() {
}

@Test
@Ignore
public void testEaseToCameraPositionTargetZoom() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -63,7 +60,6 @@ public void testEaseToCameraPositionTargetZoom() {
}

@Test
@Ignore
public void testEaseToCameraPosition() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand Down Expand Up @@ -93,7 +89,6 @@ public void testEaseToCameraPosition() {
}

@Test
@Ignore
public void testEaseToBounds() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -118,7 +113,6 @@ public void testEaseToBounds() {
}

@Test
@Ignore
public void testEaseToMoveBy() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -137,7 +131,6 @@ public void testEaseToMoveBy() {
}

@Test
@Ignore
public void testEaseToZoomIn() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -151,7 +144,6 @@ public void testEaseToZoomIn() {
}

@Test
@Ignore
public void testEaseToZoomOut() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -167,7 +159,6 @@ public void testEaseToZoomOut() {
}

@Test
@Ignore
public void testEaseToZoomBy() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand All @@ -182,7 +173,6 @@ public void testEaseToZoomBy() {
}

@Test
@Ignore
public void testEaseToZoomTo() {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
Expand Down
Loading