* 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-v10mapbox://styles/mapbox/light-v9mapbox://styles/mapbox/dark-v9mapbox://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-v9mapbox://styles/mapbox/satellite-v9mapbox://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-2dp1.5dp
- 7dp
+ @dimen/mapbox_two_dp
+ @dimen/mapbox_two_dp
+ @dimen/mapbox_two_dp
+ @dimen/mapbox_two_dp
+ 2dp
+ 4dp8dp10dp16dp
- 76dp
+ 95dp18dp
--
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 @@
8dp10dp16dp
- 95dp
+ 92dp18dp
--
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.
*
@@ -33,8 +35,6 @@ import java.lang.ref.WeakReference;
public class LocationSource extends LocationEngine implements
LostApiClient.ConnectionCallbacks, LocationListener {
- private static final String LOG_TAG = LocationSource.class.getSimpleName();
-
private static LocationEngine instance;
private WeakReference context;
@@ -48,7 +48,13 @@ public class LocationSource extends LocationEngine implements
.build();
}
- public static synchronized LocationEngine getLocationEngine(Context context) {
+ /**
+ * Get the LocationEngine instance.
+ *
+ * @param context a Context from which the application context is derived
+ * @return the LocationEngine instance
+ */
+ public static synchronized LocationEngine getLocationEngine(@NonNull Context context) {
if (instance == null) {
instance = new LocationSource(context.getApplicationContext());
}
@@ -56,6 +62,10 @@ public class LocationSource extends LocationEngine implements
return instance;
}
+ /**
+ * Activate the location engine which will connect whichever location provider you are using. You'll need to call
+ * this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
+ */
@Override
public void activate() {
if (lostApiClient != null && !lostApiClient.isConnected()) {
@@ -63,6 +73,11 @@ public class LocationSource extends LocationEngine implements
}
}
+ /**
+ * Disconnect the location engine which is useful when you no longer need location updates or requesting the users
+ * {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates
+ * using {@link LocationEngine#removeLocationUpdates()}.
+ */
@Override
public void deactivate() {
if (lostApiClient != null && lostApiClient.isConnected()) {
@@ -70,11 +85,20 @@ public class LocationSource extends LocationEngine implements
}
}
+ /**
+ * Check if your location provider has been activated/connected. This is mainly used internally but is also useful in
+ * the rare case when you'd like to know if your location engine is connected or not.
+ *
+ * @return boolean true if the location engine has been activated/connected, else false.
+ */
@Override
public boolean isConnected() {
return lostApiClient.isConnected();
}
+ /**
+ * Invoked when the location provider has connected.
+ */
@Override
public void onConnected() {
for (LocationEngineListener listener : locationListeners) {
@@ -82,11 +106,19 @@ public class LocationSource extends LocationEngine implements
}
}
+ /**
+ * Invoked when the location provider connection has been suspended.
+ */
@Override
public void onConnectionSuspended() {
- Log.d(LOG_TAG, "Connection suspended.");
+ Timber.d("Connection suspended.");
}
+ /**
+ * Returns the Last known location is the location provider is connected and location permissions are granted.
+ *
+ * @return the last known location
+ */
@Override
public Location getLastLocation() {
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
@@ -97,6 +129,9 @@ public class LocationSource extends LocationEngine implements
return null;
}
+ /**
+ * Request location updates to the location provider.
+ */
@Override
public void requestLocationUpdates() {
// Common params
@@ -122,6 +157,9 @@ public class LocationSource extends LocationEngine implements
}
}
+ /**
+ * Dismiss ongoing location update to the location provider.
+ */
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
@@ -129,6 +167,11 @@ public class LocationSource extends LocationEngine implements
}
}
+ /**
+ * Invoked when the Location has changed.
+ *
+ * @param location the new location
+ */
@Override
public void onLocationChanged(Location location) {
for (LocationEngineListener listener : locationListeners) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/FocalPointChangeListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/FocalPointChangeListener.java
index 006122a4e2..aec9a848b7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/FocalPointChangeListener.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/FocalPointChangeListener.java
@@ -2,6 +2,9 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
+/**
+ * Interface definition of a callback that is invoked when the focal point will change.
+ */
public interface FocalPointChangeListener {
void onFocalPointChanged(PointF pointF);
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 0bfa74d1c0..0ba6c10831 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
@@ -1972,9 +1972,9 @@ 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 Replaced by {@link MapboxMap.OnCameraMoveStartedListener}, {@link MapboxMap.OnCameraMoveListener} and
+ * {@link 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 {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 225278b17d..95cb7d66c4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -46,7 +46,7 @@ public class OfflineManager {
/**
* This callback receives an asynchronous response containing a list of all
- * {@link OfflineRegion} in the database, or an error message otherwise.
+ * OfflineRegion in the database or an error message otherwise.
*/
public interface ListOfflineRegionsCallback {
/**
@@ -66,7 +66,7 @@ public class OfflineManager {
/**
* This callback receives an asynchronous response containing the newly created
- * {@link OfflineRegion} in the database, or an error message otherwise.
+ * OfflineRegion in the database or an error message otherwise.
*/
public interface CreateOfflineRegionCallback {
/**
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 44bb2a05ee..baa815491f 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
@@ -98,7 +98,7 @@ public class OfflineRegion {
}
/**
- * This callback receives an asynchronous response containing the {@link OfflineRegionStatus}
+ * This callback receives an asynchronous response containing the OfflineRegionStatus
* of the offline region, or a {@link String} error message otherwise.
*/
public interface OfflineRegionStatusCallback {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java
index af98a46a9b..eae83e8c1f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/Resource.java
@@ -5,9 +5,15 @@ import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+/**
+ * Resource provides access to resource types.
+ */
public final class Resource {
// Note: Keep this in sync with include/mbgl/storage/resource.hpp
+ /**
+ * Resource type variants.
+ */
@IntDef( {UNKNOWN, STYLE, SOURCE, TILE, GLYPHS, SPRITE_IMAGE, SPRITE_JSON})
@Retention(RetentionPolicy.SOURCE)
public @interface Kind {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java
index 8ded7ecd34..15e4474105 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/CompositeFunction.java
@@ -13,7 +13,7 @@ import com.mapbox.mapboxsdk.style.layers.PropertyValue;
import java.util.Map;
/**
- * Composite functions combine {@link android.graphics.Camera} and {@link SourceFunction}s.
+ * Composite functions combine Camera and SourceFunctions.
*
* Composite functions allow the appearance of a map feature to change with both its
* properties and zoom. Each stop is an array with two elements, the first is an object
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java
index 643a126388..4dbb461e4c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Filter.java
@@ -11,7 +11,7 @@ import java.util.Collections;
public class Filter {
/**
- * Base {@link Filter} statement. Subclassed to provide concrete statements.
+ * Base Filter statement. Subclassed to provide concrete statements.
*/
public abstract static class Statement {
protected final String operator;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
index a46c11b35c..6e6e4ca613 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java
@@ -1,23 +1,51 @@
package com.mapbox.mapboxsdk.style.layers;
+/**
+ * Resembles transition property from the style specification.
+ *
+ * @see Transition documentation
+ */
public class TransitionOptions {
private long duration;
private long delay;
+ /**
+ * Create a transition property based on duration and a delay.
+ *
+ * @param duration the duration of the transition
+ * @param delay the delay to start the transition
+ */
public TransitionOptions(long duration, long delay) {
this.duration = duration;
this.delay = delay;
}
+ /**
+ * Create a transition property based on duration and a delay.
+ *
+ * @param duration the duration of the transition
+ * @param delay the delay to start the transition
+ * @return a new transition property object
+ */
public static TransitionOptions fromTransitionOptions(long duration, long delay) {
return new TransitionOptions(duration, delay);
}
+ /**
+ * Get the transition duration.
+ *
+ * @return the transition duration
+ */
public long getDuration() {
return duration;
}
+ /**
+ * Get the transition delay.
+ *
+ * @return the transition delay
+ */
public long getDelay() {
return delay;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/package-info.java
new file mode 100644
index 0000000000..a613bf9587
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Contains the Mapbox Maps Android Style Light API classes.
+ */
+package com.mapbox.mapboxsdk.style.light;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AnimatorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AnimatorUtils.java
index 7694604d9f..34c52c829b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AnimatorUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/AnimatorUtils.java
@@ -10,13 +10,31 @@ import android.support.annotation.Nullable;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
+/**
+ * Animator utility class.
+ */
public class AnimatorUtils {
+ /**
+ * Animate a view from an animator resource.
+ *
+ * @param view the view to be animated
+ * @param animatorRes the animator resource to be loaded
+ * @param listener the animator end listener
+ */
public static void animate(@NonNull final View view, @AnimatorRes int animatorRes,
@Nullable OnAnimationEndListener listener) {
animate(view, animatorRes, -1, listener);
}
+ /**
+ * Animate a view from an animator resource.
+ *
+ * @param view the view to be animated
+ * @param animatorRes the animator resource to be loaded
+ * @param duration the duration of the animator
+ * @param listener the animator end listener
+ */
public static void animate(final View view, @AnimatorRes int animatorRes, int duration,
@Nullable final OnAnimationEndListener listener) {
if (view == null) {
@@ -43,14 +61,33 @@ public class AnimatorUtils {
animator.start();
}
+ /**
+ * Animate a view from an animator resource.
+ *
+ * @param view the view to be animated
+ * @param animatorRes the animator resource to be loaded
+ */
public static void animate(@NonNull final View view, @AnimatorRes int animatorRes) {
animate(view, animatorRes, -1);
}
+ /**
+ * Animate a view from an animator resource.
+ *
+ * @param view the view to be animated
+ * @param animatorRes the animator resource to be loaded
+ * @param duration the duration of the animator
+ */
public static void animate(@NonNull final View view, @AnimatorRes int animatorRes, int duration) {
animate(view, animatorRes, duration, null);
}
+ /**
+ * Animate a view rotation property to a value.
+ *
+ * @param view the view to be rotated
+ * @param rotation the value to animate to
+ */
public static void rotate(@NonNull final View view, float rotation) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(view, View.ROTATION, view.getRotation(), rotation);
@@ -64,6 +101,12 @@ public class AnimatorUtils {
rotateAnimator.start();
}
+ /**
+ * Animate a view rotation property by a value.
+ *
+ * @param view the view to be rotated
+ * @param rotationBy the value to animate by
+ */
public static void rotateBy(@NonNull final View view, float rotationBy) {
view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
view.animate().rotationBy(rotationBy).setInterpolator(new FastOutSlowInInterpolator()).setListener(
@@ -76,6 +119,13 @@ public class AnimatorUtils {
});
}
+ /**
+ * Animate a view alpha property to a value.
+ *
+ * @param convertView the view to be animated
+ * @param alpha the value to animate to
+ * @param listener the animator end listener
+ */
public static void alpha(@NonNull final View convertView, float alpha,
@Nullable final OnAnimationEndListener listener) {
convertView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
@@ -99,10 +149,19 @@ public class AnimatorUtils {
rotateAnimator.start();
}
+ /**
+ * Animate a view alpha property to a value.
+ *
+ * @param convertView the view to be animated
+ * @param alpha the value to animate to
+ */
public static void alpha(@NonNull final View convertView, float alpha) {
alpha(convertView, alpha, null);
}
+ /**
+ * An interface definition that is invoked when an animation ends.
+ */
public interface OnAnimationEndListener {
void onAnimationEnd();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
index 2da2472d69..24c76243d9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
@@ -17,6 +17,9 @@ import com.mapbox.mapboxsdk.exceptions.ConversionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+/**
+ * Color utility class.
+ */
public class ColorUtils {
/**
--
cgit v1.2.1
From b6a4f1212cbf7454134a1e3f367d2e47db305a15 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Wed, 31 May 2017 12:59:01 +0200
Subject: [android] fix missing access token variable issue (#9151)
---
.../MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
(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 f75d7ed90d..81134e9497 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
@@ -86,9 +86,7 @@ public final class Mapbox {
* @throws MapboxConfigurationException exception thrown when not using a valid accessToken
*/
private static void validateAccessToken() throws MapboxConfigurationException {
- String
-
- = INSTANCE.accessToken;
+ String accessToken = INSTANCE.accessToken;
if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")
&& !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) {
throw new MapboxConfigurationException();
--
cgit v1.2.1
From 52eba423aecca51dd65c15d2d3dbffe2f06856ba Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 1 Jun 2017 10:05:31 +0200
Subject: [android] Cherry picking 9133 (#9145)
* [android] Fix tracking mode + camera race condition (#9133)
* [android] fix tracking mode + camera race condition
* fix resetTrackingModesIfRequired bug (comparing current camera position with target camera position
* cherry pick #9133 and update CHANGELOG
* add null check to prevent null pointer exception
---
.../mapboxsdk/constants/MapboxConstants.java | 1 -
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 8 ++--
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 30 +++++++++++-
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 54 ++++++----------------
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 9 ++--
.../mapboxsdk/maps/widgets/MyLocationView.java | 49 ++------------------
6 files changed, 57 insertions(+), 94 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index 9adefa3221..ecb6ffe24e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -113,7 +113,6 @@ public class MapboxConstants {
public static final String STATE_MY_BEARING_TRACKING_MODE = "mapbox_myBearingTracking";
public static final String STATE_MY_LOCATION_TRACKING_DISMISS = "mapbox_myLocationTrackingDismiss";
public static final String STATE_MY_BEARING_TRACKING_DISMISS = "mapbox_myBearingTrackingDismiss";
- public static final String STATE_MY_TRACKING_MODE_DISMISS_FOR_CAMERA = "mapbox_myBearingTrackingDismiss";
public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled";
public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity";
public static final String STATE_COMPASS_MARGIN_LEFT = "mapbox_compassMarginLeft";
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 39433d8b93..e60f9b1d1e 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
@@ -357,7 +357,7 @@ final class MapGestureDetector {
return false;
}
- trackingSettings.resetTrackingModesIfRequired(true, false);
+ trackingSettings.resetTrackingModesIfRequired(true, false, false);
// cancel any animation
transform.cancelTransitions();
@@ -402,7 +402,7 @@ final class MapGestureDetector {
}
// reset tracking if needed
- trackingSettings.resetTrackingModesIfRequired(true, false);
+ trackingSettings.resetTrackingModesIfRequired(true, false, false);
// Scroll the map
transform.moveBy(-distanceX, -distanceY, 0 /*no duration*/);
@@ -484,7 +484,7 @@ final class MapGestureDetector {
// to be in the center of the map. Therefore the zoom will translate the map center, so tracking
// should be disabled.
- trackingSettings.resetTrackingModesIfRequired(!quickZoom, false);
+ trackingSettings.resetTrackingModesIfRequired(!quickZoom, false, false);
// Scale the map
if (focalPoint != null) {
// arround user provided focal point
@@ -568,7 +568,7 @@ final class MapGestureDetector {
}
// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
- trackingSettings.resetTrackingModesIfRequired(true, true);
+ trackingSettings.resetTrackingModesIfRequired(true, true, false);
// Get rotate value
double bearing = transform.getRawBearing();
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 0ba6c10831..7a62f06ad2 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
@@ -746,10 +746,38 @@ public final class MapboxMap {
@UiThread
public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
final MapboxMap.CancelableCallback callback) {
+ easeCamera(update, durationMs, easingInterpolator, callback, false);
+ }
+
+ /**
+ * Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
+ * unless specified within {@link CameraUpdate}. A callback can be used to be notified when
+ * easing the camera stops. If {@link #getCameraPosition()} is called during the animation, it
+ * will return the current location of the camera in flight.
+ *
+ * Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
+ * {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
+ * method and calling it with true in the {@link CancelableCallback#onFinish()}.
+ *
+ *
+ * @param update The change that should be applied to the camera.
+ * @param durationMs The duration of the animation in milliseconds. This must be strictly
+ * positive, otherwise an IllegalArgumentException will be thrown.
+ * @param easingInterpolator True for easing interpolator, false for linear.
+ * @param callback An optional callback to be notified from the main thread when the animation
+ * stops. If the animation stops due to its natural completion, the callback
+ * will be notified with onFinish(). If the animation stops due to interruption
+ * by a later camera movement or a user gesture, onCancel() will be called.
+ * Do not update or ease the camera from within onCancel().
+ * @param isDismissable true will allow animated camera changes dismiss a tracking mode.
+ */
+ @UiThread
+ public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
+ final MapboxMap.CancelableCallback callback, final boolean isDismissable) {
new Handler().post(new Runnable() {
@Override
public void run() {
- transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, callback);
+ transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, callback, isDismissable);
}
});
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 25b60aa72d..7dcd84de75 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -33,7 +33,6 @@ public final class TrackingSettings {
private boolean myLocationEnabled;
private boolean dismissLocationTrackingOnGesture = true;
private boolean dismissBearingTrackingOnGesture = true;
- private boolean isResetTrackingWithCameraPositionChange = true;
private MapboxMap.OnMyLocationTrackingModeChangeListener onMyLocationTrackingModeChangeListener;
private MapboxMap.OnMyBearingTrackingModeChangeListener onMyBearingTrackingModeChangeListener;
@@ -57,8 +56,6 @@ public final class TrackingSettings {
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, isDismissLocationTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, isDismissBearingTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
- outState.putBoolean(MapboxConstants.STATE_MY_TRACKING_MODE_DISMISS_FOR_CAMERA,
- isDismissTrackingModesForCameraPositionChange());
}
void onRestoreInstanceState(Bundle savedInstanceState) {
@@ -77,8 +74,6 @@ public final class TrackingSettings {
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
- setDismissTrackingModeForCameraPositionChange(savedInstanceState.getBoolean(
- MapboxConstants.STATE_MY_TRACKING_MODE_DISMISS_FOR_CAMERA, true));
}
/**
@@ -259,15 +254,16 @@ public final class TrackingSettings {
}
/**
- * Reset the tracking modes as necessary. Location tracking is reset if the map center is changed,
- * bearing tracking if there is a rotation.
+ * Reset the tracking modes as necessary. Location tracking is reset if the map center is changed and not from
+ * location, bearing tracking if there is a rotation.
*
- * @param translate true if translation
- * @param rotate true if rotation
+ * @param translate true if translation
+ * @param rotate true if rotation
+ * @param isFromLocation true if from location
*/
- void resetTrackingModesIfRequired(boolean translate, boolean rotate) {
+ void resetTrackingModesIfRequired(boolean translate, boolean rotate, boolean isFromLocation) {
// if tracking is on, and we should dismiss tracking with gestures, and this is a scroll action, turn tracking off
- if (translate && !isLocationTrackingDisabled() && isDismissLocationTrackingOnGesture()) {
+ if (translate && !isLocationTrackingDisabled() && isDismissLocationTrackingOnGesture() && !isFromLocation) {
setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
}
@@ -280,38 +276,18 @@ public final class TrackingSettings {
/**
* Reset the tracking modes as necessary. Animated camera position changes can reset the underlying tracking modes.
*
- * @param cameraPosition the changed camera position
+ * @param currentCameraPosition the current camera position
+ * @param targetCameraPosition the changed camera position
+ * @param isFromLocation true if from location
*/
- void resetTrackingModesIfRequired(CameraPosition cameraPosition) {
- if (isDismissTrackingModesForCameraPositionChange()) {
- resetTrackingModesIfRequired(cameraPosition.target != null, false);
+ void resetTrackingModesIfRequired(CameraPosition currentCameraPosition, CameraPosition targetCameraPosition,
+ boolean isFromLocation) {
+ if (currentCameraPosition.target != null) {
+ resetTrackingModesIfRequired(!currentCameraPosition.target.equals(targetCameraPosition.target), false,
+ isFromLocation);
}
}
- /**
- * Returns if a animation allows to dismiss a tracking mode.
- *
- * By default this is set to true.
- *
- *
- * @return True if camera animations will allow to dismiss a tracking mode
- */
- public boolean isDismissTrackingModesForCameraPositionChange() {
- return isResetTrackingWithCameraPositionChange;
- }
-
- /**
- * Sets a flag to allow animated camera position changes to dismiss a tracking mode.
- *
- *
- *
- *
- * @param willAllowToDismiss True will allow animated camera changes dismiss a trackig mode
- */
- public void setDismissTrackingModeForCameraPositionChange(boolean willAllowToDismiss) {
- isResetTrackingWithCameraPositionChange = willAllowToDismiss;
- }
-
Location getMyLocation() {
return myLocationView.getLocation();
}
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 af44a08a81..7f44e0de07 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
@@ -94,7 +94,7 @@ final class Transform implements MapView.OnMapChangedListener {
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
- trackingSettings.resetTrackingModesIfRequired(cameraPosition);
+ trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
@@ -107,10 +107,10 @@ final class Transform implements MapView.OnMapChangedListener {
@UiThread
final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator,
- final MapboxMap.CancelableCallback callback) {
+ final MapboxMap.CancelableCallback callback, boolean isDismissable) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
- trackingSettings.resetTrackingModesIfRequired(cameraPosition);
+ trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, isDismissable);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
@@ -118,7 +118,6 @@ final class Transform implements MapView.OnMapChangedListener {
cameraCancelableCallback = callback;
mapView.addOnMapChangedListener(this);
}
-
mapView.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom, easingInterpolator);
}
@@ -129,7 +128,7 @@ final class Transform implements MapView.OnMapChangedListener {
final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (!cameraPosition.equals(this.cameraPosition)) {
- trackingSettings.resetTrackingModesIfRequired(cameraPosition);
+ trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
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 338d29c87c..f5ef46a5d3 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
@@ -485,19 +485,8 @@ public class MyLocationView extends View {
if (location != null) {
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
// center map directly
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(location)), 0, false /*linear interpolator*/,
- new MapboxMap.CancelableCallback() {
- @Override
- public void onCancel() {
-
- }
-
- @Override
- public void onFinish() {
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
- }
- });
+ null, true);
} else {
// do not use interpolated location from tracking mode
latLng = null;
@@ -663,19 +652,8 @@ public class MyLocationView extends View {
private void rotateCamera(float rotation) {
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.bearing(rotation);
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS,
- false /*linear interpolator*/, new MapboxMap.CancelableCallback() {
- @Override
- public void onCancel() {
-
- }
-
- @Override
- public void onFinish() {
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
- }
- });
+ false /*linear interpolator*/, null);
}
@Override
@@ -750,7 +728,7 @@ public class MyLocationView extends View {
abstract void invalidate();
}
- private class MyLocationTrackingBehavior extends MyLocationBehavior implements MapboxMap.CancelableCallback {
+ private class MyLocationTrackingBehavior extends MyLocationBehavior {
@Override
void updateLatLng(@NonNull Location location) {
@@ -789,10 +767,9 @@ public class MyLocationView extends View {
// accuracy
updateAccuracy(location);
- // disable dismiss of tracking settings, enabled in #onFinish
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
// ease to new camera position with a linear interpolator
- mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, this);
+ mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
+ true);
}
@Override
@@ -803,22 +780,6 @@ public class MyLocationView extends View {
screenLocation = new PointF(x, y);
MyLocationView.this.invalidate();
}
-
- @Override
- public void onCancel() {
- //no op
- }
-
- @Override
- public void onFinish() {
- // Posting to end message queue to avoid race condition #8560
- post(new Runnable() {
- @Override
- public void run() {
- mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
- }
- });
- }
}
private class MyLocationShowBehavior extends MyLocationBehavior {
--
cgit v1.2.1
From da532007043b1827e83686faca0de2a45c4ef730 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 2 Jun 2017 12:39:35 +0200
Subject: [android] - validate if gestures should execute (#9173)
---
.../com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 e60f9b1d1e..33e13c5ecc 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
@@ -383,6 +383,14 @@ final class MapGestureDetector {
// Called for drags
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
+ if (!trackingSettings.isScrollGestureCurrentlyEnabled()) {
+ return false;
+ }
+
+ if (dragStarted) {
+ return false;
+ }
+
if (!scrollInProgress) {
scrollInProgress = true;
@@ -393,13 +401,6 @@ final class MapGestureDetector {
getLocationFromGesture(e1.getX(), e1.getY()),
MapboxEvent.GESTURE_PAN_START, transform));
}
- if (!trackingSettings.isScrollGestureCurrentlyEnabled()) {
- return false;
- }
-
- if (dragStarted) {
- return false;
- }
// reset tracking if needed
trackingSettings.resetTrackingModesIfRequired(true, false, false);
--
cgit v1.2.1
From ef7b3552b52002c153a0b93a87d27f8b5d378f4f Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 6 Jun 2017 12:13:56 +0200
Subject: [android] - only invoke callback if fling scrolling animation isn't
going to be ignored. (#9192)
---
.../main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 3 ++-
.../src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | 7 +++----
2 files changed, 5 insertions(+), 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 33e13c5ecc..5346baa4e2 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
@@ -346,7 +346,6 @@ final class MapGestureDetector {
// and ignore when a scale gesture has occurred
return false;
}
- cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
float screenDensity = uiSettings.getPixelRatio();
@@ -362,6 +361,8 @@ final class MapGestureDetector {
// cancel any animation
transform.cancelTransitions();
+ cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+
// tilt results in a bigger translation, limiting input for #5281
double tilt = transform.getTilt();
double tiltFactor = 1 + ((tilt != 0) ? (tilt / 10) : 0); /* 1 -> 7 */
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 7f44e0de07..9a8997014a 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
@@ -79,7 +79,7 @@ final class Transform implements MapView.OnMapChangedListener {
@Override
public void onMapChanged(@MapView.MapChange int change) {
- if (change == REGION_DID_CHANGE_ANIMATED && cameraCancelableCallback != null) {
+ if (change == REGION_DID_CHANGE_ANIMATED) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
cameraCancelableCallback.onFinish();
@@ -116,8 +116,8 @@ final class Transform implements MapView.OnMapChangedListener {
if (callback != null) {
cameraCancelableCallback = callback;
- mapView.addOnMapChangedListener(this);
}
+ mapView.addOnMapChangedListener(this);
mapView.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom, easingInterpolator);
}
@@ -134,9 +134,8 @@ final class Transform implements MapView.OnMapChangedListener {
if (callback != null) {
cameraCancelableCallback = callback;
- mapView.addOnMapChangedListener(this);
}
-
+ mapView.addOnMapChangedListener(this);
mapView.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom);
}
--
cgit v1.2.1
From a1f8de66794f665b69c35ed163b3e554dc5db348 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Tue, 6 Jun 2017 12:15:21 +0200
Subject: [android] - dealing with infinite camera move callbacks (#9177)
(#9194)
---
.../main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 6 ++++++
1 file changed, 6 insertions(+)
(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 f5ef46a5d3..098f006f6c 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
@@ -701,6 +701,12 @@ public class MyLocationView extends View {
private abstract class MyLocationBehavior {
+ MyLocationBehavior() {
+ if (latLng != null) {
+ locationUpdateTimestamp = SystemClock.elapsedRealtime();
+ }
+ }
+
void updateLatLng(@NonNull Location newLocation) {
location = newLocation;
}
--
cgit v1.2.1
From 45327b6ac46f8b574a767e20ee6a18ab23936db6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Tue, 6 Jun 2017 21:09:20 +0200
Subject: [android] - keep location tracking mode after screen rotation (#9187)
* [android] - keep location tracking mode after screen rotation (#9186)
* [android] - using easeCamera to keep location tracking instead of overloaded moveCamera (#9187)
* [android] - checkstyle fix up
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 7a62f06ad2..8e50adb777 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
@@ -141,12 +141,20 @@ public final class MapboxMap {
*/
void onRestoreInstanceState(Bundle savedInstanceState) {
final CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION);
- if (cameraPosition != null) {
- moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(cameraPosition).build()));
- }
uiSettings.onRestoreInstanceState(savedInstanceState);
trackingSettings.onRestoreInstanceState(savedInstanceState);
+
+ if (cameraPosition != null) {
+ easeCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder(cameraPosition).build()),
+ 0,
+ false,
+ null,
+ !trackingSettings.isLocationTrackingDisabled()
+ );
+ }
+
nativeMapView.setDebug(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
final String styleUrl = savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL);
--
cgit v1.2.1
From ae837f4db242c074206aeb2c214b4418fcfed0c0 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 7 Jun 2017 12:41:30 +0200
Subject: [android] - remove conversion from pixels to dp (#9205)
---
.../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 63f2e653cc..a31babc1c5 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()) / pixelRatio;
+ return nativeGetMetersPerPixelAtLatitude(lat, getZoom());
}
public ProjectedMeters projectedMetersForLatLng(LatLng latLng) {
--
cgit v1.2.1
From 78eca869ae239b9686a885be6492196f6b0ae48a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Wed, 7 Jun 2017 18:02:28 +0200
Subject: [android] - option to disable camera animation while following
position (#9210)
---
.../mapboxsdk/constants/MapboxConstants.java | 1 +
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 25 ++++++++++++++++++++++
.../mapboxsdk/maps/widgets/MyLocationView.java | 22 +++++++++++++++----
3 files changed, 44 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index ecb6ffe24e..0396defe74 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -133,5 +133,6 @@ public class MapboxConstants {
public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "mapbox_attrMarginRight";
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom";
public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled";
+ public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled";
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 7dcd84de75..2e12de8dec 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -29,6 +29,7 @@ public final class TrackingSettings {
private final CameraZoomInvalidator zoomInvalidator;
private LocationEngine locationSource;
private LocationEngineListener myLocationListener;
+ private boolean locationChangeAnimationEnabled = true;
private boolean myLocationEnabled;
private boolean dismissLocationTrackingOnGesture = true;
@@ -56,6 +57,7 @@ public final class TrackingSettings {
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, isDismissLocationTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, isDismissBearingTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
+ outState.putBoolean(MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, isLocationChangeAnimationEnabled());
}
void onRestoreInstanceState(Bundle savedInstanceState) {
@@ -74,6 +76,8 @@ public final class TrackingSettings {
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
+ setLocationChangeAnimationEnabled(savedInstanceState.getBoolean(
+ MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, true));
}
/**
@@ -91,6 +95,7 @@ public final class TrackingSettings {
*/
@UiThread
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
+ myLocationView.setLocationChangeAnimationEnabled(isLocationChangeAnimationEnabled());
myLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
@@ -253,6 +258,26 @@ public final class TrackingSettings {
|| myLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE);
}
+ /**
+ * Returns whether location change animation is applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
+ *
+ * @return True if animation is applied, false otherwise.
+ */
+ public boolean isLocationChangeAnimationEnabled() {
+ return locationChangeAnimationEnabled;
+ }
+
+ /**
+ * Set whether location change animation should be applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
+ *
+ * @param locationChangeAnimationEnabled True if animation should be applied, false otherwise.
+ */
+ public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
+ this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
+
+ myLocationView.setLocationChangeAnimationEnabled(locationChangeAnimationEnabled);
+ }
+
/**
* Reset the tracking modes as necessary. Location tracking is reset if the map center is changed and not from
* location, bearing tracking if there is a rotation.
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 098f006f6c..afed8635a9 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
@@ -68,6 +68,7 @@ public class MyLocationView extends View {
private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
private ValueAnimator directionAnimator;
+ private boolean locationChangeAnimationEnabled;
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
new ValueAnimator.AnimatorUpdateListener() {
@@ -462,6 +463,10 @@ public class MyLocationView extends View {
myLocationBehavior.updateLatLng(location);
}
+ public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
+ this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
+ }
+
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
this.myBearingTrackingMode = myBearingTrackingMode;
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
@@ -773,9 +778,14 @@ public class MyLocationView extends View {
// accuracy
updateAccuracy(location);
- // ease to new camera position with a linear interpolator
- mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
- true);
+ if (locationChangeAnimationEnabled) {
+ // ease to new camera position with a linear interpolator
+ mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
+ true);
+ } else {
+ mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), 0, false, null,
+ true);
+ }
}
@Override
@@ -817,7 +827,11 @@ public class MyLocationView extends View {
}
locationChangeAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
- locationChangeAnimator.setDuration(locationUpdateDuration);
+ if (locationChangeAnimationEnabled) {
+ locationChangeAnimator.setDuration(locationUpdateDuration);
+ } else {
+ locationChangeAnimator.setDuration(0);
+ }
locationChangeAnimator.addUpdateListener(new MarkerCoordinateAnimatorListener(this,
latLng, newLocation
));
--
cgit v1.2.1
From 233117fe5797f7f0dabddbee780b31a624053b68 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 8 Jun 2017 08:44:29 +0200
Subject: [android] - invalidating MyLocationView bearing when not following
position (#9212)
---
.../main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 5 +++++
1 file changed, 5 insertions(+)
(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 afed8635a9..f648db413d 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
@@ -461,6 +461,11 @@ public class MyLocationView extends View {
this.location = location;
myLocationBehavior.updateLatLng(location);
+
+ if (mapboxMap != null && myBearingTrackingMode == MyBearingTracking.GPS
+ && myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
+ setBearing(mapboxMap.getCameraPosition().bearing);
+ }
}
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
--
cgit v1.2.1
From 9f88e373665124464351424e1efc95fe3a1fc05d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 9 Jun 2017 10:00:00 +0200
Subject: Custom location source fix (#9142)
* [android] - custom location engine fixes (#9139)
* Update to latest LOST dependency, fixup internal location source integration
---
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 12 +++--
.../mapboxsdk/constants/MapboxConstants.java | 2 +-
.../mapbox/mapboxsdk/location/LocationSource.java | 40 ++++-----------
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 3 --
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 31 ++++++++++--
.../mapboxsdk/maps/widgets/MyLocationView.java | 58 +++++++++++++++-------
6 files changed, 87 insertions(+), 59 deletions(-)
(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 81134e9497..17cd4e0dce 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
@@ -30,6 +30,7 @@ public final class Mapbox {
private Context context;
private String accessToken;
private Boolean connected;
+ private LocationSource locationSource;
/**
* Get an instance of Mapbox.
@@ -45,8 +46,8 @@ public final class Mapbox {
public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull String accessToken) {
if (INSTANCE == null) {
Context appContext = context.getApplicationContext();
- INSTANCE = new Mapbox(appContext, accessToken);
- LocationEngine locationEngine = LocationSource.getLocationEngine(appContext);
+ INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext));
+ LocationEngine locationEngine = new LocationSource(appContext);
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
MapboxTelemetry.getInstance().initialize(
appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
@@ -55,9 +56,10 @@ public final class Mapbox {
return INSTANCE;
}
- Mapbox(@NonNull Context context, @NonNull String accessToken) {
+ Mapbox(@NonNull Context context, @NonNull String accessToken, LocationSource locationSource) {
this.context = context;
this.accessToken = accessToken;
+ this.locationSource = locationSource;
}
/**
@@ -128,4 +130,8 @@ public final class Mapbox {
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return (activeNetwork != null && activeNetwork.isConnected());
}
+
+ public static LocationSource getLocationSource() {
+ return INSTANCE.locationSource;
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index 0396defe74..1ee59057d2 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -134,5 +134,5 @@ public class MapboxConstants {
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom";
public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled";
public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled";
-
+ public static final String STATE_USING_CUSTOM_LOCATION_SOURCE = "mapbox_usingCustomLocationSource";
}
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 4e934fa3cc..8416bd5b6c 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.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
@@ -13,10 +13,6 @@ import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LocationServices;
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.
*
@@ -35,40 +31,24 @@ import timber.log.Timber;
public class LocationSource extends LocationEngine implements
LostApiClient.ConnectionCallbacks, LocationListener {
- private static LocationEngine instance;
-
- private WeakReference context;
+ private Context context;
private LostApiClient lostApiClient;
- private LocationSource(Context context) {
+ public LocationSource(Context context) {
super();
- this.context = new WeakReference<>(context);
- lostApiClient = new LostApiClient.Builder(this.context.get())
+ this.context = context.getApplicationContext();
+ lostApiClient = new LostApiClient.Builder(this.context)
.addConnectionCallbacks(this)
.build();
}
- /**
- * Get the LocationEngine instance.
- *
- * @param context a Context from which the application context is derived
- * @return the LocationEngine instance
- */
- public static synchronized LocationEngine getLocationEngine(@NonNull Context context) {
- if (instance == null) {
- instance = new LocationSource(context.getApplicationContext());
- }
-
- return instance;
- }
-
/**
* Activate the location engine which will connect whichever location provider you are using. You'll need to call
* this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
*/
@Override
public void activate() {
- if (lostApiClient != null && !lostApiClient.isConnected()) {
+ if (!lostApiClient.isConnected()) {
lostApiClient.connect();
}
}
@@ -80,7 +60,7 @@ public class LocationSource extends LocationEngine implements
*/
@Override
public void deactivate() {
- if (lostApiClient != null && lostApiClient.isConnected()) {
+ if (lostApiClient.isConnected()) {
lostApiClient.disconnect();
}
}
@@ -111,7 +91,6 @@ public class LocationSource extends LocationEngine implements
*/
@Override
public void onConnectionSuspended() {
- Timber.d("Connection suspended.");
}
/**
@@ -120,8 +99,9 @@ public class LocationSource extends LocationEngine implements
* @return the last known location
*/
@Override
+ @Nullable
public Location getLastLocation() {
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
+ if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
}
@@ -151,7 +131,7 @@ public class LocationSource extends LocationEngine implements
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context.get())) {
+ if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
}
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 8e50adb777..8a708cb186 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
@@ -37,7 +37,6 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-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;
@@ -1872,8 +1871,6 @@ public final class MapboxMap {
* Replaces the location source of the my-location layer.
*
* @param locationSource A {@link LocationEngine} location source to use in the my-location layer.
- * Set to null to use the default {@link LocationSource}
- * location source.
*/
@UiThread
public void setLocationSource(@Nullable LocationEngine locationSource) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 2e12de8dec..bd0bf7c83b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -6,11 +6,11 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
+import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
-import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
@@ -30,6 +30,7 @@ public final class TrackingSettings {
private LocationEngine locationSource;
private LocationEngineListener myLocationListener;
private boolean locationChangeAnimationEnabled = true;
+ private boolean isCustomLocationSource;
private boolean myLocationEnabled;
private boolean dismissLocationTrackingOnGesture = true;
@@ -47,7 +48,7 @@ public final class TrackingSettings {
}
void initialise(MapboxMapOptions options) {
- locationSource = LocationSource.getLocationEngine(myLocationView.getContext());
+ locationSource = Mapbox.getLocationSource();
setMyLocationEnabled(options.getLocationEnabled());
}
@@ -58,11 +59,15 @@ public final class TrackingSettings {
outState.putBoolean(MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, isDismissBearingTrackingOnGesture());
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
outState.putBoolean(MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, isLocationChangeAnimationEnabled());
+ outState.putBoolean(MapboxConstants.STATE_USING_CUSTOM_LOCATION_SOURCE, isCustomLocationSource());
}
void onRestoreInstanceState(Bundle savedInstanceState) {
try {
- setMyLocationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED));
+ setMyLocationEnabled(
+ savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED),
+ savedInstanceState.getBoolean(MapboxConstants.STATE_USING_CUSTOM_LOCATION_SOURCE)
+ );
} catch (SecurityException ignore) {
// User did not accept location permissions
}
@@ -339,6 +344,10 @@ public final class TrackingSettings {
}
}
+ public boolean isCustomLocationSource() {
+ return isCustomLocationSource;
+ }
+
void setOnMyLocationTrackingModeChangeListener(MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
this.onMyLocationTrackingModeChangeListener = listener;
}
@@ -357,16 +366,30 @@ public final class TrackingSettings {
}
void setMyLocationEnabled(boolean locationEnabled) {
+ setMyLocationEnabled(locationEnabled, isCustomLocationSource());
+ }
+
+ private void setMyLocationEnabled(boolean locationEnabled, boolean isCustomLocationSource) {
if (!PermissionsManager.areLocationPermissionsGranted(myLocationView.getContext())) {
Timber.e("Could not activate user location tracking: "
+ "user did not accept the permission or permissions were not requested.");
return;
}
myLocationEnabled = locationEnabled;
- myLocationView.setEnabled(locationEnabled);
+ this.isCustomLocationSource = isCustomLocationSource;
+ myLocationView.setEnabled(locationEnabled, isCustomLocationSource);
}
void setLocationSource(LocationEngine locationSource) {
+ if (this.locationSource != null && this.locationSource.equals(locationSource)) {
+ // this source is already active
+ return;
+ }
+
+ this.isCustomLocationSource = locationSource != null;
+ if (locationSource == null) {
+ locationSource = Mapbox.getLocationSource();
+ }
this.locationSource = locationSource;
myLocationView.setLocationSource(locationSource);
}
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 f648db413d..9740679cf5 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
@@ -26,6 +26,7 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
+import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
@@ -40,6 +41,8 @@ import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import java.lang.ref.WeakReference;
+import timber.log.Timber;
+
/**
* UI element overlaid on a map to show the user's location.
*/
@@ -148,6 +151,10 @@ public class MyLocationView extends View {
compassListener = new CompassListener(context);
}
+ public void init(LocationSource locationSource) {
+ this.locationSource = locationSource;
+ }
+
public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
if (defaultDrawable == null) {
return;
@@ -391,9 +398,13 @@ public class MyLocationView extends View {
@Override
public void setEnabled(boolean enabled) {
+ setEnabled(enabled, false);
+ }
+
+ public void setEnabled(boolean enabled, boolean isCustomLocationSource) {
super.setEnabled(enabled);
setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
- toggleGps(enabled);
+ toggleGps(enabled, isCustomLocationSource);
}
@Override
@@ -414,22 +425,23 @@ public class MyLocationView extends View {
super.onRestoreInstanceState(state);
}
+ private void toggleGps(boolean enableGps) {
+ toggleGps(enableGps, mapboxMap != null && mapboxMap.getTrackingSettings().isCustomLocationSource());
+ }
+
/**
* Enabled / Disable GPS location updates along with updating the UI
*
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
*/
- private void toggleGps(boolean enableGps) {
- if (locationSource == null) {
- locationSource = LocationSource.getLocationEngine(this.getContext());
- }
-
+ private void toggleGps(boolean enableGps, boolean isCustomLocationSource) {
if (enableGps) {
- // Set an initial location if one available
- Location lastLocation = locationSource.getLastLocation();
-
- if (lastLocation != null) {
- setLocation(lastLocation);
+ if (locationSource == null) {
+ if (!isCustomLocationSource) {
+ locationSource = Mapbox.getLocationSource();
+ } else {
+ return;
+ }
}
if (userLocationListener == null) {
@@ -437,16 +449,18 @@ public class MyLocationView extends View {
}
locationSource.addLocationEngineListener(userLocationListener);
+ locationSource.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationSource.activate();
} else {
+ if (locationSource == null) {
+ return;
+ }
// Disable location and user dot
location = null;
- locationSource.removeLocationUpdates();
locationSource.removeLocationEngineListener(userLocationListener);
+ locationSource.removeLocationUpdates();
locationSource.deactivate();
}
-
- locationSource.setPriority(LocationEnginePriority.HIGH_ACCURACY);
}
public Location getLocation() {
@@ -564,7 +578,10 @@ public class MyLocationView extends View {
}
public void setLocationSource(LocationEngine locationSource) {
+ toggleGps(false);
this.locationSource = locationSource;
+ this.userLocationListener = null;
+ setEnabled(isEnabled(), locationSource != null);
}
private static class GpsLocationListener implements LocationEngineListener {
@@ -580,10 +597,12 @@ public class MyLocationView extends View {
@Override
public void onConnected() {
MyLocationView locationView = userLocationView.get();
- if (locationView != null) {
- LocationEngine locationEngine = locationSource.get();
- Location location = locationEngine.getLastLocation();
- locationView.setLocation(location);
+ LocationEngine locationEngine = locationSource.get();
+ if (locationView != null && locationEngine != null) {
+ Location lastKnownLocation = locationEngine.getLastLocation();
+ if (lastKnownLocation != null) {
+ locationView.setLocation(lastKnownLocation);
+ }
locationEngine.requestLocationUpdates();
}
}
@@ -627,6 +646,9 @@ public class MyLocationView extends View {
}
public boolean isSensorAvailable() {
+ if (rotationVectorSensor == null) {
+ Timber.e("Sensor.TYPE_ROTATION_VECTOR is missing from this device. Unable to use MyBearingTracking.COMPASS.");
+ }
return rotationVectorSensor != null;
}
--
cgit v1.2.1
From fa972fad60e58e5b8f9f9622f508e9732c8c9ffd Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 9 Jun 2017 11:11:33 +0200
Subject: [android] - update components with camera values when animating
(#9174)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/Transform.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/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
index 9a8997014a..505e440dcb 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
@@ -150,6 +150,10 @@ final class Transform implements MapView.OnMapChangedListener {
cameraChangeDispatcher.onCameraMove();
}
+ if (isComponentUpdateRequired(cameraPosition)) {
+ updateCameraPosition(cameraPosition);
+ }
+
this.cameraPosition = cameraPosition;
if (onCameraChangeListener != null) {
onCameraChangeListener.onCameraChange(this.cameraPosition);
@@ -158,6 +162,11 @@ final class Transform implements MapView.OnMapChangedListener {
return cameraPosition;
}
+ private boolean isComponentUpdateRequired(@NonNull CameraPosition cameraPosition) {
+ return this.cameraPosition != null && (this.cameraPosition.tilt != cameraPosition.tilt
+ || this.cameraPosition.bearing != cameraPosition.bearing);
+ }
+
void cancelTransitions() {
// notify user about cancel
cameraChangeDispatcher.onCameraMoveCanceled();
--
cgit v1.2.1
From 6ec5e4f8cdb98227db11e5989376c31832ca2048 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 9 Jun 2017 12:05:54 +0200
Subject: Cherry picks to release branch (#9230)
* [ios][macos] test remove source in use
* [android] test remove source in use
* [core] check source usage before remove
* [core] ensure layer::accept works with non-void return values on gcc
* [android] - remove upgrade runtime exceptions (#9191)
---
.../main/java/com/mapbox/mapboxsdk/maps/MapView.java | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 d00da4c155..9a1f2fc515 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
@@ -67,8 +67,6 @@ public class MapView extends FrameLayout {
private MapboxMap mapboxMap;
private MapCallback mapCallback;
- private boolean onStartCalled;
- private boolean onStopCalled;
private MapGestureDetector mapGestureDetector;
private MapKeyListener mapKeyListener;
@@ -233,7 +231,6 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onStart() {
- onStartCalled = true;
mapboxMap.onStart();
ConnectivityReceiver.instance(getContext()).activate();
}
@@ -243,11 +240,7 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onResume() {
- if (!onStartCalled) {
- // TODO: 26/10/16, can be removed after 5.0.0 release
- throw new IllegalStateException("MapView#onStart() was not called. "
- + "You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}.");
- }
+ // replaced by onStart in v5.0.0
}
/**
@@ -255,7 +248,7 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onPause() {
- // replaced by onStop in v5.0.0, keep around for future development
+ // replaced by onStop in v5.0.0
}
/**
@@ -263,7 +256,6 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onStop() {
- onStopCalled = true;
mapboxMap.onStop();
ConnectivityReceiver.instance(getContext()).deactivate();
}
@@ -273,12 +265,6 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onDestroy() {
- if (!onStopCalled) {
- // TODO: 26/10/16, can be removed after 5.0.0 release
- throw new IllegalStateException("MapView#onStop() was not called. "
- + "You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.");
- }
-
destroyed = true;
nativeMapView.terminateContext();
nativeMapView.terminateDisplay();
--
cgit v1.2.1
From 0c275ad6fa8d2c1e2523b6df7696d6fb09587411 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 13 Jun 2017 12:43:48 +0200
Subject: [android] - correct source changed map event javadoc (#9243)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.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/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 9a1f2fc515..098c701e03 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
@@ -774,7 +774,7 @@ public class MapView extends FrameLayout {
public static final int DID_FINISH_LOADING_STYLE = 14;
/**
- * This {@link MapChange} is triggered when a source attribution changes.
+ * This {@link MapChange} is triggered when a source changes.
*
* Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
*
--
cgit v1.2.1
From 7bfcce02662a9c429c3ac715728de63e2850231e Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 14 Jun 2017 14:34:03 +0200
Subject: Cherry pick release (#9263)
* [core] - bump earcut version dependency to handle unused lamba warning (#9242)
* [android] - snapshot bitmap contains view based content (#9252)
---
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 16 ++++++++---
.../com/mapbox/mapboxsdk/utils/BitmapUtils.java | 33 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 4 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
(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 a31babc1c5..af3b57151d 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
@@ -29,6 +29,7 @@ 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.mapboxsdk.utils.BitmapUtils;
import com.mapbox.services.commons.geojson.Feature;
import java.nio.ByteBuffer;
@@ -39,7 +40,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import timber.log.Timber;
-
// Class that wraps the native methods for convenience
final class NativeMapView {
@@ -920,12 +920,20 @@ final class NativeMapView {
}
protected void onFpsChanged(double fps) {
+ if (isDestroyedOn("OnFpsChanged")) {
+ return;
+ }
mapView.onFpsChanged(fps);
}
- protected void onSnapshotReady(Bitmap bitmap) {
- if (snapshotReadyCallback != null && bitmap != null) {
- snapshotReadyCallback.onSnapshotReady(bitmap);
+ protected void onSnapshotReady(Bitmap mapContent) {
+ if (isDestroyedOn("OnSnapshotReady")) {
+ return;
+ }
+
+ Bitmap viewContent = BitmapUtils.createBitmapFromView(mapView);
+ if (snapshotReadyCallback != null && mapContent != null && viewContent != null) {
+ snapshotReadyCallback.onSnapshotReady(BitmapUtils.mergeBitmap(mapContent, viewContent));
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
new file mode 100644
index 0000000000..e3fc765734
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
@@ -0,0 +1,33 @@
+package com.mapbox.mapboxsdk.utils;
+
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.support.annotation.NonNull;
+import android.view.View;
+
+public class BitmapUtils {
+
+ public static Bitmap createBitmapFromView(@NonNull View view) {
+ view.setDrawingCacheEnabled(true);
+ view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
+ view.buildDrawingCache();
+
+ if (view.getDrawingCache() == null) {
+ return null;
+ }
+
+ Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
+ view.setDrawingCacheEnabled(false);
+ view.destroyDrawingCache();
+ return snapshot;
+ }
+
+ public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) {
+ Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());
+ Canvas canvas = new Canvas(result);
+ canvas.drawBitmap(background, 0f, 0f, null);
+ canvas.drawBitmap(foreground, 10, 10, null);
+ return result;
+ }
+
+}
--
cgit v1.2.1
From 399c0071f856ad162905f32aa6516516ee59c7b1 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 20 Jun 2017 09:17:09 +0200
Subject: Validate camera position before transforming (#9275)
* [android] - add camera position validation before transforming
* annotate CameraUpdate with nullability
---
.../main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java | 2 ++
.../src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | 10 +++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
index 7e0dbf08fb..498aa8343b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.camera;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.maps.MapboxMap;
@@ -9,6 +10,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
*/
public interface CameraUpdate {
+ @Nullable
CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);
}
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 505e440dcb..89fbb79504 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
@@ -93,7 +93,7 @@ final class Transform implements MapView.OnMapChangedListener {
@UiThread
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
- if (!cameraPosition.equals(this.cameraPosition)) {
+ if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
@@ -109,7 +109,7 @@ final class Transform implements MapView.OnMapChangedListener {
final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator,
final MapboxMap.CancelableCallback callback, boolean isDismissable) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
- if (!cameraPosition.equals(this.cameraPosition)) {
+ if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, isDismissable);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
@@ -127,7 +127,7 @@ final class Transform implements MapView.OnMapChangedListener {
final void animateCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs,
final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
- if (!cameraPosition.equals(this.cameraPosition)) {
+ if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
@@ -141,6 +141,10 @@ final class Transform implements MapView.OnMapChangedListener {
}
}
+ private boolean isValidCameraPosition(@Nullable CameraPosition cameraPosition) {
+ return cameraPosition != null && !cameraPosition.equals(this.cameraPosition);
+ }
+
@UiThread
@Nullable
CameraPosition invalidateCameraPosition() {
--
cgit v1.2.1
From 20cb791b4ca1b449157d8ea02f256807dd7bc9f3 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Tue, 20 Jun 2017 09:24:07 +0200
Subject: [android] fix custom marker views anchor issue (#9282)
---
.../mapboxsdk/annotations/MarkerViewManager.java | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index bb51f3bfc2..b9e9bea4ed 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -10,6 +10,7 @@ import android.support.v4.util.LongSparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.widget.ImageView;
import com.mapbox.mapboxsdk.R;
@@ -33,6 +34,15 @@ import java.util.Map;
public class MarkerViewManager implements MapView.OnMapChangedListener {
private final ViewGroup markerViewContainer;
+ private final ViewTreeObserver.OnPreDrawListener markerViewPreDrawObserver =
+ new ViewTreeObserver.OnPreDrawListener() {
+ @Override
+ public boolean onPreDraw() {
+ invalidateViewMarkersInVisibleRegion();
+ markerViewContainer.getViewTreeObserver().removeOnPreDrawListener(markerViewPreDrawObserver);
+ return false;
+ }
+ };
private final Map markerViewMap = new HashMap<>();
private final LongSparseArray markerViewAddedListenerMap = new LongSparseArray<>();
private final List markerViewAdapters = new ArrayList<>();
@@ -180,14 +190,16 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
// ensure view is measured first
+ // #6805 invalidate marker views to ensure convertView width and height
+ // values are properly measured and up to date
if (marker.getWidth() == 0) {
- convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
- if (convertView.getMeasuredWidth() != 0) {
- marker.setWidth(convertView.getMeasuredWidth());
- marker.setHeight(convertView.getMeasuredHeight());
- }
+ convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver);
}
}
+
+ marker.setWidth(convertView.getWidth());
+ marker.setHeight(convertView.getHeight());
+
if (marker.getWidth() != 0) {
int x = (int) (marker.getAnchorU() * marker.getWidth());
int y = (int) (marker.getAnchorV() * marker.getHeight());
--
cgit v1.2.1
From 78426f1423ad3b739d7f7fa1fd7f248146281fa2 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Tue, 20 Jun 2017 10:01:02 +0200
Subject: fix trackball long press timeout calling the main thread method on a
background thread (#9305)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapKeyListener.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapKeyListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapKeyListener.java
index 7175242282..d1f01a30f7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapKeyListener.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapKeyListener.java
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.graphics.PointF;
import android.os.Handler;
+import android.os.Looper;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -204,7 +205,7 @@ final class MapKeyListener {
currentTrackballLongPressTimeOut = null;
}
currentTrackballLongPressTimeOut = new TrackballLongPressTimeOut();
- new Handler().postDelayed(currentTrackballLongPressTimeOut,
+ new Handler(Looper.getMainLooper()).postDelayed(currentTrackballLongPressTimeOut,
ViewConfiguration.getLongPressTimeout());
return true;
--
cgit v1.2.1
From a9f52e24e63af6d322b3f4744a38aab395344b1d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 20 Jun 2017 15:48:24 +0200
Subject: Revisit Javadoc for 5.1.0 (#9266)
* [android] - revisit public API javadoc
* [android] fix javadoc minor mistakes and typos
* grammar tweak
* add missing public javadoc
---
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 7 +-
.../mapbox/mapboxsdk/annotations/BubbleLayout.java | 106 +++++++++++++++
.../mapbox/mapboxsdk/annotations/IconFactory.java | 46 ++++---
.../mapboxsdk/annotations/MarkerViewManager.java | 19 ++-
.../mapbox/mapboxsdk/camera/CameraPosition.java | 60 +++++----
.../com/mapbox/mapboxsdk/camera/CameraUpdate.java | 8 +-
.../mapboxsdk/camera/CameraUpdateFactory.java | 4 +-
.../mapboxsdk/constants/MyBearingTracking.java | 14 +-
.../mapboxsdk/constants/MyLocationTracking.java | 19 ++-
.../java/com/mapbox/mapboxsdk/constants/Style.java | 1 -
.../exceptions/IconBitmapChangedException.java | 6 +-
.../exceptions/InvalidLatLngBoundsException.java | 4 +-
.../exceptions/InvalidMarkerPositionException.java | 3 +
.../exceptions/MapboxConfigurationException.java | 4 +
.../exceptions/TooManyIconsException.java | 5 +-
.../com/mapbox/mapboxsdk/geometry/ILatLng.java | 18 ++-
.../mapboxsdk/geometry/IProjectedMeters.java | 12 ++
.../java/com/mapbox/mapboxsdk/geometry/LatLng.java | 116 ++++++++++++++--
.../mapbox/mapboxsdk/geometry/LatLngBounds.java | 148 +++++++++++++-------
.../com/mapbox/mapboxsdk/geometry/LatLngSpan.java | 46 ++++++-
.../mapbox/mapboxsdk/geometry/ProjectedMeters.java | 45 ++++++-
.../mapbox/mapboxsdk/geometry/VisibleRegion.java | 31 ++++-
.../mapbox/mapboxsdk/location/LocationSource.java | 8 +-
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 30 ++---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 30 +++--
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 6 +-
.../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 12 +-
.../mapboxsdk/maps/widgets/MyLocationView.java | 150 ++++++++++++++++++++-
.../maps/widgets/MyLocationViewSettings.java | 7 +-
.../mapbox/mapboxsdk/net/ConnectivityReceiver.java | 7 +-
.../mapbox/mapboxsdk/offline/OfflineManager.java | 6 +
.../mapbox/mapboxsdk/offline/OfflineRegion.java | 1 +
.../mapboxsdk/offline/OfflineRegionStatus.java | 60 ++++++++-
.../com/mapbox/mapboxsdk/storage/FileSource.java | 19 ++-
.../mapboxsdk/style/layers/PropertyValue.java | 30 +++++
.../com/mapbox/mapboxsdk/style/light/Light.java | 22 ++-
.../com/mapbox/mapboxsdk/style/light/Position.java | 4 +-
.../mapbox/mapboxsdk/style/light/light.java.ejs | 2 +-
.../com/mapbox/mapboxsdk/utils/BitmapUtils.java | 16 +++
.../com/mapbox/mapboxsdk/utils/ColorUtils.java | 10 +-
.../mapbox/mapboxsdk/utils/MapFragmentUtils.java | 13 ++
41 files changed, 940 insertions(+), 215 deletions(-)
(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 17cd4e0dce..6722000be7 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,6 +1,5 @@
package com.mapbox.mapboxsdk;
-import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -17,10 +16,10 @@ import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
/**
- * The entry point of the Mapbox Android SDK.
+ * The entry point to initialize 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
+ * Application#onCreate() and is responsible for the active access token, application context, and
* connectivity state.
*
*/
@@ -97,6 +96,8 @@ public final class Mapbox {
/**
* Application context
+ *
+ * @return the application context
*/
public static Context getApplicationContext() {
return INSTANCE.context;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
index 07e038c08c..c58cc310a8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BubbleLayout.java
@@ -27,14 +27,32 @@ public class BubbleLayout extends LinearLayout {
private float strokeWidth;
private int strokeColor;
+ /**
+ * Creates an instance of bubble layout.
+ *
+ * @param context The context used to inflate this bubble layout
+ */
public BubbleLayout(Context context) {
this(context, null, 0);
}
+ /**
+ * Creates an instance of bubble layout.
+ *
+ * @param context The context used to inflate this bubble layout
+ * @param attrs The attribute set to initialise this bubble layout from
+ */
public BubbleLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
+ /**
+ * Creates an instance of bubble layout.
+ *
+ * @param context The context used to inflate this bubble layout
+ * @param attrs The attribute set to initialise this bubble layout from
+ * @param defStyleAttr The default style to apply this bubble layout with
+ */
public BubbleLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
@@ -78,10 +96,21 @@ public class BubbleLayout extends LinearLayout {
return dp * (metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}
+ /**
+ * Get the arrow direction.
+ *
+ * @return the arrow direction
+ */
public ArrowDirection getArrowDirection() {
return arrowDirection;
}
+ /**
+ * Set the arrow direction.
+ *
+ * @param arrowDirection The direction of the arrow
+ * @return this
+ */
public BubbleLayout setArrowDirection(ArrowDirection arrowDirection) {
resetPadding();
this.arrowDirection = arrowDirection;
@@ -89,10 +118,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
+ /**
+ * Get the arrow width.
+ *
+ * @return the width of the arrow
+ */
public float getArrowWidth() {
return arrowWidth;
}
+ /**
+ * Set the arrow width.
+ *
+ * @param arrowWidth The width of the arrow
+ * @return this
+ */
public BubbleLayout setArrowWidth(float arrowWidth) {
resetPadding();
this.arrowWidth = arrowWidth;
@@ -100,10 +140,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
+ /**
+ * Get the arrow height
+ *
+ * @return the height of the arrow
+ */
public float getArrowHeight() {
return arrowHeight;
}
+ /**
+ * Set the arrow height.
+ *
+ * @param arrowHeight The height of the arrow
+ * @return this
+ */
public BubbleLayout setArrowHeight(float arrowHeight) {
resetPadding();
this.arrowHeight = arrowHeight;
@@ -111,10 +162,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
+ /**
+ * Get the arrow position.
+ *
+ * @return the arrow position
+ */
public float getArrowPosition() {
return arrowPosition;
}
+ /**
+ * Get the arrow position.
+ *
+ * @param arrowPosition The arrow position
+ * @return this
+ */
public BubbleLayout setArrowPosition(float arrowPosition) {
resetPadding();
this.arrowPosition = arrowPosition;
@@ -122,30 +184,63 @@ public class BubbleLayout extends LinearLayout {
return this;
}
+ /**
+ * Get the corner radius
+ *
+ * @return the corner radius
+ */
public float getCornersRadius() {
return cornersRadius;
}
+ /**
+ * Set the corner radius
+ *
+ * @param cornersRadius The corner radius
+ * @return this
+ */
public BubbleLayout setCornersRadius(float cornersRadius) {
this.cornersRadius = cornersRadius;
requestLayout();
return this;
}
+ /**
+ * Get the bubble color.
+ *
+ * @return the bubble color
+ */
public int getBubbleColor() {
return bubbleColor;
}
+ /**
+ * Set the bubble color.
+ *
+ * @param bubbleColor The buble color
+ * @return this
+ */
public BubbleLayout setBubbleColor(int bubbleColor) {
this.bubbleColor = bubbleColor;
requestLayout();
return this;
}
+ /**
+ * Get stroke width.
+ *
+ * @return the stroke width
+ */
public float getStrokeWidth() {
return strokeWidth;
}
+ /**
+ * Set the stroke width.
+ *
+ * @param strokeWidth The stroke width
+ * @return this
+ */
public BubbleLayout setStrokeWidth(float strokeWidth) {
resetPadding();
this.strokeWidth = strokeWidth;
@@ -153,10 +248,21 @@ public class BubbleLayout extends LinearLayout {
return this;
}
+ /**
+ * Get the stroke color.
+ *
+ * @return the stroke color
+ */
public int getStrokeColor() {
return strokeColor;
}
+ /**
+ * Set the stroke color.
+ *
+ * @param strokeColor The stroke color
+ * @return this
+ */
public BubbleLayout setStrokeColor(int strokeColor) {
this.strokeColor = strokeColor;
requestLayout();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
index 57aa512401..f9ca9bf4cc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
@@ -23,7 +23,7 @@ import java.io.InputStream;
/**
* Factory for creating Icons from bitmap images.
*
- * {@link Icon} is used to display bitmaps on top of the map using {@link Marker} and {@link MarkerView}.
+ * icon is used to display bitmaps on top of the map using {@link Marker} and {@link MarkerView}.
*
*
* @see Icon
@@ -42,6 +42,12 @@ public final class IconFactory {
private int nextId = 0;
+ /**
+ * Get a single instance of IconFactory.
+ *
+ * @param context the context to derive the application context from
+ * @return the single instance of IconFactory
+ */
public static synchronized IconFactory getInstance(@NonNull Context context) {
if (instance == null) {
instance = new IconFactory(context.getApplicationContext());
@@ -71,10 +77,10 @@ public final class IconFactory {
}
/**
- * Creates an {@link Icon} from a given Bitmap image.
+ * Creates an icon from a given Bitmap image.
*
* @param bitmap image used for creating the Icon.
- * @return The {@link Icon} using the given Bitmap image.
+ * @return The icon using the given Bitmap image.
*/
public Icon fromBitmap(@NonNull Bitmap bitmap) {
if (nextId < 0) {
@@ -85,10 +91,10 @@ public final class IconFactory {
}
/**
- * Create an {@link Icon} using the resource ID of a Bitmap image.
+ * Creates an icon using the resource ID of a Bitmap image.
*
* @param resourceId The resource ID of a Bitmap image.
- * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
+ * @return The icon that was loaded from the asset or {@code null} if failed to load.
*/
public Icon fromResource(@DrawableRes int resourceId) {
Drawable drawable = ContextCompat.getDrawable(context, resourceId);
@@ -101,9 +107,9 @@ public final class IconFactory {
}
/**
- * Provides an {@link Icon} using the default marker icon used for {@link Marker}.
+ * Provides an icon using the default marker icon used for {@link Marker}.
*
- * @return An {@link Icon} with the default {@link Marker} icon.
+ * @return An icon with the default {@link Marker} icon.
*/
public Icon defaultMarker() {
if (defaultMarker == null) {
@@ -113,9 +119,9 @@ public final class IconFactory {
}
/**
- * Provides an {@link Icon} using the default marker icon used for {@link MarkerView}.
+ * Provides an icon using the default marker icon used for {@link MarkerView}.
*
- * @return An {@link Icon} with the default {@link MarkerView} icon.
+ * @return An icon with the default {@link MarkerView} icon.
*/
public Icon defaultMarkerView() {
if (defaultMarkerView == null) {
@@ -130,10 +136,10 @@ public final class IconFactory {
}
/**
- * Creates an {@link Icon} using the name of a Bitmap image in the assets directory.
+ * Creates an Icon using the name of a Bitmap image in the assets directory.
*
* @param assetName The name of a Bitmap image in the assets directory.
- * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
+ * @return The Icon that was loaded from the asset or null if failed to load.
*/
public Icon fromAsset(@NonNull String assetName) {
InputStream is;
@@ -146,11 +152,10 @@ public final class IconFactory {
}
/**
- * Creates an {@link Icon} using the absolute file path of a Bitmap image.
+ * Creates an Icon using the absolute file path of a Bitmap image.
*
* @param absolutePath The absolute path of the Bitmap image.
- * @return The {@link Icon} that was loaded from the absolute path or {@code null} if failed to
- * load.
+ * @return The Icon that was loaded from the absolute path or null if failed to load.
*/
public Icon fromPath(@NonNull String absolutePath) {
Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, options);
@@ -158,11 +163,11 @@ public final class IconFactory {
}
/**
- * Create an {@link Icon} using the name of a Bitmap image file located in the internal storage.
- * In particular, this calls {@link Context#openFileInput(String)}.
+ * Create an Icon using the name of a Bitmap image file located in the internal storage.
+ * In particular, this calls Context#openFileInput(String).
*
* @param fileName The name of the Bitmap image file.
- * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load.
+ * @return The Icon that was loaded from the asset or null if failed to load.
* @see
* Using the Internal Storage
*/
@@ -177,12 +182,11 @@ public final class IconFactory {
}
/**
- * Create an {@link Icon} using a previously created icon identifier along with a provided
- * Bitmap.
+ * Create an Icon using a previously created icon identifier along with a provided Bitmap.
*
- * @param iconId The {@link Icon} identifier you'd like to recreate.
+ * @param iconId The Icon identifier you'd like to recreate.
* @param bitmap a Bitmap used to replace the current one.
- * @return The {@link Icon} using the new Bitmap.
+ * @return The Icon using the new Bitmap.
*/
public static Icon recreate(@NonNull String iconId, @NonNull Bitmap bitmap) {
return new Icon(iconId, bitmap);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index b9e9bea4ed..6d42842b7d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -135,6 +135,12 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
}
+ /**
+ * Set the rotation of a MarkerView to a given rotation value.
+ *
+ * @param marker The MarkerView to change its rotation value
+ * @param rotation The rotation value
+ */
public void setRotation(@NonNull MarkerView marker, float rotation) {
View convertView = markerViewMap.get(marker);
if (convertView != null) {
@@ -544,10 +550,11 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
- * When the provided {@link MarkerView} is clicked on by a user, we check if a custom click
- * event has been created and if not, display a {@link InfoWindow}.
+ * When the provided MarkerView is clicked on by a user, we check if a custom click
+ * event has been created and if not, display a InfoWindow.
*
- * @param markerView that the click event occurred.
+ * @param markerView that the click event occurred
+ * @return true if the marker view click has been handled, false if not
*/
public boolean onClickMarkerView(MarkerView markerView) {
boolean clickHandled = false;
@@ -572,9 +579,9 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
- * Handles the {@link MarkerView}'s info window offset.
+ * Handles the MarkerView info window offset.
*
- * @param marker that we are ensuring info window offset.
+ * @param marker that we are ensuring info window offset
*/
public void ensureInfoWindowOffset(MarkerView marker) {
View view = null;
@@ -624,7 +631,7 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
/**
- * Default MarkerViewAdapter used for base class of {@link MarkerView} to adapt a MarkerView to
+ * Default MarkerViewAdapter used for base class of MarkerView to adapt a MarkerView to
* an ImageView.
*/
private static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter {
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 66c261f1d0..c2f19072db 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
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.camera;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.FloatRange;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -166,14 +167,14 @@ public final class CameraPosition implements Parcelable {
private double zoom = -1;
/**
- * Creates an empty builder.
+ * Create an empty builder.
*/
public Builder() {
super();
}
/**
- * Create Builder with an existing CameraPosition data.
+ * Create a builder with an existing CameraPosition data.
*
* @param previous Existing CameraPosition values to use
*/
@@ -188,7 +189,7 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Create Builder with an existing CameraPosition data.
+ * Create a builder with an existing CameraPosition data.
*
* @param typedArray TypedArray containing attribute values
*/
@@ -205,7 +206,7 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Create Builder from an existing CameraPositionUpdate update.
+ * Create a builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
@@ -220,7 +221,7 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Create Builder from an existing CameraPositionUpdate update.
+ * Create builder from an existing CameraPositionUpdate update.
*
* @param update Update containing camera options
*/
@@ -235,7 +236,7 @@ public final class CameraPosition implements Parcelable {
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
*
* @param bearing Bearing
- * @return Builder
+ * @return this
*/
public Builder bearing(double bearing) {
double direction = bearing;
@@ -252,19 +253,10 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Builds a CameraPosition.
+ * Sets the location where the camera is pointing at.
*
- * @return CameraPosition
- */
- public CameraPosition build() {
- return new CameraPosition(target, zoom, tilt, bearing);
- }
-
- /**
- * Sets the location that the camera is pointing at.
- *
- * @param location Location
- * @return Builder
+ * @param location target of the camera
+ * @return this
*/
public Builder target(LatLng location) {
this.target = location;
@@ -272,28 +264,42 @@ public final class CameraPosition implements Parcelable {
}
/**
- * Set the tilt in degrees
+ * Set the tilt of the camera in degrees
*
- * value is clamped to 0 and 60.
+ * value is clamped to {@link MapboxConstants#MINIMUM_TILT} and {@link MapboxConstants#MAXIMUM_TILT}.
*
*
- * @param tilt Tilt value
- * @return Builder
+ * @param tilt Tilt value of the camera
+ * @return this
*/
- public Builder tilt(double tilt) {
+ public Builder tilt(@FloatRange(from = MapboxConstants.MINIMUM_TILT,
+ to = MapboxConstants.MAXIMUM_TILT) double tilt) {
this.tilt = MathUtils.clamp(tilt, MapboxConstants.MINIMUM_TILT, MapboxConstants.MAXIMUM_TILT);
return this;
}
/**
- * Set the zoom
+ * Set the zoom of the camera
+ *
+ * Zoom ranges from {@link MapboxConstants#MINIMUM_ZOOM} to {@link MapboxConstants#MAXIMUM_ZOOM}
+ *
*
- * @param zoom Zoom value
- * @return Builder
+ * @param zoom Zoom value of the camera
+ * @return this
*/
- public Builder zoom(double zoom) {
+ public Builder zoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
+ to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
this.zoom = zoom;
return this;
}
+
+ /**
+ * Builds the CameraPosition.
+ *
+ * @return CameraPosition
+ */
+ public CameraPosition build() {
+ return new CameraPosition(target, zoom, tilt, bearing);
+ }
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
index 498aa8343b..31f13cbcff 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/camera/CameraUpdate.java
@@ -6,10 +6,16 @@ import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.maps.MapboxMap;
/**
- * Interface definition for camera position changes.
+ * Interface definition for camera updates.
*/
public interface CameraUpdate {
+ /**
+ * Get the camera position from the camera update.
+ *
+ * @param mapboxMap Map object to build the position from
+ * @return the camera position from the implementing camera update
+ */
@Nullable
CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);
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 8e1411e273..50e33f4f9f 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
@@ -42,7 +42,7 @@ public final class CameraUpdateFactory {
}
/**
- * Returns a {@link CameraUpdate} that transforms the camera such that the specified
+ * Returns a CameraUpdate that transforms the camera such that the specified
* latitude/longitude bounds are centered on screen at the greatest possible zoom level.
* You can specify padding, in order to inset the bounding box from the map view's edges.
* The returned CameraUpdate has a bearing of 0 and a tilt of 0.
@@ -56,7 +56,7 @@ public final class CameraUpdateFactory {
}
/**
- * Returns a {@link CameraUpdate} that transforms the camera such that the specified
+ * Returns a CameraUpdate that transforms the camera such that the specified
* latitude/longitude bounds are centered on screen at the greatest possible zoom level.
* You can specify padding, in order to inset the bounding box from the map view's edges.
* The returned CameraUpdate has a bearing of 0 and a tilt of 0.
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 88c3bef673..ceac862f39 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
@@ -2,23 +2,27 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
- * MyBearingTracking exposes different types bearing tracking modes.
+ * MyBearingTracking exposes different types of bearing tracking modes.
+ *
+ * These modes visualise the user direction by extracting the direction from either sensor or location data.
+ *
+ *
+ * Required to enable showing the user location first through {@link MapboxMap#setMyLocationEnabled(boolean)}.
+ *
*
* @see com.mapbox.mapboxsdk.maps.TrackingSettings#setMyBearingTrackingMode(int)
* @see MyLocationView#setMyBearingTrackingMode(int)
*/
public class MyBearingTracking {
- /**
- * Indicates that the parameter accepts one of the values from MyBearingTracking.
- */
- @IntDef( {NONE, COMPASS, GPS, /**COMBINED**/})
+ @IntDef( {NONE, COMPASS, GPS})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}
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 a1744d701f..1283283fa5 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
@@ -3,29 +3,34 @@ package com.mapbox.mapboxsdk.constants;
import android.support.annotation.IntDef;
import com.mapbox.mapboxsdk.maps.MapView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.maps.TrackingSettings;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
- * MyLocationTracking exposes different types of locational tracking modes.
+ * MyLocationTracking exposes types of location tracking modes.
+ * *
+ * This allows tracking the user location on screen by updating the camera position when a location update occurs.
+ *
+ *
+ * Required to enable showing the user location first through {@link MapboxMap#setMyLocationEnabled(boolean)}.
+ *
*
- * @see com.mapbox.mapboxsdk.maps.TrackingSettings#setMyLocationTrackingMode(int)
- * @see MyLocationView#setMyLocationTrackingMode(int)
+ * @see MapboxMap#setMyLocationEnabled(boolean)
+ * @see TrackingSettings#setMyLocationTrackingMode(int)
*/
public class MyLocationTracking {
- /**
- * Indicates the parameter accepts one of the values from MyLocationTracking.
- */
@IntDef( {TRACKING_NONE, TRACKING_FOLLOW})
@Retention(RetentionPolicy.SOURCE)
public @interface Mode {
}
/**
- * Location tracking is disabled.
+ * Tracking the location of the user is disabled.
*/
public static final int TRACKING_NONE = 0x00000000;
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 31e6313509..9943a72e06 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
@@ -17,7 +17,6 @@ import java.lang.annotation.RetentionPolicy;
*/
public class Style {
-
/**
* 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
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
index 7154049bd7..1f6b0efc4d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/IconBitmapChangedException.java
@@ -1,15 +1,13 @@
package com.mapbox.mapboxsdk.exceptions;
-import android.graphics.Bitmap;
-
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.maps.MapView;
/**
*
- * A {@code IconBitmapChangedException} is thrown by {@link MapView} when a {@link Marker} is added
- * that has a {@link Icon} with a {@link Bitmap} that has been modified since the creation of the Icon.
+ * An IconBitmapChangedException is thrown by MapView when a Marker is added
+ * that has an Icon with a Bitmap that has been modified since the creation of the Icon.
*
* You cannot modify a {@code Icon} after it has been added to the map in a {@code Marker}
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java
index 08a23a7373..c1d0385815 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidLatLngBoundsException.java
@@ -1,8 +1,8 @@
package com.mapbox.mapboxsdk.exceptions;
/**
- * A InvalidLatLngBoundsException is thrown by {@link com.mapbox.mapboxsdk.geometry.LatLngBounds}
- * when there aren't enough {@link com.mapbox.mapboxsdk.geometry.LatLng} to create a bounds.
+ * An InvalidLatLngBoundsException is thrown by LatLngBounds
+ * when there aren't enough LatLng to create a bounds.
*/
public class InvalidLatLngBoundsException extends RuntimeException {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java
index f0f9b9236b..44ee83265d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/InvalidMarkerPositionException.java
@@ -5,6 +5,9 @@ package com.mapbox.mapboxsdk.exceptions;
*/
public class InvalidMarkerPositionException extends RuntimeException {
+ /**
+ * Creates a invalid marker position exception thrown when a Marker object is created with an invalid LatLng position.
+ */
public InvalidMarkerPositionException() {
super("Adding an invalid Marker to a Map. "
+ "Missing the required position field. "
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/MapboxConfigurationException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/MapboxConfigurationException.java
index 74bceb196c..e9a0261d85 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/MapboxConfigurationException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/MapboxConfigurationException.java
@@ -8,10 +8,14 @@ import android.content.Context;
* This occurs either when {@link com.mapbox.mapboxsdk.Mapbox} is not correctly initialised or the provided access token
* through {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)} isn't valid.
*
+ *
* @see com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)
*/
public class MapboxConfigurationException extends RuntimeException {
+ /**
+ * Creates a Mapbox configuration exception thrown by MapboxMap when the SDK hasn't been properly initialised.
+ */
public MapboxConfigurationException() {
super("\nUsing MapView requires setting a valid access token. Use Mapbox.getInstance(Context context, "
+ "String accessToken) to provide one. "
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java
index 8923d822f2..bffc10dc04 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/TooManyIconsException.java
@@ -1,12 +1,11 @@
package com.mapbox.mapboxsdk.exceptions;
-import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
/**
*
- * A {@code TooManyIconsException} is thrown by {@link IconFactory} when it
- * cannot create a {@link Icon} because there are already too many icons created.
+ * A TooManyIconsException is thrown by IconFactory when it
+ * cannot create a Icon because there are already too many icons created.
*
* You should try to reuse Icon objects whenever possible.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java
index 1af8e7cfc7..07df87af3a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ILatLng.java
@@ -1,12 +1,28 @@
package com.mapbox.mapboxsdk.geometry;
/**
- * Describes a latitude, longitude point.
+ * Describes a latitude, longitude, and altitude tuple.
*/
public interface ILatLng {
+
+ /**
+ * Get the latitude, in degrees.
+ *
+ * @return the latitude value in degrees
+ */
double getLatitude();
+ /**
+ * Get the longitude, in degrees.
+ *
+ * @return the longitude value in degrees
+ */
double getLongitude();
+ /**
+ * Get the altitude, in meters.
+ *
+ * @return the altitude value in meters
+ */
double getAltitude();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java
index 694c935143..db459d7cbb 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/IProjectedMeters.java
@@ -4,7 +4,19 @@ package com.mapbox.mapboxsdk.geometry;
* Describes a projection in Mercator meters.
*/
public interface IProjectedMeters {
+
+ /**
+ * Get the north projection, in meters.
+ *
+ * @return the projected meters in north direction
+ */
double getNorthing();
+ /**
+ * Get the east projection, in meters.
+ *
+ * @return the projected meters in east direction
+ */
double getEasting();
+
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java
index ca2d3673b2..eb57241196 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLng.java
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.geometry;
import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
+import android.support.annotation.FloatRange;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
import com.mapbox.services.android.telemetry.utils.MathUtils;
@@ -21,6 +22,9 @@ import com.mapbox.services.android.telemetry.utils.MathUtils;
*/
public class LatLng implements ILatLng, Parcelable {
+ /**
+ * Inner class responsible for recreating Parcels into objects.
+ */
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public LatLng createFromParcel(Parcel in) {
return new LatLng(in);
@@ -44,7 +48,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
- * Construct a new latitude, longitude point given float arguments
+ * Construct a new latitude, longitude point given double arguments
*
* @param latitude Latitude in degrees
* @param longitude Longitude in degrees
@@ -55,7 +59,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
- * Construct a new latitude, longitude, altitude point given float arguments
+ * Construct a new latitude, longitude, altitude point given double arguments
*
* @param latitude Latitude in degrees
* @param longitude Longitude in degress
@@ -68,7 +72,7 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
- * Transform a Location into a LatLng point
+ * Construct a new latitude, longitude, altitude point given location argument
*
* @param location Android Location
*/
@@ -77,23 +81,40 @@ public class LatLng implements ILatLng, Parcelable {
}
/**
- * Clone an existing latitude longitude point
+ * Construct a new latitude, longitude, altitude point given another latitude, longitude, altitude point.
*
- * @param aLatLng LatLng
+ * @param latLng LatLng to be cloned.
*/
- public LatLng(LatLng aLatLng) {
- this.latitude = aLatLng.latitude;
- this.longitude = aLatLng.longitude;
- this.altitude = aLatLng.altitude;
+ public LatLng(LatLng latLng) {
+ this.latitude = latLng.latitude;
+ this.longitude = latLng.longitude;
+ this.altitude = latLng.altitude;
}
+ /**
+ * Constructs a new latitude, longitude, altitude tuple given a parcel.
+ *
+ * @param in the parcel containing the latitude, longitude, altitude values
+ */
protected LatLng(Parcel in) {
setLatitude(in.readDouble());
setLongitude(in.readDouble());
setAltitude(in.readDouble());
}
- public void setLatitude(double latitude) {
+ /**
+ * Set the latitude, in degrees.
+ *
+ * This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
+ * {@link GeoConstants#MAX_LATITUDE}
+ *
+ *
+ * @param latitude the latitude value in degrees
+ * @see GeoConstants#MIN_LATITUDE
+ * @see GeoConstants#MAX_LATITUDE
+ */
+ public void setLatitude(
+ @FloatRange(from = GeoConstants.MIN_LATITUDE, to = GeoConstants.MAX_LATITUDE) double latitude) {
if (Double.isNaN(latitude)) {
throw new IllegalArgumentException("latitude must not be NaN");
}
@@ -103,12 +124,35 @@ public class LatLng implements ILatLng, Parcelable {
this.latitude = latitude;
}
+ /**
+ * Get the latitude, in degrees.
+ *
+ * This value is in the range of [-85.05112878, 85.05112878], see {@link GeoConstants#MIN_LATITUDE} and
+ * {@link GeoConstants#MAX_LATITUDE}
+ *
+ *
+ * @return the latitude value in degrees
+ * @see GeoConstants#MIN_LATITUDE
+ * @see GeoConstants#MAX_LATITUDE
+ */
@Override
public double getLatitude() {
return latitude;
}
- public void setLongitude(double longitude) {
+ /**
+ * Set the longitude, in degrees.
+ *
+ * This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
+ * {@link GeoConstants#MAX_LONGITUDE}
+ *
+ *
+ * @param longitude the longitude value in degrees
+ * @see GeoConstants#MIN_LONGITUDE
+ * @see GeoConstants#MAX_LONGITUDE
+ */
+ public void setLongitude(@FloatRange(from = GeoConstants.MIN_LONGITUDE, to = GeoConstants.MAX_LONGITUDE)
+ double longitude) {
if (Double.isNaN(longitude)) {
throw new IllegalArgumentException("longitude must not be NaN");
}
@@ -118,15 +162,36 @@ public class LatLng implements ILatLng, Parcelable {
this.longitude = longitude;
}
+ /**
+ * Get the longitude, in degrees.
+ *
+ * This value is in the range of [-180, 180], see {@link GeoConstants#MIN_LONGITUDE} and
+ * {@link GeoConstants#MAX_LONGITUDE}
+ *
+ *
+ * @return the longitude value in degrees
+ * @see GeoConstants#MIN_LONGITUDE
+ * @see GeoConstants#MAX_LONGITUDE
+ */
@Override
public double getLongitude() {
return longitude;
}
+ /**
+ * Set the altitude, in meters.
+ *
+ * @param altitude the altitude in meters
+ */
public void setAltitude(double altitude) {
this.altitude = altitude;
}
+ /**
+ * Get the altitude, in meters.
+ *
+ * @return the altitude value in meters
+ */
@Override
public double getAltitude() {
return altitude;
@@ -136,13 +201,19 @@ public class LatLng implements ILatLng, Parcelable {
* Return a new LatLng object with a wrapped Longitude. This allows original data object
* to remain unchanged.
*
- * @return New LatLng object with wrapped Longitude
+ * @return new LatLng object with wrapped Longitude
*/
public LatLng wrap() {
longitude = MathUtils.wrap(longitude, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE);
return this;
}
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param object The object to compare
+ * @return True if equal, false if not
+ */
@Override
public boolean equals(Object object) {
if (this == object) {
@@ -158,6 +229,11 @@ public class LatLng implements ILatLng, Parcelable {
&& Double.compare(latLng.longitude, longitude) == 0;
}
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return the hash code value
+ */
@Override
public int hashCode() {
int result;
@@ -171,16 +247,32 @@ public class LatLng implements ILatLng, Parcelable {
return result;
}
+ /**
+ * Returns a string representation of the object.
+ *
+ * @return the string representation
+ */
@Override
public String toString() {
return "LatLng [latitude=" + latitude + ", longitude=" + longitude + ", altitude=" + altitude + "]";
}
+ /**
+ * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
+ *
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param out The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written
+ */
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(latitude);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 4a4e2a30aa..505b2db192 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.geometry;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import com.mapbox.services.android.telemetry.constants.GeoConstants;
@@ -18,10 +19,10 @@ import java.util.List;
*/
public class LatLngBounds implements Parcelable {
- private final double mLatNorth;
- private final double mLatSouth;
- private final double mLonEast;
- private final double mLonWest;
+ private final double latitudeNorth;
+ private final double latitudeSouth;
+ private final double longitudeEast;
+ private final double longitudeWest;
/**
* Construct a new LatLngBounds based on its corners, given in NESW
@@ -34,10 +35,10 @@ public class LatLngBounds implements Parcelable {
*/
LatLngBounds(final double northLatitude, final double eastLongitude, final double southLatitude,
final double westLongitude) {
- this.mLatNorth = northLatitude;
- this.mLonEast = eastLongitude;
- this.mLatSouth = southLatitude;
- this.mLonWest = westLongitude;
+ this.latitudeNorth = northLatitude;
+ this.longitudeEast = eastLongitude;
+ this.latitudeSouth = southLatitude;
+ this.longitudeWest = westLongitude;
}
/**
@@ -59,8 +60,8 @@ public class LatLngBounds implements Parcelable {
* @return LatLng center of this LatLngBounds
*/
public LatLng getCenter() {
- return new LatLng((this.mLatNorth + this.mLatSouth) / 2,
- (this.mLonEast + this.mLonWest) / 2);
+ return new LatLng((this.latitudeNorth + this.latitudeSouth) / 2,
+ (this.longitudeEast + this.longitudeWest) / 2);
}
/**
@@ -69,7 +70,7 @@ public class LatLngBounds implements Parcelable {
* @return double latitude value for north
*/
public double getLatNorth() {
- return this.mLatNorth;
+ return this.latitudeNorth;
}
/**
@@ -78,7 +79,7 @@ public class LatLngBounds implements Parcelable {
* @return double latitude value for south
*/
public double getLatSouth() {
- return this.mLatSouth;
+ return this.latitudeSouth;
}
/**
@@ -87,7 +88,7 @@ public class LatLngBounds implements Parcelable {
* @return double longitude value for east
*/
public double getLonEast() {
- return this.mLonEast;
+ return this.longitudeEast;
}
/**
@@ -96,7 +97,7 @@ public class LatLngBounds implements Parcelable {
* @return double longitude value for west
*/
public double getLonWest() {
- return this.mLonWest;
+ return this.longitudeWest;
}
/**
@@ -105,7 +106,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the south west corner
*/
public LatLng getSouthWest() {
- return new LatLng(mLatSouth, mLonWest);
+ return new LatLng(latitudeSouth, longitudeWest);
}
/**
@@ -114,7 +115,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the north east corner
*/
public LatLng getNorthEast() {
- return new LatLng(mLatNorth, mLonEast);
+ return new LatLng(latitudeNorth, longitudeEast);
}
/**
@@ -123,7 +124,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the south east corner
*/
public LatLng getSouthEast() {
- return new LatLng(mLatSouth, mLonEast);
+ return new LatLng(latitudeSouth, longitudeEast);
}
/**
@@ -132,7 +133,7 @@ public class LatLngBounds implements Parcelable {
* @return LatLng of the north west corner
*/
public LatLng getNorthWest() {
- return new LatLng(mLatNorth, mLonWest);
+ return new LatLng(latitudeNorth, longitudeWest);
}
/**
@@ -151,7 +152,7 @@ public class LatLngBounds implements Parcelable {
* @return Span distance
*/
public double getLatitudeSpan() {
- return Math.abs(this.mLatNorth - this.mLatSouth);
+ return Math.abs(this.latitudeNorth - this.latitudeSouth);
}
/**
@@ -161,7 +162,7 @@ public class LatLngBounds implements Parcelable {
* @return Span distance
*/
public double getLongitudeSpan() {
- return Math.abs(this.mLonEast - this.mLonWest);
+ return Math.abs(this.longitudeEast - this.longitudeWest);
}
@@ -174,9 +175,15 @@ public class LatLngBounds implements Parcelable {
return getLongitudeSpan() == 0.0 || getLatitudeSpan() == 0.0;
}
+ /**
+ * Returns a string representaton of the object.
+ *
+ * @return the string representation
+ */
@Override
public String toString() {
- return "N:" + this.mLatNorth + "; E:" + this.mLonEast + "; S:" + this.mLatSouth + "; W:" + this.mLonWest;
+ return "N:" + this.latitudeNorth + "; E:" + this.longitudeEast + "; S:" + this.latitudeSouth
+ + "; W:" + this.longitudeWest;
}
/**
@@ -241,10 +248,10 @@ public class LatLngBounds implements Parcelable {
}
if (o instanceof LatLngBounds) {
LatLngBounds other = (LatLngBounds) o;
- return mLatNorth == other.getLatNorth()
- && mLatSouth == other.getLatSouth()
- && mLonEast == other.getLonEast()
- && mLonWest == other.getLonWest();
+ return latitudeNorth == other.getLatNorth()
+ && latitudeSouth == other.getLatSouth()
+ && longitudeEast == other.getLonEast()
+ && longitudeWest == other.getLonWest();
}
return false;
}
@@ -258,10 +265,10 @@ public class LatLngBounds implements Parcelable {
public boolean contains(final ILatLng latLng) {
final double latitude = latLng.getLatitude();
final double longitude = latLng.getLongitude();
- return ((latitude <= this.mLatNorth)
- && (latitude >= this.mLatSouth))
- && ((longitude <= this.mLonEast)
- && (longitude >= this.mLonWest));
+ return ((latitude <= this.latitudeNorth)
+ && (latitude >= this.latitudeSouth))
+ && ((longitude <= this.longitudeEast)
+ && (longitude >= this.longitudeWest));
}
/**
@@ -295,10 +302,10 @@ public class LatLngBounds implements Parcelable {
* @return BoundingBox
*/
public LatLngBounds union(final double lonNorth, final double latEast, final double lonSouth, final double latWest) {
- return new LatLngBounds((this.mLatNorth < lonNorth) ? lonNorth : this.mLatNorth,
- (this.mLonEast < latEast) ? latEast : this.mLonEast,
- (this.mLatSouth > lonSouth) ? lonSouth : this.mLatSouth,
- (this.mLonWest > latWest) ? latWest : this.mLonWest);
+ return new LatLngBounds((this.latitudeNorth < lonNorth) ? lonNorth : this.latitudeNorth,
+ (this.longitudeEast < latEast) ? latEast : this.longitudeEast,
+ (this.latitudeSouth > lonSouth) ? lonSouth : this.latitudeSouth,
+ (this.longitudeWest > latWest) ? latWest : this.longitudeWest);
}
/**
@@ -307,6 +314,7 @@ public class LatLngBounds implements Parcelable {
* @param box LatLngBounds to intersect with
* @return LatLngBounds
*/
+ @Nullable
public LatLngBounds intersect(LatLngBounds box) {
double minLatWest = Math.max(getLonWest(), box.getLonWest());
double maxLatEast = Math.min(getLonEast(), box.getLonEast());
@@ -334,6 +342,9 @@ public class LatLngBounds implements Parcelable {
return intersect(new LatLngBounds(northLatitude, eastLongitude, southLatitude, westLongitude));
}
+ /**
+ * Inner class responsible for recreating Parcels into objects.
+ */
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
@Override
@@ -347,25 +358,41 @@ public class LatLngBounds implements Parcelable {
}
};
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return the hash code
+ */
@Override
public int hashCode() {
- return (int) ((mLatNorth + 90)
- + ((mLatSouth + 90) * 1000)
- + ((mLonEast + 180) * 1000000)
- + ((mLonEast + 180) * 1000000000));
+ return (int) ((latitudeNorth + 90)
+ + ((latitudeSouth + 90) * 1000)
+ + ((longitudeEast + 180) * 1000000)
+ + ((longitudeEast + 180) * 1000000000));
}
+ /**
+ * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
+ *
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param out The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written
+ */
@Override
- public void writeToParcel(final Parcel out, final int arg1) {
- out.writeDouble(this.mLatNorth);
- out.writeDouble(this.mLonEast);
- out.writeDouble(this.mLatSouth);
- out.writeDouble(this.mLonWest);
+ public void writeToParcel(final Parcel out, final int flags) {
+ out.writeDouble(this.latitudeNorth);
+ out.writeDouble(this.longitudeEast);
+ out.writeDouble(this.latitudeSouth);
+ out.writeDouble(this.longitudeWest);
}
private static LatLngBounds readFromParcel(final Parcel in) {
@@ -381,28 +408,51 @@ public class LatLngBounds implements Parcelable {
*/
public static final class Builder {
- private List mLatLngList;
+ private List latLngList;
+ /**
+ * Constructs a builder to compose LatLng objects to a LatLngBounds.
+ */
public Builder() {
- mLatLngList = new ArrayList<>();
+ latLngList = new ArrayList<>();
}
+ /**
+ * Builds a new LatLngBounds.
+ *
+ * Throws an {@link InvalidLatLngBoundsException} when no LatLngBounds can be created.
+ *
+ *
+ * @return the build LatLngBounds
+ */
public LatLngBounds build() {
- if (mLatLngList.size() < 2) {
- throw new InvalidLatLngBoundsException(mLatLngList.size());
+ if (latLngList.size() < 2) {
+ throw new InvalidLatLngBoundsException(latLngList.size());
}
- return LatLngBounds.fromLatLngs(mLatLngList);
+ return LatLngBounds.fromLatLngs(latLngList);
}
+ /**
+ * Adds a LatLng object to the LatLngBounds.Builder.
+ *
+ * @param latLngs the List of LatLng objects to be added
+ * @return this
+ */
public Builder includes(List latLngs) {
for (LatLng point : latLngs) {
- mLatLngList.add(point);
+ latLngList.add(point);
}
return this;
}
+ /**
+ * Adds a LatLng object to the LatLngBounds.Builder.
+ *
+ * @param latLng the LatLng to be added
+ * @return this
+ */
public Builder include(@NonNull LatLng latLng) {
- mLatLngList.add(latLng);
+ latLngList.add(latLng);
return this;
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngSpan.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngSpan.java
index d00ccdb9b8..322c7dfb74 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngSpan.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngSpan.java
@@ -64,19 +64,28 @@ public class LatLngSpan implements Parcelable {
mLongitudeSpan = longitudeSpan;
}
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param object The object to compare
+ * @return True if equal, false if not
+ */
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
}
- if (o instanceof LatLngSpan) {
- LatLngSpan other = (LatLngSpan) o;
+ if (object instanceof LatLngSpan) {
+ LatLngSpan other = (LatLngSpan) object;
return mLongitudeSpan == other.getLongitudeSpan()
&& mLatitudeSpan == other.getLatitudeSpan();
}
return false;
}
+ /**
+ * Inner class responsible for recreating Parcels into objects.
+ */
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
@Override
@@ -90,14 +99,41 @@ public class LatLngSpan implements Parcelable {
}
};
+ /**
+ * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
+ *
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param out Parcel in which the object should be written
+ * @param flags Additional flags about how the object should be written
+ */
@Override
- public void writeToParcel(Parcel out, int arg1) {
+ public void writeToParcel(Parcel out, int flags) {
out.writeDouble(mLatitudeSpan);
out.writeDouble(mLongitudeSpan);
}
+
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return hash code value of this
+ */
+ @Override
+ public int hashCode() {
+ int result;
+ long temp;
+ temp = Double.doubleToLongBits(mLatitudeSpan);
+ result = (int) (temp ^ (temp >>> 32));
+ temp = Double.doubleToLongBits(mLongitudeSpan);
+ result = 31 * result + (int) (temp ^ (temp >>> 32));
+ return result;
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java
index 761d8f2a8b..fa84c33b2b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java
@@ -13,6 +13,9 @@ import android.os.Parcelable;
*/
public class ProjectedMeters implements IProjectedMeters, Parcelable {
+ /**
+ * Inner class responsible for recreating Parcels into objects.
+ */
public static final Creator CREATOR = new Creator() {
public ProjectedMeters createFromParcel(Parcel in) {
return new ProjectedMeters(in);
@@ -47,6 +50,12 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
this.easting = projectedMeters.easting;
}
+ /**
+ * Creates a ProjectedMeters from a Parcel.
+ *
+ * @param in The parcel to create from
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
private ProjectedMeters(Parcel in) {
northing = in.readDouble();
easting = in.readDouble();
@@ -72,22 +81,32 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
return easting;
}
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param other The object to compare this to
+ * @return true if equal, false if not
+ */
@Override
- public boolean equals(Object o) {
- if (this == o) {
+ public boolean equals(Object other) {
+ if (this == other) {
return true;
}
- if (o == null || getClass() != o.getClass()) {
+ if (other == null || getClass() != other.getClass()) {
return false;
}
- ProjectedMeters projectedMeters = (ProjectedMeters) o;
+ ProjectedMeters projectedMeters = (ProjectedMeters) other;
return Double.compare(projectedMeters.easting, easting) == 0
&& Double.compare(projectedMeters.northing, northing) == 0;
-
}
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return the hash code of this
+ */
@Override
public int hashCode() {
int result;
@@ -99,16 +118,32 @@ public class ProjectedMeters implements IProjectedMeters, Parcelable {
return result;
}
+ /**
+ * Returns a string representation of the object.
+ *
+ * @return the string representation of this
+ */
@Override
public String toString() {
return "ProjectedMeters [northing=" + northing + ", easting=" + easting + "]";
}
+ /**
+ * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
+ *
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param out The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written
+ */
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeDouble(northing);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/VisibleRegion.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/VisibleRegion.java
index c5b8ad3077..c09c00fced 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/VisibleRegion.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/VisibleRegion.java
@@ -37,6 +37,11 @@ public class VisibleRegion implements Parcelable {
*/
public final LatLngBounds latLngBounds;
+ /**
+ * Creates a VisibleRegion from a Parcel.
+ *
+ * @param in The Parcel to create this from
+ */
private VisibleRegion(Parcel in) {
this.farLeft = in.readParcelable(LatLng.class.getClassLoader());
this.farRight = in.readParcelable(LatLng.class.getClassLoader());
@@ -46,7 +51,7 @@ public class VisibleRegion implements Parcelable {
}
/**
- * Creates a new VisibleRegion given the four corners of the camera.
+ * Creates a VisibleRegion given the four corners of the camera.
*
* @param farLeft A LatLng object containing the latitude and longitude of the near left corner of the region.
* @param farRight A LatLng object containing the latitude and longitude of the near left corner of the region.
@@ -88,12 +93,22 @@ public class VisibleRegion implements Parcelable {
&& latLngBounds.equals(visibleRegion.latLngBounds);
}
+ /**
+ * The string representation of the object.
+ *
+ * @return the string representation of this
+ */
@Override
public String toString() {
return "[farLeft [" + farLeft + "], farRight [" + farRight + "], nearLeft [" + nearLeft + "], nearRight ["
+ nearRight + "], latLngBounds [" + latLngBounds + "]]";
}
+ /**
+ * Returns a hash code value for the object.
+ *
+ * @return the hash code
+ */
@Override
public int hashCode() {
return ((farLeft.hashCode() + 90)
@@ -102,11 +117,22 @@ public class VisibleRegion implements Parcelable {
+ ((nearRight.hashCode() + 180) * 1000000000));
}
+ /**
+ * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
+ *
+ * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
+ */
@Override
public int describeContents() {
return 0;
}
+ /**
+ * Flatten this object in to a Parcel.
+ *
+ * @param out The Parcel in which the object should be written.
+ * @param flags Additional flags about how the object should be written
+ */
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(farLeft, flags);
@@ -116,6 +142,9 @@ public class VisibleRegion implements Parcelable {
out.writeParcelable(latLngBounds, flags);
}
+ /**
+ * Inner class responsible for recreating Parcels into objects.
+ */
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
public VisibleRegion createFromParcel(Parcel in) {
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 8416bd5b6c..12e3300429 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
@@ -28,12 +28,16 @@ import com.mapzen.android.lost.api.LostApiClient;
* in the history stack.
*
*/
-public class LocationSource extends LocationEngine implements
- LostApiClient.ConnectionCallbacks, LocationListener {
+public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener {
private Context context;
private LostApiClient lostApiClient;
+ /**
+ * Constructs a location source instance.
+ *
+ * @param context the context from which the Application context will be derived.
+ */
public LocationSource(Context context) {
super();
this.context = context.getApplicationContext();
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 098c701e03..c51d9327d2 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
@@ -1,7 +1,5 @@
package com.mapbox.mapboxsdk.maps;
-import android.app.Activity;
-import android.app.Fragment;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
@@ -27,7 +25,6 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ZoomButtonsController;
-import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -178,14 +175,14 @@ public class MapView extends FrameLayout {
/**
*
- * You must call this method from the parent's {@link android.app.Activity#onCreate(Bundle)} or
- * {@link android.app.Fragment#onCreate(Bundle)}.
+ * You must call this method from the parent's Activity#onCreate(Bundle)} or
+ * Fragment#onCreate(Bundle).
*
- * You must set a valid access token with {@link Mapbox#getInstance(Context, String)}) before you call this method
- * or an exception will be thrown.
+ * You must set a valid access token with {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)}
+ * before you call this method or an exception will be thrown.
*
* @param savedInstanceState Pass in the parent's savedInstanceState.
- * @see Mapbox#getInstance(Context, String)
+ * @see com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)
*/
@UiThread
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -214,12 +211,11 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link android.app.Activity#onSaveInstanceState(Bundle)}
- * or {@link android.app.Fragment#onSaveInstanceState(Bundle)}.
+ * You must call this method from the parent's Activity#onSaveInstanceState(Bundle)
+ * or Fragment#onSaveInstanceState(Bundle).
*
* @param outState Pass in the parent's outState.
*/
-
@UiThread
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
@@ -227,7 +223,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}
+ * You must call this method from the parent's Activity#onStart() or Fragment#onStart()
*/
@UiThread
public void onStart() {
@@ -236,7 +232,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}.
+ * You must call this method from the parent's Activity#onResume() or Fragment#onResume().
*/
@UiThread
public void onResume() {
@@ -244,7 +240,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onPause()} or {@link Fragment#onPause()}.
+ * You must call this method from the parent's Activity#onPause() or Fragment#onPause().
*/
@UiThread
public void onPause() {
@@ -252,7 +248,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.
+ * You must call this method from the parent's Activity#onStop() or Fragment#onStop().
*/
@UiThread
public void onStop() {
@@ -261,7 +257,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}.
+ * You must call this method from the parent's Activity#onDestroy() or Fragment#onDestroy().
*/
@UiThread
public void onDestroy() {
@@ -325,7 +321,7 @@ public class MapView extends FrameLayout {
}
/**
- * You must call this method from the parent's {@link Activity#onLowMemory()} or {@link Fragment#onLowMemory()}.
+ * You must call this method from the parent's Activity#onLowMemory() or Fragment#onLowMemory().
*/
@UiThread
public void onLowMemory() {
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 8a708cb186..d672ab37c3 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
@@ -736,8 +736,8 @@ public final class MapboxMap {
* will return the current location of the camera in flight.
*
* Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
- * {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
- * method and calling it with true in the {@link CancelableCallback#onFinish()}.
+ * {@link com.mapbox.mapboxsdk.maps.TrackingSettings#setDismissLocationTrackingOnGesture(boolean)} with false before
+ * invoking this method and calling it with true in the {@link CancelableCallback#onFinish()}.
*
*
* @param update The change that should be applied to the camera.
@@ -763,8 +763,8 @@ public final class MapboxMap {
* will return the current location of the camera in flight.
*
* Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
- * {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
- * method and calling it with true in the {@link CancelableCallback#onFinish()}.
+ * {@link com.mapbox.mapboxsdk.maps.TrackingSettings#setDismissLocationTrackingOnGesture(boolean)} with false before
+ * invoking this method and calling it with true in the {@link CancelableCallback#onFinish()}.
*
*
* @param update The change that should be applied to the camera.
@@ -887,7 +887,12 @@ public final class MapboxMap {
}
/**
- * Set focal bearing.
+ * Transform the map bearing given a bearing, focal point coordinates, and a duration.
+ *
+ * @param bearing The bearing of the Map to be transformed to
+ * @param focalX The x coordinate of the focal point
+ * @param focalY The y coordinate of the focal point
+ * @param duration The duration of the transformation
*/
public void setFocalBearing(double bearing, float focalX, float focalY, long duration) {
transform.setBearing(bearing, focalX, focalY, duration);
@@ -1059,7 +1064,7 @@ public final class MapboxMap {
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
* sent.
*
- * @param style The bundled style. Accepts one of the values from {@link Style}.
+ * @param style The bundled style.
* @see Style
*/
@UiThread
@@ -1075,7 +1080,8 @@ public final class MapboxMap {
* An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
* sent.
*
- * @param style The bundled style. Accepts one of the values from {@link Style}.
+ * @param style The bundled style.
+ * @param callback The callback to be invoked when the style has finished loading
* @see Style
*/
@UiThread
@@ -1576,9 +1582,11 @@ public final class MapboxMap {
}
/**
- * Gets a camera position that would fit a bounds.
+ * Get a camera position that fits a provided bounds and padding.
*
* @param latLngBounds the bounds to constrain the map with
+ * @param padding the padding to apply to the bounds
+ * @return the camera position that fits the bounds and padding
*/
public CameraPosition getCameraForLatLngBounds(@Nullable LatLngBounds latLngBounds, int[] padding) {
// calculate and set additional bounds padding
@@ -2410,11 +2418,13 @@ public final class MapboxMap {
}
/**
- * Interface definintion for a callback to be invoked when the style has finished loading.
+ * Interface definition for a callback to be invoked when the style has finished loading.
*/
public interface OnStyleLoadedListener {
/**
- * Invoked when the style has finished loading.
+ * Invoked when the style has finished loading
+ *
+ * @param style the style that has been loaded
*/
void onStyleLoaded(String style);
}
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 98f94ddb39..2efed1b322 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
@@ -378,7 +378,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of mapbox_compass_icon for a map view.
*
- * @param gravity see {@link android.view.Gravity}
+ * @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions compassGravity(int gravity) {
@@ -439,7 +439,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of logo for a map view.
*
- * @param gravity see {@link android.view.Gravity}
+ * @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions logoGravity(int gravity) {
@@ -472,7 +472,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Specifies the gravity state of attribution for a map view.
*
- * @param gravity see {@link android.view.Gravity}
+ * @param gravity Android SDK Gravity.
* @return This
*/
public MapboxMapOptions attributionGravity(int gravity) {
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 accecf232b..7f8ba21e3e 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
@@ -16,7 +16,6 @@ import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
-import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -196,7 +195,7 @@ public final class UiSettings {
setLogoMargins(resources, options.getLogoMargins());
}
- private void setLogoMargins(Resources resources, int[]logoMargins) {
+ private void setLogoMargins(Resources resources, int[] logoMargins) {
if (logoMargins != null) {
setLogoMargins(logoMargins[0], logoMargins[1], logoMargins[2], logoMargins[3]);
} else {
@@ -309,8 +308,7 @@ public final class UiSettings {
*
* By default, the compass is in the top right corner.
*
- * @param gravity One of the values from {@link Gravity}.
- * @see Gravity
+ * @param gravity Android SDK Gravity.
*/
@UiThread
public void setCompassGravity(int gravity) {
@@ -454,8 +452,7 @@ public final class UiSettings {
*
* By default, the logo is in the bottom left corner.
*
- * @param gravity One of the values from {@link Gravity}.
- * @see Gravity
+ * @param gravity Android SDK Gravity.
*/
public void setLogoGravity(int gravity) {
setWidgetGravity(logoView, gravity);
@@ -546,8 +543,7 @@ public final class UiSettings {
*
* By default, the attribution is in the bottom left corner next to the Mapbox logo.
*
- * @param gravity One of the values from {@link Gravity}.
- * @see Gravity
+ * @param gravity Android SDK Gravity.
*/
public void setAttributionGravity(int gravity) {
setWidgetGravity(attributionsView, gravity);
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 9740679cf5..72868a91d8 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
@@ -45,6 +45,9 @@ import timber.log.Timber;
/**
* UI element overlaid on a map to show the user's location.
+ *
+ * Use {@link MyLocationViewSettings} to manipulate the state of this view.
+ *
*/
public class MyLocationView extends View {
@@ -155,6 +158,12 @@ public class MyLocationView extends View {
this.locationSource = locationSource;
}
+ /**
+ * Set the foreground drawable, for internal use only.
+ *
+ * @param defaultDrawable The drawable shown when showing this view
+ * @param bearingDrawable The drawable shown when tracking of bearing is enabled
+ */
public final void setForegroundDrawables(Drawable defaultDrawable, Drawable bearingDrawable) {
if (defaultDrawable == null) {
return;
@@ -183,6 +192,11 @@ public class MyLocationView extends View {
invalidateBounds();
}
+ /**
+ * Set the foreground drawable tint, for internal use only.
+ *
+ * @param color The color to tint the drawable with
+ */
public final void setForegroundDrawableTint(@ColorInt int color) {
if (foregroundDrawable != null) {
foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
@@ -193,10 +207,24 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Set the shadow drawable, for internal use only.
+ *
+ * @param drawable The drawable shown as shadow
+ */
public final void setShadowDrawable(Drawable drawable) {
setShadowDrawable(drawable, 0, 0, 0, 0);
}
+ /**
+ * Set the shadow drawable with some additional offset.
+ *
+ * @param drawable The drawable shown as shadow
+ * @param left The left offset margin
+ * @param top The top offset margin
+ * @param right The right offset margin
+ * @param bottom The bottom offset margin
+ */
public final void setShadowDrawable(Drawable drawable, int left, int top, int right, int bottom) {
if (drawable != null) {
backgroundDrawable = drawable;
@@ -210,6 +238,11 @@ public class MyLocationView extends View {
invalidateBounds();
}
+ /**
+ * Set the shadow drawable tint color, for internal use only.
+ *
+ * @param color The tint color to apply
+ */
public final void setShadowDrawableTint(@ColorInt int color) {
if (backgroundDrawable == null) {
return;
@@ -218,6 +251,11 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Set the accuracy tint color, for internal use only.
+ *
+ * @param color The tint color to apply
+ */
public final void setAccuracyTint(@ColorInt int color) {
int alpha = accuracyPaint.getAlpha();
accuracyPaint.setColor(color);
@@ -225,6 +263,11 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Set the accuracy alpha value, for internal use only.
+ *
+ * @param alpha The alpha accuracy value to apply
+ */
public final void setAccuracyAlpha(@IntRange(from = 0, to = 255) int alpha) {
accuracyPaint.setAlpha(alpha);
invalidate();
@@ -314,6 +357,11 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Set the tilt value, for internal use only.
+ *
+ * @param tilt The tilt to apply
+ */
public void setTilt(@FloatRange(from = 0, to = 60.0f) double tilt) {
this.tilt = tilt;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
@@ -322,6 +370,11 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Set the bearing value, for internal use only.
+ *
+ * @param bearing The bearing to apply
+ */
public void setBearing(double bearing) {
this.bearing = bearing;
if (myLocationTrackingMode == MyLocationTracking.TRACKING_NONE) {
@@ -335,6 +388,11 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Set the bearing and tilt from a camera position, for internal use only.
+ *
+ * @param position The camera position to extract bearing and tilt from
+ */
public void setCameraPosition(CameraPosition position) {
if (position != null) {
setBearing(position.bearing);
@@ -342,6 +400,9 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Called when the hosting activity is starting, for internal use only.
+ */
public void onStart() {
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
compassListener.onResume();
@@ -351,6 +412,9 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Called when the hosting activity is stopping, for internal use only.
+ */
public void onStop() {
compassListener.onPause();
toggleGps(false);
@@ -382,6 +446,9 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Update current locationstate.
+ */
public void update() {
if (isEnabled()) {
myLocationBehavior.invalidate();
@@ -396,17 +463,33 @@ public class MyLocationView extends View {
this.projection = mapboxMap.getProjection();
}
+ /**
+ * Set the enabled state, for internal use only.
+ *
+ * @param enabled The value to set the state to
+ */
@Override
public void setEnabled(boolean enabled) {
setEnabled(enabled, false);
}
+ /**
+ * Set the enabled state, for internal use only.
+ *
+ * @param enabled The value to set the state to
+ * @param isCustomLocationSource Flag handling for handling user provided custom location source
+ */
public void setEnabled(boolean enabled, boolean isCustomLocationSource) {
super.setEnabled(enabled);
setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
toggleGps(enabled, isCustomLocationSource);
}
+ /**
+ * Save the view instance state, for internal use only.
+ *
+ * @return the marshaled representation of the view state
+ */
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
@@ -415,6 +498,11 @@ public class MyLocationView extends View {
return bundle;
}
+ /**
+ * Restore the view instance state, for internal use only.
+ *
+ * @param state the marshalled representation of the state to restore
+ */
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
@@ -430,7 +518,7 @@ public class MyLocationView extends View {
}
/**
- * Enabled / Disable GPS location updates along with updating the UI
+ * Enabled / Disable GPS location updates along with updating the UI, for internal use only.
*
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
*/
@@ -463,10 +551,20 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Get the current location.
+ *
+ * @return the current location
+ */
public Location getLocation() {
return location;
}
+ /**
+ * Set the current location, for internal use only.
+ *
+ * @param location The current location
+ */
public void setLocation(Location location) {
if (location == null) {
this.location = null;
@@ -482,10 +580,20 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Set location change animation enabled, for internal use only.
+ *
+ * @param locationChangeAnimationEnabled True if location changes are animated
+ */
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
}
+ /**
+ * Set the bearing tracking mode, for internal use only.
+ *
+ * @param myBearingTrackingMode The bearing tracking mode
+ */
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
this.myBearingTrackingMode = myBearingTrackingMode;
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
@@ -502,6 +610,11 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Set the location tracking mode, for internla use only.
+ *
+ * @param myLocationTrackingMode The location tracking mode
+ */
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
MyLocationBehaviorFactory factory = new MyLocationBehaviorFactory();
myLocationBehavior = factory.getBehavioralModel(myLocationTrackingMode);
@@ -522,17 +635,32 @@ public class MyLocationView extends View {
invalidate();
}
+ /**
+ * Get the location tracking mode, for internal use only.
+ *
+ * @return The location tracking mode
+ */
@MyLocationTracking.Mode
public int getMyLocationTrackingMode() {
return myLocationTrackingMode;
}
+ /**
+ * Get the bearing tracking mode, for internal use only.
+ *
+ * @return the bearing tracking mode
+ */
@MyBearingTracking.Mode
public int getMyBearingTrackingMode() {
return myBearingTrackingMode;
}
+ /**
+ * Set the compass bearing value, for internal use only.
+ *
+ * @param bearing The compas bearing value
+ */
private void setCompass(double bearing) {
setCompass(bearing, 0 /* no animation */);
}
@@ -560,14 +688,29 @@ public class MyLocationView extends View {
directionAnimator.start();
}
+ /**
+ * Get the center of this view in screen coordinates.
+ *
+ * @return the center of the view
+ */
public PointF getCenter() {
return new PointF(getCenterX(), getCenterY());
}
+ /**
+ * Get the x value of the center of this view.
+ *
+ * @return the x value of the center of the view
+ */
private float getCenterX() {
return (getX() + getMeasuredWidth()) / 2 + contentPaddingX - projectedX;
}
+ /**
+ * Get the y value of the center of this view.
+ *
+ * @return the y value of the center of the view
+ */
private float getCenterY() {
return (getY() + getMeasuredHeight()) / 2 + contentPaddingY - projectedY;
}
@@ -577,6 +720,11 @@ public class MyLocationView extends View {
contentPaddingY = (padding[1] - padding[3]) / 2;
}
+ /**
+ * Set the location source from which location updates are received, for internal use only.
+ *
+ * @param locationSource The location source to receive updates from
+ */
public void setLocationSource(LocationEngine locationSource) {
toggleGps(false);
this.locationSource = locationSource;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index e9d823ebda..2ad1bf7ebc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -5,9 +5,9 @@ import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.FocalPointChangeListener;
-import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.Projection;
@@ -77,6 +77,11 @@ public class MyLocationViewSettings {
this.focalPointChangeListener = focalPointChangedListener;
}
+ /**
+ * Initialise this with MapboxMapOptions.
+ *
+ * @param options the options to initialise this class from
+ */
public void initialise(@NonNull MapboxMapOptions options) {
CameraPosition position = options.getCamera();
if (position != null && !position.equals(CameraPosition.DEFAULT)) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
index 7be56fa694..a1bd98b780 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
@@ -24,7 +24,10 @@ public class ConnectivityReceiver extends BroadcastReceiver {
private static ConnectivityReceiver INSTANCE;
/**
- * Get or create the singleton instance
+ * Get a single instance of ConnectivityReceiver.
+ *
+ * @param context the context to extract the application context from
+ * @return single instance of ConnectivityReceiver
*/
public static synchronized ConnectivityReceiver instance(Context context) {
if (INSTANCE == null) {
@@ -74,7 +77,7 @@ public class ConnectivityReceiver extends BroadcastReceiver {
}
/**
- * @see BroadcastReceiver#onReceive(Context, Intent)
+ * {@inheritDoc}
*/
@Override
public void onReceive(Context context, Intent intent) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 95cb7d66c4..d572d696db 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -115,6 +115,12 @@ public class OfflineManager {
}).start();
}
+ /**
+ * Get the single instance of offline manager.
+ *
+ * @param context the context used to host the offline manager
+ * @return the single instance of offline manager
+ */
public static synchronized OfflineManager getInstance(Context context) {
if (instance == null) {
instance = new OfflineManager(context);
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 baa815491f..1c78d5979e 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
@@ -393,6 +393,7 @@ public class OfflineRegion {
* After you call this method, you may not call any additional methods on this object.
*
*
+ * @param bytes the metadata in bytes
* @param callback the callback to be invoked
*/
public void updateMetadata(@NonNull final byte[] bytes, @NonNull final OfflineRegionUpdateMetadataCallback callback) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
index 9c3655fbec..fe12dd46c4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
@@ -7,6 +7,7 @@ package com.mapbox.mapboxsdk.offline;
*
* Note that the total required size in bytes is not currently available. A
* future API release may provide an estimate of this number.
+ *
*/
public class OfflineRegionStatus {
@@ -51,6 +52,7 @@ public class OfflineRegionStatus {
* Specifically, it is false during early phases of an offline download. Once
* style and tile sources have been downloaded, it is possible to calculate the
* precise number of required resources, at which point it is set to true.
+ *
*/
private boolean requiredResourceCountIsPrecise = true;
@@ -73,37 +75,93 @@ public class OfflineRegionStatus {
}
/**
- * Is the region complete?
+ * Validates if the region download has completed
+ *
+ * @return true if download is complete, false if not
*/
public boolean isComplete() {
return (completedResourceCount == requiredResourceCount);
}
+ /**
+ * Returns the download state.
+ *
+ * State is defined as
+ *
+ *
+ *
{@link OfflineRegion#STATE_ACTIVE}
+ *
{@link OfflineRegion#STATE_INACTIVE}
+ *
+ *
+ * @return the download state.
+ */
@OfflineRegion.DownloadState
public int getDownloadState() {
return downloadState;
}
+ /**
+ * Get the number of resources (inclusive of tiles) that have been fully downloaded
+ * and are ready for offline access.
+ *
+ * @return the amount of resources that have finished downloading.
+ */
public long getCompletedResourceCount() {
return completedResourceCount;
}
+ /**
+ * The cumulative size, in bytes, of all resources (inclusive of tiles) that have
+ * been fully downloaded.
+ *
+ * @return the size of the resources that have finished downloading
+ */
public long getCompletedResourceSize() {
return completedResourceSize;
}
+ /**
+ * Get the number of tiles that have been fully downloaded and are ready for
+ * offline access.
+ *
+ * @return the completed tile count
+ */
public long getCompletedTileCount() {
return completedTileCount;
}
+ /**
+ * Get the cumulative size, in bytes, of all tiles that have been fully downloaded.
+ *
+ * @return the completed tile size
+ */
public long getCompletedTileSize() {
return completedTileSize;
}
+ /**
+ * Get the number of resources that are known to be required for this region. See the
+ * documentation for `requiredResourceCountIsPrecise` for an important caveat
+ * about this number.
+ *
+ * @return the amount of resources that are required
+ */
public long getRequiredResourceCount() {
return requiredResourceCount;
}
+ /**
+ * Returns when the value of requiredResourceCount is a precise
+ * count of the number of required resources, and false when it is merely a lower
+ * bound.
+ *
+ * Specifically, it is false during early phases of an offline download. Once
+ * style and tile sources have been downloaded, it is possible to calculate the
+ * precise number of required resources, at which point it is set to true.
+ *
+ *
+ * @return True if the required resource count is precise, false if not
+ */
public boolean isRequiredResourceCountPrecise() {
return requiredResourceCountIsPrecise;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
index 06676d76a1..eafef80e8d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
@@ -3,9 +3,9 @@ package com.mapbox.mapboxsdk.storage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
import android.os.Environment;
import android.support.annotation.NonNull;
-import android.content.res.AssetManager;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -28,8 +28,9 @@ public class FileSource {
/**
* Called whenever a URL needs to be transformed.
*
- * @param kind The kind of URL to be transformed.
- * @return A URL that will now be downloaded.
+ * @param kind the kind of URL to be transformed.
+ * @param url the URL to be transformed
+ * @return a URL that will now be downloaded.
*/
String onURL(@Resource.Kind int kind, String url);
@@ -38,6 +39,12 @@ public class FileSource {
// File source instance is kept alive after initialization
private static FileSource INSTANCE;
+ /**
+ * Get the single instance of FileSource.
+ *
+ * @param context the context to derive the cache path from
+ * @return the single instance of FileSource
+ */
public static synchronized FileSource getInstance(Context context) {
if (INSTANCE == null) {
String cachePath = getCachePath(context);
@@ -47,6 +54,12 @@ public class FileSource {
return INSTANCE;
}
+ /**
+ * Get the cache path for a context.
+ *
+ * @param context the context to derive the cache path from
+ * @return the cache path
+ */
public static String getCachePath(Context context) {
// Default value
boolean setStorageExternal = MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java
index 68727c8a4f..a57c440df4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyValue.java
@@ -30,14 +30,29 @@ public class PropertyValue {
this.value = value;
}
+ /**
+ * Returns if this is null
+ *
+ * @return true if this is null, false if not
+ */
public boolean isNull() {
return value == null;
}
+ /**
+ * Returns if this is a function.
+ *
+ * @return true if is a function, false if not
+ */
public boolean isFunction() {
return !isNull() && value instanceof Function;
}
+ /**
+ * Returns if this is a value.
+ *
+ * @return true if is a value, false if not
+ */
public boolean isValue() {
return !isNull() && !isFunction();
}
@@ -53,6 +68,11 @@ public class PropertyValue {
}
}
+ /**
+ * Get the value of the property.
+ *
+ * @return the property value
+ */
@Nullable
public T getValue() {
if (isValue()) {
@@ -64,6 +84,11 @@ public class PropertyValue {
}
}
+ /**
+ * Get the color int value of the property if the value is a color.
+ *
+ * @return the color int value of the property, null if not a color value
+ */
@ColorInt
@Nullable
public Integer getColorInt() {
@@ -80,6 +105,11 @@ public class PropertyValue {
}
}
+ /**
+ * Get the string representation of a property value.
+ *
+ * @return the string representation
+ */
@Override
public String toString() {
return String.format("%s: %s", name, value);
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
index b66a50b8a4..cb6465a6b1 100644
--- 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
@@ -13,7 +13,7 @@ import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
/**
* The global light source.
*
- * @see The online documentation
+ * @see The online documentation
*/
@UiThread
public class Light {
@@ -43,7 +43,8 @@ public class Light {
*
* @return anchor as String
*/
- @Property.ANCHOR public String getAnchor() {
+ @Property.ANCHOR
+ public String getAnchor() {
return nativeGetAnchor();
}
@@ -106,7 +107,7 @@ public class Light {
*
* @return color as String
*/
- public String getColor() {
+ public String getColor() {
return nativeGetColor();
}
@@ -142,7 +143,7 @@ public class Light {
*
* @return intensity as Float
*/
- public float getIntensity() {
+ public float getIntensity() {
return nativeGetIntensity();
}
@@ -165,17 +166,30 @@ public class Light {
}
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
index 215db03ad2..cd6218d3e2 100644
--- 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
@@ -18,7 +18,7 @@ public class Position {
private float polarAngle;
/**
- * Creates a Position from a radial coordinate, an azimuthal angle & a polar angle.
+ * Creates a Position from a radial coordinate, an azimuthal angle and 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°
@@ -31,7 +31,7 @@ public class Position {
}
/**
- * Returns a Position from a radial coordinate, an azimuthal angle & a polar angle
+ * Returns a Position from a radial coordinate, an azimuthal angle and a polar angle
*
* @param radialCoordinate the radial coordinate
* @param azimuthalAngle the azimuthal angle
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
index 067efe1092..80d927128d 100644
--- 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
@@ -17,7 +17,7 @@ import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
/**
* The global light source.
*
- * @see The online documentation
+ * @see The online documentation
*/
@UiThread
public class Light {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
index e3fc765734..af3a79539f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java
@@ -5,8 +5,17 @@ import android.graphics.Canvas;
import android.support.annotation.NonNull;
import android.view.View;
+/**
+ * Utility class for creating bitmaps
+ */
public class BitmapUtils {
+ /**
+ * Convert a view to a bitmap.
+ *
+ * @param view the view to convert
+ * @return the converted bitmap
+ */
public static Bitmap createBitmapFromView(@NonNull View view) {
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
@@ -22,6 +31,13 @@ public class BitmapUtils {
return snapshot;
}
+ /**
+ * Create a bitmap from a background and a foreground bitmap
+ *
+ * @param background The bitmap placed in the background
+ * @param foreground The bitmap placed in the foreground
+ * @return the merged bitmap
+ */
public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) {
Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig());
Canvas canvas = new Canvas(result);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
index 24c76243d9..14b18b00dc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
@@ -23,7 +23,7 @@ import java.util.regex.Pattern;
public class ColorUtils {
/**
- * Returns a color integer associated as primary color from a theme based on a {@link Context}.
+ * Returns a color integer associated as primary color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The primary color value of current theme in the form 0xAARRGGBB.
@@ -37,7 +37,7 @@ public class ColorUtils {
}
/**
- * Returns a color integer associated as primary dark color from a theme based on a {@link Context}.
+ * Returns a color integer associated as primary dark color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The primary dark color value of current theme in the form 0xAARRGGBB.
@@ -51,7 +51,7 @@ public class ColorUtils {
}
/**
- * Returns a color integer associated as accent color from a theme based on a {@link Context}.
+ * Returns a color integer associated as accent color from a theme based on a Context.
*
* @param context The context used to style the color attributes.
* @return The accent color value of current theme in the form 0xAARRGGBB.
@@ -65,7 +65,7 @@ public class ColorUtils {
}
/**
- * Returns a color state list associated with a theme based on a {@link Context}
+ * Returns a color state list associated with a theme based on a Context.
*
* @param color The color used for tinting.
* @return A ColorStateList object containing the primary color of a theme
@@ -85,7 +85,7 @@ public class ColorUtils {
}
/**
- * Set a color tint list to the {@link Drawable} of an {@link ImageView}.
+ * Set a color tint list to the Drawable of an ImageView.
*
* @param imageView The view to set the default tint list.
* @param tintColor The color to tint.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MapFragmentUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MapFragmentUtils.java
index f810d6231d..007880acd1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MapFragmentUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/MapFragmentUtils.java
@@ -18,12 +18,25 @@ import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
*/
public class MapFragmentUtils {
+ /**
+ * Convert MapboxMapOptions to a bundle of fragment arguments.
+ *
+ * @param options The MapboxMapOptions to convert
+ * @return a bundle of converted fragment arguments
+ */
public static Bundle createFragmentArgs(MapboxMapOptions options) {
Bundle bundle = new Bundle();
bundle.putParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS, options);
return bundle;
}
+ /**
+ * Convert a bundle of fragment arguments to MapboxMapOptions.
+ *
+ * @param context The context of the activity hosting the fragment
+ * @param args The fragment arguments
+ * @return converted MapboxMapOptions
+ */
public static MapboxMapOptions resolveArgs(Context context, Bundle args) {
MapboxMapOptions options;
if (args != null && args.containsKey(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS)) {
--
cgit v1.2.1
From a35b268606b6becf218286036e4d1cfc22ddcaa3 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 26 Jun 2017 10:36:26 -0700
Subject: [android] remove tile cache size customization
---
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 24 ++--------------------
1 file changed, 2 insertions(+), 22 deletions(-)
(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 c0586a6449..a88a11d387 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
@@ -1,11 +1,9 @@
package com.mapbox.mapboxsdk.maps;
-import android.app.ActivityManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
-import android.os.Build;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -78,27 +76,11 @@ final class NativeMapView {
fileSource = FileSource.getInstance(context);
pixelRatio = context.getResources().getDisplayMetrics().density;
- int availableProcessors = Runtime.getRuntime().availableProcessors();
- ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
- ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- activityManager.getMemoryInfo(memoryInfo);
- long totalMemory = memoryInfo.availMem;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- totalMemory = memoryInfo.totalMem;
- }
-
- if (availableProcessors < 0) {
- throw new IllegalArgumentException("availableProcessors cannot be negative.");
- }
-
- if (totalMemory < 0) {
- throw new IllegalArgumentException("totalMemory cannot be negative.");
- }
onMapChangedListeners = new CopyOnWriteArrayList<>();
this.mapView = mapView;
String programCacheDir = context.getCacheDir().getAbsolutePath();
- nativeInitialize(this, fileSource, pixelRatio, programCacheDir, availableProcessors, totalMemory);
+ nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
}
//
@@ -941,9 +923,7 @@ final class NativeMapView {
private native void nativeInitialize(NativeMapView nativeMapView,
FileSource fileSource,
float pixelRatio,
- String programCacheDir,
- int availableProcessors,
- long totalMemory);
+ String programCacheDir);
private native void nativeDestroy();
--
cgit v1.2.1
From 200d184738a2a5c8e7cb19a0f5eaa06d34cb1774 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 29 Jun 2017 09:29:23 +0200
Subject: OnCameraIdle hook into quickzoom gesture (#9339)
* [android] - OnCameraIdle hook into quickzoom gesture
* double tap fix
* show MyLocationView bearing for GPS when Compass is not available, only show error about missing compass once, fix test activity.
* fix accessor lint warning
---
.../mapboxsdk/maps/CameraChangeDispatcher.java | 8 +++++---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 21 +++++++++++++++++----
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 7 +++++--
.../mapboxsdk/maps/widgets/MyLocationView.java | 18 ++++++++++++------
4 files changed, 39 insertions(+), 15 deletions(-)
(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
index bd028aecb6..6f7d7c0080 100644
--- 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
@@ -2,8 +2,8 @@ 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;
+import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, MapboxMap.OnCameraMoveListener,
MapboxMap.OnCameraMoveCanceledListener, OnCameraIdleListener {
@@ -59,9 +59,11 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
@Override
public void onCameraIdle() {
- if (onCameraIdleListener != null && !idle) {
+ if (!idle) {
idle = true;
- onCameraIdleListener.onCameraIdle();
+ if (onCameraIdleListener != null) {
+ 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 5346baa4e2..3607703ab1 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
@@ -57,6 +57,7 @@ final class MapGestureDetector {
private boolean quickZoom = false;
private boolean scrollInProgress = false;
private boolean scaleGestureOccurred = false;
+ private boolean recentScaleGestureOccurred = false;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -148,7 +149,7 @@ final class MapGestureDetector {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// First pointer down, reset scaleGestureOccurred, used to avoid triggering a fling after a scale gesture #7666
- scaleGestureOccurred = false;
+ recentScaleGestureOccurred = false;
transform.setGestureInProgress(true);
break;
@@ -274,7 +275,7 @@ final class MapGestureDetector {
break;
case MotionEvent.ACTION_UP:
if (quickZoom) {
- // insert here?
+ cameraChangeDispatcher.onCameraIdle();
quickZoom = false;
break;
}
@@ -341,7 +342,7 @@ final class MapGestureDetector {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || scaleGestureOccurred) {
+ if ((!trackingSettings.isScrollGestureCurrentlyEnabled()) || recentScaleGestureOccurred) {
// don't allow a fling is scroll is disabled
// and ignore when a scale gesture has occurred
return false;
@@ -392,12 +393,17 @@ final class MapGestureDetector {
return false;
}
+ if (scaleGestureOccurred) {
+ return false;
+ }
+
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));
@@ -432,6 +438,7 @@ final class MapGestureDetector {
}
scaleGestureOccurred = true;
+ recentScaleGestureOccurred = true;
beginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
@@ -442,9 +449,11 @@ final class MapGestureDetector {
// Called when fingers leave screen
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
+ scaleGestureOccurred = false;
beginTime = 0;
scaleFactor = 1.0f;
zoomStarted = false;
+ cameraChangeDispatcher.onCameraIdle();
}
// Called each time a finger moves
@@ -480,6 +489,9 @@ final class MapGestureDetector {
}
// Gesture is a quickzoom if there aren't two fingers
+ if (!quickZoom && !twoTap) {
+ cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+ }
quickZoom = !twoTap;
// make an assumption here; if the zoom center is specified by the gesture, it's NOT going
@@ -492,6 +504,7 @@ final class MapGestureDetector {
// arround user provided focal point
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
+ cameraChangeDispatcher.onCameraMove();
// clamp scale factors we feed to core #7514
float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
@@ -553,7 +566,7 @@ final class MapGestureDetector {
// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
totalAngle += detector.getRotationDegreesDelta();
- if (!zoomStarted && ((totalAngle > 20.0f) || (totalAngle < -20.0f))) {
+ if (totalAngle > 20.0f || totalAngle < -20.0f) {
started = true;
}
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 89fbb79504..d788b7772b 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
@@ -215,6 +215,9 @@ final class Transform implements MapView.OnMapChangedListener {
if (cameraPosition != null) {
int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
setZoom(newZoom, focalPoint, MapboxConstants.ANIMATION_DURATION);
+ } else {
+ // we are not transforming, notify about being idle
+ cameraChangeDispatcher.onCameraIdle();
}
}
@@ -227,8 +230,8 @@ final class Transform implements MapView.OnMapChangedListener {
@Override
public void onMapChanged(int change) {
if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
- mapView.removeOnMapChangedListener(this);
cameraChangeDispatcher.onCameraIdle();
+ mapView.removeOnMapChangedListener(this);
}
}
});
@@ -327,7 +330,7 @@ final class Transform implements MapView.OnMapChangedListener {
mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
@Override
public void onMapChanged(int change) {
- if (change == MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED) {
+ if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
mapView.removeOnMapChangedListener(this);
cameraChangeDispatcher.onCameraIdle();
}
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 72868a91d8..8b6b93e03a 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
@@ -348,12 +348,17 @@ public class MyLocationView extends View {
}
// draw foreground
- if (myBearingTrackingMode == MyBearingTracking.NONE || !compassListener.isSensorAvailable()) {
+ if (myBearingTrackingMode == MyBearingTracking.NONE) {
if (foregroundDrawable != null) {
foregroundDrawable.draw(canvas);
}
} else if (foregroundBearingDrawable != null && foregroundBounds != null) {
- foregroundBearingDrawable.draw(canvas);
+ if (myBearingTrackingMode == MyBearingTracking.GPS || compassListener.isSensorAvailable()) {
+ foregroundBearingDrawable.draw(canvas);
+ } else {
+ // We are tracking MyBearingTracking.COMPASS, but sensor is not available.
+ foregroundDrawable.draw(canvas);
+ }
}
}
@@ -774,9 +779,9 @@ public class MyLocationView extends View {
private final SensorManager sensorManager;
private Sensor rotationVectorSensor;
- float[] matrix = new float[9];
- float[] orientation = new float[3];
-
+ private float[] matrix = new float[9];
+ private float[] orientation = new float[3];
+ private boolean reportMissingSensor = true;
// Compass data
private long compassUpdateNextTimestamp = 0;
@@ -794,7 +799,8 @@ public class MyLocationView extends View {
}
public boolean isSensorAvailable() {
- if (rotationVectorSensor == null) {
+ if (rotationVectorSensor == null && reportMissingSensor) {
+ reportMissingSensor = false;
Timber.e("Sensor.TYPE_ROTATION_VECTOR is missing from this device. Unable to use MyBearingTracking.COMPASS.");
}
return rotationVectorSensor != null;
--
cgit v1.2.1
From f836425be467ac9830d8f6b4caa98700ce87c19b Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 29 Jun 2017 13:36:59 +0200
Subject: [android] - keep state of initial overlain views margins (#9391)
---
.../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 45 ++++++++++++++--------
1 file changed, 29 insertions(+), 16 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 5f7b6c571b..285cd18089 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
@@ -37,8 +37,14 @@ public final class UiSettings {
private final FocalPointChangeListener focalPointChangeListener;
private final Projection projection;
private final CompassView compassView;
+ private final int[] compassMargins = new int[4];
+
private final ImageView attributionsView;
+ private final int[] attributionsMargins = new int[4];
+
private final View logoView;
+ private final int[] logoMargins = new int[4];
+
private float pixelRatio;
private boolean rotateGesturesEnabled = true;
@@ -370,7 +376,7 @@ public final class UiSettings {
*/
@UiThread
public void setCompassMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(compassView, left, top, right, bottom);
+ setWidgetMargins(compassView, compassMargins, left, top, right, bottom);
}
/**
@@ -379,7 +385,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getCompassMarginLeft() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).leftMargin;
+ return compassMargins[0];
}
/**
@@ -388,7 +394,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getCompassMarginTop() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).topMargin;
+ return compassMargins[1];
}
/**
@@ -397,7 +403,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getCompassMarginRight() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).rightMargin;
+ return compassMargins[2];
}
/**
@@ -406,7 +412,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getCompassMarginBottom() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin;
+ return compassMargins[3];
}
/**
@@ -480,7 +486,7 @@ public final class UiSettings {
* @param bottom The bottom margin in pixels.
*/
public void setLogoMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(logoView, left, top, right, bottom);
+ setWidgetMargins(logoView, logoMargins, left, top, right, bottom);
}
/**
@@ -489,7 +495,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getLogoMarginLeft() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).leftMargin;
+ return logoMargins[0];
}
/**
@@ -498,7 +504,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getLogoMarginTop() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).topMargin;
+ return logoMargins[1];
}
/**
@@ -507,7 +513,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getLogoMarginRight() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).rightMargin;
+ return logoMargins[2];
}
/**
@@ -516,7 +522,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getLogoMarginBottom() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).bottomMargin;
+ return logoMargins[3];
}
/**
@@ -571,7 +577,7 @@ public final class UiSettings {
* @param bottom The bottom margin in pixels.
*/
public void setAttributionMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(attributionsView, left, top, right, bottom);
+ setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom);
}
/**
@@ -598,7 +604,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getAttributionMarginLeft() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).leftMargin;
+ return attributionsMargins[0];
}
/**
@@ -607,7 +613,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getAttributionMarginTop() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).topMargin;
+ return attributionsMargins[1];
}
/**
@@ -616,7 +622,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getAttributionMarginRight() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).rightMargin;
+ return attributionsMargins[2];
}
/**
@@ -625,7 +631,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getAttributionMarginBottom() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).bottomMargin;
+ return attributionsMargins[3];
}
/**
@@ -929,7 +935,14 @@ public final class UiSettings {
view.setLayoutParams(layoutParams);
}
- private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) {
+ private void setWidgetMargins(@NonNull final View view, int[] initMargins, int left, int top, int right, int bottom) {
+ // keep state of initially set margins
+ initMargins[0] = left;
+ initMargins[1] = top;
+ initMargins[2] = right;
+ initMargins[3] = bottom;
+
+ // convert inital margins with padding
int[] contentPadding = projection.getContentPadding();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
left += contentPadding[0];
--
cgit v1.2.1
From 95735c06f6c394bde67532913fd7b51b2938cbc1 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 30 Jun 2017 11:21:39 +0200
Subject: Downgrade location provider dependency (#9394)
* [android] - downgrade LOST to Mapbox SDK 5.0.2 version.
* bump LOST back to Mapbox Android SDK version 4.x
---
platform/android/MapboxGLAndroidSDK/build.gradle | 4 ++-
.../mapbox/mapboxsdk/location/LocationSource.java | 33 ++++++----------------
2 files changed, 11 insertions(+), 26 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 5e19e94f5d..018294d462 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 group: 'com.google.guava'
+ }
// 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 12e3300429..6652142be3 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
@@ -28,7 +28,7 @@ import com.mapzen.android.lost.api.LostApiClient;
* in the history stack.
*
*/
-public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener {
+public class LocationSource extends LocationEngine implements LocationListener {
private Context context;
private LostApiClient lostApiClient;
@@ -41,9 +41,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
public LocationSource(Context context) {
super();
this.context = context.getApplicationContext();
- lostApiClient = new LostApiClient.Builder(this.context)
- .addConnectionCallbacks(this)
- .build();
+ lostApiClient = new LostApiClient.Builder(this.context).build();
}
/**
@@ -55,6 +53,9 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
if (!lostApiClient.isConnected()) {
lostApiClient.connect();
}
+ for (LocationEngineListener listener : locationListeners) {
+ listener.onConnected();
+ }
}
/**
@@ -80,23 +81,6 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
return lostApiClient.isConnected();
}
- /**
- * Invoked when the location provider has connected.
- */
- @Override
- public void onConnected() {
- for (LocationEngineListener listener : locationListeners) {
- listener.onConnected();
- }
- }
-
- /**
- * Invoked when the location provider connection has been suspended.
- */
- @Override
- public void onConnectionSuspended() {
- }
-
/**
* Returns the Last known location is the location provider is connected and location permissions are granted.
*
@@ -107,9 +91,8 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
public Location getLastLocation() {
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
- return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
+ return LocationServices.FusedLocationApi.getLastLocation();
}
-
return null;
}
@@ -137,7 +120,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
//noinspection MissingPermission
- LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
+ LocationServices.FusedLocationApi.requestLocationUpdates(request, this);
}
}
@@ -147,7 +130,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
- LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
+ LocationServices.FusedLocationApi.removeLocationUpdates(this);
}
}
--
cgit v1.2.1
From d2d8a575be2d4f28894c0c1f845cbb464869d97c Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Sat, 1 Jul 2017 17:38:44 +0200
Subject: [android] - update changelog for 5.1.0 release (#9405)
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
.../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 9f555da5f8..078fdbc801 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.1.0-SNAPSHOT
+VERSION_NAME=5.2.0-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
index bc0350fe1f..029d25e046 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
+++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
@@ -1,3 +1,3 @@
fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk
-fabric-version=5.0.1
+fabric-version=5.1.0
fabric-build-type=binary
--
cgit v1.2.1
From eb7926d20572c19363568f53c117cf8eb1b373d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Wed, 5 Jul 2017 17:32:23 +0200
Subject: [android] - invible marker views performance fix #9419 (#9420)
---
.../main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.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/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index 6d42842b7d..dce6f6b277 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -198,7 +198,7 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
// ensure view is measured first
// #6805 invalidate marker views to ensure convertView width and height
// values are properly measured and up to date
- if (marker.getWidth() == 0) {
+ if (marker.getWidth() == 0 && marker.isVisible()) {
convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver);
}
}
--
cgit v1.2.1
From 9ab04a29655014f1df24e269ce53942c934c8333 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Wed, 5 Jul 2017 17:32:23 +0200
Subject: [android] - invible marker views performance fix #9419 (#9420)
---
.../main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.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/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index 6d42842b7d..dce6f6b277 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -198,7 +198,7 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
// ensure view is measured first
// #6805 invalidate marker views to ensure convertView width and height
// values are properly measured and up to date
- if (marker.getWidth() == 0) {
+ if (marker.getWidth() == 0 && marker.isVisible()) {
convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver);
}
}
--
cgit v1.2.1
From adbce36fe6e1a9d95633776ff9fada67289733ae Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 6 Jul 2017 11:26:03 +0200
Subject: [android] Fix my location drawable getting tinted (#9410)
* fix my location drawable tinted when setting mapbox_myLocationTintColor in xml issue (linking my location foreground drawables with my location foreground tint color and adding the possibility of setting an undefined my location foreground tint color)
* link my location background drawable with my location background tint color and add the possibility of setting an undefined my location background tint color
---
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 21 ++++++++-------
.../mapboxsdk/maps/widgets/MyLocationView.java | 31 +++++++++++++++++-----
.../maps/widgets/MyLocationViewSettings.java | 10 +++++--
3 files changed, 44 insertions(+), 18 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 2efed1b322..80b25bf0de 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
@@ -4,7 +4,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
@@ -37,6 +36,7 @@ public class MapboxMapOptions implements Parcelable {
private static final float FOUR_DP = 4f;
private static final float NINETY_TWO_DP = 92f;
+ private static final int UNDEFINED_COLOR = -1;
private CameraPosition cameraPosition;
@@ -53,7 +53,7 @@ public class MapboxMapOptions implements Parcelable {
private int[] logoMargins;
@ColorInt
- private int attributionTintColor = -1;
+ private int attributionTintColor = UNDEFINED_COLOR;
private boolean attributionEnabled = true;
private int attributionGravity = Gravity.BOTTOM;
private int[] attributionMargins;
@@ -72,8 +72,10 @@ public class MapboxMapOptions implements Parcelable {
private Drawable myLocationForegroundDrawable;
private Drawable myLocationForegroundBearingDrawable;
private Drawable myLocationBackgroundDrawable;
- private int myLocationForegroundTintColor;
- private int myLocationBackgroundTintColor;
+ @ColorInt
+ private int myLocationForegroundTintColor = UNDEFINED_COLOR;
+ @ColorInt
+ private int myLocationBackgroundTintColor = UNDEFINED_COLOR;
private int[] myLocationBackgroundPadding;
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
@@ -234,7 +236,7 @@ public class MapboxMapOptions implements Parcelable {
FOUR_DP * pxlRatio))});
mapboxMapOptions.attributionTintColor(typedArray.getColor(
- R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1));
+ R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, UNDEFINED_COLOR));
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(
R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
mapboxMapOptions.attributionGravity(typedArray.getInt(
@@ -251,10 +253,9 @@ public class MapboxMapOptions implements Parcelable {
mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false));
mapboxMapOptions.myLocationForegroundTintColor(
- typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor,
- ColorUtils.getPrimaryColor(context)));
+ typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor, UNDEFINED_COLOR));
mapboxMapOptions.myLocationBackgroundTintColor(
- typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, Color.WHITE));
+ typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, UNDEFINED_COLOR));
Drawable foregroundDrawable = typedArray.getDrawable(R.styleable.mapbox_MapView_mapbox_myLocationDrawable);
if (foregroundDrawable == null) {
@@ -638,7 +639,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Set the background tint color of MyLocationView.
*
- * @param myLocationBackgroundTintColor the color to tint the background
+ * @param myLocationBackgroundTintColor the color to tint the background drawable
* @return This
*/
public MapboxMapOptions myLocationBackgroundTintColor(@ColorInt int myLocationBackgroundTintColor) {
@@ -944,6 +945,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return the tint color
*/
+ @ColorInt
public int getMyLocationForegroundTintColor() {
return myLocationForegroundTintColor;
}
@@ -953,6 +955,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return the tint color
*/
+ @ColorInt
public int getMyLocationBackgroundTintColor() {
return myLocationBackgroundTintColor;
}
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 8b6b93e03a..24da59bb7e 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
@@ -51,6 +51,7 @@ import timber.log.Timber;
*/
public class MyLocationView extends View {
+ private static final int UNDEFINED_TINT_COLOR = -1;
private MyLocationBehavior myLocationBehavior;
private MapboxMap mapboxMap;
@@ -198,12 +199,8 @@ public class MyLocationView extends View {
* @param color The color to tint the drawable with
*/
public final void setForegroundDrawableTint(@ColorInt int color) {
- if (foregroundDrawable != null) {
- foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
- }
- if (foregroundBearingDrawable != null) {
- foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
- }
+ applyDrawableTint(foregroundDrawable, color);
+ applyDrawableTint(foregroundBearingDrawable, color);
invalidate();
}
@@ -247,7 +244,7 @@ public class MyLocationView extends View {
if (backgroundDrawable == null) {
return;
}
- backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ applyDrawableTint(backgroundDrawable, color);
invalidate();
}
@@ -737,6 +734,26 @@ public class MyLocationView extends View {
setEnabled(isEnabled(), locationSource != null);
}
+ private void applyDrawableTint(Drawable drawable, @ColorInt int color) {
+ if (color == UNDEFINED_TINT_COLOR) {
+ removeTintColorFilter(drawable);
+ } else {
+ applyTintColorFilter(drawable, color);
+ }
+ }
+
+ private void removeTintColorFilter(Drawable drawable) {
+ if (drawable != null) {
+ drawable.mutate().setColorFilter(null);
+ }
+ }
+
+ private void applyTintColorFilter(Drawable drawable, @ColorInt int color) {
+ if (drawable != null) {
+ drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ }
+ }
+
private static class GpsLocationListener implements LocationEngineListener {
private WeakReference userLocationView;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index 2ad1bf7ebc..fe2f18e4dd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -119,6 +119,7 @@ public class MyLocationViewSettings {
*
* The foreground drawable is the image visible on screen
*
+ * It's linked with the foreground tint color
*
* @param foregroundDrawable the drawable to show as foreground without bearing
* @param foregroundBearingDrawable the drawable to show as foreground when bearing is enabled
@@ -127,6 +128,7 @@ public class MyLocationViewSettings {
this.foregroundDrawable = foregroundDrawable;
this.foregroundBearingDrawable = foregroundBearingDrawable;
myLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
+ myLocationView.setForegroundDrawableTint(foregroundTintColor);
}
/**
@@ -153,7 +155,8 @@ public class MyLocationViewSettings {
* The color will tint both the foreground and the bearing foreground drawable.
*
*
- * @param foregroundTintColor the color to tint the foreground drawable
+ * @param foregroundTintColor the color to tint the foreground drawable or -1 (undefined color) to remove the
+ * existing foreground tint color
*/
public void setForegroundTintColor(@ColorInt int foregroundTintColor) {
this.foregroundTintColor = foregroundTintColor;
@@ -174,6 +177,7 @@ public class MyLocationViewSettings {
*
* Padding can be added to provide an offset to the background
*
+ * It's linked with the background tint color
*
* @param backgroundDrawable the drawable to show as background
* @param padding the padding added to the background
@@ -186,6 +190,7 @@ public class MyLocationViewSettings {
} else {
myLocationView.setShadowDrawable(backgroundDrawable);
}
+ myLocationView.setShadowDrawableTint(backgroundTintColor);
}
/**
@@ -200,7 +205,8 @@ public class MyLocationViewSettings {
/**
* Set the background tint color.
*
- * @param backgroundTintColor the color to tint the background
+ * @param backgroundTintColor the color to tint the background drawable or -1 (undefined color) to remove the
+ * existing background tint color
*/
public void setBackgroundTintColor(@ColorInt int backgroundTintColor) {
this.backgroundTintColor = backgroundTintColor;
--
cgit v1.2.1
From d5fbcb242acff2ab270b4018b01c2c6be9c4955f Mon Sep 17 00:00:00 2001
From: Chris Loer
Date: Wed, 5 Jul 2017 13:59:45 -0700
Subject: [core] Implement circle-pitch-alignment property Closes issue #9349.
---
.../mapbox/mapboxsdk/style/layers/CircleLayer.java | 12 ++++++++++++
.../mapbox/mapboxsdk/style/layers/Property.java | 21 +++++++++++++++++++++
.../mapboxsdk/style/layers/PropertyFactory.java | 22 ++++++++++++++++++++++
3 files changed, 55 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
index 1a7df06031..10663142b5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
@@ -277,6 +277,16 @@ public class CircleLayer extends Layer {
return (PropertyValue) new PropertyValue("circle-pitch-scale", nativeGetCirclePitchScale());
}
+ /**
+ * Get the CirclePitchAlignment property
+ *
+ * @return property wrapper value around String
+ */
+ @SuppressWarnings("unchecked")
+ public PropertyValue getCirclePitchAlignment() {
+ return (PropertyValue) new PropertyValue("circle-pitch-alignment", nativeGetCirclePitchAlignment());
+ }
+
/**
* Get the CircleStrokeWidth property
*
@@ -411,6 +421,8 @@ public class CircleLayer extends Layer {
private native Object nativeGetCirclePitchScale();
+ private native Object nativeGetCirclePitchAlignment();
+
private native Object nativeGetCircleStrokeWidth();
private native TransitionOptions nativeGetCircleStrokeWidthTransition();
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 5e345268f9..d3d0e060dc 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
@@ -446,6 +446,27 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface CIRCLE_PITCH_SCALE {}
+ // CIRCLE_PITCH_ALIGNMENT: Orientation of circle when map is pitched.
+
+ /**
+ * The circle is aligned to the plane of the map.
+ */
+ public static final String CIRCLE_PITCH_ALIGNMENT_MAP = "map";
+ /**
+ * The circle is aligned to the plane of the viewport.
+ */
+ public static final String CIRCLE_PITCH_ALIGNMENT_VIEWPORT = "viewport";
+
+ /**
+ * Orientation of circle when map is pitched.
+ */
+ @StringDef({
+ CIRCLE_PITCH_ALIGNMENT_MAP,
+ CIRCLE_PITCH_ALIGNMENT_VIEWPORT,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface CIRCLE_PITCH_ALIGNMENT {}
+
// FILL_EXTRUSION_TRANSLATE_ANCHOR: Controls the translation reference point.
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index 73896b7901..c12d6b7133 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -952,6 +952,28 @@ public class PropertyFactory {
return new PaintPropertyValue<>("circle-pitch-scale", function);
}
+ /**
+ * Orientation of circle when map is pitched.
+ *
+ * @param value a String value
+ * @return property wrapper around String
+ */
+ public static PropertyValue circlePitchAlignment(@Property.CIRCLE_PITCH_ALIGNMENT String value) {
+ return new PaintPropertyValue<>("circle-pitch-alignment", value);
+ }
+
+
+ /**
+ * Orientation of circle when map is pitched.
+ *
+ * @param the zoom parameter type
+ * @param function a wrapper {@link CameraFunction} for String
+ * @return property wrapper around a String function
+ */
+ public static PropertyValue> circlePitchAlignment(CameraFunction function) {
+ return new PaintPropertyValue<>("circle-pitch-alignment", function);
+ }
+
/**
* The width of the circle's stroke. Strokes are placed outside of the {@link PropertyFactory#circleRadius}.
*
--
cgit v1.2.1
From 957829e8c468a7fc70653f43302a59274be8c752 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 6 Jul 2017 21:04:30 +0200
Subject: [android] - validate if platform implementation doesn't return a null
motion event (#9434)
---
.../main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 3607703ab1..17eb506b97 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
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.PointF;
import android.location.Location;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
@@ -134,7 +133,12 @@ final class MapGestureDetector {
* @param event the MotionEvent
* @return True if touch event is handled
*/
- boolean onTouchEvent(@NonNull MotionEvent event) {
+ boolean onTouchEvent(MotionEvent event) {
+ // framework can return null motion events in edge cases #9432
+ if (event == null) {
+ return false;
+ }
+
// Check and ignore non touch or left clicks
if ((event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) {
return false;
--
cgit v1.2.1
From 721557bba2fd857974ff0908e2e673f70fd93aef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Thu, 6 Jul 2017 21:05:04 +0200
Subject: [android] - map's visible region fix #9427 (#9428)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index ff466c436c..e0a634521b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -80,10 +80,10 @@ public class Projection {
public VisibleRegion getVisibleRegion() {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
- float left = contentPadding[0];
- float right = nativeMapView.getWidth() - contentPadding[2];
- float top = contentPadding[1];
- float bottom = nativeMapView.getHeight() - contentPadding[3];
+ float left = 0;
+ float right = nativeMapView.getWidth();
+ float top = 0;
+ float bottom = nativeMapView.getHeight();
LatLng topLeft = fromScreenLocation(new PointF(left, top));
LatLng topRight = fromScreenLocation(new PointF(right, top));
--
cgit v1.2.1
From 2876db72f2d235a02e5670329c4f8dcb2a65a8ed Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 7 Jul 2017 12:28:19 +0200
Subject: Hit test Marker and MarkerViews (#9424)
* [android] - hit test Marker and MarkerViews
* fixup
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 201 +++++++++++++--------
.../com/mapbox/mapboxsdk/maps/IconManager.java | 4 +
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 2 +-
.../com/mapbox/mapboxsdk/maps/MarkerContainer.java | 1 +
4 files changed, 132 insertions(+), 76 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 7e7947047e..f3573c78ba 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
@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.maps;
+import android.graphics.Bitmap;
import android.graphics.PointF;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
+import android.view.View;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
@@ -18,7 +21,6 @@ import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
@@ -34,7 +36,6 @@ import java.util.List;
*/
class AnnotationManager {
- private final NativeMapView nativeMapView;
private final MapView mapView;
private final IconManager iconManager;
private final InfoWindowManager infoWindowManager = new InfoWindowManager();
@@ -52,7 +53,6 @@ class AnnotationManager {
AnnotationManager(NativeMapView view, MapView mapView, LongSparseArray annotationsArray,
MarkerViewManager markerViewManager, IconManager iconManager, Annotations annotations,
Markers markers, Polygons polygons, Polylines polylines) {
- this.nativeMapView = view;
this.mapView = mapView;
this.annotationsArray = annotationsArray;
this.markerViewManager = markerViewManager;
@@ -63,7 +63,7 @@ class AnnotationManager {
this.polylines = polylines;
if (view != null) {
// null checking needed for unit tests
- nativeMapView.addOnMapChangedListener(markerViewManager);
+ view.addOnMapChangedListener(markerViewManager);
}
}
@@ -329,84 +329,135 @@ class AnnotationManager {
// Click event
//
- boolean onTap(PointF tapPoint, float screenDensity) {
- float toleranceSides = 4 * screenDensity;
- float toleranceTopBottom = 10 * screenDensity;
- boolean handledDefaultClick = false;
-
- RectF tapRect = new RectF(tapPoint.x - iconManager.getAverageIconWidth() / 2 - toleranceSides,
- tapPoint.y - iconManager.getAverageIconHeight() / 2 - toleranceTopBottom,
- tapPoint.x + iconManager.getAverageIconWidth() / 2 + toleranceSides,
- tapPoint.y + iconManager.getAverageIconHeight() / 2 + toleranceTopBottom);
-
- List nearbyMarkers = getMarkersInRect(tapRect);
- long newSelectedMarkerId = -1;
-
- // find a Marker that isn't selected yet
- if (nearbyMarkers.size() > 0) {
- Collections.sort(nearbyMarkers);
- for (Marker nearbyMarker : nearbyMarkers) {
- boolean found = false;
- for (Marker selectedMarker : selectedMarkers) {
- if (selectedMarker.equals(nearbyMarker)) {
- found = true;
- }
- }
- if (!found) {
- newSelectedMarkerId = nearbyMarker.getId();
- break;
+ boolean onTap(PointF tapPoint) {
+ MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
+ long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit);
+ return markerId >= 0 && isClickHandledForMarker(markerId);
+ }
+
+ private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
+ int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
+ int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
+ final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset,
+ tapPoint.y - averageIconHeightOffset,
+ tapPoint.x + averageIconWidthOffset,
+ tapPoint.y + averageIconHeightOffset
+ );
+ return new MarkerHit(tapRect, getMarkersInRect(tapRect));
+ }
+
+ private boolean isClickHandledForMarker(long markerId) {
+ boolean handledDefaultClick;
+ Marker marker = (Marker) getAnnotation(markerId);
+ if (marker instanceof MarkerView) {
+ handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
+ } else {
+ handledDefaultClick = onClickMarker(marker);
+ }
+
+ if (!handledDefaultClick) {
+ setMarkerSelectionState(marker);
+ }
+ return true;
+ }
+
+ private boolean onClickMarker(Marker marker) {
+ return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker);
+ }
+
+ private void setMarkerSelectionState(Marker marker) {
+ if (!selectedMarkers.contains(marker)) {
+ selectMarker(marker);
+ } else {
+ deselectMarker(marker);
+ }
+ }
+
+ private static class MarkerHitResolver {
+
+ private final MarkerViewManager markerViewManager;
+ private final Projection projection;
+
+ private View view;
+ private Bitmap bitmap;
+ private PointF markerLocation;
+
+ private Rect hitRectView = new Rect();
+ private RectF hitRectMarker = new RectF();
+ private RectF highestSurfaceIntersection = new RectF();
+
+ private long closestMarkerId = -1;
+
+ MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) {
+ this.markerViewManager = markerViewManager;
+ this.projection = projection;
+ }
+
+ public long execute(MarkerHit markerHit) {
+ resolveForMarkers(markerHit);
+ return closestMarkerId;
+ }
+
+ private void resolveForMarkers(MarkerHit markerHit) {
+ for (Marker marker : markerHit.markers) {
+ if (marker instanceof MarkerView) {
+ resolveForMarkerView(markerHit, (MarkerView) marker);
+ } else {
+ resolveForMarker(markerHit, marker);
}
}
}
- // if unselected marker found
- if (newSelectedMarkerId >= 0) {
- List annotations = getAnnotations();
- int count = annotations.size();
- for (int i = 0; i < count; i++) {
- Annotation annotation = annotations.get(i);
- if (annotation instanceof Marker) {
- if (annotation.getId() == newSelectedMarkerId) {
- Marker marker = (Marker) annotation;
-
- if (marker instanceof MarkerView) {
- handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
- } else {
- if (onMarkerClickListener != null) {
- // end developer has provided a custom click listener
- handledDefaultClick = onMarkerClickListener.onMarkerClick(marker);
- }
- }
-
- if (!handledDefaultClick) {
- // only select marker if user didn't handle the click event themselves
- selectMarker(marker);
- }
-
- return true;
- }
- }
+ private void resolveForMarkerView(MarkerHit markerHit, MarkerView markerView) {
+ view = markerViewManager.getView(markerView);
+ if (view != null) {
+ view.getHitRect(hitRectView);
+ hitRectMarker = new RectF(hitRectView);
+ hitTestMarker(markerHit, markerView, hitRectMarker);
}
- } else if (nearbyMarkers.size() > 0) {
- // we didn't find an unselected marker, check if we can close an already open markers
- for (Marker nearbyMarker : nearbyMarkers) {
- for (Marker selectedMarker : selectedMarkers) {
- if (nearbyMarker.equals(selectedMarker)) {
- if (nearbyMarker instanceof MarkerView) {
- handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) nearbyMarker);
- } else if (onMarkerClickListener != null) {
- handledDefaultClick = onMarkerClickListener.onMarkerClick(nearbyMarker);
- }
-
- if (!handledDefaultClick) {
- // only deselect marker if user didn't handle the click event themselves
- deselectMarker(nearbyMarker);
- }
- return true;
- }
+ }
+
+ private void resolveForMarker(MarkerHit markerHit, Marker marker) {
+ markerLocation = projection.toScreenLocation(marker.getPosition());
+ bitmap = marker.getIcon().getBitmap();
+ hitRectMarker.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
+ hitRectMarker.offsetTo(
+ markerLocation.x - bitmap.getWidth() / 2,
+ markerLocation.y - bitmap.getHeight() / 2
+ );
+ hitTestMarker(markerHit, marker, hitRectMarker);
+ }
+
+ private void hitTestMarker(MarkerHit markerHit, Marker marker, RectF hitRectMarker) {
+ if (hitRectMarker.contains(markerHit.getTapPointX(), markerHit.getTapPointY())) {
+ hitRectMarker.intersect(markerHit.tapRect);
+ if (isRectangleHighestSurfaceIntersection(hitRectMarker)) {
+ highestSurfaceIntersection = new RectF(hitRectMarker);
+ closestMarkerId = marker.getId();
}
}
}
- return false;
+
+ private boolean isRectangleHighestSurfaceIntersection(RectF rectF) {
+ return rectF.width() * rectF.height() > highestSurfaceIntersection.width() * highestSurfaceIntersection.height();
+ }
+ }
+
+ private static class MarkerHit {
+ private final RectF tapRect;
+ private final List markers;
+
+ MarkerHit(RectF tapRect, List markers) {
+ this.tapRect = tapRect;
+ this.markers = markers;
+ }
+
+ float getTapPointX() {
+ return tapRect.centerX();
+ }
+
+ float getTapPointY() {
+ return tapRect.centerY();
+ }
}
}
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 9f4171aee8..b5da5f59aa 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
@@ -12,6 +12,8 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import java.util.ArrayList;
import java.util.List;
+import timber.log.Timber;
+
/**
* Responsible for managing icons added to the Map.
*
@@ -105,6 +107,8 @@ class IconManager {
int iconSize = icons.size() + 1;
averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize;
averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize;
+ Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height);
+ Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight);
}
private void loadIcon(Icon icon) {
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 17eb506b97..330e09cf32 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
@@ -315,7 +315,7 @@ final class MapGestureDetector {
@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
PointF tapPoint = new PointF(motionEvent.getX(), motionEvent.getY());
- boolean tapHandled = annotationManager.onTap(tapPoint, uiSettings.getPixelRatio());
+ boolean tapHandled = annotationManager.onTap(tapPoint);
if (!tapHandled) {
if (uiSettings.isDeselectMarkersOnTap()) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
index 306ad59b8d..ef8054d70e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
@@ -261,6 +261,7 @@ class MarkerContainer implements Markers {
if (icon == null) {
icon = IconFactory.getInstance(mapView.getContext()).defaultMarkerView();
}
+ iconManager.loadIconForMarkerView(marker);
marker.setIcon(icon);
return marker;
}
--
cgit v1.2.1
From 7d59e3f8b3a0b83833cd87eb8bfefa7d0856f0a9 Mon Sep 17 00:00:00 2001
From: Antonio Zugaldia
Date: Sun, 9 Jul 2017 11:16:18 -0400
Subject: [android] fix javadoc comment for public
setOfflineMapboxTileCountLimit method (#9454)
---
.../main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 1cf3711255..1e6f44f094 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -236,10 +236,11 @@ public class OfflineManager {
return LatLngBounds.world().contains(definition.getBounds());
}
- /*
- * Changing or bypassing this limit without permission from Mapbox is prohibited
- * by the Mapbox Terms of Service.
- */
+ /**
+ * Changing or bypassing this limit without permission from Mapbox is prohibited
+ * by the Mapbox Terms of Service.
+ * @param limit the new tile count limit.
+ */
public native void setOfflineMapboxTileCountLimit(long limit);
private native void initialize(FileSource fileSource);
--
cgit v1.2.1
From e8657becc56c2aee5b070357092da028e752d461 Mon Sep 17 00:00:00 2001
From: Chris Loer
Date: Tue, 11 Jul 2017 11:22:39 -0700
Subject: [core] Update shaders.
Implements 'icon-pitch-alignment' (issue #9345)
Fixes issue #9456 (map-aligned point label regression)
---
.../mapbox/mapboxsdk/style/layers/Property.java | 26 ++++++++++++++++++++++
.../mapboxsdk/style/layers/PropertyFactory.java | 23 +++++++++++++++++++
.../mapbox/mapboxsdk/style/layers/SymbolLayer.java | 12 ++++++++++
.../com/mapbox/mapboxsdk/style/light/Light.java | 20 +++--------------
4 files changed, 64 insertions(+), 17 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 d3d0e060dc..be24b65d27 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
@@ -160,6 +160,32 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface ICON_TEXT_FIT {}
+ // ICON_PITCH_ALIGNMENT: Orientation of icon when map is pitched.
+
+ /**
+ * The icon is aligned to the plane of the map.
+ */
+ public static final String ICON_PITCH_ALIGNMENT_MAP = "map";
+ /**
+ * The icon is aligned to the plane of the viewport.
+ */
+ public static final String ICON_PITCH_ALIGNMENT_VIEWPORT = "viewport";
+ /**
+ * Automatically matches the value of {@link ICON_ROTATION_ALIGNMENT}.
+ */
+ public static final String ICON_PITCH_ALIGNMENT_AUTO = "auto";
+
+ /**
+ * Orientation of icon when map is pitched.
+ */
+ @StringDef({
+ ICON_PITCH_ALIGNMENT_MAP,
+ ICON_PITCH_ALIGNMENT_VIEWPORT,
+ ICON_PITCH_ALIGNMENT_AUTO,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ICON_PITCH_ALIGNMENT {}
+
// TEXT_PITCH_ALIGNMENT: Orientation of text when map is pitched.
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index c12d6b7133..1c68878772 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -1881,6 +1881,29 @@ public class PropertyFactory {
return new LayoutPropertyValue<>("icon-offset", function);
}
+ /**
+ * Orientation of icon when map is pitched.
+ *
+ * @param value a String value
+ * @return property wrapper around String
+ */
+ public static PropertyValue iconPitchAlignment(@Property.ICON_PITCH_ALIGNMENT String value) {
+ return new LayoutPropertyValue<>("icon-pitch-alignment", value);
+ }
+
+
+
+ /**
+ * Orientation of icon when map is pitched.
+ *
+ * @param the zoom parameter type
+ * @param function a wrapper {@link CameraFunction} for String
+ * @return property wrapper around a String function
+ */
+ public static PropertyValue> iconPitchAlignment(CameraFunction function) {
+ return new LayoutPropertyValue<>("icon-pitch-alignment", function);
+ }
+
/**
* Orientation of text when map is pitched.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
index 290e162da8..fe81dcb638 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
@@ -251,6 +251,16 @@ public class SymbolLayer extends Layer {
return (PropertyValue) new PropertyValue("icon-offset", nativeGetIconOffset());
}
+ /**
+ * Get the IconPitchAlignment property
+ *
+ * @return property wrapper value around String
+ */
+ @SuppressWarnings("unchecked")
+ public PropertyValue getIconPitchAlignment() {
+ return (PropertyValue) new PropertyValue("icon-pitch-alignment", nativeGetIconPitchAlignment());
+ }
+
/**
* Get the TextPitchAlignment property
*
@@ -891,6 +901,8 @@ public class SymbolLayer extends Layer {
private native Object nativeGetIconOffset();
+ private native Object nativeGetIconPitchAlignment();
+
private native Object nativeGetTextPitchAlignment();
private native Object nativeGetTextRotationAlignment();
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
index cb6465a6b1..8f23e7d01e 100644
--- 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
@@ -43,8 +43,7 @@ public class Light {
*
* @return anchor as String
*/
- @Property.ANCHOR
- public String getAnchor() {
+ @Property.ANCHOR public String getAnchor() {
return nativeGetAnchor();
}
@@ -107,7 +106,7 @@ public class Light {
*
* @return color as String
*/
- public String getColor() {
+ public String getColor() {
return nativeGetColor();
}
@@ -143,7 +142,7 @@ public class Light {
*
* @return intensity as Float
*/
- public float getIntensity() {
+ public float getIntensity() {
return nativeGetIntensity();
}
@@ -166,30 +165,17 @@ public class Light {
}
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
--
cgit v1.2.1
From 3c6a6c53b4413d7758ac38c92b5416407d031025 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 17 Jul 2017 09:12:19 +0200
Subject: [android] - rewire gesture handling and telemetry event push (#9494)
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 121 ++++++++++-----------
1 file changed, 57 insertions(+), 64 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 330e09cf32..675d7cc5c5 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
@@ -50,13 +50,12 @@ final class MapGestureDetector {
private PointF focalPoint;
- private boolean twoTap = false;
- private boolean zoomStarted = false;
- private boolean dragStarted = false;
- private boolean quickZoom = false;
- private boolean scrollInProgress = false;
- private boolean scaleGestureOccurred = false;
- private boolean recentScaleGestureOccurred = false;
+ private boolean twoTap;
+ private boolean quickZoom;
+ private boolean tiltGestureOccurred;
+ private boolean scrollGestureOccurred;
+ private boolean scaleGestureOccurred;
+ private boolean recentScaleGestureOccurred;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -193,10 +192,10 @@ final class MapGestureDetector {
}
// Scroll / Pan Has Stopped
- if (scrollInProgress) {
+ if (scrollGestureOccurred) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent(
getLocationFromGesture(event.getX(), event.getY()), transform));
- scrollInProgress = false;
+ scrollGestureOccurred = false;
cameraChangeDispatcher.onCameraIdle();
}
@@ -393,20 +392,18 @@ final class MapGestureDetector {
return false;
}
- if (dragStarted) {
+ if (tiltGestureOccurred) {
return false;
}
- if (scaleGestureOccurred) {
- return false;
- }
-
- if (!scrollInProgress) {
- scrollInProgress = true;
+ if (!scrollGestureOccurred) {
+ scrollGestureOccurred = true;
// Cancel any animation
- transform.cancelTransitions();
- cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+ if (!scaleGestureOccurred) {
+ transform.cancelTransitions();
+ cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+ }
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(e1.getX(), e1.getY()),
@@ -456,7 +453,6 @@ final class MapGestureDetector {
scaleGestureOccurred = false;
beginTime = 0;
scaleFactor = 1.0f;
- zoomStarted = false;
cameraChangeDispatcher.onCameraIdle();
}
@@ -468,27 +464,27 @@ final class MapGestureDetector {
return super.onScale(detector);
}
- // 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;
+ if (tiltGestureOccurred) {
+ return false;
}
// Ignore short touches in case it is a tap
// Also ignore small scales
long time = detector.getEventTime();
long interval = time - beginTime;
- if (!zoomStarted && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
- if (!zoomStarted) {
- return false;
+ // 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);
+ scaleGestureOccurred = true;
}
- if (dragStarted) {
+ if (!scaleGestureOccurred) {
return false;
}
@@ -506,7 +502,7 @@ final class MapGestureDetector {
// Scale the map
if (focalPoint != null) {
// arround user provided focal point
- transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
cameraChangeDispatcher.onCameraMove();
// clamp scale factors we feed to core #7514
@@ -514,10 +510,12 @@ final class MapGestureDetector {
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
MapboxConstants.MAXIMUM_SCALE_FACTOR_CLAMP);
// around center map
- transform.zoomBy(Math.log(scaleFactor) / Math.log(2), uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
+ transform.zoomBy(Math.log(scaleFactor) / Math.log(Math.PI / 2),
+ uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
} else {
// around gesture
- transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), detector.getFocusX(), detector.getFocusY());
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2),
+ detector.getFocusX(), detector.getFocusY());
}
return true;
@@ -544,9 +542,6 @@ final class MapGestureDetector {
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
beginTime = detector.getEventTime();
- MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
- getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
- MapboxEvent.GESTURE_ROTATION_START, transform));
return true;
}
@@ -563,17 +558,10 @@ final class MapGestureDetector {
// Called for rotation
@Override
public boolean onRotate(RotateGestureDetector detector) {
- if (!trackingSettings.isRotateGestureCurrentlyEnabled() || dragStarted) {
+ if (!trackingSettings.isRotateGestureCurrentlyEnabled() || tiltGestureOccurred) {
return false;
}
- // If rotate is large enough ignore a tap
- // Also is zoom already started, don't rotate
- totalAngle += detector.getRotationDegreesDelta();
- if (totalAngle > 20.0f || totalAngle < -20.0f) {
- started = true;
- }
-
// Ignore short touches in case it is a tap
// Also ignore small rotate
long time = detector.getEventTime();
@@ -582,6 +570,16 @@ final class MapGestureDetector {
return false;
}
+ // If rotate is large enough ignore a tap
+ // Also is zoom already started, don't rotate
+ totalAngle += detector.getRotationDegreesDelta();
+ if (totalAngle > 35.0f || totalAngle < -35.0f) {
+ MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
+ getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
+ MapboxEvent.GESTURE_ROTATION_START, transform));
+ started = true;
+ }
+
if (!started) {
return false;
}
@@ -610,9 +608,8 @@ final class MapGestureDetector {
*/
private class ShoveGestureListener implements ShoveGestureDetector.OnShoveGestureListener {
- long beginTime = 0;
- float totalDelta = 0.0f;
- boolean started = false;
+ private long beginTime = 0;
+ private float totalDelta = 0.0f;
@Override
public boolean onShoveBegin(ShoveGestureDetector detector) {
@@ -622,10 +619,6 @@ final class MapGestureDetector {
// notify camera change listener
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
- beginTime = detector.getEventTime();
- MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
- getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
- MapboxEvent.GESTURE_PITCH_START, transform));
return true;
}
@@ -633,8 +626,7 @@ final class MapGestureDetector {
public void onShoveEnd(ShoveGestureDetector detector) {
beginTime = 0;
totalDelta = 0.0f;
- started = false;
- dragStarted = false;
+ tiltGestureOccurred = false;
}
@Override
@@ -643,22 +635,26 @@ final class MapGestureDetector {
return false;
}
- // If tilt is large enough ignore a tap
- // Also if zoom already started, don't tilt
- totalDelta += detector.getShovePixelsDelta();
- if (!zoomStarted && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) {
- started = true;
- }
-
// Ignore short touches in case it is a tap
// Also ignore small tilt
long time = detector.getEventTime();
long interval = time - beginTime;
- if (!started && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!tiltGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
- if (!started) {
+ // If tilt is large enough ignore a tap
+ // Also if zoom already started, don't tilt
+ totalDelta += detector.getShovePixelsDelta();
+ if (!tiltGestureOccurred && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) {
+ tiltGestureOccurred = true;
+ beginTime = detector.getEventTime();
+ MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
+ getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
+ MapboxEvent.GESTURE_PITCH_START, transform));
+ }
+
+ if (!tiltGestureOccurred) {
return false;
}
@@ -669,9 +665,6 @@ final class MapGestureDetector {
// Tilt the map
transform.setTilt(pitch);
-
- dragStarted = true;
-
return true;
}
}
--
cgit v1.2.1
From 00dbd033a27ff0a70196449ce7f293ff7c454f5d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 17 Jul 2017 09:13:21 +0200
Subject: [android] - feature - location accuracy indicator threshold (#9472)
---
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 30 ++++++++++++++++++++++
.../mapboxsdk/maps/widgets/MyLocationView.java | 16 ++++++++++--
.../maps/widgets/MyLocationViewSettings.java | 21 +++++++++++++++
.../src/main/res/values/attrs.xml | 1 +
4 files changed, 66 insertions(+), 2 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 80b25bf0de..e2f4123e95 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
@@ -79,6 +79,7 @@ public class MapboxMapOptions implements Parcelable {
private int[] myLocationBackgroundPadding;
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
+ private float myLocationAccuracyThreshold;
private String apiBaseUrl;
@@ -148,6 +149,7 @@ public class MapboxMapOptions implements Parcelable {
myLocationBackgroundPadding = in.createIntArray();
myLocationAccuracyAlpha = in.readInt();
myLocationAccuracyTintColor = in.readInt();
+ myLocationAccuracyThreshold = in.readFloat();
style = in.readString();
apiBaseUrl = in.readString();
@@ -291,6 +293,8 @@ public class MapboxMapOptions implements Parcelable {
mapboxMapOptions.myLocationAccuracyTint(
typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyTintColor,
ColorUtils.getPrimaryColor(context)));
+ mapboxMapOptions.myLocationAccuracyThreshold(
+ typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
mapboxMapOptions.textureMode(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
} finally {
@@ -680,6 +684,17 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
+ /**
+ * Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
+ *
+ * @param myLocationAccuracyThreshold Value of accuracy (in meters), below which circle won't be displayed
+ * @return This
+ */
+ public MapboxMapOptions myLocationAccuracyThreshold(float myLocationAccuracyThreshold) {
+ this.myLocationAccuracyThreshold = myLocationAccuracyThreshold;
+ return this;
+ }
+
/**
* Enable TextureView as rendered surface.
*
@@ -987,6 +1002,15 @@ public class MapboxMapOptions implements Parcelable {
return myLocationAccuracyAlpha;
}
+ /**
+ * Returns current accuracy threshold value (in meters).
+ *
+ * @return Value of accuracy threshold (in meters), below which circle won't be displayed
+ */
+ public float getMyLocationAccuracyThreshold() {
+ return myLocationAccuracyThreshold;
+ }
+
/**
* Get the current configured debug state for a map view.
*
@@ -1065,6 +1089,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeIntArray(myLocationBackgroundPadding);
dest.writeInt(myLocationAccuracyAlpha);
dest.writeInt(myLocationAccuracyTintColor);
+ dest.writeFloat(myLocationAccuracyThreshold);
dest.writeString(style);
dest.writeString(apiBaseUrl);
@@ -1153,6 +1178,9 @@ public class MapboxMapOptions implements Parcelable {
if (myLocationAccuracyAlpha != options.myLocationAccuracyAlpha) {
return false;
}
+ if (myLocationAccuracyThreshold != options.myLocationAccuracyThreshold) {
+ return false;
+ }
if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null) {
return false;
}
@@ -1230,6 +1258,8 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + Arrays.hashCode(myLocationBackgroundPadding);
result = 31 * result + myLocationAccuracyTintColor;
result = 31 * result + myLocationAccuracyAlpha;
+ result = 31 * result + (myLocationAccuracyThreshold != +0.0f
+ ? Float.floatToIntBits(myLocationAccuracyThreshold) : 0);
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
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 24da59bb7e..017fdb353a 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
@@ -71,6 +71,7 @@ public class MyLocationView extends View {
private float accuracy;
private Paint accuracyPaint;
+ private float accuracyThreshold;
private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
@@ -591,6 +592,16 @@ public class MyLocationView extends View {
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
}
+ /**
+ * Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
+ * For internal use only.
+ *
+ * @param accuracyThreshold Value below which circle won't be displayed
+ */
+ public void setAccuracyThreshold(float accuracyThreshold) {
+ this.accuracyThreshold = accuracyThreshold;
+ }
+
/**
* Set the bearing tracking mode, for internal use only.
*
@@ -928,10 +939,11 @@ public class MyLocationView extends View {
accuracyAnimator.end();
}
- accuracyAnimator = ValueAnimator.ofFloat(accuracy, location.getAccuracy());
+ float newAccuracy = location.getAccuracy() >= accuracyThreshold ? location.getAccuracy() : 0f;
+ accuracyAnimator = ValueAnimator.ofFloat(accuracy, newAccuracy);
accuracyAnimator.setDuration(750);
accuracyAnimator.start();
- accuracy = location.getAccuracy();
+ accuracy = newAccuracy;
}
abstract void invalidate();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index fe2f18e4dd..ea74bc57aa 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -51,6 +51,7 @@ public class MyLocationViewSettings {
//
private int accuracyAlpha;
+ private float accuracyThreshold = 0f;
@ColorInt
private int accuracyTintColor;
@@ -93,6 +94,7 @@ public class MyLocationViewSettings {
setBackgroundTintColor(options.getMyLocationBackgroundTintColor());
setAccuracyAlpha(options.getMyLocationAccuracyAlpha());
setAccuracyTintColor(options.getMyLocationAccuracyTintColor());
+ setAccuracyThreshold(options.getMyLocationAccuracyThreshold());
}
/**
@@ -293,6 +295,25 @@ public class MyLocationViewSettings {
myLocationView.setAccuracyTint(accuracyTintColor);
}
+ /**
+ * Returns current accuracy threshold value (in meters).
+ *
+ * @return Value of accuracy threshold (in meters), below which circle won't be displayed
+ */
+ public float getAccuracyThreshold() {
+ return accuracyThreshold;
+ }
+
+ /**
+ * Set accuracy circle threshold. Circle won't be displayed if accuracy is below set value.
+ *
+ * @param accuracyThreshold Value of accuracy (in meters), below which circle won't be displayed
+ */
+ public void setAccuracyThreshold(float accuracyThreshold) {
+ this.accuracyThreshold = accuracyThreshold;
+ myLocationView.setAccuracyThreshold(accuracyThreshold);
+ }
+
public void setTilt(double tilt) {
myLocationView.setTilt(tilt);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index e17f01d075..e20b640d9e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -40,6 +40,7 @@
+
--
cgit v1.2.1
From 13db36f02c9e0a95b4d4a9feab241f3470f2d197 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 18 Jul 2017 12:32:40 +0200
Subject: [android] - fine tune fling gesture (#9532)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.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/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
index 675d7cc5c5..f456d3ef65 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
@@ -369,7 +369,7 @@ final class MapGestureDetector {
// tilt results in a bigger translation, limiting input for #5281
double tilt = transform.getTilt();
- double tiltFactor = 1 + ((tilt != 0) ? (tilt / 10) : 0); /* 1 -> 7 */
+ double tiltFactor = 1.5 + ((tilt != 0) ? (tilt / 10) : 0);
double offsetX = velocityX / tiltFactor / screenDensity;
double offsetY = velocityY / tiltFactor / screenDensity;
--
cgit v1.2.1
From 8deab57e17fd033c2cbb494ec68252699062e510 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 18 Jul 2017 15:34:55 +0200
Subject: [android] - add OnPolygonClickListener and OnPolylineClickListener
(#9443)
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 109 ++++++++++++++++++---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 50 ++++++++++
2 files changed, 148 insertions(+), 11 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 f3573c78ba..7eec8710a7 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
@@ -9,6 +9,8 @@ import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
import android.view.View;
+import com.mapbox.mapboxsdk.Mapbox;
+import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
@@ -19,6 +21,7 @@ import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
+import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.List;
@@ -36,15 +39,21 @@ import java.util.List;
*/
class AnnotationManager {
+ private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
+
private final MapView mapView;
private final IconManager iconManager;
private final InfoWindowManager infoWindowManager = new InfoWindowManager();
private final MarkerViewManager markerViewManager;
private final LongSparseArray annotationsArray;
private final List selectedMarkers = new ArrayList<>();
+ private final List shapeAnnotationIds = new ArrayList<>();
private MapboxMap mapboxMap;
private MapboxMap.OnMarkerClickListener onMarkerClickListener;
+ private MapboxMap.OnPolygonClickListener onPolygonClickListener;
+ private MapboxMap.OnPolylineClickListener onPolylineClickListener;
+
private Annotations annotations;
private Markers markers;
private Polygons polygons;
@@ -107,6 +116,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
annotations.removeBy(annotation);
}
@@ -123,6 +135,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
}
annotations.removeBy(annotationList);
@@ -142,6 +157,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
}
annotations.removeAll();
@@ -195,11 +213,17 @@ class AnnotationManager {
//
Polygon addPolygon(@NonNull PolygonOptions polygonOptions, @NonNull MapboxMap mapboxMap) {
- return polygons.addBy(polygonOptions, mapboxMap);
+ Polygon polygon = polygons.addBy(polygonOptions, mapboxMap);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polygon.getId());
+ return polygon;
}
List addPolygons(@NonNull List polygonOptionsList, @NonNull MapboxMap mapboxMap) {
- return polygons.addBy(polygonOptionsList, mapboxMap);
+ List polygonList = polygons.addBy(polygonOptionsList, mapboxMap);
+ for (Polygon polygon : polygonList) {
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polygon.getId());
+ }
+ return polygonList;
}
void updatePolygon(Polygon polygon) {
@@ -215,11 +239,17 @@ class AnnotationManager {
//
Polyline addPolyline(@NonNull PolylineOptions polylineOptions, @NonNull MapboxMap mapboxMap) {
- return polylines.addBy(polylineOptions, mapboxMap);
+ Polyline polyline = polylines.addBy(polylineOptions, mapboxMap);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polyline.getId());
+ return polyline;
}
List addPolylines(@NonNull List polylineOptionsList, @NonNull MapboxMap mapboxMap) {
- return polylines.addBy(polylineOptionsList, mapboxMap);
+ List polylineList = polylines.addBy(polylineOptionsList, mapboxMap);
+ for (Polyline polyline : polylineList) {
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polyline.getId());
+ }
+ return polylineList;
}
void updatePolyline(Polyline polyline) {
@@ -231,11 +261,18 @@ class AnnotationManager {
}
// TODO Refactor from here still in progress
-
void setOnMarkerClickListener(@Nullable MapboxMap.OnMarkerClickListener listener) {
onMarkerClickListener = listener;
}
+ void setOnPolygonClickListener(@Nullable MapboxMap.OnPolygonClickListener listener) {
+ onPolygonClickListener = listener;
+ }
+
+ void setOnPolylineClickListener(@Nullable MapboxMap.OnPolylineClickListener listener) {
+ onPolylineClickListener = listener;
+ }
+
void selectMarker(@NonNull Marker marker) {
if (selectedMarkers.contains(marker)) {
return;
@@ -330,11 +367,37 @@ class AnnotationManager {
//
boolean onTap(PointF tapPoint) {
+ ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
+ long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
+ if (shapeAnnotationId >= 0) {
+ handleClickForShapeAnnotation(shapeAnnotationId);
+ }
+
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
- long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit);
+ long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit);
return markerId >= 0 && isClickHandledForMarker(markerId);
}
+ private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) {
+ float touchTargetSide = Mapbox.getApplicationContext().getResources().getDimension(R.dimen.mapbox_eight_dp);
+ RectF tapRect = new RectF(
+ tapPoint.x - touchTargetSide,
+ tapPoint.y - touchTargetSide,
+ tapPoint.x + touchTargetSide,
+ tapPoint.y + touchTargetSide
+ );
+ return new ShapeAnnotationHit(tapRect, shapeAnnotationIds.toArray(new String[shapeAnnotationIds.size()]));
+ }
+
+ private void handleClickForShapeAnnotation(long shapeAnnotationId) {
+ Annotation annotation = getAnnotation(shapeAnnotationId);
+ if (annotation instanceof Polygon && onPolygonClickListener != null) {
+ onPolygonClickListener.onPolygonClick((Polygon) annotation);
+ } else if (annotation instanceof Polyline && onPolylineClickListener != null) {
+ onPolylineClickListener.onPolylineClick((Polyline) annotation);
+ }
+ }
+
private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
@@ -356,7 +419,7 @@ class AnnotationManager {
}
if (!handledDefaultClick) {
- setMarkerSelectionState(marker);
+ toggleMarkerSelectionState(marker);
}
return true;
}
@@ -365,7 +428,7 @@ class AnnotationManager {
return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker);
}
- private void setMarkerSelectionState(Marker marker) {
+ private void toggleMarkerSelectionState(Marker marker) {
if (!selectedMarkers.contains(marker)) {
selectMarker(marker);
} else {
@@ -373,6 +436,20 @@ class AnnotationManager {
}
}
+ private static class ShapeAnnotationHitResolver {
+
+ private MapboxMap mapboxMap;
+
+ ShapeAnnotationHitResolver(MapboxMap mapboxMap) {
+ this.mapboxMap = mapboxMap;
+ }
+
+ public long execute(ShapeAnnotationHit shapeHit) {
+ List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
+ return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId());
+ }
+ }
+
private static class MarkerHitResolver {
private final MarkerViewManager markerViewManager;
@@ -388,9 +465,9 @@ class AnnotationManager {
private long closestMarkerId = -1;
- MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) {
- this.markerViewManager = markerViewManager;
- this.projection = projection;
+ MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
+ this.markerViewManager = mapboxMap.getMarkerViewManager();
+ this.projection = mapboxMap.getProjection();
}
public long execute(MarkerHit markerHit) {
@@ -443,6 +520,16 @@ class AnnotationManager {
}
}
+ private static class ShapeAnnotationHit {
+ private final RectF tapPoint;
+ private final String[] layerIds;
+
+ ShapeAnnotationHit(RectF tapRect, String[] layerIds) {
+ this.tapPoint = tapRect;
+ this.layerIds = layerIds;
+ }
+ }
+
private static class MarkerHit {
private final RectF tapRect;
private final List markers;
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 18bcd4953d..6233efa966 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
@@ -1459,6 +1459,28 @@ public final class MapboxMap {
annotationManager.setOnMarkerClickListener(listener);
}
+ /**
+ * Sets a callback that's invoked when the user clicks on a polygon.
+ *
+ * @param listener The callback that's invoked when the user clicks on a polygon.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener) {
+ annotationManager.setOnPolygonClickListener(listener);
+ }
+
+ /**
+ * Sets a callback that's invoked when the user clicks on a polyline.
+ *
+ * @param listener The callback that's invoked when the user clicks on a polyline.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener) {
+ annotationManager.setOnPolylineClickListener(listener);
+ }
+
/**
*
* Selects a marker. The selected marker will have it's info window opened.
@@ -2150,6 +2172,34 @@ public final class MapboxMap {
boolean onMarkerClick(@NonNull Marker marker);
}
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on a polygon.
+ *
+ * @see MapboxMap#setOnPolygonClickListener(OnPolygonClickListener)
+ */
+ public interface OnPolygonClickListener {
+ /**
+ * Called when the user clicks on a polygon.
+ *
+ * @param polygon The polygon the user clicked on.
+ */
+ void onPolygonClick(@NonNull Polygon polygon);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on a polyline.
+ *
+ * @see MapboxMap#setOnPolylineClickListener(OnPolylineClickListener)
+ */
+ public interface OnPolylineClickListener {
+ /**
+ * Called when the user clicks on a polyline.
+ *
+ * @param polyline The polyline the user clicked on.
+ */
+ void onPolylineClick(@NonNull Polyline polyline);
+ }
+
/**
* Interface definition for a callback to be invoked when the user clicks on an info window.
*
--
cgit v1.2.1
From da581cc4855c1c342c8ff59e29938750f7e3ec2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Wed, 19 Jul 2017 14:16:25 +0200
Subject: [android] - trying to update non-existent polyline fix #9543 (#9544)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.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/PolylineContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
index 7483f1082b..397b70a158 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
@@ -80,6 +80,7 @@ class PolylineContainer implements Polylines {
public void update(Polyline polyline) {
if (!isAddedToMap(polyline)) {
Timber.w("Attempting to update non-added Polyline with value %s", polyline);
+ return;
}
nativeMapView.updatePolyline(polyline);
--
cgit v1.2.1
From 68324913d7895140e59a5ee1d13db295bbfb2522 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 19 Jul 2017 14:17:06 +0200
Subject: [android] - rewrite map object intialisation (#9462)
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 133 +++++++++++++--------
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 47 +-------
2 files changed, 90 insertions(+), 90 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 a0aebfda50..bb8771b5dd 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
@@ -5,7 +5,6 @@ import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.SurfaceTexture;
import android.os.Bundle;
-import android.os.Handler;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
@@ -42,6 +41,9 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import timber.log.Timber;
/**
*
@@ -59,17 +61,24 @@ import java.util.List;
*/
public class MapView extends FrameLayout {
+ private final MapCallback mapCallback = new MapCallback();
+ private MapboxMap mapboxMap;
+
private NativeMapView nativeMapView;
- private boolean textureMode;
+ private MapboxMapOptions mapboxMapOptions;
private boolean destroyed;
private boolean hasSurface;
- private MapboxMap mapboxMap;
- private MapCallback mapCallback;
+ private MyLocationView myLocationView;
+ private CompassView compassView;
+ private ImageView attrView;
+ private ImageView logoView;
private MapGestureDetector mapGestureDetector;
private MapKeyListener mapKeyListener;
private MapZoomButtonController mapZoomButtonController;
+ private Bundle savedInstanceState;
+ private final CopyOnWriteArrayList onMapChangedListeners = new CopyOnWriteArrayList<>();
@UiThread
public MapView(@NonNull Context context) {
@@ -101,21 +110,23 @@ public class MapView extends FrameLayout {
LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_preview, this);
return;
}
-
- // determine render surface
- textureMode = options.getTextureMode();
+ mapboxMapOptions = options;
// inflate view
View view = LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_internal, this);
- CompassView compassView = (CompassView) view.findViewById(R.id.compassView);
- MyLocationView myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
- ImageView attrView = (ImageView) view.findViewById(R.id.attributionView);
+ compassView = (CompassView) view.findViewById(R.id.compassView);
+ myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
+ attrView = (ImageView) view.findViewById(R.id.attributionView);
+ logoView = (ImageView) view.findViewById(R.id.logoView);
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
+ setWillNotDraw(false);
+ }
- // create native Map object
- nativeMapView = new NativeMapView(this);
+ private void initialiseMap() {
+ Context context = getContext();
+ addOnMapChangedListener(mapCallback);
// callback for focal point invalidation
FocalPointInvalidator focalPoint = new FocalPointInvalidator(compassView);
@@ -131,7 +142,7 @@ public class MapView extends FrameLayout {
// setup components for MapboxMap creation
Projection proj = new Projection(nativeMapView);
- UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, view.findViewById(R.id.logoView));
+ UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, logoView);
TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPoint, zoomInvalidator);
MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj, focalPoint);
LongSparseArray annotationsArray = new LongSparseArray<>();
@@ -147,6 +158,7 @@ public class MapView extends FrameLayout {
cameraChangeDispatcher);
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings, proj,
registerTouchListener, annotationManager, cameraChangeDispatcher);
+ mapCallback.attachMapboxMap(mapboxMap);
// user input
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings,
@@ -168,14 +180,15 @@ public class MapView extends FrameLayout {
setFocusableInTouchMode(true);
requestDisallowInterceptTouchEvent(true);
- // allow onDraw invocation
- setWillNotDraw(false);
-
// notify Map object about current connectivity state
nativeMapView.setReachability(ConnectivityReceiver.instance(context).isConnected(context));
// initialise MapboxMap
- mapboxMap.initialise(context, options);
+ if (savedInstanceState == null) {
+ mapboxMap.initialise(context, mapboxMapOptions);
+ } else {
+ mapboxMap.onRestoreInstanceState(savedInstanceState);
+ }
}
//
@@ -198,16 +211,11 @@ public class MapView extends FrameLayout {
if (savedInstanceState == null) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapLoadEvent());
} else if (savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) {
- mapboxMap.onRestoreInstanceState(savedInstanceState);
+ this.savedInstanceState = savedInstanceState;
}
-
- initialiseDrawingSurface(textureMode);
- addOnMapChangedListener(mapCallback = new MapCallback(mapboxMap));
}
private void initialiseDrawingSurface(boolean textureMode) {
- nativeMapView.initializeDisplay();
- nativeMapView.initializeContext();
if (textureMode) {
TextureView textureView = new TextureView(getContext());
textureView.setSurfaceTextureListener(new SurfaceTextureListener());
@@ -236,8 +244,10 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onStart() {
- mapboxMap.onStart();
ConnectivityReceiver.instance(getContext()).activate();
+ if (mapboxMap != null) {
+ mapboxMap.onStart();
+ }
}
/**
@@ -271,9 +281,6 @@ public class MapView extends FrameLayout {
@UiThread
public void onDestroy() {
destroyed = true;
- nativeMapView.terminateContext();
- nativeMapView.terminateDisplay();
- nativeMapView.destroySurface();
nativeMapView.destroy();
nativeMapView = null;
}
@@ -384,7 +391,10 @@ public class MapView extends FrameLayout {
if (destroyed) {
return;
}
-
+ if (nativeMapView == null) {
+ mapboxMapOptions.styleUrl(url);
+ return;
+ }
nativeMapView.setStyleUrl(url);
}
@@ -412,7 +422,6 @@ public class MapView extends FrameLayout {
if (!hasSurface) {
return;
}
-
nativeMapView.render();
}
@@ -422,7 +431,7 @@ public class MapView extends FrameLayout {
return;
}
- if (!isInEditMode()) {
+ if (!isInEditMode() && nativeMapView != null) {
nativeMapView.resizeView(width, height);
}
}
@@ -433,7 +442,16 @@ public class MapView extends FrameLayout {
@Override
public void surfaceCreated(SurfaceHolder holder) {
- nativeMapView.createSurface(surface = holder.getSurface());
+ if (nativeMapView == null) {
+ nativeMapView = new NativeMapView(MapView.this);
+ nativeMapView.createSurface(surface = holder.getSurface());
+ nativeMapView.resizeView(getWidth(), getHeight());
+ initialiseMap();
+ mapboxMap.onStart();
+ } else {
+ nativeMapView.createSurface(surface = holder.getSurface());
+ }
+
hasSurface = true;
}
@@ -450,6 +468,7 @@ public class MapView extends FrameLayout {
hasSurface = false;
if (nativeMapView != null) {
+ // occurs when activity goes to background
nativeMapView.destroySurface();
}
surface.release();
@@ -465,8 +484,17 @@ public class MapView extends FrameLayout {
// Must do all EGL/GL ES initialization here
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
- nativeMapView.createSurface(this.surface = new Surface(surface));
- nativeMapView.resizeFramebuffer(width, height);
+ if (nativeMapView == null) {
+ nativeMapView = new NativeMapView(MapView.this);
+ nativeMapView.createSurface(this.surface = new Surface(surface));
+ nativeMapView.resizeFramebuffer(width, height);
+ nativeMapView.resizeView(width, height);
+ initialiseMap();
+ mapboxMap.onStart();
+ } else {
+ nativeMapView.createSurface(this.surface = new Surface(surface));
+ }
+
hasSurface = true;
}
@@ -522,16 +550,32 @@ public class MapView extends FrameLayout {
// Called when view is hidden and shown
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
- if (isInEditMode() || mapZoomButtonController == null) {
+ if (isInEditMode()) {
return;
}
- mapZoomButtonController.setVisible(visibility == View.VISIBLE);
+ if (visibility == View.VISIBLE && nativeMapView == null) {
+ initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
+ }
+
+ if (mapZoomButtonController != null && nativeMapView != null) {
+ mapZoomButtonController.setVisible(visibility == View.VISIBLE);
+ }
}
//
// Map events
//
+ void onMapChange(int rawChange) {
+ for (MapView.OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
+ try {
+ onMapChangedListener.onMapChanged(rawChange);
+ } catch (RuntimeException err) {
+ Timber.e("Exception (%s) in MapView.OnMapChangedListener: %s", err.getClass(), err.getMessage());
+ }
+ }
+ }
+
/**
*
* Add a callback that's invoked when the displayed map view changes.
@@ -543,7 +587,7 @@ public class MapView extends FrameLayout {
*/
public void addOnMapChangedListener(@Nullable OnMapChangedListener listener) {
if (listener != null) {
- nativeMapView.addOnMapChangedListener(listener);
+ onMapChangedListeners.add(listener);
}
}
@@ -555,7 +599,7 @@ public class MapView extends FrameLayout {
*/
public void removeOnMapChangedListener(@Nullable OnMapChangedListener listener) {
if (listener != null) {
- nativeMapView.removeOnMapChangedListener(listener);
+ onMapChangedListeners.remove(listener);
}
}
@@ -919,11 +963,11 @@ public class MapView extends FrameLayout {
private static class MapCallback implements OnMapChangedListener {
- private final MapboxMap mapboxMap;
+ private MapboxMap mapboxMap;
private final List onMapReadyCallbackList = new ArrayList<>();
private boolean initialLoad = true;
- MapCallback(MapboxMap mapboxMap) {
+ void attachMapboxMap(MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
}
@@ -931,14 +975,9 @@ public class MapView extends FrameLayout {
public void onMapChanged(@MapChange int change) {
if (change == DID_FINISH_LOADING_STYLE && initialLoad) {
initialLoad = false;
- new Handler().post(new Runnable() {
- @Override
- public void run() {
- mapboxMap.onPreMapReady();
- onMapReady();
- mapboxMap.onPostMapReady();
- }
- });
+ mapboxMap.onPreMapReady();
+ onMapReady();
+ mapboxMap.onPostMapReady();
} else if (change == DID_FINISH_RENDERING_FRAME || change == DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) {
mapboxMap.onUpdateFullyRendered();
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
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 a88a11d387..34ac5b9eaf 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
@@ -35,7 +35,6 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
import timber.log.Timber;
@@ -57,9 +56,6 @@ final class NativeMapView {
// Device density
private final float pixelRatio;
- // Listeners for Map change events
- private CopyOnWriteArrayList onMapChangedListeners;
-
// Listener invoked to return a bitmap of the map
private MapboxMap.SnapshotReadyCallback snapshotReadyCallback;
@@ -76,7 +72,6 @@ final class NativeMapView {
fileSource = FileSource.getInstance(context);
pixelRatio = context.getResources().getDisplayMetrics().density;
- onMapChangedListeners = new CopyOnWriteArrayList<>();
this.mapView = mapView;
String programCacheDir = context.getCacheDir().getAbsolutePath();
@@ -102,34 +97,6 @@ final class NativeMapView {
destroyed = true;
}
- public void initializeDisplay() {
- if (isDestroyedOn("initializeDisplay")) {
- return;
- }
- nativeInitializeDisplay();
- }
-
- public void terminateDisplay() {
- if (isDestroyedOn("terminateDisplay")) {
- return;
- }
- nativeTerminateDisplay();
- }
-
- public void initializeContext() {
- if (isDestroyedOn("initializeContext")) {
- return;
- }
- nativeInitializeContext();
- }
-
- public void terminateContext() {
- if (isDestroyedOn("terminateContext")) {
- return;
- }
- nativeTerminateContext();
- }
-
public void createSurface(Surface surface) {
if (isDestroyedOn("createSurface")) {
return;
@@ -887,14 +854,8 @@ final class NativeMapView {
}
protected void onMapChanged(int rawChange) {
- if (onMapChangedListeners != null) {
- for (MapView.OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
- try {
- onMapChangedListener.onMapChanged(rawChange);
- } catch (RuntimeException err) {
- Timber.e("Exception (%s) in MapView.OnMapChangedListener: %s", err.getClass(), err.getMessage());
- }
- }
+ if (mapView != null) {
+ mapView.onMapChange(rawChange);
}
}
@@ -1130,11 +1091,11 @@ final class NativeMapView {
//
void addOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
- onMapChangedListeners.add(listener);
+ mapView.addOnMapChangedListener(listener);
}
void removeOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
- onMapChangedListeners.remove(listener);
+ mapView.removeOnMapChangedListener(listener);
}
//
--
cgit v1.2.1
From f94d81c305230a1f54ac5e024c98cfeb1b87739f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?=
Date: Wed, 19 Jul 2017 00:51:13 -0700
Subject: [android, ios, macos] Updated French localization
Updated French localization on iOS and macOS and added French localization on Android.
---
.../MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml
new file mode 100644
index 0000000000..48d90c3324
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-fr/strings.xml
@@ -0,0 +1,15 @@
+
+
+ Boussole. Activer pour rétablir l\'orientation de la carte vers le nord.
+ Icone d\'attribution. Activer pour montrer le dialogue d\'attribution.
+ Vue de géolocalisation. Ceci affiche votre localisation sur la carte.
+ Affichage d\'une carte créée avec Mapbox. Faites la glisser en traînant deux doigts. Zoomez ou dézoomez en écartant ou rapprochant deux doigts.
+ SDK Mapbox pour Android
+ Faire de meilleures cartes Mapbox
+ Vous aidez à améliorer les cartes OpenStreetMap et Mapbox en contribuant des données d\'utilisation anonymes.
+ D\'accord
+ Pas d\'accord
+ Plus d\'informations
+ Le cadre OfflineRegionDefinition pour définir la région de navigation ne tient pas dans les limites du monde : %s
+
+
--
cgit v1.2.1
From c5300ebabf6d01a11aca00df5eee350f49b5cbf1 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 18 Jul 2017 16:26:24 +0200
Subject: [android] add api to enable/disable tile prefetching
---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 33 ++++++++++++++++++++++
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 33 ++++++++++++++++++++++
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 18 ++++++++++++
.../src/main/res/values/attrs.xml | 2 ++
.../mapboxsdk/maps/MapboxMapOptionsTest.java | 10 +++++++
5 files changed, 96 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 6233efa966..f47fcdfd4a 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
@@ -99,6 +99,7 @@ public final class MapboxMap {
setDebugActive(options.getDebugActive());
setApiBaseUrl(options);
setStyleUrl(options);
+ setPrefetchesTiles(options);
}
/**
@@ -247,6 +248,38 @@ public final class MapboxMap {
nativeMapView.setTransitionDelay(delayMs);
}
+ /**
+ * Sets tile pre-fetching from MapboxOptions.
+ *
+ * @param options the options object
+ */
+ private void setPrefetchesTiles(@NonNull MapboxMapOptions options) {
+ setPrefetchesTiles(options.getPrefetchesTiles());
+ }
+
+ /**
+ * Enable or disable tile pre-fetching. Pre-fetching makes sure that a low-resolution
+ * tile is rendered as soon as possible at the expense of a little bandwidth.
+ *
+ * @param enable true to enable
+ */
+ @UiThread
+ public void setPrefetchesTiles(boolean enable) {
+ nativeMapView.setPrefetchesTiles(enable);
+ }
+
+ /**
+ * Check whether tile pre-fetching is enabled or not.
+ *
+ * @return true if enabled
+ *
+ * @see MapboxMap#setPrefetchesTiles(boolean)
+ */
+ @UiThread
+ public boolean getPrefetchesTiles() {
+ return nativeMapView.getPrefetchesTiles();
+ }
+
/**
* Retrieve all the layers in the style
*
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 e2f4123e95..4301d64375 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
@@ -80,6 +80,7 @@ public class MapboxMapOptions implements Parcelable {
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
private float myLocationAccuracyThreshold;
+ private boolean prefetchesTiles = true;
private String apiBaseUrl;
@@ -154,6 +155,7 @@ public class MapboxMapOptions implements Parcelable {
style = in.readString();
apiBaseUrl = in.readString();
textureMode = in.readByte() != 0;
+ prefetchesTiles = in.readByte() != 0;
}
static Bitmap getBitmapFromDrawable(Drawable drawable) {
@@ -297,6 +299,8 @@ public class MapboxMapOptions implements Parcelable {
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
mapboxMapOptions.textureMode(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
+ mapboxMapOptions.setPrefetchesTiles(
+ typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
} finally {
typedArray.recycle();
}
@@ -711,6 +715,30 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
+ /**
+ * Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
+ * a low resolution preview while more detailed tiles are loaded.
+ *
+ * Enabled by default
+ *
+ * @param enable true to enable
+ *
+ * @return This
+ */
+ public MapboxMapOptions setPrefetchesTiles(boolean enable) {
+ this.prefetchesTiles = enable;
+ return this;
+ }
+
+ /**
+ * Check whether tile pre-fetching is enabled.
+ *
+ * @return true if enabled
+ */
+ public boolean getPrefetchesTiles() {
+ return prefetchesTiles;
+ }
+
/**
* Get the current configured API endpoint base URL.
*
@@ -1094,6 +1122,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeString(style);
dest.writeString(apiBaseUrl);
dest.writeByte((byte) (textureMode ? 1 : 0));
+ dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
}
@Override
@@ -1217,6 +1246,9 @@ public class MapboxMapOptions implements Parcelable {
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) {
return false;
}
+ if (prefetchesTiles != options.prefetchesTiles) {
+ return false;
+ }
return false;
}
@@ -1263,6 +1295,7 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
+ result = 31 * result + (prefetchesTiles ? 1 : 0);
return result;
}
}
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 34ac5b9eaf..52596358e2 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
@@ -638,6 +638,20 @@ final class NativeMapView {
return nativeGetCameraPosition();
}
+ public void setPrefetchesTiles(boolean enable) {
+ if (isDestroyedOn("setPrefetchesTiles")) {
+ return;
+ }
+ nativeSetPrefetchesTiles(enable);
+ }
+
+ public boolean getPrefetchesTiles() {
+ if (isDestroyedOn("getPrefetchesTiles")) {
+ return false;
+ }
+ return nativeGetPrefetchesTiles();
+ }
+
// Runtime style Api
public long getTransitionDuration() {
@@ -1072,6 +1086,10 @@ final class NativeMapView {
private native Light nativeGetLight();
+ private native void nativeSetPrefetchesTiles(boolean enable);
+
+ private native boolean nativeGetPrefetchesTiles();
+
int getWidth() {
if (isDestroyedOn("")) {
return 0;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index e20b640d9e..a7ef78d699 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -117,6 +117,8 @@
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
index ce0cb00b0b..4f929641f3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapOptionsTest.java
@@ -186,5 +186,15 @@ public class MapboxMapOptionsTest {
assertEquals(Color.BLUE, new MapboxMapOptions()
.myLocationBackgroundTintColor(Color.BLUE).getMyLocationBackgroundTintColor());
}
+
+ @Test
+ public void testPrefetchesTiles() {
+ // Default value
+ assertTrue(new MapboxMapOptions().getPrefetchesTiles());
+
+ // Check mutations
+ assertTrue(new MapboxMapOptions().setPrefetchesTiles(true).getPrefetchesTiles());
+ assertFalse(new MapboxMapOptions().setPrefetchesTiles(false).getPrefetchesTiles());
+ }
}
--
cgit v1.2.1
From f19c36a4ba9adb6d1288a47252a0189aac5033ce Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 20 Jul 2017 10:18:40 +0200
Subject: [android] - avoid creating InfoWindow iterator if no InfoWindows are
shown (#9477)
---
.../com/mapbox/mapboxsdk/maps/InfoWindowManager.java | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
index 7599b6afa6..0b461d1227 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
@@ -22,7 +22,8 @@ import java.util.List;
*/
class InfoWindowManager {
- private List infoWindows;
+ private final List infoWindows = new ArrayList<>();
+
private MapboxMap.InfoWindowAdapter infoWindowAdapter;
private boolean allowConcurrentMultipleInfoWindows;
@@ -30,13 +31,11 @@ class InfoWindowManager {
private MapboxMap.OnInfoWindowLongClickListener onInfoWindowLongClickListener;
private MapboxMap.OnInfoWindowCloseListener onInfoWindowCloseListener;
- InfoWindowManager() {
- this.infoWindows = new ArrayList<>();
- }
-
void update() {
- for (InfoWindow infoWindow : infoWindows) {
- infoWindow.update();
+ if (!infoWindows.isEmpty()) {
+ for (InfoWindow infoWindow : infoWindows) {
+ infoWindow.update();
+ }
}
}
@@ -56,10 +55,6 @@ class InfoWindowManager {
return allowConcurrentMultipleInfoWindows;
}
- List getInfoWindows() {
- return infoWindows;
- }
-
boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
}
--
cgit v1.2.1
From ac51783a982d172b5e502662fcc3ffcd83dfd60e Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 20 Jul 2017 16:51:27 +0200
Subject: [android] - increase touch target to match largest Marker icon
(#9565)
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 12 +++----
.../com/mapbox/mapboxsdk/maps/IconManager.java | 42 +++++++++++-----------
2 files changed, 27 insertions(+), 27 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 7eec8710a7..73e90206f8 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
@@ -399,12 +399,12 @@ class AnnotationManager {
}
private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
- int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
- int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
- final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset,
- tapPoint.y - averageIconHeightOffset,
- tapPoint.x + averageIconWidthOffset,
- tapPoint.y + averageIconHeightOffset
+ int touchSurfaceWidth = (int) (iconManager.getHighestIconHeight() * 1.5);
+ int touchSurfaceHeight = (int) (iconManager.getHighestIconWidth() * 1.5);
+ final RectF tapRect = new RectF(tapPoint.x - touchSurfaceWidth,
+ tapPoint.y - touchSurfaceHeight,
+ tapPoint.x + touchSurfaceWidth,
+ tapPoint.y + touchSurfaceHeight
);
return new MarkerHit(tapRect, getMarkersInRect(tapRect));
}
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 b5da5f59aa..18eecfd9c3 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
@@ -12,8 +12,6 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import java.util.ArrayList;
import java.util.List;
-import timber.log.Timber;
-
/**
* Responsible for managing icons added to the Map.
*
@@ -30,8 +28,8 @@ class IconManager {
private NativeMapView nativeMapView;
private List icons;
- private int averageIconHeight;
- private int averageIconWidth;
+ private int highestIconWidth;
+ private int highestIconHeight;
IconManager(NativeMapView nativeMapView) {
this.nativeMapView = nativeMapView;
@@ -47,7 +45,7 @@ class IconManager {
// TODO we can move this code afterwards to getIcon as with MarkerView.getIcon
icon = loadDefaultIconForMarker(marker);
} else {
- updateAverageIconSize(icon);
+ updateHighestIconSize(icon);
}
addIcon(icon);
return icon;
@@ -56,7 +54,7 @@ class IconManager {
void loadIconForMarkerView(MarkerView marker) {
Icon icon = marker.getIcon();
Bitmap bitmap = icon.getBitmap();
- updateAverageIconSize(bitmap);
+ updateHighestIconSize(bitmap);
addIcon(icon, false);
}
@@ -64,18 +62,18 @@ class IconManager {
return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio());
}
- int getAverageIconHeight() {
- return averageIconHeight;
+ int getHighestIconWidth() {
+ return highestIconWidth;
}
- int getAverageIconWidth() {
- return averageIconWidth;
+ int getHighestIconHeight() {
+ return highestIconHeight;
}
private Icon loadDefaultIconForMarker(Marker marker) {
Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker();
Bitmap bitmap = icon.getBitmap();
- updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
+ updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
marker.setIcon(icon);
return icon;
}
@@ -95,20 +93,22 @@ class IconManager {
}
}
- private void updateAverageIconSize(Icon icon) {
- updateAverageIconSize(icon.getBitmap());
+ private void updateHighestIconSize(Icon icon) {
+ updateHighestIconSize(icon.getBitmap());
}
- private void updateAverageIconSize(Bitmap bitmap) {
- updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight());
+ private void updateHighestIconSize(Bitmap bitmap) {
+ updateHighestIconSize(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;
- Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height);
- Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight);
+ private void updateHighestIconSize(int width, int height) {
+ if (width > highestIconWidth) {
+ highestIconWidth = width;
+ }
+
+ if (height > highestIconHeight) {
+ highestIconHeight = height;
+ }
}
private void loadIcon(Icon icon) {
--
cgit v1.2.1
From d3628449460a0918e9e89c81e1baba31c4acffe0 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 20 Jul 2017 17:26:28 +0200
Subject: [android] - manage InfoWindow selection in AnnotationManager (#9567)
---
.../java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java | 5 -----
1 file changed, 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index dce6f6b277..8704e882ea 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -570,11 +570,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter);
}
- if (!clickHandled) {
- ensureInfoWindowOffset(markerView);
- select(markerView, view, adapter);
- }
-
return clickHandled;
}
--
cgit v1.2.1
From f6871f7339aff7cd052cd5d177141ccbf35426cf Mon Sep 17 00:00:00 2001
From: jingsam
Date: Fri, 21 Jul 2017 15:02:04 +0800
Subject: Update public.xml (#9575)
---
.../android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index 7294f43c02..f30cb7c27a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -20,7 +20,7 @@
-
+
--
cgit v1.2.1
From b83d79708185f0d8def1d3638fcc702305cd3fab Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Fri, 21 Jul 2017 14:03:37 +0200
Subject: [android] add lint using current baseline as starting point (#9318)
---
platform/android/MapboxGLAndroidSDK/.gitignore | 2 +
platform/android/MapboxGLAndroidSDK/build.gradle | 2 +
.../MapboxGLAndroidSDK/lint/lint-baseline-ci.xml | 629 +++++++++++++++++++++
3 files changed, 633 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/.gitignore
create mode 100644 platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/.gitignore b/platform/android/MapboxGLAndroidSDK/.gitignore
new file mode 100644
index 0000000000..cec211fe81
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/.gitignore
@@ -0,0 +1,2 @@
+lint-baseline.xml
+lint/lint-baseline-local.xml
\ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 8b92fa1af2..0cb6e529f1 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -116,6 +116,7 @@ android {
}
lintOptions {
+ baseline file("lint-baseline.xml")
checkAllWarnings true
warningsAsErrors true
}
@@ -152,3 +153,4 @@ apply from: 'gradle-javadoc.gradle'
apply from: 'gradle-publish.gradle'
apply from: 'gradle-checkstyle.gradle'
apply from: 'gradle-tests-staticblockremover.gradle'
+apply from: '../gradle-lint.gradle'
diff --git a/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml b/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
new file mode 100644
index 0000000000..4dc8ecde70
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
@@ -0,0 +1,629 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--
cgit v1.2.1
From af76efac22905be06d23567465e67da97d381a7e Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 6 Jul 2017 21:04:30 +0200
Subject: [android] - validate if platform implementation doesn't return a null
motion event (#9434)
---
.../main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 3607703ab1..17eb506b97 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
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.PointF;
import android.location.Location;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
@@ -134,7 +133,12 @@ final class MapGestureDetector {
* @param event the MotionEvent
* @return True if touch event is handled
*/
- boolean onTouchEvent(@NonNull MotionEvent event) {
+ boolean onTouchEvent(MotionEvent event) {
+ // framework can return null motion events in edge cases #9432
+ if (event == null) {
+ return false;
+ }
+
// Check and ignore non touch or left clicks
if ((event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) {
return false;
--
cgit v1.2.1
From 79f0cc3d812c95a02029749cb13900f31c6eb6b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Paczos?=
Date: Thu, 6 Jul 2017 21:05:04 +0200
Subject: [android] - map's visible region fix #9427 (#9428)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/Projection.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index ff466c436c..e0a634521b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -80,10 +80,10 @@ public class Projection {
public VisibleRegion getVisibleRegion() {
LatLngBounds.Builder builder = new LatLngBounds.Builder();
- float left = contentPadding[0];
- float right = nativeMapView.getWidth() - contentPadding[2];
- float top = contentPadding[1];
- float bottom = nativeMapView.getHeight() - contentPadding[3];
+ float left = 0;
+ float right = nativeMapView.getWidth();
+ float top = 0;
+ float bottom = nativeMapView.getHeight();
LatLng topLeft = fromScreenLocation(new PointF(left, top));
LatLng topRight = fromScreenLocation(new PointF(right, top));
--
cgit v1.2.1
From 0ce62a20c45b3a43629306b7728d474343520025 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 6 Jul 2017 11:26:03 +0200
Subject: [android] Fix my location drawable getting tinted (#9410)
* fix my location drawable tinted when setting mapbox_myLocationTintColor in xml issue (linking my location foreground drawables with my location foreground tint color and adding the possibility of setting an undefined my location foreground tint color)
* link my location background drawable with my location background tint color and add the possibility of setting an undefined my location background tint color
---
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 21 ++++++++-------
.../mapboxsdk/maps/widgets/MyLocationView.java | 31 +++++++++++++++++-----
.../maps/widgets/MyLocationViewSettings.java | 10 +++++--
3 files changed, 44 insertions(+), 18 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 2efed1b322..80b25bf0de 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
@@ -4,7 +4,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
@@ -37,6 +36,7 @@ public class MapboxMapOptions implements Parcelable {
private static final float FOUR_DP = 4f;
private static final float NINETY_TWO_DP = 92f;
+ private static final int UNDEFINED_COLOR = -1;
private CameraPosition cameraPosition;
@@ -53,7 +53,7 @@ public class MapboxMapOptions implements Parcelable {
private int[] logoMargins;
@ColorInt
- private int attributionTintColor = -1;
+ private int attributionTintColor = UNDEFINED_COLOR;
private boolean attributionEnabled = true;
private int attributionGravity = Gravity.BOTTOM;
private int[] attributionMargins;
@@ -72,8 +72,10 @@ public class MapboxMapOptions implements Parcelable {
private Drawable myLocationForegroundDrawable;
private Drawable myLocationForegroundBearingDrawable;
private Drawable myLocationBackgroundDrawable;
- private int myLocationForegroundTintColor;
- private int myLocationBackgroundTintColor;
+ @ColorInt
+ private int myLocationForegroundTintColor = UNDEFINED_COLOR;
+ @ColorInt
+ private int myLocationBackgroundTintColor = UNDEFINED_COLOR;
private int[] myLocationBackgroundPadding;
private int myLocationAccuracyTintColor;
private int myLocationAccuracyAlpha;
@@ -234,7 +236,7 @@ public class MapboxMapOptions implements Parcelable {
FOUR_DP * pxlRatio))});
mapboxMapOptions.attributionTintColor(typedArray.getColor(
- R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1));
+ R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, UNDEFINED_COLOR));
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(
R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
mapboxMapOptions.attributionGravity(typedArray.getInt(
@@ -251,10 +253,9 @@ public class MapboxMapOptions implements Parcelable {
mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false));
mapboxMapOptions.myLocationForegroundTintColor(
- typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor,
- ColorUtils.getPrimaryColor(context)));
+ typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor, UNDEFINED_COLOR));
mapboxMapOptions.myLocationBackgroundTintColor(
- typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, Color.WHITE));
+ typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundTintColor, UNDEFINED_COLOR));
Drawable foregroundDrawable = typedArray.getDrawable(R.styleable.mapbox_MapView_mapbox_myLocationDrawable);
if (foregroundDrawable == null) {
@@ -638,7 +639,7 @@ public class MapboxMapOptions implements Parcelable {
/**
* Set the background tint color of MyLocationView.
*
- * @param myLocationBackgroundTintColor the color to tint the background
+ * @param myLocationBackgroundTintColor the color to tint the background drawable
* @return This
*/
public MapboxMapOptions myLocationBackgroundTintColor(@ColorInt int myLocationBackgroundTintColor) {
@@ -944,6 +945,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return the tint color
*/
+ @ColorInt
public int getMyLocationForegroundTintColor() {
return myLocationForegroundTintColor;
}
@@ -953,6 +955,7 @@ public class MapboxMapOptions implements Parcelable {
*
* @return the tint color
*/
+ @ColorInt
public int getMyLocationBackgroundTintColor() {
return myLocationBackgroundTintColor;
}
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 8b6b93e03a..24da59bb7e 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
@@ -51,6 +51,7 @@ import timber.log.Timber;
*/
public class MyLocationView extends View {
+ private static final int UNDEFINED_TINT_COLOR = -1;
private MyLocationBehavior myLocationBehavior;
private MapboxMap mapboxMap;
@@ -198,12 +199,8 @@ public class MyLocationView extends View {
* @param color The color to tint the drawable with
*/
public final void setForegroundDrawableTint(@ColorInt int color) {
- if (foregroundDrawable != null) {
- foregroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
- }
- if (foregroundBearingDrawable != null) {
- foregroundBearingDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
- }
+ applyDrawableTint(foregroundDrawable, color);
+ applyDrawableTint(foregroundBearingDrawable, color);
invalidate();
}
@@ -247,7 +244,7 @@ public class MyLocationView extends View {
if (backgroundDrawable == null) {
return;
}
- backgroundDrawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ applyDrawableTint(backgroundDrawable, color);
invalidate();
}
@@ -737,6 +734,26 @@ public class MyLocationView extends View {
setEnabled(isEnabled(), locationSource != null);
}
+ private void applyDrawableTint(Drawable drawable, @ColorInt int color) {
+ if (color == UNDEFINED_TINT_COLOR) {
+ removeTintColorFilter(drawable);
+ } else {
+ applyTintColorFilter(drawable, color);
+ }
+ }
+
+ private void removeTintColorFilter(Drawable drawable) {
+ if (drawable != null) {
+ drawable.mutate().setColorFilter(null);
+ }
+ }
+
+ private void applyTintColorFilter(Drawable drawable, @ColorInt int color) {
+ if (drawable != null) {
+ drawable.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ }
+ }
+
private static class GpsLocationListener implements LocationEngineListener {
private WeakReference userLocationView;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index 2ad1bf7ebc..fe2f18e4dd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -119,6 +119,7 @@ public class MyLocationViewSettings {
*
* The foreground drawable is the image visible on screen
*
+ * It's linked with the foreground tint color
*
* @param foregroundDrawable the drawable to show as foreground without bearing
* @param foregroundBearingDrawable the drawable to show as foreground when bearing is enabled
@@ -127,6 +128,7 @@ public class MyLocationViewSettings {
this.foregroundDrawable = foregroundDrawable;
this.foregroundBearingDrawable = foregroundBearingDrawable;
myLocationView.setForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
+ myLocationView.setForegroundDrawableTint(foregroundTintColor);
}
/**
@@ -153,7 +155,8 @@ public class MyLocationViewSettings {
* The color will tint both the foreground and the bearing foreground drawable.
*
*
- * @param foregroundTintColor the color to tint the foreground drawable
+ * @param foregroundTintColor the color to tint the foreground drawable or -1 (undefined color) to remove the
+ * existing foreground tint color
*/
public void setForegroundTintColor(@ColorInt int foregroundTintColor) {
this.foregroundTintColor = foregroundTintColor;
@@ -174,6 +177,7 @@ public class MyLocationViewSettings {
*
* Padding can be added to provide an offset to the background
*
+ * It's linked with the background tint color
*
* @param backgroundDrawable the drawable to show as background
* @param padding the padding added to the background
@@ -186,6 +190,7 @@ public class MyLocationViewSettings {
} else {
myLocationView.setShadowDrawable(backgroundDrawable);
}
+ myLocationView.setShadowDrawableTint(backgroundTintColor);
}
/**
@@ -200,7 +205,8 @@ public class MyLocationViewSettings {
/**
* Set the background tint color.
*
- * @param backgroundTintColor the color to tint the background
+ * @param backgroundTintColor the color to tint the background drawable or -1 (undefined color) to remove the
+ * existing background tint color
*/
public void setBackgroundTintColor(@ColorInt int backgroundTintColor) {
this.backgroundTintColor = backgroundTintColor;
--
cgit v1.2.1
From 655e23269542c63b2ca32692aea9f8782c09cf59 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 18 Jul 2017 12:32:40 +0200
Subject: [android] - fine tune fling gesture (#9532)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.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/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java
index 17eb506b97..c1e997c3a1 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
@@ -370,7 +370,7 @@ final class MapGestureDetector {
// tilt results in a bigger translation, limiting input for #5281
double tilt = transform.getTilt();
- double tiltFactor = 1 + ((tilt != 0) ? (tilt / 10) : 0); /* 1 -> 7 */
+ double tiltFactor = 1.5 + ((tilt != 0) ? (tilt / 10) : 0);
double offsetX = velocityX / tiltFactor / screenDensity;
double offsetY = velocityY / tiltFactor / screenDensity;
--
cgit v1.2.1
From 9c73d3458dfe70187209562c60a73081648e1015 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 7 Jul 2017 12:28:19 +0200
Subject: Hit test Marker and MarkerViews (#9424)
* [android] - hit test Marker and MarkerViews
* fixup
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 199 +++++++++++++--------
.../com/mapbox/mapboxsdk/maps/IconManager.java | 4 +
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 2 +-
3 files changed, 131 insertions(+), 74 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 3694668a7e..392eededdc 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
@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.maps;
+import android.graphics.Bitmap;
import android.graphics.PointF;
+import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
+import android.view.View;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
@@ -19,7 +22,6 @@ import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import timber.log.Timber;
@@ -55,7 +57,7 @@ class AnnotationManager {
this.markerViewManager = markerViewManager;
if (view != null) {
// null checking needed for unit tests
- nativeMapView.addOnMapChangedListener(markerViewManager);
+ view.addOnMapChangedListener(markerViewManager);
}
}
@@ -616,84 +618,135 @@ class AnnotationManager {
// Click event
//
- boolean onTap(PointF tapPoint, float screenDensity) {
- float toleranceSides = 4 * screenDensity;
- float toleranceTopBottom = 10 * screenDensity;
- boolean handledDefaultClick = false;
-
- RectF tapRect = new RectF(tapPoint.x - iconManager.getAverageIconWidth() / 2 - toleranceSides,
- tapPoint.y - iconManager.getAverageIconHeight() / 2 - toleranceTopBottom,
- tapPoint.x + iconManager.getAverageIconWidth() / 2 + toleranceSides,
- tapPoint.y + iconManager.getAverageIconHeight() / 2 + toleranceTopBottom);
-
- List nearbyMarkers = getMarkersInRect(tapRect);
- long newSelectedMarkerId = -1;
-
- // find a Marker that isn't selected yet
- if (nearbyMarkers.size() > 0) {
- Collections.sort(nearbyMarkers);
- for (Marker nearbyMarker : nearbyMarkers) {
- boolean found = false;
- for (Marker selectedMarker : selectedMarkers) {
- if (selectedMarker.equals(nearbyMarker)) {
- found = true;
- }
- }
- if (!found) {
- newSelectedMarkerId = nearbyMarker.getId();
- break;
+ boolean onTap(PointF tapPoint) {
+ MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
+ long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit);
+ return markerId >= 0 && isClickHandledForMarker(markerId);
+ }
+
+ private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
+ int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
+ int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
+ final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset,
+ tapPoint.y - averageIconHeightOffset,
+ tapPoint.x + averageIconWidthOffset,
+ tapPoint.y + averageIconHeightOffset
+ );
+ return new MarkerHit(tapRect, getMarkersInRect(tapRect));
+ }
+
+ private boolean isClickHandledForMarker(long markerId) {
+ boolean handledDefaultClick;
+ Marker marker = (Marker) getAnnotation(markerId);
+ if (marker instanceof MarkerView) {
+ handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
+ } else {
+ handledDefaultClick = onClickMarker(marker);
+ }
+
+ if (!handledDefaultClick) {
+ setMarkerSelectionState(marker);
+ }
+ return true;
+ }
+
+ private boolean onClickMarker(Marker marker) {
+ return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker);
+ }
+
+ private void setMarkerSelectionState(Marker marker) {
+ if (!selectedMarkers.contains(marker)) {
+ selectMarker(marker);
+ } else {
+ deselectMarker(marker);
+ }
+ }
+
+ private static class MarkerHitResolver {
+
+ private final MarkerViewManager markerViewManager;
+ private final Projection projection;
+
+ private View view;
+ private Bitmap bitmap;
+ private PointF markerLocation;
+
+ private Rect hitRectView = new Rect();
+ private RectF hitRectMarker = new RectF();
+ private RectF highestSurfaceIntersection = new RectF();
+
+ private long closestMarkerId = -1;
+
+ MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) {
+ this.markerViewManager = markerViewManager;
+ this.projection = projection;
+ }
+
+ public long execute(MarkerHit markerHit) {
+ resolveForMarkers(markerHit);
+ return closestMarkerId;
+ }
+
+ private void resolveForMarkers(MarkerHit markerHit) {
+ for (Marker marker : markerHit.markers) {
+ if (marker instanceof MarkerView) {
+ resolveForMarkerView(markerHit, (MarkerView) marker);
+ } else {
+ resolveForMarker(markerHit, marker);
}
}
}
- // if unselected marker found
- if (newSelectedMarkerId >= 0) {
- List annotations = getAnnotations();
- int count = annotations.size();
- for (int i = 0; i < count; i++) {
- Annotation annotation = annotations.get(i);
- if (annotation instanceof Marker) {
- if (annotation.getId() == newSelectedMarkerId) {
- Marker marker = (Marker) annotation;
-
- if (marker instanceof MarkerView) {
- handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker);
- } else {
- if (onMarkerClickListener != null) {
- // end developer has provided a custom click listener
- handledDefaultClick = onMarkerClickListener.onMarkerClick(marker);
- }
- }
-
- if (!handledDefaultClick) {
- // only select marker if user didn't handle the click event themselves
- selectMarker(marker);
- }
-
- return true;
- }
- }
+ private void resolveForMarkerView(MarkerHit markerHit, MarkerView markerView) {
+ view = markerViewManager.getView(markerView);
+ if (view != null) {
+ view.getHitRect(hitRectView);
+ hitRectMarker = new RectF(hitRectView);
+ hitTestMarker(markerHit, markerView, hitRectMarker);
}
- } else if (nearbyMarkers.size() > 0) {
- // we didn't find an unselected marker, check if we can close an already open markers
- for (Marker nearbyMarker : nearbyMarkers) {
- for (Marker selectedMarker : selectedMarkers) {
- if (nearbyMarker.equals(selectedMarker)) {
- if (nearbyMarker instanceof MarkerView) {
- handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) nearbyMarker);
- } else if (onMarkerClickListener != null) {
- handledDefaultClick = onMarkerClickListener.onMarkerClick(nearbyMarker);
- }
-
- if (!handledDefaultClick) {
- // only deselect marker if user didn't handle the click event themselves
- deselectMarker(nearbyMarker);
- }
- return true;
- }
+ }
+
+ private void resolveForMarker(MarkerHit markerHit, Marker marker) {
+ markerLocation = projection.toScreenLocation(marker.getPosition());
+ bitmap = marker.getIcon().getBitmap();
+ hitRectMarker.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
+ hitRectMarker.offsetTo(
+ markerLocation.x - bitmap.getWidth() / 2,
+ markerLocation.y - bitmap.getHeight() / 2
+ );
+ hitTestMarker(markerHit, marker, hitRectMarker);
+ }
+
+ private void hitTestMarker(MarkerHit markerHit, Marker marker, RectF hitRectMarker) {
+ if (hitRectMarker.contains(markerHit.getTapPointX(), markerHit.getTapPointY())) {
+ hitRectMarker.intersect(markerHit.tapRect);
+ if (isRectangleHighestSurfaceIntersection(hitRectMarker)) {
+ highestSurfaceIntersection = new RectF(hitRectMarker);
+ closestMarkerId = marker.getId();
}
}
}
- return false;
+
+ private boolean isRectangleHighestSurfaceIntersection(RectF rectF) {
+ return rectF.width() * rectF.height() > highestSurfaceIntersection.width() * highestSurfaceIntersection.height();
+ }
+ }
+
+ private static class MarkerHit {
+ private final RectF tapRect;
+ private final List markers;
+
+ MarkerHit(RectF tapRect, List markers) {
+ this.tapRect = tapRect;
+ this.markers = markers;
+ }
+
+ float getTapPointX() {
+ return tapRect.centerX();
+ }
+
+ float getTapPointY() {
+ return tapRect.centerY();
+ }
}
}
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 9f4171aee8..b5da5f59aa 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
@@ -12,6 +12,8 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import java.util.ArrayList;
import java.util.List;
+import timber.log.Timber;
+
/**
* Responsible for managing icons added to the Map.
*
@@ -105,6 +107,8 @@ class IconManager {
int iconSize = icons.size() + 1;
averageIconHeight = averageIconHeight + (height - averageIconHeight) / iconSize;
averageIconWidth = averageIconWidth + (width - averageIconWidth) / iconSize;
+ Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height);
+ Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight);
}
private void loadIcon(Icon icon) {
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 c1e997c3a1..d2973bf558 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
@@ -315,7 +315,7 @@ final class MapGestureDetector {
@Override
public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
PointF tapPoint = new PointF(motionEvent.getX(), motionEvent.getY());
- boolean tapHandled = annotationManager.onTap(tapPoint, uiSettings.getPixelRatio());
+ boolean tapHandled = annotationManager.onTap(tapPoint);
if (!tapHandled) {
if (uiSettings.isDeselectMarkersOnTap()) {
--
cgit v1.2.1
From d7401f9e219e4607146cf1c34af23edb474348eb Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 18 Jul 2017 15:34:55 +0200
Subject: [android] - add OnPolygonClickListener and OnPolylineClickListener
(#9443)
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 96 ++++++++++++++++++++--
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 50 +++++++++++
2 files changed, 137 insertions(+), 9 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 392eededdc..404cc5f3bd 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
@@ -9,6 +9,8 @@ import android.support.annotation.Nullable;
import android.support.v4.util.LongSparseArray;
import android.view.View;
+import com.mapbox.mapboxsdk.Mapbox;
+import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
@@ -20,6 +22,7 @@ import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
+import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.List;
@@ -39,6 +42,8 @@ import timber.log.Timber;
*/
class AnnotationManager {
+ private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
+
private final NativeMapView nativeMapView;
private final MapView mapView;
private final IconManager iconManager;
@@ -46,9 +51,12 @@ class AnnotationManager {
private final MarkerViewManager markerViewManager;
private final LongSparseArray annotations = new LongSparseArray<>();
private final List selectedMarkers = new ArrayList<>();
+ private final List shapeAnnotationIds = new ArrayList<>();
private MapboxMap mapboxMap;
private MapboxMap.OnMarkerClickListener onMarkerClickListener;
+ private MapboxMap.OnPolygonClickListener onPolygonClickListener;
+ private MapboxMap.OnPolylineClickListener onPolylineClickListener;
AnnotationManager(NativeMapView view, MapView mapView, MarkerViewManager markerViewManager) {
this.nativeMapView = view;
@@ -101,6 +109,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
long id = annotation.getId();
if (nativeMapView != null) {
@@ -131,6 +142,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
ids[i] = annotationList.get(i).getId();
}
@@ -158,6 +172,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
}
+ } else {
+ // instanceOf Polygon/Polyline
+ shapeAnnotationIds.remove(annotation.getId());
}
}
@@ -244,7 +261,6 @@ class AnnotationManager {
return marker;
}
-
List addMarkerViews(@NonNull List extends BaseMarkerViewOptions> markerViewOptions,
@NonNull MapboxMap mapboxMap) {
List markers = new ArrayList<>();
@@ -278,7 +294,6 @@ class AnnotationManager {
Timber.w("Attempting to update non-added Marker with value %s", updatedMarker);
return;
}
-
ensureIconLoaded(updatedMarker);
nativeMapView.updateMarker(updatedMarker);
annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker);
@@ -310,6 +325,14 @@ class AnnotationManager {
onMarkerClickListener = listener;
}
+ void setOnPolygonClickListener(@Nullable MapboxMap.OnPolygonClickListener listener) {
+ onPolygonClickListener = listener;
+ }
+
+ void setOnPolylineClickListener(@Nullable MapboxMap.OnPolylineClickListener listener) {
+ onPolylineClickListener = listener;
+ }
+
void selectMarker(@NonNull Marker marker) {
if (selectedMarkers.contains(marker)) {
return;
@@ -374,7 +397,7 @@ class AnnotationManager {
@NonNull
List getMarkersInRect(@NonNull RectF rectangle) {
- // convert Rectangle to be density depedent
+ // convert Rectangle to be density dependent
float pixelRatio = nativeMapView.getPixelRatio();
RectF rect = new RectF(rectangle.left / pixelRatio,
rectangle.top / pixelRatio,
@@ -438,6 +461,7 @@ class AnnotationManager {
long id = nativeMapView != null ? nativeMapView.addPolygon(polygon) : 0;
polygon.setId(id);
polygon.setMapboxMap(mapboxMap);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, polygon);
}
return polygon;
@@ -472,6 +496,7 @@ class AnnotationManager {
id++;
}
polygon.setId(id);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, polygon);
}
}
@@ -510,6 +535,7 @@ class AnnotationManager {
long id = nativeMapView != null ? nativeMapView.addPolyline(polyline) : 0;
polyline.setMapboxMap(mapboxMap);
polyline.setId(id);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, polyline);
}
return polyline;
@@ -546,6 +572,7 @@ class AnnotationManager {
id++;
}
p.setId(id);
+ shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, p);
}
}
@@ -555,6 +582,7 @@ class AnnotationManager {
void updatePolyline(@NonNull Polyline polyline) {
if (!isAddedToMap(polyline)) {
Timber.w("Attempting to update non-added Polyline with value %s", polyline);
+ return;
}
nativeMapView.updatePolyline(polyline);
@@ -619,11 +647,37 @@ class AnnotationManager {
//
boolean onTap(PointF tapPoint) {
+ ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
+ long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
+ if (shapeAnnotationId >= 0) {
+ handleClickForShapeAnnotation(shapeAnnotationId);
+ }
+
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
- long markerId = new MarkerHitResolver(markerViewManager, mapboxMap.getProjection()).execute(markerHit);
+ long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit);
return markerId >= 0 && isClickHandledForMarker(markerId);
}
+ private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) {
+ float touchTargetSide = Mapbox.getApplicationContext().getResources().getDimension(R.dimen.mapbox_eight_dp);
+ RectF tapRect = new RectF(
+ tapPoint.x - touchTargetSide,
+ tapPoint.y - touchTargetSide,
+ tapPoint.x + touchTargetSide,
+ tapPoint.y + touchTargetSide
+ );
+ return new ShapeAnnotationHit(tapRect, shapeAnnotationIds.toArray(new String[shapeAnnotationIds.size()]));
+ }
+
+ private void handleClickForShapeAnnotation(long shapeAnnotationId) {
+ Annotation annotation = getAnnotation(shapeAnnotationId);
+ if (annotation instanceof Polygon && onPolygonClickListener != null) {
+ onPolygonClickListener.onPolygonClick((Polygon) annotation);
+ } else if (annotation instanceof Polyline && onPolylineClickListener != null) {
+ onPolylineClickListener.onPolylineClick((Polyline) annotation);
+ }
+ }
+
private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
@@ -645,7 +699,7 @@ class AnnotationManager {
}
if (!handledDefaultClick) {
- setMarkerSelectionState(marker);
+ toggleMarkerSelectionState(marker);
}
return true;
}
@@ -654,7 +708,7 @@ class AnnotationManager {
return onMarkerClickListener != null && onMarkerClickListener.onMarkerClick(marker);
}
- private void setMarkerSelectionState(Marker marker) {
+ private void toggleMarkerSelectionState(Marker marker) {
if (!selectedMarkers.contains(marker)) {
selectMarker(marker);
} else {
@@ -662,6 +716,20 @@ class AnnotationManager {
}
}
+ private static class ShapeAnnotationHitResolver {
+
+ private MapboxMap mapboxMap;
+
+ ShapeAnnotationHitResolver(MapboxMap mapboxMap) {
+ this.mapboxMap = mapboxMap;
+ }
+
+ public long execute(ShapeAnnotationHit shapeHit) {
+ List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
+ return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId());
+ }
+ }
+
private static class MarkerHitResolver {
private final MarkerViewManager markerViewManager;
@@ -677,9 +745,9 @@ class AnnotationManager {
private long closestMarkerId = -1;
- MarkerHitResolver(@NonNull MarkerViewManager markerViewManager, @NonNull Projection projection) {
- this.markerViewManager = markerViewManager;
- this.projection = projection;
+ MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
+ this.markerViewManager = mapboxMap.getMarkerViewManager();
+ this.projection = mapboxMap.getProjection();
}
public long execute(MarkerHit markerHit) {
@@ -732,6 +800,16 @@ class AnnotationManager {
}
}
+ private static class ShapeAnnotationHit {
+ private final RectF tapPoint;
+ private final String[] layerIds;
+
+ ShapeAnnotationHit(RectF tapRect, String[] layerIds) {
+ this.tapPoint = tapRect;
+ this.layerIds = layerIds;
+ }
+ }
+
private static class MarkerHit {
private final RectF tapRect;
private final List markers;
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 d672ab37c3..c8725d8d8d 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
@@ -1459,6 +1459,28 @@ public final class MapboxMap {
annotationManager.setOnMarkerClickListener(listener);
}
+ /**
+ * Sets a callback that's invoked when the user clicks on a polygon.
+ *
+ * @param listener The callback that's invoked when the user clicks on a polygon.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener) {
+ annotationManager.setOnPolygonClickListener(listener);
+ }
+
+ /**
+ * Sets a callback that's invoked when the user clicks on a polyline.
+ *
+ * @param listener The callback that's invoked when the user clicks on a polyline.
+ * To unset the callback, use null.
+ */
+ @UiThread
+ public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener) {
+ annotationManager.setOnPolylineClickListener(listener);
+ }
+
/**
*
* Selects a marker. The selected marker will have it's info window opened.
@@ -2150,6 +2172,34 @@ public final class MapboxMap {
boolean onMarkerClick(@NonNull Marker marker);
}
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on a polygon.
+ *
+ * @see MapboxMap#setOnPolygonClickListener(OnPolygonClickListener)
+ */
+ public interface OnPolygonClickListener {
+ /**
+ * Called when the user clicks on a polygon.
+ *
+ * @param polygon The polygon the user clicked on.
+ */
+ void onPolygonClick(@NonNull Polygon polygon);
+ }
+
+ /**
+ * Interface definition for a callback to be invoked when the user clicks on a polyline.
+ *
+ * @see MapboxMap#setOnPolylineClickListener(OnPolylineClickListener)
+ */
+ public interface OnPolylineClickListener {
+ /**
+ * Called when the user clicks on a polyline.
+ *
+ * @param polyline The polyline the user clicked on.
+ */
+ void onPolylineClick(@NonNull Polyline polyline);
+ }
+
/**
* Interface definition for a callback to be invoked when the user clicks on an info window.
*
--
cgit v1.2.1
From a39b4cfb00c567d93bb83390d9bbdccef12b1c65 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 20 Jul 2017 17:26:28 +0200
Subject: [android] - manage InfoWindow selection in AnnotationManager (#9567)
---
.../java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java | 5 -----
1 file changed, 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index dce6f6b277..8704e882ea 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -570,11 +570,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter);
}
- if (!clickHandled) {
- ensureInfoWindowOffset(markerView);
- select(markerView, view, adapter);
- }
-
return clickHandled;
}
--
cgit v1.2.1
From 820c04efbfa5c7e30bf5ff055538ccdd6e11b14d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 20 Jul 2017 16:51:27 +0200
Subject: [android] - increase touch target to match largest Marker icon
(#9565)
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 12 +++----
.../com/mapbox/mapboxsdk/maps/IconManager.java | 42 +++++++++++-----------
2 files changed, 27 insertions(+), 27 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 404cc5f3bd..f35eb9b4f0 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
@@ -679,12 +679,12 @@ class AnnotationManager {
}
private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
- int averageIconWidthOffset = iconManager.getAverageIconWidth() / 2;
- int averageIconHeightOffset = iconManager.getAverageIconHeight() / 2;
- final RectF tapRect = new RectF(tapPoint.x - averageIconWidthOffset,
- tapPoint.y - averageIconHeightOffset,
- tapPoint.x + averageIconWidthOffset,
- tapPoint.y + averageIconHeightOffset
+ int touchSurfaceWidth = (int) (iconManager.getHighestIconHeight() * 1.5);
+ int touchSurfaceHeight = (int) (iconManager.getHighestIconWidth() * 1.5);
+ final RectF tapRect = new RectF(tapPoint.x - touchSurfaceWidth,
+ tapPoint.y - touchSurfaceHeight,
+ tapPoint.x + touchSurfaceWidth,
+ tapPoint.y + touchSurfaceHeight
);
return new MarkerHit(tapRect, getMarkersInRect(tapRect));
}
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 b5da5f59aa..18eecfd9c3 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
@@ -12,8 +12,6 @@ import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException;
import java.util.ArrayList;
import java.util.List;
-import timber.log.Timber;
-
/**
* Responsible for managing icons added to the Map.
*
@@ -30,8 +28,8 @@ class IconManager {
private NativeMapView nativeMapView;
private List icons;
- private int averageIconHeight;
- private int averageIconWidth;
+ private int highestIconWidth;
+ private int highestIconHeight;
IconManager(NativeMapView nativeMapView) {
this.nativeMapView = nativeMapView;
@@ -47,7 +45,7 @@ class IconManager {
// TODO we can move this code afterwards to getIcon as with MarkerView.getIcon
icon = loadDefaultIconForMarker(marker);
} else {
- updateAverageIconSize(icon);
+ updateHighestIconSize(icon);
}
addIcon(icon);
return icon;
@@ -56,7 +54,7 @@ class IconManager {
void loadIconForMarkerView(MarkerView marker) {
Icon icon = marker.getIcon();
Bitmap bitmap = icon.getBitmap();
- updateAverageIconSize(bitmap);
+ updateHighestIconSize(bitmap);
addIcon(icon, false);
}
@@ -64,18 +62,18 @@ class IconManager {
return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio());
}
- int getAverageIconHeight() {
- return averageIconHeight;
+ int getHighestIconWidth() {
+ return highestIconWidth;
}
- int getAverageIconWidth() {
- return averageIconWidth;
+ int getHighestIconHeight() {
+ return highestIconHeight;
}
private Icon loadDefaultIconForMarker(Marker marker) {
Icon icon = IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarker();
Bitmap bitmap = icon.getBitmap();
- updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
+ updateHighestIconSize(bitmap.getWidth(), bitmap.getHeight() / 2);
marker.setIcon(icon);
return icon;
}
@@ -95,20 +93,22 @@ class IconManager {
}
}
- private void updateAverageIconSize(Icon icon) {
- updateAverageIconSize(icon.getBitmap());
+ private void updateHighestIconSize(Icon icon) {
+ updateHighestIconSize(icon.getBitmap());
}
- private void updateAverageIconSize(Bitmap bitmap) {
- updateAverageIconSize(bitmap.getWidth(), bitmap.getHeight());
+ private void updateHighestIconSize(Bitmap bitmap) {
+ updateHighestIconSize(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;
- Timber.e("OnUpdateAverageSizeIcon with: %s %s", width, height);
- Timber.e("OnUpdateAverageSizeIcon now: %s %s", averageIconWidth, averageIconHeight);
+ private void updateHighestIconSize(int width, int height) {
+ if (width > highestIconWidth) {
+ highestIconWidth = width;
+ }
+
+ if (height > highestIconHeight) {
+ highestIconHeight = height;
+ }
}
private void loadIcon(Icon icon) {
--
cgit v1.2.1
From b34a5ab276145dd5499133738caf0e8d6d30ddb7 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 20 Jul 2017 17:32:23 +0200
Subject: [android] - update change log, fix typo public xml
---
.../android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index 7294f43c02..f30cb7c27a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -20,7 +20,7 @@
-
+
--
cgit v1.2.1
From 7aad3613c3549ae5f4388fcbeef969e13274892b Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Fri, 21 Jul 2017 11:18:26 +0200
Subject: update release config
---
.../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
index 029d25e046..a02b5d63ac 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
+++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
@@ -1,3 +1,3 @@
fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk
-fabric-version=5.1.0
+fabric-version=5.1.1
fabric-build-type=binary
--
cgit v1.2.1
From 541712aac7433856811e2c24dff583333aabd3c8 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Mon, 24 Jul 2017 12:08:20 +0200
Subject: [android] fix geojson source proguard issue (#9569) (#9577)
---
platform/android/MapboxGLAndroidSDK/proguard-rules.pro | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
index 8e47815451..68edc12f35 100644
--- a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
+++ b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
@@ -6,4 +6,5 @@
-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
+-keep class com.mapbox.services.commons.** { *;}
+-keep class com.google.gson.** { *; }
\ No newline at end of file
--
cgit v1.2.1
From e8ad7b6a49d12a1f414e0242007a671c4514d85a Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 24 Jul 2017 11:05:29 +0200
Subject: [android] - validate Marker before opening InfoWindow
---
.../src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
index 0b461d1227..af207204d9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.maps;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
@@ -55,8 +54,8 @@ class InfoWindowManager {
return allowConcurrentMultipleInfoWindows;
}
- boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
- return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
+ boolean isInfoWindowValidForMarker(Marker marker) {
+ return marker != null && (!TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet()));
}
void setOnInfoWindowClickListener(@Nullable MapboxMap.OnInfoWindowClickListener listener) {
--
cgit v1.2.1
From 3364992be94364a6e8b302124db53aeed5d99c15 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 24 Jul 2017 10:45:35 +0200
Subject: [android] - harden click handling of shape annotations
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 24 ++++++++++++++++++----
1 file changed, 20 insertions(+), 4 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 73e90206f8..22e5cf4322 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
@@ -26,6 +26,8 @@ import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.List;
+import timber.log.Timber;
+
/**
* Responsible for managing and tracking state of Annotations linked to Map. All events related to
* annotations that occur on {@link MapboxMap} are forwarded to this class.
@@ -40,6 +42,7 @@ import java.util.List;
class AnnotationManager {
private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
+ private static final long NO_ANNOTATION_ID = -1;
private final MapView mapView;
private final IconManager iconManager;
@@ -369,13 +372,13 @@ class AnnotationManager {
boolean onTap(PointF tapPoint) {
ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId >= 0) {
+ if (shapeAnnotationId != NO_ANNOTATION_ID) {
handleClickForShapeAnnotation(shapeAnnotationId);
}
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit);
- return markerId >= 0 && isClickHandledForMarker(markerId);
+ return markerId != NO_ANNOTATION_ID && isClickHandledForMarker(markerId);
}
private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) {
@@ -445,8 +448,21 @@ class AnnotationManager {
}
public long execute(ShapeAnnotationHit shapeHit) {
+ long foundAnnotationId = NO_ANNOTATION_ID;
List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
- return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId());
+ if (!features.isEmpty()) {
+ foundAnnotationId = getIdFromFeature(features.get(0));
+ }
+ return foundAnnotationId;
+ }
+
+ private long getIdFromFeature(Feature feature) {
+ try {
+ return Long.valueOf(feature.getId());
+ } catch (NumberFormatException exception) {
+ Timber.e(exception, "Couldn't parse feature id to a long, with id: %s", feature.getId());
+ return NO_ANNOTATION_ID;
+ }
}
}
@@ -463,7 +479,7 @@ class AnnotationManager {
private RectF hitRectMarker = new RectF();
private RectF highestSurfaceIntersection = new RectF();
- private long closestMarkerId = -1;
+ private long closestMarkerId = NO_ANNOTATION_ID;
MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
this.markerViewManager = mapboxMap.getMarkerViewManager();
--
cgit v1.2.1
From 0e0536a8d7203fbf3883c0e148cb509188d2b496 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Tue, 25 Jul 2017 13:01:31 +0200
Subject: [android] fix added to map checks because LongSparseArray#indexOfKey
could return a negative number when the specified key is not mapped (#9602)
---
.../com/mapbox/mapboxsdk/maps/AnnotationManager.java | 20 ++++++++++++++++++++
.../com/mapbox/mapboxsdk/maps/MarkerContainer.java | 11 -----------
.../com/mapbox/mapboxsdk/maps/PolygonContainer.java | 11 -----------
.../com/mapbox/mapboxsdk/maps/PolylineContainer.java | 11 -----------
4 files changed, 20 insertions(+), 33 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 22e5cf4322..960f71ca13 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
@@ -181,6 +181,10 @@ class AnnotationManager {
}
void updateMarker(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
+ if (!isAddedToMap(updatedMarker)) {
+ logNonAdded(updatedMarker);
+ return;
+ }
markers.update(updatedMarker, mapboxMap);
}
@@ -230,6 +234,10 @@ class AnnotationManager {
}
void updatePolygon(Polygon polygon) {
+ if (!isAddedToMap(polygon)) {
+ logNonAdded(polygon);
+ return;
+ }
polygons.update(polygon);
}
@@ -256,6 +264,10 @@ class AnnotationManager {
}
void updatePolyline(Polyline polyline) {
+ if (!isAddedToMap(polyline)) {
+ logNonAdded(polyline);
+ return;
+ }
polylines.update(polyline);
}
@@ -365,6 +377,14 @@ class AnnotationManager {
}
}
+ private boolean isAddedToMap(Annotation annotation) {
+ return annotation != null && annotation.getId() != -1 && annotationsArray.indexOfKey(annotation.getId()) > -1;
+ }
+
+ private void logNonAdded(Annotation annotation) {
+ Timber.w("Attempting to update non-added %s with value %s", annotation.getClass().getCanonicalName(), annotation);
+ }
+
//
// Click event
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
index ef8054d70e..b6bee199a3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
@@ -18,8 +18,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import java.util.ArrayList;
import java.util.List;
-import timber.log.Timber;
-
/**
* Encapsulates {@link Marker}'s functionality.
*/
@@ -92,11 +90,6 @@ class MarkerContainer implements Markers {
@Override
public void update(@NonNull Marker updatedMarker, @NonNull MapboxMap mapboxMap) {
- if (!isAddedToMap(updatedMarker)) {
- Timber.w("Attempting to update non-added Marker with value %s", updatedMarker);
- return;
- }
-
ensureIconLoaded(updatedMarker, mapboxMap);
nativeMapView.updateMarker(updatedMarker);
annotations.setValueAt(annotations.indexOfKey(updatedMarker.getId()), updatedMarker);
@@ -237,10 +230,6 @@ class MarkerContainer implements Markers {
return marker;
}
- private boolean isAddedToMap(Annotation annotation) {
- return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
- }
-
private void ensureIconLoaded(Marker marker, MapboxMap mapboxMap) {
if (!(marker instanceof MarkerView)) {
iconManager.ensureIconLoaded(marker, mapboxMap);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
index bcb94a975c..e626fc3dc0 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
@@ -11,8 +11,6 @@ import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import java.util.ArrayList;
import java.util.List;
-import timber.log.Timber;
-
/**
* Encapsulates {@link Polygon}'s functionality.
*/
@@ -76,11 +74,6 @@ class PolygonContainer implements Polygons {
@Override
public void update(Polygon polygon) {
- if (!isAddedToMap(polygon)) {
- Timber.w("Attempting to update non-added Polygon with value %s", polygon);
- return;
- }
-
nativeMapView.updatePolygon(polygon);
annotations.setValueAt(annotations.indexOfKey(polygon.getId()), polygon);
}
@@ -97,8 +90,4 @@ class PolygonContainer implements Polygons {
}
return polygons;
}
-
- private boolean isAddedToMap(Annotation annotation) {
- return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
- }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
index 397b70a158..b9a358c0f9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
@@ -11,8 +11,6 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import java.util.ArrayList;
import java.util.List;
-import timber.log.Timber;
-
/**
* Encapsulates {@link Polyline}'s functionality.
*/
@@ -78,11 +76,6 @@ class PolylineContainer implements Polylines {
@Override
public void update(Polyline polyline) {
- if (!isAddedToMap(polyline)) {
- Timber.w("Attempting to update non-added Polyline with value %s", polyline);
- return;
- }
-
nativeMapView.updatePolyline(polyline);
annotations.setValueAt(annotations.indexOfKey(polyline.getId()), polyline);
}
@@ -99,8 +92,4 @@ class PolylineContainer implements Polylines {
}
return polylines;
}
-
- private boolean isAddedToMap(Annotation annotation) {
- return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
- }
}
--
cgit v1.2.1
From a28228013ce83ce115175d0a40b62fe0bfe81559 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 25 Jul 2017 12:50:36 +0200
Subject: [android] - don't query for shape annotations if none were added
---
.../main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 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 960f71ca13..edf448ab4f 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
@@ -390,10 +390,12 @@ class AnnotationManager {
//
boolean onTap(PointF tapPoint) {
- ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
- long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId != NO_ANNOTATION_ID) {
- handleClickForShapeAnnotation(shapeAnnotationId);
+ if (!shapeAnnotationIds.isEmpty()) {
+ ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
+ long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
+ if (shapeAnnotationId != NO_ANNOTATION_ID) {
+ handleClickForShapeAnnotation(shapeAnnotationId);
+ }
}
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
--
cgit v1.2.1
From 906fc0421aa85308460586023cfe727501c9bbb5 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 25 Jul 2017 14:10:31 +0200
Subject: [android] - hook into onGlobalLayout to start creating the surface
and as a result create the map object
---
.../main/java/com/mapbox/mapboxsdk/maps/MapView.java | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 bb8771b5dd..1f31e3b5a3 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
@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.SurfaceTexture;
+import android.os.Build;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
@@ -21,6 +22,7 @@ import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ZoomButtonsController;
@@ -122,6 +124,18 @@ public class MapView extends FrameLayout {
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
setWillNotDraw(false);
+
+ getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ } else {
+ getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ }
+ initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
+ }
+ });
}
private void initialiseMap() {
@@ -553,9 +567,6 @@ public class MapView extends FrameLayout {
if (isInEditMode()) {
return;
}
- if (visibility == View.VISIBLE && nativeMapView == null) {
- initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
- }
if (mapZoomButtonController != null && nativeMapView != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
--
cgit v1.2.1
From 93ba48a3a4df9551784497fc942b25a0a5a0d00f Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 26 Jul 2017 17:09:54 +0200
Subject: [android] - forward getMapAsync to map for fragment
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java | 10 ++++++++--
.../java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java | 10 ++++++++--
2 files changed, 16 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
index 8b1ba7b771..01c6da4971 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapFragment.java
@@ -76,6 +76,9 @@ public final class MapFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
map.onCreate(savedInstanceState);
+ if (onMapReadyCallback != null) {
+ map.getMapAsync(onMapReadyCallback);
+ }
}
/**
@@ -85,7 +88,6 @@ public final class MapFragment extends Fragment {
public void onStart() {
super.onStart();
map.onStart();
- map.getMapAsync(onMapReadyCallback);
}
/**
@@ -150,6 +152,10 @@ public final class MapFragment extends Fragment {
* @param onMapReadyCallback The callback to be invoked.
*/
public void getMapAsync(@NonNull final OnMapReadyCallback onMapReadyCallback) {
- this.onMapReadyCallback = onMapReadyCallback;
+ if (map == null) {
+ this.onMapReadyCallback = onMapReadyCallback;
+ } else {
+ map.getMapAsync(onMapReadyCallback);
+ }
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
index 77fea1a14a..6c90cd95ec 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/SupportMapFragment.java
@@ -76,6 +76,9 @@ public class SupportMapFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
map.onCreate(savedInstanceState);
+ if (onMapReadyCallback != null) {
+ map.getMapAsync(onMapReadyCallback);
+ }
}
/**
@@ -85,7 +88,6 @@ public class SupportMapFragment extends Fragment {
public void onStart() {
super.onStart();
map.onStart();
- map.getMapAsync(onMapReadyCallback);
}
/**
@@ -150,6 +152,10 @@ public class SupportMapFragment extends Fragment {
* @param onMapReadyCallback The callback to be invoked.
*/
public void getMapAsync(@NonNull final OnMapReadyCallback onMapReadyCallback) {
- this.onMapReadyCallback = onMapReadyCallback;
+ if (map == null) {
+ this.onMapReadyCallback = onMapReadyCallback;
+ } else {
+ map.getMapAsync(onMapReadyCallback);
+ }
}
}
--
cgit v1.2.1
From c5a5b4083795107b7df7bab39b461568a3861dba Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 24 Jul 2017 18:46:23 +0200
Subject: [android] - add zMediaOverlay configuration, add bottom sheet test
setup
---
.../android/MapboxGLAndroidSDK/gradle.properties | 2 +-
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 7 ++---
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 30 +++++++++++++++++++++-
.../src/main/res-public/values/public.xml | 3 +++
.../src/main/res/values/attrs.xml | 1 +
5 files changed, 38 insertions(+), 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 078fdbc801..ff6e2f61df 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -17,4 +17,4 @@ POM_PACKAGING=aar
# Only build native dependencies for the current ABI
# See https://code.google.com/p/android/issues/detail?id=221098#c20
-android.buildOnlyTargetAbi=true
+android.buildOnlyTargetAbi=true
\ No newline at end of file
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 1f31e3b5a3..848a898f94 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
@@ -133,7 +133,7 @@ public class MapView extends FrameLayout {
} else {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
- initialiseDrawingSurface(mapboxMapOptions.getTextureMode());
+ initialiseDrawingSurface(mapboxMapOptions);
}
});
}
@@ -229,13 +229,14 @@ public class MapView extends FrameLayout {
}
}
- private void initialiseDrawingSurface(boolean textureMode) {
- if (textureMode) {
+ private void initialiseDrawingSurface(MapboxMapOptions mapboxMapOptions) {
+ if (mapboxMapOptions.getTextureMode()) {
TextureView textureView = new TextureView(getContext());
textureView.setSurfaceTextureListener(new SurfaceTextureListener());
addView(textureView, 0);
} else {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
+ surfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
surfaceView.getHolder().addCallback(new SurfaceCallback());
surfaceView.setVisibility(View.VISIBLE);
}
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 4301d64375..94e2fbcf3b 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
@@ -81,6 +81,7 @@ public class MapboxMapOptions implements Parcelable {
private int myLocationAccuracyAlpha;
private float myLocationAccuracyThreshold;
private boolean prefetchesTiles = true;
+ private boolean zMediaOverlay = false;
private String apiBaseUrl;
@@ -156,6 +157,7 @@ public class MapboxMapOptions implements Parcelable {
apiBaseUrl = in.readString();
textureMode = in.readByte() != 0;
prefetchesTiles = in.readByte() != 0;
+ zMediaOverlay = in.readByte() != 0;
}
static Bitmap getBitmapFromDrawable(Drawable drawable) {
@@ -301,6 +303,8 @@ public class MapboxMapOptions implements Parcelable {
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
mapboxMapOptions.setPrefetchesTiles(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
+ mapboxMapOptions.renderSurfaceOnTop(
+ typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false));
} finally {
typedArray.recycle();
}
@@ -718,7 +722,6 @@ public class MapboxMapOptions implements Parcelable {
/**
* Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
* a low resolution preview while more detailed tiles are loaded.
- *
* Enabled by default
*
* @param enable true to enable
@@ -739,6 +742,25 @@ public class MapboxMapOptions implements Parcelable {
return prefetchesTiles;
}
+
+ /**
+ * Set the flag to render the map surface on top of another surface.
+ *
+ * @param renderOnTop true if this map is shown on top of another one, false if bottom.
+ */
+ public void renderSurfaceOnTop(boolean renderOnTop) {
+ this.zMediaOverlay = renderOnTop;
+ }
+
+ /**
+ * Get the flag to render the map surface on top of another surface.
+ *
+ * @return true if this map is
+ */
+ public boolean getRenderSurfaceOnTop() {
+ return zMediaOverlay;
+ }
+
/**
* Get the current configured API endpoint base URL.
*
@@ -1123,6 +1145,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeString(apiBaseUrl);
dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
+ dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
}
@Override
@@ -1249,6 +1272,10 @@ public class MapboxMapOptions implements Parcelable {
if (prefetchesTiles != options.prefetchesTiles) {
return false;
}
+ if (zMediaOverlay != options.zMediaOverlay) {
+ return false;
+ }
+
return false;
}
@@ -1296,6 +1323,7 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
+ result = 31 * result + (zMediaOverlay ? 1 : 0);
return result;
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index f30cb7c27a..3decd6ead1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -75,6 +75,9 @@
+
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index a7ef78d699..281fe8afe3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -118,6 +118,7 @@
+
--
cgit v1.2.1
From a8ef2af353de195648578bf0d753703cb6f34905 Mon Sep 17 00:00:00 2001
From: Lauren Budorick
Date: Wed, 26 Jul 2017 13:18:47 -0700
Subject: [core][android][macos][ios] Implement property functions for
line-join, text-justify, text-anchor (#9583)
---
.../mapbox/mapboxsdk/style/layers/PropertyFactory.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index 1c68878772..ef89c6809e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -1482,11 +1482,11 @@ public class PropertyFactory {
/**
* The display of lines when joining.
*
- * @param the zoom parameter type
- * @param function a wrapper {@link CameraFunction} for String
+ * @param the function input type
+ * @param function a wrapper function for String
* @return property wrapper around a String function
*/
- public static PropertyValue> lineJoin(CameraFunction function) {
+ public static PropertyValue> lineJoin(Function function) {
return new LayoutPropertyValue<>("line-join", function);
}
@@ -2103,11 +2103,11 @@ public class PropertyFactory {
/**
* Text justification options.
*
- * @param the zoom parameter type
- * @param function a wrapper {@link CameraFunction} for String
+ * @param the function input type
+ * @param function a wrapper function for String
* @return property wrapper around a String function
*/
- public static PropertyValue> textJustify(CameraFunction function) {
+ public static PropertyValue> textJustify(Function function) {
return new LayoutPropertyValue<>("text-justify", function);
}
@@ -2126,11 +2126,11 @@ public class PropertyFactory {
/**
* Part of the text placed closest to the anchor.
*
- * @param the zoom parameter type
- * @param function a wrapper {@link CameraFunction} for String
+ * @param the function input type
+ * @param function a wrapper function for String
* @return property wrapper around a String function
*/
- public static PropertyValue> textAnchor(CameraFunction function) {
+ public static PropertyValue> textAnchor(Function function) {
return new LayoutPropertyValue<>("text-anchor", function);
}
--
cgit v1.2.1
From 175e7e26e2008d1e55664bd1064536c23b6de86a Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 27 Jul 2017 15:38:53 +0200
Subject: [android] fix compass direction (Transform::getCameraOptions returns
counterclockwise angle after transform.invalidateCameraPosition() which needs
to be transformed to a clockwise bearing) (#9632)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 e8891429f9..e71d509fcf 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
@@ -427,7 +427,8 @@ public final class UiSettings {
return;
}
- compassView.update(cameraPosition.bearing);
+ double clockwiseBearing = -cameraPosition.bearing;
+ compassView.update(clockwiseBearing);
}
/**
--
cgit v1.2.1
From 5e6ca3ada217c84fa2f198e5de6bc89bc2c5874d Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Mon, 24 Jul 2017 12:08:20 +0200
Subject: [android] fix geojson source proguard issue (#9569) (#9577)
---
platform/android/MapboxGLAndroidSDK/proguard-rules.pro | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
index 8e47815451..68edc12f35 100644
--- a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
+++ b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
@@ -6,4 +6,5 @@
-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
+-keep class com.mapbox.services.commons.** { *;}
+-keep class com.google.gson.** { *; }
\ No newline at end of file
--
cgit v1.2.1
From 0eee31e212a9936bcfe0c61a3bf3635a8778a434 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 24 Jul 2017 10:45:35 +0200
Subject: [android] - harden click handling of shape annotations
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 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 f35eb9b4f0..ef794c8482 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
@@ -43,6 +43,7 @@ import timber.log.Timber;
class AnnotationManager {
private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
+ private static final long NO_ANNOTATION_ID = -1;
private final NativeMapView nativeMapView;
private final MapView mapView;
@@ -649,13 +650,13 @@ class AnnotationManager {
boolean onTap(PointF tapPoint) {
ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId >= 0) {
+ if (shapeAnnotationId != NO_ANNOTATION_ID) {
handleClickForShapeAnnotation(shapeAnnotationId);
}
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
long markerId = new MarkerHitResolver(mapboxMap).execute(markerHit);
- return markerId >= 0 && isClickHandledForMarker(markerId);
+ return markerId != NO_ANNOTATION_ID && isClickHandledForMarker(markerId);
}
private ShapeAnnotationHit getShapeAnnotationHitFromTap(PointF tapPoint) {
@@ -725,8 +726,21 @@ class AnnotationManager {
}
public long execute(ShapeAnnotationHit shapeHit) {
+ long foundAnnotationId = NO_ANNOTATION_ID;
List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
- return features.isEmpty() ? -1 : Long.valueOf(features.get(0).getId());
+ if (!features.isEmpty()) {
+ foundAnnotationId = getIdFromFeature(features.get(0));
+ }
+ return foundAnnotationId;
+ }
+
+ private long getIdFromFeature(Feature feature) {
+ try {
+ return Long.valueOf(feature.getId());
+ } catch (NumberFormatException exception) {
+ Timber.e(exception, "Couldn't parse feature id to a long, with id: %s", feature.getId());
+ return NO_ANNOTATION_ID;
+ }
}
}
@@ -743,7 +757,7 @@ class AnnotationManager {
private RectF hitRectMarker = new RectF();
private RectF highestSurfaceIntersection = new RectF();
- private long closestMarkerId = -1;
+ private long closestMarkerId = NO_ANNOTATION_ID;
MarkerHitResolver(@NonNull MapboxMap mapboxMap) {
this.markerViewManager = mapboxMap.getMarkerViewManager();
--
cgit v1.2.1
From beaee9349f0608246547d9092b6690a80d633e6e Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 24 Jul 2017 11:05:29 +0200
Subject: [android] - validate Marker before opening InfoWindow
---
.../main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
index 7599b6afa6..11100d6f17 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/InfoWindowManager.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.maps;
-import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
@@ -56,12 +55,8 @@ class InfoWindowManager {
return allowConcurrentMultipleInfoWindows;
}
- List getInfoWindows() {
- return infoWindows;
- }
-
- boolean isInfoWindowValidForMarker(@NonNull Marker marker) {
- return !TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet());
+ boolean isInfoWindowValidForMarker(Marker marker) {
+ return marker != null && (!TextUtils.isEmpty(marker.getTitle()) || !TextUtils.isEmpty(marker.getSnippet()));
}
void setOnInfoWindowClickListener(@Nullable MapboxMap.OnInfoWindowClickListener listener) {
--
cgit v1.2.1
From 635a3f21a0373335d4a334f5bb487251f027f47c Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Tue, 25 Jul 2017 13:01:31 +0200
Subject: [android] fix added to map checks because LongSparseArray#indexOfKey
could return a negative number when the specified key is not mapped (#9602)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.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/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java
index ef794c8482..251e5afabe 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
@@ -301,7 +301,7 @@ class AnnotationManager {
}
private boolean isAddedToMap(Annotation annotation) {
- return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) != -1;
+ return annotation != null && annotation.getId() != -1 && annotations.indexOfKey(annotation.getId()) > -1;
}
private void ensureIconLoaded(Marker marker) {
--
cgit v1.2.1
From 009da507fa780d111bb574154840a061ab284c8f Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 25 Jul 2017 12:50:36 +0200
Subject: [android] - don't query for shape annotations if none were added
---
.../main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 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 251e5afabe..712ab67de0 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
@@ -648,10 +648,12 @@ class AnnotationManager {
//
boolean onTap(PointF tapPoint) {
- ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
- long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId != NO_ANNOTATION_ID) {
- handleClickForShapeAnnotation(shapeAnnotationId);
+ if (!shapeAnnotationIds.isEmpty()) {
+ ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
+ long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
+ if (shapeAnnotationId != NO_ANNOTATION_ID) {
+ handleClickForShapeAnnotation(shapeAnnotationId);
+ }
}
MarkerHit markerHit = getMarkerHitFromTouchArea(tapPoint);
--
cgit v1.2.1
From 9b770f382ef7f1251f0f770175514345899101a8 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 26 Jul 2017 16:45:49 +0200
Subject: [android] - build snapshots from release branch for v5.1.2
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 078fdbc801..a8646e3270 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.2.0-SNAPSHOT
+VERSION_NAME=5.1.2-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
--
cgit v1.2.1
From caba393c0ec3042a3e8e7f1a782e0283d131a996 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 27 Jul 2017 15:38:53 +0200
Subject: [android] fix compass direction (Transform::getCameraOptions returns
counterclockwise angle after transform.invalidateCameraPosition() which needs
to be transformed to a clockwise bearing) (#9632)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 7f8ba21e3e..3f43c23a7f 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
@@ -421,7 +421,8 @@ public final class UiSettings {
return;
}
- compassView.update(cameraPosition.bearing);
+ double clockwiseBearing = -cameraPosition.bearing;
+ compassView.update(clockwiseBearing);
}
/**
--
cgit v1.2.1
From 685b8b2c84e47d8126e924ff3fddc22a96237680 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 28 Jul 2017 19:36:13 +0200
Subject: Solve lint issues, reduce baseline (#9627)
* [android] - fix lint issues SDK
---
platform/android/MapboxGLAndroidSDK/build.gradle | 2 +-
.../MapboxGLAndroidSDK/lint-baseline-local.xml | 37 ++
.../MapboxGLAndroidSDK/lint/lint-baseline-ci.xml | 587 +--------------------
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 2 +
.../mapbox/mapboxsdk/annotations/IconFactory.java | 2 +
.../com/mapbox/mapboxsdk/http/HTTPRequest.java | 15 +-
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 5 +-
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 10 +-
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 4 +-
.../mapboxsdk/maps/widgets/MyLocationView.java | 2 +
.../mapbox/mapboxsdk/net/ConnectivityReceiver.java | 4 +-
.../mapbox/mapboxsdk/offline/OfflineManager.java | 10 +-
.../com/mapbox/mapboxsdk/storage/FileSource.java | 6 +-
.../mapbox/mapboxsdk/style/functions/Function.java | 2 +-
.../src/main/res-public/values/public.xml | 4 +-
.../main/res/color/mapbox_material_bg_selector.xml | 5 -
.../res/drawable-nodpi/mapbox_mapview_preview.jpg | Bin 0 -> 166053 bytes
.../res/drawable-xxhdpi/mapbox_mapview_preview.jpg | Bin 166053 -> 0 bytes
.../mapbox_infowindow_icon_bg.9.png | Bin 928 -> 0 bytes
.../res/layout/mapbox_attribution_list_item.xml | 1 +
.../main/res/layout/mapbox_infowindow_content.xml | 3 +-
.../main/res/layout/mapbox_view_image_marker.xml | 7 +-
.../src/main/res/values/colors.xml | 1 -
.../src/main/res/values/dimens.xml | 9 -
24 files changed, 82 insertions(+), 636 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/lint-baseline-local.xml
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/color/mapbox_material_bg_selector.xml
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-nodpi/mapbox_mapview_preview.jpg
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_infowindow_icon_bg.9.png
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 0cb6e529f1..5e7025c4c8 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -116,7 +116,7 @@ android {
}
lintOptions {
- baseline file("lint-baseline.xml")
+ baseline file("lint-baseline-local.xml")
checkAllWarnings true
warningsAsErrors true
}
diff --git a/platform/android/MapboxGLAndroidSDK/lint-baseline-local.xml b/platform/android/MapboxGLAndroidSDK/lint-baseline-local.xml
new file mode 100644
index 0000000000..0a76f53505
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/lint-baseline-local.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml b/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
index 4dc8ecde70..fd65c9f627 100644
--- a/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
+++ b/platform/android/MapboxGLAndroidSDK/lint/lint-baseline-ci.xml
@@ -1,5 +1,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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 3af7921596..70b13f05fb 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.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -26,6 +27,7 @@ import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
@UiThread
public final class Mapbox {
+ @SuppressLint("StaticFieldLeak")
private static Mapbox INSTANCE;
private Context context;
private String accessToken;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
index f9ca9bf4cc..3c9cb31211 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.annotations;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -35,6 +36,7 @@ public final class IconFactory {
public static final String ICON_MARKERVIEW_ID = ICON_ID_PREFIX + "marker_view";
private Context context;
+ @SuppressLint("StaticFieldLeak")
private static IconFactory instance;
private Icon defaultMarker;
private Icon defaultMarkerView;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
index 9c8cda5544..91a235616a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -109,13 +109,11 @@ class HTTPRequest implements Callback {
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
- Timber.v(String.format("[HTTP] Request was successful (code = %d).", response.code()));
+ Timber.v("[HTTP] Request was successful (code = %s).", response.code());
} else {
// We don't want to call this unsuccessful because a 304 isn't really an error
String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
- Timber.d(String.format(
- "[HTTP] Request with response code = %d: %s",
- response.code(), message));
+ Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
}
byte[] body;
@@ -160,15 +158,12 @@ class HTTPRequest implements Callback {
String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
if (type == TEMPORARY_ERROR) {
- Timber.d(String.format(MapboxConstants.MAPBOX_LOCALE,
- "Request failed due to a temporary error: %s", errorMessage));
+ Timber.d("Request failed due to a temporary error: %s", errorMessage);
} else if (type == CONNECTION_ERROR) {
- Timber.i(String.format(MapboxConstants.MAPBOX_LOCALE,
- "Request failed due to a connection error: %s", errorMessage));
+ Timber.i("Request failed due to a connection error: %s", errorMessage);
} else {
// PERMANENT_ERROR
- Timber.w(String.format(MapboxConstants.MAPBOX_LOCALE,
- "Request failed due to a permanent error: %s", errorMessage));
+ Timber.w("Request failed due to a permanent error: %s", errorMessage);
}
mLock.lock();
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 f47fcdfd4a..3b8bc16bb3 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
@@ -272,7 +272,6 @@ public final class MapboxMap {
* Check whether tile pre-fetching is enabled or not.
*
* @return true if enabled
- *
* @see MapboxMap#setPrefetchesTiles(boolean)
*/
@UiThread
@@ -316,7 +315,7 @@ public final class MapboxMap {
// noinspection unchecked
return (T) nativeMapView.getLayer(layerId);
} catch (ClassCastException exception) {
- Timber.e(String.format("Layer: %s is a different type: %s", layerId, exception));
+ Timber.e(exception, "Layer: %s is a different type: ", layerId);
return null;
}
}
@@ -437,7 +436,7 @@ public final class MapboxMap {
// noinspection unchecked
return (T) nativeMapView.getSource(sourceId);
} catch (ClassCastException exception) {
- Timber.e(String.format("Source: %s is a different type: %s", sourceId, exception));
+ Timber.e(exception, "Source: %s is a different type: ", sourceId);
return null;
}
}
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 52596358e2..ddeb4b326e 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
@@ -17,7 +17,6 @@ import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
@@ -84,9 +83,10 @@ final class NativeMapView {
private boolean isDestroyedOn(String callingMethod) {
if (destroyed && !TextUtils.isEmpty(callingMethod)) {
- Timber.e(String.format(MapboxConstants.MAPBOX_LOCALE,
+ Timber.e(
"You're calling `%s` after the `MapView` was destroyed, were you invoking it after `onDestroy()`?",
- callingMethod));
+ callingMethod
+ );
}
return destroyed;
}
@@ -143,14 +143,14 @@ final class NativeMapView {
if (width > 65535) {
// we have seen edge cases where devices return incorrect values #6111
Timber.e("Device returned an out of range width size, "
- + "capping value at 65535 instead of " + width);
+ + "capping value at 65535 instead of %s", width);
width = 65535;
}
if (height > 65535) {
// we have seen edge cases where devices return incorrect values #6111
Timber.e("Device returned an out of range height size, "
- + "capping value at 65535 instead of " + height);
+ + "capping value at 65535 instead of %s", height);
height = 65535;
}
nativeResizeView(width, height);
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 d788b7772b..6f63c2eba8 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
@@ -346,7 +346,7 @@ final class Transform implements MapView.OnMapChangedListener {
void setMinZoom(double minZoom) {
if ((minZoom < MapboxConstants.MINIMUM_ZOOM) || (minZoom > MapboxConstants.MAXIMUM_ZOOM)) {
- Timber.e("Not setting minZoomPreference, value is in unsupported range: " + minZoom);
+ Timber.e("Not setting minZoomPreference, value is in unsupported range: %s", minZoom);
return;
}
mapView.setMinZoom(minZoom);
@@ -358,7 +358,7 @@ final class Transform implements MapView.OnMapChangedListener {
void setMaxZoom(double maxZoom) {
if ((maxZoom < MapboxConstants.MINIMUM_ZOOM) || (maxZoom > MapboxConstants.MAXIMUM_ZOOM)) {
- Timber.e("Not setting maxZoomPreference, value is in unsupported range: " + maxZoom);
+ Timber.e("Not setting maxZoomPreference, value is in unsupported range: %s", maxZoom);
return;
}
mapView.setMaxZoom(maxZoom);
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 017fdb353a..4e696fb56b 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
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.maps.widgets;
import android.animation.ValueAnimator;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Canvas;
@@ -775,6 +776,7 @@ public class MyLocationView extends View {
locationSource = new WeakReference<>(locationEngine);
}
+ @SuppressLint("MissingPermission")
@Override
public void onConnected() {
MyLocationView locationView = userLocationView.get();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
index a1bd98b780..817dcdb438 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.net;
+import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -21,6 +22,7 @@ import timber.log.Timber;
* Not public api.
*/
public class ConnectivityReceiver extends BroadcastReceiver {
+ @SuppressLint("StaticFieldLeak")
private static ConnectivityReceiver INSTANCE;
/**
@@ -82,7 +84,7 @@ public class ConnectivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean connected = isConnected(context);
- Timber.v("Connected: " + connected);
+ Timber.v("Connected: %s", connected);
// Loop over listeners
for (ConnectivityListener listener : listeners) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 1e6f44f094..130284e88d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.offline;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
@@ -40,6 +41,7 @@ public class OfflineManager {
private Handler handler;
// This object is implemented as a singleton
+ @SuppressLint("StaticFieldLeak")
private static OfflineManager instance;
// The application context
@@ -90,11 +92,11 @@ public class OfflineManager {
*/
private OfflineManager(Context context) {
this.context = context.getApplicationContext();
- this.fileSource = FileSource.getInstance(context);
+ this.fileSource = FileSource.getInstance(this.context);
initialize(fileSource);
// Delete any existing previous ambient cache database
- deleteAmbientDatabase(context);
+ deleteAmbientDatabase(this.context);
}
private void deleteAmbientDatabase(final Context context) {
@@ -107,10 +109,10 @@ public class OfflineManager {
File file = new File(path);
if (file.exists()) {
file.delete();
- Timber.d("Old ambient cache database deleted to save space: " + path);
+ Timber.d("Old ambient cache database deleted to save space: %s", path);
}
} catch (Exception exception) {
- Timber.e("Failed to delete old ambient cache database: ", exception);
+ Timber.e(exception, "Failed to delete old ambient cache database: ");
}
}
}).start();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
index eafef80e8d..a968cdf192 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
@@ -72,9 +72,9 @@ public class FileSource {
MapboxConstants.KEY_META_DATA_SET_STORAGE_EXTERNAL,
MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL);
} catch (PackageManager.NameNotFoundException exception) {
- Timber.e("Failed to read the package metadata: ", exception);
+ Timber.e(exception,"Failed to read the package metadata: ");
} catch (Exception exception) {
- Timber.e("Failed to read the storage key: ", exception);
+ Timber.e(exception, "Failed to read the storage key: ");
}
String cachePath = null;
@@ -83,7 +83,7 @@ public class FileSource {
// Try getting the external storage path
cachePath = context.getExternalFilesDir(null).getAbsolutePath();
} catch (NullPointerException exception) {
- Timber.e("Failed to obtain the external storage path: ", exception);
+ Timber.e(exception, "Failed to obtain the external storage path: ");
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java
index e1e40821b1..e7bb52ebb3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/functions/Function.java
@@ -279,7 +279,7 @@ public class Function {
// noinspection unchecked
return (S) stops;
} catch (ClassCastException exception) {
- Timber.e(String.format("Stops: %s is a different type: %s", stops.getClass(), exception));
+ Timber.e(exception, "Stops: %s is a different type: ", stops.getClass());
return null;
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index 3decd6ead1..d59eef7427 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -83,11 +83,13 @@
-
+
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/color/mapbox_material_bg_selector.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/color/mapbox_material_bg_selector.xml
deleted file mode 100644
index 4c733ed112..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/color/mapbox_material_bg_selector.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-nodpi/mapbox_mapview_preview.jpg b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-nodpi/mapbox_mapview_preview.jpg
new file mode 100644
index 0000000000..3a21fc08bc
Binary files /dev/null and b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-nodpi/mapbox_mapview_preview.jpg differ
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg
deleted file mode 100644
index 3a21fc08bc..0000000000
Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg and /dev/null differ
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_infowindow_icon_bg.9.png b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_infowindow_icon_bg.9.png
deleted file mode 100644
index 584b320299..0000000000
Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxxhdpi/mapbox_infowindow_icon_bg.9.png and /dev/null differ
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
index 763bb118e0..648946e8ce 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
@@ -9,5 +9,6 @@
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:textAllCaps="true"
+ android:textIsSelectable="true"
android:textAppearance="?android:attr/textAppearanceButton"
android:textColor="@color/mapbox_blue"/>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
index 26c974dc0d..027f3690d5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
@@ -23,6 +23,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
+ android:textIsSelectable="true"
android:maxEms="17"
android:textColor="@android:color/black"
android:textSize="18sp"
@@ -34,13 +35,13 @@
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
+ android:textIsSelectable="true"
android:lineSpacingExtra="1dp"
android:maxEms="17"
android:textColor="@color/mapbox_gray"
android:textSize="14sp"/>
+ android:id="@+id/image"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:contentDescription="@null"/>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
index 63ef42c2c3..68e70e948e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
@@ -3,5 +3,4 @@
#7D7F80#EEEEEE#1E8CAB
- @color/mapbox_blue
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
index 8edbd47c29..1c6a265587 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml
@@ -2,17 +2,8 @@
8dp8dp
- -2dp
- 1.5dp
- @dimen/mapbox_two_dp
- @dimen/mapbox_two_dp
- @dimen/mapbox_two_dp
- @dimen/mapbox_two_dp
- 2dp4dp8dp
- 10dp
- 16dp92dp18dp
--
cgit v1.2.1
From 11b8f2dcb23bc076a8e6f939de458d001f79eeeb Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 1 Aug 2017 08:54:16 +0200
Subject: [android] - move ZoomButtonController creation to view initalisation
(#9587)
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 9 ++++-----
.../mapboxsdk/maps/MapZoomButtonController.java | 23 ++++++++++++----------
2 files changed, 17 insertions(+), 15 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 848a898f94..766e2a051d 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
@@ -120,6 +120,7 @@ public class MapView extends FrameLayout {
myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
attrView = (ImageView) view.findViewById(R.id.attributionView);
logoView = (ImageView) view.findViewById(R.id.logoView);
+ mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
@@ -180,7 +181,7 @@ public class MapView extends FrameLayout {
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
- mapZoomButtonController = new MapZoomButtonController(this, uiSettings, zoomListener);
+ mapZoomButtonController.bind(uiSettings, zoomListener);
// inject widgets with MapboxMap
compassView.setMapboxMap(mapboxMap);
@@ -557,9 +558,7 @@ public class MapView extends FrameLayout {
@CallSuper
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- if (mapZoomButtonController != null) {
- mapZoomButtonController.setVisible(false);
- }
+ mapZoomButtonController.setVisible(false);
}
// Called when view is hidden and shown
@@ -569,7 +568,7 @@ public class MapView extends FrameLayout {
return;
}
- if (mapZoomButtonController != null && nativeMapView != null) {
+ if (nativeMapView != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapZoomButtonController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapZoomButtonController.java
index 16513904c5..018c8eb5bb 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapZoomButtonController.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapZoomButtonController.java
@@ -1,7 +1,6 @@
package com.mapbox.mapboxsdk.maps;
import android.support.annotation.NonNull;
-import android.view.View;
import android.widget.ZoomButtonsController;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
@@ -12,21 +11,25 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
* Allows single touch only devices to zoom in and out.
*
@@ -51,8 +53,14 @@ public final class Mapbox {
INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext));
LocationEngine locationEngine = new LocationSource(appContext);
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
- MapboxTelemetry.getInstance().initialize(
- appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
+
+ try {
+ MapboxTelemetry.getInstance().initialize(
+ appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
+ } catch (Exception exception) {
+ Timber.e(exception, "Unable to instantiate Mapbox telemetry");
+ }
+
ConnectivityReceiver.instance(appContext);
}
return INSTANCE;
--
cgit v1.2.1
From 104fd98a813b611b47bbf5498d7f637ab56096ec Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 1 Aug 2017 16:33:52 +0200
Subject: [android] - fix OnCameraMoveStartedListener typo (#9664)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.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/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 3b8bc16bb3..cf949dbcdc 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
@@ -1740,7 +1740,7 @@ public final class MapboxMap {
* @param listener the listener to notify
*/
@UiThread
- public void setOnCameraMoveStartedistener(@Nullable OnCameraMoveStartedListener listener) {
+ public void setOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
cameraChangeDispatcher.setOnCameraMoveStartedListener(listener);
}
--
cgit v1.2.1
From 21bbf5a9e0e82e60250f5b05dd5430052a7b2469 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 1 Aug 2017 16:33:52 +0200
Subject: [android] - fix OnCameraMoveStartedListener typo (#9664)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.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/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index c8725d8d8d..e074d938fd 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
@@ -1708,7 +1708,7 @@ public final class MapboxMap {
* @param listener the listener to notify
*/
@UiThread
- public void setOnCameraMoveStartedistener(@Nullable OnCameraMoveStartedListener listener) {
+ public void setOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
cameraChangeDispatcher.setOnCameraMoveStartedListener(listener);
}
--
cgit v1.2.1
From e4a61426bf1893637617159ebea5b61b37114d12 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 1 Aug 2017 15:25:24 +0200
Subject: [android] - try/catch initalisation of Telemetry (#9658)
---
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
(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 6722000be7..eadc3fdcf5 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
@@ -15,6 +15,8 @@ import com.mapbox.services.android.telemetry.MapboxTelemetry;
import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
+import timber.log.Timber;
+
/**
* The entry point to initialize the Mapbox Android SDK.
*
@@ -48,8 +50,14 @@ public final class Mapbox {
INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext));
LocationEngine locationEngine = new LocationSource(appContext);
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
- MapboxTelemetry.getInstance().initialize(
- appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
+
+ try {
+ MapboxTelemetry.getInstance().initialize(
+ appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
+ } catch (Exception exception) {
+ Timber.e(exception, "Unable to instantiate Mapbox telemetry");
+ }
+
ConnectivityReceiver.instance(appContext);
}
return INSTANCE;
--
cgit v1.2.1
From f5b48a5d06be88bfb373c8dab4d9576d122c8937 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 1 Aug 2017 15:25:07 +0200
Subject: [android] - remove preview image integration (#9657)
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +-
.../drawable-v21/mapbox_default_bg_selector.xml | 9 ----
.../res/drawable-xxhdpi/mapbox_mapview_preview.jpg | Bin 166053 -> 0 bytes
.../res/drawable/mapbox_default_bg_selector.xml | 6 ---
.../src/main/res/layout/mapbox_mapview_preview.xml | 52 ---------------------
.../src/main/res/values/colors.xml | 1 -
6 files changed, 1 insertion(+), 70 deletions(-)
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
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 c51d9327d2..32c4952aa1 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
@@ -95,8 +95,7 @@ public class MapView extends FrameLayout {
private void initialise(@NonNull final Context context, @NonNull final MapboxMapOptions options) {
if (isInEditMode()) {
- // in IDE, show preview map
- LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_preview, this);
+ // in IDE layout editor, just return
return;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml
deleted file mode 100644
index 2fd6815c23..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-v21/mapbox_default_bg_selector.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg
deleted file mode 100644
index 3a21fc08bc..0000000000
Binary files a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapbox_mapview_preview.jpg and /dev/null differ
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml
deleted file mode 100644
index 3efe48615b..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/drawable/mapbox_default_bg_selector.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
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
deleted file mode 100644
index 1c1ab0e71b..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_preview.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
index 63ef42c2c3..69ab7568bb 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/colors.xml
@@ -1,7 +1,6 @@
#7D7F80
- #EEEEEE#1E8CAB@color/mapbox_blue
--
cgit v1.2.1
From ebab0c1a1bb6e8e76cefff72b262e33f9ac0555c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 2 Aug 2017 12:29:10 +0200
Subject: [android] - release android v5.1.2, update config
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
.../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index a8646e3270..af1d04ab97 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.1.2-SNAPSHOT
+VERSION_NAME=5.1.3-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
index a02b5d63ac..3cfc7d5fdc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
+++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
@@ -1,3 +1,3 @@
fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk
-fabric-version=5.1.1
+fabric-version=5.1.2
fabric-build-type=binary
--
cgit v1.2.1
From 7eba031ae25a8e9256e70c3fd9271ce31aa836a5 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 7 Aug 2017 08:14:32 +0200
Subject: [android] - annotate MapboxMap with UiThread
---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 108 +--------------------
1 file changed, 1 insertion(+), 107 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 cf949dbcdc..d99b5646dd 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
@@ -59,6 +59,7 @@ import timber.log.Timber;
* Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.
*
*/
+@UiThread
public final class MapboxMap {
private final NativeMapView nativeMapView;
@@ -210,7 +211,6 @@ public final class MapboxMap {
*
* @return Duration in milliseconds
*/
- @UiThread
public long getTransitionDuration() {
return nativeMapView.getTransitionDuration();
}
@@ -220,7 +220,6 @@ public final class MapboxMap {
*
* @param durationMs Duration in milliseconds
*/
- @UiThread
public void setTransitionDuration(long durationMs) {
nativeMapView.setTransitionDuration(durationMs);
}
@@ -233,7 +232,6 @@ public final class MapboxMap {
*
* @return Delay in milliseconds
*/
- @UiThread
public long getTransitionDelay() {
return nativeMapView.getTransitionDelay();
}
@@ -243,7 +241,6 @@ public final class MapboxMap {
*
* @param delayMs Delay in milliseconds
*/
- @UiThread
public void setTransitionDelay(long delayMs) {
nativeMapView.setTransitionDelay(delayMs);
}
@@ -263,7 +260,6 @@ public final class MapboxMap {
*
* @param enable true to enable
*/
- @UiThread
public void setPrefetchesTiles(boolean enable) {
nativeMapView.setPrefetchesTiles(enable);
}
@@ -274,7 +270,6 @@ public final class MapboxMap {
* @return true if enabled
* @see MapboxMap#setPrefetchesTiles(boolean)
*/
- @UiThread
public boolean getPrefetchesTiles() {
return nativeMapView.getPrefetchesTiles();
}
@@ -284,7 +279,6 @@ public final class MapboxMap {
*
* @return all the layers in the current style
*/
- @UiThread
public List getLayers() {
return nativeMapView.getLayers();
}
@@ -296,7 +290,6 @@ public final class MapboxMap {
* @return the layer, if present in the style
*/
@Nullable
- @UiThread
public Layer getLayer(@NonNull String layerId) {
return nativeMapView.getLayer(layerId);
}
@@ -309,7 +302,6 @@ public final class MapboxMap {
* @return the casted Layer, null if another type
*/
@Nullable
- @UiThread
public T getLayerAs(@NonNull String layerId) {
try {
// noinspection unchecked
@@ -325,7 +317,6 @@ public final class MapboxMap {
*
* @param layer the layer to add
*/
- @UiThread
public void addLayer(@NonNull Layer layer) {
nativeMapView.addLayer(layer);
}
@@ -336,7 +327,6 @@ public final class MapboxMap {
* @param layer the layer to add
* @param below the layer id to add this layer before
*/
- @UiThread
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
nativeMapView.addLayerBelow(layer, below);
}
@@ -347,7 +337,6 @@ public final class MapboxMap {
* @param layer the layer to add
* @param above the layer id to add this layer above
*/
- @UiThread
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
nativeMapView.addLayerAbove(layer, above);
}
@@ -359,7 +348,6 @@ public final class MapboxMap {
* @param layer the layer to add
* @param index the index to insert the layer at
*/
- @UiThread
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
nativeMapView.addLayerAt(layer, index);
}
@@ -370,7 +358,6 @@ public final class MapboxMap {
* @param layerId the layer to remove
* @return the removed layer or null if not found
*/
- @UiThread
@Nullable
public Layer removeLayer(@NonNull String layerId) {
return nativeMapView.removeLayer(layerId);
@@ -382,7 +369,6 @@ public final class MapboxMap {
* @param layer the layer to remove
* @return the layer
*/
- @UiThread
@Nullable
public Layer removeLayer(@NonNull Layer layer) {
return nativeMapView.removeLayer(layer);
@@ -394,7 +380,6 @@ public final class MapboxMap {
* @param index the layer index
* @return the removed layer or null if not found
*/
- @UiThread
@Nullable
public Layer removeLayerAt(@IntRange(from = 0) int index) {
return nativeMapView.removeLayerAt(index);
@@ -405,7 +390,6 @@ public final class MapboxMap {
*
* @return all the sources in the current style
*/
- @UiThread
public List getSources() {
return nativeMapView.getSources();
}
@@ -417,7 +401,6 @@ public final class MapboxMap {
* @return the source if present in the current style
*/
@Nullable
- @UiThread
public Source getSource(@NonNull String sourceId) {
return nativeMapView.getSource(sourceId);
}
@@ -430,7 +413,6 @@ public final class MapboxMap {
* @return the casted Source, null if another type
*/
@Nullable
- @UiThread
public T getSourceAs(@NonNull String sourceId) {
try {
// noinspection unchecked
@@ -446,7 +428,6 @@ public final class MapboxMap {
*
* @param source the source to add
*/
- @UiThread
public void addSource(@NonNull Source source) {
nativeMapView.addSource(source);
}
@@ -457,7 +438,6 @@ public final class MapboxMap {
* @param sourceId the source to remove
* @return the source handle or null if the source was not present
*/
- @UiThread
@Nullable
public Source removeSource(@NonNull String sourceId) {
return nativeMapView.removeSource(sourceId);
@@ -469,7 +449,6 @@ public final class MapboxMap {
* @param source the source to remove
* @return the source
*/
- @UiThread
@Nullable
public Source removeSource(@NonNull Source source) {
return nativeMapView.removeSource(source);
@@ -481,7 +460,6 @@ public final class MapboxMap {
* @param name the name of the image
* @param image the pre-multiplied Bitmap
*/
- @UiThread
public void addImage(@NonNull String name, @NonNull Bitmap image) {
nativeMapView.addImage(name, image);
}
@@ -491,7 +469,6 @@ public final class MapboxMap {
*
* @param name the name of the image to remove
*/
- @UiThread
public void removeImage(String name) {
nativeMapView.removeImage(name);
}
@@ -507,7 +484,6 @@ public final class MapboxMap {
*
* @param minZoom The new minimum zoom level.
*/
- @UiThread
public void setMinZoomPreference(
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double minZoom) {
transform.setMinZoom(minZoom);
@@ -520,7 +496,6 @@ public final class MapboxMap {
*
* @return The minimum zoom level.
*/
- @UiThread
public double getMinZoomLevel() {
return transform.getMinZoom();
}
@@ -536,7 +511,6 @@ public final class MapboxMap {
*
* @param maxZoom The new maximum zoom level.
*/
- @UiThread
public void setMaxZoomPreference(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
transform.setMaxZoom(maxZoom);
@@ -549,7 +523,6 @@ public final class MapboxMap {
*
* @return The maximum zoom level.
*/
- @UiThread
public double getMaxZoomLevel() {
return transform.getMaxZoom();
}
@@ -664,7 +637,6 @@ public final class MapboxMap {
*
* @param update The change that should be applied to the camera.
*/
- @UiThread
public final void moveCamera(CameraUpdate update) {
moveCamera(update, null);
}
@@ -677,7 +649,6 @@ public final class MapboxMap {
* @param update The change that should be applied to the camera
* @param callback the callback to be invoked when an animation finishes or is canceled
*/
- @UiThread
public final void moveCamera(final CameraUpdate update, final MapboxMap.CancelableCallback callback) {
new Handler().post(new Runnable() {
@Override
@@ -698,7 +669,6 @@ public final class MapboxMap {
* @param update The change that should be applied to the camera.
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void easeCamera(CameraUpdate update) {
easeCamera(update, MapboxConstants.ANIMATION_DURATION);
}
@@ -713,7 +683,6 @@ public final class MapboxMap {
* positive, otherwise an IllegalArgumentException will be thrown.
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void easeCamera(CameraUpdate update, int durationMs) {
easeCamera(update, durationMs, null);
}
@@ -737,7 +706,6 @@ public final class MapboxMap {
* Do not update or ease the camera from within onCancel().
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void easeCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) {
easeCamera(update, durationMs, true, callback);
}
@@ -756,7 +724,6 @@ public final class MapboxMap {
* positive, otherwise an IllegalArgumentException will be thrown.
* @param easingInterpolator True for easing interpolator, false for linear.
*/
- @UiThread
public final void easeCamera(CameraUpdate update, int durationMs, boolean easingInterpolator) {
easeCamera(update, durationMs, easingInterpolator, null);
}
@@ -782,7 +749,6 @@ public final class MapboxMap {
* by a later camera movement or a user gesture, onCancel() will be called.
* Do not update or ease the camera from within onCancel().
*/
- @UiThread
public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
final MapboxMap.CancelableCallback callback) {
easeCamera(update, durationMs, easingInterpolator, callback, false);
@@ -810,7 +776,6 @@ public final class MapboxMap {
* Do not update or ease the camera from within onCancel().
* @param isDismissable true will allow animated camera changes dismiss a tracking mode.
*/
- @UiThread
public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
final MapboxMap.CancelableCallback callback, final boolean isDismissable) {
new Handler().post(new Runnable() {
@@ -830,7 +795,6 @@ public final class MapboxMap {
* @param update The change that should be applied to the camera.
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void animateCamera(CameraUpdate update) {
animateCamera(update, MapboxConstants.ANIMATION_DURATION, null);
}
@@ -847,7 +811,6 @@ public final class MapboxMap {
* called. Do not update or animate the camera from within onCancel().
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void animateCamera(CameraUpdate update, MapboxMap.CancelableCallback callback) {
animateCamera(update, MapboxConstants.ANIMATION_DURATION, callback);
}
@@ -863,7 +826,6 @@ public final class MapboxMap {
* positive, otherwise an IllegalArgumentException will be thrown.
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void animateCamera(CameraUpdate update, int durationMs) {
animateCamera(update, durationMs, null);
}
@@ -886,7 +848,6 @@ public final class MapboxMap {
* isn't required, leave it as null.
* @see com.mapbox.mapboxsdk.camera.CameraUpdateFactory for a set of updates.
*/
- @UiThread
public final void animateCamera(final CameraUpdate update, final int durationMs,
final MapboxMap.CancelableCallback callback) {
new Handler().post(new Runnable() {
@@ -957,7 +918,6 @@ public final class MapboxMap {
*
* @return If true, map debug information is currently shown.
*/
- @UiThread
public boolean isDebugActive() {
return nativeMapView.getDebug();
}
@@ -970,7 +930,6 @@ public final class MapboxMap {
*
* @param debugActive If true, map debug information is shown.
*/
- @UiThread
public void setDebugActive(boolean debugActive) {
nativeMapView.setDebug(debugActive);
}
@@ -984,7 +943,6 @@ public final class MapboxMap {
*
* @see #isDebugActive()
*/
- @UiThread
public void cycleDebugOptions() {
nativeMapView.cycleDebugOptions();
}
@@ -1034,7 +992,6 @@ public final class MapboxMap {
* @param url The URL of the map style
* @see Style
*/
- @UiThread
public void setStyleUrl(@NonNull String url) {
setStyleUrl(url, null);
}
@@ -1067,7 +1024,6 @@ public final class MapboxMap {
* @param callback The callback that is invoked when the style has loaded.
* @see Style
*/
- @UiThread
public void setStyleUrl(@NonNull final String url, @Nullable final OnStyleLoadedListener callback) {
if (callback != null) {
nativeMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
@@ -1099,7 +1055,6 @@ public final class MapboxMap {
* @param style The bundled style.
* @see Style
*/
- @UiThread
public void setStyle(@Style.StyleUrl String style) {
setStyleUrl(style);
}
@@ -1116,7 +1071,6 @@ public final class MapboxMap {
* @param callback The callback to be invoked when the style has finished loading
* @see Style
*/
- @UiThread
public void setStyle(@Style.StyleUrl String style, @Nullable OnStyleLoadedListener callback) {
setStyleUrl(style, callback);
}
@@ -1138,7 +1092,6 @@ public final class MapboxMap {
*
* @return The URL of the map style
*/
- @UiThread
@Nullable
public String getStyleUrl() {
return nativeMapView.getStyleUrl();
@@ -1158,7 +1111,6 @@ public final class MapboxMap {
* @param markerOptions A marker options object that defines how to render the marker
* @return The {@code Marker} that was added to the map
*/
- @UiThread
@NonNull
public Marker addMarker(@NonNull MarkerOptions markerOptions) {
return annotationManager.addMarker(markerOptions, this);
@@ -1174,7 +1126,6 @@ public final class MapboxMap {
* @param markerOptions A marker options object that defines how to render the marker
* @return The {@code Marker} that was added to the map
*/
- @UiThread
@NonNull
public Marker addMarker(@NonNull BaseMarkerOptions markerOptions) {
return annotationManager.addMarker(markerOptions, this);
@@ -1190,7 +1141,6 @@ public final class MapboxMap {
* @param markerOptions A marker options object that defines how to render the marker
* @return The {@code Marker} that was added to the map
*/
- @UiThread
@NonNull
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
return annotationManager.addMarker(markerOptions, this, null);
@@ -1207,7 +1157,6 @@ public final class MapboxMap {
* @param onMarkerViewAddedListener Callback invoked when the View has been added to the map
* @return The {@code Marker} that was added to the map
*/
- @UiThread
@NonNull
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions,
final MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) {
@@ -1224,7 +1173,6 @@ public final class MapboxMap {
* @param markerViewOptions A list of markerView options objects that defines how to render the markers
* @return A list of the {@code MarkerView}s that were added to the map
*/
- @UiThread
@NonNull
public List addMarkerViews(@NonNull List extends
BaseMarkerViewOptions> markerViewOptions) {
@@ -1237,7 +1185,6 @@ public final class MapboxMap {
* @param rect the rectangular area on the map to query for markerViews
* @return A list of the markerViews that were found in the rectangle
*/
- @UiThread
@NonNull
public List getMarkerViewsInRect(@NonNull RectF rect) {
return annotationManager.getMarkerViewsInRect(rect);
@@ -1253,7 +1200,6 @@ public final class MapboxMap {
* @param markerOptionsList A list of marker options objects that defines how to render the markers
* @return A list of the {@code Marker}s that were added to the map
*/
- @UiThread
@NonNull
public List addMarkers(@NonNull List extends
BaseMarkerOptions> markerOptionsList) {
@@ -1267,7 +1213,6 @@ public final class MapboxMap {
*
* @param updatedMarker An updated marker object
*/
- @UiThread
public void updateMarker(@NonNull Marker updatedMarker) {
annotationManager.updateMarker(updatedMarker, this);
}
@@ -1278,7 +1223,6 @@ public final class MapboxMap {
* @param polylineOptions A polyline options object that defines how to render the polyline
* @return The {@code Polyine} that was added to the map
*/
- @UiThread
@NonNull
public Polyline addPolyline(@NonNull PolylineOptions polylineOptions) {
return annotationManager.addPolyline(polylineOptions, this);
@@ -1290,7 +1234,6 @@ public final class MapboxMap {
* @param polylineOptionsList A list of polyline options objects that defines how to render the polylines.
* @return A list of the {@code Polyline}s that were added to the map.
*/
- @UiThread
@NonNull
public List addPolylines(@NonNull List polylineOptionsList) {
return annotationManager.addPolylines(polylineOptionsList, this);
@@ -1301,7 +1244,6 @@ public final class MapboxMap {
*
* @param polyline An updated polyline object.
*/
- @UiThread
public void updatePolyline(Polyline polyline) {
annotationManager.updatePolyline(polyline);
}
@@ -1312,7 +1254,6 @@ public final class MapboxMap {
* @param polygonOptions A polygon options object that defines how to render the polygon.
* @return The {@code Polygon} that was added to the map.
*/
- @UiThread
@NonNull
public Polygon addPolygon(@NonNull PolygonOptions polygonOptions) {
return annotationManager.addPolygon(polygonOptions, this);
@@ -1324,7 +1265,6 @@ public final class MapboxMap {
* @param polygonOptionsList A list of polygon options objects that defines how to render the polygons
* @return A list of the {@code Polygon}s that were added to the map
*/
- @UiThread
@NonNull
public List addPolygons(@NonNull List polygonOptionsList) {
return annotationManager.addPolygons(polygonOptionsList, this);
@@ -1335,7 +1275,6 @@ public final class MapboxMap {
*
* @param polygon An updated polygon object
*/
- @UiThread
public void updatePolygon(Polygon polygon) {
annotationManager.updatePolygon(polygon);
}
@@ -1348,7 +1287,6 @@ public final class MapboxMap {
*
* @param marker Marker to remove
*/
- @UiThread
public void removeMarker(@NonNull Marker marker) {
annotationManager.removeAnnotation(marker);
}
@@ -1361,7 +1299,6 @@ public final class MapboxMap {
*
* @param polyline Polyline to remove
*/
- @UiThread
public void removePolyline(@NonNull Polyline polyline) {
annotationManager.removeAnnotation(polyline);
}
@@ -1374,7 +1311,6 @@ public final class MapboxMap {
*
* @param polygon Polygon to remove
*/
- @UiThread
public void removePolygon(@NonNull Polygon polygon) {
annotationManager.removeAnnotation(polygon);
}
@@ -1384,7 +1320,6 @@ public final class MapboxMap {
*
* @param annotation The annotation object to remove.
*/
- @UiThread
public void removeAnnotation(@NonNull Annotation annotation) {
annotationManager.removeAnnotation(annotation);
}
@@ -1394,7 +1329,6 @@ public final class MapboxMap {
*
* @param id The identifier associated to the annotation to be removed
*/
- @UiThread
public void removeAnnotation(long id) {
annotationManager.removeAnnotation(id);
}
@@ -1404,7 +1338,6 @@ public final class MapboxMap {
*
* @param annotationList A list of annotation objects to remove.
*/
- @UiThread
public void removeAnnotations(@NonNull List extends Annotation> annotationList) {
annotationManager.removeAnnotations(annotationList);
}
@@ -1412,7 +1345,6 @@ public final class MapboxMap {
/**
* Removes all annotations from the map.
*/
- @UiThread
public void removeAnnotations() {
annotationManager.removeAnnotations();
}
@@ -1420,7 +1352,6 @@ public final class MapboxMap {
/**
* Removes all markers, polylines, polygons, overlays, etc from the map.
*/
- @UiThread
public void clear() {
annotationManager.removeAnnotations();
}
@@ -1486,7 +1417,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on a marker.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMarkerClickListener(@Nullable OnMarkerClickListener listener) {
annotationManager.setOnMarkerClickListener(listener);
}
@@ -1497,7 +1427,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on a polygon.
* To unset the callback, use null.
*/
- @UiThread
public void setOnPolygonClickListener(@Nullable OnPolygonClickListener listener) {
annotationManager.setOnPolygonClickListener(listener);
}
@@ -1508,7 +1437,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on a polyline.
* To unset the callback, use null.
*/
- @UiThread
public void setOnPolylineClickListener(@Nullable OnPolylineClickListener listener) {
annotationManager.setOnPolylineClickListener(listener);
}
@@ -1523,7 +1451,6 @@ public final class MapboxMap {
*
* @param marker The marker to select.
*/
- @UiThread
public void selectMarker(@NonNull Marker marker) {
if (marker == null) {
Timber.w("marker was null, so just returning");
@@ -1535,7 +1462,6 @@ public final class MapboxMap {
/**
* Deselects any currently selected marker. All markers will have it's info window closed.
*/
- @UiThread
public void deselectMarkers() {
annotationManager.deselectMarkers();
}
@@ -1545,7 +1471,6 @@ public final class MapboxMap {
*
* @param marker the marker to deselect
*/
- @UiThread
public void deselectMarker(@NonNull Marker marker) {
annotationManager.deselectMarker(marker);
}
@@ -1555,7 +1480,6 @@ public final class MapboxMap {
*
* @return The currently selected marker.
*/
- @UiThread
public List getSelectedMarkers() {
return annotationManager.getSelectedMarkers();
}
@@ -1583,7 +1507,6 @@ public final class MapboxMap {
* @param infoWindowAdapter The callback to be invoked when an info window will be shown.
* To unset the callback, use null.
*/
- @UiThread
public void setInfoWindowAdapter(@Nullable InfoWindowAdapter infoWindowAdapter) {
annotationManager.getInfoWindowManager().setInfoWindowAdapter(infoWindowAdapter);
}
@@ -1593,7 +1516,6 @@ public final class MapboxMap {
*
* @return The callback to be invoked when an info window will be shown.
*/
- @UiThread
@Nullable
public InfoWindowAdapter getInfoWindowAdapter() {
return annotationManager.getInfoWindowManager().getInfoWindowAdapter();
@@ -1604,7 +1526,6 @@ public final class MapboxMap {
*
* @param allow If true, map allows concurrent multiple infowindows to be shown.
*/
- @UiThread
public void setAllowConcurrentMultipleOpenInfoWindows(boolean allow) {
annotationManager.getInfoWindowManager().setAllowConcurrentMultipleOpenInfoWindows(allow);
}
@@ -1614,7 +1535,6 @@ public final class MapboxMap {
*
* @return If true, map allows concurrent multiple infowindows to be shown.
*/
- @UiThread
public boolean isAllowConcurrentMultipleOpenInfoWindows() {
return annotationManager.getInfoWindowManager().isAllowConcurrentMultipleOpenInfoWindows();
}
@@ -1708,7 +1628,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked on every camera change position.
* To unset the callback, use null.
*/
- @UiThread
@Deprecated
public void setOnCameraChangeListener(@Nullable OnCameraChangeListener listener) {
transform.setOnCameraChangeListener(listener);
@@ -1719,7 +1638,6 @@ public final class MapboxMap {
*
* @param listener the listener to notify
*/
- @UiThread
public void setOnCameraIdleListener(@Nullable OnCameraIdleListener listener) {
cameraChangeDispatcher.setOnCameraIdleListener(listener);
}
@@ -1729,7 +1647,6 @@ public final class MapboxMap {
*
* @param listener the listener to notify
*/
- @UiThread
public void setOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) {
cameraChangeDispatcher.setOnCameraMoveCanceledListener(listener);
}
@@ -1739,7 +1656,6 @@ public final class MapboxMap {
*
* @param listener the listener to notify
*/
- @UiThread
public void setOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
cameraChangeDispatcher.setOnCameraMoveStartedListener(listener);
}
@@ -1749,7 +1665,6 @@ public final class MapboxMap {
*
* @param listener the listener to notify
*/
- @UiThread
public void setOnCameraMoveListener(@Nullable OnCameraMoveListener listener) {
cameraChangeDispatcher.setOnCameraMoveListener(listener);
}
@@ -1760,7 +1675,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked on every frame rendered to the map view.
* To unset the callback, use null.
*/
- @UiThread
public void setOnFpsChangedListener(@Nullable OnFpsChangedListener listener) {
onFpsChangedListener = listener;
}
@@ -1776,7 +1690,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the map is scrolled.
* To unset the callback, use null.
*/
- @UiThread
public void setOnScrollListener(@Nullable OnScrollListener listener) {
onRegisterTouchListener.onRegisterScrollListener(listener);
}
@@ -1787,7 +1700,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the map is flinged.
* To unset the callback, use null.
*/
- @UiThread
public void setOnFlingListener(@Nullable OnFlingListener listener) {
onRegisterTouchListener.onRegisterFlingListener(listener);
}
@@ -1798,7 +1710,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on the map view.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
onRegisterTouchListener.onRegisterMapClickListener(listener);
}
@@ -1809,7 +1720,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user long clicks on the map view.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
onRegisterTouchListener.onRegisterMapLongClickListener(listener);
}
@@ -1820,7 +1730,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on an info window.
* To unset the callback, use null.
*/
- @UiThread
public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener) {
annotationManager.getInfoWindowManager().setOnInfoWindowClickListener(listener);
}
@@ -1830,7 +1739,6 @@ public final class MapboxMap {
*
* @return Current active InfoWindow Click Listener
*/
- @UiThread
public OnInfoWindowClickListener getOnInfoWindowClickListener() {
return annotationManager.getInfoWindowManager().getOnInfoWindowClickListener();
}
@@ -1841,7 +1749,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when a marker's info window is long pressed. To unset the callback,
* use null.
*/
- @UiThread
public void setOnInfoWindowLongClickListener(@Nullable OnInfoWindowLongClickListener
listener) {
annotationManager.getInfoWindowManager().setOnInfoWindowLongClickListener(listener);
@@ -1870,7 +1777,6 @@ public final class MapboxMap {
*
* @return Current active InfoWindow Close Listener
*/
- @UiThread
public OnInfoWindowCloseListener getOnInfoWindowCloseListener() {
return annotationManager.getInfoWindowManager().getOnInfoWindowCloseListener();
}
@@ -1884,7 +1790,6 @@ public final class MapboxMap {
*
* @return True if the my-location layer is enabled, false otherwise.
*/
- @UiThread
public boolean isMyLocationEnabled() {
return trackingSettings.isMyLocationEnabled();
}
@@ -1900,7 +1805,6 @@ public final class MapboxMap {
*
* @param enabled True to enable; false to disable.
*/
- @UiThread
public void setMyLocationEnabled(boolean enabled) {
trackingSettings.setMyLocationEnabled(enabled);
}
@@ -1910,7 +1814,6 @@ public final class MapboxMap {
*
* @return The currently displayed user location.
*/
- @UiThread
@Nullable
public Location getMyLocation() {
return trackingSettings.getMyLocation();
@@ -1923,7 +1826,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on a marker.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener
listener) {
trackingSettings.setOnMyLocationChangeListener(listener);
@@ -1934,7 +1836,6 @@ public final class MapboxMap {
*
* @param locationSource A {@link LocationEngine} location source to use in the my-location layer.
*/
- @UiThread
public void setLocationSource(@Nullable LocationEngine locationSource) {
trackingSettings.setLocationSource(locationSource);
}
@@ -1945,7 +1846,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the location tracking mode changes.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMyLocationTrackingModeChangeListener(
@Nullable MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
trackingSettings.setOnMyLocationTrackingModeChangeListener(listener);
@@ -1957,7 +1857,6 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the bearing tracking mode changes.
* To unset the callback, use null.
*/
- @UiThread
public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) {
trackingSettings.setOnMyBearingTrackingModeChangeListener(listener);
}
@@ -1971,7 +1870,6 @@ public final class MapboxMap {
*
* @param callback Callback method invoked when the snapshot is taken.
*/
- @UiThread
public void snapshot(@NonNull SnapshotReadyCallback callback) {
nativeMapView.addSnapshotCallback(callback);
}
@@ -1983,7 +1881,6 @@ public final class MapboxMap {
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
- @UiThread
@NonNull
public List queryRenderedFeatures(@NonNull PointF coordinates, @Nullable String...
layerIds) {
@@ -1998,7 +1895,6 @@ public final class MapboxMap {
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
- @UiThread
@NonNull
public List queryRenderedFeatures(@NonNull PointF coordinates,
@Nullable Filter.Statement filter,
@@ -2013,7 +1909,6 @@ public final class MapboxMap {
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
- @UiThread
@NonNull
public List queryRenderedFeatures(@NonNull RectF coordinates,
@Nullable String... layerIds) {
@@ -2028,7 +1923,6 @@ public final class MapboxMap {
* @param layerIds optionally - only query these layers
* @return the list of feature
*/
- @UiThread
@NonNull
public List queryRenderedFeatures(@NonNull RectF coordinates,
@Nullable Filter.Statement filter,
--
cgit v1.2.1
From 7f3523a9df9a15aaaf6d69de10476249889467c3 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Mon, 7 Aug 2017 16:24:29 +0200
Subject: [android] make text not selectable to fix infowindow issues caused
because selectable text consumes the click event (#9717)
---
.../src/main/res/layout/mapbox_attribution_list_item.xml | 2 +-
.../src/main/res/layout/mapbox_infowindow_content.xml | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
index 648946e8ce..f275860d59 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_attribution_list_item.xml
@@ -9,6 +9,6 @@
android:paddingLeft="24dp"
android:paddingRight="24dp"
android:textAllCaps="true"
- android:textIsSelectable="true"
+ android:textIsSelectable="false"
android:textAppearance="?android:attr/textAppearanceButton"
android:textColor="@color/mapbox_blue"/>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
index 027f3690d5..3a35396257 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/layout/mapbox_infowindow_content.xml
@@ -23,7 +23,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
- android:textIsSelectable="true"
+ android:textIsSelectable="false"
android:maxEms="17"
android:textColor="@android:color/black"
android:textSize="18sp"
@@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
- android:textIsSelectable="true"
+ android:textIsSelectable="false"
android:lineSpacingExtra="1dp"
android:maxEms="17"
android:textColor="@color/mapbox_gray"
--
cgit v1.2.1
From cf0dc1c9e796e43565bfa953d734481f3d18d059 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Wed, 9 Aug 2017 15:39:19 +0300
Subject: [android] Allow overriding abi from IDE
- This allows to build a different architecture then the default for a device, for example armeabi-v7a instead of arm64-v8a (which allows for better stack traces usually)
- Set in compiler > command-line options: -Pmapbox.abis=...
---
platform/android/MapboxGLAndroidSDK/build.gradle | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 5e7025c4c8..025097e756 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -41,11 +41,14 @@ android {
// to invoke the Java tests. When we explicitly specify an ABI of 'none', no native dependencies are
// added. When another ABI is specified explicitly, we're just going to build that ABI. In all other
// cases, all ABIs are built.
- // When invoking from the command line, set `-Pmapbox.abis=...` to only build the desired architectures.
+ //
+ // When invoking from the command line or to override the device default, set `-Pmapbox.abis=...` to
+ // only build the desired architectures.
+ //
// When building from Android Studio, gradle.properties sets `android.buildOnlyTargetAbi=true` so that
// only the architecture for the device you're running on gets built.
def abi = 'all'
- if (!project.hasProperty('android.injected.invoked.from.ide')) {
+ if (!project.hasProperty('android.injected.invoked.from.ide') || project.hasProperty("mapbox.abis")) {
// Errors when the user invokes Gradle from the command line and didn't set mapbox.abis
abi = project.getProperty("mapbox.abis")
}
--
cgit v1.2.1
From 1300e89c0b431951f27dc14fcdf3c57ea15735bb Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 7 Aug 2017 10:11:13 +0200
Subject: [android] - expose setStyleJson and getStyleJson
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 2 +-
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 23 +++++++++++++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 5745717324..cfe042d1f9 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
@@ -581,7 +581,7 @@ public class MapView extends FrameLayout {
try {
onMapChangedListener.onMapChanged(rawChange);
} catch (RuntimeException err) {
- Timber.e("Exception (%s) in MapView.OnMapChangedListener: %s", err.getClass(), err.getMessage());
+ Timber.e(err, "Exception in MapView.OnMapChangedListener");
}
}
}
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 d99b5646dd..cbb1d47b14 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
@@ -1088,7 +1088,7 @@ public final class MapboxMap {
}
/**
- * Returns the map style currently displayed in the map view.
+ * Returns the map style url currently displayed in the map view.
*
* @return The URL of the map style
*/
@@ -1097,6 +1097,27 @@ public final class MapboxMap {
return nativeMapView.getStyleUrl();
}
+ /**
+ * Loads a new map style from a json string.
+ *
+ * If the style fails to load or an invalid style URL is set, the map view will become blank.
+ * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
+ * sent.
+ *
+ */
+ public void setStyleJson(@NonNull String styleJson) {
+ nativeMapView.setStyleJson(styleJson);
+ }
+
+ /**
+ * Returns the map style json currently displayed in the map view.
+ *
+ * @return The json of the map style
+ */
+ public String getStyleJson() {
+ return nativeMapView.getStyleJson();
+ }
+
//
// Annotations
//
--
cgit v1.2.1
From 9238dd46b4bb1f3dfdc87848f97aa66629a392af Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 10 Aug 2017 13:18:46 +0200
Subject: [android] - provide compability with Samsung devices forcing 3-4
array matrix length
---
.../mapboxsdk/maps/widgets/MyLocationView.java | 30 +++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
(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 4e696fb56b..22e92872a5 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
@@ -810,6 +810,9 @@ public class MyLocationView extends View {
private Sensor rotationVectorSensor;
private float[] matrix = new float[9];
+ private float[] rotationVectorValue;
+ private float[] truncatedRotationVectorValue = new float[4];
+
private float[] orientation = new float[3];
private boolean reportMissingSensor = true;
// Compass data
@@ -846,9 +849,8 @@ public class MyLocationView extends View {
}
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
-
- // calculate the rotation matrix
- SensorManager.getRotationMatrixFromVector(matrix, event.values);
+ rotationVectorValue = getRotationVectorFromSensorEvent(event);
+ SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValue);
SensorManager.getOrientation(matrix, orientation);
magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]);
@@ -865,6 +867,28 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Pulls out the rotation vector from a SensorEvent, with a maximum length
+ * vector of four elements to avoid potential compatibility issues.
+ *
+ * @param event the sensor event
+ * @return the events rotation vector, potentially truncated
+ */
+ @NonNull
+ float[] getRotationVectorFromSensorEvent(@NonNull SensorEvent event) {
+ if (event.values.length > 4) {
+ // On some Samsung devices SensorManager.getRotationMatrixFromVector
+ // appears to throw an exception if rotation vector has length > 4.
+ // For the purposes of this class the first 4 values of the
+ // rotation vector are sufficient (see crbug.com/335298 for details).
+ // Only affects Android 4.3
+ System.arraycopy(event.values, 0, truncatedRotationVectorValue, 0, 4);
+ return truncatedRotationVectorValue;
+ } else {
+ return event.values;
+ }
+ }
+
private void rotateCamera(float rotation) {
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.bearing(rotation);
--
cgit v1.2.1
From 6fce6bb6d2f72abbddd02ec0dd0291df7d48fe47 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Fri, 28 Jul 2017 18:58:27 +0200
Subject: [android] - optimise icon management
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 7 +++
.../com/mapbox/mapboxsdk/maps/IconManager.java | 52 +++++++++++++++-------
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 9 ++++
3 files changed, 52 insertions(+), 16 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 edf448ab4f..c09c926eb5 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
@@ -118,6 +118,9 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
+ } else {
+ // do icon cleanup
+ iconManager.iconCleanup(marker.getIcon());
}
} else {
// instanceOf Polygon/Polyline
@@ -137,6 +140,8 @@ class AnnotationManager {
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
+ } else {
+ iconManager.iconCleanup(marker.getIcon());
}
} else {
// instanceOf Polygon/Polyline
@@ -159,6 +164,8 @@ class AnnotationManager {
marker.hideInfoWindow();
if (marker instanceof MarkerView) {
markerViewManager.removeMarkerView((MarkerView) marker);
+ } else {
+ iconManager.iconCleanup(marker.getIcon());
}
} else {
// instanceOf Polygon/Polyline
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 18eecfd9c3..affbf48267 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,16 +1,17 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.Bitmap;
+import android.os.Build;
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.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Responsible for managing icons added to the Map.
@@ -25,15 +26,14 @@ import java.util.List;
*/
class IconManager {
- private NativeMapView nativeMapView;
- private List icons;
+ private final Map iconMap = new HashMap<>();
+ private NativeMapView nativeMapView;
private int highestIconWidth;
private int highestIconHeight;
IconManager(NativeMapView nativeMapView) {
this.nativeMapView = nativeMapView;
- this.icons = new ArrayList<>();
// load transparent icon for MarkerView to trace actual markers, see #6352
loadIcon(IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, IconFactory.ICON_MARKERVIEW_BITMAP));
}
@@ -83,13 +83,13 @@ class IconManager {
}
private void addIcon(Icon icon, boolean addIconToMap) {
- if (!icons.contains(icon)) {
- icons.add(icon);
+ if (!iconMap.keySet().contains(icon)) {
+ iconMap.put(icon, 1);
if (addIconToMap) {
loadIcon(icon);
}
} else {
- validateIconChanged(icon);
+ iconMap.put(icon, iconMap.get(icon) + 1);
}
}
@@ -121,18 +121,11 @@ class IconManager {
}
void reloadIcons() {
- for (Icon icon : icons) {
+ for (Icon icon : iconMap.keySet()) {
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) {
@@ -149,4 +142,31 @@ class IconManager {
marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon));
}
}
+
+ public void iconCleanup(Icon icon) {
+ int refCounter = iconMap.get(icon) - 1;
+ if (refCounter == 0) {
+ remove(icon);
+ } else {
+ updateIconRefCounter(icon, refCounter);
+ }
+ }
+
+ private void remove(Icon icon) {
+ nativeMapView.removeAnnotationIcon(icon.getId());
+ iconMap.remove(icon);
+ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ recycleBitmap(icon.getBitmap());
+ }
+ }
+
+ private void updateIconRefCounter(Icon icon, int refCounter) {
+ iconMap.put(icon, refCounter);
+ }
+
+ private void recycleBitmap(Bitmap bitmap) {
+ if (!bitmap.isRecycled()) {
+ bitmap.recycle();
+ }
+ }
}
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 ddeb4b326e..b2d49bdbf8 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
@@ -507,6 +507,13 @@ final class NativeMapView {
nativeAddAnnotationIcon(symbol, width, height, scale, pixels);
}
+ public void removeAnnotationIcon(String symbol) {
+ if (isDestroyedOn("removeAnnotationIcon")) {
+ return;
+ }
+ nativeRemoveAnnotationIcon(symbol);
+ }
+
public void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
if (isDestroyedOn("setVisibleCoordinateBounds")) {
return;
@@ -990,6 +997,8 @@ final class NativeMapView {
private native void nativeAddAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels);
+ private native void nativeRemoveAnnotationIcon(String symbol);
+
private native void nativeSetVisibleCoordinateBounds(LatLng[] coordinates, RectF padding,
double direction, long duration);
--
cgit v1.2.1
From 336259d4ade7515901f0d477becbe40e9f52d108 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 14 Aug 2017 13:56:30 +0200
Subject: [android] - restore max zoom to 25.5
---
.../src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.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/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index 1ee59057d2..97a9ea94ee 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -55,7 +55,7 @@ public class MapboxConstants {
/**
* The currently supported maximum zoom level.
*/
- public static final float MAXIMUM_ZOOM = 20.0f;
+ public static final float MAXIMUM_ZOOM = 25.5f;
/**
* The currently supported maximum tilt value.
--
cgit v1.2.1
From 40993012b99887d068ec5d53f397e11ac54ca5f6 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 14 Aug 2017 14:18:51 +0200
Subject: [android] - re-add projectedMeters
---
.../main/java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index e0a634521b..a2d759d006 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -6,6 +6,7 @@ import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
/**
@@ -44,6 +45,20 @@ public class Projection {
setContentPadding(contentPadding, userLocationViewPadding);
}
+ /**
+ * Returns the spherical Mercator projected meters for a LatLng.
+ */
+ public ProjectedMeters getProjectedMetersForLatLng(LatLng latLng) {
+ return nativeMapView.projectedMetersForLatLng(latLng);
+ }
+
+ /**
+ * Returns the LatLng for a spherical Mercator projected meters.
+ */
+ public LatLng getLatLngForProjectedMeters(ProjectedMeters projectedMeters) {
+ return nativeMapView.latLngForProjectedMeters(projectedMeters);
+ }
+
/**
*
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
--
cgit v1.2.1
From 3a3a072b7a34e949b9bcc0188c4048e61cdf24dc Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 15 Aug 2017 09:14:09 +0200
Subject: [android] - deprecate MyLocationView in favor of LocationLayer plugin
---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 27 ++++++++++++++++++++++
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 4 ++++
.../mapboxsdk/maps/widgets/MyLocationView.java | 3 +++
.../maps/widgets/MyLocationViewSettings.java | 3 +++
4 files changed, 37 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 cbb1d47b14..becf337545 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
@@ -548,7 +548,10 @@ public final class MapboxMap {
* Gets the tracking interface settings for the map.
*
* @return the TrackingSettings asssociated with this map
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public TrackingSettings getTrackingSettings() {
return trackingSettings;
}
@@ -561,7 +564,10 @@ public final class MapboxMap {
* Gets the settings of the user location for the map.
*
* @return the MyLocationViewSettings associated with this map
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public MyLocationViewSettings getMyLocationViewSettings() {
return myLocationViewSettings;
}
@@ -1810,7 +1816,10 @@ public final class MapboxMap {
* Returns the status of the my-location layer.
*
* @return True if the my-location layer is enabled, false otherwise.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public boolean isMyLocationEnabled() {
return trackingSettings.isMyLocationEnabled();
}
@@ -1825,7 +1834,10 @@ public final class MapboxMap {
* android.Manifest.permission#ACCESS_COARSE_LOCATION or android.Manifest.permission#ACCESS_FINE_LOCATION.
*
* @param enabled True to enable; false to disable.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public void setMyLocationEnabled(boolean enabled) {
trackingSettings.setMyLocationEnabled(enabled);
}
@@ -1834,8 +1846,11 @@ public final class MapboxMap {
* Returns the currently displayed user location, or null if there is no location data available.
*
* @return The currently displayed user location.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
@Nullable
+ @Deprecated
public Location getMyLocation() {
return trackingSettings.getMyLocation();
}
@@ -1846,7 +1861,10 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the user clicks on a marker.
* To unset the callback, use null.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener
listener) {
trackingSettings.setOnMyLocationChangeListener(listener);
@@ -1856,7 +1874,10 @@ public final class MapboxMap {
* Replaces the location source of the my-location layer.
*
* @param locationSource A {@link LocationEngine} location source to use in the my-location layer.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public void setLocationSource(@Nullable LocationEngine locationSource) {
trackingSettings.setLocationSource(locationSource);
}
@@ -1866,7 +1887,10 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the location tracking mode changes.
* To unset the callback, use null.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public void setOnMyLocationTrackingModeChangeListener(
@Nullable MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
trackingSettings.setOnMyLocationTrackingModeChangeListener(listener);
@@ -1877,7 +1901,10 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the bearing tracking mode changes.
* To unset the callback, use null.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+ @Deprecated
public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) {
trackingSettings.setOnMyBearingTrackingModeChangeListener(listener);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index bd0bf7c83b..6881ca067b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -20,7 +20,11 @@ import timber.log.Timber;
/**
* Settings for the user location and bearing tracking of a MapboxMap.
+ *
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+@Deprecated
public final class TrackingSettings {
private final MyLocationView myLocationView;
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 22e92872a5..a0ca3297f4 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
@@ -49,7 +49,10 @@ import timber.log.Timber;
*
* Use {@link MyLocationViewSettings} to manipulate the state of this view.
*
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+@Deprecated
public class MyLocationView extends View {
private static final int UNDEFINED_TINT_COLOR = -1;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
index ea74bc57aa..a1d5b13b8b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationViewSettings.java
@@ -13,7 +13,10 @@ import com.mapbox.mapboxsdk.maps.Projection;
/**
* Settings to configure the visual appearance of the MyLocationView.
+ * @deprecated use location layer plugin from
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
+@Deprecated
public class MyLocationViewSettings {
private Projection projection;
--
cgit v1.2.1
From 71e7759a62d3d37817dca9f04aa4bc9df149ad75 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 16 Aug 2017 10:31:21 +0200
Subject: [android] - enable location change animation of MyLocationView by
default
---
.../src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.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/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
index a0ca3297f4..983ba2550f 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
@@ -80,7 +80,7 @@ public class MyLocationView extends View {
private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
private ValueAnimator directionAnimator;
- private boolean locationChangeAnimationEnabled;
+ private boolean locationChangeAnimationEnabled = true;
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
new ValueAnimator.AnimatorUpdateListener() {
--
cgit v1.2.1
From 830bf151be41609526a662c08bfdf04d358defbf Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 10 Aug 2017 15:07:48 +0200
Subject: [android] - create smallest possible LatLngBounds when visible region
crosses the dateline
---
.../java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java | 10 ++++++++++
.../main/java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 505b2db192..8b2ccffef1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -221,6 +221,16 @@ public class LatLngBounds implements Parcelable {
return new LatLng[] {getNorthEast(), getSouthWest()};
}
+ /**
+ * Constructs a LatLngBounds from doubles representing a LatLng pair.
+ *
+ * This method doesn't recalculate most east or most west boundaries.
+ *
+ */
+ public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) {
+ return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
+ }
+
/**
* Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index a2d759d006..16c73b1ca5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -93,8 +93,6 @@ public class Projection {
* @return The projection of the viewing frustum in its current state.
*/
public VisibleRegion getVisibleRegion() {
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
-
float left = 0;
float right = nativeMapView.getWidth();
float top = 0;
@@ -105,12 +103,13 @@ public class Projection {
LatLng bottomRight = fromScreenLocation(new PointF(right, bottom));
LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom));
- builder.include(topLeft)
- .include(topRight)
- .include(bottomRight)
- .include(bottomLeft);
-
- return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, builder.build());
+ return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
+ LatLngBounds.from(
+ topRight.getLatitude(),
+ topRight.getLongitude(),
+ bottomLeft.getLatitude(),
+ bottomLeft.getLongitude())
+ );
}
/**
--
cgit v1.2.1
From 83336e2224b2f814fd5dedf5d18c0174d806fb1b Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 17 Aug 2017 10:32:49 +0200
Subject: [android] - avoid IndexOutOfBounds when destroying map object
---
.../com/mapbox/mapboxsdk/maps/MarkerContainer.java | 27 ++++++---------------
.../mapbox/mapboxsdk/maps/PolygonContainer.java | 21 ++++------------
.../mapbox/mapboxsdk/maps/PolylineContainer.java | 28 ++++++----------------
3 files changed, 19 insertions(+), 57 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
index b6bee199a3..072382ce07 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
@@ -53,7 +53,7 @@ class MarkerContainer implements Markers {
mapboxMap) {
int count = markerOptionsList.size();
List markers = new ArrayList<>(count);
- if (count > 0) {
+ if (nativeMapView != null && count > 0) {
BaseMarkerOptions markerOptions;
Marker marker;
for (int i = 0; i < count; i++) {
@@ -63,26 +63,13 @@ class MarkerContainer implements Markers {
}
if (markers.size() > 0) {
- long[] ids = null;
- if (nativeMapView != null) {
- ids = nativeMapView.addMarkers(markers);
+ long[] ids = nativeMapView.addMarkers(markers);
+ for (int i = 0; i < ids.length; i++) {
+ Marker createdMarker = markers.get(i);
+ createdMarker.setMapboxMap(mapboxMap);
+ createdMarker.setId(ids[i]);
+ annotations.put(ids[i], createdMarker);
}
-
- long id = 0;
- Marker m;
- for (int i = 0; i < markers.size(); i++) {
- m = markers.get(i);
- m.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
- m.setId(id);
- annotations.put(id, m);
- }
-
}
}
return markers;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
index e626fc3dc0..016862bddc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolygonContainer.java
@@ -42,7 +42,7 @@ class PolygonContainer implements Polygons {
Polygon polygon;
List polygons = new ArrayList<>(count);
- if (count > 0) {
+ if (nativeMapView != null && count > 0) {
for (PolygonOptions polygonOptions : polygonOptionsList) {
polygon = polygonOptions.getPolygon();
if (!polygon.getPoints().isEmpty()) {
@@ -50,23 +50,12 @@ class PolygonContainer implements Polygons {
}
}
- long[] ids = null;
- if (nativeMapView != null) {
- ids = nativeMapView.addPolygons(polygons);
- }
-
- long id = 0;
- for (int i = 0; i < polygons.size(); i++) {
+ long[] ids = nativeMapView.addPolygons(polygons);
+ for (int i = 0; i < ids.length; i++) {
polygon = polygons.get(i);
polygon.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
- polygon.setId(id);
- annotations.put(id, polygon);
+ polygon.setId(ids[i]);
+ annotations.put(ids[i], polygon);
}
}
return polygons;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
index b9a358c0f9..303b25fb55 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/PolylineContainer.java
@@ -41,8 +41,7 @@ class PolylineContainer implements Polylines {
int count = polylineOptionsList.size();
Polyline polyline;
List polylines = new ArrayList<>(count);
-
- if (count > 0) {
+ if (nativeMapView != null && count > 0) {
for (PolylineOptions options : polylineOptionsList) {
polyline = options.getPolyline();
if (!polyline.getPoints().isEmpty()) {
@@ -50,25 +49,12 @@ class PolylineContainer implements Polylines {
}
}
- long[] ids = null;
- if (nativeMapView != null) {
- ids = nativeMapView.addPolylines(polylines);
- }
-
- long id = 0;
- Polyline p;
-
- for (int i = 0; i < polylines.size(); i++) {
- p = polylines.get(i);
- p.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
- p.setId(id);
- annotations.put(id, p);
+ long[] ids = nativeMapView.addPolylines(polylines);
+ for (int i = 0; i < ids.length; i++) {
+ Polyline polylineCreated = polylines.get(i);
+ polylineCreated.setMapboxMap(mapboxMap);
+ polylineCreated.setId(ids[i]);
+ annotations.put(ids[i], polylineCreated);
}
}
return polylines;
--
cgit v1.2.1
From 385e4e6ade58dbc51efde7d18843163c047337de Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 14 Aug 2017 09:57:51 +0200
Subject: [android] - style image accessor
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 4 ++++
.../src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 9 +++++++++
2 files changed, 13 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 becf337545..5389cd7e7a 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
@@ -473,6 +473,10 @@ public final class MapboxMap {
nativeMapView.removeImage(name);
}
+ public Bitmap getImage(@NonNull String name) {
+ return nativeMapView.getImage(name);
+ }
+
//
// MinZoom
//
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 b2d49bdbf8..4f5037e4b3 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
@@ -808,6 +808,13 @@ final class NativeMapView {
nativeRemoveImage(name);
}
+ public Bitmap getImage(String name) {
+ if (isDestroyedOn("getImage")) {
+ return null;
+ }
+ return nativeGetImage(name);
+ }
+
// Feature querying
@NonNull
@@ -1078,6 +1085,8 @@ final class NativeMapView {
private native void nativeRemoveImage(String name);
+ private native Bitmap nativeGetImage(String name);
+
private native void nativeUpdatePolygon(long polygonId, Polygon polygon);
private native void nativeUpdatePolyline(long polylineId, Polyline polyline);
--
cgit v1.2.1
From a059c74a54302f9604f3e3b28143be7645e6204f Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 14 Aug 2017 11:59:57 +0200
Subject: [android] - configure loggin of HttpRequest, cleanup HttpRequest
---
.../com/mapbox/mapboxsdk/http/HTTPRequest.java | 200 -----------------
.../com/mapbox/mapboxsdk/http/HttpRequest.java | 238 +++++++++++++++++++++
.../com/mapbox/mapboxsdk/http/HttpRequestUtil.java | 19 ++
3 files changed, 257 insertions(+), 200 deletions(-)
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
deleted file mode 100644
index 91a235616a..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package com.mapbox.mapboxsdk.http;
-
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.os.Build;
-import android.text.TextUtils;
-
-import com.mapbox.mapboxsdk.BuildConfig;
-import com.mapbox.mapboxsdk.Mapbox;
-import com.mapbox.mapboxsdk.constants.MapboxConstants;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.NoRouteToHostException;
-import java.net.ProtocolException;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.net.ssl.SSLException;
-
-import okhttp3.Call;
-import okhttp3.Callback;
-import okhttp3.HttpUrl;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.internal.Util;
-import timber.log.Timber;
-
-class HTTPRequest implements Callback {
-
- private static OkHttpClient mClient = new OkHttpClient();
- private String USER_AGENT_STRING = null;
-
- private static final int CONNECTION_ERROR = 0;
- private static final int TEMPORARY_ERROR = 1;
- private static final int PERMANENT_ERROR = 2;
-
- // Reentrancy is not needed, but "Lock" is an
- // abstract class.
- private ReentrantLock mLock = new ReentrantLock();
-
- private long mNativePtr = 0;
-
- private Call mCall;
- private Request mRequest;
-
- private native void nativeOnFailure(int type, String message);
-
- private native void nativeOnResponse(int code, String etag, String modified, String cacheControl, String expires,
- String retryAfter, String xRateLimitReset, byte[] body);
-
- private HTTPRequest(long nativePtr, String resourceUrl, String etag, String modified) {
- mNativePtr = nativePtr;
-
- try {
- // Don't try a request if we aren't connected
- if (!Mapbox.isConnected()) {
- throw new NoRouteToHostException("No Internet connection available.");
- }
-
- HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
- final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
- if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
- || host.endsWith(".mapbox.cn")) {
- if (httpUrl.querySize() == 0) {
- resourceUrl = resourceUrl + "?";
- } else {
- resourceUrl = resourceUrl + "&";
- }
- resourceUrl = resourceUrl + "events=true";
- }
-
- Request.Builder builder = new Request.Builder()
- .url(resourceUrl)
- .tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE))
- .addHeader("User-Agent", getUserAgent());
- if (etag.length() > 0) {
- builder = builder.addHeader("If-None-Match", etag);
- } else if (modified.length() > 0) {
- builder = builder.addHeader("If-Modified-Since", modified);
- }
- mRequest = builder.build();
- mCall = mClient.newCall(mRequest);
- mCall.enqueue(this);
- } catch (Exception exception) {
- onFailure(exception);
- }
- }
-
- public void cancel() {
- // mCall can be null if the constructor gets aborted (e.g, under a NoRouteToHostException).
- if (mCall != null) {
- mCall.cancel();
- }
-
- // TODO: We need a lock here because we can try
- // to cancel at the same time the request is getting
- // answered on the OkHTTP thread. We could get rid of
- // this lock by using Runnable when we move Android
- // implementation of mbgl::RunLoop to Looper.
- mLock.lock();
- mNativePtr = 0;
- mLock.unlock();
- }
-
- @Override
- public void onResponse(Call call, Response response) throws IOException {
- if (response.isSuccessful()) {
- Timber.v("[HTTP] Request was successful (code = %s).", response.code());
- } else {
- // We don't want to call this unsuccessful because a 304 isn't really an error
- String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
- Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
- }
-
- byte[] body;
- try {
- body = response.body().bytes();
- } catch (IOException ioException) {
- onFailure(ioException);
- // throw ioException;
- return;
- } finally {
- response.body().close();
- }
-
- mLock.lock();
- if (mNativePtr != 0) {
- nativeOnResponse(response.code(),
- response.header("ETag"),
- response.header("Last-Modified"),
- response.header("Cache-Control"),
- response.header("Expires"),
- response.header("Retry-After"),
- response.header("x-rate-limit-reset"),
- body);
- }
- mLock.unlock();
- }
-
- @Override
- public void onFailure(Call call, IOException e) {
- onFailure(e);
- }
-
- private void onFailure(Exception e) {
- int type = PERMANENT_ERROR;
- if ((e instanceof NoRouteToHostException) || (e instanceof UnknownHostException) || (e instanceof SocketException)
- || (e instanceof ProtocolException) || (e instanceof SSLException)) {
- type = CONNECTION_ERROR;
- } else if ((e instanceof InterruptedIOException)) {
- type = TEMPORARY_ERROR;
- }
-
- String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
-
- if (type == TEMPORARY_ERROR) {
- Timber.d("Request failed due to a temporary error: %s", errorMessage);
- } else if (type == CONNECTION_ERROR) {
- Timber.i("Request failed due to a connection error: %s", errorMessage);
- } else {
- // PERMANENT_ERROR
- Timber.w("Request failed due to a permanent error: %s", errorMessage);
- }
-
- mLock.lock();
- if (mNativePtr != 0) {
- nativeOnFailure(type, errorMessage);
- }
- mLock.unlock();
- }
-
- private String getUserAgent() {
- if (USER_AGENT_STRING == null) {
- return USER_AGENT_STRING = Util.toHumanReadableAscii(
- String.format("%s %s (%s) Android/%s (%s)",
- getApplicationIdentifier(),
- BuildConfig.MAPBOX_VERSION_STRING,
- BuildConfig.GIT_REVISION_SHORT,
- Build.VERSION.SDK_INT,
- Build.CPU_ABI)
- );
- } else {
- return USER_AGENT_STRING;
- }
- }
-
- private String getApplicationIdentifier() {
- try {
- Context context = Mapbox.getApplicationContext();
- PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
- return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
- } catch (Exception exception) {
- return "";
- }
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
new file mode 100644
index 0000000000..4f899cf696
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
@@ -0,0 +1,238 @@
+package com.mapbox.mapboxsdk.http;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.os.Build;
+import android.support.annotation.IntDef;
+import android.support.annotation.NonNull;
+import android.text.TextUtils;
+
+import com.mapbox.mapboxsdk.BuildConfig;
+import com.mapbox.mapboxsdk.Mapbox;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.net.NoRouteToHostException;
+import java.net.ProtocolException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.net.ssl.SSLException;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.internal.Util;
+import timber.log.Timber;
+
+/**
+ * Gateway to request and return HttpRequest to c++
+ *
+ * Reentrancy lock is not needed, but "Lock" is an abstract class.
+ *
+ */
+class HttpRequest implements Callback {
+
+ @IntDef( {CONNECTION_ERROR, TEMPORARY_ERROR, PERMANENT_ERROR})
+ @Retention(RetentionPolicy.SOURCE)
+ @interface HttpError {
+ }
+
+ private static final int CONNECTION_ERROR = 0;
+ private static final int TEMPORARY_ERROR = 1;
+ private static final int PERMANENT_ERROR = 2;
+
+ private static final ReentrantLock LOCK = new ReentrantLock();
+ private static final OkHttpClient HTTP_CLIENT = new OkHttpClient();
+
+ private static boolean logEnabled = true;
+ private static String userAgentString;
+
+ private long nativePtr;
+ private Call call;
+
+ private native void nativeOnFailure(@HttpError int type, String message);
+
+ private native void nativeOnResponse(int code, String etag, String modified, String cacheControl, String expires,
+ String retryAfter, String xRateLimitReset, byte[] body);
+
+ private HttpRequest(long nativePtr, String resourceUrl, String etag, String modified) {
+ this.nativePtr = nativePtr;
+
+ try {
+ // Don't try a request if we aren't connected
+ if (!Mapbox.isConnected()) {
+ throw new NoRouteToHostException("No Internet connection available.");
+ }
+
+ resourceUrl = adaptResourceUrl(resourceUrl);
+ call = HTTP_CLIENT.newCall(buildRequest(resourceUrl, etag, modified));
+ call.enqueue(this);
+ } catch (Exception exception) {
+ onFailure(exception);
+ }
+ }
+
+ private String adaptResourceUrl(String resourceUrl) {
+ HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
+ if (httpUrl != null && isMapboxHost(httpUrl)) {
+ HttpUrl.Builder builder = httpUrl.newBuilder();
+ builder.addQueryParameter("events", "true");
+ resourceUrl = builder.build().toString();
+ }
+ return resourceUrl;
+ }
+
+ private boolean isMapboxHost(@NonNull HttpUrl httpUrl) {
+ final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
+ return host.equals("mapbox.com") || host.endsWith(".mapbox.com")
+ || host.equals("mapbox.cn") || host.endsWith(".mapbox.cn");
+ }
+
+ private Request buildRequest(String resourceUrl, String etag, String modified) {
+ Request.Builder builder = new Request.Builder()
+ .url(resourceUrl)
+ .tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE))
+ .addHeader("User-Agent", getUserAgentString());
+ if (etag.length() > 0) {
+ builder = builder.addHeader("If-None-Match", etag);
+ } else if (modified.length() > 0) {
+ builder = builder.addHeader("If-Modified-Since", modified);
+ }
+ return builder.build();
+ }
+
+ public void cancel() {
+ // call can be null if the constructor gets aborted (e.g, under a NoRouteToHostException).
+ if (call != null) {
+ call.cancel();
+ }
+
+ // TODO: We need a LOCK here because we can try
+ // to cancel at the same time the request is getting
+ // answered on the OkHTTP thread. We could get rid of
+ // this LOCK by using Runnable when we move Android
+ // implementation of mbgl::RunLoop to Looper.
+ LOCK.lock();
+ nativePtr = 0;
+ LOCK.unlock();
+ }
+
+ @Override
+ public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
+ if (logEnabled) {
+ logOnResponse(response);
+ }
+
+ byte[] body;
+ try {
+ body = response.body().bytes();
+ } catch (IOException ioException) {
+ onFailure(ioException);
+ return;
+ } finally {
+ response.body().close();
+ }
+
+ LOCK.lock();
+ if (nativePtr != 0) {
+ nativeOnResponse(response.code(),
+ response.header("ETag"),
+ response.header("Last-Modified"),
+ response.header("Cache-Control"),
+ response.header("Expires"),
+ response.header("Retry-After"),
+ response.header("x-rate-limit-reset"),
+ body);
+ }
+ LOCK.unlock();
+ }
+
+ private void logOnResponse(Response response) {
+ if (response.isSuccessful()) {
+ Timber.v("[HTTP] Request was successful (code = %s).", response.code());
+ } else if (logEnabled) {
+ // We don't want to call this unsuccessful because a 304 isn't really an error
+ String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
+ Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call call, @NonNull IOException exception) {
+ onFailure(exception);
+ }
+
+ private void onFailure(Exception exception) {
+ int failType = resolveFailureType(exception);
+ String errorMessage = exception.getMessage() != null ? exception.getMessage() : "Error processing the request";
+ if (logEnabled) {
+ logOnFailure(failType, errorMessage);
+ }
+
+ LOCK.lock();
+ if (nativePtr != 0) {
+ nativeOnFailure(failType, errorMessage);
+ }
+ LOCK.unlock();
+ }
+
+ @HttpError
+ private int resolveFailureType(Exception exception) {
+ int type = PERMANENT_ERROR;
+ if ((exception instanceof NoRouteToHostException) || (exception instanceof UnknownHostException)
+ || (exception instanceof SocketException) || (exception instanceof ProtocolException)
+ || (exception instanceof SSLException)) {
+ type = CONNECTION_ERROR;
+ } else if ((exception instanceof InterruptedIOException)) {
+ type = TEMPORARY_ERROR;
+ }
+ return type;
+ }
+
+ private void logOnFailure(@HttpError int type, String errorMessage) {
+ if (type == TEMPORARY_ERROR) {
+ Timber.d("Request failed due to a temporary error: %s", errorMessage);
+ } else if (type == CONNECTION_ERROR) {
+ Timber.i("Request failed due to a connection error: %s", errorMessage);
+ } else {
+ // PERMANENT_ERROR
+ Timber.w("Request failed due to a permanent error: %s", errorMessage);
+ }
+ }
+
+ private String getUserAgentString() {
+ if (userAgentString == null) {
+ userAgentString = Util.toHumanReadableAscii(
+ String.format("%s %s (%s) Android/%s (%s)",
+ getApplicationIdentifier(),
+ BuildConfig.MAPBOX_VERSION_STRING,
+ BuildConfig.GIT_REVISION_SHORT,
+ Build.VERSION.SDK_INT,
+ Build.CPU_ABI)
+ );
+ }
+ return userAgentString;
+ }
+
+ private String getApplicationIdentifier() {
+ try {
+ Context context = Mapbox.getApplicationContext();
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
+ } catch (Exception exception) {
+ return "";
+ }
+ }
+
+ static void enableLog(boolean enabled) {
+ logEnabled = enabled;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
new file mode 100644
index 0000000000..46359572e6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
@@ -0,0 +1,19 @@
+package com.mapbox.mapboxsdk.http;
+
+/**
+ * Utility class for setting HttpRequest configurations
+ */
+public class HttpRequestUtil {
+
+ /**
+ * Set the log state of HttpRequest.
+ *
+ * This configuration will outlast the lifecycle of the Map.
+ *
+ *
+ * @param enabled True will enable logging, false will disable
+ */
+ public static void setLogEnabled(boolean enabled) {
+ HttpRequest.enableLog(enabled);
+ }
+}
--
cgit v1.2.1
From 05cbd4e31d40921acea40ad935ceb06a0ea08324 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 29 Jun 2017 13:36:59 +0200
Subject: [android] - keep state of initial overlain views margins (#9391)
---
.../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 45 ++++++++++++++--------
1 file changed, 29 insertions(+), 16 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 3f43c23a7f..e71d509fcf 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
@@ -36,8 +36,14 @@ public final class UiSettings {
private final FocalPointChangeListener focalPointChangeListener;
private final Projection projection;
private final CompassView compassView;
+ private final int[] compassMargins = new int[4];
+
private final ImageView attributionsView;
+ private final int[] attributionsMargins = new int[4];
+
private final View logoView;
+ private final int[] logoMargins = new int[4];
+
private float pixelRatio;
private boolean rotateGesturesEnabled = true;
@@ -368,7 +374,7 @@ public final class UiSettings {
*/
@UiThread
public void setCompassMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(compassView, left, top, right, bottom);
+ setWidgetMargins(compassView, compassMargins, left, top, right, bottom);
}
/**
@@ -377,7 +383,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getCompassMarginLeft() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).leftMargin;
+ return compassMargins[0];
}
/**
@@ -386,7 +392,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getCompassMarginTop() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).topMargin;
+ return compassMargins[1];
}
/**
@@ -395,7 +401,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getCompassMarginRight() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).rightMargin;
+ return compassMargins[2];
}
/**
@@ -404,7 +410,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getCompassMarginBottom() {
- return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin;
+ return compassMargins[3];
}
/**
@@ -478,7 +484,7 @@ public final class UiSettings {
* @param bottom The bottom margin in pixels.
*/
public void setLogoMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(logoView, left, top, right, bottom);
+ setWidgetMargins(logoView, logoMargins, left, top, right, bottom);
}
/**
@@ -487,7 +493,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getLogoMarginLeft() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).leftMargin;
+ return logoMargins[0];
}
/**
@@ -496,7 +502,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getLogoMarginTop() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).topMargin;
+ return logoMargins[1];
}
/**
@@ -505,7 +511,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getLogoMarginRight() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).rightMargin;
+ return logoMargins[2];
}
/**
@@ -514,7 +520,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getLogoMarginBottom() {
- return ((FrameLayout.LayoutParams) logoView.getLayoutParams()).bottomMargin;
+ return logoMargins[3];
}
/**
@@ -568,7 +574,7 @@ public final class UiSettings {
* @param bottom The bottom margin in pixels.
*/
public void setAttributionMargins(int left, int top, int right, int bottom) {
- setWidgetMargins(attributionsView, left, top, right, bottom);
+ setWidgetMargins(attributionsView, attributionsMargins, left, top, right, bottom);
}
/**
@@ -595,7 +601,7 @@ public final class UiSettings {
* @return The left margin in pixels
*/
public int getAttributionMarginLeft() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).leftMargin;
+ return attributionsMargins[0];
}
/**
@@ -604,7 +610,7 @@ public final class UiSettings {
* @return The top margin in pixels
*/
public int getAttributionMarginTop() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).topMargin;
+ return attributionsMargins[1];
}
/**
@@ -613,7 +619,7 @@ public final class UiSettings {
* @return The right margin in pixels
*/
public int getAttributionMarginRight() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).rightMargin;
+ return attributionsMargins[2];
}
/**
@@ -622,7 +628,7 @@ public final class UiSettings {
* @return The bottom margin in pixels
*/
public int getAttributionMarginBottom() {
- return ((FrameLayout.LayoutParams) attributionsView.getLayoutParams()).bottomMargin;
+ return attributionsMargins[3];
}
/**
@@ -926,7 +932,14 @@ public final class UiSettings {
view.setLayoutParams(layoutParams);
}
- private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) {
+ private void setWidgetMargins(@NonNull final View view, int[] initMargins, int left, int top, int right, int bottom) {
+ // keep state of initially set margins
+ initMargins[0] = left;
+ initMargins[1] = top;
+ initMargins[2] = right;
+ initMargins[3] = bottom;
+
+ // convert inital margins with padding
int[] contentPadding = projection.getContentPadding();
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
left += contentPadding[0];
--
cgit v1.2.1
From b4cb719ceba57b5b2879d54473531c3404a20c77 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 10 Aug 2017 13:18:46 +0200
Subject: [android] - provide compability with Samsung devices forcing 3-4
array matrix length
---
.../mapboxsdk/maps/widgets/MyLocationView.java | 30 +++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
(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 24da59bb7e..61b0efe656 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
@@ -797,6 +797,9 @@ public class MyLocationView extends View {
private Sensor rotationVectorSensor;
private float[] matrix = new float[9];
+ private float[] rotationVectorValue;
+ private float[] truncatedRotationVectorValue = new float[4];
+
private float[] orientation = new float[3];
private boolean reportMissingSensor = true;
// Compass data
@@ -833,9 +836,8 @@ public class MyLocationView extends View {
}
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
-
- // calculate the rotation matrix
- SensorManager.getRotationMatrixFromVector(matrix, event.values);
+ rotationVectorValue = getRotationVectorFromSensorEvent(event);
+ SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValue);
SensorManager.getOrientation(matrix, orientation);
magneticHeading = (float) Math.toDegrees(SensorManager.getOrientation(matrix, orientation)[0]);
@@ -852,6 +854,28 @@ public class MyLocationView extends View {
}
}
+ /**
+ * Pulls out the rotation vector from a SensorEvent, with a maximum length
+ * vector of four elements to avoid potential compatibility issues.
+ *
+ * @param event the sensor event
+ * @return the events rotation vector, potentially truncated
+ */
+ @NonNull
+ float[] getRotationVectorFromSensorEvent(@NonNull SensorEvent event) {
+ if (event.values.length > 4) {
+ // On some Samsung devices SensorManager.getRotationMatrixFromVector
+ // appears to throw an exception if rotation vector has length > 4.
+ // For the purposes of this class the first 4 values of the
+ // rotation vector are sufficient (see crbug.com/335298 for details).
+ // Only affects Android 4.3
+ System.arraycopy(event.values, 0, truncatedRotationVectorValue, 0, 4);
+ return truncatedRotationVectorValue;
+ } else {
+ return event.values;
+ }
+ }
+
private void rotateCamera(float rotation) {
CameraPosition.Builder builder = new CameraPosition.Builder();
builder.bearing(rotation);
--
cgit v1.2.1
From 2802c55bd5e4f104fee991cb944e4d2503cbb18d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 10 Aug 2017 15:07:48 +0200
Subject: [android] - create smallest possible LatLngBounds when visible region
crosses the dateline
---
.../java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java | 10 ++++++++++
.../main/java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++--------
2 files changed, 17 insertions(+), 8 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 505b2db192..8b2ccffef1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -221,6 +221,16 @@ public class LatLngBounds implements Parcelable {
return new LatLng[] {getNorthEast(), getSouthWest()};
}
+ /**
+ * Constructs a LatLngBounds from doubles representing a LatLng pair.
+ *
+ * This method doesn't recalculate most east or most west boundaries.
+ *
+ */
+ public static LatLngBounds from(double latNorth, double lonEast, double latSouth, double lonWest) {
+ return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
+ }
+
/**
* Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index e0a634521b..3841809a65 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -78,8 +78,6 @@ public class Projection {
* @return The projection of the viewing frustum in its current state.
*/
public VisibleRegion getVisibleRegion() {
- LatLngBounds.Builder builder = new LatLngBounds.Builder();
-
float left = 0;
float right = nativeMapView.getWidth();
float top = 0;
@@ -90,12 +88,13 @@ public class Projection {
LatLng bottomRight = fromScreenLocation(new PointF(right, bottom));
LatLng bottomLeft = fromScreenLocation(new PointF(left, bottom));
- builder.include(topLeft)
- .include(topRight)
- .include(bottomRight)
- .include(bottomLeft);
-
- return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight, builder.build());
+ return new VisibleRegion(topLeft, topRight, bottomLeft, bottomRight,
+ LatLngBounds.from(
+ topRight.getLatitude(),
+ topRight.getLongitude(),
+ bottomLeft.getLatitude(),
+ bottomLeft.getLongitude())
+ );
}
/**
--
cgit v1.2.1
From a83c19e9543ae3a84bfe41db9a03a9f4f4957064 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Mon, 14 Aug 2017 14:18:51 +0200
Subject: [android] - re-add projectedMeters
---
.../main/java/com/mapbox/mapboxsdk/maps/Projection.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
index 3841809a65..16c73b1ca5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Projection.java
@@ -6,6 +6,7 @@ import android.support.annotation.NonNull;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.geometry.VisibleRegion;
/**
@@ -44,6 +45,20 @@ public class Projection {
setContentPadding(contentPadding, userLocationViewPadding);
}
+ /**
+ * Returns the spherical Mercator projected meters for a LatLng.
+ */
+ public ProjectedMeters getProjectedMetersForLatLng(LatLng latLng) {
+ return nativeMapView.projectedMetersForLatLng(latLng);
+ }
+
+ /**
+ * Returns the LatLng for a spherical Mercator projected meters.
+ */
+ public LatLng getLatLngForProjectedMeters(ProjectedMeters projectedMeters) {
+ return nativeMapView.latLngForProjectedMeters(projectedMeters);
+ }
+
/**
*
* Returns the distance spanned by one pixel at the specified latitude and current zoom level.
--
cgit v1.2.1
From f356ff4b0047179d42e25d46578fc464e341ee5d Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 16 Aug 2017 10:31:21 +0200
Subject: [android] - enable location change animation of MyLocationView by
default
---
.../src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.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/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
index 61b0efe656..f74286705c 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
@@ -75,7 +75,7 @@ public class MyLocationView extends View {
private ValueAnimator locationChangeAnimator;
private ValueAnimator accuracyAnimator;
private ValueAnimator directionAnimator;
- private boolean locationChangeAnimationEnabled;
+ private boolean locationChangeAnimationEnabled = true;
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
new ValueAnimator.AnimatorUpdateListener() {
--
cgit v1.2.1
From 341165cef44c7ecd67f3a911eb29e0433d33e14c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 17 Aug 2017 10:32:49 +0200
Subject: [android] - avoid IndexOutOfBounds when destroying map object
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 46 +++++++++-------------
1 file changed, 18 insertions(+), 28 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 712ab67de0..d15d5eddf8 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
@@ -212,22 +212,19 @@ class AnnotationManager {
}
if (markers.size() > 0) {
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addMarkers(markers);
+ } else {
+ ids = new long[markers.size()];
}
- long id = 0;
+ long id;
Marker m;
- for (int i = 0; i < markers.size(); i++) {
+ for (int i = 0; i < ids.length; i++) {
m = markers.get(i);
m.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
m.setId(id);
annotations.put(id, m);
}
@@ -481,21 +478,18 @@ class AnnotationManager {
}
}
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addPolygons(polygons);
+ } else {
+ ids = new long[polygons.size()];
}
- long id = 0;
- for (int i = 0; i < polygons.size(); i++) {
+ long id;
+ for (int i = 0; i < ids.length; i++) {
polygon = polygons.get(i);
polygon.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
polygon.setId(id);
shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, polygon);
@@ -555,23 +549,19 @@ class AnnotationManager {
}
}
- long[] ids = null;
+ long[] ids;
if (nativeMapView != null) {
ids = nativeMapView.addPolylines(polylines);
+ } else {
+ ids = new long[polylines.size()];
}
- long id = 0;
+ long id;
Polyline p;
-
- for (int i = 0; i < polylines.size(); i++) {
+ for (int i = 0; i < ids.length; i++) {
p = polylines.get(i);
p.setMapboxMap(mapboxMap);
- if (ids != null) {
- id = ids[i];
- } else {
- // unit test
- id++;
- }
+ id = ids[i];
p.setId(id);
shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + id);
annotations.put(id, p);
--
cgit v1.2.1
From 8d04e099c7a4b0c8b100c24930f0407ba13b454c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Fri, 18 Aug 2017 11:50:45 +0200
Subject: [android] - update config for next reelease
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
.../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index af1d04ab97..033903822f 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.1.3-SNAPSHOT
+VERSION_NAME=5.1.4-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
index 3cfc7d5fdc..81e0e5d7a8 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
+++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
@@ -1,3 +1,3 @@
fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk
-fabric-version=5.1.2
+fabric-version=5.1.3
fabric-build-type=binary
--
cgit v1.2.1
From d21f19686bad074e8ae4ef103e10191665feaaed Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Wed, 2 Aug 2017 15:37:31 -0700
Subject: Set Default MaxZoom to 22
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 5389cd7e7a..0d1d0e03b5 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
@@ -495,7 +495,7 @@ public final class MapboxMap {
/**
*
- * Gets the maximum zoom level the map can be displayed at.
+ * Gets the minimum zoom level the map can be displayed at.
*
*
* @return The minimum zoom level.
@@ -512,7 +512,9 @@ public final class MapboxMap {
*
* Sets the maximum zoom level the map can be displayed at.
*
- *
+ *
+ * The default maximum zoomn level is 22. The upper bound for this value is 25.5.
+ *
* @param maxZoom The new maximum zoom level.
*/
public void setMaxZoomPreference(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
--
cgit v1.2.1
From fde31db28f83fe0238278e00a9a7470425928799 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 24 Aug 2017 14:28:39 +0200
Subject: Revert "[android] - configure loggin of HttpRequest, cleanup
HttpRequest"
This reverts commit a059c74a54302f9604f3e3b28143be7645e6204f.
---
.../com/mapbox/mapboxsdk/http/HTTPRequest.java | 200 +++++++++++++++++
.../com/mapbox/mapboxsdk/http/HttpRequest.java | 238 ---------------------
.../com/mapbox/mapboxsdk/http/HttpRequestUtil.java | 19 --
3 files changed, 200 insertions(+), 257 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
new file mode 100644
index 0000000000..91a235616a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -0,0 +1,200 @@
+package com.mapbox.mapboxsdk.http;
+
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.os.Build;
+import android.text.TextUtils;
+
+import com.mapbox.mapboxsdk.BuildConfig;
+import com.mapbox.mapboxsdk.Mapbox;
+import com.mapbox.mapboxsdk.constants.MapboxConstants;
+
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.NoRouteToHostException;
+import java.net.ProtocolException;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.net.ssl.SSLException;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.HttpUrl;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.internal.Util;
+import timber.log.Timber;
+
+class HTTPRequest implements Callback {
+
+ private static OkHttpClient mClient = new OkHttpClient();
+ private String USER_AGENT_STRING = null;
+
+ private static final int CONNECTION_ERROR = 0;
+ private static final int TEMPORARY_ERROR = 1;
+ private static final int PERMANENT_ERROR = 2;
+
+ // Reentrancy is not needed, but "Lock" is an
+ // abstract class.
+ private ReentrantLock mLock = new ReentrantLock();
+
+ private long mNativePtr = 0;
+
+ private Call mCall;
+ private Request mRequest;
+
+ private native void nativeOnFailure(int type, String message);
+
+ private native void nativeOnResponse(int code, String etag, String modified, String cacheControl, String expires,
+ String retryAfter, String xRateLimitReset, byte[] body);
+
+ private HTTPRequest(long nativePtr, String resourceUrl, String etag, String modified) {
+ mNativePtr = nativePtr;
+
+ try {
+ // Don't try a request if we aren't connected
+ if (!Mapbox.isConnected()) {
+ throw new NoRouteToHostException("No Internet connection available.");
+ }
+
+ HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
+ final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
+ if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
+ || host.endsWith(".mapbox.cn")) {
+ if (httpUrl.querySize() == 0) {
+ resourceUrl = resourceUrl + "?";
+ } else {
+ resourceUrl = resourceUrl + "&";
+ }
+ resourceUrl = resourceUrl + "events=true";
+ }
+
+ Request.Builder builder = new Request.Builder()
+ .url(resourceUrl)
+ .tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE))
+ .addHeader("User-Agent", getUserAgent());
+ if (etag.length() > 0) {
+ builder = builder.addHeader("If-None-Match", etag);
+ } else if (modified.length() > 0) {
+ builder = builder.addHeader("If-Modified-Since", modified);
+ }
+ mRequest = builder.build();
+ mCall = mClient.newCall(mRequest);
+ mCall.enqueue(this);
+ } catch (Exception exception) {
+ onFailure(exception);
+ }
+ }
+
+ public void cancel() {
+ // mCall can be null if the constructor gets aborted (e.g, under a NoRouteToHostException).
+ if (mCall != null) {
+ mCall.cancel();
+ }
+
+ // TODO: We need a lock here because we can try
+ // to cancel at the same time the request is getting
+ // answered on the OkHTTP thread. We could get rid of
+ // this lock by using Runnable when we move Android
+ // implementation of mbgl::RunLoop to Looper.
+ mLock.lock();
+ mNativePtr = 0;
+ mLock.unlock();
+ }
+
+ @Override
+ public void onResponse(Call call, Response response) throws IOException {
+ if (response.isSuccessful()) {
+ Timber.v("[HTTP] Request was successful (code = %s).", response.code());
+ } else {
+ // We don't want to call this unsuccessful because a 304 isn't really an error
+ String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
+ Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
+ }
+
+ byte[] body;
+ try {
+ body = response.body().bytes();
+ } catch (IOException ioException) {
+ onFailure(ioException);
+ // throw ioException;
+ return;
+ } finally {
+ response.body().close();
+ }
+
+ mLock.lock();
+ if (mNativePtr != 0) {
+ nativeOnResponse(response.code(),
+ response.header("ETag"),
+ response.header("Last-Modified"),
+ response.header("Cache-Control"),
+ response.header("Expires"),
+ response.header("Retry-After"),
+ response.header("x-rate-limit-reset"),
+ body);
+ }
+ mLock.unlock();
+ }
+
+ @Override
+ public void onFailure(Call call, IOException e) {
+ onFailure(e);
+ }
+
+ private void onFailure(Exception e) {
+ int type = PERMANENT_ERROR;
+ if ((e instanceof NoRouteToHostException) || (e instanceof UnknownHostException) || (e instanceof SocketException)
+ || (e instanceof ProtocolException) || (e instanceof SSLException)) {
+ type = CONNECTION_ERROR;
+ } else if ((e instanceof InterruptedIOException)) {
+ type = TEMPORARY_ERROR;
+ }
+
+ String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
+
+ if (type == TEMPORARY_ERROR) {
+ Timber.d("Request failed due to a temporary error: %s", errorMessage);
+ } else if (type == CONNECTION_ERROR) {
+ Timber.i("Request failed due to a connection error: %s", errorMessage);
+ } else {
+ // PERMANENT_ERROR
+ Timber.w("Request failed due to a permanent error: %s", errorMessage);
+ }
+
+ mLock.lock();
+ if (mNativePtr != 0) {
+ nativeOnFailure(type, errorMessage);
+ }
+ mLock.unlock();
+ }
+
+ private String getUserAgent() {
+ if (USER_AGENT_STRING == null) {
+ return USER_AGENT_STRING = Util.toHumanReadableAscii(
+ String.format("%s %s (%s) Android/%s (%s)",
+ getApplicationIdentifier(),
+ BuildConfig.MAPBOX_VERSION_STRING,
+ BuildConfig.GIT_REVISION_SHORT,
+ Build.VERSION.SDK_INT,
+ Build.CPU_ABI)
+ );
+ } else {
+ return USER_AGENT_STRING;
+ }
+ }
+
+ private String getApplicationIdentifier() {
+ try {
+ Context context = Mapbox.getApplicationContext();
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
+ } catch (Exception exception) {
+ return "";
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
deleted file mode 100644
index 4f899cf696..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
+++ /dev/null
@@ -1,238 +0,0 @@
-package com.mapbox.mapboxsdk.http;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.os.Build;
-import android.support.annotation.IntDef;
-import android.support.annotation.NonNull;
-import android.text.TextUtils;
-
-import com.mapbox.mapboxsdk.BuildConfig;
-import com.mapbox.mapboxsdk.Mapbox;
-import com.mapbox.mapboxsdk.constants.MapboxConstants;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.net.NoRouteToHostException;
-import java.net.ProtocolException;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.concurrent.locks.ReentrantLock;
-
-import javax.net.ssl.SSLException;
-
-import okhttp3.Call;
-import okhttp3.Callback;
-import okhttp3.HttpUrl;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.internal.Util;
-import timber.log.Timber;
-
-/**
- * Gateway to request and return HttpRequest to c++
- *
- * Reentrancy lock is not needed, but "Lock" is an abstract class.
- *
- */
-class HttpRequest implements Callback {
-
- @IntDef( {CONNECTION_ERROR, TEMPORARY_ERROR, PERMANENT_ERROR})
- @Retention(RetentionPolicy.SOURCE)
- @interface HttpError {
- }
-
- private static final int CONNECTION_ERROR = 0;
- private static final int TEMPORARY_ERROR = 1;
- private static final int PERMANENT_ERROR = 2;
-
- private static final ReentrantLock LOCK = new ReentrantLock();
- private static final OkHttpClient HTTP_CLIENT = new OkHttpClient();
-
- private static boolean logEnabled = true;
- private static String userAgentString;
-
- private long nativePtr;
- private Call call;
-
- private native void nativeOnFailure(@HttpError int type, String message);
-
- private native void nativeOnResponse(int code, String etag, String modified, String cacheControl, String expires,
- String retryAfter, String xRateLimitReset, byte[] body);
-
- private HttpRequest(long nativePtr, String resourceUrl, String etag, String modified) {
- this.nativePtr = nativePtr;
-
- try {
- // Don't try a request if we aren't connected
- if (!Mapbox.isConnected()) {
- throw new NoRouteToHostException("No Internet connection available.");
- }
-
- resourceUrl = adaptResourceUrl(resourceUrl);
- call = HTTP_CLIENT.newCall(buildRequest(resourceUrl, etag, modified));
- call.enqueue(this);
- } catch (Exception exception) {
- onFailure(exception);
- }
- }
-
- private String adaptResourceUrl(String resourceUrl) {
- HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
- if (httpUrl != null && isMapboxHost(httpUrl)) {
- HttpUrl.Builder builder = httpUrl.newBuilder();
- builder.addQueryParameter("events", "true");
- resourceUrl = builder.build().toString();
- }
- return resourceUrl;
- }
-
- private boolean isMapboxHost(@NonNull HttpUrl httpUrl) {
- final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
- return host.equals("mapbox.com") || host.endsWith(".mapbox.com")
- || host.equals("mapbox.cn") || host.endsWith(".mapbox.cn");
- }
-
- private Request buildRequest(String resourceUrl, String etag, String modified) {
- Request.Builder builder = new Request.Builder()
- .url(resourceUrl)
- .tag(resourceUrl.toLowerCase(MapboxConstants.MAPBOX_LOCALE))
- .addHeader("User-Agent", getUserAgentString());
- if (etag.length() > 0) {
- builder = builder.addHeader("If-None-Match", etag);
- } else if (modified.length() > 0) {
- builder = builder.addHeader("If-Modified-Since", modified);
- }
- return builder.build();
- }
-
- public void cancel() {
- // call can be null if the constructor gets aborted (e.g, under a NoRouteToHostException).
- if (call != null) {
- call.cancel();
- }
-
- // TODO: We need a LOCK here because we can try
- // to cancel at the same time the request is getting
- // answered on the OkHTTP thread. We could get rid of
- // this LOCK by using Runnable when we move Android
- // implementation of mbgl::RunLoop to Looper.
- LOCK.lock();
- nativePtr = 0;
- LOCK.unlock();
- }
-
- @Override
- public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
- if (logEnabled) {
- logOnResponse(response);
- }
-
- byte[] body;
- try {
- body = response.body().bytes();
- } catch (IOException ioException) {
- onFailure(ioException);
- return;
- } finally {
- response.body().close();
- }
-
- LOCK.lock();
- if (nativePtr != 0) {
- nativeOnResponse(response.code(),
- response.header("ETag"),
- response.header("Last-Modified"),
- response.header("Cache-Control"),
- response.header("Expires"),
- response.header("Retry-After"),
- response.header("x-rate-limit-reset"),
- body);
- }
- LOCK.unlock();
- }
-
- private void logOnResponse(Response response) {
- if (response.isSuccessful()) {
- Timber.v("[HTTP] Request was successful (code = %s).", response.code());
- } else if (logEnabled) {
- // We don't want to call this unsuccessful because a 304 isn't really an error
- String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
- Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
- }
- }
-
- @Override
- public void onFailure(@NonNull Call call, @NonNull IOException exception) {
- onFailure(exception);
- }
-
- private void onFailure(Exception exception) {
- int failType = resolveFailureType(exception);
- String errorMessage = exception.getMessage() != null ? exception.getMessage() : "Error processing the request";
- if (logEnabled) {
- logOnFailure(failType, errorMessage);
- }
-
- LOCK.lock();
- if (nativePtr != 0) {
- nativeOnFailure(failType, errorMessage);
- }
- LOCK.unlock();
- }
-
- @HttpError
- private int resolveFailureType(Exception exception) {
- int type = PERMANENT_ERROR;
- if ((exception instanceof NoRouteToHostException) || (exception instanceof UnknownHostException)
- || (exception instanceof SocketException) || (exception instanceof ProtocolException)
- || (exception instanceof SSLException)) {
- type = CONNECTION_ERROR;
- } else if ((exception instanceof InterruptedIOException)) {
- type = TEMPORARY_ERROR;
- }
- return type;
- }
-
- private void logOnFailure(@HttpError int type, String errorMessage) {
- if (type == TEMPORARY_ERROR) {
- Timber.d("Request failed due to a temporary error: %s", errorMessage);
- } else if (type == CONNECTION_ERROR) {
- Timber.i("Request failed due to a connection error: %s", errorMessage);
- } else {
- // PERMANENT_ERROR
- Timber.w("Request failed due to a permanent error: %s", errorMessage);
- }
- }
-
- private String getUserAgentString() {
- if (userAgentString == null) {
- userAgentString = Util.toHumanReadableAscii(
- String.format("%s %s (%s) Android/%s (%s)",
- getApplicationIdentifier(),
- BuildConfig.MAPBOX_VERSION_STRING,
- BuildConfig.GIT_REVISION_SHORT,
- Build.VERSION.SDK_INT,
- Build.CPU_ABI)
- );
- }
- return userAgentString;
- }
-
- private String getApplicationIdentifier() {
- try {
- Context context = Mapbox.getApplicationContext();
- PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
- return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
- } catch (Exception exception) {
- return "";
- }
- }
-
- static void enableLog(boolean enabled) {
- logEnabled = enabled;
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
deleted file mode 100644
index 46359572e6..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestUtil.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.mapbox.mapboxsdk.http;
-
-/**
- * Utility class for setting HttpRequest configurations
- */
-public class HttpRequestUtil {
-
- /**
- * Set the log state of HttpRequest.
- *
- * This configuration will outlast the lifecycle of the Map.
- *
- *
- * @param enabled True will enable logging, false will disable
- */
- public static void setLogEnabled(boolean enabled) {
- HttpRequest.enableLog(enabled);
- }
-}
--
cgit v1.2.1
From 8c020591de0f5129b9c9d6a99fcf47fdd61a2b0f Mon Sep 17 00:00:00 2001
From: Fabian Guerra
Date: Mon, 28 Aug 2017 15:18:20 -0400
Subject: [android] Diable lint check for MissingTranslation
---
platform/android/MapboxGLAndroidSDK/build.gradle | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 025097e756..c96587fce6 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -119,9 +119,10 @@ android {
}
lintOptions {
+ disable 'MissingTranslation', 'TypographyQuotes'
baseline file("lint-baseline-local.xml")
checkAllWarnings true
- warningsAsErrors true
+ warningsAsErrors false
}
testOptions {
--
cgit v1.2.1
From 2de89a99bc86776c8cadedc0ae9b344fb78b8217 Mon Sep 17 00:00:00 2001
From: Lauren Budorick
Date: Mon, 28 Aug 2017 13:32:56 -0700
Subject: Implement icon-anchor property
---
.../mapbox/mapboxsdk/style/layers/Property.java | 56 ++++++++++++++++++++++
.../mapboxsdk/style/layers/PropertyFactory.java | 23 +++++++++
.../mapbox/mapboxsdk/style/layers/SymbolLayer.java | 12 +++++
3 files changed, 91 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 be24b65d27..8d5858217b 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
@@ -160,6 +160,62 @@ public final class Property {
@Retention(RetentionPolicy.SOURCE)
public @interface ICON_TEXT_FIT {}
+ // ICON_ANCHOR: Part of the icon placed closest to the anchor.
+
+ /**
+ * The center of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_CENTER = "center";
+ /**
+ * The left side of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_LEFT = "left";
+ /**
+ * The right side of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_RIGHT = "right";
+ /**
+ * The top of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_TOP = "top";
+ /**
+ * The bottom of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_BOTTOM = "bottom";
+ /**
+ * The top left corner of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_TOP_LEFT = "top-left";
+ /**
+ * The top right corner of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_TOP_RIGHT = "top-right";
+ /**
+ * The bottom left corner of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_BOTTOM_LEFT = "bottom-left";
+ /**
+ * The bottom right corner of the icon is placed closest to the anchor.
+ */
+ public static final String ICON_ANCHOR_BOTTOM_RIGHT = "bottom-right";
+
+ /**
+ * Part of the icon placed closest to the anchor.
+ */
+ @StringDef({
+ ICON_ANCHOR_CENTER,
+ ICON_ANCHOR_LEFT,
+ ICON_ANCHOR_RIGHT,
+ ICON_ANCHOR_TOP,
+ ICON_ANCHOR_BOTTOM,
+ ICON_ANCHOR_TOP_LEFT,
+ ICON_ANCHOR_TOP_RIGHT,
+ ICON_ANCHOR_BOTTOM_LEFT,
+ ICON_ANCHOR_BOTTOM_RIGHT,
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ICON_ANCHOR {}
+
// ICON_PITCH_ALIGNMENT: Orientation of icon when map is pitched.
/**
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index ef89c6809e..3e90605a92 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -1881,6 +1881,29 @@ public class PropertyFactory {
return new LayoutPropertyValue<>("icon-offset", function);
}
+ /**
+ * Part of the icon placed closest to the anchor.
+ *
+ * @param value a String value
+ * @return property wrapper around String
+ */
+ public static PropertyValue iconAnchor(@Property.ICON_ANCHOR String value) {
+ return new LayoutPropertyValue<>("icon-anchor", value);
+ }
+
+
+
+ /**
+ * Part of the icon placed closest to the anchor.
+ *
+ * @param the function input type
+ * @param function a wrapper function for String
+ * @return property wrapper around a String function
+ */
+ public static PropertyValue> iconAnchor(Function function) {
+ return new LayoutPropertyValue<>("icon-anchor", function);
+ }
+
/**
* Orientation of icon when map is pitched.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
index fe81dcb638..d0fb82dce5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
@@ -251,6 +251,16 @@ public class SymbolLayer extends Layer {
return (PropertyValue) new PropertyValue("icon-offset", nativeGetIconOffset());
}
+ /**
+ * Get the IconAnchor property
+ *
+ * @return property wrapper value around String
+ */
+ @SuppressWarnings("unchecked")
+ public PropertyValue getIconAnchor() {
+ return (PropertyValue) new PropertyValue("icon-anchor", nativeGetIconAnchor());
+ }
+
/**
* Get the IconPitchAlignment property
*
@@ -901,6 +911,8 @@ public class SymbolLayer extends Layer {
private native Object nativeGetIconOffset();
+ private native Object nativeGetIconAnchor();
+
private native Object nativeGetIconPitchAlignment();
private native Object nativeGetTextPitchAlignment();
--
cgit v1.2.1
From dd18e1af1e8366bc3126cc897ae4b6d5890acd0b Mon Sep 17 00:00:00 2001
From: Fabian Guerra
Date: Mon, 28 Aug 2017 17:11:40 -0400
Subject: [android] Update sdk version.
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 389fcf275a..ff6e2f61df 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.1.3-SNAPSHOT
+VERSION_NAME=5.2.0-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
--
cgit v1.2.1
From 966bf8824d8d0a33bc0f99d4978a10126fc61b6a Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 22 Aug 2017 16:32:45 +0300
Subject: [android] map snapshotter
---
.../mapboxsdk/snapshotter/MapSnapshotter.java | 259 +++++++++++++++++++++
1 file changed, 259 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
new file mode 100644
index 0000000000..5db5f5f4b9
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -0,0 +1,259 @@
+package com.mapbox.mapboxsdk.snapshotter;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Canvas;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.UiThread;
+
+import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
+import com.mapbox.mapboxsdk.storage.FileSource;
+
+/**
+ * The map snapshotter creates a bitmap of the map, rendered
+ * off the UI thread. The snapshotter itself must be used on
+ * the UI thread (for access to the main looper)
+ */
+@UiThread
+public class MapSnapshotter {
+
+ /**
+ * Can be used to get notified of errors
+ * in snapshot generation
+ *
+ * @see MapSnapshotter#start(MapboxMap.SnapshotReadyCallback, ErrorHandler)
+ */
+ public static interface ErrorHandler {
+
+ /**
+ * Called on error. Snapshotting will not
+ * continue
+ *
+ * @param error the error message
+ */
+ void onError(String error);
+ }
+
+ private static final int LOGO_MARGIN_PX = 4;
+
+ // Holds the pointer to JNI NativeMapView
+ private long nativePtr = 0;
+
+ private final Context context;
+ private MapboxMap.SnapshotReadyCallback callback;
+ private ErrorHandler errorHandler;
+
+ /**
+ * MapSnapshotter options
+ */
+ public static class Options {
+ private int pixelRatio = 1;
+ private int width;
+ private int height;
+ private String styleUrl = Style.MAPBOX_STREETS;
+ private LatLngBounds region;
+ private CameraPosition cameraPosition;
+
+ /**
+ * @param width the width of the image
+ * @param height the height of the image
+ */
+ public Options(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * @param url The style URL to use
+ * @return the mutated {@link Options}
+ */
+ public Options withStyle(String url) {
+ this.styleUrl = url;
+ return this;
+ }
+
+ /**
+ * @param region the region to show in the snapshot.
+ * This is applied after the camera position
+ * @return the mutated {@link Options}
+ */
+ public Options withRegion(LatLngBounds region) {
+ this.region = region;
+ return this;
+ }
+
+ /**
+ * @param pixelRatio the pixel ratio to use (default: 1)
+ * @return the mutated {@link Options}
+ */
+ public Options withPixelRatio(int pixelRatio) {
+ this.pixelRatio = pixelRatio;
+ return this;
+ }
+
+ /**
+ * @param cameraPosition The camera position to use,
+ * the {@link CameraPosition#target} is overridden
+ * by region if set in conjunction.
+ * @return the mutated {@link Options}
+ */
+ public Options withCameraPosition(CameraPosition cameraPosition) {
+ this.cameraPosition = cameraPosition;
+ return this;
+ }
+
+ /**
+ * @return the width of the image
+ */
+ public int getWidth() {
+ return width;
+ }
+
+ /**
+ * @return the height of the image
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * @return the pixel ratio
+ */
+ public int getPixelRatio() {
+ return pixelRatio;
+ }
+
+ /**
+ * @return the region
+ */
+ @Nullable
+ public LatLngBounds getRegion() {
+ return region;
+ }
+
+ /**
+ * @return the style url
+ */
+ public String getStyleUrl() {
+ return styleUrl;
+ }
+
+ /**
+ * @return the camera position
+ */
+ @Nullable
+ public CameraPosition getCameraPosition() {
+ return cameraPosition;
+ }
+ }
+
+ /**
+ * Creates the Map snapshotter, but doesn't start rendering or
+ * loading yet.
+ *
+ * @param context the Context that is or contains the Application context
+ * @param options the options to use for the snapshot
+ */
+ public MapSnapshotter(@NonNull Context context, @NonNull Options options) {
+ this.context = context.getApplicationContext();
+ FileSource fileSource = FileSource.getInstance(context);
+ String programCacheDir = context.getCacheDir().getAbsolutePath();
+
+ nativeInitialize(this, fileSource, options.pixelRatio, options.width,
+ options.height, options.styleUrl, options.region, options.cameraPosition,
+ programCacheDir);
+ }
+
+ /**
+ * Starts loading and rendering the snapshot. The callback will be fired
+ * on the calling thread.
+ *
+ * @param callback the callback to use when the snapshot is ready
+ */
+ public void start(@NonNull MapboxMap.SnapshotReadyCallback callback) {
+ this.start(callback, null);
+ }
+
+ /**
+ * Starts loading and rendering the snapshot. The callbacks will be fired
+ * on the calling thread.
+ *
+ * @param callback the callback to use when the snapshot is ready
+ * @param errorHandler the error handler to use on snapshot errors
+ */
+ public void start(@NonNull MapboxMap.SnapshotReadyCallback callback, ErrorHandler errorHandler) {
+ if (this.callback != null) {
+ throw new IllegalStateException("Snapshotter was already started");
+ }
+
+ this.callback = callback;
+ nativeStart();
+ }
+
+ /**
+ * Must be called in on the thread
+ * the object was created on.
+ */
+ public void cancel() {
+ callback = null;
+ nativeCancel();
+ }
+
+ protected void addOverlay(Bitmap original) {
+ float margin = context.getResources().getDisplayMetrics().density * LOGO_MARGIN_PX;
+ Canvas canvas = new Canvas(original);
+ Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, null);
+ canvas.drawBitmap(logo, margin, original.getHeight() - (logo.getHeight() + margin), null);
+ }
+
+ /**
+ * Called by JNI peer when snapshot is ready.
+ * Always called on the origin (main) thread.
+ *
+ * @param bitmap the generated snapshot
+ */
+ protected void onSnapshotReady(Bitmap bitmap) {
+ if (callback != null) {
+ addOverlay(bitmap);
+ callback.onSnapshotReady(bitmap);
+ reset();
+ }
+ }
+
+ /**
+ * Called by JNI peer when snapshot has failed.
+ * Always called on the origin (main) thread.
+ *
+ * @param reason the exception string
+ */
+ protected void onSnapshotFailed(String reason) {
+ if (errorHandler != null) {
+ errorHandler.onError(reason);
+ reset();
+ }
+ }
+
+ protected void reset() {
+ callback = null;
+ errorHandler = null;
+ }
+
+ protected native void nativeInitialize(MapSnapshotter mapSnapshotter,
+ FileSource fileSource, float pixelRatio,
+ int width, int height, String styleUrl,
+ LatLngBounds region, CameraPosition position,
+ String programCacheDir);
+
+ protected native void nativeStart();
+
+ protected native void nativeCancel();
+
+ @Override
+ protected native void finalize() throws Throwable;
+}
--
cgit v1.2.1
From 69b52367d35616850b73b03f807ab5c0747c5187 Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Fri, 25 Aug 2017 16:11:24 -0700
Subject: [core][ios][macos][android]DDS-ify `text-letter-spacing` and
`text-max-width`
---
.../com/mapbox/mapboxsdk/style/layers/PropertyFactory.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
index 3e90605a92..d4ddbe48ef 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java
@@ -2057,11 +2057,11 @@ public class PropertyFactory {
/**
* The maximum line width for text wrapping.
*
- * @param the zoom parameter type
- * @param function a wrapper {@link CameraFunction} for Float
+ * @param the function input type
+ * @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
- public static PropertyValue> textMaxWidth(CameraFunction function) {
+ public static PropertyValue> textMaxWidth(Function function) {
return new LayoutPropertyValue<>("text-max-width", function);
}
@@ -2103,11 +2103,11 @@ public class PropertyFactory {
/**
* Text tracking amount.
*
- * @param the zoom parameter type
- * @param function a wrapper {@link CameraFunction} for Float
+ * @param the function input type
+ * @param function a wrapper function for Float
* @return property wrapper around a Float function
*/
- public static PropertyValue> textLetterSpacing(CameraFunction function) {
+ public static PropertyValue> textLetterSpacing(Function function) {
return new LayoutPropertyValue<>("text-letter-spacing", function);
}
--
cgit v1.2.1
From 9ce709908986967524ff734e89380c9854c43c1b Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 7 Sep 2017 17:26:26 +0200
Subject: [android] fix is download complete (a download is complete when count
and required resources match and the download state is inactive) (#9913)
---
.../src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.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/offline/OfflineRegionStatus.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
index fe12dd46c4..0f4b81fc39 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
@@ -80,7 +80,7 @@ public class OfflineRegionStatus {
* @return true if download is complete, false if not
*/
public boolean isComplete() {
- return (completedResourceCount == requiredResourceCount);
+ return (completedResourceCount == requiredResourceCount) && downloadState == OfflineRegion.STATE_INACTIVE;
}
/**
--
cgit v1.2.1
From a5bfb4ac40d94b63f1c9af11d9d25da64806fda1 Mon Sep 17 00:00:00 2001
From: Robin Darby
Date: Mon, 28 Aug 2017 15:02:44 -0600
Subject: [android] Clear out mapCallback's OnMapReadyCallbacks on onDestroy
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 cfe042d1f9..4d6189ddcf 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
@@ -296,6 +296,7 @@ public class MapView extends FrameLayout {
@UiThread
public void onDestroy() {
destroyed = true;
+ mapCallback.clearOnMapReadyCallbacks();
nativeMapView.destroy();
nativeMapView = null;
}
@@ -1014,5 +1015,9 @@ public class MapView extends FrameLayout {
void addOnMapReadyCallback(OnMapReadyCallback callback) {
onMapReadyCallbackList.add(callback);
}
+
+ void clearOnMapReadyCallbacks() {
+ onMapReadyCallbackList.clear();
+ }
}
}
--
cgit v1.2.1
From 738f68251a33f0ada108b7d723bc73406490e894 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 11 Sep 2017 14:05:41 +0200
Subject: [android] - avoid adding duplicate points to bounds
---
.../src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 8b2ccffef1..4fcb91033c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -450,7 +450,7 @@ public class LatLngBounds implements Parcelable {
*/
public Builder includes(List latLngs) {
for (LatLng point : latLngs) {
- latLngList.add(point);
+ include(point);
}
return this;
}
@@ -462,7 +462,9 @@ public class LatLngBounds implements Parcelable {
* @return this
*/
public Builder include(@NonNull LatLng latLng) {
- latLngList.add(latLng);
+ if (!latLngList.contains(latLng)) {
+ latLngList.add(latLng);
+ }
return this;
}
}
--
cgit v1.2.1
From 8e01f52dd212c57646a9b0fa1c65039a003b78cc Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 12 Sep 2017 09:34:09 +0200
Subject: [android] - don't recycle bitmap for icon reuse.
---
.../src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 affbf48267..b1d6df2103 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,7 +1,6 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.Bitmap;
-import android.os.Build;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Icon;
@@ -143,7 +142,7 @@ class IconManager {
}
}
- public void iconCleanup(Icon icon) {
+ void iconCleanup(Icon icon) {
int refCounter = iconMap.get(icon) - 1;
if (refCounter == 0) {
remove(icon);
@@ -155,18 +154,10 @@ class IconManager {
private void remove(Icon icon) {
nativeMapView.removeAnnotationIcon(icon.getId());
iconMap.remove(icon);
- if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- recycleBitmap(icon.getBitmap());
- }
}
private void updateIconRefCounter(Icon icon, int refCounter) {
iconMap.put(icon, refCounter);
}
- private void recycleBitmap(Bitmap bitmap) {
- if (!bitmap.isRecycled()) {
- bitmap.recycle();
- }
- }
}
--
cgit v1.2.1
From ef12dc082239ca42209483545edb017c799aea9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?=
Date: Tue, 12 Sep 2017 23:53:28 -0700
Subject: [android, ios, macos] Russian, Ukrainian, Hungarian and other
localization updates (#9945)
* [android, ios, macos] Updated Russian localization
Added a Russian localization of the Android SDK. Updated the iOS and macOS Russian localizations.
* [android, ios, macos] Updated Ukrainian localization
Added a Ukrainian localization of the Android SDK. Updated the iOS and macOS Ukrainian localizations.
* [ios, macos] Updated Traditional Chinese localization
* [macos] Added Hungarian localization
* [android] corrected typos
* [ios, macos] Updated Ukrainian localization
* [android, ios, macos] Configured Foundation.stringsdict on Transifex
* [ios, macos] Pulled in Foundation.stringsdict from Transifex
Updated the German, Lithuanian, and Vietnamese localizations with Foundation.stringsdict files matching Transifex.
---
.../MapboxGLAndroidSDK/src/main/res/values-ru/strings.xml | 15 +++++++++++++++
.../MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml | 15 +++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-ru/strings.xml
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-ru/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-ru/strings.xml
new file mode 100644
index 0000000000..39880d56ba
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-ru/strings.xml
@@ -0,0 +1,15 @@
+
+
+ Компас. Активируйте, чтобы повернуть карту на Север.
+ Иконка атрибутов. Активируйте, чтобы показать диалог.
+ Местоположение. Отображает ваше местоположение на карте.
+ Отображает карту, созданную при помощи Mapbox. Протисните при помощи двух пальцев. Приблизьте, соединением пальцев.
+ Mapbox Android SDK
+ Сделать карты Mapbox лучше
+ Вы помогаете сделать карты OpenStreetMap и Mapbox лучше путем предоставления анонимных данных об использовании.
+ Согласен
+ Не согласен
+ Дополнительная информация
+ Запрошенный OfflineRegionDefinition не входит в допустимые границы: %s
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml
new file mode 100644
index 0000000000..64c7e3efcc
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-uk/strings.xml
@@ -0,0 +1,15 @@
+
+
+ Компас. Натисніть щоб зорієнтувати мапу на північ.
+ Значок атрибуції. Натисніть, щоб показати діалог атрибуції.
+ Визначення положення. Показує ваше місцеположення на мапі.
+ Показує мапи створені за допомоги Mapbox. Пересувайте мапу двома пальцями. Змінюйте масштаб стуляючи/розводячи два пальці.
+ Mapbox Android SDK
+ Допоможіть зробити мапи Mapbox краще
+ Ви допомагаєте робити мапи OpenStreetMap та Mapbox краще пощирюючи анонімні дані про користування мапами.
+ Погоджуюсь
+ Не погоджуюсь
+ Додаткова інформація
+ Межі ділянки для оффлайнового користування даними за межами світу: %s
+
+
--
cgit v1.2.1
From 3f76907f92e2fff40c144e99da8e6fe6ec099a0c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 12 Sep 2017 11:26:41 +0200
Subject: [android] - bump proguard config for OkHttp 3.8.0
---
platform/android/MapboxGLAndroidSDK/proguard-rules.pro | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
index 68edc12f35..b5a1d82c81 100644
--- a/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
+++ b/platform/android/MapboxGLAndroidSDK/proguard-rules.pro
@@ -7,4 +7,9 @@
-keep interface com.mapbox.mapboxsdk.** { *; }
-keep class com.mapbox.services.android.telemetry.** { *; }
-keep class com.mapbox.services.commons.** { *;}
--keep class com.google.gson.** { *; }
\ No newline at end of file
+-keep class com.google.gson.** { *; }
+
+# config for okhttp 3.8.0, https://github.com/square/okhttp/pull/3354
+-dontwarn okio.**
+-dontwarn javax.annotation.Nullable
+-dontwarn javax.annotation.ParametersAreNonnullByDefault
\ No newline at end of file
--
cgit v1.2.1
From f0bf2c94aecf2a657d9338216a5ee9179270370a Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 12 Sep 2017 09:56:09 +0200
Subject: [android] - harden offline region deletion
---
.../src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(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 1b8c4121ef..f210729037 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
@@ -358,10 +358,10 @@ public class OfflineRegion {
*/
public void delete(@NonNull final OfflineRegionDeleteCallback callback) {
if (!isDeleted) {
+ isDeleted = true;
deleteOfflineRegion(new OfflineRegionDeleteCallback() {
@Override
public void onDelete() {
- isDeleted = true;
getHandler().post(new Runnable() {
@Override
public void run() {
@@ -376,6 +376,7 @@ public class OfflineRegion {
getHandler().post(new Runnable() {
@Override
public void run() {
+ isDeleted = false;
callback.onError(error);
}
});
--
cgit v1.2.1
From 5e63e5704a69bea9f82754fd9712b60246b11407 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Juszczyk?=
Date: Fri, 25 Aug 2017 14:45:07 +0200
Subject: Do not check connection if it is local request
Requests to servers which run on localhost should be independent from internet connection.
---
.../src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
index 91a235616a..e2626a026b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -56,13 +56,14 @@ class HTTPRequest implements Callback {
mNativePtr = nativePtr;
try {
- // Don't try a request if we aren't connected
- if (!Mapbox.isConnected()) {
+ HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
+ final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
+
+ // Don't try a request to remote server if we aren't connected
+ if (!Mapbox.isConnected() && !host.equals("127.0.0.1") && !host.equals("localhost")) {
throw new NoRouteToHostException("No Internet connection available.");
}
- HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
- final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
|| host.endsWith(".mapbox.cn")) {
if (httpUrl.querySize() == 0) {
--
cgit v1.2.1
From 2fcbd78062552a7fd4471bc0896b79f9888b91e8 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Wed, 20 Sep 2017 10:15:56 +0200
Subject: [android] hook camera events into compass (#10019)
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 62 ++++++++++++++++++---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 18 ++++++-
.../mapbox/mapboxsdk/maps/widgets/CompassView.java | 63 ++++++----------------
3 files changed, 90 insertions(+), 53 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 4d6189ddcf..149a9fbaa2 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
@@ -47,6 +47,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
import timber.log.Timber;
+import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
+import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
+
/**
*
* A {@code MapView} provides an embeddable map interface.
@@ -73,6 +76,7 @@ public class MapView extends FrameLayout {
private MyLocationView myLocationView;
private CompassView compassView;
+ private PointF focalPoint;
private ImageView attrView;
private ImageView logoView;
@@ -143,7 +147,7 @@ public class MapView extends FrameLayout {
addOnMapChangedListener(mapCallback);
// callback for focal point invalidation
- FocalPointInvalidator focalPoint = new FocalPointInvalidator(compassView);
+ final FocalPointInvalidator focalPointInvalidator = new FocalPointInvalidator(createFocalPointChangeListener());
// callback for registering touch listeners
RegisterTouchListener registerTouchListener = new RegisterTouchListener();
@@ -152,13 +156,15 @@ public class MapView extends FrameLayout {
CameraZoomInvalidator zoomInvalidator = new CameraZoomInvalidator();
// callback for camera change events
- CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher();
+ final CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher();
// setup components for MapboxMap creation
Projection proj = new Projection(nativeMapView);
- UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, logoView);
- TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPoint, zoomInvalidator);
- MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj, focalPoint);
+ UiSettings uiSettings = new UiSettings(proj, focalPointInvalidator, compassView, attrView, logoView);
+ TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointInvalidator,
+ zoomInvalidator);
+ MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, proj,
+ focalPointInvalidator);
LongSparseArray annotationsArray = new LongSparseArray<>();
MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer));
IconManager iconManager = new IconManager(nativeMapView);
@@ -182,8 +188,9 @@ public class MapView extends FrameLayout {
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
mapZoomButtonController.bind(uiSettings, zoomListener);
+ compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraChangeDispatcher));
+ compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher));
// inject widgets with MapboxMap
- compassView.setMapboxMap(mapboxMap);
myLocationView.setMapboxMap(mapboxMap);
attrView.setOnClickListener(new AttributionDialogManager(context, mapboxMap));
@@ -205,6 +212,49 @@ public class MapView extends FrameLayout {
}
}
+ private FocalPointChangeListener createFocalPointChangeListener() {
+ return new FocalPointChangeListener() {
+ @Override
+ public void onFocalPointChanged(PointF pointF) {
+ focalPoint = pointF;
+ }
+ };
+ }
+
+ private MapboxMap.OnCompassAnimationListener createCompassAnimationListener(final CameraChangeDispatcher
+ cameraChangeDispatcher) {
+ return new MapboxMap.OnCompassAnimationListener() {
+ @Override
+ public void onCompassAnimation() {
+ cameraChangeDispatcher.onCameraMove();
+ }
+
+ @Override
+ public void onCompassAnimationFinished() {
+ compassView.isAnimating(false);
+ cameraChangeDispatcher.onCameraIdle();
+ }
+ };
+ }
+
+ private OnClickListener createCompassClickListener(final CameraChangeDispatcher cameraChangeDispatcher) {
+ return new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mapboxMap != null && compassView != null) {
+ if (focalPoint != null) {
+ mapboxMap.setFocalBearing(0, focalPoint.x, focalPoint.y, TIME_MAP_NORTH_ANIMATION);
+ } else {
+ mapboxMap.setFocalBearing(0, mapboxMap.getWidth() / 2, mapboxMap.getHeight() / 2, TIME_MAP_NORTH_ANIMATION);
+ }
+ cameraChangeDispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_ANIMATION);
+ compassView.isAnimating(true);
+ compassView.postDelayed(compassView, TIME_WAIT_IDLE + TIME_MAP_NORTH_ANIMATION);
+ }
+ }
+ };
+ }
+
//
// Lifecycle events
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 0d1d0e03b5..6c7670b91c 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
@@ -513,8 +513,9 @@ public final class MapboxMap {
* Sets the maximum zoom level the map can be displayed at.
*
*
- * The default maximum zoomn level is 22. The upper bound for this value is 25.5.
+ * The default maximum zoomn level is 22. The upper bound for this value is 25.5.
*
+ *
* @param maxZoom The new maximum zoom level.
*/
public void setMaxZoomPreference(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
@@ -2081,6 +2082,21 @@ public final class MapboxMap {
void onCameraIdle();
}
+ /**
+ * Interface definition for a callback to be invoked for when the compass is animating.
+ */
+ public interface OnCompassAnimationListener {
+ /**
+ * Called repeatedly as the compass continues to move after clicking on it.
+ */
+ void onCompassAnimation();
+
+ /**
+ * Called when compass animation has ended.
+ */
+ void onCompassAnimationFinished();
+ }
+
/**
* 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/widgets/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
index 2b327409ae..45f72af1c5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
@@ -1,10 +1,8 @@
package com.mapbox.mapboxsdk.maps.widgets;
import android.content.Context;
-import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
@@ -13,11 +11,8 @@ import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
-import com.mapbox.mapboxsdk.maps.FocalPointChangeListener;
import com.mapbox.mapboxsdk.maps.MapboxMap;
-import java.lang.ref.WeakReference;
-
/**
* UI element overlaid on a map to show the map's bearing when it isn't true north (0.0). Tapping
* the compass resets the bearing to true north and hides the compass.
@@ -27,16 +22,17 @@ import java.lang.ref.WeakReference;
* use {@link com.mapbox.mapboxsdk.maps.UiSettings}.
*
*/
-public final class CompassView extends AppCompatImageView implements Runnable, FocalPointChangeListener {
+public final class CompassView extends AppCompatImageView implements Runnable {
- private static final long TIME_WAIT_IDLE = 500;
+ public static final long TIME_WAIT_IDLE = 500;
+ public static final long TIME_MAP_NORTH_ANIMATION = 150;
private static final long TIME_FADE_ANIMATION = TIME_WAIT_IDLE;
- private static final long TIME_MAP_NORTH_ANIMATION = 150;
private float rotation = 0.0f;
private boolean fadeCompassViewFacingNorth = true;
private ViewPropertyAnimatorCompat fadeAnimator;
- private PointF focalPoint;
+ private MapboxMap.OnCompassAnimationListener compassAnimationListener;
+ private boolean isAnimating = false;
public CompassView(Context context) {
super(context);
@@ -62,9 +58,12 @@ public final class CompassView extends AppCompatImageView implements Runnable, F
setLayoutParams(lp);
}
- // TODO refactor MapboxMap and replace with interface
- public void setMapboxMap(@NonNull MapboxMap mapboxMap) {
- setOnClickListener(new CompassClickListener(mapboxMap, this));
+ public void injectCompassAnimationListener(@NonNull MapboxMap.OnCompassAnimationListener compassAnimationListener) {
+ this.compassAnimationListener = compassAnimationListener;
+ }
+
+ public void isAnimating(boolean isAnimating) {
+ this.isAnimating = isAnimating;
}
private void resetAnimation() {
@@ -97,11 +96,6 @@ public final class CompassView extends AppCompatImageView implements Runnable, F
}
}
- @Nullable
- PointF getFocalPoint() {
- return focalPoint;
- }
-
/**
* Updates the direction of the compass.
*
@@ -126,6 +120,7 @@ public final class CompassView extends AppCompatImageView implements Runnable, F
setVisibility(View.VISIBLE);
}
+ notifyCompassAnimationListenerWhenAnimating();
setRotation(rotation);
}
@@ -157,7 +152,8 @@ public final class CompassView extends AppCompatImageView implements Runnable, F
@Override
public void run() {
- if (isFacingNorth() && fadeCompassViewFacingNorth) {
+ if (isHidden()) {
+ compassAnimationListener.onCompassAnimationFinished();
resetAnimation();
setLayerType(View.LAYER_TYPE_HARDWARE, null);
fadeAnimator = ViewCompat.animate(CompassView.this).alpha(0.0f).setDuration(TIME_FADE_ANIMATION);
@@ -172,34 +168,9 @@ public final class CompassView extends AppCompatImageView implements Runnable, F
}
}
- @Override
- public void onFocalPointChanged(PointF pointF) {
- focalPoint = pointF;
- }
-
- static class CompassClickListener implements View.OnClickListener {
-
- private WeakReference mapboxMap;
- private WeakReference compassView;
-
- CompassClickListener(final MapboxMap mapboxMap, CompassView compassView) {
- this.mapboxMap = new WeakReference<>(mapboxMap);
- this.compassView = new WeakReference<>(compassView);
- }
-
- @Override
- public void onClick(View view) {
- final MapboxMap mapboxMap = this.mapboxMap.get();
- final CompassView compassView = this.compassView.get();
- if (mapboxMap != null && compassView != null) {
- PointF focalPoint = compassView.getFocalPoint();
- if (focalPoint != null) {
- mapboxMap.setFocalBearing(0, focalPoint.x, focalPoint.y, TIME_MAP_NORTH_ANIMATION);
- } else {
- mapboxMap.setFocalBearing(0, mapboxMap.getWidth() / 2, mapboxMap.getHeight() / 2, TIME_MAP_NORTH_ANIMATION);
- }
- compassView.postDelayed(compassView, TIME_WAIT_IDLE + TIME_MAP_NORTH_ANIMATION);
- }
+ private void notifyCompassAnimationListenerWhenAnimating() {
+ if (isAnimating) {
+ compassAnimationListener.onCompassAnimation();
}
}
}
--
cgit v1.2.1
From c9cb4ef6248cfd2f562b0931d9dc93e4f7088b51 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 21 Sep 2017 09:59:05 +0200
Subject: [android] - set error handler when starting snapshotter, remove
obsolete static keyword on interface
---
.../src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 5db5f5f4b9..72df86d80d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -29,7 +29,7 @@ public class MapSnapshotter {
*
* @see MapSnapshotter#start(MapboxMap.SnapshotReadyCallback, ErrorHandler)
*/
- public static interface ErrorHandler {
+ public interface ErrorHandler {
/**
* Called on error. Snapshotting will not
@@ -193,6 +193,7 @@ public class MapSnapshotter {
}
this.callback = callback;
+ this.errorHandler = errorHandler;
nativeStart();
}
--
cgit v1.2.1
From 453c13dee2a3678ea3d3ceda204c7cf23d431c78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?=
Date: Wed, 20 Sep 2017 09:55:58 -0700
Subject: [android, ios, macos] Updated translations
Updated Catalan, Spanish, Swedish, Traditional Chinese, Ukrainian, and Vietnamese.
---
.../MapboxGLAndroidSDK/src/main/res/values-ca/strings.xml | 11 ++++++-----
.../MapboxGLAndroidSDK/src/main/res/values-nl/strings.xml | 3 ++-
2 files changed, 8 insertions(+), 6 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-ca/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-ca/strings.xml
index 34e9914e46..6ed788d1dc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-ca/strings.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-ca/strings.xml
@@ -1,14 +1,15 @@
Brúixola del mapa. Activa per restablir la rotació del mapa al Nord.
- Icona d\'atribució. Activa per mostrar el diàleg de l\'atribució.
+ Icona d’atribució. Activa per mostrar el diàleg de l’atribució.Vista de posició. Mostra la teva posició al mapa.
- Mostrant un mapa creat amb Mapbox. Desplaça\'t arrossegant amb dos dits. Fes zoom pessigant amb dos dits.
+ Mostrant un mapa creat amb Mapbox. Desplaça’t arrossegant amb dos dits. Fes zoom pessigant amb dos dits.Mapbox Android SDKMillora els mapes de Mapbox
- Estàs ajudant a millorar els mapes d\'OpenStreetMap i de Mapbox aportant dades d\'ús anònimes.
- D\'acord
+ Estàs ajudant a millorar els mapes d’OpenStreetMap i de Mapbox aportant dades d’ús anònimes.
+ D’acordDisconformeMés informacióLa OfflineRegionDefinition proporcionada no encaixa amb els límits del món: %s
-
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-nl/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-nl/strings.xml
index fef652c542..f1fcf837ea 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-nl/strings.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-nl/strings.xml
@@ -11,4 +11,5 @@
IntrekkenMeer informatieAangeleverde OfflineRegionDefinition past niet in de wereld omtrek: %s
-
+
+
--
cgit v1.2.1
From c0544d85008fb393ce9c8f29fb9b20e71d057b9e Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 18 Jul 2017 19:14:40 +0200
Subject: [android] remove texture view
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 18 ++++-------
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 36 ++--------------------
.../src/main/res-public/values/public.xml | 3 --
.../src/main/res/values/attrs.xml | 3 --
4 files changed, 8 insertions(+), 52 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 149a9fbaa2..4d2019d68b 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
@@ -137,7 +137,7 @@ public class MapView extends FrameLayout {
} else {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
- initialiseDrawingSurface(mapboxMapOptions);
+ initialiseDrawingSurface();
}
});
}
@@ -279,17 +279,11 @@ public class MapView extends FrameLayout {
}
}
- private void initialiseDrawingSurface(MapboxMapOptions mapboxMapOptions) {
- if (mapboxMapOptions.getTextureMode()) {
- TextureView textureView = new TextureView(getContext());
- textureView.setSurfaceTextureListener(new SurfaceTextureListener());
- addView(textureView, 0);
- } else {
- SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
- surfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
- surfaceView.getHolder().addCallback(new SurfaceCallback());
- surfaceView.setVisibility(View.VISIBLE);
- }
+ private void initialiseDrawingSurface() {
+ SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
+ surfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
+ surfaceView.getHolder().addCallback(new SurfaceCallback());
+ surfaceView.setVisibility(View.VISIBLE);
}
/**
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 94e2fbcf3b..7b979f5563 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
@@ -85,9 +85,6 @@ public class MapboxMapOptions implements Parcelable {
private String apiBaseUrl;
- @Deprecated
- private boolean textureMode;
-
private String style;
/**
@@ -155,7 +152,7 @@ public class MapboxMapOptions implements Parcelable {
style = in.readString();
apiBaseUrl = in.readString();
- textureMode = in.readByte() != 0;
+
prefetchesTiles = in.readByte() != 0;
zMediaOverlay = in.readByte() != 0;
}
@@ -299,8 +296,6 @@ public class MapboxMapOptions implements Parcelable {
ColorUtils.getPrimaryColor(context)));
mapboxMapOptions.myLocationAccuracyThreshold(
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
- mapboxMapOptions.textureMode(
- typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
mapboxMapOptions.setPrefetchesTiles(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
mapboxMapOptions.renderSurfaceOnTop(
@@ -703,22 +698,6 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
- /**
- * Enable TextureView as rendered surface.
- *
- * Since the 4.2.0 release we replaced our TextureView with an SurfaceView implemenation.
- * Enabling this option will use the deprecated TextureView instead.
- *
- *
- * @param textureMode True to enable texture mode
- * @return This
- * @deprecated As of the 4.2.0 release, using TextureView is deprecated.
- */
- public MapboxMapOptions textureMode(boolean textureMode) {
- this.textureMode = textureMode;
- return this;
- }
-
/**
* Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
* a low resolution preview while more detailed tiles are loaded.
@@ -1070,16 +1049,6 @@ public class MapboxMapOptions implements Parcelable {
return debugActive;
}
- /**
- * Returns true if TextureView is being used a render view.
- *
- * @return True if TextureView is used.
- * @deprecated As of the 4.2.0 release, using TextureView is deprecated.
- */
- public boolean getTextureMode() {
- return textureMode;
- }
-
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
@@ -1143,7 +1112,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeString(style);
dest.writeString(apiBaseUrl);
- dest.writeByte((byte) (textureMode ? 1 : 0));
+
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
}
@@ -1320,7 +1289,6 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (myLocationAccuracyThreshold != +0.0f
? Float.floatToIntBits(myLocationAccuracyThreshold) : 0);
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
- result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
result = 31 * result + (zMediaOverlay ? 1 : 0);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index d59eef7427..40045f851f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -72,9 +72,6 @@
-
-
-
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index 281fe8afe3..b673224094 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -114,9 +114,6 @@
-
-
-
--
cgit v1.2.1
From 347d7c19c0a70f91252163b14e37583eea83fdd5 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Fri, 21 Jul 2017 16:15:30 +0300
Subject: [android] async rendering
- introduces GLSurfaceView
- introduces Orchestration thread
- renders on the gl thread
---
.../com/mapbox/mapboxsdk/egl/EGLConfigChooser.java | 293 +++++++++++++++++++++
.../mapbox/mapboxsdk/egl/EGLConfigException.java | 21 ++
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 179 ++++---------
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 51 ++--
.../java/com/mapbox/mapboxsdk/utils/Compare.java | 27 ++
.../main/res/layout/mapbox_mapview_internal.xml | 2 +-
6 files changed, 426 insertions(+), 147 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/Compare.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
new file mode 100644
index 0000000000..7fc70716da
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
@@ -0,0 +1,293 @@
+package com.mapbox.mapboxsdk.egl;
+
+import android.opengl.GLSurfaceView;
+import android.support.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLDisplay;
+
+import timber.log.Timber;
+
+import static com.mapbox.mapboxsdk.utils.Compare.compare;
+import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_MASK_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_BLUE_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_BUFFER_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_COLOR_BUFFER_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_CONFIG_CAVEAT;
+import static javax.microedition.khronos.egl.EGL10.EGL_DEPTH_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_GREEN_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_NONE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RED_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RENDERABLE_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RGB_BUFFER;
+import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLES;
+import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLE_BUFFERS;
+import static javax.microedition.khronos.egl.EGL10.EGL_STENCIL_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_SURFACE_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_WINDOW_BIT;
+
+/**
+ * Selects the right EGLConfig needed for `mapbox-gl-native`
+ */
+public class EGLConfigChooser implements GLSurfaceView.EGLConfigChooser {
+
+ /**
+ * Requires API level 17
+ *
+ * @see android.opengl.EGL14.EGL_CONFORMANT;
+ */
+ @SuppressWarnings("JavadocReference")
+ private static final int EGL_CONFORMANT = 0x3042;
+
+ /**
+ * Requires API level 17
+ *
+ * @see android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
+ */
+ @SuppressWarnings("JavadocReference")
+ private static final int EGL_OPENGL_ES2_BIT = 0x0004;
+
+ @Override
+ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
+ int[] configAttribs = getConfigAttributes();
+
+ // Determine number of possible configurations
+ int[] numConfigs = getNumberOfConfigurations(egl, display, configAttribs);
+ if (numConfigs[0] < 1) {
+ Timber.e("eglChooseConfig() returned no configs.");
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+
+ // Get all possible configurations
+ EGLConfig[] possibleConfigurations = getPossibleConfigurations(egl, display, configAttribs, numConfigs);
+
+ // Choose best match
+ EGLConfig config = chooseBestMatchConfig(egl, display, possibleConfigurations);
+ if (config == null) {
+ Timber.e("No config chosen");
+ throw new EGLConfigException("No config chosen");
+ }
+
+ return config;
+ }
+
+ private int[] getNumberOfConfigurations(EGL10 egl, EGLDisplay display, int[] configAttributes) {
+ int[] numConfigs = new int[1];
+ if (!egl.eglChooseConfig(display, configAttributes, null, 0, numConfigs)) {
+ Timber.e("eglChooseConfig(NULL) returned error %d", egl.eglGetError());
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+ return numConfigs;
+ }
+
+ private EGLConfig[] getPossibleConfigurations(EGL10 egl, EGLDisplay display,
+ int[] configAttributes, int[] numConfigs) {
+ EGLConfig[] configs = new EGLConfig[numConfigs[0]];
+ if (!egl.eglChooseConfig(display, configAttributes, configs, numConfigs[0], numConfigs)) {
+ Timber.e("eglChooseConfig() returned error %d", egl.eglGetError());
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+ return configs;
+ }
+
+ // Quality
+ enum BufferFormat {
+ Format16Bit(3),
+ Format32BitNoAlpha(1),
+ Format32BitAlpha(2),
+ Format24Bit(0),
+ Unknown(4);
+
+ int value;
+
+ BufferFormat(int value) {
+ this.value = value;
+ }
+ }
+
+ enum DepthStencilFormat {
+ Format16Depth8Stencil(1),
+ Format24Depth8Stencil(0);
+
+ int value;
+
+ DepthStencilFormat(int value) {
+ this.value = value;
+ }
+ }
+
+ private EGLConfig chooseBestMatchConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ class Config implements Comparable {
+ private final BufferFormat bufferFormat;
+ private final DepthStencilFormat depthStencilFormat;
+ private final boolean isNotConformant;
+ private final boolean isCaveat;
+ private final int index;
+ private final EGLConfig config;
+
+ public Config(BufferFormat bufferFormat, DepthStencilFormat depthStencilFormat,
+ boolean isNotConformant, boolean isCaveat, int index, EGLConfig config) {
+ this.bufferFormat = bufferFormat;
+ this.depthStencilFormat = depthStencilFormat;
+ this.isNotConformant = isNotConformant;
+ this.isCaveat = isCaveat;
+ this.index = index;
+ this.config = config;
+ }
+
+
+ @Override
+ public int compareTo(@NonNull Config other) {
+ int i = compare(bufferFormat.value, other.bufferFormat.value);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(depthStencilFormat.value, other.depthStencilFormat.value);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(isNotConformant, other.isNotConformant);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(isCaveat, other.isCaveat);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(index, other.index);
+ if (i != 0) {
+ return i;
+ }
+
+ return 0;
+ }
+ }
+
+ List matches = new ArrayList<>();
+
+ int i = 0;
+ for (EGLConfig config : configs) {
+ i++;
+
+ int caveat = getConfigAttr(egl, display, config, EGL_CONFIG_CAVEAT);
+ int conformant = getConfigAttr(egl, display, config, EGL_CONFORMANT);
+ int bits = getConfigAttr(egl, display, config, EGL_BUFFER_SIZE);
+ int red = getConfigAttr(egl, display, config, EGL_RED_SIZE);
+ int green = getConfigAttr(egl, display, config, EGL_GREEN_SIZE);
+ int blue = getConfigAttr(egl, display, config, EGL_BLUE_SIZE);
+ int alpha = getConfigAttr(egl, display, config, EGL_ALPHA_SIZE);
+ int alphaMask = getConfigAttr(egl, display, config, EGL_ALPHA_MASK_SIZE);
+ int depth = getConfigAttr(egl, display, config, EGL_DEPTH_SIZE);
+ int stencil = getConfigAttr(egl, display, config, EGL_STENCIL_SIZE);
+ int sampleBuffers = getConfigAttr(egl, display, config, EGL_SAMPLE_BUFFERS);
+ int samples = getConfigAttr(egl, display, config, EGL_SAMPLES);
+
+ boolean configOk = (depth == 24) || (depth == 16);
+ configOk &= stencil == 8;
+ configOk &= sampleBuffers == 0;
+ configOk &= samples == 0;
+
+ // Filter our configs first for depth, stencil and anti-aliasing
+ if (configOk) {
+ // Work out the config's buffer format
+ BufferFormat bufferFormat;
+ if ((bits == 16) && (red == 5) && (green == 6) && (blue == 5) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format16Bit;
+ } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format32BitNoAlpha;
+ } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 8)) {
+ bufferFormat = BufferFormat.Format32BitAlpha;
+ } else if ((bits == 24) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format24Bit;
+ } else {
+ bufferFormat = BufferFormat.Unknown;
+ }
+
+ // Work out the config's depth stencil format
+ DepthStencilFormat depthStencilFormat;
+ if ((depth == 16) && (stencil == 8)) {
+ depthStencilFormat = DepthStencilFormat.Format16Depth8Stencil;
+ } else {
+ depthStencilFormat = DepthStencilFormat.Format24Depth8Stencil;
+ }
+
+ boolean isNotConformant = (conformant & EGL_OPENGL_ES2_BIT) != EGL_OPENGL_ES2_BIT;
+ boolean isCaveat = caveat != EGL_NONE;
+
+ // Ignore formats we don't recognise
+ if (bufferFormat != BufferFormat.Unknown) {
+ matches.add(new Config(bufferFormat, depthStencilFormat, isNotConformant, isCaveat, i, config));
+ }
+ }
+
+ }
+
+ // Sort
+ Collections.sort(matches);
+
+ if (matches.size() == 0) {
+ throw new EGLConfigException("No matching configurations after filtering");
+ }
+
+ Config bestMatch = matches.get(0);
+
+ if (bestMatch.isCaveat) {
+ Timber.w("Chosen config has a caveat.");
+ }
+
+ if (bestMatch.isNotConformant) {
+ Timber.w("Chosen config is not conformant.");
+ }
+
+ return bestMatch.config;
+ }
+
+ private int getConfigAttr(EGL10 egl, EGLDisplay display, EGLConfig config, int attributeName) {
+ int[] attributevalue = new int[1];
+ if (!egl.eglGetConfigAttrib(display, config, attributeName, attributevalue)) {
+ Timber.e("eglGetConfigAttrib(%d) returned error %d", attributeName, egl.eglGetError());
+ throw new EGLConfigException("eglGetConfigAttrib() failed");
+ }
+ return attributevalue[0];
+ }
+
+
+ private int[] getConfigAttributes() {
+ boolean emulator = inEmulator();
+ Timber.i("In emulator: %s", emulator);
+
+ // Get all configs at least RGB 565 with 16 depth and 8 stencil
+ return new int[] {
+ EGL_CONFIG_CAVEAT, EGL_NONE,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_BUFFER_SIZE, 16,
+ EGL_RED_SIZE, 5,
+ EGL_GREEN_SIZE, 6,
+ EGL_BLUE_SIZE, 5,
+ EGL_ALPHA_SIZE, 0,
+ EGL_DEPTH_SIZE, 16,
+ EGL_STENCIL_SIZE, 8,
+ (emulator ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT,
+ (emulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+ }
+
+ /**
+ * Detect if we are in emulator.
+ */
+ private boolean inEmulator() {
+ return System.getProperty("ro.kernel.qemu") != null;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
new file mode 100644
index 0000000000..3f576d0eda
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
@@ -0,0 +1,21 @@
+package com.mapbox.mapboxsdk.egl;
+
+/**
+ * Used for EGL configuration exceptions
+ */
+public class EGLConfigException extends RuntimeException {
+ public EGLConfigException() {
+ }
+
+ public EGLConfigException(String message) {
+ super(message);
+ }
+
+ public EGLConfigException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public EGLConfigException(Throwable cause) {
+ super(cause);
+ }
+}
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 4d2019d68b..a920bed720 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
@@ -1,10 +1,9 @@
package com.mapbox.mapboxsdk.maps;
import android.content.Context;
-import android.graphics.Canvas;
import android.graphics.PointF;
-import android.graphics.SurfaceTexture;
import android.os.Build;
+import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
@@ -16,10 +15,6 @@ import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -32,6 +27,7 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
@@ -45,10 +41,14 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
import timber.log.Timber;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
+import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
/**
*
@@ -72,7 +72,6 @@ public class MapView extends FrameLayout {
private NativeMapView nativeMapView;
private MapboxMapOptions mapboxMapOptions;
private boolean destroyed;
- private boolean hasSurface;
private MyLocationView myLocationView;
private CompassView compassView;
@@ -86,6 +85,8 @@ public class MapView extends FrameLayout {
private Bundle savedInstanceState;
private final CopyOnWriteArrayList onMapChangedListeners = new CopyOnWriteArrayList<>();
+ private GLSurfaceView glSurfaceView;
+
@UiThread
public MapView(@NonNull Context context) {
super(context);
@@ -280,10 +281,37 @@ public class MapView extends FrameLayout {
}
private void initialiseDrawingSurface() {
- SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
- surfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
- surfaceView.getHolder().addCallback(new SurfaceCallback());
- surfaceView.setVisibility(View.VISIBLE);
+ glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
+ glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
+ glSurfaceView.setEGLContextClientVersion(2);
+ glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
+ glSurfaceView.setRenderer(new GLSurfaceView.Renderer() {
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ MapView.this.post(new Runnable() {
+ @Override
+ public void run() {
+ initialiseMap();
+ mapboxMap.onStart();
+ }
+ });
+
+ nativeMapView.onSurfaceCreated(gl, config);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ nativeMapView.onSurfaceChanged(gl, width, height);
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ nativeMapView.onDrawFrame(gl);
+ }
+ });
+ glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
+ glSurfaceView.setVisibility(View.VISIBLE);
}
/**
@@ -314,7 +342,9 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onResume() {
- // replaced by onStart in v5.0.0
+ if (glSurfaceView != null) {
+ glSurfaceView.onResume();
+ }
}
/**
@@ -322,7 +352,9 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onPause() {
- // replaced by onStop in v5.0.0
+ if (glSurfaceView != null) {
+ glSurfaceView.onPause();
+ }
}
/**
@@ -465,24 +497,10 @@ public class MapView extends FrameLayout {
// Called when the map needs to be rerendered
// Called via JNI from NativeMapView
protected void onInvalidate() {
- postInvalidate();
- }
-
- @Override
- public void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- if (isInEditMode()) {
- return;
+ if (glSurfaceView != null) {
+ glSurfaceView.requestRender();
}
-
- if (destroyed) {
- return;
- }
-
- if (!hasSurface) {
- return;
- }
- nativeMapView.render();
+ // TODO: removable? postInvalidate();
}
@Override
@@ -496,103 +514,6 @@ public class MapView extends FrameLayout {
}
}
- private class SurfaceCallback implements SurfaceHolder.Callback {
-
- private Surface surface;
-
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- if (nativeMapView == null) {
- nativeMapView = new NativeMapView(MapView.this);
- nativeMapView.createSurface(surface = holder.getSurface());
- nativeMapView.resizeView(getWidth(), getHeight());
- initialiseMap();
- mapboxMap.onStart();
- } else {
- nativeMapView.createSurface(surface = holder.getSurface());
- }
-
- hasSurface = true;
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- if (destroyed) {
- return;
- }
- nativeMapView.resizeFramebuffer(width, height);
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- hasSurface = false;
-
- if (nativeMapView != null) {
- // occurs when activity goes to background
- nativeMapView.destroySurface();
- }
- surface.release();
- }
- }
-
- // This class handles TextureView callbacks
- private class SurfaceTextureListener implements TextureView.SurfaceTextureListener {
-
- private Surface surface;
-
- // Called when the native surface texture has been created
- // Must do all EGL/GL ES initialization here
- @Override
- public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
- if (nativeMapView == null) {
- nativeMapView = new NativeMapView(MapView.this);
- nativeMapView.createSurface(this.surface = new Surface(surface));
- nativeMapView.resizeFramebuffer(width, height);
- nativeMapView.resizeView(width, height);
- initialiseMap();
- mapboxMap.onStart();
- } else {
- nativeMapView.createSurface(this.surface = new Surface(surface));
- }
-
- hasSurface = true;
- }
-
- // Called when the native surface texture has been destroyed
- // Must do all EGL/GL ES destruction here
- @Override
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
- hasSurface = false;
-
- if (nativeMapView != null) {
- nativeMapView.destroySurface();
- }
- this.surface.release();
- return true;
- }
-
- // Called when the format or size of the native surface texture has been changed
- // Must handle window resizing here.
- @Override
- public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
- if (destroyed) {
- return;
- }
-
- nativeMapView.resizeFramebuffer(width, height);
- }
-
- // Called when the SurfaceTexure frame is drawn to screen
- // Must sync with UI here
- @Override
- public void onSurfaceTextureUpdated(SurfaceTexture surface) {
- if (destroyed) {
- return;
- }
- mapboxMap.onUpdateRegionChange();
- }
- }
-
//
// View events
//
@@ -612,7 +533,9 @@ public class MapView extends FrameLayout {
return;
}
- if (nativeMapView != null) {
+ if (nativeMapView == null) {
+ nativeMapView = new NativeMapView(this);
+ } else if (mapZoomButtonController != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
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 4f5037e4b3..a97b7cc8f2 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
@@ -4,12 +4,12 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
+import android.opengl.GLSurfaceView;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
-import android.view.Surface;
import com.mapbox.mapboxsdk.LibraryLoader;
import com.mapbox.mapboxsdk.annotations.Icon;
@@ -35,10 +35,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
import timber.log.Timber;
// Class that wraps the native methods for convenience
-final class NativeMapView {
+final class NativeMapView implements GLSurfaceView.Renderer {
// Flag to indicating destroy was called
private boolean destroyed = false;
@@ -97,20 +100,6 @@ final class NativeMapView {
destroyed = true;
}
- public void createSurface(Surface surface) {
- if (isDestroyedOn("createSurface")) {
- return;
- }
- nativeCreateSurface(surface);
- }
-
- public void destroySurface() {
- if (isDestroyedOn("destroySurface")) {
- return;
- }
- nativeDestroySurface();
- }
-
public void update() {
if (isDestroyedOn("update")) {
return;
@@ -156,7 +145,7 @@ final class NativeMapView {
nativeResizeView(width, height);
}
- public void resizeFramebuffer(int fbWidth, int fbHeight) {
+ private void resizeFramebuffer(int fbWidth, int fbHeight) {
if (isDestroyedOn("resizeFramebuffer")) {
return;
}
@@ -1141,6 +1130,32 @@ final class NativeMapView {
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
snapshotReadyCallback = callback;
scheduleTakeSnapshot();
- render();
+ mapView.onInvalidate();
+ // TODO. this should do a request render
+ //render();
+ }
+
+ //
+ // GLSurfaceView.Renderer
+ //
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ Timber.i("[%s] onSurfaceCreated", Thread.currentThread().getName());
+ //TODO: callback to map to re-create renderer?
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ Timber.i("[%s] onSurfaceChanged %sx%s", Thread.currentThread().getName(), width, height);
+ // Sets the current view port to the new size.
+ gl.glViewport(0, 0, width, height);
+ resizeFramebuffer(width, height);
+ // resizeView(width, height); Done from MapView#onSizeChanged
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ nativeRender();
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/Compare.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/Compare.java
new file mode 100644
index 0000000000..c7d7a13a3d
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/Compare.java
@@ -0,0 +1,27 @@
+package com.mapbox.mapboxsdk.utils;
+
+/**
+ * Comparisons from std sdk, which aren't available in API level <= 15
+ */
+public class Compare {
+
+ /**
+ * @see Integer#compare(int, int)
+ * @param x left side
+ * @param y right side
+ * @return std compare value
+ */
+ public static int compare(int x, int y) {
+ return (x < y) ? -1 : ((x == y) ? 0 : 1);
+ }
+
+ /**
+ * @see Boolean#compare(boolean, boolean)
+ * @param x left side
+ * @param y right side
+ * @return std compare value
+ */
+ public static int compare(boolean x, boolean y) {
+ return (x == y) ? 0 : (x ? 1 : -1);
+ }
+}
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 6d07de7baa..e2f1823327 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
@@ -1,7 +1,7 @@
-
Date: Mon, 11 Sep 2017 11:04:53 +0300
Subject: [android] schedule work on the gl thread using
GLSurfaceView#queueEvent
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 12 ++----
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 44 ++++++++++++++++++----
.../maps/renderer/GlSurfaceViewRenderThread.java | 25 ++++++++++++
.../mapboxsdk/maps/renderer/RenderThread.java | 12 ++++++
4 files changed, 76 insertions(+), 17 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 a920bed720..086f57abf6 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
@@ -28,6 +28,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
+import com.mapbox.mapboxsdk.maps.renderer.GlSurfaceViewRenderThread;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
@@ -312,6 +313,8 @@ public class MapView extends FrameLayout {
});
glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
glSurfaceView.setVisibility(View.VISIBLE);
+
+ nativeMapView.setRenderThread(new GlSurfaceViewRenderThread(glSurfaceView));
}
/**
@@ -494,15 +497,6 @@ public class MapView extends FrameLayout {
// Rendering
//
- // Called when the map needs to be rerendered
- // Called via JNI from NativeMapView
- protected void onInvalidate() {
- if (glSurfaceView != null) {
- glSurfaceView.requestRender();
- }
- // TODO: removable? postInvalidate();
- }
-
@Override
protected void onSizeChanged(int width, int height, int oldw, int oldh) {
if (destroyed) {
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 a97b7cc8f2..240e68bf13 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
@@ -20,6 +20,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
+import com.mapbox.mapboxsdk.maps.renderer.RenderThread;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.Filter;
@@ -52,6 +53,9 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Used for callbacks
private MapView mapView;
+ // Used to schedule work on the render thread
+ private RenderThread renderThread;
+
//Hold a reference to prevent it from being GC'd as long as it's used on the native side
private final FileSource fileSource;
@@ -69,7 +73,7 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Constructors
//
- public NativeMapView(MapView mapView) {
+ public NativeMapView(final MapView mapView) {
Context context = mapView.getContext();
fileSource = FileSource.getInstance(context);
@@ -84,6 +88,10 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Methods
//
+ public void setRenderThread(RenderThread renderThread) {
+ this.renderThread = renderThread;
+ }
+
private boolean isDestroyedOn(String callingMethod) {
if (destroyed && !TextUtils.isEmpty(callingMethod)) {
Timber.e(
@@ -104,7 +112,8 @@ final class NativeMapView implements GLSurfaceView.Renderer {
if (isDestroyedOn("update")) {
return;
}
- nativeUpdate();
+
+ requestRender();
}
public void render() {
@@ -864,9 +873,28 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Callbacks
//
- protected void onInvalidate() {
- if (mapView != null) {
- mapView.onInvalidate();
+ /**
+ * Called from JNI whenever the native map
+ * needs rendering.
+ */
+ protected void requestRender() {
+ if (renderThread != null) {
+ renderThread.requestRender();
+ }
+ }
+
+ /**
+ * Called from JNI when work needs to be processed on
+ * the Renderer Thread.
+ */
+ protected void requestProcessing() {
+ if (renderThread != null) {
+ renderThread.queueEvent(new Runnable() {
+ @Override
+ public void run() {
+ nativeProcess();
+ }
+ });
}
}
@@ -905,6 +933,8 @@ final class NativeMapView implements GLSurfaceView.Renderer {
private native void nativeDestroy();
+ private native void nativeProcess();
+
private native void nativeInitializeDisplay();
private native void nativeTerminateDisplay();
@@ -1130,9 +1160,7 @@ final class NativeMapView implements GLSurfaceView.Renderer {
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
snapshotReadyCallback = callback;
scheduleTakeSnapshot();
- mapView.onInvalidate();
- // TODO. this should do a request render
- //render();
+ renderThread.requestRender();
}
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
new file mode 100644
index 0000000000..4b8df51dbe
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
@@ -0,0 +1,25 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+import android.opengl.GLSurfaceView;
+
+/**
+ * {@link RenderThread} implementation that schedules using the
+ * {@link GLSurfaceView} thread.
+ */
+public class GlSurfaceViewRenderThread implements RenderThread {
+ private final GLSurfaceView surfaceView;
+
+ public GlSurfaceViewRenderThread(GLSurfaceView surfaceView) {
+ this.surfaceView = surfaceView;
+ }
+
+ @Override
+ public void requestRender() {
+ surfaceView.requestRender();
+ }
+
+ @Override
+ public void queueEvent(Runnable runnable) {
+ surfaceView.queueEvent(runnable);
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
new file mode 100644
index 0000000000..3b9f0f2151
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
@@ -0,0 +1,12 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+/**
+ * Created by ivo on 11/09/2017.
+ */
+
+public interface RenderThread {
+
+ void requestRender();
+
+ void queueEvent(Runnable runnable);
+}
--
cgit v1.2.1
From 5d12503302dff168137d6f3b1444e4dc32ad44dd Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Thu, 14 Sep 2017 21:23:07 +0300
Subject: [android] self-contained map renderer
- Isolates the GL thread in a MapRenderer class with a native peer
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 32 ++---
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 137 +++------------------
.../maps/renderer/GlSurfaceViewRenderThread.java | 25 ----
.../mapboxsdk/maps/renderer/MapRenderer.java | 119 ++++++++++++++++++
.../maps/renderer/MapRendererRunnable.java | 29 +++++
.../maps/renderer/MapRendererScheduler.java | 13 ++
.../mapboxsdk/maps/renderer/RenderThread.java | 12 --
7 files changed, 190 insertions(+), 177 deletions(-)
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererRunnable.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererScheduler.java
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 086f57abf6..6612110649 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
@@ -28,7 +28,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
-import com.mapbox.mapboxsdk.maps.renderer.GlSurfaceViewRenderThread;
+import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
@@ -286,35 +286,31 @@ public class MapView extends FrameLayout {
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
- glSurfaceView.setRenderer(new GLSurfaceView.Renderer() {
+ MapRenderer mapRenderer = new MapRenderer(getContext(), glSurfaceView) {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
@Override
public void run() {
- initialiseMap();
- mapboxMap.onStart();
+ // Initialise only once
+ if (mapboxMap == null) {
+ initialiseMap();
+ mapboxMap.onStart();
+ }
}
});
- nativeMapView.onSurfaceCreated(gl, config);
- }
-
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- nativeMapView.onSurfaceChanged(gl, width, height);
+ super.onSurfaceCreated(gl, config);
}
+ };
- @Override
- public void onDrawFrame(GL10 gl) {
- nativeMapView.onDrawFrame(gl);
- }
- });
+ glSurfaceView.setRenderer(mapRenderer);
glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
glSurfaceView.setVisibility(View.VISIBLE);
- nativeMapView.setRenderThread(new GlSurfaceViewRenderThread(glSurfaceView));
+ nativeMapView = new NativeMapView(this, mapRenderer);
+ nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight());
}
/**
@@ -527,9 +523,7 @@ public class MapView extends FrameLayout {
return;
}
- if (nativeMapView == null) {
- nativeMapView = new NativeMapView(this);
- } else if (mapZoomButtonController != null) {
+ if (mapZoomButtonController != null) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
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 240e68bf13..62fe2be0c3 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
@@ -4,7 +4,6 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
-import android.opengl.GLSurfaceView;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -20,7 +19,8 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
-import com.mapbox.mapboxsdk.maps.renderer.RenderThread;
+import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
+import com.mapbox.mapboxsdk.maps.renderer.MapRendererScheduler;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.Filter;
@@ -36,13 +36,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
import timber.log.Timber;
// Class that wraps the native methods for convenience
-final class NativeMapView implements GLSurfaceView.Renderer {
+final class NativeMapView {
// Flag to indicating destroy was called
private boolean destroyed = false;
@@ -53,12 +50,12 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Used for callbacks
private MapView mapView;
- // Used to schedule work on the render thread
- private RenderThread renderThread;
-
//Hold a reference to prevent it from being GC'd as long as it's used on the native side
private final FileSource fileSource;
+ // Used to schedule work on the MapRenderer Thread
+ private MapRendererScheduler scheduler;
+
// Device density
private final float pixelRatio;
@@ -73,25 +70,21 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Constructors
//
- public NativeMapView(final MapView mapView) {
+ public NativeMapView(final MapView mapView, MapRenderer mapRenderer) {
+ this.scheduler = mapRenderer;
+ this.mapView = mapView;
+
Context context = mapView.getContext();
fileSource = FileSource.getInstance(context);
-
pixelRatio = context.getResources().getDisplayMetrics().density;
- this.mapView = mapView;
- String programCacheDir = context.getCacheDir().getAbsolutePath();
- nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
+ nativeInitialize(this, fileSource, mapRenderer, pixelRatio);
}
//
// Methods
//
- public void setRenderThread(RenderThread renderThread) {
- this.renderThread = renderThread;
- }
-
private boolean isDestroyedOn(String callingMethod) {
if (destroyed && !TextUtils.isEmpty(callingMethod)) {
Timber.e(
@@ -113,14 +106,7 @@ final class NativeMapView implements GLSurfaceView.Renderer {
return;
}
- requestRender();
- }
-
- public void render() {
- if (isDestroyedOn("render")) {
- return;
- }
- nativeRender();
+ scheduler.requestRender();
}
public void resizeView(int width, int height) {
@@ -151,31 +137,8 @@ final class NativeMapView implements GLSurfaceView.Renderer {
+ "capping value at 65535 instead of %s", height);
height = 65535;
}
- nativeResizeView(width, height);
- }
-
- private void resizeFramebuffer(int fbWidth, int fbHeight) {
- if (isDestroyedOn("resizeFramebuffer")) {
- return;
- }
- if (fbWidth < 0) {
- throw new IllegalArgumentException("fbWidth cannot be negative.");
- }
- if (fbHeight < 0) {
- throw new IllegalArgumentException("fbHeight cannot be negative.");
- }
-
- if (fbWidth > 65535) {
- throw new IllegalArgumentException(
- "fbWidth cannot be greater than 65535.");
- }
-
- if (fbHeight > 65535) {
- throw new IllegalArgumentException(
- "fbHeight cannot be greater than 65535.");
- }
- nativeResizeFramebuffer(fbWidth, fbHeight);
+ nativeResizeView(width, height);
}
public void setStyleUrl(String url) {
@@ -873,31 +836,6 @@ final class NativeMapView implements GLSurfaceView.Renderer {
// Callbacks
//
- /**
- * Called from JNI whenever the native map
- * needs rendering.
- */
- protected void requestRender() {
- if (renderThread != null) {
- renderThread.requestRender();
- }
- }
-
- /**
- * Called from JNI when work needs to be processed on
- * the Renderer Thread.
- */
- protected void requestProcessing() {
- if (renderThread != null) {
- renderThread.queueEvent(new Runnable() {
- @Override
- public void run() {
- nativeProcess();
- }
- });
- }
- }
-
protected void onMapChanged(int rawChange) {
if (mapView != null) {
mapView.onMapChange(rawChange);
@@ -928,33 +866,13 @@ final class NativeMapView implements GLSurfaceView.Renderer {
private native void nativeInitialize(NativeMapView nativeMapView,
FileSource fileSource,
- float pixelRatio,
- String programCacheDir);
+ MapRenderer mapRenderer,
+ float pixelRatio);
private native void nativeDestroy();
- private native void nativeProcess();
-
- private native void nativeInitializeDisplay();
-
- private native void nativeTerminateDisplay();
-
- private native void nativeInitializeContext();
-
- private native void nativeTerminateContext();
-
- private native void nativeCreateSurface(Object surface);
-
- private native void nativeDestroySurface();
-
- private native void nativeUpdate();
-
- private native void nativeRender();
-
private native void nativeResizeView(int width, int height);
- private native void nativeResizeFramebuffer(int fbWidth, int fbHeight);
-
private native void nativeSetStyleUrl(String url);
private native String nativeGetStyleUrl();
@@ -1160,30 +1078,7 @@ final class NativeMapView implements GLSurfaceView.Renderer {
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
snapshotReadyCallback = callback;
scheduleTakeSnapshot();
- renderThread.requestRender();
- }
-
- //
- // GLSurfaceView.Renderer
- //
-
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- Timber.i("[%s] onSurfaceCreated", Thread.currentThread().getName());
- //TODO: callback to map to re-create renderer?
+ scheduler.requestRender();
}
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- Timber.i("[%s] onSurfaceChanged %sx%s", Thread.currentThread().getName(), width, height);
- // Sets the current view port to the new size.
- gl.glViewport(0, 0, width, height);
- resizeFramebuffer(width, height);
- // resizeView(width, height); Done from MapView#onSizeChanged
- }
-
- @Override
- public void onDrawFrame(GL10 gl) {
- nativeRender();
- }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
deleted file mode 100644
index 4b8df51dbe..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GlSurfaceViewRenderThread.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.mapbox.mapboxsdk.maps.renderer;
-
-import android.opengl.GLSurfaceView;
-
-/**
- * {@link RenderThread} implementation that schedules using the
- * {@link GLSurfaceView} thread.
- */
-public class GlSurfaceViewRenderThread implements RenderThread {
- private final GLSurfaceView surfaceView;
-
- public GlSurfaceViewRenderThread(GLSurfaceView surfaceView) {
- this.surfaceView = surfaceView;
- }
-
- @Override
- public void requestRender() {
- surfaceView.requestRender();
- }
-
- @Override
- public void queueEvent(Runnable runnable) {
- surfaceView.queueEvent(runnable);
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
new file mode 100644
index 0000000000..772ecb79fb
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -0,0 +1,119 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+
+import com.mapbox.mapboxsdk.storage.FileSource;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * The {@link MapRenderer} encapsulates the GL thread.
+ *
+ * Performs actions on the GL thread to manage the GL resources and
+ * render on the one end and acts as a scheduler to request work to
+ * be performed on the GL thread on the other.
+ */
+public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler {
+
+ // Holds the pointer to the native peer after initialisation
+ private long nativePtr = 0;
+
+ private final GLSurfaceView glSurfaceView;
+
+ public MapRenderer(Context context, GLSurfaceView glSurfaceView) {
+ this.glSurfaceView = glSurfaceView;
+
+ FileSource fileSource = FileSource.getInstance(context);
+ float pixelRatio = context.getResources().getDisplayMetrics().density;
+ String programCacheDir = context.getCacheDir().getAbsolutePath();
+
+ // Initialise native peer
+ nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ nativeOnSurfaceCreated();
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ if (width < 0) {
+ throw new IllegalArgumentException("fbWidth cannot be negative.");
+ }
+
+ if (height < 0) {
+ throw new IllegalArgumentException("fbHeight cannot be negative.");
+ }
+
+ if (width > 65535) {
+ throw new IllegalArgumentException(
+ "fbWidth cannot be greater than 65535.");
+ }
+
+ if (height > 65535) {
+ throw new IllegalArgumentException(
+ "fbHeight cannot be greater than 65535.");
+ }
+
+ gl.glViewport(0, 0, width, height);
+ nativeOnSurfaceChanged(width, height);
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ nativeRender();
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Called from the renderer frontend to schedule a render.
+ */
+ @Override
+ public void requestRender() {
+ glSurfaceView.requestRender();
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Schedules work to be performed on the MapRenderer thread.
+ *
+ * @param runnable the runnable to execute
+ */
+ @Override
+ public void queueEvent(Runnable runnable) {
+ glSurfaceView.queueEvent(runnable);
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Called from the native peer to schedule work on the GL
+ * thread. Explicit override for easier to read jni code.
+ *
+ * @param runnable the runnable to execute
+ * @see MapRendererRunnable
+ */
+ void queueEvent(MapRendererRunnable runnable) {
+ this.queueEvent((Runnable) runnable);
+ }
+
+ private native void nativeInitialize(MapRenderer self,
+ FileSource fileSource,
+ float pixelRatio,
+ String programCacheDir);
+
+ @Override
+ protected native void finalize() throws Throwable;
+
+ private native void nativeOnSurfaceCreated();
+
+ private native void nativeOnSurfaceChanged(int width, int height);
+
+ private native void nativeRender();
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererRunnable.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererRunnable.java
new file mode 100644
index 0000000000..28246fe578
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererRunnable.java
@@ -0,0 +1,29 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+/**
+ * Peer class for {@link Runnable}s to be scheduled on the {@link MapRenderer} thread.
+ * The actual work is performed in the native peer.
+ */
+class MapRendererRunnable implements Runnable {
+
+ // Holds the pointer to the native peer after initialisation
+ private final long nativePtr;
+
+ /**
+ * Constructed from the native peer constructor
+ *
+ * @param nativePtr the native peer's memory address
+ */
+ MapRendererRunnable(long nativePtr) {
+ this.nativePtr = nativePtr;
+ }
+
+ @Override
+ public native void run();
+
+ @Override
+ protected native void finalize() throws Throwable;
+
+ private native void nativeInitialize();
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererScheduler.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererScheduler.java
new file mode 100644
index 0000000000..7ad4f124d8
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRendererScheduler.java
@@ -0,0 +1,13 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+/**
+ * Can be used to schedule work on the map renderer
+ * thread or request a render.
+ */
+public interface MapRendererScheduler {
+
+ void requestRender();
+
+ void queueEvent(Runnable runnable);
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
deleted file mode 100644
index 3b9f0f2151..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/RenderThread.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.mapbox.mapboxsdk.maps.renderer;
-
-/**
- * Created by ivo on 11/09/2017.
- */
-
-public interface RenderThread {
-
- void requestRender();
-
- void queueEvent(Runnable runnable);
-}
--
cgit v1.2.1
From e0312ef208797983b8b143f6d104b644493db4b5 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Fri, 15 Sep 2017 10:52:36 +0300
Subject: [android] fix ZoomButtonController initialisation order
- prevents "java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController" when quitting the map before the receiver is properly registered
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.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/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 6612110649..271bd155be 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
@@ -125,7 +125,6 @@ public class MapView extends FrameLayout {
myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
attrView = (ImageView) view.findViewById(R.id.attributionView);
logoView = (ImageView) view.findViewById(R.id.logoView);
- mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
@@ -187,6 +186,7 @@ public class MapView extends FrameLayout {
annotationManager, cameraChangeDispatcher);
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);
+ mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));
MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
mapZoomButtonController.bind(uiSettings, zoomListener);
--
cgit v1.2.1
From c17be060fd910dbcaf7334356743421ac6936e7e Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 18 Sep 2017 11:31:45 +0300
Subject: [android] map snapshots
---
.../main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
(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 62fe2be0c3..5be74258fd 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
@@ -807,13 +807,6 @@ final class NativeMapView {
return features != null ? Arrays.asList(features) : new ArrayList();
}
- public void scheduleTakeSnapshot() {
- if (isDestroyedOn("scheduleTakeSnapshot")) {
- return;
- }
- nativeTakeSnapshot();
- }
-
public void setApiBaseUrl(String baseUrl) {
if (isDestroyedOn("setApiBaseUrl")) {
return;
@@ -1076,9 +1069,11 @@ final class NativeMapView {
//
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
+ if (isDestroyedOn("addSnapshotCallback")) {
+ return;
+ }
snapshotReadyCallback = callback;
- scheduleTakeSnapshot();
- scheduler.requestRender();
+ nativeTakeSnapshot();
}
}
--
cgit v1.2.1
From b0c06c764b0f9900dac3707dc5af398b41b6aa5b Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 18 Sep 2017 19:00:34 +0300
Subject: [android] re-implemented the fps listener api
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 15 -------
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 1 +
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 47 +++++++++++++---------
.../mapboxsdk/maps/renderer/MapRenderer.java | 26 ++++++++++++
4 files changed, 54 insertions(+), 35 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 271bd155be..9f6cd7ab5e 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
@@ -435,21 +435,6 @@ public class MapView extends FrameLayout {
nativeMapView.onLowMemory();
}
- // Called when debug mode is enabled to update a FPS counter
- // Called via JNI from NativeMapView
- // Forward to any listener
- protected void onFpsChanged(final double fps) {
- final MapboxMap.OnFpsChangedListener listener = mapboxMap.getOnFpsChangedListener();
- if (listener != null) {
- post(new Runnable() {
- @Override
- public void run() {
- listener.onFpsChanged(fps);
- }
- });
- }
- }
-
/**
*
* Loads a new map style from the specified URL.
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 6c7670b91c..3afc29f99b 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
@@ -1711,6 +1711,7 @@ public final class MapboxMap {
*/
public void setOnFpsChangedListener(@Nullable OnFpsChangedListener listener) {
onFpsChangedListener = listener;
+ nativeMapView.setOnFpsChangedListener(listener);
}
// used by MapView
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 5be74258fd..3ce6aab581 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
@@ -20,7 +20,6 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
-import com.mapbox.mapboxsdk.maps.renderer.MapRendererScheduler;
import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.Filter;
@@ -54,7 +53,7 @@ final class NativeMapView {
private final FileSource fileSource;
// Used to schedule work on the MapRenderer Thread
- private MapRendererScheduler scheduler;
+ private MapRenderer mapRenderer;
// Device density
private final float pixelRatio;
@@ -71,7 +70,7 @@ final class NativeMapView {
//
public NativeMapView(final MapView mapView, MapRenderer mapRenderer) {
- this.scheduler = mapRenderer;
+ this.mapRenderer = mapRenderer;
this.mapView = mapView;
Context context = mapView.getContext();
@@ -106,7 +105,7 @@ final class NativeMapView {
return;
}
- scheduler.requestRender();
+ mapRenderer.requestRender();
}
public void resizeView(int width, int height) {
@@ -510,13 +509,6 @@ final class NativeMapView {
return nativeGetDebug();
}
- public void setEnableFps(boolean enable) {
- if (isDestroyedOn("setEnableFps")) {
- return;
- }
- nativeSetEnableFps(enable);
- }
-
public boolean isFullyLoaded() {
if (isDestroyedOn("isFullyLoaded")) {
return false;
@@ -835,13 +827,6 @@ final class NativeMapView {
}
}
- protected void onFpsChanged(double fps) {
- if (isDestroyedOn("OnFpsChanged")) {
- return;
- }
- mapView.onFpsChanged(fps);
- }
-
protected void onSnapshotReady(Bitmap mapContent) {
if (isDestroyedOn("OnSnapshotReady")) {
return;
@@ -947,8 +932,6 @@ final class NativeMapView {
private native boolean nativeGetDebug();
- private native void nativeSetEnableFps(boolean enable);
-
private native boolean nativeIsFullyLoaded();
private native void nativeSetReachability(boolean status);
@@ -1076,4 +1059,28 @@ final class NativeMapView {
nativeTakeSnapshot();
}
+ public void setOnFpsChangedListener(final MapboxMap.OnFpsChangedListener listener) {
+ mapRenderer.queueEvent(new Runnable() {
+
+ @Override
+ public void run() {
+ mapRenderer.setOnFpsChangedListener(new MapboxMap.OnFpsChangedListener() {
+
+ @Override
+ public void onFpsChanged(final double fps) {
+ mapView.post(new Runnable() {
+
+ @Override
+ public void run() {
+ listener.onFpsChanged(fps);
+ }
+
+ });
+ }
+
+ });
+ }
+
+ });
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index 772ecb79fb..3f43522e01 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.maps.renderer;
import android.content.Context;
import android.opengl.GLSurfaceView;
+import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.storage.FileSource;
import javax.microedition.khronos.egl.EGLConfig;
@@ -22,6 +23,8 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
private final GLSurfaceView glSurfaceView;
+ private MapboxMap.OnFpsChangedListener onFpsChangedListener;
+
public MapRenderer(Context context, GLSurfaceView glSurfaceView) {
this.glSurfaceView = glSurfaceView;
@@ -33,6 +36,10 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
}
+ public void setOnFpsChangedListener(MapboxMap.OnFpsChangedListener listener) {
+ onFpsChangedListener = listener;
+ }
+
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
nativeOnSurfaceCreated();
@@ -65,6 +72,10 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
@Override
public void onDrawFrame(GL10 gl) {
nativeRender();
+
+ if (onFpsChangedListener != null) {
+ updateFps();
+ }
}
/**
@@ -116,4 +127,19 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
private native void nativeRender();
+ private long frames;
+ private long timeElapsed;
+
+ private void updateFps() {
+ frames++;
+ long currentTime = System.nanoTime();
+ double fps = 0;
+ if (currentTime - timeElapsed >= 1) {
+ fps = frames / ((currentTime - timeElapsed) / 1E9);
+ onFpsChangedListener.onFpsChanged(fps);
+ timeElapsed = currentTime;
+ frames = 0;
+ }
+ }
+
}
--
cgit v1.2.1
From d1e69c8bafec2b799fae441be17b79c3566baac3 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 19 Sep 2017 10:56:47 +0300
Subject: [android] CustomLayer - optionally accept a context lost callback
function
---
.../com/mapbox/mapboxsdk/style/layers/CustomLayer.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java
index 7807556b78..f77e7280f0 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CustomLayer.java
@@ -13,7 +13,16 @@ public class CustomLayer extends Layer {
long initializeFunction,
long renderFunction,
long deinitializeFunction) {
- initialize(id, initializeFunction, renderFunction, deinitializeFunction, context);
+ this(id, context, initializeFunction, renderFunction, 0L, deinitializeFunction);
+ }
+
+ public CustomLayer(String id,
+ long context,
+ long initializeFunction,
+ long renderFunction,
+ long contextLostFunction,
+ long deinitializeFunction) {
+ initialize(id, initializeFunction, renderFunction, contextLostFunction, deinitializeFunction, context);
}
public CustomLayer(long nativePtr) {
@@ -24,7 +33,8 @@ public class CustomLayer extends Layer {
nativeUpdate();
}
- protected native void initialize(String id, long initializeFunction, long renderFunction, long deinitializeFunction,
+ protected native void initialize(String id, long initializeFunction, long renderFunction,
+ long contextLostFunction, long deinitializeFunction,
long context);
protected native void nativeUpdate();
--
cgit v1.2.1
From e6fea1e726cc2d866a8da652a0100412ad89bafa Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 19 Sep 2017 14:59:39 +0200
Subject: [android] - disable rotation gesture when pinch zooming
---
.../gesturedetectors/TwoFingerGestureDetector.java | 5 ++--
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 33 ++++++++++++++--------
2 files changed, 23 insertions(+), 15 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
index 71fb9aa168..db492b6556 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
@@ -54,8 +54,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
ViewConfiguration config = ViewConfiguration.get(context);
- // We divide edge slop by 2 to make rotation gesture happen more easily #6870
- edgeSlop = config.getScaledEdgeSlop() / 2;
+ edgeSlop = config.getScaledEdgeSlop();
}
@Override
@@ -222,4 +221,4 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
return focus.y;
}
-}
+}
\ No newline at end of file
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 f456d3ef65..2394e52193 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
@@ -54,8 +54,10 @@ final class MapGestureDetector {
private boolean quickZoom;
private boolean tiltGestureOccurred;
private boolean scrollGestureOccurred;
+
private boolean scaleGestureOccurred;
private boolean recentScaleGestureOccurred;
+ private long scaleBeginTime;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -144,8 +146,8 @@ final class MapGestureDetector {
}
// Check two finger gestures first
- rotateGestureDetector.onTouchEvent(event);
scaleGestureDetector.onTouchEvent(event);
+ rotateGestureDetector.onTouchEvent(event);
shoveGestureDetector.onTouchEvent(event);
// Handle two finger tap
@@ -428,8 +430,7 @@ final class MapGestureDetector {
*/
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
- long beginTime = 0;
- float scaleFactor = 1.0f;
+ private float scaleFactor = 1.0f;
// Called when two fingers first touch the screen
@Override
@@ -438,9 +439,8 @@ final class MapGestureDetector {
return false;
}
- scaleGestureOccurred = true;
recentScaleGestureOccurred = true;
- beginTime = detector.getEventTime();
+ scaleBeginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_PINCH_START, transform));
@@ -451,7 +451,7 @@ final class MapGestureDetector {
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
scaleGestureOccurred = false;
- beginTime = 0;
+ scaleBeginTime = 0;
scaleFactor = 1.0f;
cameraChangeDispatcher.onCameraIdle();
}
@@ -471,7 +471,7 @@ final class MapGestureDetector {
// Ignore short touches in case it is a tap
// Also ignore small scales
long time = detector.getEventTime();
- long interval = time - beginTime;
+ long interval = time - scaleBeginTime;
if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
@@ -517,7 +517,6 @@ final class MapGestureDetector {
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2),
detector.getFocusX(), detector.getFocusY());
}
-
return true;
}
}
@@ -527,9 +526,11 @@ final class MapGestureDetector {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
- long beginTime = 0;
- float totalAngle = 0.0f;
- boolean started = false;
+ private static final long ROTATE_INVOKE_WAIT_TIME = 1500;
+
+ private long beginTime = 0;
+ private float totalAngle = 0.0f;
+ private boolean started = false;
// Called when two fingers first touch the screen
@Override
@@ -566,7 +567,7 @@ final class MapGestureDetector {
// Also ignore small rotate
long time = detector.getEventTime();
long interval = time - beginTime;
- if (!started && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!started && (interval <= ViewConfiguration.getTapTimeout() || isScaleGestureActive(time))) {
return false;
}
@@ -583,6 +584,7 @@ final class MapGestureDetector {
if (!started) {
return false;
}
+
// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
@@ -601,6 +603,13 @@ final class MapGestureDetector {
}
return true;
}
+
+ private boolean isScaleGestureActive(long time) {
+ long scaleExecutionTime = time - scaleBeginTime;
+ boolean scaleGestureStarted = scaleBeginTime != 0;
+ boolean scaleOffsetTimeValid = scaleExecutionTime > ROTATE_INVOKE_WAIT_TIME;
+ return (scaleGestureStarted && scaleOffsetTimeValid) || scaleGestureOccurred;
+ }
}
/**
--
cgit v1.2.1
From 9ed623acb195c7b89028f0d7e1b74e47e5fd1360 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 19 Sep 2017 14:59:39 +0200
Subject: [android] - disable rotation gesture when pinch zooming
---
.../gesturedetectors/TwoFingerGestureDetector.java | 5 +-
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 156 +++++++++++----------
2 files changed, 81 insertions(+), 80 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
index 71fb9aa168..db492b6556 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
@@ -54,8 +54,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
ViewConfiguration config = ViewConfiguration.get(context);
- // We divide edge slop by 2 to make rotation gesture happen more easily #6870
- edgeSlop = config.getScaledEdgeSlop() / 2;
+ edgeSlop = config.getScaledEdgeSlop();
}
@Override
@@ -222,4 +221,4 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
return focus.y;
}
-}
+}
\ No newline at end of file
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 d2973bf558..bff5e9bed2 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
@@ -50,13 +50,14 @@ final class MapGestureDetector {
private PointF focalPoint;
- private boolean twoTap = false;
- private boolean zoomStarted = false;
- private boolean dragStarted = false;
- private boolean quickZoom = false;
- private boolean scrollInProgress = false;
- private boolean scaleGestureOccurred = false;
- private boolean recentScaleGestureOccurred = false;
+ private boolean twoTap;
+ private boolean quickZoom;
+ private boolean tiltGestureOccurred;
+ private boolean scrollGestureOccurred;
+
+ private boolean scaleGestureOccurred;
+ private boolean recentScaleGestureOccurred;
+ private long scaleBeginTime;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -145,8 +146,8 @@ final class MapGestureDetector {
}
// Check two finger gestures first
- rotateGestureDetector.onTouchEvent(event);
scaleGestureDetector.onTouchEvent(event);
+ rotateGestureDetector.onTouchEvent(event);
shoveGestureDetector.onTouchEvent(event);
// Handle two finger tap
@@ -193,10 +194,10 @@ final class MapGestureDetector {
}
// Scroll / Pan Has Stopped
- if (scrollInProgress) {
+ if (scrollGestureOccurred) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent(
getLocationFromGesture(event.getX(), event.getY()), transform));
- scrollInProgress = false;
+ scrollGestureOccurred = false;
cameraChangeDispatcher.onCameraIdle();
}
@@ -393,20 +394,18 @@ final class MapGestureDetector {
return false;
}
- if (dragStarted) {
- return false;
- }
-
- if (scaleGestureOccurred) {
+ if (tiltGestureOccurred) {
return false;
}
- if (!scrollInProgress) {
- scrollInProgress = true;
+ if (!scrollGestureOccurred) {
+ scrollGestureOccurred = true;
// Cancel any animation
- transform.cancelTransitions();
- cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+ if (!scaleGestureOccurred) {
+ transform.cancelTransitions();
+ cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
+ }
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(e1.getX(), e1.getY()),
@@ -431,8 +430,7 @@ final class MapGestureDetector {
*/
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
- long beginTime = 0;
- float scaleFactor = 1.0f;
+ private float scaleFactor = 1.0f;
// Called when two fingers first touch the screen
@Override
@@ -441,9 +439,8 @@ final class MapGestureDetector {
return false;
}
- scaleGestureOccurred = true;
recentScaleGestureOccurred = true;
- beginTime = detector.getEventTime();
+ scaleBeginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_PINCH_START, transform));
@@ -454,9 +451,8 @@ final class MapGestureDetector {
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
scaleGestureOccurred = false;
- beginTime = 0;
+ scaleBeginTime = 0;
scaleFactor = 1.0f;
- zoomStarted = false;
cameraChangeDispatcher.onCameraIdle();
}
@@ -468,27 +464,27 @@ final class MapGestureDetector {
return super.onScale(detector);
}
- // 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;
+ if (tiltGestureOccurred) {
+ return false;
}
// Ignore short touches in case it is a tap
// Also ignore small scales
long time = detector.getEventTime();
- long interval = time - beginTime;
- if (!zoomStarted && (interval <= ViewConfiguration.getTapTimeout())) {
+ long interval = time - scaleBeginTime;
+ if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
- if (!zoomStarted) {
- return false;
+ // 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);
+ scaleGestureOccurred = true;
}
- if (dragStarted) {
+ if (!scaleGestureOccurred) {
return false;
}
@@ -506,7 +502,7 @@ final class MapGestureDetector {
// Scale the map
if (focalPoint != null) {
// arround user provided focal point
- transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), focalPoint.x, focalPoint.y);
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
cameraChangeDispatcher.onCameraMove();
// clamp scale factors we feed to core #7514
@@ -514,12 +510,13 @@ final class MapGestureDetector {
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
MapboxConstants.MAXIMUM_SCALE_FACTOR_CLAMP);
// around center map
- transform.zoomBy(Math.log(scaleFactor) / Math.log(2), uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
+ transform.zoomBy(Math.log(scaleFactor) / Math.log(Math.PI / 2),
+ uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
} else {
// around gesture
- transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(2), detector.getFocusX(), detector.getFocusY());
+ transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2),
+ detector.getFocusX(), detector.getFocusY());
}
-
return true;
}
}
@@ -529,9 +526,11 @@ final class MapGestureDetector {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
- long beginTime = 0;
- float totalAngle = 0.0f;
- boolean started = false;
+ private static final long ROTATE_INVOKE_WAIT_TIME = 1500;
+
+ private long beginTime = 0;
+ private float totalAngle = 0.0f;
+ private boolean started = false;
// Called when two fingers first touch the screen
@Override
@@ -544,9 +543,6 @@ final class MapGestureDetector {
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
beginTime = detector.getEventTime();
- MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
- getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
- MapboxEvent.GESTURE_ROTATION_START, transform));
return true;
}
@@ -563,28 +559,32 @@ final class MapGestureDetector {
// Called for rotation
@Override
public boolean onRotate(RotateGestureDetector detector) {
- if (!trackingSettings.isRotateGestureCurrentlyEnabled() || dragStarted) {
+ if (!trackingSettings.isRotateGestureCurrentlyEnabled() || tiltGestureOccurred) {
return false;
}
- // If rotate is large enough ignore a tap
- // Also is zoom already started, don't rotate
- totalAngle += detector.getRotationDegreesDelta();
- if (totalAngle > 20.0f || totalAngle < -20.0f) {
- started = true;
- }
-
// Ignore short touches in case it is a tap
// Also ignore small rotate
long time = detector.getEventTime();
long interval = time - beginTime;
- if (!started && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!started && (interval <= ViewConfiguration.getTapTimeout() || isScaleGestureActive(time))) {
return false;
}
+ // If rotate is large enough ignore a tap
+ // Also is zoom already started, don't rotate
+ totalAngle += detector.getRotationDegreesDelta();
+ if (totalAngle > 35.0f || totalAngle < -35.0f) {
+ MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
+ getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
+ MapboxEvent.GESTURE_ROTATION_START, transform));
+ started = true;
+ }
+
if (!started) {
return false;
}
+
// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
@@ -603,6 +603,13 @@ final class MapGestureDetector {
}
return true;
}
+
+ private boolean isScaleGestureActive(long time) {
+ long scaleExecutionTime = time - scaleBeginTime;
+ boolean scaleGestureStarted = scaleBeginTime != 0;
+ boolean scaleOffsetTimeValid = scaleExecutionTime > ROTATE_INVOKE_WAIT_TIME;
+ return (scaleGestureStarted && scaleOffsetTimeValid) || scaleGestureOccurred;
+ }
}
/**
@@ -610,9 +617,8 @@ final class MapGestureDetector {
*/
private class ShoveGestureListener implements ShoveGestureDetector.OnShoveGestureListener {
- long beginTime = 0;
- float totalDelta = 0.0f;
- boolean started = false;
+ private long beginTime = 0;
+ private float totalDelta = 0.0f;
@Override
public boolean onShoveBegin(ShoveGestureDetector detector) {
@@ -622,10 +628,6 @@ final class MapGestureDetector {
// notify camera change listener
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
- beginTime = detector.getEventTime();
- MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
- getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
- MapboxEvent.GESTURE_PITCH_START, transform));
return true;
}
@@ -633,8 +635,7 @@ final class MapGestureDetector {
public void onShoveEnd(ShoveGestureDetector detector) {
beginTime = 0;
totalDelta = 0.0f;
- started = false;
- dragStarted = false;
+ tiltGestureOccurred = false;
}
@Override
@@ -643,22 +644,26 @@ final class MapGestureDetector {
return false;
}
- // If tilt is large enough ignore a tap
- // Also if zoom already started, don't tilt
- totalDelta += detector.getShovePixelsDelta();
- if (!zoomStarted && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) {
- started = true;
- }
-
// Ignore short touches in case it is a tap
// Also ignore small tilt
long time = detector.getEventTime();
long interval = time - beginTime;
- if (!started && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!tiltGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
- if (!started) {
+ // If tilt is large enough ignore a tap
+ // Also if zoom already started, don't tilt
+ totalDelta += detector.getShovePixelsDelta();
+ if (!tiltGestureOccurred && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) {
+ tiltGestureOccurred = true;
+ beginTime = detector.getEventTime();
+ MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
+ getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
+ MapboxEvent.GESTURE_PITCH_START, transform));
+ }
+
+ if (!tiltGestureOccurred) {
return false;
}
@@ -669,9 +674,6 @@ final class MapGestureDetector {
// Tilt the map
transform.setTilt(pitch);
-
- dragStarted = true;
-
return true;
}
}
@@ -691,4 +693,4 @@ final class MapGestureDetector {
void setOnScrollListener(MapboxMap.OnScrollListener onScrollListener) {
this.onScrollListener = onScrollListener;
}
-}
+}
\ No newline at end of file
--
cgit v1.2.1
From 9596940638891b7041587f38f8c1aba19b0a1855 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rados=C5=82aw=20Juszczyk?=
Date: Fri, 25 Aug 2017 14:45:07 +0200
Subject: Do not check connection if it is local request
Requests to servers which run on localhost should be independent from internet connection.
---
.../src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
index 9c8cda5544..7f3a48c57a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -56,13 +56,14 @@ class HTTPRequest implements Callback {
mNativePtr = nativePtr;
try {
- // Don't try a request if we aren't connected
- if (!Mapbox.isConnected()) {
+ HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
+ final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
+
+ // Don't try a request to remote server if we aren't connected
+ if (!Mapbox.isConnected() && !host.equals("127.0.0.1") && !host.equals("localhost")) {
throw new NoRouteToHostException("No Internet connection available.");
}
- HttpUrl httpUrl = HttpUrl.parse(resourceUrl);
- final String host = httpUrl.host().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
if (host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
|| host.endsWith(".mapbox.cn")) {
if (httpUrl.querySize() == 0) {
--
cgit v1.2.1
From 95092df8e96514d59c777b6becd953ff1b187790 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 12 Sep 2017 09:56:09 +0200
Subject: [android] - harden offline region deletion
---
.../src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegion.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(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 1c78d5979e..ee6f8aa87f 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
@@ -357,10 +357,10 @@ public class OfflineRegion {
*/
public void delete(@NonNull final OfflineRegionDeleteCallback callback) {
if (!isDeleted) {
+ isDeleted = true;
deleteOfflineRegion(new OfflineRegionDeleteCallback() {
@Override
public void onDelete() {
- isDeleted = true;
getHandler().post(new Runnable() {
@Override
public void run() {
@@ -375,6 +375,7 @@ public class OfflineRegion {
getHandler().post(new Runnable() {
@Override
public void run() {
+ isDeleted = false;
callback.onError(error);
}
});
--
cgit v1.2.1
From 6dbdf3aaeb8b1a18e989bc4e7672cb2d801b2426 Mon Sep 17 00:00:00 2001
From: Robin Darby
Date: Mon, 28 Aug 2017 15:02:44 -0600
Subject: [android] Clear out mapCallback's OnMapReadyCallbacks on onDestroy
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 32c4952aa1..91c77c3e33 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
@@ -264,6 +264,7 @@ public class MapView extends FrameLayout {
nativeMapView.terminateContext();
nativeMapView.terminateDisplay();
nativeMapView.destroySurface();
+ mapCallback.clearOnMapReadyCallbacks();
nativeMapView.destroy();
nativeMapView = null;
}
@@ -955,5 +956,9 @@ public class MapView extends FrameLayout {
void addOnMapReadyCallback(OnMapReadyCallback callback) {
onMapReadyCallbackList.add(callback);
}
+
+ void clearOnMapReadyCallbacks() {
+ onMapReadyCallbackList.clear();
+ }
}
}
--
cgit v1.2.1
From 4ff9ce7486b51e00854508d4c6883a0f3f3413a0 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 11 Sep 2017 14:05:41 +0200
Subject: [android] - avoid adding duplicate points to bounds
---
.../src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 8b2ccffef1..4fcb91033c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -450,7 +450,7 @@ public class LatLngBounds implements Parcelable {
*/
public Builder includes(List latLngs) {
for (LatLng point : latLngs) {
- latLngList.add(point);
+ include(point);
}
return this;
}
@@ -462,7 +462,9 @@ public class LatLngBounds implements Parcelable {
* @return this
*/
public Builder include(@NonNull LatLng latLng) {
- latLngList.add(latLng);
+ if (!latLngList.contains(latLng)) {
+ latLngList.add(latLng);
+ }
return this;
}
}
--
cgit v1.2.1
From ac68df24d2fe9e174ad9352136a8627b042ca641 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 7 Sep 2017 17:26:26 +0200
Subject: [android] fix is download complete (a download is complete when count
and required resources match and the download state is inactive) (#9913)
---
.../src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.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/offline/OfflineRegionStatus.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
index fe12dd46c4..0f4b81fc39 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineRegionStatus.java
@@ -80,7 +80,7 @@ public class OfflineRegionStatus {
* @return true if download is complete, false if not
*/
public boolean isComplete() {
- return (completedResourceCount == requiredResourceCount);
+ return (completedResourceCount == requiredResourceCount) && downloadState == OfflineRegion.STATE_INACTIVE;
}
/**
--
cgit v1.2.1
From 0701de566b1d818c5cedf75ff72599e3711513dd Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 31 Aug 2017 18:27:12 +0200
Subject: bump MAS version number to 2.2.3 (#9901)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.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/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 91c77c3e33..9fa3126523 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
@@ -524,7 +524,7 @@ public class MapView extends FrameLayout {
//
/**
- *
+ *
P
* Add a callback that's invoked when the displayed map view changes.
*
* To remove the callback, use {@link MapView#removeOnMapChangedListener(OnMapChangedListener)}.
--
cgit v1.2.1
From 3f52377543885170da6a27e1c24657cc4cbcf29c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 26 Sep 2017 09:38:20 +0200
Subject: [android] [auto] Update properties to version 5.1.4 in preparation
for build.
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
.../resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 033903822f..078fdbc801 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.1.4-SNAPSHOT
+VERSION_NAME=5.2.0-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
index 81e0e5d7a8..716f0ffe70 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
+++ b/platform/android/MapboxGLAndroidSDK/src/main/resources/fabric/com.mapbox.mapboxsdk.mapbox-android-sdk.properties
@@ -1,3 +1,3 @@
fabric-identifier=com.mapbox.mapboxsdk.mapbox-android-sdk
-fabric-version=5.1.3
+fabric-version=5.1.4
fabric-build-type=binary
--
cgit v1.2.1
From 2f4cc7e4665d6e280bf1770f348fe069ebd928bc Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 14 Sep 2017 16:12:25 +0200
Subject: [android] - add API to perform platform side animations
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 12 +++--
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 51 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 9f6cd7ab5e..12e4c675ee 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
@@ -148,7 +148,8 @@ public class MapView extends FrameLayout {
addOnMapChangedListener(mapCallback);
// callback for focal point invalidation
- final FocalPointInvalidator focalPointInvalidator = new FocalPointInvalidator(createFocalPointChangeListener());
+ final FocalPointInvalidator focalPointInvalidator = new FocalPointInvalidator();
+ focalPointInvalidator.addListener(createFocalPointChangeListener());
// callback for registering touch listeners
RegisterTouchListener registerTouchListener = new RegisterTouchListener();
@@ -177,8 +178,11 @@ public class MapView extends FrameLayout {
markerViewManager, iconManager, annotations, markers, polygons, polylines);
Transform transform = new Transform(nativeMapView, annotationManager.getMarkerViewManager(), trackingSettings,
cameraChangeDispatcher);
+
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings, proj,
registerTouchListener, annotationManager, cameraChangeDispatcher);
+ focalPointInvalidator.addListener(mapboxMap.createFocalPointChangeListener());
+
mapCallback.attachMapboxMap(mapboxMap);
// user input
@@ -817,10 +821,10 @@ public class MapView extends FrameLayout {
private class FocalPointInvalidator implements FocalPointChangeListener {
- private final FocalPointChangeListener[] focalPointChangeListeners;
+ private final List focalPointChangeListeners = new ArrayList<>();
- FocalPointInvalidator(FocalPointChangeListener... listeners) {
- focalPointChangeListeners = listeners;
+ void addListener(FocalPointChangeListener focalPointChangeListener) {
+ focalPointChangeListeners.add(focalPointChangeListener);
}
@Override
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 3afc29f99b..c4b2a1ad4a 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
@@ -75,6 +75,7 @@ public final class MapboxMap {
private final OnRegisterTouchListener onRegisterTouchListener;
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
+ private PointF focalPoint;
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, TrackingSettings tracking,
MyLocationViewSettings myLocationView, Projection projection, OnRegisterTouchListener listener,
@@ -611,6 +612,47 @@ public final class MapboxMap {
// Camera API
//
+ /**
+ * Moves the center of the screen to a latitude and longitude specified by a LatLng object. This centers the
+ * camera on the LatLng object.
+ *
+ * @param latLng Target location to change to
+ */
+ public void setLatLng(@NonNull LatLng latLng) {
+ nativeMapView.setLatLng(latLng);
+ }
+
+ /**
+ * Moves the camera viewpoint to a particular zoom level.
+ *
+ * @param zoom Zoom level to change to
+ */
+ public void setZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
+ if (focalPoint == null) {
+ focalPoint = new PointF(nativeMapView.getWidth() / 2, nativeMapView.getHeight() / 2);
+ }
+ nativeMapView.setZoom(zoom, focalPoint, 0);
+ }
+
+ /**
+ * Moves the camera viewpoint angle to a particular angle in degrees.
+ *
+ * @param tilt Tilt angle to change to
+ */
+ public void setTilt(@FloatRange(from = MapboxConstants.MINIMUM_TILT, to = MapboxConstants.MAXIMUM_TILT) double tilt) {
+ nativeMapView.setPitch(tilt, 0);
+ }
+
+ /**
+ * Moves the camera viewpoint direction to a particular angle in degrees.
+ *
+ * @param bearing Direction angle to change to
+ */
+ public void setBearing(@FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION)
+ double bearing) {
+ nativeMapView.setBearing(bearing);
+ }
+
/**
* Cancels ongoing animations.
*
@@ -1986,6 +2028,15 @@ public final class MapboxMap {
return nativeMapView.queryRenderedFeatures(coordinates, layerIds, filter);
}
+ FocalPointChangeListener createFocalPointChangeListener() {
+ return new FocalPointChangeListener() {
+ @Override
+ public void onFocalPointChanged(PointF pointF) {
+ focalPoint = pointF;
+ }
+ };
+ }
+
//
// Interfaces
//
--
cgit v1.2.1
From ef0ce1a9a4284c4d653e31c76d8aaeb11b1712c0 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 26 Sep 2017 15:28:57 +0200
Subject: [android] - bump snapshot version to beta
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index ff6e2f61df..a9ec9fae88 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.2.0-SNAPSHOT
+VERSION_NAME=5.2.0-beta-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
--
cgit v1.2.1
From 9eba7d8b3e0db0fb4592218bf0e33841933bcd3e Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 26 Sep 2017 15:12:57 +0200
Subject: [android] - hide overlain views on init
---
.../MapboxGLAndroidSDK/src/main/res/layout/mapbox_mapview_internal.xml | 2 ++
1 file changed, 2 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 e2f1823327..df7ccaaca9 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
@@ -28,6 +28,7 @@
android:contentDescription="@string/mapbox_compassContentDescription"/>
Date: Wed, 16 Aug 2017 13:29:14 +0200
Subject: [android] - deprecate MarkerView
---
.../mapboxsdk/annotations/BaseMarkerViewOptions.java | 3 +++
.../java/com/mapbox/mapboxsdk/annotations/MarkerView.java | 3 +++
.../mapbox/mapboxsdk/annotations/MarkerViewManager.java | 3 +++
.../mapbox/mapboxsdk/annotations/MarkerViewOptions.java | 3 +++
.../main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 15 +++++++++++++++
5 files changed, 27 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
index ddedf3debf..3fd2fa4ebf 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java
@@ -14,7 +14,10 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
*
* @param Type of the marker view to be composed.
* @param Type of the builder to be used for composing.
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+@Deprecated
public abstract class BaseMarkerViewOptions>
implements Parcelable {
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 56e8cc4ce2..eb82c7bf53 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
@@ -24,7 +24,10 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
* used with event listeners to bring up info windows. An {@link InfoWindow} is displayed by default
* when either a title or snippet is provided.
*
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+@Deprecated
public class MarkerView extends Marker {
private MarkerViewManager markerViewManager;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index 8704e882ea..8304d0e6ed 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -30,7 +30,10 @@ import java.util.Map;
*
* This class is responsible for managing a {@link MarkerView} item.
*
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+@Deprecated
public class MarkerViewManager implements MapView.OnMapChangedListener {
private final ViewGroup markerViewContainer;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
index 2d829537fc..79c72e5f70 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java
@@ -12,7 +12,10 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
*
* Do not extend this class directly but extend {@link BaseMarkerViewOptions} instead.
*
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+@Deprecated
public class MarkerViewOptions extends BaseMarkerViewOptions {
private MarkerView marker;
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 c4b2a1ad4a..0c820d844c 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
@@ -1216,8 +1216,11 @@ public final class MapboxMap {
*
* @param markerOptions A marker options object that defines how to render the marker
* @return The {@code Marker} that was added to the map
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
+ @Deprecated
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) {
return annotationManager.addMarker(markerOptions, this, null);
}
@@ -1232,7 +1235,10 @@ public final class MapboxMap {
* @param markerOptions A marker options object that defines how to render the marker
* @param onMarkerViewAddedListener Callback invoked when the View has been added to the map
* @return The {@code Marker} that was added to the map
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+ @Deprecated
@NonNull
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions,
final MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) {
@@ -1248,8 +1254,11 @@ public final class MapboxMap {
*
* @param markerViewOptions A list of markerView options objects that defines how to render the markers
* @return A list of the {@code MarkerView}s that were added to the map
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
+ @Deprecated
public List addMarkerViews(@NonNull List extends
BaseMarkerViewOptions> markerViewOptions) {
return annotationManager.addMarkerViews(markerViewOptions, this);
@@ -1260,8 +1269,11 @@ public final class MapboxMap {
*
* @param rect the rectangular area on the map to query for markerViews
* @return A list of the markerViews that were found in the rectangle
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
@NonNull
+ @Deprecated
public List getMarkerViewsInRect(@NonNull RectF rect) {
return annotationManager.getMarkerViewsInRect(rect);
}
@@ -2314,7 +2326,10 @@ public final class MapboxMap {
* Interface definition for a callback to be invoked when an MarkerView will be shown.
*
* @param the instance type of MarkerView
+ * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android
+ * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java
*/
+ @Deprecated
public abstract static class MarkerViewAdapter {
private Context context;
--
cgit v1.2.1
From d73e33eb62858b91212314d97bfe9cf49e857141 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Thu, 28 Sep 2017 09:34:58 +0200
Subject: [android] fix snapshot builds (#10079)
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index a9ec9fae88..a3dab0eff6 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.2.0-beta-SNAPSHOT
+VERSION_NAME=5.2.0-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
@@ -17,4 +17,5 @@ POM_PACKAGING=aar
# Only build native dependencies for the current ABI
# See https://code.google.com/p/android/issues/detail?id=221098#c20
-android.buildOnlyTargetAbi=true
\ No newline at end of file
+android.buildOnlyTargetAbi=true
+
--
cgit v1.2.1
From cef386ca471ac703aaf97b9bad9b0505eb1dd37f Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 28 Sep 2017 08:05:12 +0200
Subject: [android] - make OfflineTilePyramidRegionDefinition parceable
---
.../OfflineTilePyramidRegionDefinition.java | 54 +++++++++++++++++++++-
1 file changed, 52 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java
index f8ec0f3d39..2a32f0bdd6 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineTilePyramidRegionDefinition.java
@@ -1,5 +1,9 @@
package com.mapbox.mapboxsdk.offline;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
/**
@@ -13,7 +17,7 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
*
* pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0.
*/
-public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefinition {
+public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefinition, Parcelable {
private String styleURL;
private LatLngBounds bounds;
@@ -22,7 +26,7 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti
private float pixelRatio;
/**
- * Constructor
+ * Constructor to create an OfflineTilePyramidDefinition from parameters.
*
* @param styleURL the style
* @param bounds the bounds
@@ -40,6 +44,22 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti
this.pixelRatio = pixelRatio;
}
+ /**
+ * Constructor to create an OfflineTilePyramidDefinition from a Parcel.
+ *
+ * @param parcel the parcel to create the OfflineTilePyramidDefinition from
+ */
+ public OfflineTilePyramidRegionDefinition(Parcel parcel) {
+ this.styleURL = parcel.readString();
+ this.bounds = new LatLngBounds.Builder()
+ .include(new LatLng(parcel.readDouble(), parcel.readDouble()))
+ .include(new LatLng(parcel.readDouble(), parcel.readDouble()))
+ .build();
+ this.minZoom = parcel.readDouble();
+ this.maxZoom = parcel.readDouble();
+ this.pixelRatio = parcel.readFloat();
+ }
+
/*
* Getters
*/
@@ -64,4 +84,34 @@ public class OfflineTilePyramidRegionDefinition implements OfflineRegionDefiniti
return pixelRatio;
}
+ /*
+ * Parceable
+ */
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(styleURL);
+ dest.writeDouble(bounds.getLatNorth());
+ dest.writeDouble(bounds.getLonEast());
+ dest.writeDouble(bounds.getLatSouth());
+ dest.writeDouble(bounds.getLonWest());
+ dest.writeDouble(minZoom);
+ dest.writeDouble(maxZoom);
+ dest.writeFloat(pixelRatio);
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public OfflineTilePyramidRegionDefinition createFromParcel(Parcel in) {
+ return new OfflineTilePyramidRegionDefinition(in);
+ }
+
+ public OfflineTilePyramidRegionDefinition[] newArray(int size) {
+ return new OfflineTilePyramidRegionDefinition[size];
+ }
+ };
}
--
cgit v1.2.1
From 94312acd8b00bd05009f21ed8e0bbfaec65d5a01 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Fri, 6 Oct 2017 13:47:01 +0200
Subject: [android] - allow multiple listeners for camera events, deprecate old
api
---
.../mapboxsdk/maps/CameraChangeDispatcher.java | 74 ++++++++++++++++++
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 84 +++++++++++++++++++++
.../mapboxsdk/maps/CameraChangeDispatcherTest.java | 87 ++++++++++++++++++++++
3 files changed, 245 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcherTest.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
index 6f7d7c0080..e3ebc74ae3 100644
--- 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
@@ -1,5 +1,10 @@
package com.mapbox.mapboxsdk.maps;
+import android.support.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener;
@@ -10,6 +15,11 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
private boolean idle = true;
+ private final List onCameraMoveStartedListenerList = new ArrayList<>();
+ private final List onCameraMoveCanceledListenerList = new ArrayList<>();
+ private final List onCameraMoveListenerList = new ArrayList<>();
+ private final List onCameraIdleListenerList = new ArrayList<>();
+
private OnCameraMoveStartedListener onCameraMoveStartedListener;
private OnCameraMoveCanceledListener onCameraMoveCanceledListener;
private OnCameraMoveListener onCameraMoveListener;
@@ -41,6 +51,12 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
if (onCameraMoveStartedListener != null) {
onCameraMoveStartedListener.onCameraMoveStarted(reason);
}
+
+ if (!onCameraMoveStartedListenerList.isEmpty()) {
+ for (OnCameraMoveStartedListener cameraMoveStartedListener : onCameraMoveStartedListenerList) {
+ cameraMoveStartedListener.onCameraMoveStarted(reason);
+ }
+ }
}
@Override
@@ -48,6 +64,12 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
if (onCameraMoveListener != null && !idle) {
onCameraMoveListener.onCameraMove();
}
+
+ if (!onCameraMoveListenerList.isEmpty()) {
+ for (OnCameraMoveListener cameraMoveListener : onCameraMoveListenerList) {
+ cameraMoveListener.onCameraMove();
+ }
+ }
}
@Override
@@ -55,6 +77,12 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
if (onCameraMoveCanceledListener != null && !idle) {
onCameraMoveCanceledListener.onCameraMoveCanceled();
}
+
+ if (!onCameraMoveCanceledListenerList.isEmpty()) {
+ for (OnCameraMoveCanceledListener cameraMoveCanceledListener : onCameraMoveCanceledListenerList) {
+ cameraMoveCanceledListener.onCameraMoveCanceled();
+ }
+ }
}
@Override
@@ -64,6 +92,52 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
if (onCameraIdleListener != null) {
onCameraIdleListener.onCameraIdle();
}
+
+ if (!onCameraIdleListenerList.isEmpty()) {
+ for (OnCameraIdleListener cameraIdleListener : onCameraIdleListenerList) {
+ cameraIdleListener.onCameraIdle();
+ }
+ }
+ }
+ }
+
+ void addOnCameraIdleListener(@NonNull OnCameraIdleListener listener) {
+ onCameraIdleListenerList.add(listener);
+ }
+
+ void removeOnCameraIdleListener(@NonNull OnCameraIdleListener listener) {
+ if (onCameraIdleListenerList.contains(listener)) {
+ onCameraIdleListenerList.remove(listener);
+ }
+ }
+
+ void addOnCameraMoveCancelListener(OnCameraMoveCanceledListener listener) {
+ onCameraMoveCanceledListenerList.add(listener);
+ }
+
+ void removeOnCameraMoveCancelListener(OnCameraMoveCanceledListener listener) {
+ if (onCameraMoveCanceledListenerList.contains(listener)) {
+ onCameraMoveCanceledListenerList.remove(listener);
+ }
+ }
+
+ void addOnCameraMoveStartedListener(OnCameraMoveStartedListener listener) {
+ onCameraMoveStartedListenerList.add(listener);
+ }
+
+ void removeOnCameraMoveStartedListener(OnCameraMoveStartedListener listener) {
+ if (onCameraMoveStartedListenerList.contains(listener)) {
+ onCameraMoveStartedListenerList.remove(listener);
+ }
+ }
+
+ void addOnCameraMoveListener(OnCameraMoveListener listener) {
+ onCameraMoveListenerList.add(listener);
+ }
+
+ void removeOnCameraMoveListener(OnCameraMoveListener listener) {
+ if (onCameraMoveListenerList.contains(listener)) {
+ onCameraMoveListenerList.remove(listener);
}
}
}
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 0c820d844c..a5c49dae7c 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
@@ -1725,38 +1725,122 @@ public final class MapboxMap {
* Sets a callback that is invoked when camera movement has ended.
*
* @param listener the listener to notify
+ * @deprecated use {@link #addOnCameraIdleListener(OnCameraIdleListener)}
+ * and {@link #removeOnCameraIdleListener(OnCameraIdleListener)} instead
*/
+ @Deprecated
public void setOnCameraIdleListener(@Nullable OnCameraIdleListener listener) {
cameraChangeDispatcher.setOnCameraIdleListener(listener);
}
+ /**
+ * Adds a callback that is invoked when camera movement has ended.
+ *
+ * @param listener the listener to notify
+ */
+ public void addOnCameraIdleListener(@Nullable OnCameraIdleListener listener) {
+ cameraChangeDispatcher.addOnCameraIdleListener(listener);
+ }
+
+ /**
+ * Removes a callback that is invoked when camera movement has ended.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeOnCameraIdleListener(@Nullable OnCameraIdleListener listener) {
+ cameraChangeDispatcher.removeOnCameraIdleListener(listener);
+ }
+
/**
* Sets a callback that is invoked when camera movement was cancelled.
*
* @param listener the listener to notify
+ * @deprecated use {@link #addOnCameraMoveCancelListener(OnCameraMoveCanceledListener)} and
+ * {@link #removeOnCameraMoveCancelListener(OnCameraMoveCanceledListener)} instead
*/
+ @Deprecated
public void setOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) {
cameraChangeDispatcher.setOnCameraMoveCanceledListener(listener);
}
+ /**
+ * Adds a callback that is invoked when camera movement was cancelled.
+ *
+ * @param listener the listener to notify
+ */
+ public void addOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) {
+ cameraChangeDispatcher.addOnCameraMoveCancelListener(listener);
+ }
+
+ /**
+ * Removes a callback that is invoked when camera movement was cancelled.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeOnCameraMoveCancelListener(@Nullable OnCameraMoveCanceledListener listener) {
+ cameraChangeDispatcher.removeOnCameraMoveCancelListener(listener);
+ }
+
/**
* Sets a callback that is invoked when camera movement has started.
*
* @param listener the listener to notify
+ * @deprecated use {@link #addOnCameraMoveStartedListener(OnCameraMoveStartedListener)} and
+ * {@link #removeOnCameraMoveStartedListener(OnCameraMoveStartedListener)} instead
*/
+ @Deprecated
public void setOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
cameraChangeDispatcher.setOnCameraMoveStartedListener(listener);
}
+ /**
+ * Adds a callback that is invoked when camera movement has started.
+ *
+ * @param listener the listener to notify
+ */
+ public void addOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
+ cameraChangeDispatcher.addOnCameraMoveStartedListener(listener);
+ }
+
+ /**
+ * Removes a callback that is invoked when camera movement has started.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeOnCameraMoveStartedListener(@Nullable OnCameraMoveStartedListener listener) {
+ cameraChangeDispatcher.removeOnCameraMoveStartedListener(listener);
+ }
+
/**
* Sets a callback that is invoked when camera position changes.
*
* @param listener the listener to notify
+ * @deprecated use {@link #addOnCameraMoveListener(OnCameraMoveListener)} and
+ * {@link #removeOnCameraMoveListener(OnCameraMoveListener)}instead
*/
+ @Deprecated
public void setOnCameraMoveListener(@Nullable OnCameraMoveListener listener) {
cameraChangeDispatcher.setOnCameraMoveListener(listener);
}
+ /**
+ * Adds a callback that is invoked when camera position changes.
+ *
+ * @param listener the listener to notify
+ */
+ public void addOnCameraMoveListener(@Nullable OnCameraMoveListener listener) {
+ cameraChangeDispatcher.addOnCameraMoveListener(listener);
+ }
+
+ /**
+ * Removes a callback that is invoked when camera position changes.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeOnCameraMoveListener(@Nullable OnCameraMoveListener listener) {
+ cameraChangeDispatcher.removeOnCameraMoveListener(listener);
+ }
+
/**
* Sets a callback that's invoked on every frame rendered to the map view.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcherTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcherTest.java
new file mode 100644
index 0000000000..090d274fe7
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/CameraChangeDispatcherTest.java
@@ -0,0 +1,87 @@
+package com.mapbox.mapboxsdk.maps;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class CameraChangeDispatcherTest {
+
+ @Test
+ public void testSetCameraIdleListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraIdleListener listener = mock(MapboxMap.OnCameraIdleListener.class);
+ dispatcher.setOnCameraIdleListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraIdle();
+ verify(listener).onCameraIdle();
+ }
+
+ @Test
+ public void testSetCameraMoveStartedListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveStartedListener listener = mock(MapboxMap.OnCameraMoveStartedListener.class);
+ dispatcher.setOnCameraMoveStartedListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ verify(listener).onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ }
+
+ @Test
+ public void testSetCameraMoveCancelListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveCanceledListener listener = mock(MapboxMap.OnCameraMoveCanceledListener.class);
+ dispatcher.setOnCameraMoveCanceledListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraMoveCanceled();
+ verify(listener).onCameraMoveCanceled();
+ }
+
+ @Test
+ public void testSetCameraMoveListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveListener listener = mock(MapboxMap.OnCameraMoveListener.class);
+ dispatcher.setOnCameraMoveListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraMove();
+ verify(listener).onCameraMove();
+ }
+
+ @Test
+ public void testAddCameraIdleListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraIdleListener listener = mock(MapboxMap.OnCameraIdleListener.class);
+ dispatcher.addOnCameraIdleListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraIdle();
+ verify(listener).onCameraIdle();
+ }
+
+ @Test
+ public void testAddCameraMoveStartedListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveStartedListener listener = mock(MapboxMap.OnCameraMoveStartedListener.class);
+ dispatcher.addOnCameraMoveStartedListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ verify(listener).onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ }
+
+ @Test
+ public void testAddCameraMoveCancelListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveCanceledListener listener = mock(MapboxMap.OnCameraMoveCanceledListener.class);
+ dispatcher.addOnCameraMoveCancelListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraMoveCanceled();
+ verify(listener).onCameraMoveCanceled();
+ }
+
+ @Test
+ public void testAddCameraMoveListener() {
+ CameraChangeDispatcher dispatcher = new CameraChangeDispatcher();
+ MapboxMap.OnCameraMoveListener listener = mock(MapboxMap.OnCameraMoveListener.class);
+ dispatcher.addOnCameraMoveListener(listener);
+ dispatcher.onCameraMoveStarted(MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE);
+ dispatcher.onCameraMove();
+ verify(listener).onCameraMove();
+ }
+}
--
cgit v1.2.1
From a1aed6f095c6326fa9c8a8ecff591c5a03144070 Mon Sep 17 00:00:00 2001
From: Antonio Zugaldia
Date: Mon, 9 Oct 2017 10:07:09 -0400
Subject: Provide a fallback method to load the native library (#10154)
* provide a fallback method to load the native library
* move context call inside loader to avoid changing method signature
---
.../java/com/mapbox/mapboxsdk/LibraryLoader.java | 28 +++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
index 8a75176ccd..35b1e7cf6a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
@@ -1,15 +1,41 @@
package com.mapbox.mapboxsdk;
+import android.content.Context;
+
+import java.io.File;
+
+import timber.log.Timber;
+
/**
* Centralises the knowledge about "mapbox-gl" library loading.
*/
public class LibraryLoader {
+ private static final String LIBRARY_NAME = "libmapbox-gl.so";
+
/**
* Loads "libmapbox-gl.so" native shared library.
*/
public static void load() {
- System.loadLibrary("mapbox-gl");
+ try {
+ System.loadLibrary("mapbox-gl");
+ } catch (UnsatisfiedLinkError error) {
+ Context context = Mapbox.getApplicationContext();
+ if (context != null) {
+ Timber.d("Loading %s from internal storage.", LIBRARY_NAME);
+ System.load(getLibraryLocation(context).getAbsolutePath());
+ }
+ }
}
+ /**
+ * Returns a file in the app internal storage that may contain a locally cached copy
+ * of the Mapbox native library.
+ *
+ * @param context The application context
+ * @return a file object
+ */
+ public static File getLibraryLocation(Context context) {
+ return new File(context.getFilesDir(), LIBRARY_NAME);
+ }
}
--
cgit v1.2.1
From 9048d6cfd0f794af3f3810a880adb0d2fc691552 Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Thu, 5 Oct 2017 15:04:50 +0200
Subject: [android] - fine tune gesture zoom & rotation
---
.../gesturedetectors/TwoFingerGestureDetector.java | 4 +++-
.../java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 14 ++++++--------
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 12 ++++++++++--
3 files changed, 19 insertions(+), 11 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
index db492b6556..3d28c2295d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
@@ -54,7 +54,9 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
ViewConfiguration config = ViewConfiguration.get(context);
- edgeSlop = config.getScaledEdgeSlop();
+ // lowering the edgeSlop allows to execute gesture faster
+ // https://github.com/mapbox/mapbox-gl-native/issues/10102
+ edgeSlop = config.getScaledEdgeSlop() / 3.0f;
}
@Override
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 2394e52193..f309570a7b 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
@@ -526,10 +526,10 @@ final class MapGestureDetector {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
- private static final long ROTATE_INVOKE_WAIT_TIME = 1500;
+ private static final long ROTATE_INVOKE_WAIT_TIME = 750;
+ private static final float ROTATE_INVOKE_ANGLE = 17.5f;
private long beginTime = 0;
- private float totalAngle = 0.0f;
private boolean started = false;
// Called when two fingers first touch the screen
@@ -551,7 +551,6 @@ final class MapGestureDetector {
public void onRotateEnd(RotateGestureDetector detector) {
// notify camera change listener
beginTime = 0;
- totalAngle = 0.0f;
started = false;
}
@@ -573,8 +572,8 @@ final class MapGestureDetector {
// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
- totalAngle += detector.getRotationDegreesDelta();
- if (totalAngle > 35.0f || totalAngle < -35.0f) {
+ float angle = detector.getRotationDegreesDelta();
+ if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) {
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
MapboxEvent.GESTURE_ROTATION_START, transform));
@@ -589,9 +588,8 @@ final class MapGestureDetector {
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
- // Get rotate value
- double bearing = transform.getRawBearing();
- bearing += detector.getRotationDegreesDelta();
+ // Calculate map bearing value
+ double bearing = transform.getRawBearing() + angle;
// Rotate the map
if (focalPoint != null) {
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 12e4c675ee..a93d05eaed 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
@@ -382,6 +382,10 @@ public class MapView extends FrameLayout {
@Override
public boolean onTouchEvent(MotionEvent event) {
+ if (!isMapInitialized()) {
+ return super.onTouchEvent(event);
+ }
+
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mapZoomButtonController.setVisible(true);
}
@@ -471,7 +475,7 @@ public class MapView extends FrameLayout {
if (destroyed) {
return;
}
- if (nativeMapView == null) {
+ if (!isMapInitialized()) {
mapboxMapOptions.styleUrl(url);
return;
}
@@ -488,7 +492,7 @@ public class MapView extends FrameLayout {
return;
}
- if (!isInEditMode() && nativeMapView != null) {
+ if (!isInEditMode() && isMapInitialized()) {
nativeMapView.resizeView(width, height);
}
}
@@ -574,6 +578,10 @@ public class MapView extends FrameLayout {
}
}
+ private boolean isMapInitialized() {
+ return nativeMapView != null;
+ }
+
MapboxMap getMapboxMap() {
return mapboxMap;
}
--
cgit v1.2.1
From 24bd336b88b4f2dae25277efeeb36a96061139a3 Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Mon, 9 Oct 2017 11:50:48 -0700
Subject: [android][ios][macOS] Implement bindings for
`Map::cameraForGeometry`. On macOS, also added -[MGLMapView setCamera:
withDuration: animationTimingFunction: edgePadding: completionHandler:] for
parity with iOS
---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 25 ++++++++++++++++++++++
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 10 +++++++++
2 files changed, 35 insertions(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 a5c49dae7c..6a88470ee7 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
@@ -44,6 +44,7 @@ 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;
+import com.mapbox.services.commons.geojson.Geometry;
import java.lang.reflect.ParameterizedType;
import java.util.List;
@@ -1666,6 +1667,30 @@ public final class MapboxMap {
return cameraPosition;
}
+ /**
+ * Get a camera position that fits a provided shape with a given bearing and padding.
+ *
+ * @param geometry the geometry to constrain the map with
+ * @param bearing the bearing at which to compute the geometry's bounds
+ * @param padding the padding to apply to the bounds
+ * @return the camera position that fits the bounds and padding
+ */
+ public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) {
+ // calculate and set additional bounds padding
+ int[] mapPadding = getPadding();
+ for (int i = 0; i < padding.length; i++) {
+ padding[i] = mapPadding[i] + padding[i];
+ }
+ projection.setContentPadding(padding, myLocationViewSettings.getPadding());
+
+ // get padded camera position from LatLngBounds
+ CameraPosition cameraPosition = nativeMapView.getCameraForGeometry(geometry, bearing);
+
+ // reset map padding
+ setPadding(mapPadding);
+ return cameraPosition;
+ }
+
//
// Padding
//
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 3ce6aab581..bd8a54783e 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
@@ -29,6 +29,7 @@ import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException;
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.utils.BitmapUtils;
import com.mapbox.services.commons.geojson.Feature;
+import com.mapbox.services.commons.geojson.Geometry;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -232,6 +233,13 @@ final class NativeMapView {
return nativeGetCameraForLatLngBounds(latLngBounds);
}
+ public CameraPosition getCameraForGeometry(Geometry geometry, double bearing) {
+ if (isDestroyedOn("getCameraForGeometry")) {
+ return null;
+ }
+ return nativeGetCameraForGeometry(geometry, bearing);
+ }
+
public void resetPosition() {
if (isDestroyedOn("resetPosition")) {
return;
@@ -873,6 +881,8 @@ final class NativeMapView {
private native CameraPosition nativeGetCameraForLatLngBounds(LatLngBounds latLngBounds);
+ private native CameraPosition nativeGetCameraForGeometry(Geometry geometry, double bearing);
+
private native void nativeResetPosition();
private native double nativeGetPitch();
--
cgit v1.2.1
From ff03a75da41be5fd7063e2dc7ef8c281656a8c4c Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Fri, 6 Oct 2017 16:29:49 +0200
Subject: [android] - hold off handling hover events untill map has been
created
---
.../main/java/com/mapbox/mapboxsdk/maps/MapView.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 a93d05eaed..260933ffa1 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
@@ -2,8 +2,8 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.PointF;
-import android.os.Build;
import android.opengl.GLSurfaceView;
+import android.os.Build;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.IntDef;
@@ -47,9 +47,9 @@ import javax.microedition.khronos.opengles.GL10;
import timber.log.Timber;
+import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
-import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
/**
*
@@ -382,7 +382,7 @@ public class MapView extends FrameLayout {
@Override
public boolean onTouchEvent(MotionEvent event) {
- if (!isMapInitialized()) {
+ if (!isMapInitialized() || !isZoomButtonControllerInitialized()) {
return super.onTouchEvent(event);
}
@@ -419,6 +419,10 @@ public class MapView extends FrameLayout {
@Override
public boolean onHoverEvent(MotionEvent event) {
+ if (!isZoomButtonControllerInitialized()) {
+ return super.onHoverEvent(event);
+ }
+
switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
case MotionEvent.ACTION_HOVER_MOVE:
@@ -506,7 +510,9 @@ public class MapView extends FrameLayout {
@CallSuper
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- mapZoomButtonController.setVisible(false);
+ if (isZoomButtonControllerInitialized()) {
+ mapZoomButtonController.setVisible(false);
+ }
}
// Called when view is hidden and shown
@@ -516,7 +522,7 @@ public class MapView extends FrameLayout {
return;
}
- if (mapZoomButtonController != null) {
+ if (isZoomButtonControllerInitialized()) {
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
}
}
@@ -582,6 +588,10 @@ public class MapView extends FrameLayout {
return nativeMapView != null;
}
+ private boolean isZoomButtonControllerInitialized() {
+ return mapZoomButtonController != null;
+ }
+
MapboxMap getMapboxMap() {
return mapboxMap;
}
--
cgit v1.2.1
From 6d673799f8e632e5566197433f67c39fd3663565 Mon Sep 17 00:00:00 2001
From: Antonio Zugaldia
Date: Wed, 11 Oct 2017 09:06:58 -0400
Subject: [android] Revert native loading behavior (#10180)
---
.../java/com/mapbox/mapboxsdk/LibraryLoader.java | 23 +---------------------
1 file changed, 1 insertion(+), 22 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
index 35b1e7cf6a..a024f0ab70 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/LibraryLoader.java
@@ -1,9 +1,5 @@
package com.mapbox.mapboxsdk;
-import android.content.Context;
-
-import java.io.File;
-
import timber.log.Timber;
/**
@@ -11,8 +7,6 @@ import timber.log.Timber;
*/
public class LibraryLoader {
- private static final String LIBRARY_NAME = "libmapbox-gl.so";
-
/**
* Loads "libmapbox-gl.so" native shared library.
*/
@@ -20,22 +14,7 @@ public class LibraryLoader {
try {
System.loadLibrary("mapbox-gl");
} catch (UnsatisfiedLinkError error) {
- Context context = Mapbox.getApplicationContext();
- if (context != null) {
- Timber.d("Loading %s from internal storage.", LIBRARY_NAME);
- System.load(getLibraryLocation(context).getAbsolutePath());
- }
+ Timber.e(error, "Failed to load native shared library.");
}
}
-
- /**
- * Returns a file in the app internal storage that may contain a locally cached copy
- * of the Mapbox native library.
- *
- * @param context The application context
- * @return a file object
- */
- public static File getLibraryLocation(Context context) {
- return new File(context.getFilesDir(), LIBRARY_NAME);
- }
}
--
cgit v1.2.1
From d95079a0f94fdc9294c41739fa993eb48ea2971d Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Tue, 12 Sep 2017 18:40:25 +0200
Subject: [android] - use FileSource pause and resume when
foregrounding/backgrounding app
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +++
.../mapbox/mapboxsdk/offline/OfflineRegion.java | 9 ++++++++
.../com/mapbox/mapboxsdk/storage/FileSource.java | 24 +++++++++++++++++++++-
3 files changed, 35 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 260933ffa1..9182b952e6 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
@@ -33,6 +33,7 @@ import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
+import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
import java.lang.annotation.Retention;
@@ -335,6 +336,7 @@ public class MapView extends FrameLayout {
@UiThread
public void onStart() {
ConnectivityReceiver.instance(getContext()).activate();
+ FileSource.getInstance(getContext()).activate();
if (mapboxMap != null) {
mapboxMap.onStart();
}
@@ -367,6 +369,7 @@ public class MapView extends FrameLayout {
public void onStop() {
mapboxMap.onStop();
ConnectivityReceiver.instance(getContext()).deactivate();
+ FileSource.getInstance(getContext()).deactivate();
}
/**
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 f210729037..1b9a156352 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
@@ -300,10 +300,19 @@ public class OfflineRegion {
/**
* Pause or resume downloading of regional resources.
+ *
+ * After a download has been completed, you are required to reset the state of the region to STATE_INACTIVE.
+ *
*
* @param state the download state
*/
public void setDownloadState(@DownloadState int state) {
+ if (state == STATE_ACTIVE) {
+ fileSource.activate();
+ } else {
+ fileSource.deactivate();
+ }
+
this.state = state;
setOfflineRegionDownloadState(state);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
index a968cdf192..41dc449b50 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
@@ -72,7 +72,7 @@ public class FileSource {
MapboxConstants.KEY_META_DATA_SET_STORAGE_EXTERNAL,
MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL);
} catch (PackageManager.NameNotFoundException exception) {
- Timber.e(exception,"Failed to read the package metadata: ");
+ Timber.e(exception, "Failed to read the package metadata: ");
} catch (Exception exception) {
Timber.e(exception, "Failed to read the storage key: ");
}
@@ -119,17 +119,39 @@ public class FileSource {
}
private long nativePtr;
+ private long activeCounter;
+ private boolean wasPaused;
private FileSource(String cachePath, AssetManager assetManager) {
initialize(Mapbox.getAccessToken(), cachePath, assetManager);
}
+ public void activate() {
+ activeCounter++;
+ if (activeCounter == 1 && wasPaused) {
+ wasPaused = false;
+ resume();
+ }
+ }
+
+ public void deactivate() {
+ activeCounter--;
+ if (activeCounter == 0) {
+ wasPaused = true;
+ pause();
+ }
+ }
+
public native void setAccessToken(@NonNull String accessToken);
public native String getAccessToken();
public native void setApiBaseUrl(String baseUrl);
+ private native void resume();
+
+ private native void pause();
+
/**
* Sets a callback for transforming URLs requested from the internet
*
--
cgit v1.2.1
From a221b459e99dd15e0731d79622df815a0f86613b Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 18 Oct 2017 10:55:45 +0200
Subject: [android] - execute notifying listeners when not idle
---
.../mapbox/mapboxsdk/maps/CameraChangeDispatcher.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
(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
index e3ebc74ae3..cf780dcc3f 100644
--- 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
@@ -25,18 +25,22 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
private OnCameraMoveListener onCameraMoveListener;
private OnCameraIdleListener onCameraIdleListener;
+ @Deprecated
void setOnCameraMoveStartedListener(OnCameraMoveStartedListener onCameraMoveStartedListener) {
this.onCameraMoveStartedListener = onCameraMoveStartedListener;
}
+ @Deprecated
void setOnCameraMoveCanceledListener(OnCameraMoveCanceledListener onCameraMoveCanceledListener) {
this.onCameraMoveCanceledListener = onCameraMoveCanceledListener;
}
+ @Deprecated
void setOnCameraMoveListener(OnCameraMoveListener onCameraMoveListener) {
this.onCameraMoveListener = onCameraMoveListener;
}
+ @Deprecated
void setOnCameraIdleListener(OnCameraIdleListener onCameraIdleListener) {
this.onCameraIdleListener = onCameraIdleListener;
}
@@ -46,12 +50,14 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
if (!idle) {
return;
}
-
idle = false;
+
+ // deprecated API
if (onCameraMoveStartedListener != null) {
onCameraMoveStartedListener.onCameraMoveStarted(reason);
}
+ // new API
if (!onCameraMoveStartedListenerList.isEmpty()) {
for (OnCameraMoveStartedListener cameraMoveStartedListener : onCameraMoveStartedListenerList) {
cameraMoveStartedListener.onCameraMoveStarted(reason);
@@ -61,11 +67,13 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
@Override
public void onCameraMove() {
+ // deprecated API
if (onCameraMoveListener != null && !idle) {
onCameraMoveListener.onCameraMove();
}
- if (!onCameraMoveListenerList.isEmpty()) {
+ // new API
+ if (!onCameraMoveListenerList.isEmpty() && !idle) {
for (OnCameraMoveListener cameraMoveListener : onCameraMoveListenerList) {
cameraMoveListener.onCameraMove();
}
@@ -74,11 +82,13 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
@Override
public void onCameraMoveCanceled() {
+ // deprecated API
if (onCameraMoveCanceledListener != null && !idle) {
onCameraMoveCanceledListener.onCameraMoveCanceled();
}
- if (!onCameraMoveCanceledListenerList.isEmpty()) {
+ // new API
+ if (!onCameraMoveCanceledListenerList.isEmpty() && !idle) {
for (OnCameraMoveCanceledListener cameraMoveCanceledListener : onCameraMoveCanceledListenerList) {
cameraMoveCanceledListener.onCameraMoveCanceled();
}
@@ -89,10 +99,12 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
public void onCameraIdle() {
if (!idle) {
idle = true;
+ // deprecated API
if (onCameraIdleListener != null) {
onCameraIdleListener.onCameraIdle();
}
+ // new API
if (!onCameraIdleListenerList.isEmpty()) {
for (OnCameraIdleListener cameraIdleListener : onCameraIdleListenerList) {
cameraIdleListener.onCameraIdle();
--
cgit v1.2.1
From 24fc48982a635578db3f2262b9f56a27c53688cb Mon Sep 17 00:00:00 2001
From: Tobrun Van Nuland
Date: Wed, 18 Oct 2017 13:06:36 +0200
Subject: [android] - wire up MapZoomButtonController with camera change events
---
.../main/java/com/mapbox/mapboxsdk/maps/MapView.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 9182b952e6..309090ed3f 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
@@ -191,8 +191,10 @@ public class MapView extends FrameLayout {
annotationManager, cameraChangeDispatcher);
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);
+ // overlain zoom buttons
mapZoomButtonController = new MapZoomButtonController(new ZoomButtonsController(this));
- MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform);
+ MapZoomControllerListener zoomListener = new MapZoomControllerListener(mapGestureDetector, uiSettings, transform,
+ cameraChangeDispatcher, getWidth(), getHeight());
mapZoomButtonController.bind(uiSettings, zoomListener);
compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraChangeDispatcher));
@@ -880,16 +882,23 @@ public class MapView extends FrameLayout {
}
}
- private class MapZoomControllerListener implements ZoomButtonsController.OnZoomListener {
+ private static class MapZoomControllerListener implements ZoomButtonsController.OnZoomListener {
private final MapGestureDetector mapGestureDetector;
private final UiSettings uiSettings;
private final Transform transform;
+ private final CameraChangeDispatcher cameraChangeDispatcher;
+ private final float mapWidth;
+ private final float mapHeight;
- MapZoomControllerListener(MapGestureDetector detector, UiSettings uiSettings, Transform transform) {
+ MapZoomControllerListener(MapGestureDetector detector, UiSettings uiSettings, Transform transform,
+ CameraChangeDispatcher dispatcher, float mapWidth, float mapHeight) {
this.mapGestureDetector = detector;
this.uiSettings = uiSettings;
this.transform = transform;
+ this.cameraChangeDispatcher = dispatcher;
+ this.mapWidth = mapWidth;
+ this.mapHeight = mapHeight;
}
// Not used
@@ -902,6 +911,7 @@ public class MapView extends FrameLayout {
@Override
public void onZoom(boolean zoomIn) {
if (uiSettings.isZoomGesturesEnabled()) {
+ cameraChangeDispatcher.onCameraMoveStarted(CameraChangeDispatcher.REASON_API_ANIMATION);
onZoom(zoomIn, mapGestureDetector.getFocalPoint());
}
}
@@ -910,7 +920,7 @@ public class MapView extends FrameLayout {
if (focalPoint != null) {
transform.zoom(zoomIn, focalPoint);
} else {
- PointF centerPoint = new PointF(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
+ PointF centerPoint = new PointF(mapWidth / 2, mapHeight / 2);
transform.zoom(zoomIn, centerPoint);
}
}
--
cgit v1.2.1
From af904467582e79d8dbf2a405776a81131ff1fa11 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 23 Oct 2017 06:21:26 +0200
Subject: [android] - null check mapboxMap with onStop invocation
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 309090ed3f..f4198cdde7 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
@@ -369,7 +369,10 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onStop() {
- mapboxMap.onStop();
+ if (mapboxMap != null) {
+ // map was destroyed before it was started
+ mapboxMap.onStop();
+ }
ConnectivityReceiver.instance(getContext()).deactivate();
FileSource.getInstance(getContext()).deactivate();
}
--
cgit v1.2.1
From bd06e2f6fa3ca3367b831caeb52ecb6da3f199fd Mon Sep 17 00:00:00 2001
From: Antonio Zugaldia
Date: Thu, 26 Oct 2017 12:57:46 -0400
Subject: [android] - lower amount of external dependencies (#10268)
---
platform/android/MapboxGLAndroidSDK/build.gradle | 5 ++-
.../mapboxsdk/maps/AttributionDialogManager.java | 6 +--
.../mapbox/mapboxsdk/maps/widgets/CompassView.java | 4 +-
.../com/mapbox/mapboxsdk/utils/ColorUtils.java | 48 ++++++++++++++++------
.../src/main/res/values/styles.xml | 6 ---
5 files changed, 44 insertions(+), 25 deletions(-)
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index c96587fce6..19587d0078 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
dependencies {
compile rootProject.ext.dep.supportAnnotations
- compile rootProject.ext.dep.supportV4
- compile rootProject.ext.dep.supportDesign
+ compile rootProject.ext.dep.supportFragmentV4
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
compile(rootProject.ext.dep.lost) {
exclude group: 'com.google.guava'
+ exclude group: 'com.android.support'
}
testCompile rootProject.ext.dep.junit
testCompile rootProject.ext.dep.mockito
@@ -20,6 +20,7 @@ dependencies {
// Mapbox Android Services (Telemetry support)
compile(rootProject.ext.dep.mapboxAndroidTelemetry) {
transitive = true
+ exclude group: 'com.android.support'
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
index 5113a0cc73..9ccff387f5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java
@@ -1,12 +1,12 @@
package com.mapbox.mapboxsdk.maps;
+import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
-import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@@ -56,7 +56,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
private void showAttributionDialog() {
attributionKeys = attributionMap.keySet().toArray(new String[attributionMap.size()]);
- AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.mapbox_AlertDialogStyle);
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionKeys), this);
builder.show();
@@ -77,7 +77,7 @@ class AttributionDialogManager implements View.OnClickListener, DialogInterface.
}
private void showTelemetryDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.mapbox_AlertDialogStyle);
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionTelemetryTitle);
builder.setMessage(R.string.mapbox_attributionTelemetryMessage);
builder.setPositiveButton(R.string.mapbox_attributionTelemetryPositive, new DialogInterface.OnClickListener() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
index 45f72af1c5..1e604c9bef 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/CompassView.java
@@ -6,10 +6,10 @@ import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
-import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
@@ -22,7 +22,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
* use {@link com.mapbox.mapboxsdk.maps.UiSettings}.
*
*/
-public final class CompassView extends AppCompatImageView implements Runnable {
+public final class CompassView extends ImageView implements Runnable {
public static final long TIME_WAIT_IDLE = 500;
public static final long TIME_MAP_NORTH_ANIMATION = 150;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
index 14b18b00dc..1c0e439afc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ColorUtils.java
@@ -5,6 +5,7 @@ import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
+import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.graphics.drawable.DrawableCompat;
@@ -30,10 +31,15 @@ public class ColorUtils {
*/
@ColorInt
public static int getPrimaryColor(@NonNull Context context) {
- TypedValue typedValue = new TypedValue();
- Resources.Theme theme = context.getTheme();
- theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
- return typedValue.data;
+ try {
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = context.getTheme();
+ int id = context.getResources().getIdentifier("colorPrimary", "attrs", context.getPackageName());
+ theme.resolveAttribute(id, typedValue, true);
+ return typedValue.data;
+ } catch (Exception exception) {
+ return getColorCompat(context, R.color.mapbox_blue);
+ }
}
/**
@@ -44,10 +50,15 @@ public class ColorUtils {
*/
@ColorInt
public static int getPrimaryDarkColor(@NonNull Context context) {
- TypedValue typedValue = new TypedValue();
- Resources.Theme theme = context.getTheme();
- theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
- return typedValue.data;
+ try {
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = context.getTheme();
+ int id = context.getResources().getIdentifier("colorPrimaryDark", "attrs", context.getPackageName());
+ theme.resolveAttribute(id, typedValue, true);
+ return typedValue.data;
+ } catch (Exception exception) {
+ return getColorCompat(context, R.color.mapbox_blue);
+ }
}
/**
@@ -58,10 +69,15 @@ public class ColorUtils {
*/
@ColorInt
public static int getAccentColor(@NonNull Context context) {
- TypedValue typedValue = new TypedValue();
- Resources.Theme theme = context.getTheme();
- theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
- return typedValue.data;
+ try {
+ TypedValue typedValue = new TypedValue();
+ Resources.Theme theme = context.getTheme();
+ int id = context.getResources().getIdentifier("colorAccent", "attrs", context.getPackageName());
+ theme.resolveAttribute(id, typedValue, true);
+ return typedValue.data;
+ } catch (Exception exception) {
+ return getColorCompat(context, R.color.mapbox_gray);
+ }
}
/**
@@ -122,4 +138,12 @@ public class ColorUtils {
throw new ConversionException("Not a valid rgb/rgba value");
}
}
+
+ private static int getColorCompat(Context context, int id) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ return context.getResources().getColor(id, context.getTheme());
+ } else {
+ return context.getResources().getColor(id);
+ }
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
deleted file mode 100644
index eba1fb3a7d..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
--
cgit v1.2.1
From edf399f1b74eb57a9782f981eb5c94ac0e13afaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?=
Date: Fri, 27 Oct 2017 15:47:10 -0700
Subject: [android, ios, macos] Added Bulgarian localization
---
.../MapboxGLAndroidSDK/src/main/res/values-bg/strings.xml | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-bg/strings.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-bg/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-bg/strings.xml
new file mode 100644
index 0000000000..262e94f368
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-bg/strings.xml
@@ -0,0 +1,15 @@
+
+
+ Компас на картата. Активирай, за да насочиш картата на север.
+ Иконка функции. Активирай, за да покажеш диалог функции.
+ Изглед локация. Това показва местоположението ти на картата.
+ Показва карта създадена с Mapbox. Скролни с два пръста. Мащабирай с два пръста.
+ Mapbox Android SDK
+ Направи Mapbox картите по-добри.
+ Помагаш OpenStreetMap и Mapbox картите да станат по-добри, като предоставяш анонимни данни за потребление.
+ Съгласявам се
+ Не се съгласявам
+ Повече инфо
+ Предоставените OfflineRegionDefinition не пасват в границите на света: %s
+
+
--
cgit v1.2.1
From 72a6eb8b5c317e4cc3d30a998af3ba09a2fc5138 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?=
Date: Fri, 27 Oct 2017 15:49:07 -0700
Subject: [android, ios, macos] Added Hungarian localization
Added a Hungarian localization to the Android SDK. Updated the iOS and macOS SDK Hungarian localization.
---
.../MapboxGLAndroidSDK/src/main/res/values-hu/strings.xml | 13 +++++++++++++
1 file changed, 13 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/res/values-hu/strings.xml
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-hu/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-hu/strings.xml
new file mode 100644
index 0000000000..520edb2733
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-hu/strings.xml
@@ -0,0 +1,13 @@
+
+
+ Hely nézet. Megmutatja, hol vagy a térképen.
+ Egy Mapbox-szal készült térkép megjelenítése. Húzd két ujjadat a görgetéshez. Csippentsd össze a nagyításhoz.
+ Mapbox Android SDK
+ Tedd jobbá a Mapbox térképeket
+ Segítesz az OpenStreetMap és Mapbox térképek jobbá tételében névtelen felhasználási adatok elküldésével.
+ Egyetértek
+ Nem értek egyet
+ Több infó
+ A megadott OfflineRegionDefinition nem fér bele a világ kereteibe: %s
+
+
--
cgit v1.2.1
From 5893af7f245311d89b8d2ccd0fc0278394acbf83 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 24 Oct 2017 09:36:23 -0700
Subject: [android] - move shape annotation click handling to core
---
.../mapbox/mapboxsdk/maps/AnnotationManager.java | 87 +++++++---------------
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +-
.../com/mapbox/mapboxsdk/maps/MarkerContainer.java | 9 +--
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 18 +++++
.../mapboxsdk/maps/ShapeAnnotationContainer.java | 38 ++++++++++
.../mapbox/mapboxsdk/maps/ShapeAnnotations.java | 13 ++++
6 files changed, 100 insertions(+), 68 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java
(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 c09c926eb5..9f256c341b 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
@@ -21,7 +21,6 @@ import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
-import com.mapbox.services.commons.geojson.Feature;
import java.util.ArrayList;
import java.util.List;
@@ -41,7 +40,6 @@ import timber.log.Timber;
*/
class AnnotationManager {
- private static final String LAYER_ID_SHAPE_ANNOTATIONS = "com.mapbox.annotations.shape.";
private static final long NO_ANNOTATION_ID = -1;
private final MapView mapView;
@@ -50,7 +48,6 @@ class AnnotationManager {
private final MarkerViewManager markerViewManager;
private final LongSparseArray annotationsArray;
private final List selectedMarkers = new ArrayList<>();
- private final List shapeAnnotationIds = new ArrayList<>();
private MapboxMap mapboxMap;
private MapboxMap.OnMarkerClickListener onMarkerClickListener;
@@ -58,13 +55,14 @@ class AnnotationManager {
private MapboxMap.OnPolylineClickListener onPolylineClickListener;
private Annotations annotations;
+ private ShapeAnnotations shapeAnnotations;
private Markers markers;
private Polygons polygons;
private Polylines polylines;
AnnotationManager(NativeMapView view, MapView mapView, LongSparseArray annotationsArray,
MarkerViewManager markerViewManager, IconManager iconManager, Annotations annotations,
- Markers markers, Polygons polygons, Polylines polylines) {
+ Markers markers, Polygons polygons, Polylines polylines, ShapeAnnotations shapeAnnotations) {
this.mapView = mapView;
this.annotationsArray = annotationsArray;
this.markerViewManager = markerViewManager;
@@ -73,6 +71,7 @@ class AnnotationManager {
this.markers = markers;
this.polygons = polygons;
this.polylines = polylines;
+ this.shapeAnnotations = shapeAnnotations;
if (view != null) {
// null checking needed for unit tests
view.addOnMapChangedListener(markerViewManager);
@@ -122,9 +121,6 @@ class AnnotationManager {
// do icon cleanup
iconManager.iconCleanup(marker.getIcon());
}
- } else {
- // instanceOf Polygon/Polyline
- shapeAnnotationIds.remove(annotation.getId());
}
annotations.removeBy(annotation);
}
@@ -143,9 +139,6 @@ class AnnotationManager {
} else {
iconManager.iconCleanup(marker.getIcon());
}
- } else {
- // instanceOf Polygon/Polyline
- shapeAnnotationIds.remove(annotation.getId());
}
}
annotations.removeBy(annotationList);
@@ -167,9 +160,6 @@ class AnnotationManager {
} else {
iconManager.iconCleanup(marker.getIcon());
}
- } else {
- // instanceOf Polygon/Polyline
- shapeAnnotationIds.remove(annotation.getId());
}
}
annotations.removeAll();
@@ -227,17 +217,11 @@ class AnnotationManager {
//
Polygon addPolygon(@NonNull PolygonOptions polygonOptions, @NonNull MapboxMap mapboxMap) {
- Polygon polygon = polygons.addBy(polygonOptions, mapboxMap);
- shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polygon.getId());
- return polygon;
+ return polygons.addBy(polygonOptions, mapboxMap);
}
List addPolygons(@NonNull List polygonOptionsList, @NonNull MapboxMap mapboxMap) {
- List polygonList = polygons.addBy(polygonOptionsList, mapboxMap);
- for (Polygon polygon : polygonList) {
- shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polygon.getId());
- }
- return polygonList;
+ return polygons.addBy(polygonOptionsList, mapboxMap);
}
void updatePolygon(Polygon polygon) {
@@ -257,17 +241,11 @@ class AnnotationManager {
//
Polyline addPolyline(@NonNull PolylineOptions polylineOptions, @NonNull MapboxMap mapboxMap) {
- Polyline polyline = polylines.addBy(polylineOptions, mapboxMap);
- shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polyline.getId());
- return polyline;
+ return polylines.addBy(polylineOptions, mapboxMap);
}
List addPolylines(@NonNull List polylineOptionsList, @NonNull MapboxMap mapboxMap) {
- List polylineList = polylines.addBy(polylineOptionsList, mapboxMap);
- for (Polyline polyline : polylineList) {
- shapeAnnotationIds.add(LAYER_ID_SHAPE_ANNOTATIONS + polyline.getId());
- }
- return polylineList;
+ return polylines.addBy(polylineOptionsList, mapboxMap);
}
void updatePolyline(Polyline polyline) {
@@ -397,11 +375,11 @@ class AnnotationManager {
//
boolean onTap(PointF tapPoint) {
- if (!shapeAnnotationIds.isEmpty()) {
- ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
- long shapeAnnotationId = new ShapeAnnotationHitResolver(mapboxMap).execute(shapeAnnotationHit);
- if (shapeAnnotationId != NO_ANNOTATION_ID) {
- handleClickForShapeAnnotation(shapeAnnotationId);
+ ShapeAnnotationHit shapeAnnotationHit = getShapeAnnotationHitFromTap(tapPoint);
+ Annotation annotation = new ShapeAnnotationHitResolver(shapeAnnotations).execute(shapeAnnotationHit);
+ if (annotation != null) {
+ if (handleClickForShapeAnnotation(annotation)) {
+ return true;
}
}
@@ -418,16 +396,18 @@ class AnnotationManager {
tapPoint.x + touchTargetSide,
tapPoint.y + touchTargetSide
);
- return new ShapeAnnotationHit(tapRect, shapeAnnotationIds.toArray(new String[shapeAnnotationIds.size()]));
+ return new ShapeAnnotationHit(tapRect);
}
- private void handleClickForShapeAnnotation(long shapeAnnotationId) {
- Annotation annotation = getAnnotation(shapeAnnotationId);
+ private boolean handleClickForShapeAnnotation(Annotation annotation) {
if (annotation instanceof Polygon && onPolygonClickListener != null) {
onPolygonClickListener.onPolygonClick((Polygon) annotation);
+ return true;
} else if (annotation instanceof Polyline && onPolylineClickListener != null) {
onPolylineClickListener.onPolylineClick((Polyline) annotation);
+ return true;
}
+ return false;
}
private MarkerHit getMarkerHitFromTouchArea(PointF tapPoint) {
@@ -470,28 +450,19 @@ class AnnotationManager {
private static class ShapeAnnotationHitResolver {
- private MapboxMap mapboxMap;
-
- ShapeAnnotationHitResolver(MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- }
+ private ShapeAnnotations shapeAnnotations;
- public long execute(ShapeAnnotationHit shapeHit) {
- long foundAnnotationId = NO_ANNOTATION_ID;
- List features = mapboxMap.queryRenderedFeatures(shapeHit.tapPoint, shapeHit.layerIds);
- if (!features.isEmpty()) {
- foundAnnotationId = getIdFromFeature(features.get(0));
- }
- return foundAnnotationId;
+ ShapeAnnotationHitResolver(ShapeAnnotations shapeAnnotations) {
+ this.shapeAnnotations = shapeAnnotations;
}
- private long getIdFromFeature(Feature feature) {
- try {
- return Long.valueOf(feature.getId());
- } catch (NumberFormatException exception) {
- Timber.e(exception, "Couldn't parse feature id to a long, with id: %s", feature.getId());
- return NO_ANNOTATION_ID;
+ public Annotation execute(ShapeAnnotationHit shapeHit) {
+ Annotation foundAnnotation = null;
+ List annotations = shapeAnnotations.obtainAllIn(shapeHit.tapPoint);
+ if (annotations.size() > 0) {
+ foundAnnotation = annotations.get(0);
}
+ return foundAnnotation;
}
}
@@ -567,11 +538,9 @@ class AnnotationManager {
private static class ShapeAnnotationHit {
private final RectF tapPoint;
- private final String[] layerIds;
- ShapeAnnotationHit(RectF tapRect, String[] layerIds) {
- this.tapPoint = tapRect;
- this.layerIds = layerIds;
+ ShapeAnnotationHit(RectF tapPoint) {
+ this.tapPoint = tapPoint;
}
}
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 f4198cdde7..de27964a5d 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
@@ -175,8 +175,9 @@ public class MapView extends FrameLayout {
Markers markers = new MarkerContainer(nativeMapView, this, annotationsArray, iconManager, markerViewManager);
Polygons polygons = new PolygonContainer(nativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray);
+ ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray);
AnnotationManager annotationManager = new AnnotationManager(nativeMapView, this, annotationsArray,
- markerViewManager, iconManager, annotations, markers, polygons, polylines);
+ markerViewManager, iconManager, annotations, markers, polygons, polylines, shapeAnnotations);
Transform transform = new Transform(nativeMapView, annotationManager.getMarkerViewManager(), trackingSettings,
cameraChangeDispatcher);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
index 072382ce07..2c2f07a112 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java
@@ -98,15 +98,8 @@ class MarkerContainer implements Markers {
@NonNull
@Override
public List obtainAllIn(@NonNull RectF rectangle) {
- // convert Rectangle to be density depedent
- float pixelRatio = nativeMapView.getPixelRatio();
- RectF rect = new RectF(rectangle.left / pixelRatio,
- rectangle.top / pixelRatio,
- rectangle.right / pixelRatio,
- rectangle.bottom / pixelRatio);
-
+ RectF rect = nativeMapView.getDensityDependantRectangle(rectangle);
long[] ids = nativeMapView.queryPointAnnotations(rect);
-
List idsList = new ArrayList<>(ids.length);
for (long id : ids) {
idsList.add(id);
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 bd8a54783e..db0b14a4c7 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
@@ -468,6 +468,13 @@ final class NativeMapView {
return nativeQueryPointAnnotations(rect);
}
+ public long[] queryShapeAnnotations(RectF rectF) {
+ if (isDestroyedOn("queryShapeAnnotations")) {
+ return new long[] {};
+ }
+ return nativeQueryShapeAnnotations(rectF);
+ }
+
public void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels) {
if (isDestroyedOn("addAnnotationIcon")) {
return;
@@ -825,6 +832,15 @@ final class NativeMapView {
return pixelRatio;
}
+ RectF getDensityDependantRectangle(final RectF rectangle) {
+ return new RectF(
+ rectangle.left / pixelRatio,
+ rectangle.top / pixelRatio,
+ rectangle.right / pixelRatio,
+ rectangle.bottom / pixelRatio
+ );
+ }
+
//
// Callbacks
//
@@ -927,6 +943,8 @@ final class NativeMapView {
private native long[] nativeQueryPointAnnotations(RectF rect);
+ private native long[] nativeQueryShapeAnnotations(RectF rect);
+
private native void nativeAddAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels);
private native void nativeRemoveAnnotationIcon(String symbol);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java
new file mode 100644
index 0000000000..6ded2f32fb
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotationContainer.java
@@ -0,0 +1,38 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.graphics.RectF;
+import android.support.v4.util.LongSparseArray;
+
+import com.mapbox.mapboxsdk.annotations.Annotation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class ShapeAnnotationContainer implements ShapeAnnotations {
+
+ private final NativeMapView nativeMapView;
+ private final LongSparseArray annotations;
+
+ ShapeAnnotationContainer(NativeMapView nativeMapView, LongSparseArray annotations) {
+ this.nativeMapView = nativeMapView;
+ this.annotations = annotations;
+ }
+
+ @Override
+ public List obtainAllIn(RectF rectangle) {
+ RectF rect = nativeMapView.getDensityDependantRectangle(rectangle);
+ long[] annotationIds = nativeMapView.queryShapeAnnotations(rect);
+ return getAnnotationsFromIds(annotationIds);
+ }
+
+ private List getAnnotationsFromIds(long[] annotationIds) {
+ List shapeAnnotations = new ArrayList<>();
+ for (long annotationId : annotationIds) {
+ Annotation annotation = annotations.get(annotationId);
+ if (annotation != null) {
+ shapeAnnotations.add(annotation);
+ }
+ }
+ return shapeAnnotations;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java
new file mode 100644
index 0000000000..f9b2ca10db
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/ShapeAnnotations.java
@@ -0,0 +1,13 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.graphics.RectF;
+
+import com.mapbox.mapboxsdk.annotations.Annotation;
+
+import java.util.List;
+
+interface ShapeAnnotations {
+
+ List obtainAllIn(RectF rectF);
+
+}
--
cgit v1.2.1
From b8d5798beacfa7d3d8d904336005ac2976f02ff3 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Mon, 30 Oct 2017 11:22:47 -0700
Subject: [android] - avoid null pointer if map wasn't initalised when saving
instance state
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 de27964a5d..e53d564cd7 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
@@ -329,8 +329,10 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onSaveInstanceState(@NonNull Bundle outState) {
- outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
- mapboxMap.onSaveInstanceState(outState);
+ if (mapboxMap != null) {
+ outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
+ mapboxMap.onSaveInstanceState(outState);
+ }
}
/**
--
cgit v1.2.1
From 8c4e2f0886b090946e7c4c0210379080b6bd567c Mon Sep 17 00:00:00 2001
From: Ramin Mirsharifi
Date: Tue, 3 Oct 2017 17:51:55 +0330
Subject: [android] - Add touch velocity effects on scale gesture.
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 48 +++++++++++++++++++---
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 11 +++++
2 files changed, 54 insertions(+), 5 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 f309570a7b..bdc0938456 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
@@ -3,12 +3,14 @@ package com.mapbox.mapboxsdk.maps;
import android.content.Context;
import android.graphics.PointF;
import android.location.Location;
+import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
+import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
@@ -59,6 +61,10 @@ final class MapGestureDetector {
private boolean recentScaleGestureOccurred;
private long scaleBeginTime;
+ private VelocityTracker velocityTracker = null;
+ private boolean wasZoomingIn = false;
+ private final Handler handler = new Handler();
+
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
CameraChangeDispatcher cameraChangeDispatcher) {
@@ -153,6 +159,12 @@ final class MapGestureDetector {
// Handle two finger tap
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
+ if (velocityTracker == null) {
+ velocityTracker = VelocityTracker.obtain();
+ } else {
+ velocityTracker.clear();
+ }
+ velocityTracker.addMovement(event);
// First pointer down, reset scaleGestureOccurred, used to avoid triggering a fling after a scale gesture #7666
recentScaleGestureOccurred = false;
transform.setGestureInProgress(true);
@@ -180,7 +192,8 @@ final class MapGestureDetector {
boolean isTap = tapInterval <= ViewConfiguration.getTapTimeout();
boolean inProgress = rotateGestureDetector.isInProgress()
|| scaleGestureDetector.isInProgress()
- || shoveGestureDetector.isInProgress();
+ || shoveGestureDetector.isInProgress()
+ || scaleGestureOccurred;
if (twoTap && isTap && !inProgress) {
if (focalPoint != null) {
@@ -203,11 +216,23 @@ final class MapGestureDetector {
twoTap = false;
transform.setGestureInProgress(false);
+ if (velocityTracker != null) {
+ velocityTracker.recycle();
+ }
+ velocityTracker = null;
break;
case MotionEvent.ACTION_CANCEL:
twoTap = false;
transform.setGestureInProgress(false);
+ if (velocityTracker != null) {
+ velocityTracker.recycle();
+ }
+ velocityTracker = null;
+ break;
+ case MotionEvent.ACTION_MOVE:
+ velocityTracker.addMovement(event);
+ velocityTracker.computeCurrentVelocity(1000);
break;
}
@@ -450,10 +475,22 @@ final class MapGestureDetector {
// Called when fingers leave screen
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
- scaleGestureOccurred = false;
- scaleBeginTime = 0;
- scaleFactor = 1.0f;
- cameraChangeDispatcher.onCameraIdle();
+ double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity());
+ if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING) {
+ long animationTime = (long)(Math.log(velocityXY) * 66);
+ transform.zoom(wasZoomingIn, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ scaleGestureOccurred = false;
+ }
+ }, animationTime);
+ } else {
+ scaleGestureOccurred = false;
+ scaleBeginTime = 0;
+ scaleFactor = 1.0f;
+ cameraChangeDispatcher.onCameraIdle();
+ }
}
// Called each time a finger moves
@@ -500,6 +537,7 @@ final class MapGestureDetector {
trackingSettings.resetTrackingModesIfRequired(!quickZoom, false, false);
// Scale the map
+ wasZoomingIn = (Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2)) >= 0;
if (focalPoint != null) {
// arround user provided focal point
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2), focalPoint.x, focalPoint.y);
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 6f63c2eba8..026564902c 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
@@ -221,6 +221,17 @@ final class Transform implements MapView.OnMapChangedListener {
}
}
+ void zoom(boolean zoomIn, @NonNull PointF focalPoint,long duration) {
+ CameraPosition cameraPosition = invalidateCameraPosition();
+ if (cameraPosition != null) {
+ int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
+ setZoom(newZoom, focalPoint, duration);
+ } else {
+ // we are not transforming, notify about being idle
+ cameraChangeDispatcher.onCameraIdle();
+ }
+ }
+
void setZoom(double zoom, @NonNull PointF focalPoint) {
setZoom(zoom, focalPoint, 0);
}
--
cgit v1.2.1
From c351f65c0923c2e21ea0467239d46a343af6aa9c Mon Sep 17 00:00:00 2001
From: Ramin Mirsharifi
Date: Sat, 7 Oct 2017 13:33:44 +0330
Subject: [android] - Add touch velocity effects on scale gesture. Fine tune.
---
.../java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 13 +++++++++----
.../src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | 4 ++--
2 files changed, 11 insertions(+), 6 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 bdc0938456..95f34b9b70 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
@@ -419,7 +419,7 @@ final class MapGestureDetector {
return false;
}
- if (tiltGestureOccurred) {
+ if (tiltGestureOccurred || scaleGestureOccurred) {
return false;
}
@@ -476,9 +476,14 @@ final class MapGestureDetector {
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity());
- if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING) {
+ if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING / 2) {
long animationTime = (long)(Math.log(velocityXY) * 66);
- transform.zoom(wasZoomingIn, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
+ double zoomAddition = (float) (Math.log(velocityXY) / 7.7);
+ if (!wasZoomingIn) {
+ zoomAddition = -zoomAddition;
+ }
+ scaleGestureOccurred = true;
+ transform.zoom(zoomAddition, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
handler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -509,7 +514,7 @@ final class MapGestureDetector {
// Also ignore small scales
long time = detector.getEventTime();
long interval = time - scaleBeginTime;
- if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
+ if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout() / 3)) {
return false;
}
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 026564902c..e18e7f91c6 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
@@ -221,10 +221,10 @@ final class Transform implements MapView.OnMapChangedListener {
}
}
- void zoom(boolean zoomIn, @NonNull PointF focalPoint,long duration) {
+ void zoom(double zoomAddition, @NonNull PointF focalPoint,long duration) {
CameraPosition cameraPosition = invalidateCameraPosition();
if (cameraPosition != null) {
- int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1));
+ int newZoom = (int) Math.round(cameraPosition.zoom + zoomAddition);
setZoom(newZoom, focalPoint, duration);
} else {
// we are not transforming, notify about being idle
--
cgit v1.2.1
From 9b41791dec22dc5cc83a38aa00b7fe99f1c673ed Mon Sep 17 00:00:00 2001
From: Ramin Mirsharifi
Date: Mon, 9 Oct 2017 16:49:35 +0330
Subject: [android] - Add angular velocity effect on rotation gesture.
---
.../gesturedetectors/TwoFingerGestureDetector.java | 4 +-
.../mapboxsdk/constants/MapboxConstants.java | 4 +-
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 233 +++++++++++++++------
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 6 +-
5 files changed, 179 insertions(+), 71 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
index 3d28c2295d..db492b6556 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java
@@ -54,9 +54,7 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector {
ViewConfiguration config = ViewConfiguration.get(context);
- // lowering the edgeSlop allows to execute gesture faster
- // https://github.com/mapbox/mapbox-gl-native/issues/10102
- edgeSlop = config.getScaledEdgeSlop() / 3.0f;
+ edgeSlop = config.getScaledEdgeSlop();
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
index 97a9ea94ee..fc448ccf7b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -80,12 +80,12 @@ public class MapboxConstants {
/**
* The currently used minimun scale factor to clamp to when a quick zoom gesture occurs
*/
- public static final float MINIMUM_SCALE_FACTOR_CLAMP = 0.65f;
+ public static final float MINIMUM_SCALE_FACTOR_CLAMP = 0.00f;
/**
* The currently used maximum scale factor to clamp to when a quick zoom gesture occurs
*/
- public static final float MAXIMUM_SCALE_FACTOR_CLAMP = 1.35f;
+ public static final float MAXIMUM_SCALE_FACTOR_CLAMP = 0.45f;
/**
* Fragment Argument Key for MapboxMapOptions
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 95f34b9b70..4120e164a4 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
@@ -1,12 +1,15 @@
package com.mapbox.mapboxsdk.maps;
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.PointF;
import android.location.Location;
-import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ScaleGestureDetectorCompat;
+import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
@@ -59,11 +62,13 @@ final class MapGestureDetector {
private boolean scaleGestureOccurred;
private boolean recentScaleGestureOccurred;
+ private boolean scaleAnimating;
private long scaleBeginTime;
- private VelocityTracker velocityTracker = null;
- private boolean wasZoomingIn = false;
- private final Handler handler = new Handler();
+ private VelocityTracker velocityTracker;
+ private boolean wasZoomingIn;
+ private boolean wasClockwiseRotating;
+ private boolean rotateGestureOccurred;
MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings,
TrackingSettings trackingSettings, AnnotationManager annotationManager,
@@ -192,8 +197,7 @@ final class MapGestureDetector {
boolean isTap = tapInterval <= ViewConfiguration.getTapTimeout();
boolean inProgress = rotateGestureDetector.isInProgress()
|| scaleGestureDetector.isInProgress()
- || shoveGestureDetector.isInProgress()
- || scaleGestureOccurred;
+ || shoveGestureDetector.isInProgress();
if (twoTap && isTap && !inProgress) {
if (focalPoint != null) {
@@ -419,7 +423,7 @@ final class MapGestureDetector {
return false;
}
- if (tiltGestureOccurred || scaleGestureOccurred) {
+ if (tiltGestureOccurred) {
return false;
}
@@ -455,7 +459,11 @@ final class MapGestureDetector {
*/
private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
+ private static final int ANIMATION_TIME_MULTIPLIER = 77;
+ private static final double ZOOM_DISTANCE_DIVIDER = 5;
+
private float scaleFactor = 1.0f;
+ private PointF scalePointBegin;
// Called when two fingers first touch the screen
@Override
@@ -465,6 +473,7 @@ final class MapGestureDetector {
}
recentScaleGestureOccurred = true;
+ scalePointBegin = new PointF(detector.getFocusX(), detector.getFocusY());
scaleBeginTime = detector.getEventTime();
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
@@ -472,32 +481,6 @@ final class MapGestureDetector {
return true;
}
- // Called when fingers leave screen
- @Override
- public void onScaleEnd(ScaleGestureDetector detector) {
- double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity());
- if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING / 2) {
- long animationTime = (long)(Math.log(velocityXY) * 66);
- double zoomAddition = (float) (Math.log(velocityXY) / 7.7);
- if (!wasZoomingIn) {
- zoomAddition = -zoomAddition;
- }
- scaleGestureOccurred = true;
- transform.zoom(zoomAddition, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime);
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- scaleGestureOccurred = false;
- }
- }, animationTime);
- } else {
- scaleGestureOccurred = false;
- scaleBeginTime = 0;
- scaleFactor = 1.0f;
- cameraChangeDispatcher.onCameraIdle();
- }
- }
-
// Called each time a finger moves
// Called for pinch zooms and quickzooms/quickscales
@Override
@@ -506,6 +489,7 @@ final class MapGestureDetector {
return super.onScale(detector);
}
+ wasZoomingIn = (Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2)) >= 0;
if (tiltGestureOccurred) {
return false;
}
@@ -514,13 +498,13 @@ final class MapGestureDetector {
// Also ignore small scales
long time = detector.getEventTime();
long interval = time - scaleBeginTime;
- if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout() / 3)) {
+ if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) {
return false;
}
// If scale is large enough ignore a tap
scaleFactor *= detector.getScaleFactor();
- if ((scaleFactor > 1.05f) || (scaleFactor < 0.95f)) {
+ if ((scaleFactor > 1.1f) || (scaleFactor < 0.9f)) {
// notify camera change listener
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
scaleGestureOccurred = true;
@@ -539,29 +523,87 @@ final class MapGestureDetector {
// make an assumption here; if the zoom center is specified by the gesture, it's NOT going
// to be in the center of the map. Therefore the zoom will translate the map center, so tracking
// should be disabled.
-
trackingSettings.resetTrackingModesIfRequired(!quickZoom, false, false);
// Scale the map
- wasZoomingIn = (Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2)) >= 0;
if (focalPoint != null) {
// arround user provided focal point
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2), focalPoint.x, focalPoint.y);
} else if (quickZoom) {
cameraChangeDispatcher.onCameraMove();
// clamp scale factors we feed to core #7514
- float scaleFactor = MathUtils.clamp(detector.getScaleFactor(),
+ float scaleFactor = detector.getScaleFactor();
+ // around center map
+ double zoomBy = Math.log(scaleFactor) / Math.log(Math.PI / 2);
+ boolean negative = zoomBy < 0;
+ zoomBy = MathUtils.clamp(Math.abs(zoomBy),
MapboxConstants.MINIMUM_SCALE_FACTOR_CLAMP,
MapboxConstants.MAXIMUM_SCALE_FACTOR_CLAMP);
- // around center map
- transform.zoomBy(Math.log(scaleFactor) / Math.log(Math.PI / 2),
- uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
+ transform.zoomBy(negative ? -zoomBy : zoomBy, uiSettings.getWidth() / 2, uiSettings.getHeight() / 2);
+ recentScaleGestureOccurred = true;
} else {
// around gesture
transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2),
- detector.getFocusX(), detector.getFocusY());
+ scalePointBegin.x, scalePointBegin.y);
}
return true;
}
+
+ // Called when fingers leave screen
+ @Override
+ public void onScaleEnd(final ScaleGestureDetector detector) {
+ if (rotateGestureOccurred || quickZoom) {
+ reset();
+ return;
+ }
+
+ double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity());
+ if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING / 2) {
+ scaleAnimating = true;
+ double zoomAddition = calculateScale(velocityXY);
+ double currentZoom = transform.getRawZoom();
+ long animationTime = (long) (Math.log(velocityXY) * ANIMATION_TIME_MULTIPLIER);
+ createScaleAnimator(currentZoom, zoomAddition, animationTime).start();
+ } else if (!scaleAnimating) {
+ reset();
+ }
+ }
+
+ private void reset() {
+ scaleAnimating = false;
+ scaleGestureOccurred = false;
+ scaleBeginTime = 0;
+ scaleFactor = 1.0f;
+ cameraChangeDispatcher.onCameraIdle();
+ }
+
+ private double calculateScale(double velocityXY) {
+ double zoomAddition = (float) (Math.log(velocityXY) / ZOOM_DISTANCE_DIVIDER);
+ if (!wasZoomingIn) {
+ zoomAddition = -zoomAddition;
+ }
+ return zoomAddition;
+ }
+
+ private Animator createScaleAnimator(double currentZoom, double zoomAddition, long animationTime) {
+ ValueAnimator animator = ValueAnimator.ofFloat((float) currentZoom, (float) (currentZoom + zoomAddition));
+ animator.setDuration(animationTime);
+ animator.setInterpolator(new FastOutSlowInInterpolator());
+ animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ transform.setZoom((Float) animation.getAnimatedValue(), scalePointBegin);
+ }
+ });
+ animator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ reset();
+ }
+ });
+ return animator;
+ }
}
/**
@@ -569,11 +611,13 @@ final class MapGestureDetector {
*/
private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener {
- private static final long ROTATE_INVOKE_WAIT_TIME = 750;
- private static final float ROTATE_INVOKE_ANGLE = 17.5f;
+ private static final float ROTATE_INVOKE_ANGLE = 15.30f;
+ private static final float ROTATE_LIMITATION_ANGLE = 3.35f;
+ private static final float ROTATE_LIMITATION_DURATION = ROTATE_LIMITATION_ANGLE * 1.85f;
private long beginTime = 0;
private boolean started = false;
+ private boolean animating = false;
// Called when two fingers first touch the screen
@Override
@@ -589,14 +633,6 @@ final class MapGestureDetector {
return true;
}
- // Called when the fingers leave the screen
- @Override
- public void onRotateEnd(RotateGestureDetector detector) {
- // notify camera change listener
- beginTime = 0;
- started = false;
- }
-
// Called each time one of the two fingers moves
// Called for rotation
@Override
@@ -605,14 +641,6 @@ final class MapGestureDetector {
return false;
}
- // Ignore short touches in case it is a tap
- // Also ignore small rotate
- long time = detector.getEventTime();
- long interval = time - beginTime;
- if (!started && (interval <= ViewConfiguration.getTapTimeout() || isScaleGestureActive(time))) {
- return false;
- }
-
// If rotate is large enough ignore a tap
// Also is zoom already started, don't rotate
float angle = detector.getRotationDegreesDelta();
@@ -627,6 +655,11 @@ final class MapGestureDetector {
return false;
}
+ wasClockwiseRotating = detector.getRotationDegreesDelta() > 0;
+ if (scaleBeginTime != 0) {
+ rotateGestureOccurred = true;
+ }
+
// rotation constitutes translation of anything except the center of
// rotation, so cancel both location and bearing tracking if required
trackingSettings.resetTrackingModesIfRequired(true, true, false);
@@ -645,11 +678,81 @@ final class MapGestureDetector {
return true;
}
- private boolean isScaleGestureActive(long time) {
- long scaleExecutionTime = time - scaleBeginTime;
- boolean scaleGestureStarted = scaleBeginTime != 0;
- boolean scaleOffsetTimeValid = scaleExecutionTime > ROTATE_INVOKE_WAIT_TIME;
- return (scaleGestureStarted && scaleOffsetTimeValid) || scaleGestureOccurred;
+ // Called when the fingers leave the screen
+ @Override
+ public void onRotateEnd(RotateGestureDetector detector) {
+ long interval = detector.getEventTime() - beginTime;
+ if ((!started && (interval <= ViewConfiguration.getTapTimeout())) || scaleAnimating || interval > 500) {
+ reset();
+ return;
+ }
+
+ double angularVelocity = calculateVelocityVector(detector);
+ if (Math.abs(angularVelocity) > 0.001 && rotateGestureOccurred && !animating) {
+ animateRotateVelocity();
+ } else if (!animating) {
+ reset();
+ }
+ }
+
+ private void reset() {
+ beginTime = 0;
+ started = false;
+ animating = false;
+ rotateGestureOccurred = false;
+ }
+
+ private void animateRotateVelocity() {
+ animating = true;
+ double currentRotation = transform.getRawBearing();
+ double rotateAdditionDegrees = calculateVelocityInDegrees();
+ createAnimator(currentRotation, rotateAdditionDegrees).start();
+ }
+
+ private double calculateVelocityVector(RotateGestureDetector detector) {
+ return ((detector.getFocusX() * velocityTracker.getYVelocity())
+ + (detector.getFocusY() * velocityTracker.getXVelocity()))
+ / (Math.pow(detector.getFocusX(), 2) + Math.pow(detector.getFocusY(), 2));
+ }
+
+ private double calculateVelocityInDegrees() {
+ double angleRadians = Math.atan2(velocityTracker.getXVelocity(), velocityTracker.getYVelocity());
+ double angle = angleRadians / (Math.PI / 180);
+ if (angle <= 0) {
+ angle += 360;
+ }
+
+ // limit the angle
+ angle = angle / ROTATE_LIMITATION_ANGLE;
+
+ // correct direction
+ if (!wasClockwiseRotating) {
+ angle = -angle;
+ }
+
+ return angle;
+ }
+
+ private Animator createAnimator(double currentRotation, double rotateAdditionDegrees) {
+ ValueAnimator animator = ValueAnimator.ofFloat(
+ (float) currentRotation,
+ (float) (currentRotation + rotateAdditionDegrees)
+ );
+ animator.setDuration((long) (Math.abs(rotateAdditionDegrees) * ROTATE_LIMITATION_DURATION));
+ animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
+ @Override
+ public void onAnimationUpdate(ValueAnimator animation) {
+ transform.setBearing((Float) animation.getAnimatedValue());
+ }
+ });
+ animator.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ reset();
+ }
+ });
+ return animator;
}
}
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 e53d564cd7..e45e8be6ad 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
@@ -425,6 +425,9 @@ public class MapView extends FrameLayout {
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
+ if (mapGestureDetector == null) {
+ return super.onGenericMotionEvent(event);
+ }
return mapGestureDetector.onGenericMotionEvent(event) || super.onGenericMotionEvent(event);
}
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 e18e7f91c6..c5fd37f21e 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
@@ -210,6 +210,10 @@ final class Transform implements MapView.OnMapChangedListener {
return cameraPosition.zoom;
}
+ double getRawZoom() {
+ return mapView.getZoom();
+ }
+
void zoom(boolean zoomIn, @NonNull PointF focalPoint) {
CameraPosition cameraPosition = invalidateCameraPosition();
if (cameraPosition != null) {
@@ -221,7 +225,7 @@ final class Transform implements MapView.OnMapChangedListener {
}
}
- void zoom(double zoomAddition, @NonNull PointF focalPoint,long duration) {
+ void zoom(double zoomAddition, @NonNull PointF focalPoint, long duration) {
CameraPosition cameraPosition = invalidateCameraPosition();
if (cameraPosition != null) {
int newZoom = (int) Math.round(cameraPosition.zoom + zoomAddition);
--
cgit v1.2.1
From ebe6a30821d244a95f7e631636a25b283b5430be Mon Sep 17 00:00:00 2001
From: Osana Babayan <32496536+osana@users.noreply.github.com>
Date: Tue, 31 Oct 2017 09:23:02 -0700
Subject: [android] Make sure onFinish has new camera position after
camera.move (#10324)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 4 ++++
.../src/main/java/com/mapbox/mapboxsdk/maps/Transform.java | 3 ---
2 files changed, 4 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 6a88470ee7..f3d4a5b3c2 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
@@ -713,6 +713,10 @@ public final class MapboxMap {
// MapChange.REGION_DID_CHANGE_ANIMATED is not called for `jumpTo`
// invalidate camera position to provide OnCameraChange event.
invalidateCameraPosition();
+
+ if (callback != null) {
+ callback.onFinish();
+ }
}
});
}
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 c5fd37f21e..0366e50627 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
@@ -98,9 +98,6 @@ final class Transform implements MapView.OnMapChangedListener {
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
- if (callback != null) {
- callback.onFinish();
- }
cameraChangeDispatcher.onCameraIdle();
}
}
--
cgit v1.2.1
From f578b262820c02b0621b7c512118f92b755cc06d Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 24 Oct 2017 17:43:53 -0700
Subject: [android] - add bulk addImages api on MapboxMap
---
.../main/java/com/mapbox/mapboxsdk/maps/Image.java | 17 ++++++
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 14 ++++-
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 65 ++++++++++++++++++++++
3 files changed, 93 insertions(+), 3 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
new file mode 100644
index 0000000000..b2f6cef3b0
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Image.java
@@ -0,0 +1,17 @@
+package com.mapbox.mapboxsdk.maps;
+
+class Image {
+ private final byte[] buffer;
+ private final float pixelRatio;
+ private final String name;
+ private final int width;
+ private final int height;
+
+ public Image(byte[] buffer, float pixelRatio, String name, int width, int height) {
+ this.buffer = buffer;
+ this.pixelRatio = pixelRatio;
+ this.name = name;
+ this.width = width;
+ this.height = height;
+ }
+}
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 f3d4a5b3c2..ee21ddaaa5 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
@@ -47,6 +47,7 @@ import com.mapbox.services.commons.geojson.Feature;
import com.mapbox.services.commons.geojson.Geometry;
import java.lang.reflect.ParameterizedType;
+import java.util.HashMap;
import java.util.List;
import timber.log.Timber;
@@ -466,6 +467,13 @@ public final class MapboxMap {
nativeMapView.addImage(name, image);
}
+ /**
+ * Adds an images to be used in the map's style
+ */
+ public void addImages(@NonNull HashMap images) {
+ nativeMapView.addImages(images);
+ }
+
/**
* Removes an image from the map's style
*
@@ -1674,9 +1682,9 @@ public final class MapboxMap {
/**
* Get a camera position that fits a provided shape with a given bearing and padding.
*
- * @param geometry the geometry to constrain the map with
- * @param bearing the bearing at which to compute the geometry's bounds
- * @param padding the padding to apply to the bounds
+ * @param geometry the geometry to constrain the map with
+ * @param bearing the bearing at which to compute the geometry's bounds
+ * @param padding the padding to apply to the bounds
* @return the camera position that fits the bounds and padding
*/
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) {
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 db0b14a4c7..8b6bce69e2 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
@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
+import android.os.AsyncTask;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -34,7 +35,9 @@ import com.mapbox.services.commons.geojson.Geometry;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import timber.log.Timber;
@@ -753,6 +756,7 @@ final class NativeMapView {
if (isDestroyedOn("addImage")) {
return;
}
+
// Check/correct config
if (image.getConfig() != Bitmap.Config.ARGB_8888) {
image = image.copy(Bitmap.Config.ARGB_8888, false);
@@ -769,6 +773,14 @@ final class NativeMapView {
nativeAddImage(name, image.getWidth(), image.getHeight(), pixelRatio, buffer.array());
}
+ public void addImages(@NonNull HashMap bitmapHashMap) {
+ if (isDestroyedOn("addImages")) {
+ return;
+ }
+ //noinspection unchecked
+ new BitmapImageConversionTask(this).execute(bitmapHashMap);
+ }
+
public void removeImage(String name) {
if (isDestroyedOn("removeImage")) {
return;
@@ -1024,6 +1036,8 @@ final class NativeMapView {
private native void nativeAddImage(String name, int width, int height, float pixelRatio,
byte[] array);
+ private native void nativeAddImages(Image[] images);
+
private native void nativeRemoveImage(String name);
private native Bitmap nativeGetImage(String name);
@@ -1111,4 +1125,55 @@ final class NativeMapView {
});
}
+
+
+ //
+ // Image conversion
+ //
+
+ private static class BitmapImageConversionTask extends AsyncTask, Void, List> {
+
+ private NativeMapView nativeMapView;
+
+ BitmapImageConversionTask(NativeMapView nativeMapView) {
+ this.nativeMapView = nativeMapView;
+ }
+
+ @Override
+ protected List doInBackground(HashMap... params) {
+ HashMap bitmapHashMap = params[0];
+
+ List images = new ArrayList<>();
+ ByteBuffer buffer;
+ String name;
+ Bitmap bitmap;
+
+ for (Map.Entry stringBitmapEntry : bitmapHashMap.entrySet()) {
+ name = stringBitmapEntry.getKey();
+ bitmap = stringBitmapEntry.getValue();
+
+ if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
+ bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
+ }
+
+ buffer = ByteBuffer.allocate(bitmap.getByteCount());
+ bitmap.copyPixelsToBuffer(buffer);
+
+ float density = bitmap.getDensity() == Bitmap.DENSITY_NONE ? Bitmap.DENSITY_NONE : bitmap.getDensity();
+ float pixelRatio = density / DisplayMetrics.DENSITY_DEFAULT;
+
+ images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight()));
+ }
+
+ return images;
+ }
+
+ @Override
+ protected void onPostExecute(List images) {
+ super.onPostExecute(images);
+ if (nativeMapView != null && !nativeMapView.isDestroyedOn("nativeAddImages")) {
+ nativeMapView.nativeAddImages(images.toArray(new Image[images.size()]));
+ }
+ }
+ }
}
--
cgit v1.2.1
From 9aa2c197cad27efa2be26c50ff1e185860a270a5 Mon Sep 17 00:00:00 2001
From: Osana Babayan <32496536+osana@users.noreply.github.com>
Date: Mon, 30 Oct 2017 16:48:56 -0700
Subject: [android] MapboxMap.animate() and Mapbox.easeCamera() should throw
IllegalArgument (#10321)
if non-positive duration is passed in
---
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 7 ++++
.../com/mapbox/mapboxsdk/maps/MapboxMapTest.java | 47 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 ee21ddaaa5..7988a466be 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
@@ -846,6 +846,10 @@ public final class MapboxMap {
*/
public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
final MapboxMap.CancelableCallback callback, final boolean isDismissable) {
+
+ if (durationMs <= 0) {
+ throw new IllegalArgumentException("Null duration passed into easeCamera");
+ }
new Handler().post(new Runnable() {
@Override
public void run() {
@@ -918,6 +922,9 @@ public final class MapboxMap {
*/
public final void animateCamera(final CameraUpdate update, final int durationMs,
final MapboxMap.CancelableCallback callback) {
+ if (durationMs <= 0) {
+ throw new IllegalArgumentException("Null duration passed into animageCamera");
+ }
new Handler().post(new Runnable() {
@Override
public void run() {
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
new file mode 100644
index 0000000000..5e9f94db28
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -0,0 +1,47 @@
+package com.mapbox.mapboxsdk.maps;
+
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
+import com.mapbox.mapboxsdk.geometry.LatLng;
+import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+
+public class MapboxMapTest {
+
+ private MapboxMap mapboxMap;
+
+ @Before
+ public void beforeTest() {
+
+ mapboxMap = new MapboxMap(mock(NativeMapView.class),
+ mock(Transform.class),
+ mock(UiSettings.class),
+ mock(TrackingSettings.class),
+ mock(MyLocationViewSettings.class),
+ mock(Projection.class),
+ mock(MapboxMap.OnRegisterTouchListener.class),
+ mock(AnnotationManager.class),
+ mock(CameraChangeDispatcher.class));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testAnimateCameraChecksDurationPositive() {
+ mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(30.0, 30.0)),
+ 0, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testEaseCameraChecksDurationPositive() {
+ mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(30.0, 30.0)),
+ 0, null);
+ }
+
+ @After
+ public void afterTest() {
+ mapboxMap = null;
+ }
+}
--
cgit v1.2.1
From 03d3aee6fc3a36e3b98b4692a33179dddeb50032 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 31 Oct 2017 13:18:41 -0700
Subject: [android] - rework ease interactions to take in account possitve
duration requirement
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 8 ++------
.../java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java | 7 +++----
2 files changed, 5 insertions(+), 10 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 7988a466be..6bf8342efb 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
@@ -150,12 +150,8 @@ public final class MapboxMap {
trackingSettings.onRestoreInstanceState(savedInstanceState);
if (cameraPosition != null) {
- easeCamera(CameraUpdateFactory.newCameraPosition(
- new CameraPosition.Builder(cameraPosition).build()),
- 0,
- false,
- null,
- !trackingSettings.isLocationTrackingDisabled()
+ moveCamera(CameraUpdateFactory.newCameraPosition(
+ new CameraPosition.Builder(cameraPosition).build())
);
}
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 983ba2550f..ac91746a2a 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
@@ -49,6 +49,7 @@ import timber.log.Timber;
*
* Use {@link MyLocationViewSettings} to manipulate the state of this view.
*
+ *
* @deprecated use location layer plugin from
* https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
*/
@@ -639,8 +640,7 @@ public class MyLocationView extends View {
if (location != null) {
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
// center map directly
- mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(location)), 0, false /*linear interpolator*/,
- null, true);
+ mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location)));
} else {
// do not use interpolated location from tracking mode
latLng = null;
@@ -1022,8 +1022,7 @@ public class MyLocationView extends View {
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
true);
} else {
- mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), 0, false, null,
- true);
+ mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(builder.build()));
}
}
--
cgit v1.2.1
From fd3587608b950df86809606819e89fbe71139ac3 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 2 Oct 2017 17:22:56 +0300
Subject: [android] map snapshotter - add mutators
---
.../mapboxsdk/snapshotter/MapSnapshotter.java | 34 ++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 72df86d80d..8118f9ad92 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -184,7 +184,7 @@ public class MapSnapshotter {
* Starts loading and rendering the snapshot. The callbacks will be fired
* on the calling thread.
*
- * @param callback the callback to use when the snapshot is ready
+ * @param callback the callback to use when the snapshot is ready
* @param errorHandler the error handler to use on snapshot errors
*/
public void start(@NonNull MapboxMap.SnapshotReadyCallback callback, ErrorHandler errorHandler) {
@@ -197,12 +197,42 @@ public class MapSnapshotter {
nativeStart();
}
+ /**
+ * Updates the snapshotter with a new size
+ *
+ * @param width the width
+ * @param height the height
+ */
+ public native void setSize(int width, int height);
+
+ /**
+ * Updates the snapshotter with a new {@link CameraPosition}
+ *
+ * @param cameraPosition the camera position
+ */
+ public native void setCameraPosition(CameraPosition cameraPosition);
+
+ /**
+ * Updates the snapshotter with a new {@link LatLngBounds}
+ *
+ * @param region the region
+ */
+ public native void setRegion(LatLngBounds region);
+
+ /**
+ * Updates the snapshotter with a new style url
+ *
+ * @param styleUrl the style url
+ */
+ public native void setStyleUrl(String styleUrl);
+
+
/**
* Must be called in on the thread
* the object was created on.
*/
public void cancel() {
- callback = null;
+ reset();
nativeCancel();
}
--
cgit v1.2.1
From 9c3e78a9b95782e8fbf15cf7a4052f46f27922fd Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 9 Oct 2017 16:54:32 +0300
Subject: [android] map snapshotter - wrap snapshot in native peer for access
to the pointFor functionality
---
.../mapbox/mapboxsdk/snapshotter/MapSnapshot.java | 45 ++++++++++++++++++++++
.../mapboxsdk/snapshotter/MapSnapshotter.java | 33 +++++++++++-----
2 files changed, 69 insertions(+), 9 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
new file mode 100644
index 0000000000..2d1412aeda
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
@@ -0,0 +1,45 @@
+package com.mapbox.mapboxsdk.snapshotter;
+
+import android.graphics.Bitmap;
+import android.graphics.PointF;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+
+/**
+ * A completed snapshot.
+ *
+ * @see MapSnapshotter
+ */
+public class MapSnapshot {
+
+ private long nativePtr = 0;
+ private Bitmap bitmap;
+
+ /**
+ * Created from native side
+ */
+ private MapSnapshot(long nativePtr, Bitmap bitmap) {
+ this.nativePtr = nativePtr;
+ this.bitmap = bitmap;
+ }
+
+ /**
+ * @return the bitmap
+ */
+ public Bitmap getBitmap() {
+ return bitmap;
+ }
+
+ /**
+ * Calculate the point in pixels on the Image from geographical coordinates.
+ *
+ * @param latLng the geographical coordinates
+ * @return the point on the image
+ */
+ public native PointF pixelForLatLng(LatLng latLng);
+
+ // Unused, needed for peer binding
+ private native void initialize();
+
+ protected native void finalize();
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 8118f9ad92..37d05fc328 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -12,7 +12,6 @@ import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.storage.FileSource;
/**
@@ -23,11 +22,27 @@ import com.mapbox.mapboxsdk.storage.FileSource;
@UiThread
public class MapSnapshotter {
+ /**
+ * Get notified on snapshot completion.
+ *
+ * @see MapSnapshotter#start(SnapshotReadyCallback, ErrorHandler)
+ */
+ public interface SnapshotReadyCallback {
+
+ /**
+ * Called when the snapshot is complete.
+ *
+ * @param snapshot the snapshot
+ */
+ void onSnapshotReady(MapSnapshot snapshot);
+
+ }
+
/**
* Can be used to get notified of errors
* in snapshot generation
*
- * @see MapSnapshotter#start(MapboxMap.SnapshotReadyCallback, ErrorHandler)
+ * @see MapSnapshotter#start(SnapshotReadyCallback, ErrorHandler)
*/
public interface ErrorHandler {
@@ -46,7 +61,7 @@ public class MapSnapshotter {
private long nativePtr = 0;
private final Context context;
- private MapboxMap.SnapshotReadyCallback callback;
+ private SnapshotReadyCallback callback;
private ErrorHandler errorHandler;
/**
@@ -176,7 +191,7 @@ public class MapSnapshotter {
*
* @param callback the callback to use when the snapshot is ready
*/
- public void start(@NonNull MapboxMap.SnapshotReadyCallback callback) {
+ public void start(@NonNull SnapshotReadyCallback callback) {
this.start(callback, null);
}
@@ -187,7 +202,7 @@ public class MapSnapshotter {
* @param callback the callback to use when the snapshot is ready
* @param errorHandler the error handler to use on snapshot errors
*/
- public void start(@NonNull MapboxMap.SnapshotReadyCallback callback, ErrorHandler errorHandler) {
+ public void start(@NonNull SnapshotReadyCallback callback, ErrorHandler errorHandler) {
if (this.callback != null) {
throw new IllegalStateException("Snapshotter was already started");
}
@@ -247,12 +262,12 @@ public class MapSnapshotter {
* Called by JNI peer when snapshot is ready.
* Always called on the origin (main) thread.
*
- * @param bitmap the generated snapshot
+ * @param snapshot the generated snapshot
*/
- protected void onSnapshotReady(Bitmap bitmap) {
+ protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
- addOverlay(bitmap);
- callback.onSnapshotReady(bitmap);
+ addOverlay(snapshot.getBitmap());
+ callback.onSnapshotReady(snapshot);
reset();
}
}
--
cgit v1.2.1
From 0c5e15e21eb5815f064211226d267e4c6f7fdcf3 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Fri, 27 Oct 2017 20:08:47 +0300
Subject: [android] map snapshotter - expose attributions
---
.../java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
index 2d1412aeda..aefa962402 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
@@ -14,13 +14,15 @@ public class MapSnapshot {
private long nativePtr = 0;
private Bitmap bitmap;
+ private String[] attributions;
/**
* Created from native side
*/
- private MapSnapshot(long nativePtr, Bitmap bitmap) {
+ private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions) {
this.nativePtr = nativePtr;
this.bitmap = bitmap;
+ this.attributions = attributions;
}
/**
@@ -38,6 +40,13 @@ public class MapSnapshot {
*/
public native PointF pixelForLatLng(LatLng latLng);
+ /**
+ * @return The attributions for the sources of this snapshot.
+ */
+ protected String[] getAttributions() {
+ return attributions;
+ }
+
// Unused, needed for peer binding
private native void initialize();
--
cgit v1.2.1
From cb7f6dfaec2f90a81d588c2458e01d2a191f9ba1 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 27 Oct 2017 15:57:35 -0700
Subject: [android] - make snapshot logo optional
---
.../com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java | 11 ++++++++++-
.../mapbox/mapboxsdk/snapshotter/MapSnapshotter.java | 18 +++++++++++++++---
2 files changed, 25 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
index aefa962402..eb4f94c428 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshot.java
@@ -15,14 +15,16 @@ public class MapSnapshot {
private long nativePtr = 0;
private Bitmap bitmap;
private String[] attributions;
+ private boolean showLogo;
/**
* Created from native side
*/
- private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions) {
+ private MapSnapshot(long nativePtr, Bitmap bitmap, String[] attributions, boolean showLogo) {
this.nativePtr = nativePtr;
this.bitmap = bitmap;
this.attributions = attributions;
+ this.showLogo = showLogo;
}
/**
@@ -47,6 +49,13 @@ public class MapSnapshot {
return attributions;
}
+ /**
+ * @return Flag indicating to show the Mapbox logo.
+ */
+ boolean isShowLogo() {
+ return showLogo;
+ }
+
// Unused, needed for peer binding
private native void initialize();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 37d05fc328..00fa0171cd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -74,6 +74,7 @@ public class MapSnapshotter {
private String styleUrl = Style.MAPBOX_STREETS;
private LatLngBounds region;
private CameraPosition cameraPosition;
+ private boolean showLogo = true;
/**
* @param width the width of the image
@@ -123,6 +124,15 @@ public class MapSnapshotter {
return this;
}
+ /**
+ * @param showLogo The flag indicating to show the Mapbox logo.
+ * @return the mutated {@link Options}
+ */
+ public Options withLogo(boolean showLogo) {
+ this.showLogo = showLogo;
+ return this;
+ }
+
/**
* @return the width of the image
*/
@@ -182,7 +192,7 @@ public class MapSnapshotter {
nativeInitialize(this, fileSource, options.pixelRatio, options.width,
options.height, options.styleUrl, options.region, options.cameraPosition,
- programCacheDir);
+ options.showLogo, programCacheDir);
}
/**
@@ -266,7 +276,9 @@ public class MapSnapshotter {
*/
protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
- addOverlay(snapshot.getBitmap());
+ if (snapshot.isShowLogo()) {
+ addOverlay(snapshot.getBitmap());
+ }
callback.onSnapshotReady(snapshot);
reset();
}
@@ -294,7 +306,7 @@ public class MapSnapshotter {
FileSource fileSource, float pixelRatio,
int width, int height, String styleUrl,
LatLngBounds region, CameraPosition position,
- String programCacheDir);
+ boolean showLogo, String programCacheDir);
protected native void nativeStart();
--
cgit v1.2.1
From a5ff277ed98dfc7a21ef92f99567ee5a682a2210 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Sun, 29 Oct 2017 08:01:10 -0700
Subject: [android] - add logo resize to MapSnapshotter
---
.../mapboxsdk/snapshotter/MapSnaphotUtil.java | 29 +++++++++++++++++++
.../mapboxsdk/snapshotter/MapSnapshotter.java | 33 +++++++++++++++++++---
2 files changed, 58 insertions(+), 4 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java
new file mode 100644
index 0000000000..da86dc51fb
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnaphotUtil.java
@@ -0,0 +1,29 @@
+package com.mapbox.mapboxsdk.snapshotter;
+
+import android.graphics.BitmapFactory;
+
+class MapSnaphotUtil {
+
+ static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
+ // Raw height and width of image
+ final int height = options.outHeight;
+ final int width = options.outWidth;
+ int inSampleSize = 1;
+
+ if (height > reqHeight || width > reqWidth) {
+
+ final int halfHeight = height / 2;
+ final int halfWidth = width / 2;
+
+ // Calculate the largest inSampleSize value that is a power of 2 and keeps both
+ // height and width larger than the requested height and width.
+ while ((halfHeight / inSampleSize) >= reqHeight
+ && (halfWidth / inSampleSize) >= reqWidth) {
+ inSampleSize *= 2;
+ }
+ }
+ return inSampleSize;
+ }
+
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 00fa0171cd..5206606c83 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -7,6 +7,7 @@ import android.graphics.Canvas;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
+import android.util.DisplayMetrics;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
@@ -55,7 +56,7 @@ public class MapSnapshotter {
void onError(String error);
}
- private static final int LOGO_MARGIN_PX = 4;
+ private static final int LOGO_MARGIN_DP = 4;
// Holds the pointer to JNI NativeMapView
private long nativePtr = 0;
@@ -262,10 +263,34 @@ public class MapSnapshotter {
}
protected void addOverlay(Bitmap original) {
- float margin = context.getResources().getDisplayMetrics().density * LOGO_MARGIN_PX;
+ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
+ float margin = displayMetrics.density * LOGO_MARGIN_DP;
Canvas canvas = new Canvas(original);
- Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, null);
- canvas.drawBitmap(logo, margin, original.getHeight() - (logo.getHeight() + margin), null);
+
+ // Decode just the boundaries
+ BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
+ bitmapOptions.inJustDecodeBounds = true;
+ BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, bitmapOptions);
+ int srcWidth = bitmapOptions.outWidth;
+ int srcHeight = bitmapOptions.outHeight;
+
+ // Ratio, preferred dimensions and resulting sample size
+ float widthRatio = displayMetrics.widthPixels / original.getWidth();
+ float heightRatio = displayMetrics.heightPixels / original.getHeight();
+ float prefWidth = srcWidth / widthRatio;
+ float prefHeight = srcHeight / heightRatio;
+ int sampleSize = MapSnaphotUtil.calculateInSampleSize(bitmapOptions, (int) prefWidth, (int) prefHeight);
+
+ // Scale bitmap
+ bitmapOptions.inJustDecodeBounds = false;
+ bitmapOptions.inScaled = true;
+ bitmapOptions.inSampleSize = sampleSize;
+ bitmapOptions.inDensity = srcWidth;
+ bitmapOptions.inTargetDensity = (int) prefWidth * bitmapOptions.inSampleSize;
+ Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, bitmapOptions);
+
+ float scaledHeight = bitmapOptions.outHeight * heightRatio / bitmapOptions.inSampleSize;
+ canvas.drawBitmap(logo, margin, original.getHeight() - scaledHeight - margin, null);
}
/**
--
cgit v1.2.1
From e6d50da2c5f30408d8190dadd2d965851dfcb1d1 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 1 Nov 2017 12:32:12 -0700
Subject: [android] - check for possitive animation duration
---
.../src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.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/widgets/MyLocationView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/widgets/MyLocationView.java
index ac91746a2a..8a393ebb1f 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
@@ -1017,7 +1017,7 @@ public class MyLocationView extends View {
// accuracy
updateAccuracy(location);
- if (locationChangeAnimationEnabled) {
+ if (locationChangeAnimationEnabled && animationDuration > 0) {
// ease to new camera position with a linear interpolator
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
true);
--
cgit v1.2.1
From d0d401b007f460337dd9834ce529f34834ee4a60 Mon Sep 17 00:00:00 2001
From: Osana Babayan <32496536+osana@users.noreply.github.com>
Date: Wed, 1 Nov 2017 17:10:49 -0700
Subject: [android] android.hardware.location.gps feature should not be
required (#10347)
---
platform/android/MapboxGLAndroidSDK/src/main/AndroidManifest.xml | 1 +
1 file changed, 1 insertion(+)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDK/src/main/AndroidManifest.xml
index 231e36e092..b61035a008 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
+
--
cgit v1.2.1
From 29a94ae939cf1d81017251ec374e3fff703dc4a6 Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Wed, 1 Nov 2017 18:25:52 -0700
Subject: [android] make location provider optional (#9488) (#10354)
---
platform/android/MapboxGLAndroidSDK/build.gradle | 5 +-
.../com/mapbox/mapboxsdk/EmptyLocationSource.java | 107 +++++++++++++++++++++
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 35 +++++--
.../mapbox/mapboxsdk/location/LocationSource.java | 89 ++++++++++++-----
.../mapbox/mapboxsdk/location/package-info.java | 2 +-
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 2 +-
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 8 +-
.../mapboxsdk/maps/widgets/MyLocationView.java | 59 +++++++-----
.../test/java/com/mapbox/mapboxsdk/MapboxTest.java | 6 +-
9 files changed, 245 insertions(+), 68 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 19587d0078..49806780b5 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -5,8 +5,7 @@ dependencies {
compile rootProject.ext.dep.supportFragmentV4
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
- compile(rootProject.ext.dep.lost) {
- exclude group: 'com.google.guava'
+ provided(rootProject.ext.dep.lost) {
exclude group: 'com.android.support'
}
testCompile rootProject.ext.dep.junit
@@ -22,6 +21,8 @@ dependencies {
transitive = true
exclude group: 'com.android.support'
}
+
+ compile(rootProject.ext.dep.mapboxAndroidCore)
}
android {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
new file mode 100644
index 0000000000..d24ed5a113
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
@@ -0,0 +1,107 @@
+package com.mapbox.mapboxsdk;
+
+
+import android.location.Location;
+import android.support.annotation.Nullable;
+
+import com.mapbox.mapboxsdk.location.LocationSource;
+import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.core.location.LocationEngineListener;
+
+class EmptyLocationSource extends LocationSource {
+
+ /**
+ * Activate the location engine which will connect whichever location provider you are using. You'll need to call
+ * this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
+ */
+ @Override
+ public void activate() {
+ // Intentionally left empty
+ }
+
+ /**
+ * Disconnect the location engine which is useful when you no longer need location updates or requesting the users
+ * {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates
+ * using {@link LocationEngine#removeLocationUpdates()}.
+ */
+ @Override
+ public void deactivate() {
+ // Intentionally left empty
+ }
+
+ /**
+ * Check if your location provider has been activated/connected. This is mainly used internally but is also useful in
+ * the rare case when you'd like to know if your location engine is connected or not.
+ *
+ * @return boolean true if the location engine has been activated/connected, else false.
+ */
+ @Override
+ public boolean isConnected() {
+ return false;
+ }
+
+ /**
+ * Returns the Last known location is the location provider is connected and location permissions are granted.
+ *
+ * @return the last known location
+ */
+ @Override
+ @Nullable
+ public Location getLastLocation() {
+ return null;
+ }
+
+ /**
+ * Request location updates to the location provider.
+ */
+ @Override
+ public void requestLocationUpdates() {
+ // Intentionally left empty
+ }
+
+ /**
+ * Dismiss ongoing location update to the location provider.
+ */
+ @Override
+ public void removeLocationUpdates() {
+ // Intentionally left empty
+ }
+
+ /**
+ * Invoked when the Location has changed.
+ *
+ * @param location the new location
+ */
+ @Override
+ public void onLocationChanged(Location location) {
+ // Intentionally left empty
+ }
+
+ /**
+ * Useful when you'd like to add a location listener to handle location connections and update events. It is important
+ * to note, that the callback will continue getting called even when your application isn't in the foreground.
+ * Therefore, it is a good idea to use {@link LocationEngine#removeLocationEngineListener(LocationEngineListener)}
+ * inside your activities {@code onStop()} method.
+ *
+ * @param listener A {@link LocationEngineListener} which you'd like to add to your location engine.
+ * @since 2.0.0
+ */
+ @Override
+ public void addLocationEngineListener(LocationEngineListener listener) {
+ // Intentionally left empty
+ }
+
+ /**
+ * If you no longer need your {@link LocationEngineListener} to be invoked with every location update, use this
+ * method to remove it. It's also important to remove your listeners before the activity is destroyed to prevent any
+ * potential memory leaks.
+ *
+ * @param listener the {@link LocationEngineListener} you'd like to remove from this {@link LocationEngine}.
+ * @return true.
+ * @since 2.0.0
+ */
+ @Override
+ public boolean removeLocationEngineListener(LocationEngineListener listener) {
+ return true;
+ }
+}
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 7fd9d6172d..e575dc9062 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
@@ -12,9 +12,10 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
+import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.core.location.LocationEnginePriority;
+import com.mapbox.services.android.core.location.LocationEngineProvider;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
-import com.mapbox.services.android.telemetry.location.LocationEngine;
-import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import timber.log.Timber;
@@ -34,7 +35,7 @@ public final class Mapbox {
private Context context;
private String accessToken;
private Boolean connected;
- private LocationSource locationSource;
+ private LocationEngine locationEngine;
/**
* Get an instance of Mapbox.
@@ -50,8 +51,9 @@ public final class Mapbox {
public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull String accessToken) {
if (INSTANCE == null) {
Context appContext = context.getApplicationContext();
- INSTANCE = new Mapbox(appContext, accessToken, new LocationSource(appContext));
- LocationEngine locationEngine = new LocationSource(appContext);
+ LocationEngineProvider locationEngineProvider = new LocationEngineProvider(context);
+ LocationEngine locationEngine = locationEngineProvider.obtainBestLocationEngineAvailable();
+ INSTANCE = new Mapbox(appContext, accessToken, locationEngine);
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
try {
@@ -66,10 +68,10 @@ public final class Mapbox {
return INSTANCE;
}
- Mapbox(@NonNull Context context, @NonNull String accessToken, LocationSource locationSource) {
+ Mapbox(@NonNull Context context, @NonNull String accessToken, LocationEngine locationEngine) {
this.context = context;
this.accessToken = accessToken;
- this.locationSource = locationSource;
+ this.locationEngine = locationEngine;
}
/**
@@ -143,7 +145,24 @@ public final class Mapbox {
return (activeNetwork != null && activeNetwork.isConnected());
}
+ /**
+ * Returns a location source instance with empty methods.
+ *
+ * @return an empty location source implementation
+ * @deprecated Replaced by {@link Mapbox#getLocationEngine()}
+ */
+ @Deprecated
public static LocationSource getLocationSource() {
- return INSTANCE.locationSource;
+ return new EmptyLocationSource();
+ }
+
+
+ /**
+ * Returns the location engine used by the SDK.
+ *
+ * @return the location engine configured
+ */
+ public static LocationEngine getLocationEngine() {
+ return INSTANCE.locationEngine;
}
}
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 6652142be3..5129db08e8 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
@@ -4,16 +4,17 @@ import android.content.Context;
import android.location.Location;
import android.support.annotation.Nullable;
-import com.mapbox.services.android.telemetry.location.LocationEngine;
-import com.mapbox.services.android.telemetry.location.LocationEngineListener;
-import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
-import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
+import com.mapbox.mapboxsdk.Mapbox;
+import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.core.location.LocationEngineListener;
+import com.mapbox.services.android.core.location.LocationEnginePriority;
import com.mapzen.android.lost.api.LocationListener;
import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LocationServices;
import com.mapzen.android.lost.api.LostApiClient;
/**
+ * LocationEngine using the Open Source Lost library
* Manages locational updates. Contains methods to register and unregister location listeners.
*
*
You can register a LocationEngineListener with LocationSource#addLocationEngineListener(LocationEngineListener)
@@ -27,8 +28,11 @@ import com.mapzen.android.lost.api.LostApiClient;
* overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back
* in the history stack.
*
+ *
+ * @deprecated Use a {@link Mapbox#getLocationEngine()} instead.
*/
-public class LocationSource extends LocationEngine implements LocationListener {
+@Deprecated
+public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener {
private Context context;
private LostApiClient lostApiClient;
@@ -41,7 +45,16 @@ public class LocationSource extends LocationEngine implements LocationListener {
public LocationSource(Context context) {
super();
this.context = context.getApplicationContext();
- lostApiClient = new LostApiClient.Builder(this.context).build();
+ lostApiClient = new LostApiClient.Builder(this.context)
+ .addConnectionCallbacks(this)
+ .build();
+ }
+
+ /**
+ * Constructs a location source instance.
+ * Needed to create empty location source implementations.
+ */
+ public LocationSource() {
}
/**
@@ -50,12 +63,9 @@ public class LocationSource extends LocationEngine implements LocationListener {
*/
@Override
public void activate() {
- if (!lostApiClient.isConnected()) {
+ if (lostApiClient != null && !lostApiClient.isConnected()) {
lostApiClient.connect();
}
- for (LocationEngineListener listener : locationListeners) {
- listener.onConnected();
- }
}
/**
@@ -65,7 +75,7 @@ public class LocationSource extends LocationEngine implements LocationListener {
*/
@Override
public void deactivate() {
- if (lostApiClient.isConnected()) {
+ if (lostApiClient != null && lostApiClient.isConnected()) {
lostApiClient.disconnect();
}
}
@@ -81,6 +91,24 @@ public class LocationSource extends LocationEngine implements LocationListener {
return lostApiClient.isConnected();
}
+ /**
+ * Invoked when the location provider has connected.
+ */
+ @Override
+ public void onConnected() {
+ for (LocationEngineListener listener : locationListeners) {
+ listener.onConnected();
+ }
+ }
+
+ /**
+ * Invoked when the location provider connection has been suspended.
+ */
+ @Override
+ public void onConnectionSuspended() {
+ // Intentionally left empty
+ }
+
/**
* Returns the Last known location is the location provider is connected and location permissions are granted.
*
@@ -89,9 +117,9 @@ public class LocationSource extends LocationEngine implements LocationListener {
@Override
@Nullable
public Location getLastLocation() {
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
+ if (lostApiClient.isConnected()) {
//noinspection MissingPermission
- return LocationServices.FusedLocationApi.getLastLocation();
+ return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
}
return null;
}
@@ -101,13 +129,18 @@ public class LocationSource extends LocationEngine implements LocationListener {
*/
@Override
public void requestLocationUpdates() {
- // Common params
- LocationRequest request = LocationRequest.create()
- .setInterval(1000)
- .setFastestInterval(1000)
- .setSmallestDisplacement(3.0f);
+ LocationRequest request = LocationRequest.create();
+
+ if (interval != null) {
+ request.setInterval(interval);
+ }
+ if (fastestInterval != null) {
+ request.setFastestInterval(fastestInterval);
+ }
+ if (smallestDisplacement != null) {
+ request.setSmallestDisplacement(smallestDisplacement);
+ }
- // Priority matching is straightforward
if (priority == LocationEnginePriority.NO_POWER) {
request.setPriority(LocationRequest.PRIORITY_NO_POWER);
} else if (priority == LocationEnginePriority.LOW_POWER) {
@@ -118,9 +151,9 @@ public class LocationSource extends LocationEngine implements LocationListener {
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
- if (lostApiClient.isConnected() && PermissionsManager.areLocationPermissionsGranted(context)) {
+ if (lostApiClient.isConnected()) {
//noinspection MissingPermission
- LocationServices.FusedLocationApi.requestLocationUpdates(request, this);
+ LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
}
}
@@ -130,10 +163,20 @@ public class LocationSource extends LocationEngine implements LocationListener {
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
- LocationServices.FusedLocationApi.removeLocationUpdates(this);
+ LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
}
}
+ /**
+ * Returns the location engine type.
+ *
+ * @return Lost type
+ */
+ @Override
+ public Type obtainType() {
+ return Type.LOST;
+ }
+
/**
* Invoked when the Location has changed.
*
@@ -145,4 +188,4 @@ public class LocationSource extends LocationEngine implements LocationListener {
listener.onLocationChanged(location);
}
}
-}
+}
\ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java
index 6b0c9a76c0..b27559e95e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/package-info.java
@@ -1,4 +1,4 @@
/**
* Contains the Mapbox Maps Android Location API classes.
*/
-package com.mapbox.mapboxsdk.location;
+package com.mapbox.mapboxsdk.location;
\ No newline at end of file
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 6bf8342efb..f0461b6307 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
@@ -42,7 +42,7 @@ 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.android.core.location.LocationEngine;
import com.mapbox.services.commons.geojson.Feature;
import com.mapbox.services.commons.geojson.Geometry;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 6881ca067b..2f85c82587 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -12,8 +12,8 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
-import com.mapbox.services.android.telemetry.location.LocationEngine;
-import com.mapbox.services.android.telemetry.location.LocationEngineListener;
+import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.core.location.LocationEngineListener;
import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
import timber.log.Timber;
@@ -52,7 +52,7 @@ public final class TrackingSettings {
}
void initialise(MapboxMapOptions options) {
- locationSource = Mapbox.getLocationSource();
+ locationSource = Mapbox.getLocationEngine();
setMyLocationEnabled(options.getLocationEnabled());
}
@@ -392,7 +392,7 @@ public final class TrackingSettings {
this.isCustomLocationSource = locationSource != null;
if (locationSource == null) {
- locationSource = Mapbox.getLocationSource();
+ locationSource = Mapbox.getLocationEngine();
}
this.locationSource = locationSource;
myLocationView.setLocationSource(locationSource);
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 8a393ebb1f..cc7602e056 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
@@ -36,9 +36,9 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
-import com.mapbox.services.android.telemetry.location.LocationEngine;
-import com.mapbox.services.android.telemetry.location.LocationEngineListener;
-import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
+import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.core.location.LocationEngineListener;
+import com.mapbox.services.android.core.location.LocationEnginePriority;
import java.lang.ref.WeakReference;
@@ -70,7 +70,7 @@ public class MyLocationView extends View {
private LatLng latLng;
private Location location;
- private LocationEngine locationSource;
+ private LocationEngine locationEngine;
private long locationUpdateTimestamp;
private float previousDirection;
@@ -161,8 +161,9 @@ public class MyLocationView extends View {
compassListener = new CompassListener(context);
}
+ @Deprecated
public void init(LocationSource locationSource) {
- this.locationSource = locationSource;
+ this.locationEngine = locationSource;
}
/**
@@ -448,8 +449,8 @@ public class MyLocationView extends View {
}
if (userLocationListener != null) {
- locationSource.removeLocationEngineListener(userLocationListener);
- locationSource = null;
+ locationEngine.removeLocationEngineListener(userLocationListener);
+ locationEngine = null;
userLocationListener = null;
}
}
@@ -485,12 +486,12 @@ public class MyLocationView extends View {
* Set the enabled state, for internal use only.
*
* @param enabled The value to set the state to
- * @param isCustomLocationSource Flag handling for handling user provided custom location source
+ * @param isCustomLocationEngine Flag handling for handling user provided custom location engine
*/
- public void setEnabled(boolean enabled, boolean isCustomLocationSource) {
+ public void setEnabled(boolean enabled, boolean isCustomLocationEngine) {
super.setEnabled(enabled);
setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
- toggleGps(enabled, isCustomLocationSource);
+ toggleGps(enabled, isCustomLocationEngine);
}
/**
@@ -530,32 +531,33 @@ public class MyLocationView extends View {
*
* @param enableGps true if GPS is to be enabled, false if GPS is to be disabled
*/
- private void toggleGps(boolean enableGps, boolean isCustomLocationSource) {
+ private void toggleGps(boolean enableGps, boolean isCustomLocationEngine) {
if (enableGps) {
- if (locationSource == null) {
- if (!isCustomLocationSource) {
- locationSource = Mapbox.getLocationSource();
+ if (locationEngine == null) {
+ if (!isCustomLocationEngine) {
+ locationEngine = Mapbox.getLocationEngine();
} else {
return;
}
}
if (userLocationListener == null) {
- userLocationListener = new GpsLocationListener(this, locationSource);
+ userLocationListener = new GpsLocationListener(this, locationEngine);
}
- locationSource.addLocationEngineListener(userLocationListener);
- locationSource.setPriority(LocationEnginePriority.HIGH_ACCURACY);
- locationSource.activate();
+ locationEngine.addLocationEngineListener(userLocationListener);
+ locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
+ locationEngine.activate();
} else {
- if (locationSource == null) {
+ if (locationEngine == null) {
return;
}
// Disable location and user dot
location = null;
- locationSource.removeLocationEngineListener(userLocationListener);
- locationSource.removeLocationUpdates();
- locationSource.deactivate();
+ locationEngine.removeLocationEngineListener(userLocationListener);
+ locationEngine.removeLocationUpdates();
+ locationEngine.deactivate();
+ restoreLocationEngine();
}
}
@@ -740,13 +742,13 @@ public class MyLocationView extends View {
/**
* Set the location source from which location updates are received, for internal use only.
*
- * @param locationSource The location source to receive updates from
+ * @param locationEngine The location engine to receive updates from
*/
- public void setLocationSource(LocationEngine locationSource) {
+ public void setLocationSource(LocationEngine locationEngine) {
toggleGps(false);
- this.locationSource = locationSource;
+ this.locationEngine = locationEngine;
this.userLocationListener = null;
- setEnabled(isEnabled(), locationSource != null);
+ setEnabled(isEnabled(), locationEngine != null);
}
private void applyDrawableTint(Drawable drawable, @ColorInt int color) {
@@ -769,6 +771,11 @@ public class MyLocationView extends View {
}
}
+ private void restoreLocationEngine() {
+ locationEngine.setPriority(LocationEnginePriority.LOW_POWER);
+ locationEngine.activate();
+ }
+
private static class GpsLocationListener implements LocationEngineListener {
private WeakReference userLocationView;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
index e05190cd57..09acf3feef 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
@@ -5,7 +5,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
-import com.mapbox.mapboxsdk.location.LocationSource;
+import com.mapbox.services.android.core.location.LocationEngine;
import org.junit.Before;
import org.junit.Test;
@@ -25,13 +25,13 @@ public class MapboxTest {
private Context context;
private Context appContext;
- private LocationSource locationSource;
+ private LocationEngine locationSource;
@Before
public void before() {
context = mock(Context.class);
appContext = mock(Context.class);
- locationSource = mock(LocationSource.class);
+ locationSource = mock(LocationEngine.class);
when(context.getApplicationContext()).thenReturn(appContext);
}
--
cgit v1.2.1
From 5dbd94016b9784f865e46d2bf46df240fc96fe7e Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 1 Nov 2017 16:46:09 -0700
Subject: [android] - fix logo scale for MapSnapshot
---
.../mapboxsdk/snapshotter/MapSnapshotter.java | 79 ++++++++++++++--------
1 file changed, 52 insertions(+), 27 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 5206606c83..5deedc3e63 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
+import android.graphics.Matrix;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
@@ -262,35 +263,59 @@ public class MapSnapshotter {
nativeCancel();
}
- protected void addOverlay(Bitmap original) {
+ /**
+ * Draw an overlay on the map snapshot.
+ *
+ * @param mapSnapshot the map snapshot to draw the overlay on
+ */
+ protected void addOverlay(MapSnapshot mapSnapshot) {
+ Bitmap original = mapSnapshot.getBitmap();
+ Canvas canvas = new Canvas(original);
+ addLogo(canvas, original);
+ }
+
+ /**
+ * Draw a logo on the canvas created from the map snapshot.
+ *
+ * @param canvas the canvas to draw the bitmap on
+ * @param original the map snapshot image
+ */
+ private void addLogo(Canvas canvas, Bitmap original) {
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float margin = displayMetrics.density * LOGO_MARGIN_DP;
- Canvas canvas = new Canvas(original);
+ Bitmap logo = createScaledLogo(original);
+ canvas.drawBitmap(logo, margin, original.getHeight() - logo.getHeight() - margin, null);
+ }
+
+ /**
+ * Create a scaled logo for a map snapshot.
+ *
+ * @param snapshot the map snapshot where the logo should be placed on
+ * @return the scaled bitmap logo
+ */
+ private Bitmap createScaledLogo(Bitmap snapshot) {
+ Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, null);
+ float scale = calculateLogoScale(snapshot, logo);
+ Matrix matrix = new Matrix();
+ matrix.postScale(scale, scale);
+ return Bitmap.createBitmap(logo, 0, 0, logo.getWidth(), logo.getHeight(), matrix, true);
+ }
- // Decode just the boundaries
- BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
- bitmapOptions.inJustDecodeBounds = true;
- BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, bitmapOptions);
- int srcWidth = bitmapOptions.outWidth;
- int srcHeight = bitmapOptions.outHeight;
-
- // Ratio, preferred dimensions and resulting sample size
- float widthRatio = displayMetrics.widthPixels / original.getWidth();
- float heightRatio = displayMetrics.heightPixels / original.getHeight();
- float prefWidth = srcWidth / widthRatio;
- float prefHeight = srcHeight / heightRatio;
- int sampleSize = MapSnaphotUtil.calculateInSampleSize(bitmapOptions, (int) prefWidth, (int) prefHeight);
-
- // Scale bitmap
- bitmapOptions.inJustDecodeBounds = false;
- bitmapOptions.inScaled = true;
- bitmapOptions.inSampleSize = sampleSize;
- bitmapOptions.inDensity = srcWidth;
- bitmapOptions.inTargetDensity = (int) prefWidth * bitmapOptions.inSampleSize;
- Bitmap logo = BitmapFactory.decodeResource(context.getResources(), R.drawable.mapbox_logo_icon, bitmapOptions);
-
- float scaledHeight = bitmapOptions.outHeight * heightRatio / bitmapOptions.inSampleSize;
- canvas.drawBitmap(logo, margin, original.getHeight() - scaledHeight - margin, null);
+ /**
+ * Calculates the scale of the logo, only allow downscaling.
+ *
+ * @param snapshot the bitmap of the map snapshot
+ * @param logo the bitmap of the mapbox logo
+ * @return the scale value
+ */
+ private float calculateLogoScale(Bitmap snapshot, Bitmap logo) {
+ DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
+ float widthRatio = displayMetrics.widthPixels / snapshot.getWidth();
+ float heightRatio = displayMetrics.heightPixels / snapshot.getHeight();
+ float prefWidth = logo.getWidth() / widthRatio;
+ float prefHeight = logo.getHeight() / heightRatio;
+ float calculatedScale = Math.min(prefWidth / logo.getWidth(), prefHeight / logo.getHeight()) * 2;
+ return calculatedScale < 1 ? calculatedScale : 1.0f;
}
/**
@@ -302,7 +327,7 @@ public class MapSnapshotter {
protected void onSnapshotReady(MapSnapshot snapshot) {
if (callback != null) {
if (snapshot.isShowLogo()) {
- addOverlay(snapshot.getBitmap());
+ addOverlay(snapshot);
}
callback.onSnapshotReady(snapshot);
reset();
--
cgit v1.2.1
From d9fe24176153f14d1c101f48993860ee776cbfb0 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 2 Nov 2017 11:18:15 -0700
Subject: [android] - workaround Android O OkHttp bug.
---
.../src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
index e2626a026b..32aa250997 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -85,7 +85,14 @@ class HTTPRequest implements Callback {
}
mRequest = builder.build();
mCall = mClient.newCall(mRequest);
- mCall.enqueue(this);
+
+ // TODO remove code block for workaround in #10303
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
+ mCall.enqueue(this);
+ } else {
+ // Calling execute instead of enqueue is a workaround for #10303
+ onResponse(mCall, mCall.execute());
+ }
} catch (Exception exception) {
onFailure(exception);
}
--
cgit v1.2.1
From 6adeee601e5752af6297265d2bd02e88eca85707 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 2 Oct 2017 15:41:02 +0300
Subject: [android] encapsulate gl surfaceview rendering specifics in map
renderer subclass
- preparation for re-introduction of texture view
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 21 +++---
.../maps/renderer/GLSurfaceViewMapRenderer.java | 84 ++++++++++++++++++++++
.../mapboxsdk/maps/renderer/MapRenderer.java | 54 ++++++--------
3 files changed, 113 insertions(+), 46 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 e45e8be6ad..4fc2a1dffc 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
@@ -27,7 +27,7 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
-import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
+import com.mapbox.mapboxsdk.maps.renderer.GLSurfaceViewMapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
@@ -87,7 +87,7 @@ public class MapView extends FrameLayout {
private Bundle savedInstanceState;
private final CopyOnWriteArrayList onMapChangedListeners = new CopyOnWriteArrayList<>();
- private GLSurfaceView glSurfaceView;
+ private MapRenderer mapRenderer;
@UiThread
public MapView(@NonNull Context context) {
@@ -290,12 +290,10 @@ public class MapView extends FrameLayout {
}
private void initialiseDrawingSurface() {
- glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
+ GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
- glSurfaceView.setEGLContextClientVersion(2);
- glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
- MapRenderer mapRenderer = new MapRenderer(getContext(), glSurfaceView) {
+ GLSurfaceViewMapRenderer mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
@@ -313,10 +311,9 @@ public class MapView extends FrameLayout {
}
};
- glSurfaceView.setRenderer(mapRenderer);
- glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
glSurfaceView.setVisibility(View.VISIBLE);
+ this.mapRenderer = mapRenderer;
nativeMapView = new NativeMapView(this, mapRenderer);
nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight());
}
@@ -352,8 +349,8 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onResume() {
- if (glSurfaceView != null) {
- glSurfaceView.onResume();
+ if (mapRenderer != null) {
+ mapRenderer.onResume();
}
}
@@ -362,8 +359,8 @@ public class MapView extends FrameLayout {
*/
@UiThread
public void onPause() {
- if (glSurfaceView != null) {
- glSurfaceView.onPause();
+ if (mapRenderer != null) {
+ mapRenderer.onPause();
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
new file mode 100644
index 0000000000..d0ec9f9495
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
@@ -0,0 +1,84 @@
+package com.mapbox.mapboxsdk.maps.renderer;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+
+import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
+
+/**
+ * The {@link GLSurfaceViewMapRenderer} encapsulates the GL thread and
+ * {@link GLSurfaceView} specifics to render the map.
+ *
+ * @see MapRenderer
+ */
+public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceView.Renderer {
+
+ private final GLSurfaceView glSurfaceView;
+
+ public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView) {
+ super(context);
+ this.glSurfaceView = glSurfaceView;
+ glSurfaceView.setEGLContextClientVersion(2);
+ glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
+ glSurfaceView.setRenderer(this);
+ glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
+ }
+
+ @Override
+ public void onPause() {
+ if (glSurfaceView != null) {
+ glSurfaceView.onPause();
+ }
+ }
+
+ @Override
+ public void onResume() {
+ if (glSurfaceView != null) {
+ glSurfaceView.onResume();
+ }
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ super.onSurfaceCreated(gl, config);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ super.onSurfaceChanged(gl, width, height);
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ super.onDrawFrame(gl);
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Called from the renderer frontend to schedule a render.
+ */
+ @Override
+ public void requestRender() {
+ glSurfaceView.requestRender();
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Schedules work to be performed on the MapRenderer thread.
+ *
+ * @param runnable the runnable to execute
+ */
+ @Override
+ public void queueEvent(Runnable runnable) {
+ glSurfaceView.queueEvent(runnable);
+ }
+
+
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index 3f43522e01..a7c0fa3778 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -1,7 +1,7 @@
package com.mapbox.mapboxsdk.maps.renderer;
import android.content.Context;
-import android.opengl.GLSurfaceView;
+import android.support.annotation.CallSuper;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.storage.FileSource;
@@ -16,17 +16,14 @@ import javax.microedition.khronos.opengles.GL10;
* render on the one end and acts as a scheduler to request work to
* be performed on the GL thread on the other.
*/
-public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler {
+public abstract class MapRenderer implements MapRendererScheduler {
// Holds the pointer to the native peer after initialisation
private long nativePtr = 0;
- private final GLSurfaceView glSurfaceView;
-
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
- public MapRenderer(Context context, GLSurfaceView glSurfaceView) {
- this.glSurfaceView = glSurfaceView;
+ public MapRenderer(Context context) {
FileSource fileSource = FileSource.getInstance(context);
float pixelRatio = context.getResources().getDisplayMetrics().density;
@@ -36,17 +33,26 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
}
+ public void onPause() {
+ // Implement if needed
+ }
+
+ public void onResume() {
+ // Implement if needed
+ }
+
+
public void setOnFpsChangedListener(MapboxMap.OnFpsChangedListener listener) {
onFpsChangedListener = listener;
}
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ @CallSuper
+ protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
nativeOnSurfaceCreated();
}
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
+ @CallSuper
+ protected void onSurfaceChanged(GL10 gl, int width, int height) {
if (width < 0) {
throw new IllegalArgumentException("fbWidth cannot be negative.");
}
@@ -69,8 +75,8 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
nativeOnSurfaceChanged(width, height);
}
- @Override
- public void onDrawFrame(GL10 gl) {
+ @CallSuper
+ protected void onDrawFrame(GL10 gl) {
nativeRender();
if (onFpsChangedListener != null) {
@@ -78,28 +84,6 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
}
}
- /**
- * May be called from any thread.
- *
- * Called from the renderer frontend to schedule a render.
- */
- @Override
- public void requestRender() {
- glSurfaceView.requestRender();
- }
-
- /**
- * May be called from any thread.
- *
- * Schedules work to be performed on the MapRenderer thread.
- *
- * @param runnable the runnable to execute
- */
- @Override
- public void queueEvent(Runnable runnable) {
- glSurfaceView.queueEvent(runnable);
- }
-
/**
* May be called from any thread.
*
@@ -109,6 +93,7 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
* @param runnable the runnable to execute
* @see MapRendererRunnable
*/
+ @CallSuper
void queueEvent(MapRendererRunnable runnable) {
this.queueEvent((Runnable) runnable);
}
@@ -118,6 +103,7 @@ public class MapRenderer implements GLSurfaceView.Renderer, MapRendererScheduler
float pixelRatio,
String programCacheDir);
+ @CallSuper
@Override
protected native void finalize() throws Throwable;
--
cgit v1.2.1
From fd5f357d1d244a13c5b51b66829f47beda4ca1ed Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 31 Oct 2017 12:31:13 +0200
Subject: [android] move egl under renderer package
---
.../com/mapbox/mapboxsdk/egl/EGLConfigChooser.java | 293 ---------------------
.../mapbox/mapboxsdk/egl/EGLConfigException.java | 21 --
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 2 +-
.../maps/renderer/GLSurfaceViewMapRenderer.java | 84 ------
.../maps/renderer/egl/EGLConfigChooser.java | 293 +++++++++++++++++++++
.../maps/renderer/egl/EGLConfigException.java | 21 ++
.../glsurfaceview/GLSurfaceViewMapRenderer.java | 81 ++++++
7 files changed, 396 insertions(+), 399 deletions(-)
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigChooser.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigException.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
deleted file mode 100644
index 7fc70716da..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigChooser.java
+++ /dev/null
@@ -1,293 +0,0 @@
-package com.mapbox.mapboxsdk.egl;
-
-import android.opengl.GLSurfaceView;
-import android.support.annotation.NonNull;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.microedition.khronos.egl.EGL10;
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.egl.EGLDisplay;
-
-import timber.log.Timber;
-
-import static com.mapbox.mapboxsdk.utils.Compare.compare;
-import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_MASK_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_BLUE_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_BUFFER_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_COLOR_BUFFER_TYPE;
-import static javax.microedition.khronos.egl.EGL10.EGL_CONFIG_CAVEAT;
-import static javax.microedition.khronos.egl.EGL10.EGL_DEPTH_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_GREEN_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_NONE;
-import static javax.microedition.khronos.egl.EGL10.EGL_RED_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_RENDERABLE_TYPE;
-import static javax.microedition.khronos.egl.EGL10.EGL_RGB_BUFFER;
-import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLES;
-import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLE_BUFFERS;
-import static javax.microedition.khronos.egl.EGL10.EGL_STENCIL_SIZE;
-import static javax.microedition.khronos.egl.EGL10.EGL_SURFACE_TYPE;
-import static javax.microedition.khronos.egl.EGL10.EGL_WINDOW_BIT;
-
-/**
- * Selects the right EGLConfig needed for `mapbox-gl-native`
- */
-public class EGLConfigChooser implements GLSurfaceView.EGLConfigChooser {
-
- /**
- * Requires API level 17
- *
- * @see android.opengl.EGL14.EGL_CONFORMANT;
- */
- @SuppressWarnings("JavadocReference")
- private static final int EGL_CONFORMANT = 0x3042;
-
- /**
- * Requires API level 17
- *
- * @see android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
- */
- @SuppressWarnings("JavadocReference")
- private static final int EGL_OPENGL_ES2_BIT = 0x0004;
-
- @Override
- public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
- int[] configAttribs = getConfigAttributes();
-
- // Determine number of possible configurations
- int[] numConfigs = getNumberOfConfigurations(egl, display, configAttribs);
- if (numConfigs[0] < 1) {
- Timber.e("eglChooseConfig() returned no configs.");
- throw new EGLConfigException("eglChooseConfig() failed");
- }
-
- // Get all possible configurations
- EGLConfig[] possibleConfigurations = getPossibleConfigurations(egl, display, configAttribs, numConfigs);
-
- // Choose best match
- EGLConfig config = chooseBestMatchConfig(egl, display, possibleConfigurations);
- if (config == null) {
- Timber.e("No config chosen");
- throw new EGLConfigException("No config chosen");
- }
-
- return config;
- }
-
- private int[] getNumberOfConfigurations(EGL10 egl, EGLDisplay display, int[] configAttributes) {
- int[] numConfigs = new int[1];
- if (!egl.eglChooseConfig(display, configAttributes, null, 0, numConfigs)) {
- Timber.e("eglChooseConfig(NULL) returned error %d", egl.eglGetError());
- throw new EGLConfigException("eglChooseConfig() failed");
- }
- return numConfigs;
- }
-
- private EGLConfig[] getPossibleConfigurations(EGL10 egl, EGLDisplay display,
- int[] configAttributes, int[] numConfigs) {
- EGLConfig[] configs = new EGLConfig[numConfigs[0]];
- if (!egl.eglChooseConfig(display, configAttributes, configs, numConfigs[0], numConfigs)) {
- Timber.e("eglChooseConfig() returned error %d", egl.eglGetError());
- throw new EGLConfigException("eglChooseConfig() failed");
- }
- return configs;
- }
-
- // Quality
- enum BufferFormat {
- Format16Bit(3),
- Format32BitNoAlpha(1),
- Format32BitAlpha(2),
- Format24Bit(0),
- Unknown(4);
-
- int value;
-
- BufferFormat(int value) {
- this.value = value;
- }
- }
-
- enum DepthStencilFormat {
- Format16Depth8Stencil(1),
- Format24Depth8Stencil(0);
-
- int value;
-
- DepthStencilFormat(int value) {
- this.value = value;
- }
- }
-
- private EGLConfig chooseBestMatchConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
- class Config implements Comparable {
- private final BufferFormat bufferFormat;
- private final DepthStencilFormat depthStencilFormat;
- private final boolean isNotConformant;
- private final boolean isCaveat;
- private final int index;
- private final EGLConfig config;
-
- public Config(BufferFormat bufferFormat, DepthStencilFormat depthStencilFormat,
- boolean isNotConformant, boolean isCaveat, int index, EGLConfig config) {
- this.bufferFormat = bufferFormat;
- this.depthStencilFormat = depthStencilFormat;
- this.isNotConformant = isNotConformant;
- this.isCaveat = isCaveat;
- this.index = index;
- this.config = config;
- }
-
-
- @Override
- public int compareTo(@NonNull Config other) {
- int i = compare(bufferFormat.value, other.bufferFormat.value);
- if (i != 0) {
- return i;
- }
-
- i = compare(depthStencilFormat.value, other.depthStencilFormat.value);
- if (i != 0) {
- return i;
- }
-
- i = compare(isNotConformant, other.isNotConformant);
- if (i != 0) {
- return i;
- }
-
- i = compare(isCaveat, other.isCaveat);
- if (i != 0) {
- return i;
- }
-
- i = compare(index, other.index);
- if (i != 0) {
- return i;
- }
-
- return 0;
- }
- }
-
- List matches = new ArrayList<>();
-
- int i = 0;
- for (EGLConfig config : configs) {
- i++;
-
- int caveat = getConfigAttr(egl, display, config, EGL_CONFIG_CAVEAT);
- int conformant = getConfigAttr(egl, display, config, EGL_CONFORMANT);
- int bits = getConfigAttr(egl, display, config, EGL_BUFFER_SIZE);
- int red = getConfigAttr(egl, display, config, EGL_RED_SIZE);
- int green = getConfigAttr(egl, display, config, EGL_GREEN_SIZE);
- int blue = getConfigAttr(egl, display, config, EGL_BLUE_SIZE);
- int alpha = getConfigAttr(egl, display, config, EGL_ALPHA_SIZE);
- int alphaMask = getConfigAttr(egl, display, config, EGL_ALPHA_MASK_SIZE);
- int depth = getConfigAttr(egl, display, config, EGL_DEPTH_SIZE);
- int stencil = getConfigAttr(egl, display, config, EGL_STENCIL_SIZE);
- int sampleBuffers = getConfigAttr(egl, display, config, EGL_SAMPLE_BUFFERS);
- int samples = getConfigAttr(egl, display, config, EGL_SAMPLES);
-
- boolean configOk = (depth == 24) || (depth == 16);
- configOk &= stencil == 8;
- configOk &= sampleBuffers == 0;
- configOk &= samples == 0;
-
- // Filter our configs first for depth, stencil and anti-aliasing
- if (configOk) {
- // Work out the config's buffer format
- BufferFormat bufferFormat;
- if ((bits == 16) && (red == 5) && (green == 6) && (blue == 5) && (alpha == 0)) {
- bufferFormat = BufferFormat.Format16Bit;
- } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
- bufferFormat = BufferFormat.Format32BitNoAlpha;
- } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 8)) {
- bufferFormat = BufferFormat.Format32BitAlpha;
- } else if ((bits == 24) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
- bufferFormat = BufferFormat.Format24Bit;
- } else {
- bufferFormat = BufferFormat.Unknown;
- }
-
- // Work out the config's depth stencil format
- DepthStencilFormat depthStencilFormat;
- if ((depth == 16) && (stencil == 8)) {
- depthStencilFormat = DepthStencilFormat.Format16Depth8Stencil;
- } else {
- depthStencilFormat = DepthStencilFormat.Format24Depth8Stencil;
- }
-
- boolean isNotConformant = (conformant & EGL_OPENGL_ES2_BIT) != EGL_OPENGL_ES2_BIT;
- boolean isCaveat = caveat != EGL_NONE;
-
- // Ignore formats we don't recognise
- if (bufferFormat != BufferFormat.Unknown) {
- matches.add(new Config(bufferFormat, depthStencilFormat, isNotConformant, isCaveat, i, config));
- }
- }
-
- }
-
- // Sort
- Collections.sort(matches);
-
- if (matches.size() == 0) {
- throw new EGLConfigException("No matching configurations after filtering");
- }
-
- Config bestMatch = matches.get(0);
-
- if (bestMatch.isCaveat) {
- Timber.w("Chosen config has a caveat.");
- }
-
- if (bestMatch.isNotConformant) {
- Timber.w("Chosen config is not conformant.");
- }
-
- return bestMatch.config;
- }
-
- private int getConfigAttr(EGL10 egl, EGLDisplay display, EGLConfig config, int attributeName) {
- int[] attributevalue = new int[1];
- if (!egl.eglGetConfigAttrib(display, config, attributeName, attributevalue)) {
- Timber.e("eglGetConfigAttrib(%d) returned error %d", attributeName, egl.eglGetError());
- throw new EGLConfigException("eglGetConfigAttrib() failed");
- }
- return attributevalue[0];
- }
-
-
- private int[] getConfigAttributes() {
- boolean emulator = inEmulator();
- Timber.i("In emulator: %s", emulator);
-
- // Get all configs at least RGB 565 with 16 depth and 8 stencil
- return new int[] {
- EGL_CONFIG_CAVEAT, EGL_NONE,
- EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
- EGL_BUFFER_SIZE, 16,
- EGL_RED_SIZE, 5,
- EGL_GREEN_SIZE, 6,
- EGL_BLUE_SIZE, 5,
- EGL_ALPHA_SIZE, 0,
- EGL_DEPTH_SIZE, 16,
- EGL_STENCIL_SIZE, 8,
- (emulator ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT,
- (emulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,
- EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL_NONE
- };
- }
-
- /**
- * Detect if we are in emulator.
- */
- private boolean inEmulator() {
- return System.getProperty("ro.kernel.qemu") != null;
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
deleted file mode 100644
index 3f576d0eda..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/egl/EGLConfigException.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.mapbox.mapboxsdk.egl;
-
-/**
- * Used for EGL configuration exceptions
- */
-public class EGLConfigException extends RuntimeException {
- public EGLConfigException() {
- }
-
- public EGLConfigException(String message) {
- super(message);
- }
-
- public EGLConfigException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public EGLConfigException(Throwable cause) {
- super(cause);
- }
-}
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 4fc2a1dffc..c316ea27d8 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
@@ -27,7 +27,7 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
-import com.mapbox.mapboxsdk.maps.renderer.GLSurfaceViewMapRenderer;
+import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
deleted file mode 100644
index d0ec9f9495..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/GLSurfaceViewMapRenderer.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.mapbox.mapboxsdk.maps.renderer;
-
-import android.content.Context;
-import android.opengl.GLSurfaceView;
-
-import com.mapbox.mapboxsdk.egl.EGLConfigChooser;
-
-import javax.microedition.khronos.egl.EGLConfig;
-import javax.microedition.khronos.opengles.GL10;
-
-import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
-
-/**
- * The {@link GLSurfaceViewMapRenderer} encapsulates the GL thread and
- * {@link GLSurfaceView} specifics to render the map.
- *
- * @see MapRenderer
- */
-public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceView.Renderer {
-
- private final GLSurfaceView glSurfaceView;
-
- public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView) {
- super(context);
- this.glSurfaceView = glSurfaceView;
- glSurfaceView.setEGLContextClientVersion(2);
- glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
- glSurfaceView.setRenderer(this);
- glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
- }
-
- @Override
- public void onPause() {
- if (glSurfaceView != null) {
- glSurfaceView.onPause();
- }
- }
-
- @Override
- public void onResume() {
- if (glSurfaceView != null) {
- glSurfaceView.onResume();
- }
- }
-
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- super.onSurfaceCreated(gl, config);
- }
-
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- super.onSurfaceChanged(gl, width, height);
- }
-
- @Override
- public void onDrawFrame(GL10 gl) {
- super.onDrawFrame(gl);
- }
-
- /**
- * May be called from any thread.
- *
- * Called from the renderer frontend to schedule a render.
- */
- @Override
- public void requestRender() {
- glSurfaceView.requestRender();
- }
-
- /**
- * May be called from any thread.
- *
- * Schedules work to be performed on the MapRenderer thread.
- *
- * @param runnable the runnable to execute
- */
- @Override
- public void queueEvent(Runnable runnable) {
- glSurfaceView.queueEvent(runnable);
- }
-
-
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigChooser.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigChooser.java
new file mode 100644
index 0000000000..b6f467708f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigChooser.java
@@ -0,0 +1,293 @@
+package com.mapbox.mapboxsdk.maps.renderer.egl;
+
+import android.opengl.GLSurfaceView;
+import android.support.annotation.NonNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLDisplay;
+
+import timber.log.Timber;
+
+import static com.mapbox.mapboxsdk.utils.Compare.compare;
+import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_MASK_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_ALPHA_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_BLUE_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_BUFFER_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_COLOR_BUFFER_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_CONFIG_CAVEAT;
+import static javax.microedition.khronos.egl.EGL10.EGL_DEPTH_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_GREEN_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_NONE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RED_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RENDERABLE_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_RGB_BUFFER;
+import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLES;
+import static javax.microedition.khronos.egl.EGL10.EGL_SAMPLE_BUFFERS;
+import static javax.microedition.khronos.egl.EGL10.EGL_STENCIL_SIZE;
+import static javax.microedition.khronos.egl.EGL10.EGL_SURFACE_TYPE;
+import static javax.microedition.khronos.egl.EGL10.EGL_WINDOW_BIT;
+
+/**
+ * Selects the right EGLConfig needed for `mapbox-gl-native`
+ */
+public class EGLConfigChooser implements GLSurfaceView.EGLConfigChooser {
+
+ /**
+ * Requires API level 17
+ *
+ * @see android.opengl.EGL14.EGL_CONFORMANT;
+ */
+ @SuppressWarnings("JavadocReference")
+ private static final int EGL_CONFORMANT = 0x3042;
+
+ /**
+ * Requires API level 17
+ *
+ * @see android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
+ */
+ @SuppressWarnings("JavadocReference")
+ private static final int EGL_OPENGL_ES2_BIT = 0x0004;
+
+ @Override
+ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
+ int[] configAttribs = getConfigAttributes();
+
+ // Determine number of possible configurations
+ int[] numConfigs = getNumberOfConfigurations(egl, display, configAttribs);
+ if (numConfigs[0] < 1) {
+ Timber.e("eglChooseConfig() returned no configs.");
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+
+ // Get all possible configurations
+ EGLConfig[] possibleConfigurations = getPossibleConfigurations(egl, display, configAttribs, numConfigs);
+
+ // Choose best match
+ EGLConfig config = chooseBestMatchConfig(egl, display, possibleConfigurations);
+ if (config == null) {
+ Timber.e("No config chosen");
+ throw new EGLConfigException("No config chosen");
+ }
+
+ return config;
+ }
+
+ private int[] getNumberOfConfigurations(EGL10 egl, EGLDisplay display, int[] configAttributes) {
+ int[] numConfigs = new int[1];
+ if (!egl.eglChooseConfig(display, configAttributes, null, 0, numConfigs)) {
+ Timber.e("eglChooseConfig(NULL) returned error %d", egl.eglGetError());
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+ return numConfigs;
+ }
+
+ private EGLConfig[] getPossibleConfigurations(EGL10 egl, EGLDisplay display,
+ int[] configAttributes, int[] numConfigs) {
+ EGLConfig[] configs = new EGLConfig[numConfigs[0]];
+ if (!egl.eglChooseConfig(display, configAttributes, configs, numConfigs[0], numConfigs)) {
+ Timber.e("eglChooseConfig() returned error %d", egl.eglGetError());
+ throw new EGLConfigException("eglChooseConfig() failed");
+ }
+ return configs;
+ }
+
+ // Quality
+ enum BufferFormat {
+ Format16Bit(3),
+ Format32BitNoAlpha(1),
+ Format32BitAlpha(2),
+ Format24Bit(0),
+ Unknown(4);
+
+ int value;
+
+ BufferFormat(int value) {
+ this.value = value;
+ }
+ }
+
+ enum DepthStencilFormat {
+ Format16Depth8Stencil(1),
+ Format24Depth8Stencil(0);
+
+ int value;
+
+ DepthStencilFormat(int value) {
+ this.value = value;
+ }
+ }
+
+ private EGLConfig chooseBestMatchConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ class Config implements Comparable {
+ private final BufferFormat bufferFormat;
+ private final DepthStencilFormat depthStencilFormat;
+ private final boolean isNotConformant;
+ private final boolean isCaveat;
+ private final int index;
+ private final EGLConfig config;
+
+ public Config(BufferFormat bufferFormat, DepthStencilFormat depthStencilFormat,
+ boolean isNotConformant, boolean isCaveat, int index, EGLConfig config) {
+ this.bufferFormat = bufferFormat;
+ this.depthStencilFormat = depthStencilFormat;
+ this.isNotConformant = isNotConformant;
+ this.isCaveat = isCaveat;
+ this.index = index;
+ this.config = config;
+ }
+
+
+ @Override
+ public int compareTo(@NonNull Config other) {
+ int i = compare(bufferFormat.value, other.bufferFormat.value);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(depthStencilFormat.value, other.depthStencilFormat.value);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(isNotConformant, other.isNotConformant);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(isCaveat, other.isCaveat);
+ if (i != 0) {
+ return i;
+ }
+
+ i = compare(index, other.index);
+ if (i != 0) {
+ return i;
+ }
+
+ return 0;
+ }
+ }
+
+ List matches = new ArrayList<>();
+
+ int i = 0;
+ for (EGLConfig config : configs) {
+ i++;
+
+ int caveat = getConfigAttr(egl, display, config, EGL_CONFIG_CAVEAT);
+ int conformant = getConfigAttr(egl, display, config, EGL_CONFORMANT);
+ int bits = getConfigAttr(egl, display, config, EGL_BUFFER_SIZE);
+ int red = getConfigAttr(egl, display, config, EGL_RED_SIZE);
+ int green = getConfigAttr(egl, display, config, EGL_GREEN_SIZE);
+ int blue = getConfigAttr(egl, display, config, EGL_BLUE_SIZE);
+ int alpha = getConfigAttr(egl, display, config, EGL_ALPHA_SIZE);
+ int alphaMask = getConfigAttr(egl, display, config, EGL_ALPHA_MASK_SIZE);
+ int depth = getConfigAttr(egl, display, config, EGL_DEPTH_SIZE);
+ int stencil = getConfigAttr(egl, display, config, EGL_STENCIL_SIZE);
+ int sampleBuffers = getConfigAttr(egl, display, config, EGL_SAMPLE_BUFFERS);
+ int samples = getConfigAttr(egl, display, config, EGL_SAMPLES);
+
+ boolean configOk = (depth == 24) || (depth == 16);
+ configOk &= stencil == 8;
+ configOk &= sampleBuffers == 0;
+ configOk &= samples == 0;
+
+ // Filter our configs first for depth, stencil and anti-aliasing
+ if (configOk) {
+ // Work out the config's buffer format
+ BufferFormat bufferFormat;
+ if ((bits == 16) && (red == 5) && (green == 6) && (blue == 5) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format16Bit;
+ } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format32BitNoAlpha;
+ } else if ((bits == 32) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 8)) {
+ bufferFormat = BufferFormat.Format32BitAlpha;
+ } else if ((bits == 24) && (red == 8) && (green == 8) && (blue == 8) && (alpha == 0)) {
+ bufferFormat = BufferFormat.Format24Bit;
+ } else {
+ bufferFormat = BufferFormat.Unknown;
+ }
+
+ // Work out the config's depth stencil format
+ DepthStencilFormat depthStencilFormat;
+ if ((depth == 16) && (stencil == 8)) {
+ depthStencilFormat = DepthStencilFormat.Format16Depth8Stencil;
+ } else {
+ depthStencilFormat = DepthStencilFormat.Format24Depth8Stencil;
+ }
+
+ boolean isNotConformant = (conformant & EGL_OPENGL_ES2_BIT) != EGL_OPENGL_ES2_BIT;
+ boolean isCaveat = caveat != EGL_NONE;
+
+ // Ignore formats we don't recognise
+ if (bufferFormat != BufferFormat.Unknown) {
+ matches.add(new Config(bufferFormat, depthStencilFormat, isNotConformant, isCaveat, i, config));
+ }
+ }
+
+ }
+
+ // Sort
+ Collections.sort(matches);
+
+ if (matches.size() == 0) {
+ throw new EGLConfigException("No matching configurations after filtering");
+ }
+
+ Config bestMatch = matches.get(0);
+
+ if (bestMatch.isCaveat) {
+ Timber.w("Chosen config has a caveat.");
+ }
+
+ if (bestMatch.isNotConformant) {
+ Timber.w("Chosen config is not conformant.");
+ }
+
+ return bestMatch.config;
+ }
+
+ private int getConfigAttr(EGL10 egl, EGLDisplay display, EGLConfig config, int attributeName) {
+ int[] attributevalue = new int[1];
+ if (!egl.eglGetConfigAttrib(display, config, attributeName, attributevalue)) {
+ Timber.e("eglGetConfigAttrib(%d) returned error %d", attributeName, egl.eglGetError());
+ throw new EGLConfigException("eglGetConfigAttrib() failed");
+ }
+ return attributevalue[0];
+ }
+
+
+ private int[] getConfigAttributes() {
+ boolean emulator = inEmulator();
+ Timber.i("In emulator: %s", emulator);
+
+ // Get all configs at least RGB 565 with 16 depth and 8 stencil
+ return new int[] {
+ EGL_CONFIG_CAVEAT, EGL_NONE,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_BUFFER_SIZE, 16,
+ EGL_RED_SIZE, 5,
+ EGL_GREEN_SIZE, 6,
+ EGL_BLUE_SIZE, 5,
+ EGL_ALPHA_SIZE, 0,
+ EGL_DEPTH_SIZE, 16,
+ EGL_STENCIL_SIZE, 8,
+ (emulator ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT,
+ (emulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_NONE
+ };
+ }
+
+ /**
+ * Detect if we are in emulator.
+ */
+ private boolean inEmulator() {
+ return System.getProperty("ro.kernel.qemu") != null;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigException.java
new file mode 100644
index 0000000000..d5a1c9951f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/egl/EGLConfigException.java
@@ -0,0 +1,21 @@
+package com.mapbox.mapboxsdk.maps.renderer.egl;
+
+/**
+ * Used for EGL configuration exceptions
+ */
+public class EGLConfigException extends RuntimeException {
+ public EGLConfigException() {
+ }
+
+ public EGLConfigException(String message) {
+ super(message);
+ }
+
+ public EGLConfigException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public EGLConfigException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
new file mode 100644
index 0000000000..ba2e118faa
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
@@ -0,0 +1,81 @@
+package com.mapbox.mapboxsdk.maps.renderer.glsurfaceview;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+
+import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
+import com.mapbox.mapboxsdk.maps.renderer.egl.EGLConfigChooser;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
+
+/**
+ * The {@link GLSurfaceViewMapRenderer} encapsulates the GL thread and
+ * {@link GLSurfaceView} specifics to render the map.
+ *
+ * @see MapRenderer
+ */
+public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceView.Renderer {
+
+ private final GLSurfaceView glSurfaceView;
+
+ public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView) {
+ super(context);
+ this.glSurfaceView = glSurfaceView;
+ glSurfaceView.setEGLContextClientVersion(2);
+ glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
+ glSurfaceView.setRenderer(this);
+ glSurfaceView.setRenderMode(RENDERMODE_WHEN_DIRTY);
+ }
+
+ @Override
+ public void onPause() {
+ glSurfaceView.onPause();
+ }
+
+ @Override
+ public void onResume() {
+ glSurfaceView.onResume();
+ }
+
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ super.onSurfaceCreated(gl, config);
+ }
+
+ @Override
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ super.onSurfaceChanged(gl, width, height);
+ }
+
+ @Override
+ public void onDrawFrame(GL10 gl) {
+ super.onDrawFrame(gl);
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Called from the renderer frontend to schedule a render.
+ */
+ @Override
+ public void requestRender() {
+ glSurfaceView.requestRender();
+ }
+
+ /**
+ * May be called from any thread.
+ *
+ * Schedules work to be performed on the MapRenderer thread.
+ *
+ * @param runnable the runnable to execute
+ */
+ @Override
+ public void queueEvent(Runnable runnable) {
+ glSurfaceView.queueEvent(runnable);
+ }
+
+
+}
--
cgit v1.2.1
From e9bb4d1582dafcb4ca87bdfc6bb58bac2d405954 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 2 Oct 2017 15:41:02 +0300
Subject: [android] texture view map renderer
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 4 +
.../mapboxsdk/maps/renderer/MapRenderer.java | 3 +
.../textureview/TextureViewMapRenderer.java | 96 +++++
.../textureview/TextureViewRenderThread.java | 442 +++++++++++++++++++++
4 files changed, 545 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 c316ea27d8..b5546f2cc4 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
@@ -386,6 +386,10 @@ public class MapView extends FrameLayout {
mapCallback.clearOnMapReadyCallbacks();
nativeMapView.destroy();
nativeMapView = null;
+
+ if (mapRenderer != null) {
+ mapRenderer.onDestroy();
+ }
}
@Override
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index a7c0fa3778..961438ed14 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -41,6 +41,9 @@ public abstract class MapRenderer implements MapRendererScheduler {
// Implement if needed
}
+ public void onDestroy() {
+ // Implement if needed
+ }
public void setOnFpsChangedListener(MapboxMap.OnFpsChangedListener listener) {
onFpsChangedListener = listener;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
new file mode 100644
index 0000000000..8cd724a828
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
@@ -0,0 +1,96 @@
+package com.mapbox.mapboxsdk.maps.renderer.textureview;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.view.TextureView;
+
+import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * The {@link TextureViewMapRenderer} encapsulates the GL thread and
+ * {@link TextureView} specifics to render the map.
+ *
+ * @see MapRenderer
+ */
+public class TextureViewMapRenderer extends MapRenderer {
+ private TextureViewRenderThread renderThread;
+
+ /**
+ * Create a {@link MapRenderer} for the given {@link TextureView}
+ *
+ * @param context the current Context
+ * @param textureView the TextureView
+ */
+ public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView) {
+ super(context);
+ renderThread = new TextureViewRenderThread(textureView, this);
+ renderThread.start();
+ }
+
+ /**
+ * Overridden to provide package access
+ */
+ @Override
+ protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ super.onSurfaceCreated(gl, config);
+ }
+
+ /**
+ * Overridden to provide package access
+ */
+ @Override
+ protected void onSurfaceChanged(GL10 gl, int width, int height) {
+ super.onSurfaceChanged(gl, width, height);
+ }
+
+ /**
+ * Overridden to provide package access
+ */
+ @Override
+ protected void onDrawFrame(GL10 gl) {
+ super.onDrawFrame(gl);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void requestRender() {
+ renderThread.requestRender();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void queueEvent(Runnable runnable) {
+ renderThread.queueEvent(runnable);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPause() {
+ renderThread.onPause();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onResume() {
+ renderThread.onResume();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onDestroy() {
+ renderThread.onDestroy();
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
new file mode 100644
index 0000000000..3ed55b634a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
@@ -0,0 +1,442 @@
+package com.mapbox.mapboxsdk.maps.renderer.textureview;
+
+import android.graphics.SurfaceTexture;
+import android.support.annotation.NonNull;
+import android.support.annotation.UiThread;
+import android.view.TextureView;
+
+import com.mapbox.mapboxsdk.maps.renderer.egl.EGLConfigChooser;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGL11;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.egl.EGLContext;
+import javax.microedition.khronos.egl.EGLDisplay;
+import javax.microedition.khronos.egl.EGLSurface;
+import javax.microedition.khronos.opengles.GL10;
+
+import timber.log.Timber;
+
+/**
+ * The render thread is responsible for managing the communication between the
+ * ui thread and the render thread it creates. Also, the EGL and GL contexts
+ * are managed from here.
+ */
+class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextureListener {
+
+ private final TextureViewMapRenderer mapRenderer;
+ private final EGLHolder eglHolder;
+
+ // Lock used for synchronization
+ private final Object lock = new Object();
+
+ // Guarded by lock
+ private final ArrayList eventQueue = new ArrayList<>();
+ private SurfaceTexture surface;
+ private int width;
+ private int height;
+ private boolean requestRender;
+ private boolean sizeChanged;
+ private boolean paused;
+ private boolean destroyContext;
+ private boolean destroySurface;
+ private boolean shouldExit;
+ private boolean exited;
+
+ /**
+ * Create a render thread for the given TextureView / Maprenderer combination.
+ *
+ * @param textureView the TextureView
+ * @param mapRenderer the MapRenderer
+ */
+ @UiThread
+ TextureViewRenderThread(@NonNull TextureView textureView, @NonNull TextureViewMapRenderer mapRenderer) {
+ textureView.setSurfaceTextureListener(this);
+ this.mapRenderer = mapRenderer;
+ this.eglHolder = new EGLHolder(new WeakReference<>(textureView));
+ }
+
+ // SurfaceTextureListener methods
+
+ @UiThread
+ @Override
+ public void onSurfaceTextureAvailable(final SurfaceTexture surface, final int width, final int height) {
+ synchronized (lock) {
+ this.surface = surface;
+ this.width = width;
+ this.height = height;
+ this.requestRender = true;
+ lock.notifyAll();
+ }
+ }
+
+ @Override
+ @UiThread
+ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, final int width, final int height) {
+ synchronized (lock) {
+ this.width = width;
+ this.height = height;
+ this.sizeChanged = true;
+ this.requestRender = true;
+ lock.notifyAll();
+ }
+ }
+
+ @Override
+ @UiThread
+ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
+ synchronized (lock) {
+ this.surface = null;
+ this.destroySurface = true;
+ this.requestRender = false;
+ lock.notifyAll();
+ }
+ return true;
+ }
+
+ @Override
+ @UiThread
+ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
+ // Ignored
+ }
+
+ // MapRenderer delegate methods
+
+ /**
+ * May be called from any thread
+ */
+ void requestRender() {
+ synchronized (lock) {
+ requestRender = true;
+ lock.notifyAll();
+ }
+ }
+
+ /**
+ * May be called from any thread
+ */
+ void queueEvent(Runnable runnable) {
+ if (runnable == null) {
+ throw new IllegalArgumentException("runnable must not be null");
+ }
+ synchronized (lock) {
+ eventQueue.add(runnable);
+ lock.notifyAll();
+ }
+ }
+
+
+ @UiThread
+ void onPause() {
+ synchronized (lock) {
+ this.paused = true;
+ lock.notifyAll();
+ }
+ }
+
+ @UiThread
+ void onResume() {
+ synchronized (lock) {
+ this.paused = false;
+ lock.notifyAll();
+ }
+ }
+
+
+ @UiThread
+ void onDestroy() {
+ synchronized (lock) {
+ this.shouldExit = true;
+ lock.notifyAll();
+
+ // Wait for the thread to exit
+ while (!this.exited) {
+ try {
+ lock.wait();
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+
+ // Thread implementation
+
+ @Override
+ public void run() {
+ try {
+
+ while (true) {
+ Runnable event = null;
+ boolean initializeEGL = false;
+ boolean recreateSurface = false;
+ int w = -1;
+ int h = -1;
+
+ // Guarded block
+ synchronized (lock) {
+ while (true) {
+
+ if (shouldExit) {
+ return;
+ }
+
+ // If any events are scheduled, pop one for processing
+ if (!eventQueue.isEmpty()) {
+ event = eventQueue.remove(0);
+ break;
+ }
+
+ if (destroySurface) {
+ eglHolder.destroySurface();
+ destroySurface = false;
+ break;
+ }
+
+ if (destroyContext) {
+ eglHolder.destroyContext();
+ destroyContext = false;
+ break;
+ }
+
+ if (surface != null && !paused && requestRender) {
+
+ w = width;
+ h = height;
+
+ // Initialize EGL if needed
+ if (eglHolder.eglContext == EGL10.EGL_NO_CONTEXT) {
+ initializeEGL = true;
+ break;
+ }
+
+ // Check if the size has changed
+ if (sizeChanged) {
+ recreateSurface = true;
+ sizeChanged = false;
+ break;
+ }
+
+ // Reset the request render flag now, so we can catch new requests
+ // while rendering
+ requestRender = false;
+
+ // Break the guarded loop and continue to process
+ break;
+ }
+
+
+ // Wait until needed
+ lock.wait();
+
+ } // end guarded while loop
+
+ } // end guarded block
+
+ // Run event, if any
+ if (event != null) {
+ event.run();
+ continue;
+ }
+
+ GL10 gl = eglHolder.createGL();
+
+ // Initialize EGL
+ if (initializeEGL) {
+ eglHolder.prepare();
+ eglHolder.createSurface();
+ mapRenderer.onSurfaceCreated(gl, eglHolder.eglConfig);
+ mapRenderer.onSurfaceChanged(gl, w, h);
+ continue;
+ }
+
+ // If the surface size has changed inform the map renderer.
+ if (recreateSurface) {
+ eglHolder.createSurface();
+ mapRenderer.onSurfaceChanged(gl, w, h);
+ continue;
+ }
+
+ // Don't continue without a surface
+ if (eglHolder.eglSurface == EGL10.EGL_NO_SURFACE) {
+ continue;
+ }
+
+ // Time to render a frame
+ mapRenderer.onDrawFrame(gl);
+
+ // Swap and check the result
+ int swapError = eglHolder.swap();
+ switch (swapError) {
+ case EGL10.EGL_SUCCESS:
+ break;
+ case EGL11.EGL_CONTEXT_LOST:
+ Timber.w("Context lost. Waiting for re-aquire");
+ synchronized (lock) {
+ surface = null;
+ destroySurface = true;
+ destroyContext = true;
+ }
+ break;
+ default:
+ Timber.w("eglSwapBuffer error: %s. Waiting or new surface", swapError);
+ // Probably lost the surface. Clear the current one and
+ // wait for a new one to be set
+ synchronized (lock) {
+ surface = null;
+ destroySurface = true;
+ }
+ }
+
+ }
+
+ } catch (InterruptedException err) {
+ // To be expected
+ } finally {
+ // Cleanup
+ eglHolder.cleanup();
+
+ // Signal we're done
+ synchronized (lock) {
+ this.exited = true;
+ lock.notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Holds the EGL state and offers methods to mutate it.
+ */
+ private static class EGLHolder {
+ private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
+ private final WeakReference textureViewWeakRef;
+
+ private EGL10 egl;
+ private EGLConfig eglConfig;
+ private EGLDisplay eglDisplay = EGL10.EGL_NO_DISPLAY;
+ private EGLContext eglContext = EGL10.EGL_NO_CONTEXT;
+ private EGLSurface eglSurface = EGL10.EGL_NO_SURFACE;
+
+ EGLHolder(WeakReference textureViewWeakRef) {
+ this.textureViewWeakRef = textureViewWeakRef;
+ }
+
+ void prepare() {
+ this.egl = (EGL10) EGLContext.getEGL();
+
+ // Only re-initialize display when needed
+ if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
+ this.eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+
+ if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
+ throw new RuntimeException("eglGetDisplay failed");
+ }
+
+ int[] version = new int[2];
+ if (!egl.eglInitialize(eglDisplay, version)) {
+ throw new RuntimeException("eglInitialize failed");
+ }
+ }
+
+ if (textureViewWeakRef == null) {
+ // No texture view present
+ eglConfig = null;
+ eglContext = EGL10.EGL_NO_CONTEXT;
+ } else /*if (eglContext == EGL10.EGL_NO_CONTEXT)*/ {
+ eglConfig = new EGLConfigChooser().chooseConfig(egl, eglDisplay);
+ int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
+ eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
+ }
+
+ if (eglContext == EGL10.EGL_NO_CONTEXT) {
+ throw new RuntimeException("createContext");
+ }
+ }
+
+ GL10 createGL() {
+ return (GL10) eglContext.getGL();
+ }
+
+ boolean createSurface() {
+ // The window size has changed, so we need to create a new surface.
+ destroySurface();
+
+ // Create an EGL surface we can render into.
+ TextureView view = textureViewWeakRef.get();
+ if (view != null) {
+ int[] surfaceAttribs = {EGL10.EGL_NONE};
+ eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, view.getSurfaceTexture(), surfaceAttribs);
+ } else {
+ eglSurface = EGL10.EGL_NO_SURFACE;
+ }
+
+ if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
+ int error = egl.eglGetError();
+ if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
+ Timber.e("createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
+ }
+ return false;
+ }
+
+ return makeCurrent();
+ }
+
+ boolean makeCurrent() {
+ if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
+ // Could not make the context current, probably because the underlying
+ // SurfaceView surface has been destroyed.
+ Timber.w("eglMakeCurrent: %s", egl.eglGetError());
+ return false;
+ }
+
+ return true;
+ }
+
+ int swap() {
+ if (!egl.eglSwapBuffers(eglDisplay, eglSurface)) {
+ return egl.eglGetError();
+ }
+ return EGL10.EGL_SUCCESS;
+ }
+
+ private void destroySurface() {
+ if (eglSurface == EGL10.EGL_NO_SURFACE) {
+ return;
+ }
+
+ if (!egl.eglDestroySurface(eglDisplay, eglSurface)) {
+ Timber.e("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface);
+ throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ }
+ }
+
+ private void destroyContext() {
+ if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
+ return;
+ }
+
+ if (!egl.eglDestroyContext(eglDisplay, eglContext)) {
+ Timber.e("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext);
+ throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ }
+ }
+
+ private void terminate() {
+ if (eglDisplay != EGL10.EGL_NO_DISPLAY) {
+ if (!egl.eglTerminate(eglDisplay)) {
+ Timber.w("Could not terminate egl. Display %s", eglDisplay);
+ }
+ eglDisplay = EGL10.EGL_NO_DISPLAY;
+ }
+ }
+
+ void cleanup() {
+ destroySurface();
+ destroyContext();
+ terminate();
+ }
+ }
+}
--
cgit v1.2.1
From 3b2bd7ce4f7087f51f2aeace22fe60c5c83ee1d9 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Tue, 31 Oct 2017 18:12:04 +0200
Subject: [android] bring back texture view
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 66 +++++++++++++++-------
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 37 +++++++++++-
.../src/main/res-public/values/public.xml | 3 +
.../src/main/res/values/attrs.xml | 3 +
4 files changed, 85 insertions(+), 24 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 b5546f2cc4..ba09df2cbe 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
@@ -15,6 +15,7 @@ import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
+import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
@@ -29,6 +30,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
+import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
@@ -139,7 +141,7 @@ public class MapView extends FrameLayout {
} else {
getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
- initialiseDrawingSurface();
+ initialiseDrawingSurface(options);
}
});
}
@@ -289,31 +291,53 @@ public class MapView extends FrameLayout {
}
}
- private void initialiseDrawingSurface() {
- GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
- glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
+ private void initialiseDrawingSurface(MapboxMapOptions options) {
+ if (options.getTextureMode()) {
+ TextureView textureView = new TextureView(getContext());
+ mapRenderer = new TextureViewMapRenderer(getContext(), textureView) {
+ @Override
+ protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ MapView.this.post(new Runnable() {
+ @Override
+ public void run() {
+ // Initialise only once
+ if (mapboxMap == null) {
+ initialiseMap();
+ mapboxMap.onStart();
+ }
+ }
+ });
- GLSurfaceViewMapRenderer mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) {
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- MapView.this.post(new Runnable() {
- @Override
- public void run() {
- // Initialise only once
- if (mapboxMap == null) {
- initialiseMap();
- mapboxMap.onStart();
+ super.onSurfaceCreated(gl, config);
+ }
+ };
+ addView(textureView, 0);
+ } else {
+ GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
+ glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
+
+ mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) {
+ @Override
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ MapView.this.post(new Runnable() {
+ @Override
+ public void run() {
+ // Initialise only once
+ if (mapboxMap == null) {
+ initialiseMap();
+ mapboxMap.onStart();
+ }
}
- }
- });
+ });
- super.onSurfaceCreated(gl, config);
- }
- };
+ super.onSurfaceCreated(gl, config);
+ }
+ };
- glSurfaceView.setVisibility(View.VISIBLE);
+ glSurfaceView.setVisibility(View.VISIBLE);
+
+ }
- this.mapRenderer = mapRenderer;
nativeMapView = new NativeMapView(this, mapRenderer);
nativeMapView.resizeView(getMeasuredWidth(), getMeasuredHeight());
}
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 7b979f5563..f26e0b9d3b 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
@@ -85,6 +85,8 @@ public class MapboxMapOptions implements Parcelable {
private String apiBaseUrl;
+ private boolean textureMode;
+
private String style;
/**
@@ -152,7 +154,7 @@ public class MapboxMapOptions implements Parcelable {
style = in.readString();
apiBaseUrl = in.readString();
-
+ textureMode = in.readByte() != 0;
prefetchesTiles = in.readByte() != 0;
zMediaOverlay = in.readByte() != 0;
}
@@ -296,6 +298,8 @@ public class MapboxMapOptions implements Parcelable {
ColorUtils.getPrimaryColor(context)));
mapboxMapOptions.myLocationAccuracyThreshold(
typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyThreshold, 0));
+ mapboxMapOptions.textureMode(
+ typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
mapboxMapOptions.setPrefetchesTiles(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
mapboxMapOptions.renderSurfaceOnTop(
@@ -698,13 +702,30 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
+ /**
+ * Enable {@link android.view.TextureView} as rendered surface.
+ *
+ * Since the 5.2.0 release we replaced our TextureView with an {@link android.opengl.GLSurfaceView}
+ * implementation. Enabling this option will use the {@link android.view.TextureView} instead.
+ * {@link android.view.TextureView} can be useful in situations where you need to animate, scale
+ * or transform the view. This comes at a siginficant performance penalty and should not be considered
+ * unless absolutely needed.
+ *
+ *
+ * @param textureMode True to enable texture mode
+ * @return This
+ */
+ public MapboxMapOptions textureMode(boolean textureMode) {
+ this.textureMode = textureMode;
+ return this;
+ }
+
/**
* Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render
* a low resolution preview while more detailed tiles are loaded.
* Enabled by default
*
* @param enable true to enable
- *
* @return This
*/
public MapboxMapOptions setPrefetchesTiles(boolean enable) {
@@ -1049,6 +1070,15 @@ public class MapboxMapOptions implements Parcelable {
return debugActive;
}
+ /**
+ * Returns true if TextureView is being used the render view.
+ *
+ * @return True if TextureView is used.
+ */
+ public boolean getTextureMode() {
+ return textureMode;
+ }
+
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
@@ -1112,7 +1142,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeString(style);
dest.writeString(apiBaseUrl);
-
+ dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
}
@@ -1289,6 +1319,7 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (myLocationAccuracyThreshold != +0.0f
? Float.floatToIntBits(myLocationAccuracyThreshold) : 0);
result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0);
+ result = 31 * result + (textureMode ? 1 : 0);
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
result = 31 * result + (zMediaOverlay ? 1 : 0);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index 40045f851f..f406f4d042 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -72,6 +72,9 @@
+
+
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index b673224094..2a4c2fe746 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -114,6 +114,9 @@
+
+
+
--
cgit v1.2.1
From 8753edf08f4634a9f49020741464a6b7dc61cf2d Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Wed, 1 Nov 2017 11:43:27 +0200
Subject: [android] test app - texture view test activities
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 ba09df2cbe..c025a119b7 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
@@ -28,8 +28,8 @@ import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
-import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.MapRenderer;
+import com.mapbox.mapboxsdk.maps.renderer.glsurfaceview.GLSurfaceViewMapRenderer;
import com.mapbox.mapboxsdk.maps.renderer.textureview.TextureViewMapRenderer;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
@@ -50,7 +50,6 @@ import javax.microedition.khronos.opengles.GL10;
import timber.log.Timber;
-import static android.opengl.GLSurfaceView.RENDERMODE_WHEN_DIRTY;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
--
cgit v1.2.1
From d1d0c200442133e2eca110e3521f1caf831eda5c Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Fri, 3 Nov 2017 11:33:00 +0200
Subject: [android] TextureView - cleanup destruction code
---
.../textureview/TextureViewRenderThread.java | 41 +++++++++++++++-------
1 file changed, 29 insertions(+), 12 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
index 3ed55b634a..c34833e9ce 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewRenderThread.java
@@ -213,6 +213,12 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
break;
}
+ // (re-)Initialize EGL Surface if needed
+ if (eglHolder.eglSurface == EGL10.EGL_NO_SURFACE) {
+ recreateSurface = true;
+ break;
+ }
+
// Check if the size has changed
if (sizeChanged) {
recreateSurface = true;
@@ -247,7 +253,14 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
// Initialize EGL
if (initializeEGL) {
eglHolder.prepare();
- eglHolder.createSurface();
+ if (!eglHolder.createSurface()) {
+ synchronized (lock) {
+ // Cleanup the surface if one could not be created
+ // and wait for another to be ready.
+ destroySurface = true;
+ }
+ continue;
+ }
mapRenderer.onSurfaceCreated(gl, eglHolder.eglConfig);
mapRenderer.onSurfaceChanged(gl, w, h);
continue;
@@ -345,7 +358,7 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
// No texture view present
eglConfig = null;
eglContext = EGL10.EGL_NO_CONTEXT;
- } else /*if (eglContext == EGL10.EGL_NO_CONTEXT)*/ {
+ } else if (eglContext == EGL10.EGL_NO_CONTEXT) {
eglConfig = new EGLConfigChooser().chooseConfig(egl, eglDisplay);
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
eglContext = egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
@@ -408,29 +421,33 @@ class TextureViewRenderThread extends Thread implements TextureView.SurfaceTextu
}
if (!egl.eglDestroySurface(eglDisplay, eglSurface)) {
- Timber.e("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface);
- throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ Timber.w("Could not destroy egl surface. Display %s, Surface %s", eglDisplay, eglSurface);
}
+
+ eglSurface = EGL10.EGL_NO_SURFACE;
}
private void destroyContext() {
- if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
+ if (eglContext == EGL10.EGL_NO_CONTEXT) {
return;
}
if (!egl.eglDestroyContext(eglDisplay, eglContext)) {
- Timber.e("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext);
- throw new RuntimeException("eglDestroyContext: " + egl.eglGetError());
+ Timber.w("Could not destroy egl context. Display %s, Context %s", eglDisplay, eglContext);
}
+
+ eglContext = EGL10.EGL_NO_CONTEXT;
}
private void terminate() {
- if (eglDisplay != EGL10.EGL_NO_DISPLAY) {
- if (!egl.eglTerminate(eglDisplay)) {
- Timber.w("Could not terminate egl. Display %s", eglDisplay);
- }
- eglDisplay = EGL10.EGL_NO_DISPLAY;
+ if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
+ return;
+ }
+
+ if (!egl.eglTerminate(eglDisplay)) {
+ Timber.w("Could not terminate egl. Display %s", eglDisplay);
}
+ eglDisplay = EGL10.EGL_NO_DISPLAY;
}
void cleanup() {
--
cgit v1.2.1
From cdc5dde0ec5add19ad327d1afa8c9ed8803900df Mon Sep 17 00:00:00 2001
From: Pablo Guardiola
Date: Fri, 3 Nov 2017 15:39:53 -0700
Subject: [android] revert adding mapbox-android-core dependency (#10354)
(#10380)
---
platform/android/MapboxGLAndroidSDK/build.gradle | 3 +-
.../com/mapbox/mapboxsdk/EmptyLocationSource.java | 4 +-
.../src/main/java/com/mapbox/mapboxsdk/Mapbox.java | 6 +--
.../mapbox/mapboxsdk/location/LocationSource.java | 43 +++++++---------------
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 2 +-
.../mapbox/mapboxsdk/maps/TrackingSettings.java | 4 +-
.../mapboxsdk/maps/widgets/MyLocationView.java | 6 +--
.../test/java/com/mapbox/mapboxsdk/MapboxTest.java | 2 +-
8 files changed, 26 insertions(+), 44 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 49806780b5..f3e9433a0b 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -6,6 +6,7 @@ dependencies {
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
provided(rootProject.ext.dep.lost) {
+ exclude group: 'com.google.guava'
exclude group: 'com.android.support'
}
testCompile rootProject.ext.dep.junit
@@ -21,8 +22,6 @@ dependencies {
transitive = true
exclude group: 'com.android.support'
}
-
- compile(rootProject.ext.dep.mapboxAndroidCore)
}
android {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
index d24ed5a113..8ea7e61eee 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/EmptyLocationSource.java
@@ -5,8 +5,8 @@ import android.location.Location;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.location.LocationSource;
-import com.mapbox.services.android.core.location.LocationEngine;
-import com.mapbox.services.android.core.location.LocationEngineListener;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngineListener;
class EmptyLocationSource extends LocationSource {
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 e575dc9062..357bcd5f99 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
@@ -12,9 +12,9 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
-import com.mapbox.services.android.core.location.LocationEngine;
-import com.mapbox.services.android.core.location.LocationEnginePriority;
-import com.mapbox.services.android.core.location.LocationEngineProvider;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
+import com.mapbox.services.android.telemetry.location.LocationEngineProvider;
import com.mapbox.services.android.telemetry.MapboxTelemetry;
import timber.log.Timber;
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 5129db08e8..c6bc13f538 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
@@ -5,9 +5,9 @@ import android.location.Location;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.Mapbox;
-import com.mapbox.services.android.core.location.LocationEngine;
-import com.mapbox.services.android.core.location.LocationEngineListener;
-import com.mapbox.services.android.core.location.LocationEnginePriority;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngineListener;
+import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import com.mapzen.android.lost.api.LocationListener;
import com.mapzen.android.lost.api.LocationRequest;
import com.mapzen.android.lost.api.LocationServices;
@@ -32,7 +32,7 @@ import com.mapzen.android.lost.api.LostApiClient;
* @deprecated Use a {@link Mapbox#getLocationEngine()} instead.
*/
@Deprecated
-public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener {
+public class LocationSource extends LocationEngine implements LocationListener {
private Context context;
private LostApiClient lostApiClient;
@@ -45,9 +45,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
public LocationSource(Context context) {
super();
this.context = context.getApplicationContext();
- lostApiClient = new LostApiClient.Builder(this.context)
- .addConnectionCallbacks(this)
- .build();
+ lostApiClient = new LostApiClient.Builder(this.context).build();
}
/**
@@ -63,9 +61,12 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
*/
@Override
public void activate() {
- if (lostApiClient != null && !lostApiClient.isConnected()) {
+ if (!lostApiClient.isConnected()) {
lostApiClient.connect();
}
+ for (LocationEngineListener listener : locationListeners) {
+ listener.onConnected();
+ }
}
/**
@@ -75,7 +76,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
*/
@Override
public void deactivate() {
- if (lostApiClient != null && lostApiClient.isConnected()) {
+ if (lostApiClient.isConnected()) {
lostApiClient.disconnect();
}
}
@@ -91,24 +92,6 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
return lostApiClient.isConnected();
}
- /**
- * Invoked when the location provider has connected.
- */
- @Override
- public void onConnected() {
- for (LocationEngineListener listener : locationListeners) {
- listener.onConnected();
- }
- }
-
- /**
- * Invoked when the location provider connection has been suspended.
- */
- @Override
- public void onConnectionSuspended() {
- // Intentionally left empty
- }
-
/**
* Returns the Last known location is the location provider is connected and location permissions are granted.
*
@@ -119,7 +102,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
public Location getLastLocation() {
if (lostApiClient.isConnected()) {
//noinspection MissingPermission
- return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
+ return LocationServices.FusedLocationApi.getLastLocation();
}
return null;
}
@@ -153,7 +136,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
if (lostApiClient.isConnected()) {
//noinspection MissingPermission
- LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
+ LocationServices.FusedLocationApi.requestLocationUpdates(request, this);
}
}
@@ -163,7 +146,7 @@ public class LocationSource extends LocationEngine implements LostApiClient.Conn
@Override
public void removeLocationUpdates() {
if (lostApiClient.isConnected()) {
- LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
+ LocationServices.FusedLocationApi.removeLocationUpdates(this);
}
}
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 f0461b6307..6bf8342efb 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
@@ -42,7 +42,7 @@ 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.core.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
import com.mapbox.services.commons.geojson.Feature;
import com.mapbox.services.commons.geojson.Geometry;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
index 2f85c82587..6eacbbaeaf 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/TrackingSettings.java
@@ -12,8 +12,8 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
-import com.mapbox.services.android.core.location.LocationEngine;
-import com.mapbox.services.android.core.location.LocationEngineListener;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngineListener;
import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
import timber.log.Timber;
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 cc7602e056..aa7934ec1e 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
@@ -36,9 +36,9 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.location.LocationSource;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.Projection;
-import com.mapbox.services.android.core.location.LocationEngine;
-import com.mapbox.services.android.core.location.LocationEngineListener;
-import com.mapbox.services.android.core.location.LocationEnginePriority;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngineListener;
+import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
import java.lang.ref.WeakReference;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
index 09acf3feef..7a28d846ea 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
@@ -5,7 +5,7 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
-import com.mapbox.services.android.core.location.LocationEngine;
+import com.mapbox.services.android.telemetry.location.LocationEngine;
import org.junit.Before;
import org.junit.Test;
--
cgit v1.2.1
From 4d486e10ce394c44d3bfab5989af7d03014d75e9 Mon Sep 17 00:00:00 2001
From: tobrun
Date: Mon, 6 Nov 2017 15:28:11 +0100
Subject: [android] - check for null value when calling mapboxMap.clear
---
.../main/java/com/mapbox/mapboxsdk/maps/IconManager.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/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java
index b1d6df2103..80ffa973e7 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
@@ -143,11 +143,14 @@ class IconManager {
}
void iconCleanup(Icon icon) {
- int refCounter = iconMap.get(icon) - 1;
- if (refCounter == 0) {
- remove(icon);
- } else {
- updateIconRefCounter(icon, refCounter);
+ Integer refCounter = iconMap.get(icon);
+ if (refCounter != null) {
+ refCounter--;
+ if (refCounter == 0) {
+ remove(icon);
+ } else {
+ updateIconRefCounter(icon, refCounter);
+ }
}
}
--
cgit v1.2.1
From 24de48b7724cb359b3044cd691588a221dd2b550 Mon Sep 17 00:00:00 2001
From: tobrun
Date: Mon, 6 Nov 2017 14:36:13 +0100
Subject: [android] - update android unit tests, update test make target to SDK
---
.../java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java | 9 ---------
.../java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java | 11 +++++++++--
2 files changed, 9 insertions(+), 11 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
index 8d9a360714..bb96c9939d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
@@ -73,15 +73,6 @@ public class LatLngBoundsTest {
assertEquals("Center should match", new LatLng(1, 1), center);
}
- @Test
- public void emptySpan() {
- latLngBounds = new LatLngBounds.Builder()
- .include(LAT_LNG_NOT_NULL_ISLAND)
- .include(LAT_LNG_NOT_NULL_ISLAND)
- .build();
- assertTrue("Should be empty", latLngBounds.isEmptySpan());
- }
-
@Test
public void notEmptySpan() {
latLngBounds = new LatLngBounds.Builder()
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
index 0d592f9bb3..239ad7392b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
@@ -10,6 +10,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
import com.mapbox.mapboxsdk.geometry.LatLng;
import org.junit.Test;
+import org.mockito.ArgumentMatchers;
import java.util.ArrayList;
import java.util.List;
@@ -32,8 +33,9 @@ public class AnnotationManagerTest {
Markers markers = new MarkerContainer(aNativeMapView, aMapView, annotationsArray, aIconManager, aMarkerViewManager);
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
+ ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
AnnotationManager annotationManager = new AnnotationManager(aNativeMapView, aMapView, annotationsArray,
- aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines);
+ aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
Marker aMarker = mock(Marker.class);
long aId = 5L;
when(aNativeMapView.addMarker(aMarker)).thenReturn(aId);
@@ -58,18 +60,23 @@ public class AnnotationManagerTest {
Markers markers = new MarkerContainer(aNativeMapView, aMapView, annotationsArray, aIconManager, aMarkerViewManager);
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
+ ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
AnnotationManager annotationManager = new AnnotationManager(aNativeMapView, aMapView, annotationsArray,
- aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines);
+ aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
long firstId = 1L;
long secondId = 2L;
List markerList = new ArrayList<>();
MarkerOptions firstMarkerOption = new MarkerOptions().position(new LatLng()).title("first");
MarkerOptions secondMarkerOption = new MarkerOptions().position(new LatLng()).title("second");
+
markerList.add(firstMarkerOption);
markerList.add(secondMarkerOption);
MapboxMap aMapboxMap = mock(MapboxMap.class);
when(aNativeMapView.addMarker(any(Marker.class))).thenReturn(firstId, secondId);
+ when(aNativeMapView.addMarkers(ArgumentMatchers.anyList()))
+ .thenReturn(new long[]{firstId, secondId});
+
annotationManager.addMarkers(markerList, aMapboxMap);
assertEquals(2, annotationManager.getAnnotations().size());
--
cgit v1.2.1
From a47f8245dacffad2b7f8f71a38b7eb41ee28b0b5 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Fri, 10 Nov 2017 16:33:51 +0100
Subject: Monkey crashes (#10440)
* [android] - avoid null map from trackballevent
* [android] - fixup animated marker test activity from monkey runs
* [android] - harden NativeMapView OnMapChangeListener
* [android] - harden against destroyed wrapper activity while moving touch pointers
* [android] - harden bulk marker activity for monkey runner
* [android] - harden scale end gesture event for null velocity tracker
* [android] - invalid mapboxMap invocation
* [android] - reset test setup
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 11 +++++++++--
.../com/mapbox/mapboxsdk/maps/NativeMapView.java | 4 +++-
.../java/com/mapbox/mapboxsdk/maps/Transform.java | 20 +++++++++++---------
3 files changed, 23 insertions(+), 12 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 4120e164a4..9d7d980ae3 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
@@ -235,8 +235,10 @@ final class MapGestureDetector {
velocityTracker = null;
break;
case MotionEvent.ACTION_MOVE:
- velocityTracker.addMovement(event);
- velocityTracker.computeCurrentVelocity(1000);
+ if (velocityTracker != null) {
+ velocityTracker.addMovement(event);
+ velocityTracker.computeCurrentVelocity(1000);
+ }
break;
}
@@ -551,6 +553,11 @@ final class MapGestureDetector {
// Called when fingers leave screen
@Override
public void onScaleEnd(final ScaleGestureDetector detector) {
+ if (velocityTracker == null) {
+ return;
+ }
+
+
if (rotateGestureOccurred || quickZoom) {
reset();
return;
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 8b6bce69e2..e8eb7e8718 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
@@ -1082,7 +1082,9 @@ final class NativeMapView {
//
void addOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
- mapView.addOnMapChangedListener(listener);
+ if (mapView != null) {
+ mapView.addOnMapChangedListener(listener);
+ }
}
void removeOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
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 0366e50627..16c45ebea2 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
@@ -238,16 +238,18 @@ 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) {
- cameraChangeDispatcher.onCameraIdle();
- mapView.removeOnMapChangedListener(this);
+ if (mapView != null) {
+ mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
+ @Override
+ public void onMapChanged(int change) {
+ if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
+ cameraChangeDispatcher.onCameraIdle();
+ mapView.removeOnMapChangedListener(this);
+ }
}
- }
- });
- mapView.setZoom(zoom, focalPoint, duration);
+ });
+ mapView.setZoom(zoom, focalPoint, duration);
+ }
}
// Direction
--
cgit v1.2.1
From 7dabec61b6b66781feade474e1092086596790f2 Mon Sep 17 00:00:00 2001
From: Ivo van Dongen
Date: Mon, 20 Nov 2017 15:22:34 +0200
Subject: [android] Enable map rendering when app is paused
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 9 +++++++++
.../java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java | 8 ++++++++
.../maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java | 4 ++--
.../maps/renderer/textureview/TextureViewMapRenderer.java | 4 ++--
4 files changed, 21 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 c025a119b7..beb51d7b68 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
@@ -365,6 +365,10 @@ public class MapView extends FrameLayout {
if (mapboxMap != null) {
mapboxMap.onStart();
}
+
+ if (mapRenderer != null) {
+ mapRenderer.onStart();
+ }
}
/**
@@ -396,6 +400,11 @@ public class MapView extends FrameLayout {
// map was destroyed before it was started
mapboxMap.onStop();
}
+
+ if (mapRenderer != null) {
+ mapRenderer.onStop();
+ }
+
ConnectivityReceiver.instance(getContext()).deactivate();
FileSource.getInstance(getContext()).deactivate();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index 961438ed14..2baff473e9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -33,6 +33,10 @@ public abstract class MapRenderer implements MapRendererScheduler {
nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
}
+ public void onStart() {
+ // Implement if needed
+ }
+
public void onPause() {
// Implement if needed
}
@@ -41,6 +45,10 @@ public abstract class MapRenderer implements MapRendererScheduler {
// Implement if needed
}
+ public void onStop() {
+ // Implement if needed
+ }
+
public void onDestroy() {
// Implement if needed
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
index ba2e118faa..d98e4d06a3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
@@ -31,12 +31,12 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
}
@Override
- public void onPause() {
+ public void onStop() {
glSurfaceView.onPause();
}
@Override
- public void onResume() {
+ public void onStart() {
glSurfaceView.onResume();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
index 8cd724a828..397904b1f5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
@@ -74,7 +74,7 @@ public class TextureViewMapRenderer extends MapRenderer {
* {@inheritDoc}
*/
@Override
- public void onPause() {
+ public void onStop() {
renderThread.onPause();
}
@@ -82,7 +82,7 @@ public class TextureViewMapRenderer extends MapRenderer {
* {@inheritDoc}
*/
@Override
- public void onResume() {
+ public void onStart() {
renderThread.onResume();
}
--
cgit v1.2.1
From 59a8fd2ff85a2ee627a191a5bf327effacdd6e22 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 22 Nov 2017 17:08:23 +0100
Subject: [android] - activate filesource to list offline regions (#10531)
---
.../src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 130284e88d..6a2bf6b07b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -149,8 +149,8 @@ public class OfflineManager {
*
* @param callback the callback to be invoked
*/
- public void listOfflineRegions(@NonNull
- final ListOfflineRegionsCallback callback) {
+ public void listOfflineRegions(@NonNull final ListOfflineRegionsCallback callback) {
+ fileSource.activate();
listOfflineRegions(fileSource, new ListOfflineRegionsCallback() {
@Override
@@ -158,6 +158,7 @@ public class OfflineManager {
getHandler().post(new Runnable() {
@Override
public void run() {
+ fileSource.deactivate();
callback.onList(offlineRegions);
}
});
@@ -168,6 +169,7 @@ public class OfflineManager {
getHandler().post(new Runnable() {
@Override
public void run() {
+ fileSource.deactivate();
callback.onError(error);
}
});
@@ -241,6 +243,7 @@ public class OfflineManager {
/**
* Changing or bypassing this limit without permission from Mapbox is prohibited
* by the Mapbox Terms of Service.
+ *
* @param limit the new tile count limit.
*/
public native void setOfflineMapboxTileCountLimit(long limit);
--
cgit v1.2.1
From e3f1d8e3a0beb648ec90ac4d9baa5f27c6cf3935 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 22 Nov 2017 18:46:31 +0100
Subject: [android] - harden MarkerView integration by checking for null bitmap
(#10532)
---
.../src/main/java/com/mapbox/mapboxsdk/annotations/Icon.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/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java
index 2ee17c227d..8749656e35 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
@@ -36,7 +36,7 @@ public class Icon {
* @return The bitmap being used for the icon.
*/
public Bitmap getBitmap() {
- if (mBitmap.getConfig() != Bitmap.Config.ARGB_8888) {
+ if (mBitmap != null && mBitmap.getConfig() != Bitmap.Config.ARGB_8888) {
mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, false);
}
return mBitmap;
--
cgit v1.2.1
From eb6de2c434d6cbd5060a9a19cf4f13ec8a792c3b Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Tue, 31 Oct 2017 11:45:19 -0700
Subject: [android] Bindings for Custom Geometry Sources
---
.../mapbox/mapboxsdk/geometry/LatLngBounds.java | 19 ++
.../style/sources/CustomGeometrySource.java | 203 +++++++++++++++++++++
.../mapboxsdk/style/sources/GeoJsonOptions.java | 11 ++
.../style/sources/GeometryTileProvider.java | 22 +++
.../mapboxsdk/geometry/LatLngBoundsTest.java | 19 ++
5 files changed, 274 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
index 4fcb91033c..4e22814a2c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/LatLngBounds.java
@@ -231,6 +231,25 @@ public class LatLngBounds implements Parcelable {
return new LatLngBounds(latNorth, lonEast, latSouth, lonWest);
}
+ private static double lat_(int z, int y) {
+ double n = Math.PI - 2.0 * Math.PI * y / Math.pow(2.0, z);
+ return Math.toDegrees(Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
+ }
+
+ private static double lon_(int z, int x) {
+ return x / Math.pow(2.0, z) * 360.0 - GeoConstants.MAX_LONGITUDE;
+ }
+
+ /**
+ * Constructs a LatLngBounds from a Tile identifier.
+ * @param z Tile zoom level.
+ * @param x Tile X coordinate.
+ * @param y Tile Y coordinate.
+ */
+ public static LatLngBounds from(int z, int x, int y) {
+ return new LatLngBounds(lat_(z, y), lon_(z, x + 1), lat_(z, y + 1), lon_(z, x));
+ }
+
/**
* Constructs a LatLngBounds from current bounds with an additional latitude-longitude pair.
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
new file mode 100644
index 0000000000..e10be1d4ba
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
@@ -0,0 +1,203 @@
+package com.mapbox.mapboxsdk.style.sources;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.UiThread;
+import android.support.annotation.WorkerThread;
+
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.mapboxsdk.style.layers.Filter;
+import com.mapbox.services.commons.geojson.Feature;
+import com.mapbox.services.commons.geojson.FeatureCollection;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Custom Vector Source, allows using FeatureCollections.
+ *
+ */
+@UiThread
+public class CustomGeometrySource extends Source {
+ private ExecutorService executor;
+ private GeometryTileProvider provider;
+ private final Map cancelledTileRequests = new ConcurrentHashMap<>();
+
+ /**
+ * Create a CustomGeometrySource
+ *
+ * @param id The source id.
+ * @param provider The tile provider that returns geometry data for this source.
+ */
+ public CustomGeometrySource(String id, GeometryTileProvider provider) {
+ this(id, provider, new GeoJsonOptions());
+ }
+
+ /**
+ * Create a CustomGeometrySource with non-default GeoJsonOptions.
+ *
Supported options are minZoom, maxZoom, buffer, and tolerance.
+ *
+ * @param id The source id.
+ * @param provider The tile provider that returns geometry data for this source.
+ * @param options GeoJsonOptions.
+ */
+ public CustomGeometrySource(String id, GeometryTileProvider provider, GeoJsonOptions options) {
+ this.provider = provider;
+ executor = Executors.newFixedThreadPool(4);
+ initialize(this, id, options);
+ }
+
+ /**
+ * Invalidate previously provided features within a given bounds at all zoom levels.
+ * Invoking this method will result in new requests to `GeometryTileProvider` for regions
+ * that contain, include, or intersect with the provided bounds.
+ *
+ * @param bounds The region in which features should be invalidated at all zoom levels
+ */
+ public void invalidateRegion(LatLngBounds bounds) {
+ nativeInvalidateBounds(bounds);
+ }
+
+ /**
+ * Invalidate the geometry contents of a specific tile. Invoking this method will result
+ * in new requests to `GeometryTileProvider` for visible tiles.
+ *
+ * @param zoomLevel Tile zoom level.
+ * @param x Tile X coordinate.
+ * @param y Tile Y coordinate.
+ */
+ public void invalidateTile(int zoomLevel, int x, int y) {
+ nativeInvalidateTile(zoomLevel, x, y);
+ }
+
+ /**
+ * Set or update geometry contents of a specific tile. Use this method to update tiles
+ * for which `GeometryTileProvider` was previously invoked. This method can be called from
+ * background threads.
+ *
+ * @param zoomLevel Tile zoom level.
+ * @param x Tile X coordinate.
+ * @param y Tile Y coordinate.
+ * @param data Feature collection for the tile.
+ */
+ public void setTileData(int zoomLevel, int x, int y, FeatureCollection data) {
+ nativeSetTileData(zoomLevel, x, y, data);
+ }
+
+ /**
+ * Queries the source for features.
+ *
+ * @param filter an optional filter statement to filter the returned Features
+ * @return the features
+ */
+ @NonNull
+ public List querySourceFeatures(@Nullable Filter.Statement filter) {
+ Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
+ return features != null ? Arrays.asList(features) : new ArrayList();
+ }
+
+ protected native void initialize(CustomGeometrySource self, String sourceId, Object options);
+
+ private native Feature[] querySourceFeatures(Object[] filter);
+
+ private native void nativeSetTileData(int z, int x, int y, FeatureCollection data);
+
+ private native void nativeInvalidateTile(int z, int x, int y);
+
+ private native void nativeInvalidateBounds(LatLngBounds bounds);
+
+ @Override
+ protected native void finalize() throws Throwable;
+
+ private void setTileData(TileID tileId, FeatureCollection data) {
+ cancelledTileRequests.remove(tileId);
+ nativeSetTileData(tileId.z, tileId.x, tileId.y, data);
+ }
+
+ @WorkerThread
+ private void fetchTile(int z, int x, int y) {
+ AtomicBoolean cancelFlag = new AtomicBoolean(false);
+ TileID tileID = new TileID(z, x, y);
+ cancelledTileRequests.put(tileID, cancelFlag);
+ GeometryTileRequest request = new GeometryTileRequest(tileID, provider, this, cancelFlag);
+ executor.submit(request);
+ }
+
+ @WorkerThread
+ private void cancelTile(int z, int x, int y) {
+ AtomicBoolean cancelFlag = cancelledTileRequests.get(new TileID(z, x, y));
+ if (cancelFlag != null) {
+ cancelFlag.compareAndSet(false, true);
+ }
+ }
+
+ private static class TileID {
+ public int z;
+ public int x;
+ public int y;
+
+ public TileID(int _z, int _x, int _y) {
+ z = _z;
+ x = _x;
+ y = _y;
+ }
+
+ public int hashCode() {
+ return Arrays.hashCode(new int[]{z, x, y});
+ }
+
+ public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
+
+ if (object instanceof TileID) {
+ TileID other = (TileID)object;
+ return this.z == other.z && this.x == other.x && this.y == other.y;
+ }
+ return false;
+ }
+ }
+
+ private static class GeometryTileRequest implements Runnable {
+ private TileID id;
+ private GeometryTileProvider provider;
+ private WeakReference sourceRef;
+ private AtomicBoolean cancelled;
+
+ public GeometryTileRequest(TileID _id, GeometryTileProvider p,
+ CustomGeometrySource _source, AtomicBoolean _cancelled) {
+ id = _id;
+ provider = p;
+ sourceRef = new WeakReference<>(_source);
+ cancelled = _cancelled;
+ }
+
+ public void run() {
+ if (isCancelled()) {
+ return;
+ }
+
+ FeatureCollection data = provider.getFeaturesForBounds(LatLngBounds.from(id.z, id.x, id.y), id.z);
+ CustomGeometrySource source = sourceRef.get();
+ if (!isCancelled() && source != null && !data.getFeatures().isEmpty()) {
+ source.setTileData(id, data);
+ }
+ }
+
+ private Boolean isCancelled() {
+ return cancelled.get();
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java
index 1a1711e547..81f7255b86 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonOptions.java
@@ -10,6 +10,17 @@ import java.util.HashMap;
*/
public class GeoJsonOptions extends HashMap {
+ /**
+ * Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels).
+ *
+ * @param maxZoom the maximum zoom - Defaults to 18.
+ * @return the current instance for chaining
+ */
+ public GeoJsonOptions withMinZoom(int minZoom) {
+ this.put("minzoom", minZoom);
+ return this;
+ }
+
/**
* Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels).
*
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java
new file mode 100644
index 0000000000..3f1eb315d3
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeometryTileProvider.java
@@ -0,0 +1,22 @@
+package com.mapbox.mapboxsdk.style.sources;
+
+import android.support.annotation.WorkerThread;
+
+import com.mapbox.mapboxsdk.geometry.LatLngBounds;
+import com.mapbox.services.commons.geojson.FeatureCollection;
+
+/**
+ * Interface that defines methods for working with {@link CustomGeometrySource}.
+ */
+public interface GeometryTileProvider {
+
+ /***
+ * Interface method called by {@link CustomGeometrySource} to request features for a tile.
+ *
+ * @param bounds {@link LatLngBounds} of the tile.
+ * @param zoomLevel Tile zoom level.
+ * @return Return a @{link FeatureCollection} to be displayed in the requested tile.
+ */
+ @WorkerThread
+ FeatureCollection getFeaturesForBounds(LatLngBounds bounds, int zoomLevel);
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
index bb96c9939d..4eb8e237fd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/geometry/LatLngBoundsTest.java
@@ -4,6 +4,7 @@ import android.os.Parcelable;
import com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException;
import com.mapbox.mapboxsdk.utils.MockParcel;
+import com.mapbox.services.android.telemetry.constants.GeoConstants;
import org.junit.Before;
import org.junit.Test;
@@ -272,4 +273,22 @@ public class LatLngBoundsTest {
Parcelable parcel = MockParcel.obtain(latLngBounds);
assertEquals("Parcel should match original object", parcel, latLngBounds);
}
+
+ @Test
+ public void fromTileID() {
+ //GeoConstants.MAX_LATITUDE is not defined to a high enough precision
+ double MAX_LATITUDE = 85.05112877980659;
+ LatLngBounds bounds = LatLngBounds.from(0, 0, 0);
+ assertEquals(-GeoConstants.MAX_LONGITUDE, bounds.getLonWest(), DELTA);
+ assertEquals(-MAX_LATITUDE, bounds.getLatSouth(), DELTA);
+ assertEquals(GeoConstants.MAX_LONGITUDE, bounds.getLonEast(), DELTA);
+ assertEquals(MAX_LATITUDE, bounds.getLatNorth(), DELTA);
+
+ bounds = LatLngBounds.from(10, 288, 385);
+ assertEquals(-78.75, bounds.getLonWest(), DELTA);
+ assertEquals(40.446947059600497, bounds.getLatSouth(), DELTA);
+ assertEquals(-78.3984375, bounds.getLonEast(), DELTA);
+ assertEquals(40.713955826286039, bounds.getLatNorth(), DELTA);
+
+ }
}
--
cgit v1.2.1
From f06ebcc96791838acb485fc37877725a443ca8f5 Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Mon, 13 Nov 2017 16:06:26 -0800
Subject: [android] Reuse Java Source objects by holding on to a strong
reference in the C++ peer.
---
.../main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
(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 e8eb7e8718..f1635c898f 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
@@ -733,7 +733,7 @@ final class NativeMapView {
if (isDestroyedOn("addSource")) {
return;
}
- nativeAddSource(source.getNativePtr());
+ nativeAddSource(source, source.getNativePtr());
}
@Nullable
@@ -741,14 +741,15 @@ final class NativeMapView {
if (isDestroyedOn("removeSource")) {
return null;
}
- return nativeRemoveSourceById(sourceId);
+ Source source = getSource(sourceId);
+ return removeSource(source);
}
public Source removeSource(@NonNull Source source) {
if (isDestroyedOn("removeSource")) {
return null;
}
- nativeRemoveSource(source.getNativePtr());
+ nativeRemoveSource(source, source.getNativePtr());
return source;
}
@@ -1027,11 +1028,9 @@ final class NativeMapView {
private native Source nativeGetSource(String sourceId);
- private native void nativeAddSource(long nativeSourcePtr) throws CannotAddSourceException;
+ private native void nativeAddSource(Source source, long sourcePtr) throws CannotAddSourceException;
- private native Source nativeRemoveSourceById(String sourceId);
-
- private native void nativeRemoveSource(long sourcePtr);
+ private native void nativeRemoveSource(Source source, long sourcePtr);
private native void nativeAddImage(String name, int width, int height, float pixelRatio,
byte[] array);
--
cgit v1.2.1
From e2702c76ead76b77f2ac3621673ef74e532d38d7 Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Mon, 13 Nov 2017 16:06:26 -0800
Subject: [android] Use inherited javaPeer in CustomGeometrySource C++ peer
---
.../com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
index e10be1d4ba..1ff1eeacc3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
@@ -51,7 +51,7 @@ public class CustomGeometrySource extends Source {
public CustomGeometrySource(String id, GeometryTileProvider provider, GeoJsonOptions options) {
this.provider = provider;
executor = Executors.newFixedThreadPool(4);
- initialize(this, id, options);
+ initialize(id, options);
}
/**
@@ -103,7 +103,7 @@ public class CustomGeometrySource extends Source {
return features != null ? Arrays.asList(features) : new ArrayList();
}
- protected native void initialize(CustomGeometrySource self, String sourceId, Object options);
+ protected native void initialize(String sourceId, Object options);
private native Feature[] querySourceFeatures(Object[] filter);
@@ -127,7 +127,7 @@ public class CustomGeometrySource extends Source {
TileID tileID = new TileID(z, x, y);
cancelledTileRequests.put(tileID, cancelFlag);
GeometryTileRequest request = new GeometryTileRequest(tileID, provider, this, cancelFlag);
- executor.submit(request);
+ executor.execute(request);
}
@WorkerThread
--
cgit v1.2.1
From ed5e009062b8ad7493c670c8a278220b1de0e528 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 29 Nov 2017 12:26:52 +0100
Subject: [android] - use concurrent lists for camera change listeners (#10542)
---
.../mapboxsdk/maps/CameraChangeDispatcher.java | 51 +++++++++++-----------
1 file changed, 25 insertions(+), 26 deletions(-)
(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
index cf780dcc3f..f046744c31 100644
--- 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
@@ -2,8 +2,7 @@ package com.mapbox.mapboxsdk.maps;
import android.support.annotation.NonNull;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveCanceledListener;
@@ -15,10 +14,10 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
private boolean idle = true;
- private final List onCameraMoveStartedListenerList = new ArrayList<>();
- private final List onCameraMoveCanceledListenerList = new ArrayList<>();
- private final List onCameraMoveListenerList = new ArrayList<>();
- private final List onCameraIdleListenerList = new ArrayList<>();
+ private final CopyOnWriteArrayList onCameraMoveStarted = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onCameraMoveCanceled = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onCameraMove = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onCameraIdle = new CopyOnWriteArrayList<>();
private OnCameraMoveStartedListener onCameraMoveStartedListener;
private OnCameraMoveCanceledListener onCameraMoveCanceledListener;
@@ -58,8 +57,8 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
}
// new API
- if (!onCameraMoveStartedListenerList.isEmpty()) {
- for (OnCameraMoveStartedListener cameraMoveStartedListener : onCameraMoveStartedListenerList) {
+ if (!onCameraMoveStarted.isEmpty()) {
+ for (OnCameraMoveStartedListener cameraMoveStartedListener : onCameraMoveStarted) {
cameraMoveStartedListener.onCameraMoveStarted(reason);
}
}
@@ -73,8 +72,8 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
}
// new API
- if (!onCameraMoveListenerList.isEmpty() && !idle) {
- for (OnCameraMoveListener cameraMoveListener : onCameraMoveListenerList) {
+ if (!onCameraMove.isEmpty() && !idle) {
+ for (OnCameraMoveListener cameraMoveListener : onCameraMove) {
cameraMoveListener.onCameraMove();
}
}
@@ -88,8 +87,8 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
}
// new API
- if (!onCameraMoveCanceledListenerList.isEmpty() && !idle) {
- for (OnCameraMoveCanceledListener cameraMoveCanceledListener : onCameraMoveCanceledListenerList) {
+ if (!onCameraMoveCanceled.isEmpty() && !idle) {
+ for (OnCameraMoveCanceledListener cameraMoveCanceledListener : onCameraMoveCanceled) {
cameraMoveCanceledListener.onCameraMoveCanceled();
}
}
@@ -105,8 +104,8 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
}
// new API
- if (!onCameraIdleListenerList.isEmpty()) {
- for (OnCameraIdleListener cameraIdleListener : onCameraIdleListenerList) {
+ if (!onCameraIdle.isEmpty()) {
+ for (OnCameraIdleListener cameraIdleListener : onCameraIdle) {
cameraIdleListener.onCameraIdle();
}
}
@@ -114,42 +113,42 @@ class CameraChangeDispatcher implements MapboxMap.OnCameraMoveStartedListener, M
}
void addOnCameraIdleListener(@NonNull OnCameraIdleListener listener) {
- onCameraIdleListenerList.add(listener);
+ onCameraIdle.add(listener);
}
void removeOnCameraIdleListener(@NonNull OnCameraIdleListener listener) {
- if (onCameraIdleListenerList.contains(listener)) {
- onCameraIdleListenerList.remove(listener);
+ if (onCameraIdle.contains(listener)) {
+ onCameraIdle.remove(listener);
}
}
void addOnCameraMoveCancelListener(OnCameraMoveCanceledListener listener) {
- onCameraMoveCanceledListenerList.add(listener);
+ onCameraMoveCanceled.add(listener);
}
void removeOnCameraMoveCancelListener(OnCameraMoveCanceledListener listener) {
- if (onCameraMoveCanceledListenerList.contains(listener)) {
- onCameraMoveCanceledListenerList.remove(listener);
+ if (onCameraMoveCanceled.contains(listener)) {
+ onCameraMoveCanceled.remove(listener);
}
}
void addOnCameraMoveStartedListener(OnCameraMoveStartedListener listener) {
- onCameraMoveStartedListenerList.add(listener);
+ onCameraMoveStarted.add(listener);
}
void removeOnCameraMoveStartedListener(OnCameraMoveStartedListener listener) {
- if (onCameraMoveStartedListenerList.contains(listener)) {
- onCameraMoveStartedListenerList.remove(listener);
+ if (onCameraMoveStarted.contains(listener)) {
+ onCameraMoveStarted.remove(listener);
}
}
void addOnCameraMoveListener(OnCameraMoveListener listener) {
- onCameraMoveListenerList.add(listener);
+ onCameraMove.add(listener);
}
void removeOnCameraMoveListener(OnCameraMoveListener listener) {
- if (onCameraMoveListenerList.contains(listener)) {
- onCameraMoveListenerList.remove(listener);
+ if (onCameraMove.contains(listener)) {
+ onCameraMove.remove(listener);
}
}
}
--
cgit v1.2.1
From 7e6ca6793a3fe508d4111a11a5887362707ddd26 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Thu, 30 Nov 2017 11:45:40 +0100
Subject: [android] - handle destroying activity programmatically as part of
theme switching (#10589)
---
.../src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 beb51d7b68..c468ecbc8c 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
@@ -416,8 +416,12 @@ public class MapView extends FrameLayout {
public void onDestroy() {
destroyed = true;
mapCallback.clearOnMapReadyCallbacks();
- nativeMapView.destroy();
- nativeMapView = null;
+
+ if (nativeMapView != null) {
+ // null when destroying an activity programmatically mapbox-navigation-android/issues/503
+ nativeMapView.destroy();
+ nativeMapView = null;
+ }
if (mapRenderer != null) {
mapRenderer.onDestroy();
--
cgit v1.2.1
From cb5dc2eed8e773e6064419f2d40c969b6ec22fdb Mon Sep 17 00:00:00 2001
From: Langston Smith
Date: Mon, 4 Dec 2017 08:19:47 -0800
Subject: Android SDK renaming (#10609)
* changes in various markdown files
* more tweaks
* Updated attribution title
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index a3dab0eff6..7b357bb75c 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -11,7 +11,7 @@ POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=mapbox
POM_DEVELOPER_NAME=Mapbox
-POM_NAME=Mapbox Android SDK
+POM_NAME=Mapbox Maps SDK for Android
POM_ARTIFACT_ID=mapbox-android-sdk
POM_PACKAGING=aar
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml
index 65fb3e14a3..79c2c8d699 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml
@@ -4,7 +4,7 @@
Attribution icon. Activate to show attribution dialog.Location View. This shows your location on the map.Showing a Map created with Mapbox. Scroll by dragging two fingers. Zoom by pinching two fingers.
- Mapbox Android SDK
+ Mapbox Maps SDK for AndroidMake Mapbox Maps BetterYou are helping to make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.Agree
--
cgit v1.2.1
From c311e69e0ef61f5203fa6cf632d5ec73b1e181da Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 6 Dec 2017 11:51:33 +0100
Subject: [android] - add FileSource activation/deactivation to MapSnapshotter,
handle multiple deactivate scenario in FileSource (#10556)
---
.../com/mapbox/mapboxsdk/storage/FileSource.java | 24 ++--------------------
1 file changed, 2 insertions(+), 22 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
index 41dc449b50..f0cb8d973a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/storage/FileSource.java
@@ -6,10 +6,8 @@ import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.os.Environment;
import android.support.annotation.NonNull;
-
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
-
import timber.log.Timber;
/**
@@ -119,28 +117,14 @@ public class FileSource {
}
private long nativePtr;
- private long activeCounter;
- private boolean wasPaused;
private FileSource(String cachePath, AssetManager assetManager) {
initialize(Mapbox.getAccessToken(), cachePath, assetManager);
}
- public void activate() {
- activeCounter++;
- if (activeCounter == 1 && wasPaused) {
- wasPaused = false;
- resume();
- }
- }
+ public native void activate();
- public void deactivate() {
- activeCounter--;
- if (activeCounter == 0) {
- wasPaused = true;
- pause();
- }
- }
+ public native void deactivate();
public native void setAccessToken(@NonNull String accessToken);
@@ -148,10 +132,6 @@ public class FileSource {
public native void setApiBaseUrl(String baseUrl);
- private native void resume();
-
- private native void pause();
-
/**
* Sets a callback for transforming URLs requested from the internet
*
--
cgit v1.2.1
From 86fdb2682d95c3fe644c66c2b27b6e89ce3f6d81 Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Wed, 6 Dec 2017 16:40:36 +0100
Subject: [android] - build boba snapshots from master
---
platform/android/MapboxGLAndroidSDK/gradle.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties
index 7b357bb75c..f00eb1d77f 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle.properties
+++ b/platform/android/MapboxGLAndroidSDK/gradle.properties
@@ -1,5 +1,5 @@
GROUP=com.mapbox.mapboxsdk
-VERSION_NAME=5.2.0-SNAPSHOT
+VERSION_NAME=6.0.0-SNAPSHOT
POM_DESCRIPTION=Mapbox GL Android SDK
POM_URL=https://github.com/mapbox/mapbox-gl-native
--
cgit v1.2.1
From f26c5ef2f066b9174499e0b2c29ef732920a067b Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Fri, 1 Dec 2017 16:15:54 -0800
Subject: [android] null check
---
.../java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.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/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
index 1ff1eeacc3..62f1719ddf 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
@@ -191,7 +191,7 @@ public class CustomGeometrySource extends Source {
FeatureCollection data = provider.getFeaturesForBounds(LatLngBounds.from(id.z, id.x, id.y), id.z);
CustomGeometrySource source = sourceRef.get();
- if (!isCancelled() && source != null && !data.getFeatures().isEmpty()) {
+ if (!isCancelled() && source != null && data != null) {
source.setTileData(id, data);
}
}
--
cgit v1.2.1
From 00ed34f7d700ae255eae1af1ca46b939ffee219d Mon Sep 17 00:00:00 2001
From: Chris Loer
Date: Thu, 30 Nov 2017 12:38:06 -0800
Subject: [android] Android implementation of local CJK glyph rendering -
Draws bold version of glyph if font stack contains string "bold" - Not
hooked up to global configuration yet
---
.../mapboxsdk/text/LocalGlyphRasterizer.java | 46 ++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/text/LocalGlyphRasterizer.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/text/LocalGlyphRasterizer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/text/LocalGlyphRasterizer.java
new file mode 100644
index 0000000000..920a1270ac
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/text/LocalGlyphRasterizer.java
@@ -0,0 +1,46 @@
+package com.mapbox.mapboxsdk.text;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Bitmap;
+import android.graphics.Typeface;
+import android.support.annotation.WorkerThread;
+
+/**
+ * LocalGlyphRasterizer is the Android-specific platform implementation used
+ * by the portable local_glyph_rasterizer.hpp
+ */
+public class LocalGlyphRasterizer {
+
+ /***
+ * Uses Android-native drawing code to rasterize a single glyph
+ * to a square @{link Bitmap} which can be returned to portable
+ * code for transformation into a Signed Distance Field glyph.
+ *
+ * @param fontFamily Font family string to pass to Typeface.create
+ * @param bold If true, use Typeface.BOLD option
+ * @param glyphID 16-bit Unicode BMP codepoint to draw
+ *
+ * @return Return a @{link Bitmap} to be displayed in the requested tile.
+ */
+ @WorkerThread
+ protected static Bitmap drawGlyphBitmap(String fontFamily, boolean bold, char glyphID) {
+ /*
+ 35x35px dimensions are hardwired to match local_glyph_rasterizer.cpp
+ These dimensions are large enough to draw a 24 point character in the middle
+ of the bitmap (y: 20) with some buffer around the edge
+ */
+ Bitmap bitmap = Bitmap.createBitmap(35, 35, Bitmap.Config.ARGB_8888);
+
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setTextSize(24);
+ paint.setTypeface(Typeface.create(fontFamily, bold ? Typeface.BOLD : Typeface.NORMAL));
+
+ Canvas canvas = new Canvas();
+ canvas.setBitmap(bitmap);
+ canvas.drawText(String.valueOf(glyphID), 0, 20, paint);
+
+ return bitmap;
+ }
+}
--
cgit v1.2.1
From bee60130d31f502a0bf4f07f4674c6a8a21619e8 Mon Sep 17 00:00:00 2001
From: Asheem Mamoowala
Date: Thu, 7 Dec 2017 15:50:46 -0800
Subject: [android] Add Configuration hook for local ideograph font family and
demo activity
---
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 4 ++--
.../mapbox/mapboxsdk/maps/MapboxMapOptions.java | 28 ++++++++++++++++++++++
.../mapboxsdk/maps/renderer/MapRenderer.java | 8 +++----
.../glsurfaceview/GLSurfaceViewMapRenderer.java | 4 ++--
.../textureview/TextureViewMapRenderer.java | 4 ++--
.../src/main/res-public/values/public.xml | 1 +
.../src/main/res/values/attrs.xml | 1 +
7 files changed, 40 insertions(+), 10 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 c468ecbc8c..c9bfbeb80a 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
@@ -293,7 +293,7 @@ public class MapView extends FrameLayout {
private void initialiseDrawingSurface(MapboxMapOptions options) {
if (options.getTextureMode()) {
TextureView textureView = new TextureView(getContext());
- mapRenderer = new TextureViewMapRenderer(getContext(), textureView) {
+ mapRenderer = new TextureViewMapRenderer(getContext(), textureView, options.getLocalIdeographFontFamily()) {
@Override
protected void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
@@ -315,7 +315,7 @@ public class MapView extends FrameLayout {
GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
glSurfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop());
- mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView) {
+ mapRenderer = new GLSurfaceViewMapRenderer(getContext(), glSurfaceView, options.getLocalIdeographFontFamily()) {
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
MapView.this.post(new Runnable() {
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 f26e0b9d3b..5d8da05fa8 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
@@ -82,6 +82,7 @@ public class MapboxMapOptions implements Parcelable {
private float myLocationAccuracyThreshold;
private boolean prefetchesTiles = true;
private boolean zMediaOverlay = false;
+ private String localIdeographFontFamily;
private String apiBaseUrl;
@@ -157,6 +158,7 @@ public class MapboxMapOptions implements Parcelable {
textureMode = in.readByte() != 0;
prefetchesTiles = in.readByte() != 0;
zMediaOverlay = in.readByte() != 0;
+ localIdeographFontFamily = in.readString();
}
static Bitmap getBitmapFromDrawable(Drawable drawable) {
@@ -304,6 +306,7 @@ public class MapboxMapOptions implements Parcelable {
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
mapboxMapOptions.renderSurfaceOnTop(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false));
+ mapboxMapOptions.localIdeographFontFamily(typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
} finally {
typedArray.recycle();
}
@@ -733,6 +736,18 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
+ /**
+ * Set the font-family for generating glyphs locally for ideographs in the ‘CJK Unified Ideographs’
+ * and ‘Hangul Syllables’ ranges.
+ *
+ * @param fontFamily font family for local ideograph generation.
+ * @return
+ */
+ public MapboxMapOptions localIdeographFontFamily(String fontFamily) {
+ this.localIdeographFontFamily = fontFamily;
+ return this;
+ }
+
/**
* Check whether tile pre-fetching is enabled.
*
@@ -1079,6 +1094,14 @@ public class MapboxMapOptions implements Parcelable {
return textureMode;
}
+ /**
+ * Returns the font-family for locally overriding generation of glyphs in the
+ * ‘CJK Unified Ideographs’ and ‘Hangul Syllables’ ranges.
+ *
+ * @return Local ideograph font family name.
+ */
+ public String getLocalIdeographFontFamily() { return localIdeographFontFamily; }
+
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public MapboxMapOptions createFromParcel(Parcel in) {
return new MapboxMapOptions(in);
@@ -1145,6 +1168,7 @@ public class MapboxMapOptions implements Parcelable {
dest.writeByte((byte) (textureMode ? 1 : 0));
dest.writeByte((byte) (prefetchesTiles ? 1 : 0));
dest.writeByte((byte) (zMediaOverlay ? 1 : 0));
+ dest.writeString(localIdeographFontFamily);
}
@Override
@@ -1274,6 +1298,9 @@ public class MapboxMapOptions implements Parcelable {
if (zMediaOverlay != options.zMediaOverlay) {
return false;
}
+ if (localIdeographFontFamily != options.localIdeographFontFamily) {
+ return false;
+ }
return false;
}
@@ -1323,6 +1350,7 @@ public class MapboxMapOptions implements Parcelable {
result = 31 * result + (style != null ? style.hashCode() : 0);
result = 31 * result + (prefetchesTiles ? 1 : 0);
result = 31 * result + (zMediaOverlay ? 1 : 0);
+ result = 31 * result + (localIdeographFontFamily != null ? localIdeographFontFamily.hashCode() : 0);
return result;
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
index 2baff473e9..fcee5bd179 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java
@@ -23,14 +23,13 @@ public abstract class MapRenderer implements MapRendererScheduler {
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
- public MapRenderer(Context context) {
+ public MapRenderer(Context context, String localIdeographFontFamily) {
FileSource fileSource = FileSource.getInstance(context);
float pixelRatio = context.getResources().getDisplayMetrics().density;
String programCacheDir = context.getCacheDir().getAbsolutePath();
-
// Initialise native peer
- nativeInitialize(this, fileSource, pixelRatio, programCacheDir);
+ nativeInitialize(this, fileSource, pixelRatio, programCacheDir, localIdeographFontFamily);
}
public void onStart() {
@@ -112,7 +111,8 @@ public abstract class MapRenderer implements MapRendererScheduler {
private native void nativeInitialize(MapRenderer self,
FileSource fileSource,
float pixelRatio,
- String programCacheDir);
+ String programCacheDir,
+ String localIdeographFontFamily);
@CallSuper
@Override
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
index d98e4d06a3..7bc56475c0 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/glsurfaceview/GLSurfaceViewMapRenderer.java
@@ -21,8 +21,8 @@ public class GLSurfaceViewMapRenderer extends MapRenderer implements GLSurfaceVi
private final GLSurfaceView glSurfaceView;
- public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView) {
- super(context);
+ public GLSurfaceViewMapRenderer(Context context, GLSurfaceView glSurfaceView, String localIdeographFontFamily) {
+ super(context, localIdeographFontFamily);
this.glSurfaceView = glSurfaceView;
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setEGLConfigChooser(new EGLConfigChooser());
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
index 397904b1f5..9ebf60051a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
@@ -24,8 +24,8 @@ public class TextureViewMapRenderer extends MapRenderer {
* @param context the current Context
* @param textureView the TextureView
*/
- public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView) {
- super(context);
+ public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView, String localIdeographFontFamily) {
+ super(context, localIdeographFontFamily);
renderThread = new TextureViewRenderThread(textureView, this);
renderThread.start();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
index f406f4d042..412d8c5d9b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml
@@ -11,6 +11,7 @@
+
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
index 2a4c2fe746..97adce8a4e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml
@@ -5,6 +5,7 @@
+
--
cgit v1.2.1
From f2d70aa890f97031a7ff70ace182f90ba0c65d56 Mon Sep 17 00:00:00 2001
From: Chris Loer
Date: Thu, 7 Dec 2017 16:03:13 -0800
Subject: [android] Fixups for LocalGlyphActivity
---
.../main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java | 9 ++++++---
.../maps/renderer/textureview/TextureViewMapRenderer.java | 4 +++-
2 files changed, 9 insertions(+), 4 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 5d8da05fa8..48c83628d6 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
@@ -306,7 +306,8 @@ public class MapboxMapOptions implements Parcelable {
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true));
mapboxMapOptions.renderSurfaceOnTop(
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false));
- mapboxMapOptions.localIdeographFontFamily(typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
+ mapboxMapOptions.localIdeographFontFamily(
+ typedArray.getString(R.styleable.mapbox_MapView_mapbox_localIdeographFontFamily));
} finally {
typedArray.recycle();
}
@@ -741,7 +742,7 @@ public class MapboxMapOptions implements Parcelable {
* and ‘Hangul Syllables’ ranges.
*
* @param fontFamily font family for local ideograph generation.
- * @return
+ * @return This
*/
public MapboxMapOptions localIdeographFontFamily(String fontFamily) {
this.localIdeographFontFamily = fontFamily;
@@ -1100,7 +1101,9 @@ public class MapboxMapOptions implements Parcelable {
*
* @return Local ideograph font family name.
*/
- public String getLocalIdeographFontFamily() { return localIdeographFontFamily; }
+ public String getLocalIdeographFontFamily() {
+ return localIdeographFontFamily;
+ }
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public MapboxMapOptions createFromParcel(Parcel in) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
index 9ebf60051a..dcc95217ff 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/textureview/TextureViewMapRenderer.java
@@ -24,7 +24,9 @@ public class TextureViewMapRenderer extends MapRenderer {
* @param context the current Context
* @param textureView the TextureView
*/
- public TextureViewMapRenderer(@NonNull Context context, @NonNull TextureView textureView, String localIdeographFontFamily) {
+ public TextureViewMapRenderer(@NonNull Context context,
+ @NonNull TextureView textureView,
+ String localIdeographFontFamily) {
super(context, localIdeographFontFamily);
renderThread = new TextureViewRenderThread(textureView, this);
renderThread.start();
--
cgit v1.2.1
From 44363d4826638b1c3b5c6ce9e1eda178cf71f32b Mon Sep 17 00:00:00 2001
From: paczos
Date: Wed, 13 Dec 2017 17:54:20 +0100
Subject: [android] added map touch listeners api based on lists
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 58 ++++++++++
.../java/com/mapbox/mapboxsdk/maps/MapView.java | 48 +++++++-
.../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 126 +++++++++++++++++++--
3 files changed, 220 insertions(+), 12 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 9d7d980ae3..2c95c09485 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
@@ -26,6 +26,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 java.util.concurrent.CopyOnWriteArrayList;
+
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener.REASON_API_GESTURE;
/**
@@ -53,6 +55,11 @@ final class MapGestureDetector {
private MapboxMap.OnFlingListener onFlingListener;
private MapboxMap.OnScrollListener onScrollListener;
+ private final CopyOnWriteArrayList onMapClickListenerList = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onMapLongClickListenerList = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onFlingListenerList = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onScrollListenerList = new CopyOnWriteArrayList<>();
+
private PointF focalPoint;
private boolean twoTap;
@@ -359,6 +366,10 @@ final class MapGestureDetector {
if (onMapClickListener != null) {
onMapClickListener.onMapClick(projection.fromScreenLocation(tapPoint));
}
+
+ for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
+ listener.onMapClick(projection.fromScreenLocation(tapPoint));
+ }
}
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
@@ -374,6 +385,13 @@ final class MapGestureDetector {
onMapLongClickListener.onMapLongClick(
projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())));
}
+
+ if (!quickZoom) {
+ for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
+ listener.onMapLongClick(
+ projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())));
+ }
+ }
}
@Override
@@ -415,6 +433,10 @@ final class MapGestureDetector {
if (onFlingListener != null) {
onFlingListener.onFling();
}
+
+ for (MapboxMap.OnFlingListener listener : onFlingListenerList) {
+ listener.onFling();
+ }
return true;
}
@@ -452,6 +474,10 @@ final class MapGestureDetector {
if (onScrollListener != null) {
onScrollListener.onScroll();
}
+
+ for (MapboxMap.OnScrollListener listener : onScrollListenerList) {
+ listener.onScroll();
+ }
return true;
}
}
@@ -844,4 +870,36 @@ final class MapGestureDetector {
void setOnScrollListener(MapboxMap.OnScrollListener onScrollListener) {
this.onScrollListener = onScrollListener;
}
+
+ void addOnMapClickListener(MapboxMap.OnMapClickListener onMapClickListener) {
+ onMapClickListenerList.add(onMapClickListener);
+ }
+
+ void removeOnMapClickListener(MapboxMap.OnMapClickListener onMapClickListener) {
+ onMapClickListenerList.remove(onMapClickListener);
+ }
+
+ void addOnMapLongClickListener(MapboxMap.OnMapLongClickListener onMapLongClickListener) {
+ onMapLongClickListenerList.add(onMapLongClickListener);
+ }
+
+ void removeOnMapLongClickListener(MapboxMap.OnMapLongClickListener onMapLongClickListener) {
+ onMapLongClickListenerList.remove(onMapLongClickListener);
+ }
+
+ void addOnFlingListener(MapboxMap.OnFlingListener onFlingListener) {
+ onFlingListenerList.add(onFlingListener);
+ }
+
+ void removeOnFlingListener(MapboxMap.OnFlingListener onFlingListener) {
+ onFlingListenerList.remove(onFlingListener);
+ }
+
+ void addOnScrollListener(MapboxMap.OnScrollListener onScrollListener) {
+ onScrollListenerList.add(onScrollListener);
+ }
+
+ void removeOnScrollListener(MapboxMap.OnScrollListener onScrollListener) {
+ onScrollListenerList.remove(onScrollListener);
+ }
}
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 c9bfbeb80a..11ec6eaaac 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
@@ -908,24 +908,64 @@ public class MapView extends FrameLayout {
private class RegisterTouchListener implements MapboxMap.OnRegisterTouchListener {
@Override
- public void onRegisterMapClickListener(MapboxMap.OnMapClickListener listener) {
+ public void onSetMapClickListener(MapboxMap.OnMapClickListener listener) {
mapGestureDetector.setOnMapClickListener(listener);
}
@Override
- public void onRegisterMapLongClickListener(MapboxMap.OnMapLongClickListener listener) {
+ public void onAddMapClickListener(MapboxMap.OnMapClickListener listener) {
+ mapGestureDetector.addOnMapClickListener(listener);
+ }
+
+ @Override
+ public void onRemoveMapClickListener(MapboxMap.OnMapClickListener listener) {
+ mapGestureDetector.removeOnMapClickListener(listener);
+ }
+
+ @Override
+ public void onSetMapLongClickListener(MapboxMap.OnMapLongClickListener listener) {
mapGestureDetector.setOnMapLongClickListener(listener);
}
@Override
- public void onRegisterScrollListener(MapboxMap.OnScrollListener listener) {
+ public void onAddMapLongClickListener(MapboxMap.OnMapLongClickListener listener) {
+ mapGestureDetector.addOnMapLongClickListener(listener);
+ }
+
+ @Override
+ public void onRemoveMapLongClickListener(MapboxMap.OnMapLongClickListener listener) {
+ mapGestureDetector.removeOnMapLongClickListener(listener);
+ }
+
+ @Override
+ public void onSetScrollListener(MapboxMap.OnScrollListener listener) {
mapGestureDetector.setOnScrollListener(listener);
}
@Override
- public void onRegisterFlingListener(MapboxMap.OnFlingListener listener) {
+ public void onAddScrollListener(MapboxMap.OnScrollListener listener) {
+ mapGestureDetector.addOnScrollListener(listener);
+ }
+
+ @Override
+ public void onRemoveScrollListener(MapboxMap.OnScrollListener listener) {
+ mapGestureDetector.removeOnScrollListener(listener);
+ }
+
+ @Override
+ public void onSetFlingListener(MapboxMap.OnFlingListener listener) {
mapGestureDetector.setOnFlingListener(listener);
}
+
+ @Override
+ public void onAddFlingListener(MapboxMap.OnFlingListener listener) {
+ mapGestureDetector.addOnFlingListener(listener);
+ }
+
+ @Override
+ public void onRemoveFlingListener(MapboxMap.OnFlingListener listener) {
+ mapGestureDetector.removeOnFlingListener(listener);
+ }
}
private static class MapZoomControllerListener implements ZoomButtonsController.OnZoomListener {
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 6bf8342efb..e6818ca436 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
@@ -1902,9 +1902,34 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the map is scrolled.
* To unset the callback, use null.
+ *
+ * @deprecated Use {@link #addOnScrollListener(OnScrollListener)} instead.
*/
+ @Deprecated
public void setOnScrollListener(@Nullable OnScrollListener listener) {
- onRegisterTouchListener.onRegisterScrollListener(listener);
+ onRegisterTouchListener.onSetScrollListener(listener);
+ }
+
+ /**
+ * Adds a callback that's invoked when the map is scrolled.
+ *
+ * @param listener The callback that's invoked when the map is scrolled.
+ * To unset the callback, use null.
+ *
+ */
+ public void addOnScrollListener(@Nullable OnScrollListener listener) {
+ onRegisterTouchListener.onAddScrollListener(listener);
+ }
+
+ /**
+ * Removes a callback that's invoked when the map is scrolled.
+ *
+ * @param listener The callback that's invoked when the map is scrolled.
+ * To unset the callback, use null.
+ *
+ */
+ public void removeOnScrollListener(@Nullable OnScrollListener listener) {
+ onRegisterTouchListener.onRemoveScrollListener(listener);
}
/**
@@ -1912,9 +1937,32 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the map is flinged.
* To unset the callback, use null.
+ *
+ * @deprecated Use {@link #addOnFlingListener(OnFlingListener)} instead.
*/
+ @Deprecated
public void setOnFlingListener(@Nullable OnFlingListener listener) {
- onRegisterTouchListener.onRegisterFlingListener(listener);
+ onRegisterTouchListener.onSetFlingListener(listener);
+ }
+
+ /**
+ * Adds a callback that's invoked when the map is flinged.
+ *
+ * @param listener The callback that's invoked when the map is flinged.
+ * To unset the callback, use null.
+ */
+ public void addOnFlingListener(@Nullable OnFlingListener listener) {
+ onRegisterTouchListener.onAddFlingListener(listener);
+ }
+
+ /**
+ * Removes a callback that's invoked when the map is flinged.
+ *
+ * @param listener The callback that's invoked when the map is flinged.
+ * To unset the callback, use null.
+ */
+ public void removeOnFlingListener(@Nullable OnFlingListener listener) {
+ onRegisterTouchListener.onRemoveFlingListener(listener);
}
/**
@@ -1922,9 +1970,32 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the user clicks on the map view.
* To unset the callback, use null.
+ *
+ * @deprecated Use {@link #addOnMapClickListener(OnMapClickListener)} instead.
*/
+ @Deprecated
public void setOnMapClickListener(@Nullable OnMapClickListener listener) {
- onRegisterTouchListener.onRegisterMapClickListener(listener);
+ onRegisterTouchListener.onSetMapClickListener(listener);
+ }
+
+ /**
+ * Adds a callback that's invoked when the user clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user clicks on the map view.
+ * To unset the callback, use null.
+ */
+ public void addOnMapClickListener(@Nullable OnMapClickListener listener) {
+ onRegisterTouchListener.onAddMapClickListener(listener);
+ }
+
+ /**
+ * Removes a callback that's invoked when the user clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user clicks on the map view.
+ * To unset the callback, use null.
+ */
+ public void removeOnMapClickListener(@Nullable OnMapClickListener listener) {
+ onRegisterTouchListener.onRemoveMapClickListener(listener);
}
/**
@@ -1932,9 +2003,32 @@ public final class MapboxMap {
*
* @param listener The callback that's invoked when the user long clicks on the map view.
* To unset the callback, use null.
+ *
+ * @deprecated Use {@link #addOnMapLongClickListener(OnMapLongClickListener)} instead.
*/
+ @Deprecated
public void setOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
- onRegisterTouchListener.onRegisterMapLongClickListener(listener);
+ onRegisterTouchListener.onSetMapLongClickListener(listener);
+ }
+
+ /**
+ * Adds a callback that's invoked when the user long clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user long clicks on the map view.
+ * To unset the callback, use null.
+ */
+ public void addOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
+ onRegisterTouchListener.onAddMapLongClickListener(listener);
+ }
+
+ /**
+ * Removes a callback that's invoked when the user long clicks on the map view.
+ *
+ * @param listener The callback that's invoked when the user long clicks on the map view.
+ * To unset the callback, use null.
+ */
+ public void removeOnMapLongClickListener(@Nullable OnMapLongClickListener listener) {
+ onRegisterTouchListener.onRemoveMapLongClickListener(listener);
}
/**
@@ -2304,13 +2398,29 @@ public final class MapboxMap {
* related to touch and click events.
*/
interface OnRegisterTouchListener {
- void onRegisterMapClickListener(OnMapClickListener listener);
+ void onSetMapClickListener(OnMapClickListener listener);
+
+ void onAddMapClickListener(OnMapClickListener listener);
+
+ void onRemoveMapClickListener(OnMapClickListener listener);
+
+ void onSetMapLongClickListener(OnMapLongClickListener listener);
+
+ void onAddMapLongClickListener(OnMapLongClickListener listener);
+
+ void onRemoveMapLongClickListener(OnMapLongClickListener listener);
+
+ void onSetScrollListener(OnScrollListener listener);
+
+ void onAddScrollListener(OnScrollListener listener);
+
+ void onRemoveScrollListener(OnScrollListener listener);
- void onRegisterMapLongClickListener(OnMapLongClickListener listener);
+ void onSetFlingListener(OnFlingListener listener);
- void onRegisterScrollListener(OnScrollListener listener);
+ void onAddFlingListener(OnFlingListener listener);
- void onRegisterFlingListener(OnFlingListener listener);
+ void onRemoveFlingListener(OnFlingListener listener);
}
/**
--
cgit v1.2.1
From 2afa8a172505674956e07655421a55e7aa9f41b2 Mon Sep 17 00:00:00 2001
From: paczos
Date: Thu, 14 Dec 2017 11:36:11 +0100
Subject: [android] added map touch listeners test
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 100 ++++++++++++---------
.../mapboxsdk/maps/MapTouchListenersTest.java | 95 ++++++++++++++++++++
2 files changed, 153 insertions(+), 42 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
(limited to 'platform/android/MapboxGLAndroidSDK')
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 2c95c09485..7885defc93 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
@@ -45,10 +45,10 @@ final class MapGestureDetector {
private final AnnotationManager annotationManager;
private final CameraChangeDispatcher cameraChangeDispatcher;
- private final GestureDetectorCompat gestureDetector;
- private final ScaleGestureDetector scaleGestureDetector;
- private final RotateGestureDetector rotateGestureDetector;
- private final ShoveGestureDetector shoveGestureDetector;
+ private GestureDetectorCompat gestureDetector;
+ private ScaleGestureDetector scaleGestureDetector;
+ private RotateGestureDetector rotateGestureDetector;
+ private ShoveGestureDetector shoveGestureDetector;
private MapboxMap.OnMapClickListener onMapClickListener;
private MapboxMap.OnMapLongClickListener onMapLongClickListener;
@@ -88,12 +88,14 @@ final class MapGestureDetector {
this.cameraChangeDispatcher = cameraChangeDispatcher;
// Touch gesture detectors
- gestureDetector = new GestureDetectorCompat(context, new GestureListener());
- gestureDetector.setIsLongpressEnabled(true);
- scaleGestureDetector = new ScaleGestureDetector(context, new ScaleGestureListener());
- ScaleGestureDetectorCompat.setQuickScaleEnabled(scaleGestureDetector, true);
- rotateGestureDetector = new RotateGestureDetector(context, new RotateGestureListener());
- shoveGestureDetector = new ShoveGestureDetector(context, new ShoveGestureListener());
+ if (context != null) {
+ gestureDetector = new GestureDetectorCompat(context, new GestureListener());
+ gestureDetector.setIsLongpressEnabled(true);
+ scaleGestureDetector = new ScaleGestureDetector(context, new ScaleGestureListener());
+ ScaleGestureDetectorCompat.setQuickScaleEnabled(scaleGestureDetector, true);
+ rotateGestureDetector = new RotateGestureDetector(context, new RotateGestureListener());
+ shoveGestureDetector = new ShoveGestureDetector(context, new ShoveGestureListener());
+ }
}
/**
@@ -294,7 +296,6 @@ final class MapGestureDetector {
return false;
}
-
/**
* Responsible for handling one finger gestures.
*/
@@ -362,14 +363,7 @@ final class MapGestureDetector {
annotationManager.deselectMarkers();
}
- // notify app of map click
- if (onMapClickListener != null) {
- onMapClickListener.onMapClick(projection.fromScreenLocation(tapPoint));
- }
-
- for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
- listener.onMapClick(projection.fromScreenLocation(tapPoint));
- }
+ notifyOnMapClickListeners(tapPoint);
}
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
@@ -381,17 +375,8 @@ final class MapGestureDetector {
@Override
public void onLongPress(MotionEvent motionEvent) {
- if (onMapLongClickListener != null && !quickZoom) {
- onMapLongClickListener.onMapLongClick(
- projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())));
- }
-
- if (!quickZoom) {
- for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
- listener.onMapLongClick(
- projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())));
- }
- }
+ PointF longClickPoint = new PointF(motionEvent.getX(), motionEvent.getY());
+ notifyOnMapLongClickListeners(longClickPoint);
}
@Override
@@ -430,13 +415,7 @@ final class MapGestureDetector {
// update transformation
transform.moveBy(offsetX, offsetY, animationTime);
- if (onFlingListener != null) {
- onFlingListener.onFling();
- }
-
- for (MapboxMap.OnFlingListener listener : onFlingListenerList) {
- listener.onFling();
- }
+ notifyOnFlingListeners();
return true;
}
@@ -471,14 +450,51 @@ final class MapGestureDetector {
// Scroll the map
transform.moveBy(-distanceX, -distanceY, 0 /*no duration*/);
- if (onScrollListener != null) {
- onScrollListener.onScroll();
+ notifyOnScrollListeners();
+ return true;
+ }
+ }
+
+ void notifyOnMapClickListeners(PointF tapPoint) {
+ // notify app of map click
+ if (onMapClickListener != null) {
+ onMapClickListener.onMapClick(projection.fromScreenLocation(tapPoint));
+ }
+
+ for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
+ listener.onMapClick(projection.fromScreenLocation(tapPoint));
+ }
+ }
+
+ void notifyOnMapLongClickListeners(PointF longClickPoint) {
+ if (!quickZoom) {
+ if (onMapLongClickListener != null) {
+ onMapLongClickListener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
}
- for (MapboxMap.OnScrollListener listener : onScrollListenerList) {
- listener.onScroll();
+ for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
+ listener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
}
- return true;
+ }
+ }
+
+ void notifyOnFlingListeners() {
+ if (onFlingListener != null) {
+ onFlingListener.onFling();
+ }
+
+ for (MapboxMap.OnFlingListener listener : onFlingListenerList) {
+ listener.onFling();
+ }
+ }
+
+ void notifyOnScrollListeners() {
+ if (onScrollListener != null) {
+ onScrollListener.onScroll();
+ }
+
+ for (MapboxMap.OnScrollListener listener : onScrollListenerList) {
+ listener.onScroll();
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
new file mode 100644
index 0000000000..1e27e2ea4d
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
@@ -0,0 +1,95 @@
+package com.mapbox.mapboxsdk.maps;
+
+import android.graphics.PointF;
+
+import com.mapbox.mapboxsdk.geometry.LatLng;
+
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class MapTouchListenersTest {
+
+ @Test
+ public void OnMapClickListenerTest() throws Exception {
+ LatLng latLng = new LatLng();
+ PointF pointF = new PointF();
+
+ Projection projection = mock(Projection.class);
+ when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
+ MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
+ null, projection, null, null, null, null);
+
+ MapboxMap.OnMapClickListener listener = mock(MapboxMap.OnMapClickListener.class);
+ mapGestureDetector.addOnMapClickListener(listener);
+ mapGestureDetector.notifyOnMapClickListeners(pointF);
+ verify(listener, times(1)).onMapClick(latLng);
+
+ mapGestureDetector.removeOnMapClickListener(listener);
+ mapGestureDetector.notifyOnMapClickListeners(pointF);
+ verify(listener, times(1)).onMapClick(latLng);
+ }
+
+ @Test
+ public void OnMapLongClickListenerTest() throws Exception {
+ LatLng latLng = new LatLng();
+ PointF pointF = new PointF();
+
+ Projection projection = mock(Projection.class);
+ when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
+ MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
+ null, projection, null, null, null, null);
+
+ MapboxMap.OnMapLongClickListener listener = mock(MapboxMap.OnMapLongClickListener.class);
+ mapGestureDetector.addOnMapLongClickListener(listener);
+ mapGestureDetector.notifyOnMapLongClickListeners(pointF);
+ verify(listener, times(1)).onMapLongClick(latLng);
+
+ mapGestureDetector.removeOnMapLongClickListener(listener);
+ mapGestureDetector.notifyOnMapLongClickListeners(pointF);
+ verify(listener, times(1)).onMapLongClick(latLng);
+ }
+
+ @Test
+ public void OnFlingListenerTest() throws Exception {
+ LatLng latLng = new LatLng();
+ PointF pointF = new PointF();
+
+ Projection projection = mock(Projection.class);
+ when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
+ MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
+ null, projection, null, null, null, null);
+
+ MapboxMap.OnFlingListener listener = mock(MapboxMap.OnFlingListener.class);
+ mapGestureDetector.addOnFlingListener(listener);
+ mapGestureDetector.notifyOnFlingListeners();
+ verify(listener, times(1)).onFling();
+
+ mapGestureDetector.removeOnFlingListener(listener);
+ mapGestureDetector.notifyOnFlingListeners();
+ verify(listener, times(1)).onFling();
+ }
+
+ @Test
+ public void OnScrollListenerTest() throws Exception {
+ LatLng latLng = new LatLng();
+ PointF pointF = new PointF();
+
+ Projection projection = mock(Projection.class);
+ when(projection.fromScreenLocation(pointF)).thenReturn(latLng);
+ MapGestureDetector mapGestureDetector = new MapGestureDetector(null,
+ null, projection, null, null, null, null);
+
+ MapboxMap.OnScrollListener listener = mock(MapboxMap.OnScrollListener.class);
+ mapGestureDetector.addOnScrollListener(listener);
+ mapGestureDetector.notifyOnScrollListeners();
+ verify(listener, times(1)).onScroll();
+
+ mapGestureDetector.removeOnScrollListener(listener);
+ mapGestureDetector.notifyOnScrollListeners();
+ verify(listener, times(1)).onScroll();
+ }
+}
--
cgit v1.2.1
From fc50605507005a3b116b2e2163f518ad533578b9 Mon Sep 17 00:00:00 2001
From: paczos
Date: Thu, 14 Dec 2017 11:43:00 +0100
Subject: [android] checkstyle fixup
---
.../com/mapbox/mapboxsdk/maps/MapGestureDetector.java | 15 +++++++++++----
.../com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java | 8 ++++----
2 files changed, 15 insertions(+), 8 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 7885defc93..9694be43f7 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
@@ -55,10 +55,17 @@ final class MapGestureDetector {
private MapboxMap.OnFlingListener onFlingListener;
private MapboxMap.OnScrollListener onScrollListener;
- private final CopyOnWriteArrayList onMapClickListenerList = new CopyOnWriteArrayList<>();
- private final CopyOnWriteArrayList onMapLongClickListenerList = new CopyOnWriteArrayList<>();
- private final CopyOnWriteArrayList onFlingListenerList = new CopyOnWriteArrayList<>();
- private final CopyOnWriteArrayList onScrollListenerList = new CopyOnWriteArrayList<>();
+ private final CopyOnWriteArrayList onMapClickListenerList
+ = new CopyOnWriteArrayList<>();
+
+ private final CopyOnWriteArrayList onMapLongClickListenerList
+ = new CopyOnWriteArrayList<>();
+
+ private final CopyOnWriteArrayList onFlingListenerList
+ = new CopyOnWriteArrayList<>();
+
+ private final CopyOnWriteArrayList onScrollListenerList
+ = new CopyOnWriteArrayList<>();
private PointF focalPoint;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
index 1e27e2ea4d..eeb00355bd 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapTouchListenersTest.java
@@ -14,7 +14,7 @@ import static org.mockito.Mockito.when;
public class MapTouchListenersTest {
@Test
- public void OnMapClickListenerTest() throws Exception {
+ public void onMapClickListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
@@ -34,7 +34,7 @@ public class MapTouchListenersTest {
}
@Test
- public void OnMapLongClickListenerTest() throws Exception {
+ public void onMapLongClickListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
@@ -54,7 +54,7 @@ public class MapTouchListenersTest {
}
@Test
- public void OnFlingListenerTest() throws Exception {
+ public void onFlingListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
@@ -74,7 +74,7 @@ public class MapTouchListenersTest {
}
@Test
- public void OnScrollListenerTest() throws Exception {
+ public void onScrollListenerTest() throws Exception {
LatLng latLng = new LatLng();
PointF pointF = new PointF();
--
cgit v1.2.1
From d2cc855cd3e45aff7d079ecd21c814cae4fc2465 Mon Sep 17 00:00:00 2001
From: paczos
Date: Thu, 14 Dec 2017 15:45:54 +0100
Subject: [android] new map touch listeners API comments
---
.../mapbox/mapboxsdk/maps/MapGestureDetector.java | 28 +++++++++++++++-------
1 file changed, 19 insertions(+), 9 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 9694be43f7..0fea5ce0ff 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
@@ -50,11 +50,13 @@ final class MapGestureDetector {
private RotateGestureDetector rotateGestureDetector;
private ShoveGestureDetector shoveGestureDetector;
+ // deprecated map touch API
private MapboxMap.OnMapClickListener onMapClickListener;
private MapboxMap.OnMapLongClickListener onMapLongClickListener;
private MapboxMap.OnFlingListener onFlingListener;
private MapboxMap.OnScrollListener onScrollListener;
+ // new map touch API
private final CopyOnWriteArrayList onMapClickListenerList
= new CopyOnWriteArrayList<>();
@@ -383,7 +385,10 @@ final class MapGestureDetector {
@Override
public void onLongPress(MotionEvent motionEvent) {
PointF longClickPoint = new PointF(motionEvent.getX(), motionEvent.getY());
- notifyOnMapLongClickListeners(longClickPoint);
+
+ if (!quickZoom) {
+ notifyOnMapLongClickListeners(longClickPoint);
+ }
}
@Override
@@ -463,43 +468,48 @@ final class MapGestureDetector {
}
void notifyOnMapClickListeners(PointF tapPoint) {
- // notify app of map click
+ // deprecated API
if (onMapClickListener != null) {
onMapClickListener.onMapClick(projection.fromScreenLocation(tapPoint));
}
+ // new API
for (MapboxMap.OnMapClickListener listener : onMapClickListenerList) {
listener.onMapClick(projection.fromScreenLocation(tapPoint));
}
}
void notifyOnMapLongClickListeners(PointF longClickPoint) {
- if (!quickZoom) {
- if (onMapLongClickListener != null) {
- onMapLongClickListener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
- }
+ // deprecated API
+ if (onMapLongClickListener != null) {
+ onMapLongClickListener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
+ }
- for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
- listener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
- }
+ // new API
+ for (MapboxMap.OnMapLongClickListener listener : onMapLongClickListenerList) {
+ listener.onMapLongClick(projection.fromScreenLocation(longClickPoint));
}
}
void notifyOnFlingListeners() {
+ // deprecated API
if (onFlingListener != null) {
onFlingListener.onFling();
}
+ // new API
for (MapboxMap.OnFlingListener listener : onFlingListenerList) {
listener.onFling();
}
}
void notifyOnScrollListeners() {
+ //deprecated API
if (onScrollListener != null) {
onScrollListener.onScroll();
}
+ // new API
for (MapboxMap.OnScrollListener listener : onScrollListenerList) {
listener.onScroll();
}
--
cgit v1.2.1
From 04cbf346e9e0b1cfffc50b8dfd46b4a329fd1850 Mon Sep 17 00:00:00 2001
From: Langston Smith
Date: Mon, 18 Dec 2017 08:10:52 -0800
Subject: Updated location layer plugin link in MapboxMap object's javadocs
(#10707)
---
.../main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
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 e6818ca436..bf80542f6a 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
@@ -562,7 +562,7 @@ public final class MapboxMap {
*
* @return the TrackingSettings asssociated with this map
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public TrackingSettings getTrackingSettings() {
@@ -578,7 +578,7 @@ public final class MapboxMap {
*
* @return the MyLocationViewSettings associated with this map
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public MyLocationViewSettings getMyLocationViewSettings() {
@@ -2097,7 +2097,7 @@ public final class MapboxMap {
*
* @return True if the my-location layer is enabled, false otherwise.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public boolean isMyLocationEnabled() {
@@ -2115,7 +2115,7 @@ public final class MapboxMap {
*
* @param enabled True to enable; false to disable.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public void setMyLocationEnabled(boolean enabled) {
@@ -2127,7 +2127,7 @@ public final class MapboxMap {
*
* @return The currently displayed user location.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Nullable
@Deprecated
@@ -2142,7 +2142,7 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the user clicks on a marker.
* To unset the callback, use null.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListener
@@ -2155,7 +2155,7 @@ public final class MapboxMap {
*
* @param locationSource A {@link LocationEngine} location source to use in the my-location layer.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public void setLocationSource(@Nullable LocationEngine locationSource) {
@@ -2168,7 +2168,7 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the location tracking mode changes.
* To unset the callback, use null.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public void setOnMyLocationTrackingModeChangeListener(
@@ -2182,7 +2182,7 @@ public final class MapboxMap {
* @param listener The callback that's invoked when the bearing tracking mode changes.
* To unset the callback, use null.
* @deprecated use location layer plugin from
- * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugins/locationlayer instead.
+ * https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-locationlayer instead.
*/
@Deprecated
public void setOnMyBearingTrackingModeChangeListener(@Nullable OnMyBearingTrackingModeChangeListener listener) {
--
cgit v1.2.1
From 9759ba78367cea366ad28057d47725a37170c9f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?=
Date: Mon, 18 Dec 2017 12:49:58 -0800
Subject: [android] Updated Spanish, Vietnamese translations
---
.../android/MapboxGLAndroidSDK/src/main/res/values-es/strings.xml | 5 +++--
.../android/MapboxGLAndroidSDK/src/main/res/values-vi/strings.xml | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-es/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-es/strings.xml
index 92c055223f..9844642381 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-es/strings.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-es/strings.xml
@@ -4,12 +4,13 @@
Ícono de atribución. Actívalo para mostrar el diálogo de atribución.Vista de ubicación. Muestra tu ubicación en el mapa.Se está mostrando un mapa creado con Mapbox. Arrastra dos dedos para desplazarte o pellizca para acercar.
- Mapbox Android SDK
+ Mapbox Maps SDK para AndroidAyúdanos a mejorar los mapas de MapboxGracias a tu contribución de datos anónimos de uso, ayudas a mejorar OpenStreetMap y Mapbox.AceptarRechazarMás información
+ No puede abrir la página Web porque no hay un navegador Web en el dispositivo.El parámetro OfflineRegionDefinition que se ingresó no coincide con los límites mundiales: %s
-
+ Ajustes de telemetría
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values-vi/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values-vi/strings.xml
index a0cad6487a..77e72a4db7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/res/values-vi/strings.xml
+++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values-vi/strings.xml
@@ -4,12 +4,13 @@
Biểu tượng ghi công. Kích hoạt để xem hộp thoại ghi công.Cái chỉ vị trí. Cái này chỉ vị trí của bạn trên bản đồ.Đang xem bản đồ được xây dựng dùng Mapbox. Kéo hai ngón tay để cuộn. Chụm các ngón tay lại để phóng to. Tách các ngón tay ra để thu nhỏ.
- Mapbox Android SDK
+ Mapbox Maps SDK cho AndroidCải tiến các Bản đồ MapboxBạn đang giúp cải tiến các bản đồ OpenStreetMap và Mapbox bằng cách đóng góp dữ liệu vô danh hóa về cách sử dụng.Đồng ýPhản đốiThông tin thêm
+ Không thể mở trang Web vì thiết bị thiếu trình duyệt.OfflineRegionDefinition được cung cấp không vừa thế giới: %s
-
+ Thiết lập Trình viễn trắc
--
cgit v1.2.1
From 757cc0f2be1c0972f9b74a91ed873fe8a892f27f Mon Sep 17 00:00:00 2001
From: Tobrun
Date: Tue, 19 Dec 2017 08:55:48 +0100
Subject: [android] - add binding integration for expressions (#10654)
---
.../MapboxGLAndroidSDK/gradle-checkstyle.gradle | 1 +
.../mapboxsdk/style/expressions/Expression.java | 1761 ++++++++++++++++++++
.../com/mapbox/mapboxsdk/style/layers/Layer.java | 13 +-
.../mapbox/mapboxsdk/style/layers/Property.java | 24 +-
.../mapboxsdk/style/layers/PropertyFactory.java | 1055 +++++++++++-
.../style/layers/property_factory.java.ejs | 23 +
.../style/expressions/ExpressionTest.java | 1010 +++++++++++
7 files changed, 3851 insertions(+), 36 deletions(-)
create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
create mode 100644 platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
(limited to 'platform/android/MapboxGLAndroidSDK')
diff --git a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle
index e0bc076d3d..420ccb473a 100644
--- a/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle
+++ b/platform/android/MapboxGLAndroidSDK/gradle-checkstyle.gradle
@@ -16,6 +16,7 @@ task checkstyle(type: Checkstyle) {
exclude '**/style/layers/PropertyFactory.java'
exclude '**/style/layers/*Layer.java'
exclude '**/style/light/Light.java'
+ exclude '**/Expression.java' // allowing single character signature as e()
classpath = files()
ignoreFailures = false
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
new file mode 100644
index 0000000000..4d09fcaac6
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
@@ -0,0 +1,1761 @@
+package com.mapbox.mapboxsdk.style.expressions;
+
+import android.support.annotation.ColorInt;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.Size;
+
+import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The value for any layout property, paint property, or filter may be specified as an expression.
+ * An expression defines a formula for computing the value of the property using the operators described below.
+ * The set of expression operators provided by Mapbox GL includes:
+ *
+ *
+ *
Element
+ *
Mathematical operators for performing arithmetic and other operations on numeric values
+ *
Logical operators for manipulating boolean values and making conditional decisions
+ *
String operators for manipulating strings
+ *
Data operators, providing access to the properties of source features
+ *
Camera operators, providing access to the parameters defining the current map view
+ *
+ *
+ *
+ * Expressions are represented as JSON arrays.
+ * The first element of an expression array is a string naming the expression operator,
+ * e.g. "*"or "case". Subsequent elements (if any) are the arguments to the expression.
+ * Each argument is either a literal value (a string, number, boolean, or null), or another expression array.
+ *
+ *
+ * Data expression: a data expression is any expression that access feature data -- that is,
+ * any expression that uses one of the data operators:get,has,id,geometry-type, or properties.
+ * Data expressions allow a feature's properties to determine its appearance.
+ * They can be used to differentiate features within the same layer and to create data visualizations.
+ *
+ *
+ * Camera expression: a camera expression is any expression that uses the zoom operator.
+ * Such expressions allow the the appearance of a layer to change with the map's zoom level.
+ * Camera expressions can be used to create the appearance of depth and to control data density.
+ *
+ *
+ * Composition: a single expression may use a mix of data operators, camera operators, and other operators.
+ * Such composite expressions allows a layer's appearance to be determined by
+ * a combination of the zoom level and individual feature properties.
+ *
+ *
+ * @param the type of the expression
+ */
+public class Expression {
+
+ private final String operator;
+ private final Expression[] arguments;
+
+ /**
+ * Creates an empty expression for expression literals
+ */
+ Expression() {
+ operator = null;
+ arguments = null;
+ }
+
+ /**
+ * Creates an expression from its operator and varargs expressions.
+ *
+ * @param operator the expression operator
+ * @param arguments expressions input
+ */
+ public Expression(@NonNull String operator, @Nullable Expression... arguments) {
+ this.operator = operator;
+ this.arguments = arguments;
+ }
+
+ /**
+ * Converts the expression to Object array representation.
+ *
+ * The output will later be converted to a JSON Object array.
+ *
+ *
+ * @return the converted object array expression
+ */
+ @NonNull
+ public Object[] toArray() {
+ List