summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2016-03-10 11:57:29 -0500
committerTobrun <tobrun.van.nuland@gmail.com>2016-03-10 14:59:33 -0500
commit4cb75a5c36e5e82053c9dd5fae626596aee6136b (patch)
tree1ad35127f9ae351b4fc58caa3f741f5176ad83e0
parent64b163ee5dea3db2c5f6dcfaa4463e8e97e6333b (diff)
downloadqtlocation-mapboxgl-4cb75a5c36e5e82053c9dd5fae626596aee6136b.tar.gz
[android] #4263 - fix null pointer on MapboxMapEventManager
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java3
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java45
2 files changed, 25 insertions, 23 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 90632f4bdc..afc2f1e24e 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
@@ -376,7 +376,8 @@ public class MapView extends FrameLayout {
validateTelemetryServiceConfigured();
// Start Telemetry (authorization determined in initial MapboxEventManager constructor)
- MapboxEventManager.configureAndStartMapboxEventManager(getContext(), getAccessToken());
+ MapboxEventManager eventManager = MapboxEventManager.getMapboxEventManager();
+ eventManager.initialise(getContext(), getAccessToken());
}
// Initialize EGL
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
index 3339658ca2..97393df4ad 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java
@@ -84,13 +84,22 @@ public class MapboxEventManager {
/**
* Private Constructor for configuring the single instance per app.
- * @param context Application Context
- * @param accessToken Access Token used in application, can be overridden by putting staging credentials in AppManifest
*/
- private MapboxEventManager(@NonNull Context context, String accessToken) {
- super();
+ private MapboxEventManager() {
+
+ }
+
+ /**
+ * Internal setup of MapboxEventsManager. It needs to be called once before @link MapboxEventManager#getMapboxEventManager
+ * <p/>
+ * This allows for a cleaner getMapboxEventManager() that doesn't require context and accessToken
+ *
+ * @param context The context associated with MapView
+ * @param accessToken The accessToken to load MapView
+ */
+ public void initialise(@NonNull Context context, @NonNull String accessToken) {
+ this.context = context.getApplicationContext();
this.accessToken = accessToken;
- this.context = context;
// Setup Message Digest
try {
@@ -157,26 +166,14 @@ public class MapboxEventManager {
}
/**
- * Internal setup of MapboxEventsManager. It needs to be called once before @link MapboxEventManager#getMapboxEventManager
- *
- * This allows for a cleaner getMapboxEventManager() that doesn't require context and accessToken
- *
- * @param context Context
- * @param accessToken Access Token
- */
- public static void configureAndStartMapboxEventManager(@NonNull Context context, @NonNull String accessToken) {
- if (mapboxEventManager != null) {
- Log.w(TAG, "Singleton has already been created.");
- return;
- }
- mapboxEventManager = new MapboxEventManager(context.getApplicationContext(), accessToken);
- }
-
- /**
* Primary Access method using Singleton pattern
+ *
* @return MapboxEventManager
*/
public static MapboxEventManager getMapboxEventManager() {
+ if (mapboxEventManager == null) {
+ mapboxEventManager = new MapboxEventManager();
+ }
return mapboxEventManager;
}
@@ -266,15 +263,19 @@ public class MapboxEventManager {
/**
* Push Interactive Events to the system for processing
+ *
* @param eventWithAttributes Event with attributes
*/
public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
+ if (context == null || accessToken == null) {
+ return;
+ }
if (eventWithAttributes == null) {
return;
}
- String eventType = (String)eventWithAttributes.get(MapboxEvent.ATTRIBUTE_EVENT);
+ String eventType = (String) eventWithAttributes.get(MapboxEvent.ATTRIBUTE_EVENT);
if (TextUtils.isEmpty(eventType)) {
return;
}