[android] #4077 - Creating configureAndStartMapboxEventManager() to minimize paramaters needs on getMapboxEventManager()
This commit is contained in:
@@ -215,7 +215,7 @@ public class MapView extends FrameLayout {
|
||||
|
||||
mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView);
|
||||
mUserLocationView.setMapboxMap(mMapboxMap);
|
||||
|
||||
|
||||
mCompassView = (CompassView) view.findViewById(R.id.compassView);
|
||||
mCompassView.setMapboxMap(mMapboxMap);
|
||||
|
||||
@@ -372,8 +372,11 @@ public class MapView extends FrameLayout {
|
||||
// Force a check for Telemetry
|
||||
validateTelemetryServiceConfigured();
|
||||
|
||||
// Force a check for an access token
|
||||
validateAccessToken(getAccessToken());
|
||||
|
||||
// Start Telemetry (authorization determined in initial MapboxEventManager constructor)
|
||||
MapboxEventManager.getMapboxEventManager(getContext()).isTelemetryEnabled();
|
||||
MapboxEventManager.configureAndStartMapboxEventManager(getContext(), getAccessToken());
|
||||
}
|
||||
|
||||
// Force a check for an access token
|
||||
@@ -400,7 +403,7 @@ public class MapView extends FrameLayout {
|
||||
Hashtable<String, Object> evt = new Hashtable<>();
|
||||
evt.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_MAP_LOAD);
|
||||
evt.put(MapboxEvent.ATTRIBUTE_CREATED, MapboxEventManager.generateCreateDate());
|
||||
MapboxEventManager.getMapboxEventManager(getContext()).pushEvent(evt);
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1201,7 +1204,7 @@ public class MapView extends FrameLayout {
|
||||
evt.put(MapboxEvent.KEY_LONGITUDE, tapLatLng.getLongitude());
|
||||
evt.put(MapboxEvent.KEY_ZOOM, mMapboxMap.getCameraPosition().zoom);
|
||||
|
||||
MapboxEventManager.getMapboxEventManager(getContext()).pushEvent(evt);
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1220,7 +1223,7 @@ public class MapView extends FrameLayout {
|
||||
evt.put(MapboxEvent.KEY_LONGITUDE, tapLatLng.getLongitude());
|
||||
evt.put(MapboxEvent.KEY_ZOOM, mMapboxMap.getCameraPosition().zoom);
|
||||
|
||||
MapboxEventManager.getMapboxEventManager(getContext()).pushEvent(evt);
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
|
||||
// Called when user touches the screen, all positions are absolute
|
||||
@@ -2301,7 +2304,7 @@ public class MapView extends FrameLayout {
|
||||
if (which == ATTRIBUTION_INDEX_TELEMETRY_SETTINGS) {
|
||||
|
||||
int array = R.array.attribution_telemetry_options;
|
||||
if (MapboxEventManager.getMapboxEventManager(context).isTelemetryEnabled()) {
|
||||
if (MapboxEventManager.getMapboxEventManager().isTelemetryEnabled()) {
|
||||
array = R.array.attribution_telemetry_options_already_participating;
|
||||
}
|
||||
String[] items = context.getResources().getStringArray(array);
|
||||
@@ -2328,11 +2331,11 @@ public class MapView extends FrameLayout {
|
||||
telemDialog.cancel();
|
||||
return;
|
||||
case 1:
|
||||
MapboxEventManager.getMapboxEventManager(context).setTelemetryEnabled(false);
|
||||
MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(false);
|
||||
telemDialog.cancel();
|
||||
return;
|
||||
case 2:
|
||||
MapboxEventManager.getMapboxEventManager(context).setTelemetryEnabled(true);
|
||||
MapboxEventManager.getMapboxEventManager().setTelemetryEnabled(true);
|
||||
telemDialog.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -83,9 +83,9 @@ public class MapboxEventManager {
|
||||
|
||||
private Timer timer = null;
|
||||
|
||||
private MapboxEventManager(@NonNull Context context) {
|
||||
private MapboxEventManager(@NonNull Context context, String accessToken) {
|
||||
super();
|
||||
this.accessToken = ApiAccess.getToken(context);
|
||||
this.accessToken = accessToken;
|
||||
this.context = context;
|
||||
|
||||
// Setup Message Digest
|
||||
@@ -152,15 +152,27 @@ public class MapboxEventManager {
|
||||
batteryStatus = context.registerReceiver(null, iFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param context Application Context
|
||||
* @return MapboxEventManager
|
||||
*/
|
||||
public static MapboxEventManager getMapboxEventManager(@NonNull Context context) {
|
||||
if (mapboxEventManager == null) {
|
||||
mapboxEventManager = new MapboxEventManager(context.getApplicationContext());
|
||||
}
|
||||
public static MapboxEventManager getMapboxEventManager() {
|
||||
return mapboxEventManager;
|
||||
}
|
||||
|
||||
@@ -491,7 +503,7 @@ public class MapboxEventManager {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
|
||||
if (events.size() < 1) {
|
||||
if (events.size() < 1) {
|
||||
Log.d(TAG, "No events in the queue to send so returning.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.ToneGenerator;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -63,7 +61,7 @@ public class TelemetryLocationReceiver extends BroadcastReceiver {
|
||||
Location location = (Location)intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
|
||||
if (location != null) {
|
||||
Log.d(TAG, "location received = " + location);
|
||||
MapboxEventManager.getMapboxEventManager(context).addLocationEvent(location);
|
||||
MapboxEventManager.getMapboxEventManager().addLocationEvent(location);
|
||||
} else {
|
||||
Log.d(TAG, "location NOT received");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user