[android] - create device independent tests for camera position testing
This commit is contained in:
@@ -146,8 +146,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
nativeMapView.addOnMapChangedListener(mapCallback);
|
||||
|
||||
// callback for focal point invalidation
|
||||
final FocalPointInvalidator focalPointInvalidator = new FocalPointInvalidator();
|
||||
focalPointInvalidator.addListener(createFocalPointChangeListener());
|
||||
final FocalPointInvalidator focalInvalidator = new FocalPointInvalidator();
|
||||
focalInvalidator.addListener(createFocalPointChangeListener());
|
||||
|
||||
// callback for registering touch listeners
|
||||
GesturesManagerInteractionListener registerTouchListener = new GesturesManagerInteractionListener();
|
||||
@@ -157,7 +157,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalPointInvalidator, compassView, attrView, logoView);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalInvalidator, compassView, attrView, logoView, getPixelRatio());
|
||||
LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>();
|
||||
MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer));
|
||||
IconManager iconManager = new IconManager(nativeMapView);
|
||||
@@ -310,15 +310,12 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
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);
|
||||
}
|
||||
nativeMapView = new NativeMapView(getContext(), getPixelRatio(), this, mapRenderer);
|
||||
nativeMapView.addOnMapChangedListener(change -> {
|
||||
// dispatch events to external listeners
|
||||
if (!onMapChangedListeners.isEmpty()) {
|
||||
for (OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
|
||||
onMapChangedListener.onMapChanged(change);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -583,6 +580,16 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private float getPixelRatio() {
|
||||
// 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;
|
||||
}
|
||||
return pixelRatio;
|
||||
}
|
||||
|
||||
//
|
||||
// View events
|
||||
//
|
||||
|
||||
@@ -1568,7 +1568,7 @@ public final class MapboxMap {
|
||||
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided bounds and the current camera tilt.
|
||||
* Get a camera position that fits a provided bounds and the current camera tilt and bearing.
|
||||
*
|
||||
* @param latLngBounds the bounds to set the map with
|
||||
* @return the camera position that fits the bounds
|
||||
@@ -1581,7 +1581,7 @@ public final class MapboxMap {
|
||||
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided bounds and padding and the current camera tilt.
|
||||
* Get a camera position that fits a provided bounds and padding and the current camera tilt and bearing.
|
||||
*
|
||||
* @param latLngBounds the bounds to set the map with
|
||||
* @param padding the padding to apply to the bounds
|
||||
@@ -1596,12 +1596,12 @@ public final class MapboxMap {
|
||||
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided bounds, padding and tilt.
|
||||
* Get a camera position that fits a provided bounds, bearing and tilt.
|
||||
*
|
||||
* @param latLngBounds the bounds to set the map with
|
||||
* @param bearing the bearing to transform the camera position with
|
||||
* @param tilt to transform the camera position with
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that fits the bounds and given bearing and tilt
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds,
|
||||
@@ -1614,13 +1614,13 @@ public final class MapboxMap {
|
||||
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided bounds, padding and tilt.
|
||||
* Get a camera position that fits a provided bounds, padding, bearing and tilt.
|
||||
*
|
||||
* @param latLngBounds the bounds to set the map with
|
||||
* @param padding the padding to apply to the bounds
|
||||
* @param bearing the bearing to transform the camera position with
|
||||
* @param tilt to transform the camera position with
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that fits the bounds, bearing and tilt
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds latLngBounds,
|
||||
@@ -1633,10 +1633,10 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
* Get a camera position that fits a provided shape.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @param geometry the geometry to wraps the map with
|
||||
* @return the camera position that fits the geometry inside
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry) {
|
||||
@@ -1645,11 +1645,11 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
* Get a camera position that fits a provided shape and padding.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @param geometry the geometry to wraps the map with
|
||||
* @param padding the padding to apply to the bounds
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that fits the geometry inside and padding
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
|
||||
@@ -1659,12 +1659,12 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
* Get a camera position that fits a provided shape with a given bearing and tilt.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @param geometry the geometry to wraps the map with
|
||||
* @param bearing the bearing at which to compute the geometry's bounds
|
||||
* @param tilt the tilt at which to compute the geometry's bounds
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that the geometry inside with bearing and tilt
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
|
||||
@@ -1676,13 +1676,13 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
* Get a camera position that fits a provided shape with a given padding, bearing and tilt.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @param geometry the geometry to wraps the map with
|
||||
* @param padding the padding to apply to the bounds
|
||||
* @param bearing the bearing at which to compute the geometry's bounds
|
||||
* @param tilt the tilt at which to compute the geometry's bounds
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that fits the geometry inside with padding, bearing and tilt
|
||||
*/
|
||||
@NonNull
|
||||
public CameraPosition getCameraForGeometry(@NonNull Geometry geometry,
|
||||
@@ -1697,10 +1697,10 @@ public final class MapboxMap {
|
||||
/**
|
||||
* Get a camera position that fits a provided shape with a given bearing and padding.
|
||||
*
|
||||
* @param geometry the geometry to constrain the map with
|
||||
* @param geometry the geometry to wraps the map with
|
||||
* @param bearing the bearing at which to compute the geometry's bounds
|
||||
* @param padding the padding to apply to the bounds
|
||||
* @return the camera position that fits the bounds and padding
|
||||
* @return the camera position that fits the geometry inside with padding and bearing
|
||||
* @deprecated use Mapbox{@link #getCameraForGeometry(Geometry, int[], double, double)} instead
|
||||
*/
|
||||
@NonNull
|
||||
|
||||
@@ -13,7 +13,6 @@ import android.support.annotation.Nullable;
|
||||
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;
|
||||
@@ -76,6 +75,8 @@ public class MapboxMapOptions implements Parcelable {
|
||||
|
||||
private String style;
|
||||
|
||||
private float pixelRatio;
|
||||
|
||||
/**
|
||||
* Creates a new MapboxMapOptions object.
|
||||
*/
|
||||
@@ -122,6 +123,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
prefetchesTiles = in.readByte() != 0;
|
||||
zMediaOverlay = in.readByte() != 0;
|
||||
localIdeographFontFamily = in.readString();
|
||||
pixelRatio = in.readFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,6 +220,8 @@ public class MapboxMapOptions implements Parcelable {
|
||||
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();
|
||||
}
|
||||
@@ -545,6 +549,18 @@ public class MapboxMapOptions implements Parcelable {
|
||||
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.
|
||||
*
|
||||
@@ -813,6 +829,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
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);
|
||||
@@ -866,6 +891,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
|
||||
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
|
||||
dest.writeString(localIdeographFontFamily);
|
||||
dest.writeFloat(pixelRatio);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -959,7 +985,10 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (zMediaOverlay != options.zMediaOverlay) {
|
||||
return false;
|
||||
}
|
||||
if (localIdeographFontFamily != options.localIdeographFontFamily) {
|
||||
if (!localIdeographFontFamily.equals(options.localIdeographFontFamily)) {
|
||||
return false;
|
||||
}
|
||||
if (pixelRatio != options.pixelRatio) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1001,6 +1030,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class UiSettings {
|
||||
private final View logoView;
|
||||
private final int[] logoMargins = new int[4];
|
||||
|
||||
private float pixelRatio;
|
||||
private final float pixelRatio;
|
||||
|
||||
private boolean rotateGesturesEnabled = true;
|
||||
|
||||
@@ -68,15 +68,14 @@ public final class UiSettings {
|
||||
private PointF userProvidedFocalPoint;
|
||||
|
||||
UiSettings(@NonNull Projection projection, @NonNull FocalPointChangeListener listener,
|
||||
@NonNull CompassView compassView, @NonNull ImageView attributionsView, @NonNull View logoView) {
|
||||
@NonNull CompassView compassView, @NonNull ImageView attributionsView, @NonNull View logoView,
|
||||
float pixelRatio) {
|
||||
this.projection = projection;
|
||||
this.focalPointChangeListener = listener;
|
||||
this.compassView = compassView;
|
||||
this.attributionsView = attributionsView;
|
||||
this.logoView = logoView;
|
||||
if (logoView.getResources() != null) {
|
||||
this.pixelRatio = logoView.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
this.pixelRatio = pixelRatio;
|
||||
}
|
||||
|
||||
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
|
||||
|
||||
Reference in New Issue
Block a user