[android] Integration of the new events library (#10999)
* [android] integration of the new events library * JNI Bug - current build with JNI bug * fix #10999 comments * Clean-up - clean-up timbers and test code * [android] fix sdk identifier and sdk version * [android] merge from master (MAS 3.0) * [android] bump events lib version to 3.0.0-beta.1 and remove never used methods from math utils class
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
package com.mapbox.mapboxsdk;
|
||||
|
||||
|
||||
import android.location.Location;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.location.LocationSource;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
|
||||
|
||||
class EmptyLocationSource extends LocationSource {
|
||||
|
||||
/**
|
||||
* Activate the location engine which will connect whichever location provider you are using. You'll need to call
|
||||
* this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
|
||||
*/
|
||||
@Override
|
||||
public void activate() {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect the location engine which is useful when you no longer need location updates or requesting the users
|
||||
* {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates
|
||||
* using {@link LocationEngine#removeLocationUpdates()}.
|
||||
*/
|
||||
@Override
|
||||
public void deactivate() {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if your location provider has been activated/connected. This is mainly used internally but is also useful in
|
||||
* the rare case when you'd like to know if your location engine is connected or not.
|
||||
*
|
||||
* @return boolean true if the location engine has been activated/connected, else false.
|
||||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Last known location is the location provider is connected and location permissions are granted.
|
||||
*
|
||||
* @return the last known location
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Location getLastLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request location updates to the location provider.
|
||||
*/
|
||||
@Override
|
||||
public void requestLocationUpdates() {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss ongoing location update to the location provider.
|
||||
*/
|
||||
@Override
|
||||
public void removeLocationUpdates() {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the Location has changed.
|
||||
*
|
||||
* @param location the new location
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Useful when you'd like to add a location listener to handle location connections and update events. It is important
|
||||
* to note, that the callback will continue getting called even when your application isn't in the foreground.
|
||||
* Therefore, it is a good idea to use {@link LocationEngine#removeLocationEngineListener(LocationEngineListener)}
|
||||
* inside your activities {@code onStop()} method.
|
||||
*
|
||||
* @param listener A {@link LocationEngineListener} which you'd like to add to your location engine.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Override
|
||||
public void addLocationEngineListener(LocationEngineListener listener) {
|
||||
// Intentionally left empty
|
||||
}
|
||||
|
||||
/**
|
||||
* If you no longer need your {@link LocationEngineListener} to be invoked with every location update, use this
|
||||
* method to remove it. It's also important to remove your listeners before the activity is destroyed to prevent any
|
||||
* potential memory leaks.
|
||||
*
|
||||
* @param listener the {@link LocationEngineListener} you'd like to remove from this {@link LocationEngine}.
|
||||
* @return true.
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Override
|
||||
public boolean removeLocationEngineListener(LocationEngineListener listener) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,16 +8,12 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.UiThread;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEnginePriority;
|
||||
import com.mapbox.android.core.location.LocationEngineProvider;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
|
||||
import com.mapbox.mapboxsdk.location.LocationSource;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngineProvider;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* The entry point to initialize the Mapbox Android SDK.
|
||||
@@ -56,15 +52,9 @@ public final class Mapbox {
|
||||
INSTANCE = new Mapbox(appContext, accessToken, locationEngine);
|
||||
locationEngine.setPriority(LocationEnginePriority.NO_POWER);
|
||||
|
||||
try {
|
||||
MapboxTelemetry.getInstance().initialize(
|
||||
appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT, locationEngine);
|
||||
} catch (Exception exception) {
|
||||
Timber.e(exception, "Unable to instantiate Mapbox telemetry");
|
||||
}
|
||||
|
||||
ConnectivityReceiver.instance(appContext);
|
||||
}
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@@ -145,23 +135,12 @@ public final class Mapbox {
|
||||
return (activeNetwork != null && activeNetwork.isConnected());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a location source instance with empty methods.
|
||||
*
|
||||
* @return an empty location source implementation
|
||||
* @deprecated Replaced by {@link Mapbox#getLocationEngine()}
|
||||
*/
|
||||
@Deprecated
|
||||
public static LocationSource getLocationSource() {
|
||||
return new EmptyLocationSource();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the location engine used by the SDK.
|
||||
*
|
||||
* @return the location engine configured
|
||||
*/
|
||||
// TODO Do we need to expose this?
|
||||
public static LocationEngine getLocationEngine() {
|
||||
return INSTANCE.locationEngine;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import android.support.annotation.FloatRange;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.services.android.telemetry.utils.MathUtils;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
|
||||
/**
|
||||
* Resembles the position, angle, zoom and tilt of the user's viewpoint.
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
|
||||
import com.mapzen.android.lost.api.LocationListener;
|
||||
import com.mapzen.android.lost.api.LocationRequest;
|
||||
import com.mapzen.android.lost.api.LocationServices;
|
||||
import com.mapzen.android.lost.api.LostApiClient;
|
||||
|
||||
/**
|
||||
* LocationEngine using the Open Source Lost library
|
||||
* Manages locational updates. Contains methods to register and unregister location listeners.
|
||||
* <ul>
|
||||
* <li>You can register a LocationEngineListener with LocationSource#addLocationEngineListener(LocationEngineListener)
|
||||
* to receive location updates.</li>
|
||||
* <li> You can unregister a LocationEngineListener with
|
||||
* LocationEngine#removeLocationEngineListener(LocationEngineListener)} to stop receiving location updates.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in
|
||||
* Activity.onStop(). (You won't receive location updates when paused, and this will cut down on unnecessary system
|
||||
* overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back
|
||||
* in the history stack.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated Use a {@link Mapbox#getLocationEngine()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LocationSource extends LocationEngine implements LostApiClient.ConnectionCallbacks, LocationListener {
|
||||
|
||||
private Context context;
|
||||
private LostApiClient lostApiClient;
|
||||
|
||||
/**
|
||||
* Constructs a location source instance.
|
||||
*
|
||||
* @param context the context from which the Application context will be derived.
|
||||
*/
|
||||
public LocationSource(Context context) {
|
||||
super();
|
||||
this.context = context.getApplicationContext();
|
||||
lostApiClient = new LostApiClient.Builder(this.context)
|
||||
.addConnectionCallbacks(this)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a location source instance.
|
||||
* Needed to create empty location source implementations.
|
||||
*/
|
||||
public LocationSource() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the location engine which will connect whichever location provider you are using. You'll need to call
|
||||
* this before requesting user location updates using {@link LocationEngine#requestLocationUpdates()}.
|
||||
*/
|
||||
@Override
|
||||
public void activate() {
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect the location engine which is useful when you no longer need location updates or requesting the users
|
||||
* {@link LocationEngine#getLastLocation()}. Before deactivating, you'll need to stop request user location updates
|
||||
* using {@link LocationEngine#removeLocationUpdates()}.
|
||||
*/
|
||||
@Override
|
||||
public void deactivate() {
|
||||
if (lostApiClient != null && lostApiClient.isConnected()) {
|
||||
lostApiClient.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if your location provider has been activated/connected. This is mainly used internally but is also useful in
|
||||
* the rare case when you'd like to know if your location engine is connected or not.
|
||||
*
|
||||
* @return boolean true if the location engine has been activated/connected, else false.
|
||||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return lostApiClient.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the location provider has connected.
|
||||
*/
|
||||
@Override
|
||||
public void onConnected() {
|
||||
for (LocationEngineListener listener : locationListeners) {
|
||||
listener.onConnected();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the location provider connection has been suspended.
|
||||
*/
|
||||
@Override
|
||||
public void onConnectionSuspended() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Last known location is the location provider is connected and location permissions are granted.
|
||||
*
|
||||
* @return the last known location
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Location getLastLocation() {
|
||||
if (lostApiClient.isConnected()) {
|
||||
//noinspection MissingPermission
|
||||
return LocationServices.FusedLocationApi.getLastLocation(lostApiClient);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request location updates to the location provider.
|
||||
*/
|
||||
@Override
|
||||
public void requestLocationUpdates() {
|
||||
LocationRequest request = LocationRequest.create();
|
||||
|
||||
if (interval != null) {
|
||||
request.setInterval(interval);
|
||||
}
|
||||
if (fastestInterval != null) {
|
||||
request.setFastestInterval(fastestInterval);
|
||||
}
|
||||
if (smallestDisplacement != null) {
|
||||
request.setSmallestDisplacement(smallestDisplacement);
|
||||
}
|
||||
|
||||
if (priority == LocationEnginePriority.NO_POWER) {
|
||||
request.setPriority(LocationRequest.PRIORITY_NO_POWER);
|
||||
} else if (priority == LocationEnginePriority.LOW_POWER) {
|
||||
request.setPriority(LocationRequest.PRIORITY_LOW_POWER);
|
||||
} else if (priority == LocationEnginePriority.BALANCED_POWER_ACCURACY) {
|
||||
request.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
|
||||
} else if (priority == LocationEnginePriority.HIGH_ACCURACY) {
|
||||
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
}
|
||||
|
||||
if (lostApiClient.isConnected()) {
|
||||
//noinspection MissingPermission
|
||||
LocationServices.FusedLocationApi.requestLocationUpdates(lostApiClient, request, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss ongoing location update to the location provider.
|
||||
*/
|
||||
@Override
|
||||
public void removeLocationUpdates() {
|
||||
if (lostApiClient.isConnected()) {
|
||||
LocationServices.FusedLocationApi.removeLocationUpdates(lostApiClient, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location engine type.
|
||||
*
|
||||
* @return Lost type
|
||||
*/
|
||||
@Override
|
||||
public Type obtainType() {
|
||||
return Type.LOST;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the Location has changed.
|
||||
*
|
||||
* @param location the new location
|
||||
*/
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
for (LocationEngineListener listener : locationListeners) {
|
||||
listener.onLocationChanged(location);
|
||||
}
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
if (lostApiClient != null) {
|
||||
if (lostApiClient.isConnected()) {
|
||||
onConnected();
|
||||
} else {
|
||||
lostApiClient.connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Contains the Mapbox Maps Android Location API classes.
|
||||
*/
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
@@ -16,7 +16,6 @@ import com.mapbox.mapboxsdk.attribution.Attribution;
|
||||
import com.mapbox.mapboxsdk.attribution.AttributionParser;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -88,7 +87,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
|
||||
builder.setPositiveButton(R.string.mapbox_attributionTelemetryPositive, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MapboxTelemetry.getInstance().setTelemetryEnabled(true);
|
||||
Events.obtainTelemetry().enable();
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
@@ -102,7 +101,7 @@ public class AttributionDialogManager implements View.OnClickListener, DialogInt
|
||||
builder.setNegativeButton(R.string.mapbox_attributionTelemetryNegative, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MapboxTelemetry.getInstance().setTelemetryEnabled(false);
|
||||
Events.obtainTelemetry().disable();
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
|
||||
import com.mapbox.android.telemetry.MapboxTelemetry;
|
||||
import com.mapbox.android.telemetry.TelemetryEnabler;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
|
||||
class Events {
|
||||
static final String TWO_FINGER_TAP = "TwoFingerTap";
|
||||
static final String DOUBLE_TAP = "DoubleTap";
|
||||
static final String SINGLE_TAP = "SingleTap";
|
||||
static final String PAN = "Pan";
|
||||
static final String PINCH = "Pinch";
|
||||
static final String ROTATION = "Rotation";
|
||||
static final String PITCH = "Pitch";
|
||||
private MapboxTelemetry telemetry;
|
||||
|
||||
private Events() {
|
||||
telemetry = new MapboxTelemetry(Mapbox.getApplicationContext(), Mapbox.getAccessToken(),
|
||||
BuildConfig.MAPBOX_EVENTS_USER_AGENT);
|
||||
TelemetryEnabler.State telemetryState = TelemetryEnabler.retrieveTelemetryStateFromPreferences();
|
||||
if (TelemetryEnabler.State.NOT_INITIALIZED.equals(telemetryState)
|
||||
|| TelemetryEnabler.State.ENABLED.equals(telemetryState)) {
|
||||
telemetry.enable();
|
||||
}
|
||||
}
|
||||
|
||||
private static class EventsHolder {
|
||||
private static final Events INSTANCE = new Events();
|
||||
}
|
||||
|
||||
static MapboxTelemetry obtainTelemetry() {
|
||||
return EventsHolder.INSTANCE.telemetry;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.PointF;
|
||||
import android.location.Location;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.GestureDetectorCompat;
|
||||
import android.support.v4.view.ScaleGestureDetectorCompat;
|
||||
@@ -19,12 +18,12 @@ import android.view.ViewConfiguration;
|
||||
import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector;
|
||||
import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector;
|
||||
import com.mapbox.android.telemetry.Event;
|
||||
import com.mapbox.android.telemetry.MapEventFactory;
|
||||
import com.mapbox.android.telemetry.MapState;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.services.android.telemetry.MapboxEvent;
|
||||
import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
import com.mapbox.services.android.telemetry.utils.MathUtils;
|
||||
import com.mapbox.services.android.telemetry.utils.TelemetryUtils;
|
||||
import com.mapbox.mapboxsdk.utils.MathUtils;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -144,19 +143,6 @@ final class MapGestureDetector {
|
||||
return focalPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given coordinates from a gesture, use the current projection to translate it into
|
||||
* a Location object.
|
||||
*
|
||||
* @param x coordinate
|
||||
* @param y coordinate
|
||||
* @return location
|
||||
*/
|
||||
private Location getLocationFromGesture(float x, float y) {
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(x, y));
|
||||
return TelemetryUtils.buildLocation(latLng.getLongitude(), latLng.getLatitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when user touches the screen, all positions are absolute.
|
||||
* <p>
|
||||
@@ -202,9 +188,13 @@ final class MapGestureDetector {
|
||||
&& uiSettings.isZoomGesturesEnabled();
|
||||
if (twoTap) {
|
||||
// Confirmed 2nd Finger Down
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(event.getX(), event.getY()),
|
||||
MapboxEvent.GESTURE_TWO_FINGER_SINGLETAP, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(event.getX(), event.getY()));
|
||||
MapState twoFingerTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
twoFingerTap.setGesture(Events.TWO_FINGER_TAP);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, twoFingerTap));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -233,8 +223,12 @@ final class MapGestureDetector {
|
||||
|
||||
// Scroll / Pan Has Stopped
|
||||
if (scrollGestureOccurred) {
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapDragEndEvent(
|
||||
getLocationFromGesture(event.getX(), event.getY()), transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(event.getX(), event.getY()));
|
||||
MapState dragend = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_DRAGEND, dragend));
|
||||
}
|
||||
scrollGestureOccurred = false;
|
||||
|
||||
if (!scaleAnimating && !rotateAnimating) {
|
||||
@@ -350,9 +344,13 @@ final class MapGestureDetector {
|
||||
// Zoom in on gesture
|
||||
transform.zoom(true, new PointF(e.getX(), e.getY()));
|
||||
}
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(e.getX(), e.getY()),
|
||||
MapboxEvent.GESTURE_DOUBLETAP, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(e.getX(), e.getY()));
|
||||
MapState doubleTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
doubleTap.setGesture(Events.DOUBLE_TAP);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, doubleTap));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -380,9 +378,13 @@ final class MapGestureDetector {
|
||||
notifyOnMapClickListeners(tapPoint);
|
||||
}
|
||||
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(motionEvent.getX(), motionEvent.getY()),
|
||||
MapboxEvent.GESTURE_SINGLETAP, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(motionEvent.getX(), motionEvent.getY()));
|
||||
MapState singleTap = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
singleTap.setGesture(Events.SINGLE_TAP);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, singleTap));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -456,9 +458,13 @@ final class MapGestureDetector {
|
||||
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
|
||||
}
|
||||
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(e1.getX(), e1.getY()),
|
||||
MapboxEvent.GESTURE_PAN_START, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(e1.getX(), e1.getY()));
|
||||
MapState pan = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
pan.setGesture(Events.PAN);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pan));
|
||||
}
|
||||
}
|
||||
|
||||
// reset tracking if needed
|
||||
@@ -541,9 +547,13 @@ final class MapGestureDetector {
|
||||
recentScaleGestureOccurred = true;
|
||||
scalePointBegin = new PointF(detector.getFocusX(), detector.getFocusY());
|
||||
scaleBeginTime = detector.getEventTime();
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
MapboxEvent.GESTURE_PINCH_START, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY()));
|
||||
MapState pinch = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
pinch.setGesture(Events.PINCH);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pinch));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -724,9 +734,13 @@ final class MapGestureDetector {
|
||||
// Also is zoom already started, don't rotate
|
||||
float angle = detector.getRotationDegreesDelta();
|
||||
if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) {
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
MapboxEvent.GESTURE_ROTATION_START, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY()));
|
||||
MapState rotation = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
rotation.setGesture(Events.ROTATION);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, rotation));
|
||||
}
|
||||
started = true;
|
||||
}
|
||||
|
||||
@@ -895,9 +909,13 @@ final class MapGestureDetector {
|
||||
if (!tiltGestureOccurred && ((totalDelta > 10.0f) || (totalDelta < -10.0f))) {
|
||||
tiltGestureOccurred = true;
|
||||
beginTime = detector.getEventTime();
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent(
|
||||
getLocationFromGesture(detector.getFocusX(), detector.getFocusY()),
|
||||
MapboxEvent.GESTURE_PITCH_START, transform));
|
||||
if (isZoomValid(transform)) {
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
LatLng latLng = projection.fromScreenLocation(new PointF(detector.getFocusX(), detector.getFocusY()));
|
||||
MapState pitch = new MapState(latLng.getLatitude(), latLng.getLongitude(), transform.getZoom());
|
||||
pitch.setGesture(Events.PITCH);
|
||||
Events.obtainTelemetry().push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, pitch));
|
||||
}
|
||||
}
|
||||
|
||||
if (!tiltGestureOccurred) {
|
||||
@@ -962,4 +980,15 @@ final class MapGestureDetector {
|
||||
void removeOnScrollListener(MapboxMap.OnScrollListener onScrollListener) {
|
||||
onScrollListenerList.remove(onScrollListener);
|
||||
}
|
||||
|
||||
private boolean isZoomValid(Transform transform) {
|
||||
if (transform == null) {
|
||||
return false;
|
||||
}
|
||||
double mapZoom = transform.getZoom();
|
||||
if (mapZoom < MapboxConstants.MINIMUM_ZOOM || mapZoom > MapboxConstants.MAXIMUM_ZOOM) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ZoomButtonsController;
|
||||
|
||||
import com.mapbox.android.telemetry.AppUserTurnstile;
|
||||
import com.mapbox.android.telemetry.Event;
|
||||
import com.mapbox.android.telemetry.MapEventFactory;
|
||||
import com.mapbox.android.telemetry.MapboxTelemetry;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.annotations.Annotation;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerViewManager;
|
||||
@@ -36,7 +41,6 @@ import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationViewSettings;
|
||||
import com.mapbox.mapboxsdk.net.ConnectivityReceiver;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.services.android.telemetry.MapboxTelemetry;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -285,7 +289,12 @@ public class MapView extends FrameLayout {
|
||||
@UiThread
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (savedInstanceState == null) {
|
||||
MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapLoadEvent());
|
||||
MapboxTelemetry telemetry = Events.obtainTelemetry();
|
||||
AppUserTurnstile turnstileEvent = new AppUserTurnstile(BuildConfig.MAPBOX_SDK_IDENTIFIER,
|
||||
BuildConfig.MAPBOX_SDK_VERSION);
|
||||
telemetry.push(turnstileEvent);
|
||||
MapEventFactory mapEventFactory = new MapEventFactory();
|
||||
telemetry.push(mapEventFactory.createMapLoadEvent(Event.Type.MAP_LOAD));
|
||||
} else if (savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) {
|
||||
this.savedInstanceState = savedInstanceState;
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.location.Location;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.services.android.telemetry.MapboxEvent;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* Wrapper class for MapboxEvent
|
||||
* <p>
|
||||
* Provides facility methods to use Transform and handle the case that the zoom, required for a telemetry event,
|
||||
* isn't available yet.
|
||||
* </p>
|
||||
*/
|
||||
class MapboxEventWrapper {
|
||||
|
||||
@Nullable
|
||||
static Hashtable<String, Object> buildMapClickEvent(
|
||||
@NonNull Location location, @NonNull String gestureId, Transform transform) {
|
||||
try {
|
||||
double mapZoom = transform.getZoom();
|
||||
if (mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM) {
|
||||
// validate zoom #8057
|
||||
return MapboxEvent.buildMapClickEvent(location, gestureId, transform.getZoom());
|
||||
}
|
||||
} catch (NullPointerException exception) {
|
||||
// Map/Transform is not ready yet #8650
|
||||
// returning null is valid, event is ignored.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Hashtable<String, Object> buildMapDragEndEvent(
|
||||
@NonNull Location location, Transform transform) {
|
||||
try {
|
||||
double mapZoom = transform.getZoom();
|
||||
if (mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM) {
|
||||
// validate zoom #8057
|
||||
return MapboxEvent.buildMapDragEndEvent(location, transform.getZoom());
|
||||
}
|
||||
} catch (NullPointerException exception) {
|
||||
// Map/Transform is not ready yet #8650
|
||||
// returning null is valid, event is ignored.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static Hashtable<String, Object> buildMapLoadEvent() {
|
||||
return MapboxEvent.buildMapLoadEvent();
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ import com.mapbox.mapboxsdk.style.layers.Filter;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.light.Light;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -12,9 +12,9 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
|
||||
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.maps.widgets.MyLocationView;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
|
||||
import com.mapbox.services.android.telemetry.permissions.PermissionsManager;
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ import com.mapbox.mapboxsdk.constants.MyLocationTracking;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Projection;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngine;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEngineListener;
|
||||
import com.mapbox.services.android.telemetry.location.LocationEnginePriority;
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineListener;
|
||||
import com.mapbox.android.core.location.LocationEnginePriority;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class GeoJsonOptions extends HashMap<String, Object> {
|
||||
/**
|
||||
* Maximum zoom level at which to create vector tiles (higher means greater detail at high zoom levels).
|
||||
*
|
||||
* @param maxZoom the maximum zoom - Defaults to 18.
|
||||
* @param minZoom the maximum zoom - Defaults to 18.
|
||||
* @return the current instance for chaining
|
||||
*/
|
||||
public GeoJsonOptions withMinZoom(int minZoom) {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.mapbox.mapboxsdk.utils;
|
||||
|
||||
// TODO Remove this class if we finally include it within MAS 3.x (GeoJSON)
|
||||
public class MathUtils {
|
||||
|
||||
/**
|
||||
* Test a value in specified range, returning minimum if it's below, and maximum if it's above
|
||||
*
|
||||
* @param value Value to test
|
||||
* @param min Minimum value of range
|
||||
* @param max Maximum value of range
|
||||
* @return value if it's between min and max, min if it's below, max if it's above
|
||||
*/
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a value in specified range, returning minimum if it's below, and maximum if it's above
|
||||
*
|
||||
* @param value Value to test
|
||||
* @param min Minimum value of range
|
||||
* @param max Maximum value of range
|
||||
* @return value if it's between min and max, min if it's below, max if it's above
|
||||
*/
|
||||
public static float clamp(float value, float min, float max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constrains value to the given range (including min, excluding max) via modular arithmetic.
|
||||
* <p>
|
||||
* Same formula as used in Core GL (wrap.hpp)
|
||||
* std::fmod((std::fmod((value - min), d) + d), d) + min;
|
||||
*
|
||||
* @param value Value to wrap
|
||||
* @param min Minimum value
|
||||
* @param max Maximum value
|
||||
* @return Wrapped value
|
||||
*/
|
||||
public static double wrap(double value, double min, double max) {
|
||||
double delta = max - min;
|
||||
|
||||
double firstMod = (value - min) % delta;
|
||||
double secondMod = (firstMod + delta) % delta;
|
||||
|
||||
return secondMod + min;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user