diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-04 12:47:08 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-07-05 13:30:50 +0200 |
commit | 32dce870d756063167e000302afb553714f1f0cb (patch) | |
tree | 9624d19e424b6ddddcb0b5030f898c953ab9d317 /platform/android/MapboxGLAndroidSDK/src/main | |
parent | ec78936e18946e3cad75d23beb03b90fcf0cb915 (diff) | |
download | qtlocation-mapboxgl-32dce870d756063167e000302afb553714f1f0cb.tar.gz |
[android] - create device independent tests for camera position testing
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main')
6 files changed, 77 insertions, 39 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 3227cb0dab..f4b1bca251 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -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 // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index 1a8fc1eac7..64ad0d29b3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -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 diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index bb4e2f9212..02c50c9f18 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -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(); } @@ -546,6 +550,18 @@ public class MapboxMapOptions implements Parcelable { } /** + * 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. * * @return true if 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; } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index 100787fbf0..32fc0589d1 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -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) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 9ab8d34ef3..99432e7066 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -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" /> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 0f7e0563f7..75339e3194 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -106,6 +106,7 @@ <attr name="mapbox_enableTilePrefetch" format="boolean"/> <attr name="mapbox_enableZMediaOverlay" format="boolean"/> + <attr name="mapbox_pixelRatio" format="float"/> </declare-styleable> |