From ad46d67aeb84b258668126dddc00c581f4808f3e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 11 May 2017 21:00:41 +0200 Subject: [android] - keep observer when timeout occurs, make observer param nullable, fixup log messages (#8919) --- .../com/mapbox/mapboxsdk/offline/OfflineRegion.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java index a55e8dd848..2110e12b36 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java @@ -4,6 +4,7 @@ import android.os.Handler; import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.storage.FileSource; @@ -205,7 +206,7 @@ public class OfflineRegion { /** * Constructor - * + *

* For JNI use only, to create a new offline region, use * {@link OfflineManager#createOfflineRegion} instead. */ @@ -247,7 +248,7 @@ public class OfflineRegion { * * @param observer the observer to be notified */ - public void setObserver(@NonNull final OfflineRegionObserver observer) { + public void setObserver(@Nullable final OfflineRegionObserver observer) { setOfflineRegionObserver(new OfflineRegionObserver() { @Override public void onStatusChanged(final OfflineRegionStatus status) { @@ -255,7 +256,9 @@ public class OfflineRegion { getHandler().post(new Runnable() { @Override public void run() { - observer.onStatusChanged(status); + if (observer != null) { + observer.onStatusChanged(status); + } } }); } @@ -267,7 +270,9 @@ public class OfflineRegion { getHandler().post(new Runnable() { @Override public void run() { - observer.onError(error); + if (observer != null) { + observer.onError(error); + } } }); } @@ -279,7 +284,9 @@ public class OfflineRegion { getHandler().post(new Runnable() { @Override public void run() { - observer.mapboxTileCountLimitExceeded(limit); + if (observer != null) { + observer.mapboxTileCountLimitExceeded(limit); + } } }); } -- cgit v1.2.1 From 850b008a2fd872c6158502b821da17864711bb12 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Thu, 11 May 2017 21:39:17 +0200 Subject: [android] - avoid crashing when deleting already deleted region (#8920) --- .../mapbox/mapboxsdk/offline/OfflineRegion.java | 48 ++++++++++++---------- 1 file changed, 27 insertions(+), 21 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java index 2110e12b36..44bb2a05ee 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java @@ -37,6 +37,9 @@ public class OfflineRegion { //Region id private long id; + // delete status + private boolean isDeleted; + private OfflineRegionDefinition definition; /** @@ -353,28 +356,31 @@ public class OfflineRegion { * @param callback the callback to be invoked */ public void delete(@NonNull final OfflineRegionDeleteCallback callback) { - deleteOfflineRegion(new OfflineRegionDeleteCallback() { - @Override - public void onDelete() { - getHandler().post(new Runnable() { - @Override - public void run() { - callback.onDelete(); - OfflineRegion.this.finalize(); - } - }); - } + if (!isDeleted) { + deleteOfflineRegion(new OfflineRegionDeleteCallback() { + @Override + public void onDelete() { + isDeleted = true; + getHandler().post(new Runnable() { + @Override + public void run() { + callback.onDelete(); + OfflineRegion.this.finalize(); + } + }); + } - @Override - public void onError(final String error) { - getHandler().post(new Runnable() { - @Override - public void run() { - callback.onError(error); - } - }); - } - }); + @Override + public void onError(final String error) { + getHandler().post(new Runnable() { + @Override + public void run() { + callback.onError(error); + } + }); + } + }); + } } /** -- cgit v1.2.1 From e681f69993ea9b28e745e8933744960eb5a608f8 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 12 May 2017 15:16:13 +0200 Subject: [android] - update LOST to 2.3.0 (#8872) --- platform/android/MapboxGLAndroidSDK/build.gradle | 4 +++- .../java/com/mapbox/mapboxsdk/location/LocationSource.java | 10 ---------- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index 1156a6ef43..c4668f598c 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -6,7 +6,9 @@ dependencies { compile rootProject.ext.dep.supportDesign compile rootProject.ext.dep.timber compile rootProject.ext.dep.okhttp3 - compile rootProject.ext.dep.lost + compile(rootProject.ext.dep.lost) { + exclude module: 'support-compat' + } // Mapbox Android Services (GeoJSON support) compile(rootProject.ext.dep.mapboxJavaGeoJSON) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java index b795cf1d5b..c4bdb4a17d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java @@ -135,14 +135,4 @@ public class LocationSource extends LocationEngine implements listener.onLocationChanged(location); } } - - @Override - public void onProviderDisabled(String provider) { - Log.d(LOG_TAG, "Provider disabled: " + provider); - } - - @Override - public void onProviderEnabled(String provider) { - Log.d(LOG_TAG, "Provider enabled: " + provider); - } } -- cgit v1.2.1 From cb737362b631284e1516561caf30c2027f9bdc03 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 12 May 2017 15:27:27 +0200 Subject: [android] - update proguard config, allow debug mimification, update OkHttp to latest version (#8944) --- platform/android/MapboxGLAndroidSDK/build.gradle | 4 +- .../android/MapboxGLAndroidSDK/proguard-rules.pro | 89 +--------------------- 2 files changed, 7 insertions(+), 86 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index c4668f598c..fca36237c3 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -95,6 +95,9 @@ android { } } } + + // proguard config for .aar + consumerProguardFiles 'proguard-rules.pro' } // avoid naming conflicts, force usage of prefix @@ -122,7 +125,6 @@ android { release { // aar proguard configuration - consumerProguardFiles 'proguard-rules.pro' jniDebuggable false } } diff --git a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro index baecd80e50..8e47815451 100644 --- a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro +++ b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro @@ -2,89 +2,8 @@ # in ../sdk/tools/proguard/proguard-android.txt, # contents of this file will be appended into proguard-android.txt -keepattributes Signature, *Annotation*, EnclosingMethod - -# Square okio, ignoring warnings, -# see https://github.com/square/okio/issues/60 --dontwarn okhttp3.** --dontwarn okio.** - -# Gesture package -keep class almeros.android.multitouch.gesturedetectors.** { *; } - -# Package annotations --keep class com.mapbox.mapboxsdk.annotations.** { *; } - -# Package camera --keep class com.mapbox.mapboxsdk.camera.** { *; } - -# Package geometry --keep class com.mapbox.mapboxsdk.geometry.** { *; } - -# Package http --keep class com.mapbox.mapboxsdk.http.** { *; } - -# Package maps --keep class com.mapbox.mapboxsdk.maps.** { *; } - -# Package net --keep class com.mapbox.mapboxsdk.net.** { *; } - -# Package offline --keep class com.mapbox.mapboxsdk.offline.** { *; } - -# Package storage --keep class com.mapbox.mapboxsdk.storage.** { *; } - -# Package style --keep class com.mapbox.mapboxsdk.style.layers.** { *; } --keep class com.mapbox.mapboxsdk.style.sources.** { *; } --keep class com.mapbox.mapboxsdk.style.functions.** { *; } - -# Package telemetry --keep class com.mapbox.mapboxsdk.telemetry.** { *; } - -# -# Mapbox-java Proguard rules -# We include these rules since libjava is a Jar file not AAR -# - -# Retrofit 2 -# Platform calls Class.forName on types which do not exist on Android to determine platform. --dontnote retrofit2.Platform -# Platform used when running on RoboVM on iOS. Will not be used at runtime. --dontnote retrofit2.Platform$IOS$MainThreadExecutor -# Platform used when running on Java 8 VMs. Will not be used at runtime. --dontwarn retrofit2.Platform$Java8 -# Retain generic type information for use by reflection by converters and adapters. --keepattributes Signature -# Retain declared checked exceptions for use by a Proxy instance. --keepattributes Exceptions - -# For using GSON @Expose annotation --keepattributes *Annotation* -# Gson specific classes --dontwarn sun.misc.** - -# Prevent proguard from stripping interface information from TypeAdapterFactory, -# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) --keep class * implements com.google.gson.TypeAdapterFactory --keep class * implements com.google.gson.JsonSerializer --keep class * implements com.google.gson.JsonDeserializer - -# MAS Data Models --keep class com.mapbox.services.commons.geojson.** { *; } --keep class com.mapbox.services.mapmatching.v4.models.** { *; } --keep class com.mapbox.services.distance.v1.models.** { *; } --keep class com.mapbox.services.directions.v4.models.** { *; } --keep class com.mapbox.services.directions.v5.models.** { *; } --keep class com.mapbox.services.geocoding.v5.models.** { *; } - --dontwarn javax.annotation.** - --keepclassmembers class rx.internal.util.unsafe.** { - long producerIndex; - long consumerIndex; -} - --keep class com.google.** { *; } --dontwarn com.google.** \ No newline at end of file +-keep class com.mapbox.mapboxsdk.** { *; } +-keep interface com.mapbox.mapboxsdk.** { *; } +-keep class com.mapbox.services.android.telemetry.** { *; } +-keep class com.mapbox.services.commons.** { *;} \ No newline at end of file -- cgit v1.2.1 From 0ef1293dada1490c808ae821228d5a2f3324afdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Fri, 9 Sep 2016 10:17:42 -0700 Subject: [core, android, ios, macos, qt] v10 default styles Upgraded from v9 default styles to v10 wherever the developer expects to get the latest and greatest, as well as in a couple tests where it may be beneficial to ensure that we can handle a two-digit version number in the style URL. Cherry-picked from ed54849e9909e7f7cd8724b39b2bc94f16cf9a11. --- .../src/main/java/com/mapbox/mapboxsdk/constants/Style.java | 6 +++--- platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java index d55fd4c023..fae3bdde2c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java @@ -35,13 +35,13 @@ public class Style { * constant means your map style will always use the latest version and may change as we * improve the style. */ - public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v9"; + public static final String MAPBOX_STREETS = "mapbox://styles/mapbox/streets-v10"; /** * Outdoors: A general-purpose style tailored to outdoor activities. Using this constant means * your map style will always use the latest version and may change as we improve the style. */ - public static final String OUTDOORS = "mapbox://styles/mapbox/outdoors-v9"; + public static final String OUTDOORS = "mapbox://styles/mapbox/outdoors-v10"; /** * Light: Subtle light backdrop for data visualizations. Using this constant means your map @@ -66,5 +66,5 @@ public class Style { * constant means your map style will always use the latest version and may change as we * improve the style. */ - public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-streets-v9"; + public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-streets-v10"; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml index 0862305cfb..7adc29e2de 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -18,10 +18,10 @@ - mapbox://styles/mapbox/streets-v9 - mapbox://styles/mapbox/outdoors-v9 + mapbox://styles/mapbox/streets-v10 + mapbox://styles/mapbox/outdoors-v10 mapbox://styles/mapbox/light-v9 mapbox://styles/mapbox/dark-v9 mapbox://styles/mapbox/satellite-v9 - mapbox://styles/mapbox/satellite-streets-v9 + mapbox://styles/mapbox/satellite-streets-v10 -- cgit v1.2.1 From 886bf2528ff1615a50521e75fc6ea211cef3b8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 8 May 2017 17:45:22 -0700 Subject: [core, android, ios, macos] Added Traffic Day/Night to default styles The Styles API section of the Mapbox API Documentation site now lists Traffic Day v2 and Traffic Night v2, so this change adds those styles to all the places where styles are listed. Also switched iosapp and macosapp to unversioned style factory methods since MGLStyleDefaultVersion is no longer applicable for all styles. Cherry-picked from 4d6f54553d277c0af24a0b8ff03d2dd7e9284ca2. --- .../java/com/mapbox/mapboxsdk/constants/Style.java | 20 +++++++++++++++++++- .../src/main/res/values/strings.xml | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java index fae3bdde2c..77d0929df3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java @@ -23,7 +23,7 @@ public class Style { * constants means your map style will always use the latest version and may change as we * improve the style */ - @StringDef( {MAPBOX_STREETS, OUTDOORS, LIGHT, DARK, SATELLITE, SATELLITE_STREETS}) + @StringDef( {MAPBOX_STREETS, OUTDOORS, LIGHT, DARK, SATELLITE, SATELLITE_STREETS, TRAFFIC_DAY, TRAFFIC_NIGHT}) @Retention(RetentionPolicy.SOURCE) public @interface StyleUrl { } @@ -67,4 +67,22 @@ public class Style { * improve the style. */ public static final String SATELLITE_STREETS = "mapbox://styles/mapbox/satellite-streets-v10"; + + /** + * Traffic Day: Color-coded roads based on live traffic congestion data. Traffic data is currently + * available in + * these select + * countries. Using this constant means your map style will always use the latest version and + * may change as we improve the style. + */ + public static final String TRAFFIC_DAY = "mapbox://styles/mapbox/traffic-day-v2"; + + /** + * Traffic Night: Color-coded roads based on live traffic congestion data, designed to maximize + * legibility in low-light situations. Traffic data is currently available in + * these select + * countries. Using this constant means your map style will always use the latest version and + * may change as we improve the style. + */ + public static final String TRAFFIC_NIGHT = "mapbox://styles/mapbox/traffic-night-v2"; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml index 7adc29e2de..65fb3e14a3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -24,4 +24,6 @@ mapbox://styles/mapbox/dark-v9 mapbox://styles/mapbox/satellite-v9 mapbox://styles/mapbox/satellite-streets-v10 + mapbox://styles/mapbox/traffic-day-v2 + mapbox://styles/mapbox/traffic-night-v2 -- cgit v1.2.1 From a68788a2cfb85efe69b0d81672bff7272368494e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 12 May 2017 20:07:06 +0200 Subject: [android] Release android-v5.1.0-beta.2 (#8976) * [android] url getter on sources * [android] fix ui test filter in makefile * [android] - build SNAPSHOT from release branch (#8958) * [android] - update changelog for 5.1.0-beta.2 * [android] - bump version number * [android] - Camera change listener v2.0 * [core] allow filesource url transform reset * [android] Update attribution wordmark (#8774) * Update wordmark on android * Moved attribution i icon to the right of mapbox word (in mapview preview image) * update padding and margin * [android] update hardcoded branch name * revert version to 5.1.0-SNAPSHOT --- .../mapboxsdk/maps/CameraChangeDispatcher.java | 67 ++++++++++++++ .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 39 ++++---- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 11 ++- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 100 ++++++++++++++++++++- .../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 30 +++---- .../java/com/mapbox/mapboxsdk/maps/Transform.java | 57 ++++++++++-- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 23 ++--- .../mapboxsdk/style/sources/GeoJsonSource.java | 10 +++ .../mapboxsdk/style/sources/RasterSource.java | 13 +++ .../mapboxsdk/style/sources/VectorSource.java | 10 +++ .../main/res/drawable-hdpi/mapbox_logo_icon.png | Bin 3408 -> 4778 bytes .../main/res/drawable-mdpi/mapbox_logo_icon.png | Bin 1958 -> 2622 bytes .../main/res/drawable-xhdpi/mapbox_logo_icon.png | Bin 4492 -> 6579 bytes .../main/res/drawable-xxhdpi/mapbox_logo_icon.png | Bin 7059 -> 10802 bytes .../main/res/drawable-xxxhdpi/mapbox_logo_icon.png | Bin 9402 -> 14441 bytes .../main/res/drawable/mapbox_info_icon_default.xml | 8 +- .../res/drawable/mapbox_info_icon_selected.xml | 10 +-- .../main/res/layout/mapbox_mapview_internal.xml | 3 +- .../src/main/res/layout/mapbox_mapview_preview.xml | 35 +++++--- .../src/main/res/values/dimens.xml | 9 +- 20 files changed, 342 insertions(+), 83 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java new file mode 100644 index 0000000000..bd028aecb6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcher.java @@ -0,0 +1,67 @@ +package com.mapbox.mapboxsdk.maps; + +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener; +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener; +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener; +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener; + +class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener, + MapboxMap.OnCameraMoveCanceledListener, OnCameraIdleListener { + + private boolean idle = true; + + private OnCameraMoveStartedListener onCameraMoveStartedListener; + private OnCameraMoveCanceledListener onCameraMoveCanceledListener; + private OnCameraMoveListener onCameraMoveListener; + private OnCameraIdleListener onCameraIdleListener; + + void setOnCameraMoveStartedListener(OnCameraMoveStartedListener onCameraMoveStartedListener) { + this.onCameraMoveStartedListener = onCameraMoveStartedListener; + } + + void setOnCameraMoveCanceledListener(OnCameraMoveCanceledListener onCameraMoveCanceledListener) { + this.onCameraMoveCanceledListener = onCameraMoveCanceledListener; + } + + void setOnCameraMoveListener(OnCameraMoveListener onCameraMoveListener) { + this.onCameraMoveListener = onCameraMoveListener; + } + + void setOnCameraIdleListener(OnCameraIdleListener onCameraIdleListener) { + this.onCameraIdleListener = onCameraIdleListener; + } + + @Override + public void onCameraMoveStarted(int reason) { + if (!idle) { + return; + } + + idle = false; + if (onCameraMoveStartedListener != null) { + onCameraMoveStartedListener.onCameraMoveStarted(reason); + } + } + + @Override + public void onCameraMove() { + if (onCameraMoveListener != null && !idle) { + onCameraMoveListener.onCameraMove(); + } + } + + @Override + public void onCameraMoveCanceled() { + if (onCameraMoveCanceledListener != null && !idle) { + onCameraMoveCanceledListener.onCameraMoveCanceled(); + } + } + + @Override + public void onCameraIdle() { + if (onCameraIdleListener != null && !idle) { + idle = true; + onCameraIdleListener.onCameraIdle(); + } + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index dca833bbf4..39433d8b93 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -22,6 +22,8 @@ import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.utils.MathUtils; import com.mapbox.services.android.telemetry.utils.TelemetryUtils; +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE; + /** * Manages gestures events on a MapView. *

@@ -35,6 +37,7 @@ final class MapGestureDetector { private final UiSettings uiSettings; private final TrackingSettings trackingSettings; private final AnnotationManager annotationManager; + private final CameraChangeDispatcher cameraChangeDispatcher; private final GestureDetectorCompat gestureDetector; private final ScaleGestureDetector scaleGestureDetector; @@ -56,12 +59,14 @@ final class MapGestureDetector { private boolean scaleGestureOccurred = false; MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings, - TrackingSettings trackingSettings, AnnotationManager annotationManager) { + TrackingSettings trackingSettings, AnnotationManager annotationManager, + CameraChangeDispatcher cameraChangeDispatcher) { this.annotationManager = annotationManager; this.transform = transform; this.projection = projection; this.uiSettings = uiSettings; this.trackingSettings = trackingSettings; + this.cameraChangeDispatcher = cameraChangeDispatcher; // Touch gesture detectors gestureDetector = new GestureDetectorCompat(context, new GestureListener()); @@ -187,6 +192,7 @@ final class MapGestureDetector { MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent( getLocationFromGesture(event.getX(), event.getY()), transform)); scrollInProgress = false; + cameraChangeDispatcher.onCameraIdle(); } twoTap = false; @@ -273,6 +279,9 @@ final class MapGestureDetector { break; } + // notify camera change listener + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); + // Single finger double tap if (focalPoint != null) { // User provided focal point @@ -337,6 +346,7 @@ final class MapGestureDetector { // and ignore when a scale gesture has occurred return false; } + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); float screenDensity = uiSettings.getPixelRatio(); @@ -362,9 +372,7 @@ final class MapGestureDetector { long animationTime = (long) (velocityXY / 7 / tiltFactor + MapboxConstants.ANIMATION_DURATION_FLING_BASE); // update transformation - transform.setGestureInProgress(true); transform.moveBy(offsetX, offsetY, animationTime); - transform.setGestureInProgress(false); if (onFlingListener != null) { onFlingListener.onFling(); @@ -377,6 +385,10 @@ final class MapGestureDetector { public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (!scrollInProgress) { scrollInProgress = true; + + // Cancel any animation + transform.cancelTransitions(); + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( getLocationFromGesture(e1.getX(), e1.getY()), MapboxEvent.GESTURE_PAN_START, transform)); @@ -391,8 +403,6 @@ final class MapGestureDetector { // reset tracking if needed trackingSettings.resetTrackingModesIfRequired(true, false); - // Cancel any animation - transform.cancelTransitions(); // Scroll the map transform.moveBy(-distanceX, -distanceY, 0 /*no duration*/); @@ -446,6 +456,8 @@ final class MapGestureDetector { // If scale is large enough ignore a tap scaleFactor *= detector.getScaleFactor(); if ((scaleFactor > 1.05f) || (scaleFactor < 0.95f)) { + // notify camera change listener + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); zoomStarted = true; } @@ -465,9 +477,6 @@ final class MapGestureDetector { return false; } - // Cancel any animation - transform.cancelTransitions(); - // Gesture is a quickzoom if there aren't two fingers quickZoom = !twoTap; @@ -512,6 +521,9 @@ final class MapGestureDetector { return false; } + // notify camera change listener + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); + beginTime = detector.getEventTime(); MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), @@ -522,6 +534,7 @@ final class MapGestureDetector { // Called when the fingers leave the screen @Override public void onRotateEnd(RotateGestureDetector detector) { + // notify camera change listener beginTime = 0; totalAngle = 0.0f; started = false; @@ -553,13 +566,8 @@ final class MapGestureDetector { if (!started) { return false; } - - // Cancel any animation - transform.cancelTransitions(); - // rotation constitutes translation of anything except the center of // rotation, so cancel both location and bearing tracking if required - trackingSettings.resetTrackingModesIfRequired(true, true); // Get rotate value @@ -593,6 +601,8 @@ final class MapGestureDetector { return false; } + // notify camera change listener + cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); beginTime = detector.getEventTime(); MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), @@ -633,9 +643,6 @@ final class MapGestureDetector { return false; } - // Cancel any animation - transform.cancelTransitions(); - // Get tilt value (scale and clamp) double pitch = transform.getTilt(); pitch -= 0.1 * detector.getShovePixelsDelta(); 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 872802292c..d00da4c155 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 @@ -129,6 +129,9 @@ public class MapView extends FrameLayout { // callback for zooming in the camera CameraZoomInvalidator zoomInvalidator = new CameraZoomInvalidator(); + // callback for camera change events + CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher(); + // setup components for MapboxMap creation Projection proj = new Projection(nativeMapView); UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, view.findViewById(R.id.logoView)); @@ -136,12 +139,14 @@ public class MapView extends FrameLayout { MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj, focalPoint); MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer)); AnnotationManager annotations = new AnnotationManager(nativeMapView, this, markerViewManager); - Transform transform = new Transform(nativeMapView, annotations.getMarkerViewManager(), trackingSettings); + Transform transform = new Transform(nativeMapView, annotations.getMarkerViewManager(), trackingSettings, + cameraChangeDispatcher); mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings, proj, - registerTouchListener, annotations); + registerTouchListener, annotations, cameraChangeDispatcher); // user input - mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings, annotations); + mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings, annotations, + cameraChangeDispatcher); mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings); MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform); 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 1751dcf042..96603355f1 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 @@ -69,6 +69,7 @@ public final class MapboxMap { private final Transform transform; private final AnnotationManager annotationManager; private final MyLocationViewSettings myLocationViewSettings; + private final CameraChangeDispatcher cameraChangeDispatcher; private final OnRegisterTouchListener onRegisterTouchListener; @@ -76,7 +77,7 @@ public final class MapboxMap { MapboxMap(NativeMapView map, Transform transform, UiSettings ui, TrackingSettings tracking, MyLocationViewSettings myLocationView, Projection projection, OnRegisterTouchListener listener, - AnnotationManager annotations) { + AnnotationManager annotations, CameraChangeDispatcher cameraChangeDispatcher) { this.nativeMapView = map; this.uiSettings = ui; this.trackingSettings = tracking; @@ -85,6 +86,7 @@ public final class MapboxMap { this.annotationManager = annotations.bind(this); this.transform = transform; this.onRegisterTouchListener = listener; + this.cameraChangeDispatcher = cameraChangeDispatcher; } void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) { @@ -1595,10 +1597,51 @@ public final class MapboxMap { * To unset the callback, use null. */ @UiThread + @Deprecated public void setOnCameraChangeListener(@Nullable OnCameraChangeListener listener) { transform.setOnCameraChangeListener(listener); } + /** + * Sets a callback that is invoked when camera movement has ended. + * + * @param listener the listener to notify + */ + @UiThread + public void setOnCameraIdleListener(@Nullable OnCameraIdleListener listener) { + cameraChangeDispatcher.setOnCameraIdleListener(listener); + } + + /** + * Sets a callback that is invoked when camera movement was cancelled. + * + * @param listener the listener to notify + */ + @UiThread + public void setOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) { + cameraChangeDispatcher.setOnCameraMoveCanceledListener(listener); + } + + /** + * Sets a callback that is invoked when camera movement has started. + * + * @param listener the listener to notify + */ + @UiThread + public void setOnCameraMoveStartedistener(@Nullable OnCameraMoveStartedListener listener) { + cameraChangeDispatcher.setOnCameraMoveStartedListener(listener); + } + + /** + * Sets a callback that is invoked when camera position changes. + * + * @param listener the listener to notify + */ + @UiThread + public void setOnCameraMoveListener(@Nullable OnCameraMoveListener listener) { + cameraChangeDispatcher.setOnCameraMoveListener(listener); + } + /** * Sets a callback that's invoked on every frame rendered to the map view. * @@ -1913,7 +1956,12 @@ public final class MapboxMap { /** * Interface definition for a callback to be invoked when the camera changes position. + * + * @deprecated Replaced by MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener and + * MapboxMap.OnCameraIdleListener. The order in which the deprecated onCameraChange method will be called in relation + * to the methods in the new camera change listeners is undefined. */ + @Deprecated public interface OnCameraChangeListener { /** * Called after the camera position has changed. During an animation, @@ -1925,6 +1973,56 @@ public final class MapboxMap { void onCameraChange(CameraPosition position); } + /** + * Interface definition for a callback to be invoked for when the camera motion starts. + */ + public interface OnCameraMoveStartedListener { + int REASON_API_GESTURE = 1; + int REASON_DEVELOPER_ANIMATION = 2; + int REASON_API_ANIMATION = 3; + + /** + * Called when the camera starts moving after it has been idle or when the reason for camera motion has changed. + * + * @param reason the reason for the camera change + */ + void onCameraMoveStarted(int reason); + } + + /** + * Interface definition for a callback to be invoked for when the camera changes position. + */ + public interface OnCameraMoveListener { + /** + * Called repeatedly as the camera continues to move after an onCameraMoveStarted call. + * This may be called as often as once every frame and should not perform expensive operations. + */ + void onCameraMove(); + } + + /** + * Interface definition for a callback to be invoked for when the camera's motion has been stopped or when the camera + * starts moving for a new reason. + */ + public interface OnCameraMoveCanceledListener { + /** + * Called when the developer explicitly calls the cancelTransitions() method or if the reason for camera motion has + * changed before the onCameraIdle had a chance to fire after the previous animation. + * Do not update or animate the camera from within this method. + */ + void onCameraMoveCanceled(); + } + + /** + * Interface definition for a callback to be invoked for when camera movement has ended. + */ + public interface OnCameraIdleListener { + /** + * Called when camera movement has ended. + */ + void onCameraIdle(); + } + /** * Interface definition for a callback to be invoked when a frame is rendered to the map view. * 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 8fcfdd6db0..68603ab1a3 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 @@ -35,10 +35,8 @@ import java.util.Arrays; */ public class MapboxMapOptions implements Parcelable { - private static final float DIMENSION_SEVEN_DP = 7f; - private static final float DIMENSION_TEN_DP = 10f; - private static final float DIMENSION_SIXTEEN_DP = 16f; - private static final float DIMENSION_SEVENTY_SIX_DP = 76f; + private static final float FOUR_DP = 4f; + private static final float EIGHTY_NINE_DP = 92f; private CameraPosition cameraPosition; @@ -206,13 +204,13 @@ public class MapboxMapOptions implements Parcelable { Gravity.TOP | Gravity.END)); mapboxMapOptions.compassMargins(new int[] { (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginLeft, - DIMENSION_TEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), ((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginTop, - DIMENSION_TEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), ((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginRight, - DIMENSION_TEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), ((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginBottom, - DIMENSION_TEN_DP * pxlRatio))}); + FOUR_DP * pxlRatio))}); mapboxMapOptions.compassFadesWhenFacingNorth(typedArray.getBoolean( R.styleable.mapbox_MapView_mapbox_uiCompassFadeFacingNorth, true)); Drawable compassDrawable = typedArray.getDrawable( @@ -227,13 +225,13 @@ public class MapboxMapOptions implements Parcelable { Gravity.BOTTOM | Gravity.START)); mapboxMapOptions.logoMargins(new int[] { (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginLeft, - DIMENSION_SIXTEEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginTop, - DIMENSION_SIXTEEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginRight, - DIMENSION_SIXTEEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginBottom, - DIMENSION_SIXTEEN_DP * pxlRatio))}); + FOUR_DP * pxlRatio))}); mapboxMapOptions.attributionTintColor(typedArray.getColor( R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1)); @@ -243,13 +241,13 @@ public class MapboxMapOptions implements Parcelable { R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM)); mapboxMapOptions.attributionMargins(new int[] { (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft, - DIMENSION_SEVENTY_SIX_DP) * pxlRatio), + EIGHTY_NINE_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop, - DIMENSION_SEVEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight, - DIMENSION_SEVEN_DP * pxlRatio)), + FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginBottom, - DIMENSION_SEVEN_DP * pxlRatio))}); + FOUR_DP * pxlRatio))}); mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false)); mapboxMapOptions.myLocationForegroundTintColor( diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index e101340111..af44a08a81 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationView; import timber.log.Timber; import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED; +import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener; /** * Resembles the current Map transformation. @@ -33,13 +34,18 @@ final class Transform implements MapView.OnMapChangedListener { private CameraPosition cameraPosition; private MapboxMap.CancelableCallback cameraCancelableCallback; + private MapboxMap.OnCameraChangeListener onCameraChangeListener; - Transform(NativeMapView mapView, MarkerViewManager markerViewManager, TrackingSettings trackingSettings) { + private CameraChangeDispatcher cameraChangeDispatcher; + + Transform(NativeMapView mapView, MarkerViewManager markerViewManager, TrackingSettings trackingSettings, + CameraChangeDispatcher cameraChangeDispatcher) { this.mapView = mapView; this.markerViewManager = markerViewManager; this.trackingSettings = trackingSettings; this.myLocationView = trackingSettings.getMyLocationView(); + this.cameraChangeDispatcher = cameraChangeDispatcher; } void initialise(@NonNull MapboxMap mapboxMap, @NonNull MapboxMapOptions options) { @@ -79,6 +85,7 @@ final class Transform implements MapView.OnMapChangedListener { cameraCancelableCallback.onFinish(); cameraCancelableCallback = null; } + cameraChangeDispatcher.onCameraIdle(); mapView.removeOnMapChangedListener(this); } } @@ -89,10 +96,12 @@ final class Transform implements MapView.OnMapChangedListener { if (!cameraPosition.equals(this.cameraPosition)) { trackingSettings.resetTrackingModesIfRequired(cameraPosition); cancelTransitions(); + cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION); mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom); if (callback != null) { callback.onFinish(); } + cameraChangeDispatcher.onCameraIdle(); } } @@ -103,6 +112,8 @@ final class Transform implements MapView.OnMapChangedListener { if (!cameraPosition.equals(this.cameraPosition)) { trackingSettings.resetTrackingModesIfRequired(cameraPosition); cancelTransitions(); + cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION); + if (callback != null) { cameraCancelableCallback = callback; mapView.addOnMapChangedListener(this); @@ -119,8 +130,9 @@ final class Transform implements MapView.OnMapChangedListener { CameraPosition cameraPosition = update.getCameraPosition(mapboxMap); if (!cameraPosition.equals(this.cameraPosition)) { trackingSettings.resetTrackingModesIfRequired(cameraPosition); - cancelTransitions(); + cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION); + if (callback != null) { cameraCancelableCallback = callback; mapView.addOnMapChangedListener(this); @@ -135,7 +147,12 @@ final class Transform implements MapView.OnMapChangedListener { @Nullable CameraPosition invalidateCameraPosition() { if (mapView != null) { - cameraPosition = mapView.getCameraPosition(); + CameraPosition cameraPosition = mapView.getCameraPosition(); + if (this.cameraPosition != null && !this.cameraPosition.equals(cameraPosition)) { + cameraChangeDispatcher.onCameraMove(); + } + + this.cameraPosition = cameraPosition; if (onCameraChangeListener != null) { onCameraChangeListener.onCameraChange(this.cameraPosition); } @@ -144,10 +161,17 @@ final class Transform implements MapView.OnMapChangedListener { } void cancelTransitions() { + // notify user about cancel + cameraChangeDispatcher.onCameraMoveCanceled(); + + // notify animateCamera and easeCamera about cancelling if (cameraCancelableCallback != null) { + cameraChangeDispatcher.onCameraIdle(); cameraCancelableCallback.onCancel(); cameraCancelableCallback = null; } + + // cancel ongoing transitions mapView.cancelTransitions(); } @@ -157,6 +181,10 @@ final class Transform implements MapView.OnMapChangedListener { mapView.resetNorth(); } + // + // Camera change listener API + // + void setOnCameraChangeListener(@Nullable MapboxMap.OnCameraChangeListener listener) { this.onCameraChangeListener = listener; } @@ -172,9 +200,6 @@ final class Transform implements MapView.OnMapChangedListener { } void zoom(boolean zoomIn, @NonNull PointF focalPoint) { - // Cancel any animation - cancelTransitions(); - CameraPosition cameraPosition = invalidateCameraPosition(); if (cameraPosition != null) { int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1)); @@ -187,6 +212,15 @@ final class Transform implements MapView.OnMapChangedListener { } void setZoom(double zoom, @NonNull PointF focalPoint, long duration) { + mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + if (change == MapView.REGION_DID_CHANGE_ANIMATED) { + mapView.removeOnMapChangedListener(this); + cameraChangeDispatcher.onCameraIdle(); + } + } + }); mapView.setZoom(zoom, focalPoint, duration); } @@ -278,6 +312,17 @@ final class Transform implements MapView.OnMapChangedListener { } void moveBy(double offsetX, double offsetY, long duration) { + if (duration > 0) { + mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() { + @Override + public void onMapChanged(int change) { + if (change == MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED) { + mapView.removeOnMapChangedListener(this); + cameraChangeDispatcher.onCameraIdle(); + } + } + }); + } mapView.moveBy(offsetX, offsetY, duration); } 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 354a42536a..1bcf8a70b9 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 @@ -146,7 +146,7 @@ public final class UiSettings { if (compassMargins != null) { setCompassMargins(compassMargins[0], compassMargins[1], compassMargins[2], compassMargins[3]); } else { - int tenDp = (int) resources.getDimension(R.dimen.mapbox_ten_dp); + int tenDp = (int) resources.getDimension(R.dimen.mapbox_four_dp); setCompassMargins(tenDp, tenDp, tenDp, tenDp); } setCompassFadeFacingNorth(options.getCompassFadeFacingNorth()); @@ -171,9 +171,7 @@ public final class UiSettings { private byte[] convert(Bitmap resource) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); resource.compress(Bitmap.CompressFormat.PNG, 100, stream); - byte[] byteArray = stream.toByteArray(); - - return byteArray; + return stream.toByteArray(); } private void restoreCompass(Bundle savedInstanceState) { @@ -189,10 +187,7 @@ public final class UiSettings { private Drawable decode(byte[] bitmap) { Bitmap compass = BitmapFactory.decodeByteArray(bitmap, 0, bitmap.length); - - Drawable compassImage = new BitmapDrawable(compassView.getResources(), compass); - - return compassImage; + return new BitmapDrawable(compassView.getResources(), compass); } private void initialiseLogo(MapboxMapOptions options, Resources resources) { @@ -202,8 +197,8 @@ public final class UiSettings { if (logoMargins != null) { setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]); } else { - int sixteenDp = (int) resources.getDimension(R.dimen.mapbox_sixteen_dp); - setLogoMargins(sixteenDp, sixteenDp, sixteenDp, sixteenDp); + int twoDp = (int) resources.getDimension(R.dimen.mapbox_two_dp); + setLogoMargins(twoDp, twoDp, twoDp, twoDp); } } @@ -226,16 +221,12 @@ public final class UiSettings { } private void initialiseAttribution(Context context, MapboxMapOptions options) { - Resources resources = context.getResources(); setAttributionEnabled(options.getAttributionEnabled()); setAttributionGravity(options.getAttributionGravity()); int[] attributionMargins = options.getAttributionMargins(); if (attributionMargins != null) { - setAttributionMargins(attributionMargins[0], attributionMargins[1], attributionMargins[2], attributionMargins[3]); - } else { - int sevenDp = (int) resources.getDimension(R.dimen.mapbox_seven_dp); - int seventySixDp = (int) resources.getDimension(R.dimen.mapbox_seventy_six_dp); - setAttributionMargins(seventySixDp, sevenDp, sevenDp, sevenDp); + setAttributionMargins(attributionMargins[0], attributionMargins[1], + attributionMargins[2], attributionMargins[3]); } int attributionTintColor = options.getAttributionTintColor(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java index ec80186761..10ecb945ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java @@ -227,6 +227,14 @@ public class GeoJsonSource extends Source { nativeSetUrl(url); } + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + /** * Queries the source for features. * @@ -243,6 +251,8 @@ public class GeoJsonSource extends Source { protected native void nativeSetUrl(String url); + protected native String nativeGetUrl(); + private native void nativeSetGeoJsonString(String geoJson); private native void nativeSetFeatureCollection(FeatureCollection geoJson); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java index 98b74afcff..38ed208618 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java @@ -1,5 +1,7 @@ package com.mapbox.mapboxsdk.style.sources; +import android.support.annotation.Nullable; + import java.net.URL; /** @@ -72,8 +74,19 @@ public class RasterSource extends Source { initialize(id, tileSet.toValueObject(), tileSize); } + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + protected native void initialize(String layerId, Object payload, int tileSize); @Override protected native void finalize() throws Throwable; + + protected native String nativeGetUrl(); + } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java index 7230492d0e..9b59cf8967 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java @@ -76,11 +76,21 @@ public class VectorSource extends Source { return features != null ? Arrays.asList(features) : new ArrayList(); } + /** + * @return The url or null + */ + @Nullable + public String getUrl() { + return nativeGetUrl(); + } + protected native void initialize(String layerId, Object payload); @Override protected native void finalize() throws Throwable; + protected native String nativeGetUrl(); + private native Feature[] querySourceFeatures(String[] sourceLayerId, Object[] filter); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_logo_icon.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_logo_icon.png index c0f4ed2c4c..7568387a8d 100644 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_logo_icon.png and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-hdpi/mapbox_logo_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_logo_icon.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_logo_icon.png index 5a9da3fe39..9cdec5151c 100644 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_logo_icon.png and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-mdpi/mapbox_logo_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_logo_icon.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_logo_icon.png index 194aa64da2..7eec45f4b1 100644 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_logo_icon.png and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xhdpi/mapbox_logo_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_logo_icon.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_logo_icon.png index d1260a16f3..5876056f1c 100644 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_logo_icon.png and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_logo_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_logo_icon.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_logo_icon.png index 5f9647610a..e5780ccc07 100644 Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_logo_icon.png and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_logo_icon.png differ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_default.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_default.xml index fa82bb8d9b..65837d65d0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_default.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_default.xml @@ -1,8 +1,8 @@ + android:width="21dp" + android:height="21dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_selected.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_selected.xml index 074928d05a..ccbd1d8d39 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_selected.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_info_icon_selected.xml @@ -1,9 +1,9 @@ + android:width="21dp" + android:height="21dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + android:pathData="M11,17h2v-6h-2v6zm1,-15C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm0,18c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM11,9h2V7h-2v2z"/> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_internal.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_internal.xml index e6a2677785..6d07de7baa 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_internal.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_internal.xml @@ -39,10 +39,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" - android:background="@drawable/mapbox_default_bg_selector" android:clickable="true" + android:focusable="true" android:contentDescription="@string/mapbox_attributionsIconContentDescription" - android:padding="7dp" android:src="@drawable/mapbox_info_bg_selector"/> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml index d015bc5785..1c1ab0e71b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml @@ -1,22 +1,29 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:contentDescription="@null" + android:src="@drawable/mapbox_mapview_preview" + android:layout_alignParentTop="true" + android:layout_alignParentLeft="true" + android:layout_alignParentStart="true"/> @@ -24,18 +31,22 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" - android:layout_marginBottom="@dimen/mapbox_seven_dp" - android:layout_marginLeft="@dimen/mapbox_seventy_six_dp" + android:layout_toEndOf="@+id/logoView" + android:contentDescription="@null" + android:layout_marginBottom="@dimen/mapbox_four_dp" android:background="@drawable/mapbox_default_bg_selector" - android:clickable="true" - android:contentDescription="@string/mapbox_attributionsIconContentDescription" - android:src="@drawable/mapbox_info_bg_selector" /> + android:src="@drawable/mapbox_info_bg_selector" + android:layout_marginLeft="@dimen/mapbox_four_dp" + android:layout_marginStart="@dimen/mapbox_four_dp" + android:layout_toRightOf="@+id/logoView"/> + android:contentDescription="@null" + android:src="@drawable/mapbox_compass_icon"/> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml index df6983e11d..ce20cb9a8b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml @@ -4,10 +4,15 @@ 8dp -2dp 1.5dp - 7dp + @dimen/mapbox_two_dp + @dimen/mapbox_two_dp + @dimen/mapbox_two_dp + @dimen/mapbox_two_dp + 2dp + 4dp 8dp 10dp 16dp - 76dp + 95dp 18dp -- cgit v1.2.1 From 59442167b16ec5b92c29aad4670340b740a0a9e4 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 15 May 2017 13:39:34 +0200 Subject: [android] - MarkerView deselect events with OnMarkerViewClickListener integration (#8996) --- .../java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 6553b64592..e811470d64 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -670,12 +670,15 @@ class AnnotationManager { for (Marker nearbyMarker : nearbyMarkers) { for (Marker selectedMarker : selectedMarkers) { if (nearbyMarker.equals(selectedMarker)) { - if (onMarkerClickListener != null) { - // end developer has provided a custom click listener + if (nearbyMarker instanceof MarkerView) { + handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) nearbyMarker); + } else if (onMarkerClickListener != null) { handledDefaultClick = onMarkerClickListener.onMarkerClick(nearbyMarker); - if (!handledDefaultClick) { - deselectMarker(nearbyMarker); - } + } + + if (!handledDefaultClick) { + // only deselect marker if user didn't handle the click event themselves + deselectMarker(nearbyMarker); } return true; } -- cgit v1.2.1 From eb83c7250933b7d3705a3508976c69571a9b9d4c Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 19 May 2017 09:14:54 +0200 Subject: [android] - bump tools and support lib version due to SNAPSHOT dependencies (#9046) * [android] - bump tools and support lib version for SNAPSHOT dependencies * revert unsupported Circle CI build tools version --- platform/android/MapboxGLAndroidSDK/build.gradle | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle index fca36237c3..5e19e94f5d 100644 --- a/platform/android/MapboxGLAndroidSDK/build.gradle +++ b/platform/android/MapboxGLAndroidSDK/build.gradle @@ -6,9 +6,7 @@ dependencies { compile rootProject.ext.dep.supportDesign compile rootProject.ext.dep.timber compile rootProject.ext.dep.okhttp3 - compile(rootProject.ext.dep.lost) { - exclude module: 'support-compat' - } + compile rootProject.ext.dep.lost // Mapbox Android Services (GeoJSON support) compile(rootProject.ext.dep.mapboxJavaGeoJSON) { -- cgit v1.2.1 From f4f587f46dbde355bebd70e57cacf2ad788d0fd9 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 19 May 2017 12:23:47 +0200 Subject: [android] - remove marker from selected markers when removing marker from annotation manager. (#9047) --- .../main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index e811470d64..3694668a7e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -92,6 +92,10 @@ class AnnotationManager { if (annotation instanceof Marker) { Marker marker = (Marker) annotation; marker.hideInfoWindow(); + if (selectedMarkers.contains(marker)) { + selectedMarkers.remove(marker); + } + if (marker instanceof MarkerView) { markerViewManager.removeMarkerView((MarkerView) marker); } @@ -118,6 +122,10 @@ class AnnotationManager { if (annotation instanceof Marker) { Marker marker = (Marker) annotation; marker.hideInfoWindow(); + if (selectedMarkers.contains(marker)) { + selectedMarkers.remove(marker); + } + if (marker instanceof MarkerView) { markerViewManager.removeMarkerView((MarkerView) marker); } @@ -138,6 +146,7 @@ class AnnotationManager { Annotation annotation; int count = annotations.size(); long[] ids = new long[count]; + selectedMarkers.clear(); for (int i = 0; i < count; i++) { ids[i] = annotations.keyAt(i); annotation = annotations.get(ids[i]); -- cgit v1.2.1 From 3c35bf1d170d1b331d871f75ad031834d99d2e78 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 24 May 2017 14:47:31 +0200 Subject: [android] - stop location updates when toggle MyLocationView state (#9099) --- .../src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 1 + 1 file changed, 1 insertion(+) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java index aecf3cc655..338d29c87c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java @@ -440,6 +440,7 @@ public class MyLocationView extends View { } else { // Disable location and user dot location = null; + locationSource.removeLocationUpdates(); locationSource.removeLocationEngineListener(userLocationListener); locationSource.deactivate(); } -- cgit v1.2.1 From c392c678ab4ea560cefca59d14b215e2d4c79ecb Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 26 May 2017 10:32:11 +0200 Subject: [android] - logo placement for creating a Mapview programatically (#9094) * [android] - Correct logo placement for creating a Mapview programatically, fixup non default placements * Fixed NIGHTY_TWO_DP typo to NINETY_TWO_DP --- .../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 4 ++-- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 28 +++++++++++++++------- .../src/main/res/values/dimens.xml | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') 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 68603ab1a3..98f94ddb39 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 @@ -36,7 +36,7 @@ import java.util.Arrays; public class MapboxMapOptions implements Parcelable { private static final float FOUR_DP = 4f; - private static final float EIGHTY_NINE_DP = 92f; + private static final float NINETY_TWO_DP = 92f; private CameraPosition cameraPosition; @@ -241,7 +241,7 @@ public class MapboxMapOptions implements Parcelable { R.styleable.mapbox_MapView_mapbox_uiAttributionGravity, Gravity.BOTTOM)); mapboxMapOptions.attributionMargins(new int[] { (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginLeft, - EIGHTY_NINE_DP * pxlRatio)), + NINETY_TWO_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop, FOUR_DP * pxlRatio)), (int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight, 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 1bcf8a70b9..accecf232b 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 @@ -193,12 +193,16 @@ public final class UiSettings { private void initialiseLogo(MapboxMapOptions options, Resources resources) { setLogoEnabled(options.getLogoEnabled()); setLogoGravity(options.getLogoGravity()); - int[] logoMargins = options.getLogoMargins(); + setLogoMargins(resources, options.getLogoMargins()); + } + + private void setLogoMargins(Resources resources, int[]logoMargins) { if (logoMargins != null) { setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]); } else { - int twoDp = (int) resources.getDimension(R.dimen.mapbox_two_dp); - setLogoMargins(twoDp, twoDp, twoDp, twoDp); + // user did not specify margins when programmatically creating a map + int fourDp = (int) resources.getDimension(R.dimen.mapbox_four_dp); + setLogoMargins(fourDp, fourDp, fourDp, fourDp); } } @@ -223,15 +227,23 @@ public final class UiSettings { private void initialiseAttribution(Context context, MapboxMapOptions options) { setAttributionEnabled(options.getAttributionEnabled()); setAttributionGravity(options.getAttributionGravity()); - int[] attributionMargins = options.getAttributionMargins(); + setAttributionMargins(context, options.getAttributionMargins()); + int attributionTintColor = options.getAttributionTintColor(); + setAttributionTintColor(attributionTintColor != -1 + ? attributionTintColor : ColorUtils.getPrimaryColor(context)); + } + + private void setAttributionMargins(Context context, int[] attributionMargins) { if (attributionMargins != null) { setAttributionMargins(attributionMargins[0], attributionMargins[1], attributionMargins[2], attributionMargins[3]); + } else { + // user did not specify margins when programmatically creating a map + Resources resources = context.getResources(); + int margin = (int) resources.getDimension(R.dimen.mapbox_four_dp); + int leftMargin = (int) resources.getDimension(R.dimen.mapbox_ninety_two_dp); + setAttributionMargins(leftMargin, margin, margin, margin); } - - int attributionTintColor = options.getAttributionTintColor(); - setAttributionTintColor(attributionTintColor != -1 - ? attributionTintColor : ColorUtils.getPrimaryColor(context)); } private void saveAttribution(Bundle outState) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml index ce20cb9a8b..8edbd47c29 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml @@ -13,6 +13,6 @@ 8dp 10dp 16dp - 95dp + 92dp 18dp -- cgit v1.2.1 From 5716bd3aecc777813161292e104ac9ceba3f230a Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 26 May 2017 16:04:09 +0200 Subject: [android] - add binding support for Light (#9013) --- .../MapboxGLAndroidSDK/gradle-checkstyle.gradle | 1 + .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 15 ++ .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 10 ++ .../mapbox/mapboxsdk/style/layers/Property.java | 21 +++ .../com/mapbox/mapboxsdk/style/light/Light.java | 181 +++++++++++++++++++++ .../com/mapbox/mapboxsdk/style/light/Position.java | 81 +++++++++ .../mapbox/mapboxsdk/style/light/light.java.ejs | 121 ++++++++++++++ 7 files changed, 430 insertions(+) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle index 05037c6be7..e0bc076d3d 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle +++ b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle @@ -15,6 +15,7 @@ task checkstyle(type: Checkstyle) { exclude '**/style/layers/Property.java' exclude '**/style/layers/PropertyFactory.java' exclude '**/style/layers/*Layer.java' + exclude '**/style/light/Light.java' classpath = files() ignoreFailures = false } 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 96603355f1..0bfa74d1c0 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 @@ -41,6 +41,7 @@ import com.mapbox.mapboxsdk.location.LocationSource; import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings; import com.mapbox.mapboxsdk.style.layers.Filter; import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.commons.geojson.Feature; @@ -567,6 +568,20 @@ public final class MapboxMap { return projection; } + // + // + // + + /** + * Get the global light source used to change lighting conditions on extruded fill layers. + * + * @return the global light source + */ + @Nullable + public Light getLight() { + return nativeMapView.getLight(); + } + // // Camera API // diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index cf8faa9012..008a1971cc 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -26,6 +26,7 @@ import com.mapbox.mapboxsdk.storage.FileSource; import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException; import com.mapbox.mapboxsdk.style.layers.Filter; import com.mapbox.mapboxsdk.style.layers.Layer; +import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; import com.mapbox.mapboxsdk.style.sources.Source; import com.mapbox.services.commons.geojson.Feature; @@ -885,6 +886,13 @@ final class NativeMapView { fileSource.setApiBaseUrl(baseUrl); } + public Light getLight() { + if (isDestroyedOn("getLight")) { + return null; + } + return nativeGetLight(); + } + public float getPixelRatio() { return pixelRatio; } @@ -1120,6 +1128,8 @@ final class NativeMapView { String[] layerIds, Object[] filter); + private native Light nativeGetLight(); + int getWidth() { if (isDestroyedOn("")) { return 0; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java index 48e0ec5de3..5e345268f9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Property.java @@ -467,6 +467,27 @@ public final class Property { @Retention(RetentionPolicy.SOURCE) public @interface FILL_EXTRUSION_TRANSLATE_ANCHOR {} + // ANCHOR: Whether extruded geometries are lit relative to the map or viewport. + + /** + * The position of the light source is aligned to the rotation of the map. + */ + public static final String ANCHOR_MAP = "map"; + /** + * The position of the light source is aligned to the rotation of the viewport. + */ + public static final String ANCHOR_VIEWPORT = "viewport"; + + /** + * Whether extruded geometries are lit relative to the map or viewport. + */ + @StringDef({ + ANCHOR_MAP, + ANCHOR_VIEWPORT, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ANCHOR {} + private Property() { } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java new file mode 100644 index 0000000000..b66a50b8a4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java @@ -0,0 +1,181 @@ +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.style.light; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; +import android.support.annotation.UiThread; + +import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; + +/** + * The global light source. + * + * @see The online documentation + */ +@UiThread +public class Light { + + private long nativePtr; + + /** + * Creates a Light. + * + * @param nativePtr pointer used by core + */ + public Light(long nativePtr) { + this.nativePtr = nativePtr; + } + + /** + * Set the Anchor property. Whether extruded geometries are lit relative to the map or viewport. + * + * @param anchor as String + */ + public void setAnchor(@Property.ANCHOR String anchor) { + nativeSetAnchor(anchor); + } + + /** + * Get the Anchor property. Whether extruded geometries are lit relative to the map or viewport. + * + * @return anchor as String + */ + @Property.ANCHOR public String getAnchor() { + return nativeGetAnchor(); + } + + /** + * Set the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). + * + * @param position of the light + */ + public void setPosition(@NonNull Position position) { + nativeSetPosition(position); + } + + /** + * Get the Position property. Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). + * + * @return position as Position + */ + public Position getPosition() { + return nativeGetPosition(); + } + + /** + * Get the Position property transition options. + * + * @return transition options for position + */ + public TransitionOptions getPositionTransition() { + return nativeGetPositionTransition(); + } + + /** + * Set the Position property transition options. + * + * @param options transition options for position + */ + public void setPositionTransition(TransitionOptions options) { + nativeSetPositionTransition(options.getDuration(), options.getDelay()); + } + + /** + * Set the Color property. Color tint for lighting extruded geometries. + * + * @param color as int + */ + public void setColor(@ColorInt int color) { + nativeSetColor(PropertyFactory.colorToRgbaString(color)); + } + + /** + * Set the Color property. Color tint for lighting extruded geometries. + * + * @param color as String + */ + public void setColor(String color) { + nativeSetColor(color); + } + + /** + * Get the Color property. Color tint for lighting extruded geometries. + * + * @return color as String + */ + public String getColor() { + return nativeGetColor(); + } + + /** + * Get the Color property transition options. + * + * @return transition options for color + */ + public TransitionOptions getColorTransition() { + return nativeGetColorTransition(); + } + + /** + * Set the Color property transition options. + * + * @param options transition options for color + */ + public void setColorTransition(TransitionOptions options) { + nativeSetColorTransition(options.getDuration(), options.getDelay()); + } + + /** + * Set the Intensity property. Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. + * + * @param intensity as Float + */ + public void setIntensity(float intensity) { + nativeSetIntensity(intensity); + } + + /** + * Get the Intensity property. Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. + * + * @return intensity as Float + */ + public float getIntensity() { + return nativeGetIntensity(); + } + + /** + * Get the Intensity property transition options. + * + * @return transition options for intensity + */ + public TransitionOptions getIntensityTransition() { + return nativeGetIntensityTransition(); + } + + /** + * Set the Intensity property transition options. + * + * @param options transition options for intensity + */ + public void setIntensityTransition(TransitionOptions options) { + nativeSetIntensityTransition(options.getDuration(), options.getDelay()); + } + + private native void nativeSetAnchor(String anchor); + private native String nativeGetAnchor(); + private native void nativeSetPosition(Position position); + private native Position nativeGetPosition(); + private native TransitionOptions nativeGetPositionTransition(); + private native void nativeSetPositionTransition(long duration, long delay); + private native void nativeSetColor(String color); + private native String nativeGetColor(); + private native TransitionOptions nativeGetColorTransition(); + private native void nativeSetColorTransition(long duration, long delay); + private native void nativeSetIntensity(float intensity); + private native float nativeGetIntensity(); + private native TransitionOptions nativeGetIntensityTransition(); + private native void nativeSetIntensityTransition(long duration, long delay); +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java new file mode 100644 index 0000000000..215db03ad2 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java @@ -0,0 +1,81 @@ +package com.mapbox.mapboxsdk.style.light; + +/** + * Position of the light source relative to lit (extruded) geometries. + *

+ * The position is constructed out of a radial coordinate, an azimuthal angle and a polar angle. + * where the radial coordinate indicates the distance from the center of the base of an object to its light, the + * azimuthal angle indicates the position of the light relative to 0° (0° when + * {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to viewport corresponds to the top of the + * viewport, or 0° when {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to map corresponds to due + * north, and degrees proceed clockwise), and polar indicates the height of the light + * (from 0°, directly above, to 180°, directly below). + */ +public class Position { + + private float radialCoordinate; + private float azimuthalAngle; + private float polarAngle; + + /** + * Creates a Position from a radial coordinate, an azimuthal angle & a polar angle. + * + * @param radialCoordinate the distance from the center of the base of an object to its light + * @param azimuthalAngle the position of the light relative to 0° + * @param polarAngle the height of the light + */ + public Position(float radialCoordinate, float azimuthalAngle, float polarAngle) { + this.radialCoordinate = radialCoordinate; + this.azimuthalAngle = azimuthalAngle; + this.polarAngle = polarAngle; + } + + /** + * Returns a Position from a radial coordinate, an azimuthal angle & a polar angle + * + * @param radialCoordinate the radial coordinate + * @param azimuthalAngle the azimuthal angle + * @param polarAngle the polar angle + * @return the created Position object + */ + public static Position fromPosition(float radialCoordinate, float azimuthalAngle, float polarAngle) { + return new Position(radialCoordinate, azimuthalAngle, polarAngle); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Position position = (Position) o; + + if (Float.compare(position.radialCoordinate, radialCoordinate) != 0) { + return false; + } + if (Float.compare(position.azimuthalAngle, azimuthalAngle) != 0) { + return false; + } + return Float.compare(position.polarAngle, polarAngle) == 0; + } + + @Override + public int hashCode() { + int result = (radialCoordinate != +0.0f ? Float.floatToIntBits(radialCoordinate) : 0); + result = 31 * result + (azimuthalAngle != +0.0f ? Float.floatToIntBits(azimuthalAngle) : 0); + result = 31 * result + (polarAngle != +0.0f ? Float.floatToIntBits(polarAngle) : 0); + return result; + } + + @Override + public String toString() { + return "Position{" + + "radialCoordinate=" + radialCoordinate + + ", azimuthalAngle=" + azimuthalAngle + + ", polarAngle=" + polarAngle + + '}'; + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs new file mode 100644 index 0000000000..067efe1092 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs @@ -0,0 +1,121 @@ +<% + const properties = locals.properties; + const doc = locals.doc; +-%> +// This file is generated. Edit android/platform/scripts/generate-style-code.js, then run `make android-style-code`. + +package com.mapbox.mapboxsdk.style.light; + +import android.support.annotation.ColorInt; +import android.support.annotation.NonNull; +import android.support.annotation.UiThread; + +import com.mapbox.mapboxsdk.style.layers.Property; +import com.mapbox.mapboxsdk.style.layers.PropertyFactory; +import com.mapbox.mapboxsdk.style.layers.TransitionOptions; + +/** + * The global light source. + * + * @see The online documentation + */ +@UiThread +public class Light { + + private long nativePtr; + + /** + * Creates a Light. + * + * @param nativePtr pointer used by core + */ + public Light(long nativePtr) { + this.nativePtr = nativePtr; + } +<% for (const property of properties) { -%> +<% if (property.name == "position") {-%> + + /** + * Set the <%- camelize(property.name) %> property. <%- property.doc %> + * + * @param position of the light + */ + public void set<%- camelize(property.name) %>(@NonNull Position position) { + nativeSet<%- camelize(property.name) %>(position); + } + + /** + * Get the <%- camelize(property.name) %> property. <%- property.doc %> + * + * @return <%- property.name %> as Position + */ + public Position get<%- camelize(property.name) %>() { + return nativeGet<%- camelize(property.name) %>(); + } +<% } else { -%> +<% if (property.name == "color") {-%> + + /** + * Set the <%- camelize(property.name) %> property. <%- property.doc %> + * + * @param <%- property.name %> as int + */ + public void set<%- camelize(property.name) %>(@ColorInt int <%- property.name %>) { + nativeSet<%- camelize(property.name) %>(PropertyFactory.colorToRgbaString(<%- property.name %>)); + } +<% } -%> + + /** + * Set the <%- camelize(property.name) %> property. <%- property.doc %> + * + * @param <%- property.name %> as <%- propertyType(property) %> + */ + public void set<%- camelize(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyJavaType(property) %> <%- property.name %>) { + nativeSet<%- camelize(property.name) %>(<%- property.name %>); + } + + /** + * Get the <%- camelize(property.name) %> property. <%- property.doc %> + * + * @return <%- property.name %> as <%- propertyType(property) %> + */ + <%- propertyTypeAnnotation(property) %> public <%- propertyJavaType(property) %> get<%- camelize(property.name) %>() { + return nativeGet<%- camelize(property.name) %>(); + } +<% } -%> +<% if (property.transition) { -%> + + /** + * Get the <%- camelize(property.name) %> property transition options. + * + * @return transition options for <%- property.name %> + */ + public TransitionOptions get<%- camelize(property.name) %>Transition() { + return nativeGet<%- camelize(property.name) %>Transition(); + } + + /** + * Set the <%- camelize(property.name) %> property transition options. + * + * @param options transition options for <%- property.name %> + */ + public void set<%- camelize(property.name) %>Transition(TransitionOptions options) { + nativeSet<%- camelize(property.name) %>Transition(options.getDuration(), options.getDelay()); + } +<% } -%> +<% } -%> + +<% for (const property of properties) { -%> +<% if (property.name == "position") {-%> + private native void nativeSet<%- camelize(property.name) %>(Position position); + private native Position nativeGet<%- camelize(property.name) %>(); +<% } else { -%> + private native void nativeSet<%- camelize(property.name) %>(<%- propertyJavaType(property) -%> <%- property.name %>); + private native <%- propertyJavaType(property) -%> nativeGet<%- camelize(property.name) %>(); +<% } -%> +<% if (property.transition) { -%> + private native TransitionOptions nativeGet<%- camelize(property.name) %>Transition(); + private native void nativeSet<%- camelize(property.name) %>Transition(long duration, long delay); +<% } -%> +<% } -%> +} \ No newline at end of file -- cgit v1.2.1 From bc5b147df79425ec03f2fbe6f3a2566ee45b4800 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Fri, 26 May 2017 20:01:57 +0200 Subject: [android] - convert dp to pixels when getting meters per pixel at. (#9048) --- .../src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 008a1971cc..02eeb25f83 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -621,7 +621,7 @@ final class NativeMapView { if (isDestroyedOn("getMetersPerPixelAtLatitude")) { return 0; } - return nativeGetMetersPerPixelAtLatitude(lat, getZoom()); + return nativeGetMetersPerPixelAtLatitude(lat, getZoom()) / pixelRatio; } public ProjectedMeters projectedMetersForLatLng(LatLng latLng) { -- cgit v1.2.1 From fc495dec12a5136f7476aa9d5cb8d76c95024919 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Tue, 30 May 2017 16:56:19 +0200 Subject: [android] - harden orientation changes (#9128) --- .../com/mapbox/mapboxsdk/annotations/Icon.java | 67 +++++++--- .../mapbox/mapboxsdk/annotations/MarkerView.java | 4 + .../com/mapbox/mapboxsdk/maps/IconManager.java | 148 ++++++++++----------- .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 4 - 4 files changed, 125 insertions(+), 98 deletions(-) (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java index b1a05ec436..2ee17c227d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java @@ -1,15 +1,18 @@ package com.mapbox.mapboxsdk.annotations; import android.graphics.Bitmap; +import android.util.DisplayMetrics; -import com.mapbox.mapboxsdk.maps.MapView; +import java.nio.ByteBuffer; /** - * Icon is the visual representation of a {@link Marker} on a {@link MapView}. + * Icon is the visual representation of a Marker on a MapView. * * @see Marker + * @see IconFactory */ public class Icon { + private Bitmap mBitmap; private String mId; @@ -19,29 +22,67 @@ public class Icon { } /** - * {@link String} identifier for this {@link Icon}. + * String identifier for this icon. * - * @return {@link String} identifier for this {@link Icon}. + * @return String identifier for this icon. */ public String getId() { return mId; } /** - * Get the {@link Bitmap} being used for this {@link Icon}. + * Get the bitmap being used for this icon. * - * @return The {@link Bitmap} being used for the {@link Icon}. + * @return The bitmap being used for the icon. */ public Bitmap getBitmap() { + if (mBitmap.getConfig() != Bitmap.Config.ARGB_8888) { + mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, false); + } return mBitmap; } /** - * Compares this {@link Icon} object with another {@link Icon} and determines if they match. + * Get the icon bitmap scale. + *

+ * Requires the bitmap to be set before calling this method. + *

+ * + * @return the scale of the bitmap + */ + public float getScale() { + if (mBitmap == null) { + throw new IllegalStateException("Required to set a Icon before calling getScale"); + } + float density = mBitmap.getDensity(); + if (density == Bitmap.DENSITY_NONE) { + density = DisplayMetrics.DENSITY_DEFAULT; + } + return density / DisplayMetrics.DENSITY_DEFAULT; + } + + /** + * Get the icon bitmap bytes. + *

+ * Requires the bitmap to be set before calling this method. + *

* - * @param object Another {@link Icon} to compare with this object. - * @return True if the {@link Icon} being passed in matches this {@link Icon} object. Else, - * false. + * @return the bytes of the bitmap + */ + public byte[] toBytes() { + if (mBitmap == null) { + throw new IllegalStateException("Required to set a Icon before calling toBytes"); + } + ByteBuffer buffer = ByteBuffer.allocate(mBitmap.getRowBytes() * mBitmap.getHeight()); + mBitmap.copyPixelsToBuffer(buffer); + return buffer.array(); + } + + /** + * Compares this icon object with another icon and determines if they match. + * + * @param object Another iconi to compare with this object. + * @return True if the icon being passed in matches this icon object. Else, false. */ @Override public boolean equals(Object object) { @@ -53,11 +94,7 @@ public class Icon { } Icon icon = (Icon) object; - - if (!mBitmap.equals(icon.mBitmap)) { - return false; - } - return mId.equals(icon.mId); + return mBitmap.equals(icon.mBitmap) && mId.equals(icon.mId); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java index 30336d4ebd..56e8cc4ce2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.annotations; import android.support.annotation.FloatRange; import android.support.annotation.Nullable; +import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapboxMap; @@ -361,6 +362,9 @@ public class MarkerView extends Marker { */ @Override public Icon getIcon() { + if (markerViewIcon == null) { + setIcon(IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarkerView()); + } return markerViewIcon; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java index c9d81a88bc..9f4171aee8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java @@ -1,15 +1,14 @@ package com.mapbox.mapboxsdk.maps; import android.graphics.Bitmap; -import android.util.DisplayMetrics; +import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerView; import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -41,118 +40,109 @@ class IconManager { Icon loadIconForMarker(Marker marker) { Icon icon = marker.getIcon(); - - // calculating average before adding - int iconSize = icons.size() + 1; - - // TODO replace former if case with anchor implementation, - // current workaround for having extra pixels is diving height by 2 if (icon == null) { - icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarker(); - Bitmap bitmap = icon.getBitmap(); - averageIconHeight = averageIconHeight + (bitmap.getHeight() / 2 - averageIconHeight) / iconSize; - averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize; - marker.setIcon(icon); - } else { - Bitmap bitmap = icon.getBitmap(); - averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize; - averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize; - } - - if (!icons.contains(icon)) { - icons.add(icon); - loadIcon(icon); + // TODO replace with anchor implementation, we are faking an anchor by adding extra pixels and diving height by 2 + // TODO we can move this code afterwards to getIcon as with MarkerView.getIcon + icon = loadDefaultIconForMarker(marker); } else { - Icon oldIcon = icons.get(icons.indexOf(icon)); - if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) { - throw new IconBitmapChangedException(); - } + updateAverageIconSize(icon); } + addIcon(icon); return icon; } - Icon loadIconForMarkerView(MarkerView marker) { + void loadIconForMarkerView(MarkerView marker) { Icon icon = marker.getIcon(); - int iconSize = icons.size() + 1; - if (icon == null) { - icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarkerView(); - marker.setIcon(icon); - } Bitmap bitmap = icon.getBitmap(); - averageIconHeight = averageIconHeight + (bitmap.getHeight() - averageIconHeight) / iconSize; - averageIconWidth = averageIconWidth + (bitmap.getWidth() - averageIconWidth) / iconSize; - if (!icons.contains(icon)) { - icons.add(icon); - } else { - Icon oldIcon = icons.get(icons.indexOf(icon)); - if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) { - throw new IconBitmapChangedException(); - } - } - return icon; + updateAverageIconSize(bitmap); + addIcon(icon, false); } int getTopOffsetPixelsForIcon(Icon icon) { return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio()); } - void loadIcon(Icon icon) { + int getAverageIconHeight() { + return averageIconHeight; + } + + int getAverageIconWidth() { + return averageIconWidth; + } + + private Icon loadDefaultIconForMarker(Marker marker) { + Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker(); Bitmap bitmap = icon.getBitmap(); - String id = icon.getId(); - if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) { - bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false); - } - ByteBuffer buffer = ByteBuffer.allocate(bitmap.getRowBytes() * bitmap.getHeight()); - bitmap.copyPixelsToBuffer(buffer); + updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight() / 2); + marker.setIcon(icon); + return icon; + } + + private void addIcon(Icon icon) { + addIcon(icon, true); + } - float density = bitmap.getDensity(); - if (density == Bitmap.DENSITY_NONE) { - density = DisplayMetrics.DENSITY_DEFAULT; + private void addIcon(Icon icon, boolean addIconToMap) { + if (!icons.contains(icon)) { + icons.add(icon); + if (addIconToMap) { + loadIcon(icon); + } + } else { + validateIconChanged(icon); } - float scale = density / DisplayMetrics.DENSITY_DEFAULT; - nativeMapView.addAnnotationIcon( - id, + } + + private void updateAverageIconSize(Icon icon) { + updateAverageIconSize(icon.getBitmap()); + } + + private void updateAverageIconSize(Bitmap bitmap) { + updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight()); + } + + private void updateAverageIconSize(int width, int height) { + int iconSize = icons.size() + 1; + averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize; + averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize; + } + + private void loadIcon(Icon icon) { + Bitmap bitmap = icon.getBitmap(); + nativeMapView.addAnnotationIcon(icon.getId(), bitmap.getWidth(), bitmap.getHeight(), - scale, buffer.array()); + icon.getScale(), + icon.toBytes()); } void reloadIcons() { - int count = icons.size(); - for (int i = 0; i < count; i++) { - Icon icon = icons.get(i); + for (Icon icon : icons) { loadIcon(icon); } } + private void validateIconChanged(Icon icon) { + Icon oldIcon = icons.get(icons.indexOf(icon)); + if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) { + throw new IconBitmapChangedException(); + } + } + void ensureIconLoaded(Marker marker, MapboxMap mapboxMap) { Icon icon = marker.getIcon(); if (icon == null) { - icon = IconFactory.getInstance(nativeMapView.getContext()).defaultMarker(); - marker.setIcon(icon); - } - if (!icons.contains(icon)) { - icons.add(icon); - loadIcon(icon); - } else { - Icon oldIcon = icons.get(icons.indexOf(icon)); - if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) { - throw new IconBitmapChangedException(); - } + icon = loadDefaultIconForMarker(marker); } + addIcon(icon); + setTopOffsetPixels(marker, mapboxMap, icon); + } + private void setTopOffsetPixels(Marker marker, MapboxMap mapboxMap, Icon icon) { // this seems to be a costly operation according to the profiler so I'm trying to save some calls Marker previousMarker = marker.getId() != -1 ? (Marker) mapboxMap.getAnnotation(marker.getId()) : null; if (previousMarker == null || previousMarker.getIcon() == null || previousMarker.getIcon() != marker.getIcon()) { marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon)); } } - - int getAverageIconHeight() { - return averageIconHeight; - } - - int getAverageIconWidth() { - return averageIconWidth; - } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 02eeb25f83..63f2e653cc 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -897,10 +897,6 @@ final class NativeMapView { return pixelRatio; } - public Context getContext() { - return mapView.getContext(); - } - // // Callbacks // -- cgit v1.2.1 From 83df8a8621287e548ee771599c9c98b61b9971a3 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 31 May 2017 09:46:12 +0200 Subject: [android] - javadoc update for 5.1.0 release (#9138) * [android] - javadoc update for 5.1.0 release * oxford comma * Grammar/spelling tweaks * grammar tweak * grammar tweak * Grammar tweaks * Grammar tweaks --- .../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 33 ++++++++---- .../mapbox/mapboxsdk/camera/CameraPosition.java | 4 +- .../mapboxsdk/camera/CameraUpdateFactory.java | 2 +- .../mapboxsdk/constants/MyBearingTracking.java | 4 +- .../mapboxsdk/constants/MyLocationTracking.java | 4 +- .../java/com/mapbox/mapboxsdk/constants/Style.java | 2 +- .../mapbox/mapboxsdk/location/LocationSource.java | 53 +++++++++++++++++-- .../mapboxsdk/maps/FocalPointChangeListener.java | 3 ++ .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 6 +-- .../mapbox/mapboxsdk/offline/OfflineManager.java | 4 +- .../mapbox/mapboxsdk/offline/OfflineRegion.java | 2 +- .../com/mapbox/mapboxsdk/storage/Resource.java | 6 +++ .../style/functions/CompositeFunction.java | 2 +- .../com/mapbox/mapboxsdk/style/layers/Filter.java | 2 +- .../mapboxsdk/style/layers/TransitionOptions.java | 28 ++++++++++ .../mapbox/mapboxsdk/style/light/package-info.java | 4 ++ .../com/mapbox/mapboxsdk/utils/AnimatorUtils.java | 59 ++++++++++++++++++++++ .../com/mapbox/mapboxsdk/utils/ColorUtils.java | 3 ++ 18 files changed, 188 insertions(+), 33 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/package-info.java (limited to 'platform/android/MapboxGLAndroidSDK') diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java index 8098ee4d86..f75d7ed90d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk; +import android.app.Application; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -15,6 +16,14 @@ import com.mapbox.services.android.telemetry.MapboxTelemetry; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEnginePriority; +/** + * The entry point of the Mapbox Android SDK. + *

+ * Obtain a reference by calling {@link #getInstance(Context, String)}. Usually this class is configured in + * {@link Application#onCreate()} and is responsible for the active access token, application context, and + * connectivity state. + *

+ */ public final class Mapbox { private static Mapbox INSTANCE; @@ -25,7 +34,7 @@ public final class Mapbox { /** * Get an instance of Mapbox. *

- * This class manages the active access token, application context and connectivity state. + * This class manages the active access token, application context, and connectivity state. *

* * @param context Android context which holds or is an application context @@ -52,9 +61,9 @@ public final class Mapbox { } /** - * Access Token for this application. + * Access token for this application. * - * @return Mapbox Access Token + * @return Mapbox access token */ public static String getAccessToken() { validateMapbox(); @@ -72,12 +81,14 @@ public final class Mapbox { } /** - * Runtime validation of Access Token. + * Runtime validation of access token. * * @throws MapboxConfigurationException exception thrown when not using a valid accessToken */ private static void validateAccessToken() throws MapboxConfigurationException { - String accessToken = INSTANCE.accessToken; + String + + = INSTANCE.accessToken; if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.") && !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) { throw new MapboxConfigurationException(); @@ -92,11 +103,11 @@ public final class Mapbox { } /** - * Manually sets the connectivity state of the app. This is useful for apps that control their + * Manually sets the connectivity state of the app. This is useful for apps which control their * own connectivity state and want to bypass any checks to the ConnectivityManager. * * @param connected flag to determine the connectivity state, true for connected, false for - * disconnected, null for ConnectivityManager to determine. + * disconnected, and null for ConnectivityManager to determine. */ public static synchronized void setConnected(Boolean connected) { // Connectivity state overridden by app @@ -104,10 +115,10 @@ public final class Mapbox { } /** - * Determines whether we have an Internet connection available. Please do not rely on this - * method in your apps, this method is used internally by the SDK. + * Determines whether we have an internet connection available. Please do not rely on this + * method in your apps. This method is used internally by the SDK. * - * @return true if there is an Internet connection, false otherwise + * @return true if there is an internet connection, false otherwise */ public static synchronized Boolean isConnected() { if (INSTANCE.connected != null) { @@ -119,4 +130,4 @@ public final class Mapbox { NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return (activeNetwork != null && activeNetwork.isConnected()); } -} \ No newline at end of file +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java index 5e958ff565..66c261f1d0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraPosition.java @@ -156,7 +156,7 @@ public final class CameraPosition implements Parcelable { } /** - * Builder for composing {@link CameraPosition} objects. + * Builder for composing CameraPosition objects. */ public static final class Builder { @@ -190,7 +190,7 @@ public final class CameraPosition implements Parcelable { /** * Create Builder with an existing CameraPosition data. * - * @param typedArray TypedArray containgin attribute values + * @param typedArray TypedArray containing attribute values */ public Builder(TypedArray typedArray) { super(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java index 64b86054a0..8e1411e273 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdateFactory.java @@ -15,7 +15,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** - * Factory for creating {@link CameraUpdate} objects. + * Factory for creating CameraUpdate objects. */ public final class CameraUpdateFactory { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java index f53c65d055..88c3bef673 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyBearingTracking.java @@ -16,7 +16,7 @@ import java.lang.annotation.RetentionPolicy; public class MyBearingTracking { /** - * Indicates the parameter accepts one of the values from {@link MyBearingTracking}. + * Indicates that the parameter accepts one of the values from MyBearingTracking. */ @IntDef( {NONE, COMPASS, GPS, /**COMBINED**/}) @Retention(RetentionPolicy.SOURCE) @@ -38,6 +38,4 @@ public class MyBearingTracking { */ public static final int GPS = 0x00000008; - // public static final int COMBINED = 0x00000012; - } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java index 39f653596f..a1744d701f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MyLocationTracking.java @@ -17,7 +17,7 @@ import java.lang.annotation.RetentionPolicy; public class MyLocationTracking { /** - * Indicates the parameter accepts one of the values from {@link MyLocationTracking}. + * Indicates the parameter accepts one of the values from MyLocationTracking. */ @IntDef( {TRACKING_NONE, TRACKING_FOLLOW}) @Retention(RetentionPolicy.SOURCE) @@ -30,7 +30,7 @@ public class MyLocationTracking { public static final int TRACKING_NONE = 0x00000000; /** - * Tracking the location of the user, {@link MapView} will reposition to center of {@link MyLocationView} + * Tracking the location of the user. {@link MapView} will reposition to center of {@link MyLocationView} */ public static final int TRACKING_FOLLOW = 0x00000004; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java index 77d0929df3..31e6313509 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/Style.java @@ -19,7 +19,7 @@ public class Style { /** - * Indicates the parameter accepts one of the values from {@link Style}. Using one of these + * Indicates the parameter accepts one of the values from Style. Using one of these * constants means your map style will always use the latest version and may change as we * improve the style */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java index c4bdb4a17d..4e934fa3cc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationSource.java @@ -2,7 +2,7 @@ package com.mapbox.mapboxsdk.location; import android.content.Context; import android.location.Location; -import android.util.Log; +import android.support.annotation.NonNull; import com.mapbox.services.android.telemetry.location.LocationEngine; import com.mapbox.services.android.telemetry.location.LocationEngineListener; @@ -15,6 +15,8 @@ import com.mapzen.android.lost.api.LostApiClient; import java.lang.ref.WeakReference; +import timber.log.Timber; + /** * Manages locational updates. Contains methods to register and unregister location listeners. *