diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java new file mode 100644 index 000000000..d9cf40767 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java @@ -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()); + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxAccountManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxAccountManager.java deleted file mode 100644 index 5f26228c5..000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/MapboxAccountManager.java +++ /dev/null @@ -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; - } - -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index d953bfca0..409b0bf19 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -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 { *
*/ 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- * Returns the Mapbox access token set in the app resources. - *
- * 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. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index 398093344..93422b183 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -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; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 5bbba8682..5dee9bf43 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -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; - /** *
* 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
- * DEPRECATED @see MapboxAccountManager#start(String) - *
- *- * Sets the current Mapbox access token used to load map styles and tiles. - *
- *- * You must set a valid access token before you call {@link MapView#onCreate(Bundle)} - * or an exception will be thrown. - *
- * - * @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); - } - - /** - *- * DEPRECATED @see MapboxAccountManager#getAccessToken() - *
- *- * Returns the current Mapbox access token used to load map styles and tiles. - *
- * - * @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. *@@ -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. *
@@ -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
+ * Allows single touch only devices to zoom in and out.
+ *
+ * Invalidation of the camera position is required to update the added components in
+ * OnMapReadyCallback with the correct transformation.
+ *
- * Loads a new map style from the specified bundled style.
- *
- * 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.
- *
* Loads a new map style from the specified URL.
@@ -761,6 +807,28 @@ public final class MapboxMap {
nativeMapView.setStyleUrl(url);
}
+ /**
+ *
+ * Loads a new map style from the specified bundled style.
+ *
+ * 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.
+ *
- * DEPRECATED @see MapboxAccountManager#getAccessToken()
- *
- * Returns the current Mapbox access token used to load map styles and tiles.
- *
- * DEPRECATED @see MapboxAccountManager#start(String)
- *
- * Sets the current Mapbox access token used to load map styles and tiles.
- *
* 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.
- *
- * 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}.
*
- * DEPRECATED @see MapboxAccountManager#start(String)
- *
- * DEPRECATED @see MapboxAccountManager#start(String)
- *
- * Returns the Mapbox access token set in the app resources.
- *
* 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();
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
index b58d5bfc0..0928f0631 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java
@@ -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));
+ }
+
/**
*
* 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);
+ }
+
/**
*
* 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);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
index 63d925430..7c37569ae 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/net/ConnectivityReceiver.java
@@ -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;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
index 58093f285..1a396f689 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/offline/OfflineManager.java
@@ -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);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEvent.java
index b125b35cf..b5203bc02 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEvent.java
@@ -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
* 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