MapboxAccountManager refactor, removal deprecated accesstoken (#7462)
* [android] - move object ownership, move depenencies and responsibility. * [android] - MapboxAccountManager refactor, removal deprecated accesstoken.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
|
||||
public final class Mapbox {
|
||||
|
||||
private static Mapbox INSTANCE;
|
||||
private Context context;
|
||||
private String accessToken;
|
||||
private Boolean connected;
|
||||
|
||||
public static synchronized Mapbox getInstance(@NonNull Context context, @NonNull String accessToken) {
|
||||
if (INSTANCE == null) {
|
||||
Context appContext = context.getApplicationContext();
|
||||
INSTANCE = new Mapbox(appContext, accessToken);
|
||||
MapboxEventManager.getMapboxEventManager().initialize(appContext, accessToken);
|
||||
ConnectivityReceiver.instance(appContext);
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private Mapbox(@NonNull Context context, @NonNull String accessToken) {
|
||||
this.context = context;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access Token for this application.
|
||||
*
|
||||
* @return Mapbox Access Token
|
||||
*/
|
||||
public static String getAccessToken() {
|
||||
return INSTANCE.accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Application context
|
||||
*/
|
||||
public static Context getApplicationContext() {
|
||||
return INSTANCE.context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime validation of Access Token.
|
||||
*
|
||||
* @throws InvalidAccessTokenException the exception thrown
|
||||
*/
|
||||
public static void validateAccessToken() throws InvalidAccessTokenException {
|
||||
String accessToken = INSTANCE.accessToken;
|
||||
if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")
|
||||
&& !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) {
|
||||
throw new InvalidAccessTokenException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually sets the connectivity state of the app. This is useful for apps that 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.
|
||||
*/
|
||||
public static void setConnected(Boolean connected) {
|
||||
// Connectivity state overridden by app
|
||||
INSTANCE.connected = connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static Boolean isConnected() {
|
||||
if (INSTANCE.connected != null) {
|
||||
// Connectivity state overridden by app
|
||||
return INSTANCE.connected;
|
||||
}
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) INSTANCE.context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
return (activeNetwork != null && activeNetwork.isConnected());
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
|
||||
import com.mapbox.mapboxsdk.exceptions.MapboxAccountManagerNotStartedException;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
|
||||
public class MapboxAccountManager {
|
||||
|
||||
private static MapboxAccountManager mapboxAccountManager = null;
|
||||
|
||||
private final String accessToken;
|
||||
private final Context applicationContext;
|
||||
|
||||
private Boolean connected = null;
|
||||
|
||||
/**
|
||||
* MapboxAccountManager should NOT be instantiated directly.
|
||||
* Use @see MapboxAccountManager#getInstance() instead.
|
||||
*
|
||||
* @param applicationContext Context used to get ApplicationContext
|
||||
* @param accessToken Mapbox Access Token
|
||||
*/
|
||||
private MapboxAccountManager(Context applicationContext, String accessToken) {
|
||||
super();
|
||||
this.applicationContext = applicationContext.getApplicationContext();
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Primary entry point to Mapbox for implementing developers.
|
||||
* Must be configured in either Application.onCreate() or Launch Activity.onCreate()
|
||||
*
|
||||
* @param context Context used to get Application Context
|
||||
* @param accessToken Mapbox Access Token. You can get one on the Mapbox Web site.
|
||||
* @return MapboxAccountManager instance for app
|
||||
*/
|
||||
public static MapboxAccountManager start(Context context, String accessToken) {
|
||||
if (mapboxAccountManager == null) {
|
||||
//Create a new account manager
|
||||
mapboxAccountManager = new MapboxAccountManager(context, accessToken);
|
||||
|
||||
//Initialize the event manager
|
||||
MapboxEventManager.getMapboxEventManager().initialize(context, accessToken);
|
||||
|
||||
//Register a receiver to listen for connectivity updates
|
||||
ConnectivityReceiver.instance(context);
|
||||
}
|
||||
|
||||
return mapboxAccountManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal Use Only
|
||||
* Get an instance of MapboxAccountManager configured with the app's Access Token
|
||||
*
|
||||
* @return MapboxAccountManager instance for app. May be NULL if not configured yet.
|
||||
*/
|
||||
public static MapboxAccountManager getInstance() {
|
||||
if (mapboxAccountManager == null) {
|
||||
throw new MapboxAccountManagerNotStartedException();
|
||||
}
|
||||
|
||||
return mapboxAccountManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Access Token for this application.
|
||||
*
|
||||
* @return Mapbox Access Token
|
||||
*/
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime validation of Access Token.
|
||||
*
|
||||
* @param accessToken Access Token to check
|
||||
* @throws InvalidAccessTokenException the exception thrown
|
||||
*/
|
||||
public static void validateAccessToken(String accessToken) throws InvalidAccessTokenException {
|
||||
if (TextUtils.isEmpty(accessToken) || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")
|
||||
&& !accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("sk."))) {
|
||||
throw new InvalidAccessTokenException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually sets the connectivity state of the app. This is useful for apps that 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.
|
||||
*/
|
||||
public void setConnected(Boolean connected) {
|
||||
// Connectivity state overridden by app
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public Boolean isConnected() {
|
||||
if (connected != null) {
|
||||
// Connectivity state overridden by app
|
||||
return connected;
|
||||
}
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
return (activeNetwork != null && activeNetwork.isConnected());
|
||||
}
|
||||
|
||||
/**
|
||||
* Not public API
|
||||
*
|
||||
* @return the Application Context
|
||||
*/
|
||||
public Context getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +41,8 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
|
||||
// Requires removing MapboxMap from Annotations by using Peer model from #6912
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
private long viewMarkerBoundsUpdateTime;
|
||||
private boolean enabled;
|
||||
private long updateTime;
|
||||
private MapboxMap.OnMarkerViewClickListener onMarkerViewClickListener;
|
||||
private boolean isWaitingForRenderInvoke;
|
||||
|
||||
@@ -61,7 +62,6 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
|
||||
this.mapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMapChanged(@MapView.MapChange int change) {
|
||||
if (isWaitingForRenderInvoke && change == MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) {
|
||||
@@ -70,6 +70,10 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setWaitingForRenderInvoke(boolean waitingForRenderInvoke) {
|
||||
isWaitingForRenderInvoke = waitingForRenderInvoke;
|
||||
}
|
||||
@@ -418,13 +422,13 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
|
||||
* </p>
|
||||
*/
|
||||
public void scheduleViewMarkerInvalidation() {
|
||||
if (!markerViewAdapters.isEmpty()) {
|
||||
if (enabled) {
|
||||
long currentTime = SystemClock.elapsedRealtime();
|
||||
if (currentTime < viewMarkerBoundsUpdateTime) {
|
||||
if (currentTime < updateTime) {
|
||||
return;
|
||||
}
|
||||
invalidateViewMarkersInVisibleRegion();
|
||||
viewMarkerBoundsUpdateTime = currentTime + 250;
|
||||
updateTime = currentTime + 250;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,11 +596,11 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
|
||||
* Default MarkerViewAdapter used for base class of {@link MarkerView} to adapt a MarkerView to
|
||||
* an ImageView.
|
||||
*/
|
||||
public static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> {
|
||||
private static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> {
|
||||
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public ImageMarkerViewAdapter(Context context) {
|
||||
ImageMarkerViewAdapter(Context context) {
|
||||
super(context);
|
||||
inflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.mapbox.mapboxsdk.constants;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -14,15 +12,6 @@ public class MapboxConstants {
|
||||
*/
|
||||
public static final Locale MAPBOX_LOCALE = Locale.US;
|
||||
|
||||
/**
|
||||
* Key used to store access token in AndroidManifest.xml
|
||||
*
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String KEY_META_DATA_MANIFEST = "com.mapbox.AccessToken";
|
||||
|
||||
/**
|
||||
* Key used to store staging data server url in AndroidManifest.xml
|
||||
*/
|
||||
@@ -137,8 +126,6 @@ public class MapboxConstants {
|
||||
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "atrrMarginBottom";
|
||||
public static final String STATE_ATTRIBUTION_ENABLED = "atrrEnabled";
|
||||
|
||||
public static final String TAG = "MapboxMap";
|
||||
|
||||
public static final String MAPBOX_SHARED_PREFERENCES_FILE = "MapboxSharedPreferences";
|
||||
public static final String MAPBOX_SHARED_PREFERENCE_KEY_VENDORID = "mapboxVendorId";
|
||||
public static final String MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED = "mapboxTelemetryEnabled";
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
package com.mapbox.mapboxsdk.exceptions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
/**
|
||||
* A {@code InvalidAccessTokenException} is thrown by {@link com.mapbox.mapboxsdk.maps.MapboxMap} when there is either
|
||||
* no access token set before {@link MapView#onCreate(Bundle)} or an invalid access token is set in
|
||||
* {@link MapView#setAccessToken(String)}
|
||||
* A {@code InvalidAccessTokenException} is thrown by {@link com.mapbox.mapboxsdk.maps.MapboxMap}
|
||||
* when there is either no access token set before {@link MapView#onCreate(Bundle)} or an invalid access token
|
||||
* is set in {@link com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)}
|
||||
*
|
||||
* @see MapView#onCreate(Bundle)
|
||||
* @see MapView#setAccessToken(String)
|
||||
* @see com.mapbox.mapboxsdk.Mapbox#getInstance(Context, String)
|
||||
*/
|
||||
public class InvalidAccessTokenException extends RuntimeException {
|
||||
|
||||
public InvalidAccessTokenException() {
|
||||
super("\nUsing MapView requires setting a valid access token. Use setAccessToken on Mapview to provide one. "
|
||||
super("\nUsing MapView requires setting a valid access token. Use Mapbox.getInstance(Context context, "
|
||||
+ "String accessToken) to provide one. "
|
||||
+ "\nPlease see https://www.mapbox.com/help/create-api-access-token/ to learn how to create one."
|
||||
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.exceptions;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
/**
|
||||
* A MapboxAccountManagerNotStartedException is thrown by {@link com.mapbox.mapboxsdk.maps.MapView}
|
||||
* when {@link MapboxAccountManager} is not started before {@link MapView#onCreate(Bundle)}.
|
||||
*
|
||||
* @see MapView#onCreate(Bundle)
|
||||
* @see MapboxAccountManager#start(android.content.Context, String)
|
||||
*/
|
||||
public class MapboxAccountManagerNotStartedException extends RuntimeException {
|
||||
|
||||
public MapboxAccountManagerNotStartedException() {
|
||||
super("\nMapboxAccountManager was not started correctly. Use MapboxAccountManager#start(Context, String) to"
|
||||
+ "initialise. "
|
||||
+ "\nMore information in this guide https://www.mapbox.com/help/first-steps-android-sdk/#access-tokens.");
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,8 @@ import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -29,6 +27,7 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.internal.Util;
|
||||
import timber.log.Timber;
|
||||
|
||||
class HTTPRequest implements Callback {
|
||||
|
||||
@@ -58,7 +57,7 @@ class HTTPRequest implements Callback {
|
||||
|
||||
try {
|
||||
// Don't try a request if we aren't connected
|
||||
if (!MapboxAccountManager.getInstance().isConnected()) {
|
||||
if (!Mapbox.isConnected()) {
|
||||
throw new NoRouteToHostException("No Internet connection available.");
|
||||
}
|
||||
|
||||
@@ -196,11 +195,11 @@ class HTTPRequest implements Callback {
|
||||
|
||||
private String getApplicationIdentifier() {
|
||||
try {
|
||||
Context context = MapboxAccountManager.getInstance().getApplicationContext();
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import com.mapbox.mapboxsdk.annotations.PolylineOptions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -45,8 +44,6 @@ class AnnotationManager {
|
||||
private final List<Marker> selectedMarkers = new ArrayList<>();
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
private HashMap<MarkerView, MarkerViewManager.OnMarkerViewAddedListener> markerMap = new HashMap<>();
|
||||
private MapboxMap.OnMarkerClickListener onMarkerClickListener;
|
||||
|
||||
AnnotationManager(NativeMapView view, MapView mapView, MarkerViewManager markerViewManager) {
|
||||
@@ -68,6 +65,11 @@ class AnnotationManager {
|
||||
return this;
|
||||
}
|
||||
|
||||
void update() {
|
||||
markerViewManager.scheduleViewMarkerInvalidation();
|
||||
infoWindowManager.update();
|
||||
}
|
||||
|
||||
//
|
||||
// Annotations
|
||||
//
|
||||
@@ -157,6 +159,15 @@ class AnnotationManager {
|
||||
// Markers
|
||||
//
|
||||
|
||||
Marker addMarker(@NonNull BaseMarkerOptions markerOptions, @NonNull MapboxMap mapboxMap) {
|
||||
Marker marker = prepareMarker(markerOptions);
|
||||
long id = nativeMapView != null ? nativeMapView.addMarker(marker) : 0;
|
||||
marker.setMapboxMap(mapboxMap);
|
||||
marker.setId(id);
|
||||
annotations.put(id, marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
List<Marker> addMarkers(@NonNull List<? extends BaseMarkerOptions> markerOptionsList, @NonNull MapboxMap mapboxMap) {
|
||||
int count = markerOptionsList.size();
|
||||
List<Marker> markers = new ArrayList<>(count);
|
||||
@@ -202,26 +213,8 @@ class AnnotationManager {
|
||||
return marker;
|
||||
}
|
||||
|
||||
Marker addMarker(@NonNull BaseMarkerOptions markerOptions, @NonNull MapboxMap mapboxMap) {
|
||||
Marker marker = prepareMarker(markerOptions);
|
||||
long id = nativeMapView != null ? nativeMapView.addMarker(marker) : 0;
|
||||
marker.setMapboxMap(mapboxMap);
|
||||
marker.setId(id);
|
||||
annotations.put(id, marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap) {
|
||||
MarkerView marker = prepareViewMarker(markerOptions);
|
||||
marker.setMapboxMap(mapboxMap);
|
||||
long id = nativeMapView.addMarker(marker);
|
||||
marker.setId(id);
|
||||
annotations.put(id, marker);
|
||||
return marker;
|
||||
}
|
||||
|
||||
public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap,
|
||||
final MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) {
|
||||
MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap,
|
||||
@Nullable MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) {
|
||||
final MarkerView marker = prepareViewMarker(markerOptions);
|
||||
|
||||
// add marker to map
|
||||
@@ -230,7 +223,9 @@ class AnnotationManager {
|
||||
marker.setId(id);
|
||||
annotations.put(id, marker);
|
||||
|
||||
markerViewManager.addOnMarkerViewAddedListener(marker, onMarkerViewAddedListener);
|
||||
if (onMarkerViewAddedListener != null) {
|
||||
markerViewManager.addOnMarkerViewAddedListener(marker, onMarkerViewAddedListener);
|
||||
}
|
||||
markerViewManager.setWaitingForRenderInvoke(true);
|
||||
return marker;
|
||||
}
|
||||
@@ -362,7 +357,7 @@ class AnnotationManager {
|
||||
return selectedMarkers;
|
||||
}
|
||||
|
||||
public List<Marker> getMarkersInRect(@NonNull RectF rectangle) {
|
||||
List<Marker> getMarkersInRect(@NonNull RectF rectangle) {
|
||||
// convert Rectangle to be density depedent
|
||||
float pixelRatio = nativeMapView.getPixelRatio();
|
||||
RectF rect = new RectF(rectangle.left / pixelRatio,
|
||||
@@ -390,7 +385,7 @@ class AnnotationManager {
|
||||
return new ArrayList<>(annotations);
|
||||
}
|
||||
|
||||
public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rectangle) {
|
||||
List<MarkerView> getMarkerViewsInRect(@NonNull RectF rectangle) {
|
||||
float pixelRatio = nativeMapView.getPixelRatio();
|
||||
RectF rect = new RectF(rectangle.left / pixelRatio,
|
||||
rectangle.top / pixelRatio,
|
||||
|
||||
@@ -16,8 +16,8 @@ import java.util.List;
|
||||
* Maintains a {@link List} of opened {@link InfoWindow} and tracks configurations as
|
||||
* allowConcurrentMultipleInfoWindows which allows to have multiple {@link InfoWindow} open at the
|
||||
* same time. Responsible for managing listeners as
|
||||
* {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener}
|
||||
* and {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowLongClickListener}.
|
||||
* {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener} and
|
||||
* {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowLongClickListener}.
|
||||
* </p>
|
||||
*/
|
||||
class InfoWindowManager {
|
||||
@@ -34,6 +34,12 @@ class InfoWindowManager {
|
||||
this.infoWindows = new ArrayList<>();
|
||||
}
|
||||
|
||||
void update() {
|
||||
for (InfoWindow infoWindow : infoWindows) {
|
||||
infoWindow.update();
|
||||
}
|
||||
}
|
||||
|
||||
void setInfoWindowAdapter(@Nullable MapboxMap.InfoWindowAdapter infoWindowAdapter) {
|
||||
this.infoWindowAdapter = infoWindowAdapter;
|
||||
}
|
||||
|
||||
@@ -2,22 +2,17 @@ package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
|
||||
|
||||
/**
|
||||
* Fragment wrapper around a map view.
|
||||
@@ -72,24 +67,6 @@ public final class MapFragment extends Fragment {
|
||||
options = bundle.getParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS);
|
||||
}
|
||||
|
||||
// Assign an AccessToken if needed
|
||||
if (options == null || options.getAccessToken() == null) {
|
||||
String token = null;
|
||||
if (MapboxAccountManager.getInstance() != null) {
|
||||
token = MapboxAccountManager.getInstance().getAccessToken();
|
||||
} else {
|
||||
token = getToken(inflater.getContext());
|
||||
}
|
||||
if (TextUtils.isEmpty(token)) {
|
||||
throw new InvalidAccessTokenException();
|
||||
}
|
||||
if (options == null) {
|
||||
options = new MapboxMapOptions().accessToken(token);
|
||||
} else {
|
||||
options.accessToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
Drawable foregroundDrawable = options.getMyLocationForegroundDrawable();
|
||||
Drawable foregroundBearingDrawable = options.getMyLocationForegroundBearingDrawable();
|
||||
if (foregroundDrawable == null || foregroundBearingDrawable == null) {
|
||||
@@ -109,39 +86,6 @@ public final class MapFragment extends Fragment {
|
||||
return map = new MapView(inflater.getContext(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the Mapbox access token set in the app resources.
|
||||
* </p>
|
||||
* It will first search the application manifest for a {@link MapboxConstants#KEY_META_DATA_MANIFEST}
|
||||
* meta-data value. If not found it will then attempt to load the access token from the
|
||||
* {@code res/raw/token.txt} development file.
|
||||
*
|
||||
* @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}.
|
||||
* @return The Mapbox access token or null if not found.
|
||||
* @see MapboxConstants#KEY_META_DATA_MANIFEST
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
private String getToken(@NonNull Context context) {
|
||||
try {
|
||||
// read out AndroidManifest
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
|
||||
PackageManager.GET_META_DATA);
|
||||
String token = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
|
||||
if (token == null || token.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return token;
|
||||
} catch (Exception exception) {
|
||||
// use fallback on string resource, used for development
|
||||
int tokenResId = context.getResources().getIdentifier("mapbox_access_token", "string", context.getPackageName());
|
||||
return tokenResId != 0 ? context.getString(tokenResId) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the fragment view hierarchy is created.
|
||||
*
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector;
|
||||
@@ -119,8 +120,8 @@ final class MapGestureDetector {
|
||||
&& uiSettings.isZoomGesturesEnabled();
|
||||
if (twoTap) {
|
||||
// Confirmed 2nd Finger Down
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_TWO_FINGER_SINGLETAP, event.getX(),
|
||||
event.getY(), transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_TWO_FINGER_SINGLETAP, event.getX(), event.getY(), transform.getZoom());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -220,12 +221,12 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTapEvent(MotionEvent motionEvent) {
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
if (!uiSettings.isZoomGesturesEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (motionEvent.getAction()) {
|
||||
switch (e.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
@@ -243,13 +244,12 @@ final class MapGestureDetector {
|
||||
transform.zoom(true, focalPoint.x, focalPoint.y);
|
||||
} else {
|
||||
// Zoom in on gesture
|
||||
transform.zoom(true, motionEvent.getX(), motionEvent.getY());
|
||||
transform.zoom(true, e.getX(), e.getY());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_DOUBLETAP, motionEvent.getX(), motionEvent.getY(),
|
||||
transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_DOUBLETAP, e.getX(), e.getY(), transform.getZoom());
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -278,16 +278,16 @@ final class MapGestureDetector {
|
||||
}
|
||||
}
|
||||
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_SINGLETAP, motionEvent.getX(), motionEvent.getY(),
|
||||
transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_SINGLETAP, motionEvent.getX(), motionEvent.getY(), transform.getZoom());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent motionEvent) {
|
||||
if (onMapLongClickListener != null && !quickZoom) {
|
||||
onMapLongClickListener.onMapLongClick(projection.fromScreenLocation(new PointF(motionEvent.getX(),
|
||||
motionEvent.getY())));
|
||||
onMapLongClickListener.onMapLongClick(
|
||||
projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,8 +318,8 @@ final class MapGestureDetector {
|
||||
onFlingListener.onFling();
|
||||
}
|
||||
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_PAN_START, e1.getX(), e1.getY(),
|
||||
transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_PAN_START, e1.getX(), e1.getY(), transform.getZoom());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -368,8 +368,8 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_PINCH_START, detector.getFocusX(),
|
||||
detector.getFocusY(), transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_PINCH_START, detector.getFocusX(), detector.getFocusY(), transform.getZoom());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -455,8 +455,8 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_ROTATION_START, detector.getFocusX(),
|
||||
detector.getFocusY(), transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_ROTATION_START, detector.getFocusX(), detector.getFocusY(), transform.getZoom());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -535,8 +535,8 @@ final class MapGestureDetector {
|
||||
}
|
||||
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxEvent.trackGestureEvent(projection, MapboxEvent.GESTURE_PITCH_START, detector.getFocusX(),
|
||||
detector.getFocusY(), transform.getZoom());
|
||||
MapboxEvent.trackGestureEvent(projection,
|
||||
MapboxEvent.GESTURE_PITCH_START, detector.getFocusX(), detector.getFocusY(), transform.getZoom());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -590,6 +590,34 @@ final class MapGestureDetector {
|
||||
}
|
||||
}
|
||||
|
||||
// This class handles input events from the zoom control buttons
|
||||
// Zoom controls allow single touch only devices to zoom in and out
|
||||
private static class OnZoomListener implements ZoomButtonsController.OnZoomListener {
|
||||
|
||||
private UiSettings uiSettings;
|
||||
private Transform transform;
|
||||
|
||||
OnZoomListener(UiSettings uiSettings, Transform transform) {
|
||||
this.uiSettings = uiSettings;
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
// Not used
|
||||
@Override
|
||||
public void onVisibilityChanged(boolean visible) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// Called when user pushes a zoom button
|
||||
@Override
|
||||
public void onZoom(boolean zoomIn) {
|
||||
if (!uiSettings.isZoomGesturesEnabled()) {
|
||||
return;
|
||||
}
|
||||
transform.zoom(zoomIn);
|
||||
}
|
||||
}
|
||||
|
||||
void setOnMapClickListener(MapboxMap.OnMapClickListener onMapClickListener) {
|
||||
this.onMapClickListener = onMapClickListener;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
@@ -38,19 +37,13 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.location.LocationListener;
|
||||
import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
@@ -60,51 +53,9 @@ import com.mapbox.mapboxsdk.telemetry.MapboxEventManager;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.ANIMATION_DURATION;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_GRAVITY;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_MARGIN_BOTTOM;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_MARGIN_RIGHT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ATTRIBUTION_MARGIN_TOP;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_CAMERA_POSITION;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_FADE_WHEN_FACING_NORTH;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_GRAVITY;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_MARGIN_LEFT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_MARGIN_RIGHT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_COMPASS_MARGIN_TOP;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_DEBUG_ACTIVE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_HAS_SAVED_STATE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_GRAVITY;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_MARGIN_BOTTOM;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_MARGIN_LEFT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_MARGIN_RIGHT;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_LOGO_MARGIN_TOP;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_MY_BEARING_TRACKING_MODE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_MY_LOCATION_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ROTATE_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ROTATE_ENABLED_CHANGE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_SCROLL_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_SCROLL_ENABLED_CHANGE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_STYLE_URL;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_TILT_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_TILT_ENABLED_CHANGE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ZOOM_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ZOOM_ENABLED_CHANGE;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A {@code MapView} provides an embeddable map interface.
|
||||
@@ -121,66 +72,108 @@ import static com.mapbox.mapboxsdk.constants.MapboxConstants.STATE_ZOOM_ENABLED_
|
||||
*/
|
||||
public class MapView extends FrameLayout {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
private boolean initialLoad;
|
||||
private boolean destroyed;
|
||||
|
||||
private NativeMapView nativeMapView;
|
||||
private boolean destroyed;
|
||||
private boolean hasSurface = false;
|
||||
|
||||
private CompassView compassView;
|
||||
private MyLocationView myLocationView;
|
||||
private LocationListener myLocationListener;
|
||||
private MapboxMap mapboxMap;
|
||||
private MapCallback mapCallback;
|
||||
private boolean onStartCalled;
|
||||
private boolean onStopCalled;
|
||||
|
||||
private MapGestureDetector mapGestureDetector;
|
||||
private MapKeyListener mapKeyListener;
|
||||
private MapZoomButtonController mapZoomButtonController;
|
||||
|
||||
private ConnectivityReceiver connectivityReceiver;
|
||||
|
||||
private List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
|
||||
private SnapshotRequest snapshotRequest;
|
||||
private ZoomButtonsController zoomButtonsController;
|
||||
|
||||
private boolean onStartCalled;
|
||||
private boolean onStopCalled;
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context) {
|
||||
super(context);
|
||||
initialize(context, MapboxMapOptions.createFromAttributes(context, null));
|
||||
initialise(context, MapboxMapOptions.createFromAttributes(context, null));
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
|
||||
initialise(context, MapboxMapOptions.createFromAttributes(context, attrs));
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
initialize(context, MapboxMapOptions.createFromAttributes(context, attrs));
|
||||
initialise(context, MapboxMapOptions.createFromAttributes(context, attrs));
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context, @NonNull MapboxMapOptions options) {
|
||||
super(context);
|
||||
initialize(context, options);
|
||||
initialise(context, options);
|
||||
}
|
||||
|
||||
private void initialize(@NonNull final Context context, @NonNull final MapboxMapOptions options) {
|
||||
private void initialise(@NonNull final Context context, @NonNull final MapboxMapOptions options) {
|
||||
if (isInEditMode()) {
|
||||
// if we are in an editor mode we show an image of a map
|
||||
// in IDE, show preview map
|
||||
LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_preview, this);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO distill into singular purpose methods/classes
|
||||
initialLoad = true;
|
||||
// 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);
|
||||
initalizeDrawingSurface(context, options);
|
||||
|
||||
// create native Map object
|
||||
nativeMapView = new NativeMapView(this);
|
||||
|
||||
// callback for focal point invalidation
|
||||
FocalPointInvalidator focalPoint = new FocalPointInvalidator();
|
||||
|
||||
// callback for registering touch listeners
|
||||
RegisterTouchListener registerTouchListener = new RegisterTouchListener();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView);
|
||||
UiSettings uiSettings = new UiSettings(proj, focalPoint, compassView, attrView, view.findViewById(R.id.logoView));
|
||||
TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPoint);
|
||||
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);
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings, proj,
|
||||
registerTouchListener, annotations);
|
||||
|
||||
// user input
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, trackingSettings, annotations);
|
||||
mapKeyListener = new MapKeyListener(transform, trackingSettings, uiSettings);
|
||||
mapZoomButtonController = new MapZoomButtonController(this, uiSettings, transform);
|
||||
|
||||
// inject widgets with MapboxMap
|
||||
compassView.setMapboxMap(mapboxMap);
|
||||
myLocationView.setMapboxMap(mapboxMap);
|
||||
attrView.setOnClickListener(new AttributionOnClickListener(context, transform));
|
||||
|
||||
// Ensure this view is interactable
|
||||
setClickable(true);
|
||||
setLongClickable(true);
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
// allow onDraw invocation
|
||||
setWillNotDraw(false);
|
||||
|
||||
// notify Map object about current connectivity state
|
||||
nativeMapView.setReachability(isConnected());
|
||||
|
||||
// initialise MapboxMap
|
||||
mapboxMap.initialise(context, options);
|
||||
}
|
||||
|
||||
private void initalizeDrawingSurface(Context context, MapboxMapOptions options) {
|
||||
if (options.getTextureMode()) {
|
||||
TextureView textureView = new TextureView(context);
|
||||
textureView.setSurfaceTextureListener(new SurfaceTextureListener());
|
||||
@@ -190,66 +183,6 @@ public class MapView extends FrameLayout {
|
||||
surfaceView.getHolder().addCallback(new SurfaceCallback());
|
||||
surfaceView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
nativeMapView = new NativeMapView(this);
|
||||
|
||||
// inflate overlain Views
|
||||
compassView = (CompassView) view.findViewById(R.id.compassView);
|
||||
myLocationView = (MyLocationView) view.findViewById(R.id.userLocationView);
|
||||
ImageView logoView = (ImageView) view.findViewById(R.id.logoView);
|
||||
ImageView attributionsView = (ImageView) view.findViewById(R.id.attributionView);
|
||||
attributionsView.setOnClickListener(new AttributionOnClickListener(this));
|
||||
ViewGroup markerViewContainer = (ViewGroup) findViewById(R.id.markerViewContainer);
|
||||
|
||||
// interface for focal point invalidation
|
||||
FocalPointInvalidator focalPointInvalidator = new FocalPointInvalidator();
|
||||
|
||||
// interface for registering touch listeners
|
||||
RegisterTouchListener registerTouchListener = new RegisterTouchListener();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection projection = new Projection(nativeMapView);
|
||||
UiSettings uiSettings = new UiSettings(projection, focalPointInvalidator, compassView, attributionsView, logoView);
|
||||
TrackingSettings trackingSettings = new TrackingSettings(myLocationView, uiSettings, focalPointInvalidator);
|
||||
MyLocationViewSettings myLocationViewSettings = new MyLocationViewSettings(myLocationView, projection,
|
||||
focalPointInvalidator);
|
||||
MarkerViewManager markerViewManager = new MarkerViewManager(markerViewContainer);
|
||||
AnnotationManager annotationManager = new AnnotationManager(nativeMapView, this, markerViewManager);
|
||||
Transform transform = new Transform(nativeMapView, annotationManager.getMarkerViewManager(), trackingSettings);
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, trackingSettings, myLocationViewSettings,
|
||||
projection, registerTouchListener, annotationManager);
|
||||
|
||||
// active user input
|
||||
mapGestureDetector = new MapGestureDetector(context, mapboxMap.getTransform(), projection, uiSettings,
|
||||
trackingSettings, annotationManager);
|
||||
mapKeyListener = new MapKeyListener(mapboxMap.getTransform(), trackingSettings, uiSettings);
|
||||
|
||||
// attach widgets to MapboxMap
|
||||
compassView.setMapboxMap(mapboxMap);
|
||||
myLocationView.setMapboxMap(mapboxMap);
|
||||
|
||||
// Ensure this view is interactable
|
||||
setClickable(true);
|
||||
setLongClickable(true);
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
requestDisallowInterceptTouchEvent(true);
|
||||
requestFocus();
|
||||
|
||||
// Connectivity
|
||||
onConnectivityChanged(isConnected());
|
||||
|
||||
// configure the zoom button controller
|
||||
zoomButtonsController = new ZoomButtonsController(MapView.this);
|
||||
zoomButtonsController.setZoomSpeed(ANIMATION_DURATION);
|
||||
zoomButtonsController.setOnZoomListener(new OnZoomListener(mapboxMap));
|
||||
|
||||
mapboxMap.initialise(context, options);
|
||||
|
||||
// Shows the zoom controls
|
||||
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
|
||||
uiSettings.setZoomControlsEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -261,155 +194,28 @@ 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)}.
|
||||
* </p>
|
||||
* You must set a valid access token with {@link MapView#setAccessToken(String)} before you this method
|
||||
* You must set a valid access token with {@link Mapbox#getInstance(Context, String)}) before you call this method
|
||||
* or an exception will be thrown.
|
||||
*
|
||||
* @param savedInstanceState Pass in the parent's savedInstanceState.
|
||||
* @see MapView#setAccessToken(String)
|
||||
* @see Mapbox#getInstance(Context, String)
|
||||
*/
|
||||
@UiThread
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
// TODO distill into singular purpose methods/classes
|
||||
String accessToken = mapboxMap.getAccessToken();
|
||||
if (TextUtils.isEmpty(accessToken)) {
|
||||
accessToken = MapboxAccountManager.getInstance().getAccessToken();
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
} else {
|
||||
// user provided access token through xml attributes, need to start MapboxAccountManager
|
||||
MapboxAccountManager.start(getContext(), accessToken);
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
}
|
||||
Mapbox.validateAccessToken();
|
||||
nativeMapView.setAccessToken(Mapbox.getAccessToken());
|
||||
|
||||
// Force a check for an access token
|
||||
MapboxAccountManager.validateAccessToken(accessToken);
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.getBoolean(STATE_HAS_SAVED_STATE)) {
|
||||
|
||||
// Get previous camera position
|
||||
CameraPosition cameraPosition = savedInstanceState.getParcelable(STATE_CAMERA_POSITION);
|
||||
if (cameraPosition != null) {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(cameraPosition).build()));
|
||||
}
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setZoomGesturesEnabled(savedInstanceState.getBoolean(STATE_ZOOM_ENABLED));
|
||||
uiSettings.setZoomGestureChangeAllowed(savedInstanceState.getBoolean(STATE_ZOOM_ENABLED_CHANGE));
|
||||
uiSettings.setScrollGesturesEnabled(savedInstanceState.getBoolean(STATE_SCROLL_ENABLED));
|
||||
uiSettings.setScrollGestureChangeAllowed(savedInstanceState.getBoolean(STATE_SCROLL_ENABLED_CHANGE));
|
||||
uiSettings.setRotateGesturesEnabled(savedInstanceState.getBoolean(STATE_ROTATE_ENABLED));
|
||||
uiSettings.setRotateGestureChangeAllowed(savedInstanceState.getBoolean(STATE_ROTATE_ENABLED_CHANGE));
|
||||
uiSettings.setTiltGesturesEnabled(savedInstanceState.getBoolean(STATE_TILT_ENABLED));
|
||||
uiSettings.setTiltGestureChangeAllowed(savedInstanceState.getBoolean(STATE_TILT_ENABLED_CHANGE));
|
||||
uiSettings.setZoomControlsEnabled(savedInstanceState.getBoolean(STATE_ZOOM_CONTROLS_ENABLED));
|
||||
|
||||
// Compass
|
||||
uiSettings.setCompassEnabled(savedInstanceState.getBoolean(STATE_COMPASS_ENABLED));
|
||||
uiSettings.setCompassGravity(savedInstanceState.getInt(STATE_COMPASS_GRAVITY));
|
||||
uiSettings.setCompassMargins(savedInstanceState.getInt(STATE_COMPASS_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(STATE_COMPASS_MARGIN_TOP),
|
||||
savedInstanceState.getInt(STATE_COMPASS_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(STATE_COMPASS_MARGIN_BOTTOM));
|
||||
uiSettings.setCompassFadeFacingNorth(savedInstanceState.getBoolean(STATE_COMPASS_FADE_WHEN_FACING_NORTH));
|
||||
|
||||
// Logo
|
||||
uiSettings.setLogoEnabled(savedInstanceState.getBoolean(STATE_LOGO_ENABLED));
|
||||
uiSettings.setLogoGravity(savedInstanceState.getInt(STATE_LOGO_GRAVITY));
|
||||
uiSettings.setLogoMargins(savedInstanceState.getInt(STATE_LOGO_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(STATE_LOGO_MARGIN_TOP),
|
||||
savedInstanceState.getInt(STATE_LOGO_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(STATE_LOGO_MARGIN_BOTTOM));
|
||||
|
||||
// Attribution
|
||||
uiSettings.setAttributionEnabled(savedInstanceState.getBoolean(STATE_ATTRIBUTION_ENABLED));
|
||||
uiSettings.setAttributionGravity(savedInstanceState.getInt(STATE_ATTRIBUTION_GRAVITY));
|
||||
uiSettings.setAttributionMargins(savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_TOP),
|
||||
savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(STATE_ATTRIBUTION_MARGIN_BOTTOM));
|
||||
|
||||
mapboxMap.setDebugActive(savedInstanceState.getBoolean(STATE_DEBUG_ACTIVE));
|
||||
|
||||
String styleUrl = savedInstanceState.getString(STATE_STYLE_URL);
|
||||
if (!TextUtils.isEmpty(styleUrl)) {
|
||||
nativeMapView.setStyleUrl(savedInstanceState.getString(STATE_STYLE_URL));
|
||||
}
|
||||
|
||||
// User location
|
||||
try {
|
||||
mapboxMap.setMyLocationEnabled(savedInstanceState.getBoolean(STATE_MY_LOCATION_ENABLED));
|
||||
} catch (SecurityException ignore) {
|
||||
// User did not accept location permissions
|
||||
}
|
||||
|
||||
TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
|
||||
//noinspection ResourceType
|
||||
trackingSettings.setMyLocationTrackingMode(
|
||||
savedInstanceState.getInt(STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
|
||||
//noinspection ResourceType
|
||||
trackingSettings.setMyBearingTrackingMode(
|
||||
savedInstanceState.getInt(STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
|
||||
trackingSettings.setDismissLocationTrackingOnGesture(
|
||||
savedInstanceState.getBoolean(STATE_MY_LOCATION_TRACKING_DISMISS, true));
|
||||
trackingSettings.setDismissBearingTrackingOnGesture(
|
||||
savedInstanceState.getBoolean(STATE_MY_BEARING_TRACKING_DISMISS, true));
|
||||
} else if (savedInstanceState == null) {
|
||||
// Start Telemetry (authorization determined in initial MapboxEventManager constructor)
|
||||
Timber.i("MapView start Telemetry...");
|
||||
MapboxEventManager eventManager = MapboxEventManager.getMapboxEventManager();
|
||||
eventManager.initialize(getContext(), getAccessToken());
|
||||
if (savedInstanceState == null) {
|
||||
MapboxEvent.trackMapLoadEvent();
|
||||
} else if (savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) {
|
||||
mapboxMap.onRestoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
// Initialize EGL
|
||||
nativeMapView.initializeDisplay();
|
||||
nativeMapView.initializeContext();
|
||||
|
||||
// Add annotation deselection listener
|
||||
addOnMapChangedListener(new OnMapChangedListener() {
|
||||
@Override
|
||||
public void onMapChanged(@MapChange int change) {
|
||||
|
||||
// TODO extract logic into separate OnMapReady and Update Component
|
||||
if (change == DID_FINISH_LOADING_STYLE && initialLoad) {
|
||||
initialLoad = false;
|
||||
mapboxMap.getAnnotationManager().reloadMarkers();
|
||||
mapboxMap.getAnnotationManager().adjustTopOffsetPixels(mapboxMap);
|
||||
|
||||
// Notify listeners the map is ready
|
||||
if (onMapReadyCallbackList.size() > 0) {
|
||||
Iterator<OnMapReadyCallback> iterator = onMapReadyCallbackList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
OnMapReadyCallback callback = iterator.next();
|
||||
callback.onMapReady(mapboxMap);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// invalidate camera to update overlain views with correct tilt value
|
||||
mapboxMap.invalidateCameraPosition();
|
||||
|
||||
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
|
||||
mapboxMap.getMarkerViewManager().scheduleViewMarkerInvalidation();
|
||||
|
||||
compassView.update(mapboxMap.getTransform().getBearing());
|
||||
myLocationView.update();
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
|
||||
for (InfoWindow infoWindow : mapboxMap.getInfoWindows()) {
|
||||
infoWindow.update();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Fire MapLoad
|
||||
if (savedInstanceState == null) {
|
||||
Hashtable<String, Object> evt = new Hashtable<>();
|
||||
evt.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_MAP_LOAD);
|
||||
evt.put(MapboxEvent.ATTRIBUTE_CREATED, MapboxEventManager.generateCreateDate());
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
addOnMapChangedListener(mapCallback = new MapCallback(mapboxMap));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,55 +227,8 @@ public class MapView extends FrameLayout {
|
||||
|
||||
@UiThread
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putBoolean(STATE_HAS_SAVED_STATE, true);
|
||||
outState.putParcelable(STATE_CAMERA_POSITION, mapboxMap.getCameraPosition());
|
||||
outState.putBoolean(STATE_DEBUG_ACTIVE, mapboxMap.isDebugActive());
|
||||
outState.putString(STATE_STYLE_URL, nativeMapView.getStyleUrl());
|
||||
outState.putBoolean(STATE_MY_LOCATION_ENABLED, mapboxMap.isMyLocationEnabled());
|
||||
|
||||
// TrackingSettings
|
||||
TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
|
||||
outState.putInt(STATE_MY_LOCATION_TRACKING_MODE, trackingSettings.getMyLocationTrackingMode());
|
||||
outState.putInt(STATE_MY_BEARING_TRACKING_MODE, trackingSettings.getMyBearingTrackingMode());
|
||||
outState.putBoolean(STATE_MY_LOCATION_TRACKING_DISMISS, trackingSettings.isDismissLocationTrackingOnGesture());
|
||||
outState.putBoolean(STATE_MY_BEARING_TRACKING_DISMISS, trackingSettings.isDismissBearingTrackingOnGesture());
|
||||
|
||||
// UiSettings
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
outState.putBoolean(STATE_ZOOM_ENABLED, uiSettings.isZoomGesturesEnabled());
|
||||
outState.putBoolean(STATE_ZOOM_ENABLED_CHANGE, uiSettings.isZoomGestureChangeAllowed());
|
||||
outState.putBoolean(STATE_SCROLL_ENABLED, uiSettings.isScrollGesturesEnabled());
|
||||
outState.putBoolean(STATE_SCROLL_ENABLED_CHANGE, uiSettings.isScrollGestureChangeAllowed());
|
||||
outState.putBoolean(STATE_ROTATE_ENABLED, uiSettings.isRotateGesturesEnabled());
|
||||
outState.putBoolean(STATE_ROTATE_ENABLED_CHANGE, uiSettings.isRotateGestureChangeAllowed());
|
||||
outState.putBoolean(STATE_TILT_ENABLED, uiSettings.isTiltGesturesEnabled());
|
||||
outState.putBoolean(STATE_TILT_ENABLED_CHANGE, uiSettings.isTiltGestureChangeAllowed());
|
||||
outState.putBoolean(STATE_ZOOM_CONTROLS_ENABLED, uiSettings.isZoomControlsEnabled());
|
||||
|
||||
// UiSettings - Compass
|
||||
outState.putBoolean(STATE_COMPASS_ENABLED, uiSettings.isCompassEnabled());
|
||||
outState.putInt(STATE_COMPASS_GRAVITY, uiSettings.getCompassGravity());
|
||||
outState.putInt(STATE_COMPASS_MARGIN_LEFT, uiSettings.getCompassMarginLeft());
|
||||
outState.putInt(STATE_COMPASS_MARGIN_TOP, uiSettings.getCompassMarginTop());
|
||||
outState.putInt(STATE_COMPASS_MARGIN_BOTTOM, uiSettings.getCompassMarginBottom());
|
||||
outState.putInt(STATE_COMPASS_MARGIN_RIGHT, uiSettings.getCompassMarginRight());
|
||||
outState.putBoolean(STATE_COMPASS_FADE_WHEN_FACING_NORTH, uiSettings.isCompassFadeWhenFacingNorth());
|
||||
|
||||
// UiSettings - Logo
|
||||
outState.putInt(STATE_LOGO_GRAVITY, uiSettings.getLogoGravity());
|
||||
outState.putInt(STATE_LOGO_MARGIN_LEFT, uiSettings.getLogoMarginLeft());
|
||||
outState.putInt(STATE_LOGO_MARGIN_TOP, uiSettings.getLogoMarginTop());
|
||||
outState.putInt(STATE_LOGO_MARGIN_RIGHT, uiSettings.getLogoMarginRight());
|
||||
outState.putInt(STATE_LOGO_MARGIN_BOTTOM, uiSettings.getLogoMarginBottom());
|
||||
outState.putBoolean(STATE_LOGO_ENABLED, uiSettings.isLogoEnabled());
|
||||
|
||||
// UiSettings - Attribution
|
||||
outState.putInt(STATE_ATTRIBUTION_GRAVITY, uiSettings.getAttributionGravity());
|
||||
outState.putInt(STATE_ATTRIBUTION_MARGIN_LEFT, uiSettings.getAttributionMarginLeft());
|
||||
outState.putInt(STATE_ATTRIBUTION_MARGIN_TOP, uiSettings.getAttributionMarginTop());
|
||||
outState.putInt(STATE_ATTRIBUTION_MARGIN_RIGHT, uiSettings.getAttributionMarginRight());
|
||||
outState.putInt(STATE_ATTRIBUTION_MARGIN_BOTTOM, uiSettings.getAttributionMarginBottom());
|
||||
outState.putBoolean(STATE_ATTRIBUTION_ENABLED, uiSettings.isAttributionEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true);
|
||||
mapboxMap.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,18 +237,8 @@ public class MapView extends FrameLayout {
|
||||
@UiThread
|
||||
public void onStart() {
|
||||
onStartCalled = true;
|
||||
|
||||
// Register for connectivity changes
|
||||
connectivityReceiver = new ConnectivityReceiver();
|
||||
getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
nativeMapView.update();
|
||||
myLocationView.onStart();
|
||||
|
||||
if (TextUtils.isEmpty(nativeMapView.getStyleUrl())) {
|
||||
// if user hasn't loaded a Style yet, load default for them instead
|
||||
nativeMapView.setStyleUrl(Style.MAPBOX_STREETS);
|
||||
}
|
||||
mapboxMap.onStart();
|
||||
registerConnectivityReceiver();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -518,14 +267,8 @@ public class MapView extends FrameLayout {
|
||||
@UiThread
|
||||
public void onStop() {
|
||||
onStopCalled = true;
|
||||
|
||||
// Unregister for connectivity changes
|
||||
if (connectivityReceiver != null) {
|
||||
getContext().unregisterReceiver(connectivityReceiver);
|
||||
connectivityReceiver = null;
|
||||
}
|
||||
|
||||
myLocationView.onStop();
|
||||
mapboxMap.onStop();
|
||||
unregisterConnectivityReceiver();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,12 +290,22 @@ public class MapView extends FrameLayout {
|
||||
nativeMapView = null;
|
||||
}
|
||||
|
||||
private void registerConnectivityReceiver() {
|
||||
getContext().registerReceiver(connectivityReceiver = new ConnectivityReceiver(),
|
||||
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
}
|
||||
|
||||
private void unregisterConnectivityReceiver() {
|
||||
if (connectivityReceiver != null) {
|
||||
getContext().unregisterReceiver(connectivityReceiver);
|
||||
connectivityReceiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (mapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
zoomButtonsController.setVisible(true);
|
||||
}
|
||||
mapZoomButtonController.setVisible(true);
|
||||
}
|
||||
return mapGestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
|
||||
}
|
||||
@@ -587,17 +340,11 @@ public class MapView extends FrameLayout {
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_HOVER_ENTER:
|
||||
case MotionEvent.ACTION_HOVER_MOVE:
|
||||
// Show the zoom controls
|
||||
if (mapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
zoomButtonsController.setVisible(true);
|
||||
}
|
||||
mapZoomButtonController.setVisible(true);
|
||||
return true;
|
||||
|
||||
case MotionEvent.ACTION_HOVER_EXIT:
|
||||
// Hide the zoom controls
|
||||
if (mapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
zoomButtonsController.setVisible(false);
|
||||
}
|
||||
mapZoomButtonController.setVisible(false);
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -618,15 +365,15 @@ public class MapView extends FrameLayout {
|
||||
// Called via JNI from NativeMapView
|
||||
// Forward to any listener
|
||||
protected void onFpsChanged(final double fps) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapboxMap.OnFpsChangedListener listener = mapboxMap.getOnFpsChangedListener();
|
||||
if (listener != null) {
|
||||
final MapboxMap.OnFpsChangedListener listener = mapboxMap.getOnFpsChangedListener();
|
||||
if (listener != null) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
listener.onFpsChanged(fps);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -664,64 +411,13 @@ public class MapView extends FrameLayout {
|
||||
|
||||
// stopgap for https://github.com/mapbox/mapbox-gl-native/issues/6242
|
||||
if (TextUtils.isEmpty(nativeMapView.getAccessToken())) {
|
||||
setAccessToken(MapboxAccountManager.getInstance().getAccessToken());
|
||||
Mapbox.validateAccessToken();
|
||||
nativeMapView.setAccessToken(Mapbox.getAccessToken());
|
||||
}
|
||||
|
||||
nativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#start(String)
|
||||
* </p>
|
||||
* <p>
|
||||
* Sets the current Mapbox access token used to load map styles and tiles.
|
||||
* </p>
|
||||
* <p>
|
||||
* You must set a valid access token before you call {@link MapView#onCreate(Bundle)}
|
||||
* or an exception will be thrown.
|
||||
* </p>
|
||||
*
|
||||
* @param accessToken Your public Mapbox access token.
|
||||
* @see MapView#onCreate(Bundle)
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@UiThread
|
||||
public void setAccessToken(@NonNull String accessToken) {
|
||||
if (destroyed) {
|
||||
return;
|
||||
}
|
||||
// validateAccessToken does the null check
|
||||
if (!TextUtils.isEmpty(accessToken)) {
|
||||
accessToken = accessToken.trim();
|
||||
}
|
||||
MapboxAccountManager.validateAccessToken(accessToken);
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#getAccessToken()
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns the current Mapbox access token used to load map styles and tiles.
|
||||
* </p>
|
||||
*
|
||||
* @return The current Mapbox access token.
|
||||
* @deprecated As of release 4.1.0, replaced by {@link MapboxAccountManager#getAccessToken()}
|
||||
*/
|
||||
@Deprecated
|
||||
@UiThread
|
||||
@Nullable
|
||||
public String getAccessToken() {
|
||||
if (destroyed) {
|
||||
return "";
|
||||
}
|
||||
return nativeMapView.getAccessToken();
|
||||
}
|
||||
|
||||
//
|
||||
// Rendering
|
||||
//
|
||||
@@ -835,14 +531,7 @@ public class MapView extends FrameLayout {
|
||||
if (destroyed) {
|
||||
return;
|
||||
}
|
||||
// TODO move to transform. java
|
||||
compassView.update(mapboxMap.getTransform().getBearing());
|
||||
myLocationView.update();
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
|
||||
for (InfoWindow infoWindow : mapboxMap.getInfoWindows()) {
|
||||
infoWindow.update();
|
||||
}
|
||||
mapboxMap.onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -855,18 +544,7 @@ public class MapView extends FrameLayout {
|
||||
@CallSuper
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
// Required by ZoomButtonController (from Android SDK documentation)
|
||||
if (mapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
zoomButtonsController.setVisible(false);
|
||||
}
|
||||
|
||||
// make sure we don't leak location listener
|
||||
if (myLocationListener != null) {
|
||||
// cleanup to prevent memory leak
|
||||
LocationServices services = LocationServices.getLocationServices(getContext());
|
||||
services.removeLocationListener(myLocationListener);
|
||||
myLocationListener = null;
|
||||
}
|
||||
mapZoomButtonController.setVisible(false);
|
||||
}
|
||||
|
||||
// Called when view is hidden and shown
|
||||
@@ -875,10 +553,7 @@ public class MapView extends FrameLayout {
|
||||
if (isInEditMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mapboxMap != null && mapboxMap.getUiSettings().isZoomControlsEnabled()) {
|
||||
zoomButtonsController.setVisible(visibility == View.VISIBLE);
|
||||
}
|
||||
mapZoomButtonController.setVisible(visibility == View.VISIBLE);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -892,26 +567,19 @@ public class MapView extends FrameLayout {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!destroyed && intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
||||
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
|
||||
onConnectivityChanged(!noConnectivity);
|
||||
nativeMapView.setReachability(!intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called when MapView is being created
|
||||
private boolean isConnected() {
|
||||
Context appContext = getContext().getApplicationContext();
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager)
|
||||
appContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
|
||||
return (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
|
||||
}
|
||||
|
||||
// Called when our Internet connectivity has changed
|
||||
private void onConnectivityChanged(boolean isConnected) {
|
||||
nativeMapView.setReachability(isConnected);
|
||||
}
|
||||
|
||||
//
|
||||
// Map events
|
||||
//
|
||||
@@ -958,11 +626,11 @@ public class MapView extends FrameLayout {
|
||||
*/
|
||||
@UiThread
|
||||
public void getMapAsync(final OnMapReadyCallback callback) {
|
||||
if (!initialLoad && callback != null) {
|
||||
if (!mapCallback.isInitialLoad() && callback != null) {
|
||||
callback.onMapReady(mapboxMap);
|
||||
} else {
|
||||
if (callback != null) {
|
||||
onMapReadyCallbackList.add(callback);
|
||||
mapCallback.addOnMapReadyCallback(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1026,20 +694,21 @@ public class MapView extends FrameLayout {
|
||||
|
||||
private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2;
|
||||
private static final int ATTRIBUTION_INDEX_TELEMETRY_SETTINGS = 3;
|
||||
private MapView mapView;
|
||||
private Context context;
|
||||
private Transform transform;
|
||||
|
||||
AttributionOnClickListener(MapView mapView) {
|
||||
super();
|
||||
this.mapView = mapView;
|
||||
public AttributionOnClickListener(Context context, Transform transform) {
|
||||
this.context = context;
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
// Called when someone presses the attribution icon
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mapView.getContext(), R.style.mapbox_AlertDialogStyle);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.mapbox_AlertDialogStyle);
|
||||
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
|
||||
String[] items = mapView.getContext().getResources().getStringArray(R.array.mapbox_attribution_names);
|
||||
builder.setAdapter(new ArrayAdapter<>(mapView.getContext(), R.layout.mapbox_attribution_list_item, items), this);
|
||||
String[] items = context.getResources().getStringArray(R.array.mapbox_attribution_names);
|
||||
builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, items), this);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@@ -1081,7 +750,7 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
String url = context.getResources().getStringArray(R.array.mapbox_attribution_links)[which];
|
||||
if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) {
|
||||
CameraPosition cameraPosition = mapView.getMapboxMap().getCameraPosition();
|
||||
CameraPosition cameraPosition = transform.getCameraPosition();
|
||||
if (cameraPosition != null) {
|
||||
url = String.format(url, cameraPosition.target.getLongitude(),
|
||||
cameraPosition.target.getLatitude(), (int) cameraPosition.zoom);
|
||||
@@ -1277,7 +946,6 @@ public class MapView extends FrameLayout {
|
||||
*/
|
||||
public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13;
|
||||
|
||||
|
||||
/**
|
||||
* This {@link MapChange} is triggered when a style has finished loading.
|
||||
* <p>
|
||||
@@ -1289,7 +957,6 @@ public class MapView extends FrameLayout {
|
||||
*/
|
||||
public static final int DID_FINISH_LOADING_STYLE = 14;
|
||||
|
||||
|
||||
/**
|
||||
* This {@link MapChange} is triggered when a source attribution changes.
|
||||
* <p>
|
||||
@@ -1332,34 +999,6 @@ public class MapView extends FrameLayout {
|
||||
void onMapChanged(@MapChange int change);
|
||||
}
|
||||
|
||||
// This class handles input events from the zoom control buttons
|
||||
// Zoom controls allow single touch only devices to zoom in and out
|
||||
private class OnZoomListener implements ZoomButtonsController.OnZoomListener {
|
||||
|
||||
private UiSettings uiSettings;
|
||||
private Transform transform;
|
||||
|
||||
OnZoomListener(MapboxMap mapboxMap) {
|
||||
this.uiSettings = mapboxMap.getUiSettings();
|
||||
this.transform = mapboxMap.getTransform();
|
||||
}
|
||||
|
||||
// Not used
|
||||
@Override
|
||||
public void onVisibilityChanged(boolean visible) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// Called when user pushes a zoom button
|
||||
@Override
|
||||
public void onZoom(boolean zoomIn) {
|
||||
if (!uiSettings.isZoomGesturesEnabled()) {
|
||||
return;
|
||||
}
|
||||
transform.zoom(zoomIn);
|
||||
}
|
||||
}
|
||||
|
||||
private class FocalPointInvalidator implements FocalPointChangeListener {
|
||||
|
||||
@Override
|
||||
@@ -1391,7 +1030,46 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
NativeMapView getNativeMapView() {
|
||||
return nativeMapView;
|
||||
private static class MapCallback implements OnMapChangedListener {
|
||||
|
||||
private final MapboxMap mapboxMap;
|
||||
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
|
||||
private boolean initialLoad = true;
|
||||
|
||||
MapCallback(MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapChanged(@MapChange int change) {
|
||||
if (change == DID_FINISH_LOADING_STYLE && initialLoad) {
|
||||
initialLoad = false;
|
||||
mapboxMap.onPreMapReady();
|
||||
onMapReady();
|
||||
mapboxMap.onPostMapReady();
|
||||
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
|
||||
mapboxMap.onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void onMapReady() {
|
||||
if (onMapReadyCallbackList.size() > 0) {
|
||||
// Notify listeners, clear when done
|
||||
Iterator<OnMapReadyCallback> iterator = onMapReadyCallbackList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
OnMapReadyCallback callback = iterator.next();
|
||||
callback.onMapReady(mapboxMap);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInitialLoad() {
|
||||
return initialLoad;
|
||||
}
|
||||
|
||||
void addOnMapReadyCallback(OnMapReadyCallback callback) {
|
||||
onMapReadyCallbackList.add(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
|
||||
/**
|
||||
* The MapZoomButtonController is a ui interface element shown on top of the map.
|
||||
* <p>
|
||||
* Allows single touch only devices to zoom in and out.
|
||||
* </p>
|
||||
*/
|
||||
final class MapZoomButtonController extends ZoomButtonsController {
|
||||
|
||||
private UiSettings uiSettings;
|
||||
|
||||
MapZoomButtonController(@NonNull View ownerView, @NonNull UiSettings uiSettings, @NonNull Transform transform) {
|
||||
super(ownerView);
|
||||
this.uiSettings = uiSettings;
|
||||
setZoomSpeed(MapboxConstants.ANIMATION_DURATION);
|
||||
setOnZoomListener(new OnZoomListener(uiSettings, transform));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
if (uiSettings.isZoomControlsEnabled()) {
|
||||
super.setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom controls allow single touch only devices to zoom in and out
|
||||
private static class OnZoomListener implements ZoomButtonsController.OnZoomListener {
|
||||
|
||||
private final UiSettings uiSettings;
|
||||
private final Transform transform;
|
||||
|
||||
OnZoomListener(UiSettings uiSettings, Transform transform) {
|
||||
this.uiSettings = uiSettings;
|
||||
this.transform = transform;
|
||||
}
|
||||
|
||||
// Not used
|
||||
@Override
|
||||
public void onVisibilityChanged(boolean visible) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// Called when user pushes a zoom button
|
||||
@Override
|
||||
public void onZoom(boolean zoomIn) {
|
||||
if (!uiSettings.isZoomGesturesEnabled()) {
|
||||
return;
|
||||
}
|
||||
transform.zoom(zoomIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -15,11 +16,10 @@ import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerView;
|
||||
@@ -60,12 +60,14 @@ import timber.log.Timber;
|
||||
public final class MapboxMap {
|
||||
|
||||
private final NativeMapView nativeMapView;
|
||||
|
||||
private final UiSettings uiSettings;
|
||||
private final TrackingSettings trackingSettings;
|
||||
private final Projection projection;
|
||||
private final Transform transform;
|
||||
private final AnnotationManager annotationManager;
|
||||
private final MyLocationViewSettings myLocationViewSettings;
|
||||
|
||||
private final OnRegisterTouchListener onRegisterTouchListener;
|
||||
|
||||
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
|
||||
@@ -87,15 +89,81 @@ public final class MapboxMap {
|
||||
transform.initialise(this, options);
|
||||
uiSettings.initialise(context, options);
|
||||
myLocationViewSettings.initialise(options);
|
||||
setMyLocationEnabled(options.getLocationEnabled());
|
||||
trackingSettings.initialise(options);
|
||||
|
||||
// api base url
|
||||
// Map configuration
|
||||
setDebugActive(options.getDebugActive());
|
||||
setApiBaseUrl(options);
|
||||
setAccessToken(options);
|
||||
setStyleUrl(options);
|
||||
}
|
||||
|
||||
void onStart() {
|
||||
nativeMapView.update();
|
||||
trackingSettings.onStart();
|
||||
if (TextUtils.isEmpty(nativeMapView.getStyleUrl())) {
|
||||
// if user hasn't loaded a Style yet
|
||||
nativeMapView.setStyleUrl(Style.MAPBOX_STREETS);
|
||||
}
|
||||
}
|
||||
|
||||
void onStop() {
|
||||
trackingSettings.onStop();
|
||||
}
|
||||
|
||||
void onSaveInstanceState(Bundle outState) {
|
||||
outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, transform.getCameraPosition());
|
||||
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, nativeMapView.getDebug());
|
||||
outState.putString(MapboxConstants.STATE_STYLE_URL, nativeMapView.getStyleUrl());
|
||||
trackingSettings.onSaveInstanceState(outState);
|
||||
uiSettings.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
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);
|
||||
nativeMapView.setDebug(savedInstanceState.getBoolean(MapboxConstants.STATE_DEBUG_ACTIVE));
|
||||
|
||||
final String styleUrl = savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL);
|
||||
if (!TextUtils.isEmpty(styleUrl)) {
|
||||
nativeMapView.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the OnMapReadyCallback is invoked.
|
||||
*/
|
||||
void onPreMapReady() {
|
||||
annotationManager.reloadMarkers();
|
||||
annotationManager.adjustTopOffsetPixels(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the OnMapReadyCallback has finished executing.
|
||||
* <p>
|
||||
* Invalidation of the camera position is required to update the added components in
|
||||
* OnMapReadyCallback with the correct transformation.
|
||||
* </p>
|
||||
*/
|
||||
void onPostMapReady() {
|
||||
invalidateCameraPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user
|
||||
*/
|
||||
void onUpdate() {
|
||||
CameraPosition cameraPosition = transform.getCameraPosition();
|
||||
uiSettings.update(cameraPosition);
|
||||
// FIXME introduce update method with camera position
|
||||
trackingSettings.update();
|
||||
annotationManager.update();
|
||||
}
|
||||
|
||||
// Style
|
||||
|
||||
@Nullable
|
||||
@@ -117,8 +185,8 @@ public final class MapboxMap {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (T) nativeMapView.getLayer(layerId);
|
||||
} catch (ClassCastException classCastException) {
|
||||
Timber.e(String.format("Layer: %s is a different type: %s", layerId, classCastException.getMessage()));
|
||||
} catch (ClassCastException exception) {
|
||||
Timber.e(String.format("Layer: %s is a different type: %s", layerId, exception));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -148,7 +216,7 @@ public final class MapboxMap {
|
||||
* Removes the layer. Any references to the layer become invalid and should not be used anymore
|
||||
*
|
||||
* @param layerId the layer to remove
|
||||
* @throws NoSuchLayerException Thrown when the layer doesn't exist.
|
||||
* @throws NoSuchLayerException the exception thrown when layer with layerId doesn't exist
|
||||
*/
|
||||
@UiThread
|
||||
public void removeLayer(@NonNull String layerId) throws NoSuchLayerException {
|
||||
@@ -159,7 +227,7 @@ public final class MapboxMap {
|
||||
* Removes the layer. The reference is re-usable after this and can be re-added
|
||||
*
|
||||
* @param layer the layer to remove
|
||||
* @throws NoSuchLayerException Thrown when the layer doesn't exist.
|
||||
* @throws NoSuchLayerException the exeption thrown when the layer doesn't exist
|
||||
*/
|
||||
@UiThread
|
||||
public void removeLayer(@NonNull Layer layer) throws NoSuchLayerException {
|
||||
@@ -185,8 +253,8 @@ public final class MapboxMap {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
return (T) nativeMapView.getSource(sourceId);
|
||||
} catch (ClassCastException classCastException) {
|
||||
Timber.e(String.format("Source: %s is a different type: %s", sourceId, classCastException.getMessage()));
|
||||
} catch (ClassCastException exception) {
|
||||
Timber.e(String.format("Source: %s is a different type: %s", sourceId, exception));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +273,7 @@ public final class MapboxMap {
|
||||
* Removes the source. Any references to the source become invalid and should not be used anymore
|
||||
*
|
||||
* @param sourceId the source to remove
|
||||
* @throws NoSuchSourceException Thrown when the source doesn't exist.
|
||||
* @throws NoSuchSourceException the exception thrown when the source with sourceId doesn't exist
|
||||
*/
|
||||
@UiThread
|
||||
public void removeSource(@NonNull String sourceId) throws NoSuchSourceException {
|
||||
@@ -216,7 +284,7 @@ public final class MapboxMap {
|
||||
* Removes the source, preserving the reverence for re-use
|
||||
*
|
||||
* @param source the source to remove
|
||||
* @throws NoSuchSourceException Thrown when the source doesn't exist.
|
||||
* @throws NoSuchSourceException the exception thrown when the source with sourceId doesn't exist
|
||||
*/
|
||||
@UiThread
|
||||
public void removeSource(@NonNull Source source) throws NoSuchSourceException {
|
||||
@@ -285,8 +353,8 @@ 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) {
|
||||
public void setMaxZoomPreference(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) {
|
||||
transform.setMaxZoom(maxZoom);
|
||||
}
|
||||
|
||||
@@ -705,28 +773,6 @@ public final class MapboxMap {
|
||||
// Styling
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified bundled style.
|
||||
* </p>
|
||||
* <p>
|
||||
* This method is asynchronous and will return immediately before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
|
||||
* </p>
|
||||
* 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.
|
||||
*
|
||||
* @param style The bundled style. Accepts one of the values from {@link Style}.
|
||||
* @see Style
|
||||
* @deprecated use {@link #setStyleUrl(String)} instead with versioned url methods from {@link Style}
|
||||
*/
|
||||
@UiThread
|
||||
@Deprecated
|
||||
public void setStyle(@Style.StyleUrl String style) {
|
||||
setStyleUrl(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified URL.
|
||||
@@ -761,6 +807,28 @@ public final class MapboxMap {
|
||||
nativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified bundled style.
|
||||
* </p>
|
||||
* <p>
|
||||
* This method is asynchronous and will return immediately before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
|
||||
* </p>
|
||||
* 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.
|
||||
*
|
||||
* @param style The bundled style. Accepts one of the values from {@link Style}.
|
||||
* @see Style
|
||||
* @deprecated use {@link #setStyleUrl(String)} instead with versioned url methods from {@link Style}
|
||||
*/
|
||||
@UiThread
|
||||
@Deprecated
|
||||
public void setStyle(@Style.StyleUrl String style) {
|
||||
setStyleUrl(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a new map style from MapboxMapOptions if available.
|
||||
*
|
||||
@@ -769,6 +837,11 @@ public final class MapboxMap {
|
||||
private void setStyleUrl(@NonNull MapboxMapOptions options) {
|
||||
String style = options.getStyle();
|
||||
if (!TextUtils.isEmpty(style)) {
|
||||
// stopgap for https://github.com/mapbox/mapbox-gl-native/issues/6242
|
||||
if (TextUtils.isEmpty(nativeMapView.getAccessToken())) {
|
||||
Mapbox.validateAccessToken();
|
||||
nativeMapView.setAccessToken(Mapbox.getAccessToken());
|
||||
}
|
||||
setStyleUrl(style);
|
||||
}
|
||||
}
|
||||
@@ -787,56 +860,6 @@ public final class MapboxMap {
|
||||
return nativeMapView.getStyleUrl();
|
||||
}
|
||||
|
||||
//
|
||||
// Access token
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#getAccessToken()
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns the current Mapbox access token used to load map styles and tiles.
|
||||
* </p>
|
||||
*
|
||||
* @return The current Mapbox access token.
|
||||
* @deprecated As of release 4.1.0, replaced by {@link MapboxAccountManager#getAccessToken()}
|
||||
*/
|
||||
@Deprecated
|
||||
@UiThread
|
||||
@Nullable
|
||||
public String getAccessToken() {
|
||||
return nativeMapView.getAccessToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#start(String)
|
||||
* </p>
|
||||
* <p>
|
||||
* Sets the current Mapbox access token used to load map styles and tiles.
|
||||
* </p>
|
||||
*
|
||||
* @param accessToken Your public Mapbox access token.
|
||||
* @see MapView#setAccessToken(String)
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
@UiThread
|
||||
public void setAccessToken(@NonNull String accessToken) {
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
}
|
||||
|
||||
private void setAccessToken(@NonNull MapboxMapOptions options) {
|
||||
String accessToken = options.getAccessToken();
|
||||
if (!TextUtils.isEmpty(accessToken)) {
|
||||
nativeMapView.setAccessToken(accessToken);
|
||||
} else {
|
||||
nativeMapView.setAccessToken(MapboxAccountManager.getInstance().getAccessToken());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Annotations
|
||||
//
|
||||
@@ -908,6 +931,9 @@ public final class MapboxMap {
|
||||
return annotationManager.addMarker(markerOptions, this, onMarkerViewAddedListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME javadoc
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public List<MarkerView> addMarkerViews(@NonNull List<? extends
|
||||
@@ -915,6 +941,9 @@ public final class MapboxMap {
|
||||
return annotationManager.addMarkerViews(markerViewOptions, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME javadoc
|
||||
*/
|
||||
@UiThread
|
||||
@NonNull
|
||||
public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect) {
|
||||
@@ -1276,20 +1305,6 @@ public final class MapboxMap {
|
||||
return annotationManager.getInfoWindowManager().isAllowConcurrentMultipleOpenInfoWindows();
|
||||
}
|
||||
|
||||
// Internal API
|
||||
List<InfoWindow> getInfoWindows() {
|
||||
return annotationManager.getInfoWindowManager().getInfoWindows();
|
||||
}
|
||||
|
||||
AnnotationManager getAnnotationManager() {
|
||||
return annotationManager;
|
||||
}
|
||||
|
||||
Transform getTransform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Padding
|
||||
//
|
||||
@@ -1409,7 +1424,7 @@ public final class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
public void setOnInfoWindowClickListener(@Nullable OnInfoWindowClickListener listener) {
|
||||
getAnnotationManager().getInfoWindowManager().setOnInfoWindowClickListener(listener);
|
||||
annotationManager.getInfoWindowManager().setOnInfoWindowClickListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1419,7 +1434,7 @@ public final class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
public OnInfoWindowClickListener getOnInfoWindowClickListener() {
|
||||
return getAnnotationManager().getInfoWindowManager().getOnInfoWindowClickListener();
|
||||
return annotationManager.getInfoWindowManager().getOnInfoWindowClickListener();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1431,7 +1446,7 @@ public final class MapboxMap {
|
||||
@UiThread
|
||||
public void setOnInfoWindowLongClickListener(@Nullable OnInfoWindowLongClickListener
|
||||
listener) {
|
||||
getAnnotationManager().getInfoWindowManager().setOnInfoWindowLongClickListener(listener);
|
||||
annotationManager.getInfoWindowManager().setOnInfoWindowLongClickListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1440,11 +1455,11 @@ public final class MapboxMap {
|
||||
* @return Current active InfoWindow long Click Listener
|
||||
*/
|
||||
public OnInfoWindowLongClickListener getOnInfoWindowLongClickListener() {
|
||||
return getAnnotationManager().getInfoWindowManager().getOnInfoWindowLongClickListener();
|
||||
return annotationManager.getInfoWindowManager().getOnInfoWindowLongClickListener();
|
||||
}
|
||||
|
||||
public void setOnInfoWindowCloseListener(@Nullable OnInfoWindowCloseListener listener) {
|
||||
getAnnotationManager().getInfoWindowManager().setOnInfoWindowCloseListener(listener);
|
||||
annotationManager.getInfoWindowManager().setOnInfoWindowCloseListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1454,7 +1469,7 @@ public final class MapboxMap {
|
||||
*/
|
||||
@UiThread
|
||||
public OnInfoWindowCloseListener getOnInfoWindowCloseListener() {
|
||||
return getAnnotationManager().getInfoWindowManager().getOnInfoWindowCloseListener();
|
||||
return annotationManager.getInfoWindowManager().getOnInfoWindowCloseListener();
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1472,13 +1487,13 @@ public final class MapboxMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Enables or disables the my-location layer.
|
||||
* While enabled, the my-location layer continuously draws an indication of a user's current
|
||||
* location and bearing.
|
||||
* <p>
|
||||
* In order to use the my-location layer feature you need to request permission for either
|
||||
* {@code ACCESS_COARSE_LOCATION} or {@code ACCESS_FINE_LOCATION}.
|
||||
* </p>
|
||||
* In order to use the my-location layer feature you need to request permission for either
|
||||
* android.Manifest.permission#ACCESS_COARSE_LOCATION or android.Manifest.permission#ACCESS_FINE_LOCATION.
|
||||
*
|
||||
* @param enabled True to enable; false to disable.
|
||||
*/
|
||||
@@ -1968,4 +1983,11 @@ public final class MapboxMap {
|
||||
*/
|
||||
void onSnapshotReady(Bitmap snapshot);
|
||||
}
|
||||
|
||||
//
|
||||
// Used for instrumentation testing
|
||||
//
|
||||
Transform getTransform() {
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,6 @@ public class MapboxMapOptions implements Parcelable {
|
||||
private boolean textureMode;
|
||||
|
||||
private String style;
|
||||
@Deprecated
|
||||
private String accessToken;
|
||||
|
||||
/**
|
||||
* Creates a new MapboxMapOptions object.
|
||||
@@ -143,7 +141,6 @@ public class MapboxMapOptions implements Parcelable {
|
||||
myLocationAccuracyTintColor = in.readInt();
|
||||
|
||||
style = in.readString();
|
||||
accessToken = in.readString();
|
||||
apiBaseUrl = in.readString();
|
||||
textureMode = in.readByte() != 0;
|
||||
}
|
||||
@@ -170,80 +167,74 @@ public class MapboxMapOptions implements Parcelable {
|
||||
*/
|
||||
public static MapboxMapOptions createFromAttributes(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
|
||||
float screenDensity = context.getResources().getDisplayMetrics().density;
|
||||
float pxlRatio = context.getResources().getDisplayMetrics().density;
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.mapbox_MapView, 0, 0);
|
||||
try {
|
||||
mapboxMapOptions.camera(new CameraPosition.Builder(typedArray).build());
|
||||
|
||||
mapboxMapOptions.accessToken(typedArray.getString(R.styleable.mapbox_MapView_mapbox_accessToken));
|
||||
mapboxMapOptions.styleUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_styleUrl));
|
||||
mapboxMapOptions.apiBaseUrl(typedArray.getString(R.styleable.mapbox_MapView_mapbox_apiBaseUrl));
|
||||
|
||||
mapboxMapOptions.zoomGesturesEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiZoomGestures, true));
|
||||
mapboxMapOptions.scrollGesturesEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiScrollGestures, true));
|
||||
mapboxMapOptions.rotateGesturesEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiRotateGestures, true));
|
||||
mapboxMapOptions.tiltGesturesEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiTiltGestures, true));
|
||||
mapboxMapOptions.zoomControlsEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiZoomControls, false));
|
||||
mapboxMapOptions.zoomGesturesEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiZoomGestures, true));
|
||||
mapboxMapOptions.scrollGesturesEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiScrollGestures, true));
|
||||
mapboxMapOptions.rotateGesturesEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiRotateGestures, true));
|
||||
mapboxMapOptions.tiltGesturesEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiTiltGestures, true));
|
||||
mapboxMapOptions.zoomControlsEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiZoomControls, false));
|
||||
|
||||
mapboxMapOptions.maxZoomPreference(typedArray.getFloat(
|
||||
R.styleable.mapbox_MapView_mapbox_cameraZoomMax, MapboxConstants.MAXIMUM_ZOOM));
|
||||
mapboxMapOptions.minZoomPreference(typedArray.getFloat(
|
||||
R.styleable.mapbox_MapView_mapbox_cameraZoomMin, MapboxConstants.MINIMUM_ZOOM));
|
||||
mapboxMapOptions.maxZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMax,
|
||||
MapboxConstants.MAXIMUM_ZOOM));
|
||||
mapboxMapOptions.minZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMin,
|
||||
MapboxConstants.MINIMUM_ZOOM));
|
||||
|
||||
mapboxMapOptions.compassEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompass, true));
|
||||
mapboxMapOptions.compassGravity(typedArray.getInt(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassGravity, Gravity.TOP | Gravity.END));
|
||||
mapboxMapOptions.compassMargins(
|
||||
new int[] {(int) (typedArray.getDimension(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassMarginLeft, DIMENSION_TEN_DP * screenDensity)),
|
||||
((int) typedArray.getDimension(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassMarginTop, DIMENSION_TEN_DP * screenDensity)),
|
||||
((int) typedArray.getDimension(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassMarginRight, DIMENSION_TEN_DP * screenDensity)),
|
||||
((int) typedArray.getDimension(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassMarginBottom, DIMENSION_TEN_DP * screenDensity))});
|
||||
mapboxMapOptions.compassFadesWhenFacingNorth(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiCompassFadeFacingNorth, true));
|
||||
mapboxMapOptions.compassEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiCompass, true));
|
||||
mapboxMapOptions.compassGravity(typedArray.getInt(R.styleable.mapbox_MapView_mapbox_uiCompassGravity,
|
||||
Gravity.TOP | Gravity.END));
|
||||
mapboxMapOptions.compassMargins(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginLeft,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginTop,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginRight,
|
||||
DIMENSION_TEN_DP * pxlRatio)),
|
||||
((int) typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiCompassMarginBottom,
|
||||
DIMENSION_TEN_DP * pxlRatio))});
|
||||
mapboxMapOptions.compassFadesWhenFacingNorth(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiCompassFadeFacingNorth, true));
|
||||
|
||||
mapboxMapOptions.logoEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiLogo, true));
|
||||
mapboxMapOptions.logoGravity(typedArray.getInt(
|
||||
R.styleable.mapbox_MapView_mapbox_uiLogoGravity, Gravity.BOTTOM | Gravity.START));
|
||||
mapboxMapOptions.logoMargins(new int[] {(int) (
|
||||
typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginLeft, DIMENSION_SIXTEEN_DP
|
||||
* screenDensity)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginTop, DIMENSION_SIXTEEN_DP
|
||||
* screenDensity)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginRight, DIMENSION_SIXTEEN_DP
|
||||
* screenDensity)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginBottom, DIMENSION_SIXTEEN_DP
|
||||
* screenDensity))});
|
||||
mapboxMapOptions.logoGravity(typedArray.getInt(R.styleable.mapbox_MapView_mapbox_uiLogoGravity,
|
||||
Gravity.BOTTOM | Gravity.START));
|
||||
mapboxMapOptions.logoMargins(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginLeft,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginTop,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginRight,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiLogoMarginBottom,
|
||||
DIMENSION_SIXTEEN_DP * pxlRatio))});
|
||||
|
||||
mapboxMapOptions.attributionTintColor(
|
||||
typedArray.getColor(R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1));
|
||||
mapboxMapOptions.attributionEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
|
||||
mapboxMapOptions.attributionGravity(
|
||||
typedArray.getInt(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)
|
||||
* screenDensity),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop, DIMENSION_SEVEN_DP
|
||||
* screenDensity)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight, DIMENSION_SEVEN_DP
|
||||
* screenDensity)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginBottom, DIMENSION_SEVEN_DP
|
||||
* screenDensity))});
|
||||
mapboxMapOptions.attributionTintColor(typedArray.getColor(
|
||||
R.styleable.mapbox_MapView_mapbox_uiAttributionTintColor, -1));
|
||||
mapboxMapOptions.attributionEnabled(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_uiAttribution, true));
|
||||
mapboxMapOptions.attributionGravity(typedArray.getInt(
|
||||
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),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginTop,
|
||||
DIMENSION_SEVEN_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginRight,
|
||||
DIMENSION_SEVEN_DP * pxlRatio)),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_uiAttributionMarginBottom,
|
||||
DIMENSION_SEVEN_DP * pxlRatio))});
|
||||
|
||||
mapboxMapOptions.locationEnabled(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false));
|
||||
mapboxMapOptions.locationEnabled(typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_myLocation, false));
|
||||
mapboxMapOptions.myLocationForegroundTintColor(
|
||||
typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationTintColor,
|
||||
ColorUtils.getPrimaryColor(context)));
|
||||
@@ -270,20 +261,22 @@ public class MapboxMapOptions implements Parcelable {
|
||||
mapboxMapOptions.myLocationForegroundDrawables(foregroundDrawable, foregroundBearingDrawable);
|
||||
mapboxMapOptions.myLocationBackgroundDrawable(backgroundDrawable);
|
||||
mapboxMapOptions.myLocationBackgroundPadding(new int[] {
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginLeft, 0)
|
||||
* screenDensity),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginTop, 0)
|
||||
* screenDensity),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginRight, 0)
|
||||
* screenDensity),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginBottom, 0)
|
||||
* screenDensity)});
|
||||
mapboxMapOptions.myLocationAccuracyAlpha(typedArray.getInt(
|
||||
R.styleable.mapbox_MapView_mapbox_myLocationAccuracyAlpha, 100));
|
||||
mapboxMapOptions.myLocationAccuracyTint(typedArray.getColor(
|
||||
R.styleable.mapbox_MapView_mapbox_myLocationAccuracyTintColor, ColorUtils.getPrimaryColor(context)));
|
||||
mapboxMapOptions.textureMode(typedArray.getBoolean(
|
||||
R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginLeft,
|
||||
0) * pxlRatio),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginTop,
|
||||
0) * pxlRatio),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginRight,
|
||||
0) * pxlRatio),
|
||||
(int) (typedArray.getDimension(R.styleable.mapbox_MapView_mapbox_myLocationBackgroundMarginBottom,
|
||||
0) * pxlRatio)
|
||||
});
|
||||
mapboxMapOptions.myLocationAccuracyAlpha(
|
||||
typedArray.getInt(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyAlpha, 100));
|
||||
mapboxMapOptions.myLocationAccuracyTint(
|
||||
typedArray.getColor(R.styleable.mapbox_MapView_mapbox_myLocationAccuracyTintColor,
|
||||
ColorUtils.getPrimaryColor(context)));
|
||||
mapboxMapOptions.textureMode(
|
||||
typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false));
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
@@ -312,23 +305,6 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#start(String)
|
||||
* </p>
|
||||
* Specifies the accesstoken associated with a map view.
|
||||
*
|
||||
* @param accessToken Token to be used to access the service
|
||||
* @return This
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public MapboxMapOptions accessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the style url associated with a map view.
|
||||
*
|
||||
@@ -778,19 +754,6 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return logoMargins;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DEPRECATED @see MapboxAccountManager#start(String)
|
||||
* </p>
|
||||
* Get the current configured access token for a map view.
|
||||
*
|
||||
* @return Access token to be used.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current configured style url for a map view.
|
||||
*
|
||||
@@ -982,16 +945,15 @@ public class MapboxMapOptions implements Parcelable {
|
||||
return textureMode;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<MapboxMapOptions> CREATOR =
|
||||
new Parcelable.Creator<MapboxMapOptions>() {
|
||||
public MapboxMapOptions createFromParcel(Parcel in) {
|
||||
return new MapboxMapOptions(in);
|
||||
}
|
||||
public static final Parcelable.Creator<MapboxMapOptions> CREATOR = new Parcelable.Creator<MapboxMapOptions>() {
|
||||
public MapboxMapOptions createFromParcel(Parcel in) {
|
||||
return new MapboxMapOptions(in);
|
||||
}
|
||||
|
||||
public MapboxMapOptions[] newArray(int size) {
|
||||
return new MapboxMapOptions[size];
|
||||
}
|
||||
};
|
||||
public MapboxMapOptions[] newArray(int size) {
|
||||
return new MapboxMapOptions[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
@@ -1041,21 +1003,20 @@ public class MapboxMapOptions implements Parcelable {
|
||||
dest.writeInt(myLocationAccuracyTintColor);
|
||||
|
||||
dest.writeString(style);
|
||||
dest.writeString(accessToken);
|
||||
dest.writeString(apiBaseUrl);
|
||||
dest.writeByte((byte) (textureMode ? 1 : 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object) {
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (object == null || getClass() != object.getClass()) {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MapboxMapOptions options = (MapboxMapOptions) object;
|
||||
MapboxMapOptions options = (MapboxMapOptions) o;
|
||||
|
||||
if (debugActive != options.debugActive) {
|
||||
return false;
|
||||
@@ -1156,8 +1117,7 @@ public class MapboxMapOptions implements Parcelable {
|
||||
if (apiBaseUrl != null ? !apiBaseUrl.equals(options.apiBaseUrl) : options.apiBaseUrl != null) {
|
||||
return false;
|
||||
}
|
||||
return accessToken != null ? accessToken.equals(options.accessToken) : options.accessToken == null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1199,7 +1159,6 @@ 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 + (accessToken != null ? accessToken.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,18 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException;
|
||||
|
||||
/**
|
||||
* Support Fragment wrapper around a map view.
|
||||
@@ -81,24 +76,6 @@ public class SupportMapFragment extends Fragment {
|
||||
options = bundle.getParcelable(MapboxConstants.FRAG_ARG_MAPBOXMAPOPTIONS);
|
||||
}
|
||||
|
||||
// Assign an AccessToken if needed
|
||||
if (options == null || options.getAccessToken() == null) {
|
||||
String token = null;
|
||||
if (MapboxAccountManager.getInstance() != null) {
|
||||
token = MapboxAccountManager.getInstance().getAccessToken();
|
||||
} else {
|
||||
token = getToken(inflater.getContext());
|
||||
}
|
||||
if (TextUtils.isEmpty(token)) {
|
||||
throw new InvalidAccessTokenException();
|
||||
}
|
||||
if (options == null) {
|
||||
options = new MapboxMapOptions().accessToken(token);
|
||||
} else {
|
||||
options.accessToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
Drawable foregroundDrawable = options.getMyLocationForegroundDrawable();
|
||||
Drawable foregroundBearingDrawable = options.getMyLocationForegroundBearingDrawable();
|
||||
if (foregroundDrawable == null || foregroundBearingDrawable == null) {
|
||||
@@ -118,39 +95,6 @@ public class SupportMapFragment extends Fragment {
|
||||
return map = new MapView(inflater.getContext(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Returns the Mapbox access token set in the app resources.
|
||||
* </p>
|
||||
* It will first search the application manifest for a {@link MapboxConstants#KEY_META_DATA_MANIFEST}
|
||||
* meta-data value. If not found it will then attempt to load the access token from the
|
||||
* {@code res/raw/token.txt} development file.
|
||||
*
|
||||
* @param context The {@link Context} of the {@link android.app.Activity} or {@link android.app.Fragment}.
|
||||
* @return The Mapbox access token or null if not found.
|
||||
* @see MapboxConstants#KEY_META_DATA_MANIFEST
|
||||
* @deprecated As of release 4.1.0, replaced by
|
||||
* {@link com.mapbox.mapboxsdk.MapboxAccountManager#start(Context, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
private String getToken(@NonNull Context context) {
|
||||
try {
|
||||
// read out AndroidManifest
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(),
|
||||
PackageManager.GET_META_DATA);
|
||||
String token = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
|
||||
if (token == null || token.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return token;
|
||||
} catch (Exception exception) {
|
||||
// use fallback on string resource, used for development
|
||||
int tokenResId = context.getResources().getIdentifier("mapbox_access_token", "string", context.getPackageName());
|
||||
return tokenResId != 0 ? context.getString(tokenResId) : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the fragment view hierarchy is created.
|
||||
*
|
||||
@@ -237,4 +181,4 @@ public class SupportMapFragment extends Fragment {
|
||||
public void getMapAsync(@NonNull final OnMapReadyCallback onMapReadyCallback) {
|
||||
this.onMapReadyCallback = onMapReadyCallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,14 @@ import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.PointF;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
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.LocationListener;
|
||||
@@ -42,6 +44,36 @@ public final class TrackingSettings {
|
||||
this.uiSettings = uiSettings;
|
||||
}
|
||||
|
||||
void initialise(MapboxMapOptions options) {
|
||||
setMyLocationEnabled(options.getLocationEnabled());
|
||||
}
|
||||
|
||||
void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, getMyLocationTrackingMode());
|
||||
outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, getMyBearingTrackingMode());
|
||||
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());
|
||||
}
|
||||
|
||||
void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
try {
|
||||
setMyLocationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED));
|
||||
} catch (SecurityException ignore) {
|
||||
// User did not accept location permissions
|
||||
}
|
||||
//noinspection ResourceType
|
||||
setMyLocationTrackingMode(savedInstanceState.getInt(
|
||||
MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE));
|
||||
//noinspection ResourceType
|
||||
setMyBearingTrackingMode(savedInstanceState.getInt(
|
||||
MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE));
|
||||
setDismissLocationTrackingOnGesture(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
|
||||
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Set the current my location tracking mode.
|
||||
@@ -244,6 +276,9 @@ 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.
|
||||
*
|
||||
* @param translate true if translation
|
||||
* @param rotate true if rotation
|
||||
*/
|
||||
void resetTrackingModesIfRequired(boolean translate, boolean rotate) {
|
||||
// if tracking is on, and we should dismiss tracking with gestures, and this is a scroll action, turn tracking off
|
||||
@@ -283,20 +318,18 @@ public final class TrackingSettings {
|
||||
}
|
||||
|
||||
boolean isPermissionsAccepted() {
|
||||
return (ContextCompat.checkSelfPermission(myLocationView.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
== PackageManager.PERMISSION_GRANTED)
|
||||
|| ContextCompat.checkSelfPermission(myLocationView.getContext(), Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
return (ContextCompat.checkSelfPermission(myLocationView.getContext(),
|
||||
Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
|
||||
|| ContextCompat.checkSelfPermission(myLocationView.getContext(),
|
||||
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
void setOnMyLocationTrackingModeChangeListener(
|
||||
MapboxMap.OnMyLocationTrackingModeChangeListener onMyLocationTrackingModeChangeListener) {
|
||||
this.onMyLocationTrackingModeChangeListener = onMyLocationTrackingModeChangeListener;
|
||||
void setOnMyLocationTrackingModeChangeListener(MapboxMap.OnMyLocationTrackingModeChangeListener listener) {
|
||||
this.onMyLocationTrackingModeChangeListener = listener;
|
||||
}
|
||||
|
||||
void setOnMyBearingTrackingModeChangeListener(
|
||||
MapboxMap.OnMyBearingTrackingModeChangeListener onMyBearingTrackingModeChangeListener) {
|
||||
this.onMyBearingTrackingModeChangeListener = onMyBearingTrackingModeChangeListener;
|
||||
void setOnMyBearingTrackingModeChangeListener(MapboxMap.OnMyBearingTrackingModeChangeListener listener) {
|
||||
this.onMyBearingTrackingModeChangeListener = listener;
|
||||
}
|
||||
|
||||
MyLocationView getMyLocationView() {
|
||||
@@ -317,4 +350,19 @@ public final class TrackingSettings {
|
||||
myLocationEnabled = locationEnabled;
|
||||
myLocationView.setEnabled(locationEnabled);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (!myLocationView.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
myLocationView.update();
|
||||
}
|
||||
|
||||
void onStart() {
|
||||
myLocationView.onStart();
|
||||
}
|
||||
|
||||
void onStop() {
|
||||
myLocationView.onStop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -15,6 +17,8 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
|
||||
import com.mapbox.mapboxsdk.utils.ColorUtils;
|
||||
|
||||
@@ -66,6 +70,23 @@ public final class UiSettings {
|
||||
initialiseCompass(options, resources);
|
||||
initialiseLogo(options, resources);
|
||||
initialiseAttribution(context, options);
|
||||
initialiseZoomControl(context);
|
||||
}
|
||||
|
||||
void onSaveInstanceState(Bundle outState) {
|
||||
saveGestures(outState);
|
||||
saveCompass(outState);
|
||||
saveLogo(outState);
|
||||
saveAttribution(outState);
|
||||
saveZoomControl(outState);
|
||||
}
|
||||
|
||||
void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
restoreGestures(savedInstanceState);
|
||||
restoreCompass(savedInstanceState);
|
||||
restoreLogo(savedInstanceState);
|
||||
restoreAttribution(savedInstanceState);
|
||||
restoreZoomControl(savedInstanceState);
|
||||
}
|
||||
|
||||
private void initialiseGestures(MapboxMapOptions options) {
|
||||
@@ -80,6 +101,28 @@ public final class UiSettings {
|
||||
setZoomControlsEnabled(options.getZoomControlsEnabled());
|
||||
}
|
||||
|
||||
private void saveGestures(Bundle outState) {
|
||||
outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, isZoomGesturesEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED_CHANGE, isZoomGestureChangeAllowed());
|
||||
outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, isScrollGesturesEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE, isScrollGestureChangeAllowed());
|
||||
outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, isRotateGesturesEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE, isRotateGestureChangeAllowed());
|
||||
outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, isTiltGesturesEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE, isTiltGestureChangeAllowed());
|
||||
}
|
||||
|
||||
private void restoreGestures(Bundle savedInstanceState) {
|
||||
setZoomGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED));
|
||||
setZoomGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED_CHANGE));
|
||||
setScrollGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED));
|
||||
setScrollGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE));
|
||||
setRotateGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED));
|
||||
setRotateGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE));
|
||||
setTiltGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED));
|
||||
setTiltGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE));
|
||||
}
|
||||
|
||||
private void initialiseCompass(MapboxMapOptions options, Resources resources) {
|
||||
setCompassEnabled(options.getCompassEnabled());
|
||||
setCompassGravity(options.getCompassGravity());
|
||||
@@ -93,6 +136,26 @@ public final class UiSettings {
|
||||
setCompassFadeFacingNorth(options.getCompassFadeFacingNorth());
|
||||
}
|
||||
|
||||
private void saveCompass(Bundle outState) {
|
||||
outState.putBoolean(MapboxConstants.STATE_COMPASS_ENABLED, isCompassEnabled());
|
||||
outState.putInt(MapboxConstants.STATE_COMPASS_GRAVITY, getCompassGravity());
|
||||
outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT, getCompassMarginLeft());
|
||||
outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_TOP, getCompassMarginTop());
|
||||
outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM, getCompassMarginBottom());
|
||||
outState.putInt(MapboxConstants.STATE_COMPASS_MARGIN_RIGHT, getCompassMarginRight());
|
||||
outState.putBoolean(MapboxConstants.STATE_COMPASS_FADE_WHEN_FACING_NORTH, isCompassFadeWhenFacingNorth());
|
||||
}
|
||||
|
||||
private void restoreCompass(Bundle savedInstanceState) {
|
||||
setCompassEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_ENABLED));
|
||||
setCompassGravity(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_GRAVITY));
|
||||
setCompassMargins(savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_TOP),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_COMPASS_MARGIN_BOTTOM));
|
||||
setCompassFadeFacingNorth(savedInstanceState.getBoolean(MapboxConstants.STATE_COMPASS_FADE_WHEN_FACING_NORTH));
|
||||
}
|
||||
|
||||
private void initialiseLogo(MapboxMapOptions options, Resources resources) {
|
||||
setLogoEnabled(options.getLogoEnabled());
|
||||
setLogoGravity(options.getLogoGravity());
|
||||
@@ -105,6 +168,24 @@ public final class UiSettings {
|
||||
}
|
||||
}
|
||||
|
||||
private void saveLogo(Bundle outState) {
|
||||
outState.putInt(MapboxConstants.STATE_LOGO_GRAVITY, getLogoGravity());
|
||||
outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_LEFT, getLogoMarginLeft());
|
||||
outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_TOP, getLogoMarginTop());
|
||||
outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_RIGHT, getLogoMarginRight());
|
||||
outState.putInt(MapboxConstants.STATE_LOGO_MARGIN_BOTTOM, getLogoMarginBottom());
|
||||
outState.putBoolean(MapboxConstants.STATE_LOGO_ENABLED, isLogoEnabled());
|
||||
}
|
||||
|
||||
private void restoreLogo(Bundle savedInstanceState) {
|
||||
setLogoEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_LOGO_ENABLED));
|
||||
setLogoGravity(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_GRAVITY));
|
||||
setLogoMargins(savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_TOP),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_LOGO_MARGIN_BOTTOM));
|
||||
}
|
||||
|
||||
private void initialiseAttribution(Context context, MapboxMapOptions options) {
|
||||
Resources resources = context.getResources();
|
||||
setAttributionEnabled(options.getAttributionEnabled());
|
||||
@@ -123,6 +204,38 @@ public final class UiSettings {
|
||||
? attributionTintColor : ColorUtils.getPrimaryColor(context));
|
||||
}
|
||||
|
||||
private void saveAttribution(Bundle outState) {
|
||||
outState.putInt(MapboxConstants.STATE_ATTRIBUTION_GRAVITY, getAttributionGravity());
|
||||
outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT, getAttributionMarginLeft());
|
||||
outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_TOP, getAttributionMarginTop());
|
||||
outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_RIGHT, getAttributionMarginRight());
|
||||
outState.putInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_BOTTOM, getAttributionMarginBottom());
|
||||
outState.putBoolean(MapboxConstants.STATE_ATTRIBUTION_ENABLED, isAttributionEnabled());
|
||||
}
|
||||
|
||||
private void restoreAttribution(Bundle savedInstanceState) {
|
||||
setAttributionEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ATTRIBUTION_ENABLED));
|
||||
setAttributionGravity(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_GRAVITY));
|
||||
setAttributionMargins(savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_LEFT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_TOP),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_RIGHT),
|
||||
savedInstanceState.getInt(MapboxConstants.STATE_ATTRIBUTION_MARGIN_BOTTOM));
|
||||
}
|
||||
|
||||
private void initialiseZoomControl(Context context) {
|
||||
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
|
||||
setZoomControlsEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveZoomControl(Bundle outState) {
|
||||
outState.putBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED, isZoomControlsEnabled());
|
||||
}
|
||||
|
||||
private void restoreZoomControl(Bundle savedInstanceState) {
|
||||
setZoomControlsEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_CONTROLS_ENABLED));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Enables or disables the compass. The compass is an icon on the map that indicates the
|
||||
@@ -242,6 +355,14 @@ public final class UiSettings {
|
||||
return ((FrameLayout.LayoutParams) compassView.getLayoutParams()).bottomMargin;
|
||||
}
|
||||
|
||||
void update(@NonNull CameraPosition cameraPosition) {
|
||||
if (!isCompassEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
compassView.update(cameraPosition.bearing);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Enables or disables the Mapbox logo.
|
||||
@@ -401,8 +522,8 @@ public final class UiSettings {
|
||||
public void setAttributionTintColor(@ColorInt int tintColor) {
|
||||
// Check that the tint color being passed in isn't transparent.
|
||||
if (Color.alpha(tintColor) == 0) {
|
||||
ColorUtils.setTintList(attributionsView, ContextCompat.getColor(attributionsView.getContext(),
|
||||
R.color.mapbox_blue));
|
||||
ColorUtils.setTintList(attributionsView,
|
||||
ContextCompat.getColor(attributionsView.getContext(), R.color.mapbox_blue));
|
||||
} else {
|
||||
ColorUtils.setTintList(attributionsView, tintColor);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when connectivity changes.
|
||||
* Not public api.
|
||||
@@ -82,7 +82,7 @@ public class ConnectivityReceiver extends BroadcastReceiver {
|
||||
* @return true if connected
|
||||
*/
|
||||
public boolean isConnected(Context context) {
|
||||
Boolean connected = MapboxAccountManager.getInstance().isConnected();
|
||||
Boolean connected = Mapbox.isConnected();
|
||||
if (connected != null) {
|
||||
// Connectivity state overridden by app
|
||||
return connected;
|
||||
|
||||
@@ -7,14 +7,15 @@ import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* The offline manager is the main entry point for offline-related functionality.
|
||||
* It'll help you list and create offline regions.
|
||||
@@ -91,15 +92,14 @@ public class OfflineManager {
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
private OfflineManager(Context context) {
|
||||
// Get a pointer to the DefaultFileSource instance
|
||||
String assetRoot = getDatabasePath(context);
|
||||
String cachePath = assetRoot + File.separator + DATABASE_NAME;
|
||||
mDefaultFileSourcePtr = createDefaultFileSource(cachePath, assetRoot, DEFAULT_MAX_CACHE_SIZE);
|
||||
|
||||
if (MapboxAccountManager.getInstance() != null) {
|
||||
setAccessToken(mDefaultFileSourcePtr, MapboxAccountManager.getInstance().getAccessToken());
|
||||
if (!TextUtils.isEmpty(Mapbox.getAccessToken())) {
|
||||
setAccessToken(mDefaultFileSourcePtr, Mapbox.getAccessToken());
|
||||
}
|
||||
|
||||
// Delete any existing previous ambient cache database
|
||||
@@ -117,10 +117,10 @@ public class OfflineManager {
|
||||
setStorageExternal = appInfo.metaData.getBoolean(
|
||||
MapboxConstants.KEY_META_DATA_SET_STORAGE_EXTERNAL,
|
||||
MapboxConstants.DEFAULT_SET_STORAGE_EXTERNAL);
|
||||
} catch (PackageManager.NameNotFoundException nameNotFoundException) {
|
||||
Timber.e("Failed to read the package metadata: " + nameNotFoundException.getMessage());
|
||||
} catch (PackageManager.NameNotFoundException exception) {
|
||||
Timber.e("Failed to read the package metadata: ", exception);
|
||||
} catch (Exception exception) {
|
||||
Timber.e("Failed to read the storage key: " + exception.getMessage());
|
||||
Timber.e("Failed to read the storage key: ", exception);
|
||||
}
|
||||
|
||||
String databasePath = null;
|
||||
@@ -128,8 +128,8 @@ public class OfflineManager {
|
||||
try {
|
||||
// Try getting the external storage path
|
||||
databasePath = context.getExternalFilesDir(null).getAbsolutePath();
|
||||
} catch (NullPointerException nullPointerException) {
|
||||
Timber.e("Failed to obtain the external storage path: " + nullPointerException.getMessage());
|
||||
} catch (NullPointerException exception) {
|
||||
Timber.e("Failed to obtain the external storage path: ", exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class OfflineManager {
|
||||
Timber.d("Old ambient cache database deleted to save space: " + path);
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Timber.e("Failed to delete old ambient cache database: " + exception.getMessage());
|
||||
Timber.e("Failed to delete old ambient cache database: ", exception);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -187,6 +187,7 @@ public class OfflineManager {
|
||||
if (instance == null) {
|
||||
instance = new OfflineManager(context);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -194,7 +195,7 @@ public class OfflineManager {
|
||||
* Access token getter/setter
|
||||
*
|
||||
* @param accessToken the accessToken to be used by the offline manager.
|
||||
* @deprecated As of release 4.1.0, replaced by {@link MapboxAccountManager#start(Context, String)} ()}
|
||||
* @deprecated As of release 4.1.0, replaced by {@link Mapbox#getInstance(Context, String)}}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setAccessToken(String accessToken) {
|
||||
@@ -205,7 +206,7 @@ public class OfflineManager {
|
||||
* Get Access Token
|
||||
*
|
||||
* @return Access Token
|
||||
* @deprecated As of release 4.1.0, replaced by {@link MapboxAccountManager#getAccessToken()}
|
||||
* @deprecated As of release 4.1.0, replaced by {@link Mapbox#getAccessToken()}
|
||||
*/
|
||||
@Deprecated
|
||||
public String getAccessToken() {
|
||||
@@ -309,7 +310,6 @@ public class OfflineManager {
|
||||
/*
|
||||
* Native methods
|
||||
*/
|
||||
|
||||
private native long createDefaultFileSource(
|
||||
String cachePath, String assetRoot, long maximumCacheSize);
|
||||
|
||||
|
||||
@@ -77,16 +77,20 @@ public class MapboxEvent implements Serializable {
|
||||
* Helper method for tracking gesture events
|
||||
*
|
||||
* @param projection Projection of the Map object
|
||||
* @param gestureId Type of Gesture See {@see MapboxEvent#GESTURE_SINGLETAP MapboxEvent#GESTURE_DOUBLETAP
|
||||
* MapboxEvent#GESTURE_TWO_FINGER_SINGLETAP MapboxEvent#GESTURE_QUICK_ZOOM
|
||||
* MapboxEvent#GESTURE_PAN_START MapboxEvent#GESTURE_PINCH_START
|
||||
* MapboxEvent#GESTURE_ROTATION_START MapboxEvent#GESTURE_PITCH_START}
|
||||
* @param gestureId Type of Gesture See {@see MapboxEvent#GESTURE_SINGLETAP
|
||||
* MapboxEvent#GESTURE_DOUBLETAP
|
||||
* MapboxEvent#GESTURE_TWO_FINGER_SINGLETAP
|
||||
* MapboxEvent#GESTURE_QUICK_ZOOM
|
||||
* MapboxEvent#GESTURE_PAN_START
|
||||
* MapboxEvent#GESTURE_PINCH_START
|
||||
* MapboxEvent#GESTURE_ROTATION_START
|
||||
* MapboxEvent#GESTURE_PITCH_START}
|
||||
* @param xCoordinate Original x screen coordinate at start of gesture
|
||||
* @param yCoordinate Original y screen cooridnate at start of gesture
|
||||
* @param zoom Zoom level to be registered
|
||||
*/
|
||||
public static void trackGestureEvent(@NonNull Projection projection, @NonNull String gestureId,
|
||||
float xCoordinate, float yCoordinate, double zoom) {
|
||||
public static void trackGestureEvent(@NonNull Projection projection, @NonNull String gestureId, float xCoordinate,
|
||||
float yCoordinate, double zoom) {
|
||||
LatLng tapLatLng = projection.fromScreenLocation(new PointF(xCoordinate, yCoordinate));
|
||||
|
||||
// NaN and Infinite checks to prevent JSON errors at send to server time
|
||||
@@ -120,8 +124,8 @@ public class MapboxEvent implements Serializable {
|
||||
* @param yCoordinate Orginal y screen coordinate at end of drag
|
||||
* @param zoom Zoom level to be registered
|
||||
*/
|
||||
public static void trackGestureDragEndEvent(@NonNull Projection projection, float xCoordinate,
|
||||
float yCoordinate, double zoom) {
|
||||
public static void trackGestureDragEndEvent(@NonNull Projection projection, float xCoordinate, float yCoordinate,
|
||||
double zoom) {
|
||||
LatLng tapLatLng = projection.fromScreenLocation(new PointF(xCoordinate, yCoordinate));
|
||||
|
||||
// NaN and Infinite checks to prevent JSON errors at send to server time
|
||||
@@ -144,4 +148,14 @@ public class MapboxEvent implements Serializable {
|
||||
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for tracking map load event
|
||||
*/
|
||||
public static void trackMapLoadEvent() {
|
||||
Hashtable<String, Object> evt = new Hashtable<>();
|
||||
evt.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_MAP_LOAD);
|
||||
evt.put(MapboxEvent.ATTRIBUTE_CREATED, MapboxEventManager.generateCreateDate());
|
||||
MapboxEventManager.getMapboxEventManager().pushEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.MapboxAccountManager;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.constants.GeoConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException;
|
||||
import com.mapbox.mapboxsdk.location.LocationServices;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
@@ -53,45 +54,6 @@ import okhttp3.Response;
|
||||
import okhttp3.internal.Util;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.KEY_META_DATA_STAGING_ACCESS_TOKEN;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.KEY_META_DATA_STAGING_SERVER;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_LOCALE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_SHARED_PREFERENCES_FILE;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_ACCESS_TOKEN;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_URL;
|
||||
import static com.mapbox.mapboxsdk.constants.MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_ACCESSIBILITY_FONT_SCALE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_APPLICATION_STATE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_BATTERY_LEVEL;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_CARRIER;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_CREATED;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_ENABLED_TELEMETRY;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_EVENT;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_MODEL;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_ORIENTATION;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_PLUGGED_IN;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_RESOLUTION;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_SESSION_ID;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_SOURCE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_USERID;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.ATTRIBUTE_WIFI;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_ALTITUDE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_GESTURE_ID;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_HORIZONTAL_ACCURACY;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_LATITUDE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_LONGITUDE;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.KEY_ZOOM;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.MAPBOX_EVENTS_BASE_URL;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.SOURCE_MAPBOX;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.TYPE_LOCATION;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.TYPE_MAP_CLICK;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.TYPE_MAP_DRAGEND;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.TYPE_MAP_LOAD;
|
||||
import static com.mapbox.mapboxsdk.telemetry.MapboxEvent.TYPE_TURNSTILE;
|
||||
|
||||
/**
|
||||
* Singleton control center for managing Telemetry Data.
|
||||
* Primary access is via MapboxEventManager.getMapboxEventManager()
|
||||
@@ -106,11 +68,12 @@ public class MapboxEventManager {
|
||||
|
||||
private final Vector<Hashtable<String, Object>> events = new Vector<>();
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", MAPBOX_LOCALE);
|
||||
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",
|
||||
MapboxConstants.MAPBOX_LOCALE);
|
||||
|
||||
private Context context = null;
|
||||
private String accessToken = null;
|
||||
private String eventsURL = MAPBOX_EVENTS_BASE_URL;
|
||||
private String eventsURL = MapboxEvent.MAPBOX_EVENTS_BASE_URL;
|
||||
|
||||
private String userAgent = BuildConfig.MAPBOX_EVENTS_USER_AGENT_BASE;
|
||||
|
||||
@@ -144,8 +107,8 @@ public class MapboxEventManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal setup of MapboxEventsManager. It needs to be called once before
|
||||
* {@link MapboxEventManager#getMapboxEventManager}
|
||||
* 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
|
||||
*
|
||||
@@ -169,29 +132,29 @@ public class MapboxEventManager {
|
||||
// Setup Message Digest
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("SHA-1");
|
||||
} catch (NoSuchAlgorithmException noSuchAlgorithmException) {
|
||||
Timber.w("Error getting Encryption Algorithm: " + noSuchAlgorithmException);
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
Timber.w("Error getting Encryption Algorithm: ", exception);
|
||||
}
|
||||
|
||||
// Create Initial Session Id
|
||||
rotateSessionId();
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(MAPBOX_SHARED_PREFERENCES_FILE,
|
||||
SharedPreferences prefs = context.getSharedPreferences(MapboxConstants.MAPBOX_SHARED_PREFERENCES_FILE,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
// Determine if Telemetry Should Be Enabled
|
||||
Timber.i("Right before Telemetry set enabled in initialized()");
|
||||
setTelemetryEnabled(prefs.getBoolean(MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED, true));
|
||||
setTelemetryEnabled(prefs.getBoolean(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED, true));
|
||||
|
||||
// Load / Create Vendor Id
|
||||
if (prefs.contains(MAPBOX_SHARED_PREFERENCE_KEY_VENDORID)) {
|
||||
mapboxVendorId = prefs.getString(MAPBOX_SHARED_PREFERENCE_KEY_VENDORID, "");
|
||||
if (prefs.contains(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID)) {
|
||||
mapboxVendorId = prefs.getString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID, "");
|
||||
}
|
||||
if (TextUtils.isEmpty(mapboxVendorId)) {
|
||||
String vendorId = UUID.randomUUID().toString();
|
||||
mapboxVendorId = encodeString(vendorId);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString(MAPBOX_SHARED_PREFERENCE_KEY_VENDORID, mapboxVendorId);
|
||||
editor.putString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_VENDORID, mapboxVendorId);
|
||||
editor.apply();
|
||||
editor.commit();
|
||||
}
|
||||
@@ -204,13 +167,14 @@ public class MapboxEventManager {
|
||||
try {
|
||||
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(),
|
||||
PackageManager.GET_META_DATA);
|
||||
String stagingURL = appInfo.metaData.getString(KEY_META_DATA_STAGING_SERVER);
|
||||
String stagingAccessToken = appInfo.metaData.getString(KEY_META_DATA_STAGING_ACCESS_TOKEN);
|
||||
String stagingURL = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_STAGING_SERVER);
|
||||
String stagingAccessToken = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_STAGING_ACCESS_TOKEN);
|
||||
|
||||
if (TextUtils.isEmpty(stagingURL) || TextUtils.isEmpty(stagingAccessToken)) {
|
||||
Timber.d("Looking in SharedPreferences for Staging Credentials");
|
||||
stagingURL = prefs.getString(MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_URL, null);
|
||||
stagingAccessToken = prefs.getString(MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_ACCESS_TOKEN, null);
|
||||
stagingURL = prefs.getString(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_URL, null);
|
||||
stagingAccessToken = prefs.getString(
|
||||
MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_STAGING_ACCESS_TOKEN, null);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(stagingURL) && !TextUtils.isEmpty(stagingAccessToken)) {
|
||||
@@ -222,11 +186,12 @@ public class MapboxEventManager {
|
||||
// Build User Agent
|
||||
String appIdentifier = getApplicationIdentifier();
|
||||
if (TextUtils.equals(userAgent, BuildConfig.MAPBOX_EVENTS_USER_AGENT_BASE) && !TextUtils.isEmpty(appIdentifier)) {
|
||||
userAgent = Util.toHumanReadableAscii(String.format(MAPBOX_LOCALE, "%s %s", appIdentifier, userAgent));
|
||||
userAgent = Util
|
||||
.toHumanReadableAscii(String.format(MapboxConstants.MAPBOX_LOCALE, "%s %s", appIdentifier, userAgent));
|
||||
}
|
||||
|
||||
} catch (Exception exception) {
|
||||
Timber.e("Error Trying to load Staging Credentials: " + exception.toString());
|
||||
Timber.e("Error Trying to load Staging Credentials: ", exception);
|
||||
}
|
||||
|
||||
// Register for battery updates
|
||||
@@ -262,7 +227,7 @@ public class MapboxEventManager {
|
||||
}
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Timber.w("Error checking for Telemetry Service Config: " + exception);
|
||||
Timber.w("Error checking for Telemetry Service Config: ", exception);
|
||||
}
|
||||
throw new TelemetryServiceNotConfiguredException();
|
||||
}
|
||||
@@ -281,8 +246,7 @@ public class MapboxEventManager {
|
||||
* @param telemetryEnabled True to start telemetry, false to stop it
|
||||
*/
|
||||
public void setTelemetryEnabled(boolean telemetryEnabled) {
|
||||
Timber.i("setTelemetryEnabled(); this.telemetryEnabled = " + this.telemetryEnabled + "; telemetryEnabled = "
|
||||
+ telemetryEnabled);
|
||||
Timber.i("this.telemetryEnabled = " + this.telemetryEnabled + "; telemetryEnabled = " + telemetryEnabled);
|
||||
if (this.telemetryEnabled == telemetryEnabled) {
|
||||
Timber.d("No need to start / stop telemetry as it's already in that state.");
|
||||
return;
|
||||
@@ -340,9 +304,10 @@ public class MapboxEventManager {
|
||||
|
||||
// Persist
|
||||
this.telemetryEnabled = telemetryEnabled;
|
||||
SharedPreferences prefs = context.getSharedPreferences(MAPBOX_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
|
||||
SharedPreferences prefs = context.getSharedPreferences(MapboxConstants.MAPBOX_SHARED_PREFERENCES_FILE,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putBoolean(MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED, telemetryEnabled);
|
||||
editor.putBoolean(MapboxConstants.MAPBOX_SHARED_PREFERENCE_KEY_TELEMETRY_ENABLED, telemetryEnabled);
|
||||
editor.apply();
|
||||
editor.commit();
|
||||
}
|
||||
@@ -393,18 +358,18 @@ public class MapboxEventManager {
|
||||
|
||||
// Add Location even to queue
|
||||
Hashtable<String, Object> event = new Hashtable<>();
|
||||
event.put(ATTRIBUTE_EVENT, TYPE_LOCATION);
|
||||
event.put(ATTRIBUTE_CREATED, generateCreateDate());
|
||||
event.put(ATTRIBUTE_SOURCE, SOURCE_MAPBOX);
|
||||
event.put(ATTRIBUTE_SESSION_ID, encodeString(mapboxSessionId));
|
||||
event.put(KEY_LATITUDE, Math.floor(location.getLatitude() * locationEventAccuracy)
|
||||
/ locationEventAccuracy);
|
||||
event.put(KEY_LONGITUDE, Math.floor(location.getLongitude() * locationEventAccuracy)
|
||||
/ locationEventAccuracy);
|
||||
event.put(KEY_ALTITUDE, location.getAltitude());
|
||||
event.put(KEY_HORIZONTAL_ACCURACY, Math.round(location.getAccuracy()));
|
||||
event.put(ATTRIBUTE_OPERATING_SYSTEM, operatingSystem);
|
||||
event.put(ATTRIBUTE_APPLICATION_STATE, getApplicationState());
|
||||
event.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_LOCATION);
|
||||
event.put(MapboxEvent.ATTRIBUTE_CREATED, generateCreateDate());
|
||||
event.put(MapboxEvent.ATTRIBUTE_SOURCE, MapboxEvent.SOURCE_MAPBOX);
|
||||
event.put(MapboxEvent.ATTRIBUTE_SESSION_ID, encodeString(mapboxSessionId));
|
||||
event.put(MapboxEvent.KEY_LATITUDE,
|
||||
Math.floor(location.getLatitude() * locationEventAccuracy) / locationEventAccuracy);
|
||||
event.put(MapboxEvent.KEY_LONGITUDE,
|
||||
Math.floor(location.getLongitude() * locationEventAccuracy) / locationEventAccuracy);
|
||||
event.put(MapboxEvent.KEY_ALTITUDE, location.getAltitude());
|
||||
event.put(MapboxEvent.KEY_HORIZONTAL_ACCURACY, Math.round(location.getAccuracy()));
|
||||
event.put(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, operatingSystem);
|
||||
event.put(MapboxEvent.ATTRIBUTE_APPLICATION_STATE, getApplicationState());
|
||||
|
||||
putEventOnQueue(event);
|
||||
|
||||
@@ -425,24 +390,24 @@ public class MapboxEventManager {
|
||||
return;
|
||||
}
|
||||
|
||||
String eventType = (String) eventWithAttributes.get(ATTRIBUTE_EVENT);
|
||||
String eventType = (String) eventWithAttributes.get(MapboxEvent.ATTRIBUTE_EVENT);
|
||||
if (TextUtils.isEmpty(eventType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventType.equalsIgnoreCase(TYPE_MAP_LOAD)) {
|
||||
if (eventType.equalsIgnoreCase(MapboxEvent.TYPE_MAP_LOAD)) {
|
||||
// Map Load Data Model
|
||||
eventWithAttributes.put(ATTRIBUTE_USERID, mapboxVendorId);
|
||||
eventWithAttributes.put(ATTRIBUTE_MODEL, Build.MODEL);
|
||||
eventWithAttributes.put(ATTRIBUTE_OPERATING_SYSTEM, operatingSystem);
|
||||
eventWithAttributes.put(ATTRIBUTE_RESOLUTION, displayMetrics.density);
|
||||
eventWithAttributes.put(ATTRIBUTE_ACCESSIBILITY_FONT_SCALE, getAccesibilityFontScaleSize());
|
||||
eventWithAttributes.put(ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_USERID, mapboxVendorId);
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_MODEL, Build.MODEL);
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, operatingSystem);
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_RESOLUTION, displayMetrics.density);
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_ACCESSIBILITY_FONT_SCALE, getAccesibilityFontScaleSize());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
|
||||
// Put Map Load on events before Turnstile clears it
|
||||
putEventOnQueue(eventWithAttributes);
|
||||
@@ -453,20 +418,20 @@ public class MapboxEventManager {
|
||||
// Return immediately to avoid double adding of event
|
||||
return;
|
||||
|
||||
} else if (eventType.equalsIgnoreCase(TYPE_MAP_CLICK)) {
|
||||
eventWithAttributes.put(ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
} else if (eventType.equalsIgnoreCase(TYPE_MAP_DRAGEND)) {
|
||||
eventWithAttributes.put(ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
} else if (eventType.equalsIgnoreCase(MapboxEvent.TYPE_MAP_CLICK)) {
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
} else if (eventType.equalsIgnoreCase(MapboxEvent.TYPE_MAP_DRAGEND)) {
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_ORIENTATION, getOrientation());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_BATTERY_LEVEL, getBatteryLevel());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_PLUGGED_IN, isPluggedIn());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CARRIER, getCellularCarrier());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE, getCellularNetworkType());
|
||||
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_WIFI, getConnectedToWifi());
|
||||
} else {
|
||||
Timber.w("This is not an event type in the Events Data Model.");
|
||||
return;
|
||||
@@ -481,10 +446,10 @@ public class MapboxEventManager {
|
||||
private void pushTurnstileEvent() {
|
||||
|
||||
Hashtable<String, Object> event = new Hashtable<>();
|
||||
event.put(ATTRIBUTE_EVENT, TYPE_TURNSTILE);
|
||||
event.put(ATTRIBUTE_CREATED, generateCreateDate());
|
||||
event.put(ATTRIBUTE_USERID, mapboxVendorId);
|
||||
event.put(ATTRIBUTE_ENABLED_TELEMETRY, telemetryEnabled);
|
||||
event.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_TURNSTILE);
|
||||
event.put(MapboxEvent.ATTRIBUTE_CREATED, generateCreateDate());
|
||||
event.put(MapboxEvent.ATTRIBUTE_USERID, mapboxVendorId);
|
||||
event.put(MapboxEvent.ATTRIBUTE_ENABLED_TELEMETRY, telemetryEnabled);
|
||||
|
||||
events.add(event);
|
||||
|
||||
@@ -516,7 +481,7 @@ public class MapboxEventManager {
|
||||
return hex;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Timber.w("Error encoding string, will return in original form." + exception);
|
||||
Timber.w("Error encoding string, will return in original form.", exception);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
@@ -526,8 +491,8 @@ public class MapboxEventManager {
|
||||
*/
|
||||
private void rotateSessionId() {
|
||||
long now = System.currentTimeMillis();
|
||||
if ((TextUtils.isEmpty(mapboxSessionId)) || (now - mapboxSessionIdLastSet
|
||||
> (SESSION_ID_ROTATION_HOURS * hourInMillis))) {
|
||||
if ((TextUtils.isEmpty(mapboxSessionId))
|
||||
|| (now - mapboxSessionIdLastSet > (SESSION_ID_ROTATION_HOURS * hourInMillis))) {
|
||||
mapboxSessionId = UUID.randomUUID().toString();
|
||||
mapboxSessionIdLastSet = System.currentTimeMillis();
|
||||
}
|
||||
@@ -655,7 +620,7 @@ public class MapboxEventManager {
|
||||
status = true;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
Timber.w("Error getting Wifi Connection Status: " + exception);
|
||||
Timber.w("Error getting Wifi Connection Status: ", exception);
|
||||
status = false;
|
||||
}
|
||||
}
|
||||
@@ -678,7 +643,7 @@ public class MapboxEventManager {
|
||||
}
|
||||
|
||||
// Check for NetworkConnectivity
|
||||
if (!MapboxAccountManager.getInstance().isConnected()) {
|
||||
if (!Mapbox.isConnected()) {
|
||||
Timber.w("Not connected to network, so empty events cache and return without attempting to send events");
|
||||
// Make sure that events don't pile up when Offline
|
||||
// and thus impact available memory over time.
|
||||
@@ -699,67 +664,70 @@ public class MapboxEventManager {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
|
||||
// Build the JSON but only if there's a value for it in the evt
|
||||
jsonObject.putOpt(ATTRIBUTE_EVENT, evt.get(ATTRIBUTE_EVENT));
|
||||
jsonObject.putOpt(ATTRIBUTE_CREATED, evt.get(ATTRIBUTE_CREATED));
|
||||
jsonObject.putOpt(ATTRIBUTE_USERID, evt.get(ATTRIBUTE_USERID));
|
||||
jsonObject.putOpt(ATTRIBUTE_ENABLED_TELEMETRY, evt.get(ATTRIBUTE_ENABLED_TELEMETRY));
|
||||
jsonObject.putOpt(ATTRIBUTE_SOURCE, evt.get(ATTRIBUTE_SOURCE));
|
||||
jsonObject.putOpt(ATTRIBUTE_SESSION_ID, evt.get(ATTRIBUTE_SESSION_ID));
|
||||
jsonObject.putOpt(KEY_LATITUDE, evt.get(KEY_LATITUDE));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_EVENT, evt.get(MapboxEvent.ATTRIBUTE_EVENT));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_CREATED, evt.get(MapboxEvent.ATTRIBUTE_CREATED));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_USERID, evt.get(MapboxEvent.ATTRIBUTE_USERID));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_ENABLED_TELEMETRY, evt.get(MapboxEvent.ATTRIBUTE_ENABLED_TELEMETRY));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_SOURCE, evt.get(MapboxEvent.ATTRIBUTE_SOURCE));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_SESSION_ID, evt.get(MapboxEvent.ATTRIBUTE_SESSION_ID));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_LATITUDE, evt.get(MapboxEvent.KEY_LATITUDE));
|
||||
|
||||
// Make sure Longitude Is Wrapped
|
||||
if (evt.containsKey(KEY_LONGITUDE)) {
|
||||
double lon = (double) evt.get(KEY_LONGITUDE);
|
||||
if (evt.containsKey(MapboxEvent.KEY_LONGITUDE)) {
|
||||
double lon = (double) evt.get(MapboxEvent.KEY_LONGITUDE);
|
||||
if ((lon < GeoConstants.MIN_LONGITUDE) || (lon > GeoConstants.MAX_LONGITUDE)) {
|
||||
lon = MathUtils.wrap(lon, GeoConstants.MIN_LONGITUDE, GeoConstants.MAX_LONGITUDE);
|
||||
}
|
||||
jsonObject.put(KEY_LONGITUDE, lon);
|
||||
jsonObject.put(MapboxEvent.KEY_LONGITUDE, lon);
|
||||
}
|
||||
|
||||
jsonObject.putOpt(KEY_ALTITUDE, evt.get(KEY_ALTITUDE));
|
||||
jsonObject.putOpt(KEY_ZOOM, evt.get(KEY_ZOOM));
|
||||
jsonObject.putOpt(ATTRIBUTE_OPERATING_SYSTEM, evt.get(ATTRIBUTE_OPERATING_SYSTEM));
|
||||
jsonObject.putOpt(ATTRIBUTE_USERID, evt.get(ATTRIBUTE_USERID));
|
||||
jsonObject.putOpt(ATTRIBUTE_MODEL, evt.get(ATTRIBUTE_MODEL));
|
||||
jsonObject.putOpt(ATTRIBUTE_RESOLUTION, evt.get(ATTRIBUTE_RESOLUTION));
|
||||
jsonObject.putOpt(ATTRIBUTE_ACCESSIBILITY_FONT_SCALE, evt.get(ATTRIBUTE_ACCESSIBILITY_FONT_SCALE));
|
||||
jsonObject.putOpt(ATTRIBUTE_BATTERY_LEVEL, evt.get(ATTRIBUTE_BATTERY_LEVEL));
|
||||
jsonObject.putOpt(ATTRIBUTE_PLUGGED_IN, evt.get(ATTRIBUTE_PLUGGED_IN));
|
||||
jsonObject.putOpt(ATTRIBUTE_WIFI, evt.get(ATTRIBUTE_WIFI));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_ALTITUDE, evt.get(MapboxEvent.KEY_ALTITUDE));
|
||||
jsonObject.putOpt(MapboxEvent.KEY_ZOOM, evt.get(MapboxEvent.KEY_ZOOM));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, evt.get(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_USERID, evt.get(MapboxEvent.ATTRIBUTE_USERID));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_MODEL, evt.get(MapboxEvent.ATTRIBUTE_MODEL));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_RESOLUTION, evt.get(MapboxEvent.ATTRIBUTE_RESOLUTION));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_ACCESSIBILITY_FONT_SCALE,
|
||||
evt.get(MapboxEvent.ATTRIBUTE_ACCESSIBILITY_FONT_SCALE));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_BATTERY_LEVEL, evt.get(MapboxEvent.ATTRIBUTE_BATTERY_LEVEL));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_PLUGGED_IN, evt.get(MapboxEvent.ATTRIBUTE_PLUGGED_IN));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_WIFI, evt.get(MapboxEvent.ATTRIBUTE_WIFI));
|
||||
|
||||
// Special Cases where empty string is denoting null and therefore should not be sent at all
|
||||
// This arises as thread safe Hashtable does not accept null values (nor keys)
|
||||
if (evt.containsKey(ATTRIBUTE_ORIENTATION)) {
|
||||
String orientation = (String) evt.get(ATTRIBUTE_ORIENTATION);
|
||||
if (evt.containsKey(MapboxEvent.ATTRIBUTE_ORIENTATION)) {
|
||||
String orientation = (String) evt.get(MapboxEvent.ATTRIBUTE_ORIENTATION);
|
||||
if (!TextUtils.isEmpty(orientation)) {
|
||||
jsonObject.putOpt(ATTRIBUTE_ORIENTATION, orientation);
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_ORIENTATION, orientation);
|
||||
}
|
||||
}
|
||||
if (evt.containsKey(ATTRIBUTE_CARRIER)) {
|
||||
String carrier = (String) evt.get(ATTRIBUTE_CARRIER);
|
||||
if (evt.containsKey(MapboxEvent.ATTRIBUTE_CARRIER)) {
|
||||
String carrier = (String) evt.get(MapboxEvent.ATTRIBUTE_CARRIER);
|
||||
if (!TextUtils.isEmpty(carrier)) {
|
||||
jsonObject.putOpt(ATTRIBUTE_CARRIER, carrier);
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_CARRIER, carrier);
|
||||
}
|
||||
}
|
||||
if (evt.containsKey(ATTRIBUTE_APPLICATION_STATE)) {
|
||||
String appState = (String) evt.get(ATTRIBUTE_APPLICATION_STATE);
|
||||
if (evt.containsKey(MapboxEvent.ATTRIBUTE_APPLICATION_STATE)) {
|
||||
String appState = (String) evt.get(MapboxEvent.ATTRIBUTE_APPLICATION_STATE);
|
||||
if (!TextUtils.isEmpty(appState)) {
|
||||
jsonObject.putOpt(ATTRIBUTE_APPLICATION_STATE, evt.get(ATTRIBUTE_APPLICATION_STATE));
|
||||
jsonObject.putOpt(MapboxEvent.ATTRIBUTE_APPLICATION_STATE,
|
||||
evt.get(MapboxEvent.ATTRIBUTE_APPLICATION_STATE));
|
||||
}
|
||||
}
|
||||
|
||||
// Special Cases where null has to be passed if no value exists
|
||||
// Requires using put() instead of putOpt()
|
||||
String eventType = (String) evt.get(ATTRIBUTE_EVENT);
|
||||
if (!TextUtils.isEmpty(eventType) && eventType.equalsIgnoreCase(TYPE_MAP_CLICK)) {
|
||||
jsonObject.put(KEY_GESTURE_ID, evt.get(KEY_GESTURE_ID));
|
||||
String eventType = (String) evt.get(MapboxEvent.ATTRIBUTE_EVENT);
|
||||
if (!TextUtils.isEmpty(eventType) && eventType.equalsIgnoreCase(MapboxEvent.TYPE_MAP_CLICK)) {
|
||||
jsonObject.put(MapboxEvent.KEY_GESTURE_ID, evt.get(MapboxEvent.KEY_GESTURE_ID));
|
||||
}
|
||||
if (evt.containsKey(ATTRIBUTE_CELLULAR_NETWORK_TYPE)) {
|
||||
String cellularNetworkType = (String) evt.get(ATTRIBUTE_CELLULAR_NETWORK_TYPE);
|
||||
if (evt.containsKey(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE)) {
|
||||
String cellularNetworkType = (String) evt.get(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE);
|
||||
if (TextUtils.isEmpty(cellularNetworkType)) {
|
||||
jsonObject.put(ATTRIBUTE_CELLULAR_NETWORK_TYPE, null);
|
||||
jsonObject.put(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE, null);
|
||||
} else {
|
||||
jsonObject.put(ATTRIBUTE_CELLULAR_NETWORK_TYPE, evt.get(ATTRIBUTE_CELLULAR_NETWORK_TYPE));
|
||||
jsonObject.put(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE,
|
||||
evt.get(MapboxEvent.ATTRIBUTE_CELLULAR_NETWORK_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,7 +771,7 @@ public class MapboxEventManager {
|
||||
Timber.d("response code = " + response.code() + " for events " + events.size());
|
||||
|
||||
} catch (Exception exception) {
|
||||
Timber.e("FlushTheEventsTask borked: " + exception);
|
||||
Timber.e("FlushTheEventsTask borked: ", exception);
|
||||
exception.printStackTrace();
|
||||
} finally {
|
||||
if (response != null && response.body() != null) {
|
||||
@@ -837,10 +805,10 @@ public class MapboxEventManager {
|
||||
private String getApplicationIdentifier() {
|
||||
try {
|
||||
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
return String.format(MAPBOX_LOCALE, "%s/%s/%s", context.getPackageName(), packageInfo.versionName,
|
||||
packageInfo.versionCode);
|
||||
return String.format(MapboxConstants.MAPBOX_LOCALE, "%s/%s/%s", context.getPackageName(),
|
||||
packageInfo.versionName, packageInfo.versionCode);
|
||||
} catch (Exception exception) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user