[android] - remove internal gesture event handling code, deprecate public gesture event hooks

This commit is contained in:
Tobrun
2019-05-09 21:38:23 +02:00
parent fd527b1d23
commit 947bc75f56
10 changed files with 22 additions and 485 deletions

View File

@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk.constants;
@Deprecated
public class TelemetryConstants {
public static final String TWO_FINGER_TAP = "TwoFingerTap";

View File

@@ -11,21 +11,16 @@ import android.support.annotation.Nullable;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.animation.DecelerateInterpolator;
import com.mapbox.android.gestures.AndroidGesturesManager;
import com.mapbox.android.gestures.Constants;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.MultiFingerTapGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
import com.mapbox.android.gestures.ShoveGestureDetector;
import com.mapbox.android.gestures.StandardGestureDetector;
import com.mapbox.android.gestures.MultiFingerTapGestureDetector;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
import com.mapbox.android.gestures.StandardScaleGestureDetector;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.TelemetryConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MathUtils;
import java.util.ArrayList;
@@ -332,8 +327,6 @@ final class MapGestureDetector {
notifyOnMapClickListeners(tapPoint);
}
sendTelemetryEvent(TelemetryConstants.SINGLE_TAP, new PointF(motionEvent.getX(), motionEvent.getY()));
return true;
}
@@ -368,7 +361,6 @@ final class MapGestureDetector {
zoomInAnimated(zoomFocalPoint, false);
sendTelemetryEvent(TelemetryConstants.DOUBLE_TAP, new PointF(motionEvent.getX(), motionEvent.getY()));
return true;
}
@@ -430,7 +422,6 @@ final class MapGestureDetector {
}
cancelTransitionsIfRequired();
sendTelemetryEvent(TelemetryConstants.PAN, detector.getFocalPoint());
notifyOnMoveBeginListeners(detector);
return true;
}
@@ -497,8 +488,6 @@ final class MapGestureDetector {
);
}
sendTelemetryEvent(TelemetryConstants.PINCH, getScaleFocalPoint(detector));
notifyOnScaleBeginListeners(detector);
return true;
@@ -609,8 +598,6 @@ final class MapGestureDetector {
gesturesManager.getStandardScaleGestureDetector().interrupt();
}
sendTelemetryEvent(TelemetryConstants.ROTATION, getRotateFocalPoint(detector));
notifyOnRotateBeginListeners(detector);
return true;
@@ -725,8 +712,6 @@ final class MapGestureDetector {
cancelTransitionsIfRequired();
sendTelemetryEvent(TelemetryConstants.PITCH, detector.getFocalPoint());
// disabling move gesture during shove
gesturesManager.getMoveGestureDetector().setEnabled(false);
@@ -775,8 +760,6 @@ final class MapGestureDetector {
transform.cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE);
sendTelemetryEvent(TelemetryConstants.TWO_FINGER_TAP, detector.getFocalPoint());
PointF zoomFocalPoint;
// Single finger double tap
if (constantFocalPoint != null) {
@@ -890,20 +873,6 @@ final class MapGestureDetector {
&& (!uiSettings.isTiltGesturesEnabled() || !gesturesManager.getShoveGestureDetector().isInProgress());
}
private void sendTelemetryEvent(String eventType, @NonNull PointF focalPoint) {
TelemetryDefinition telemetry = Mapbox.getTelemetry();
if (telemetry != null) {
CameraPosition cameraPosition = transform.getCameraPosition();
if (cameraPosition != null) {
double zoom = cameraPosition.zoom;
if (isZoomValid(zoom)) {
LatLng latLng = projection.fromScreenLocation(focalPoint);
telemetry.onGestureInteraction(eventType, latLng.getLatitude(), latLng.getLongitude(), zoom);
}
}
}
}
private boolean isZoomValid(double mapZoom) {
return mapZoom >= MapboxConstants.MINIMUM_ZOOM && mapZoom <= MapboxConstants.MAXIMUM_ZOOM;
}

View File

@@ -22,7 +22,9 @@ public interface TelemetryDefinition {
* @param latitude the latitude value of the gesture focal point
* @param longitude the longitude value of the gesture focal point
* @param zoom current zoom of the map
* @deprecated since 7.5.0, this event is no longer supported
*/
@Deprecated
void onGestureInteraction(String eventType, double latitude, double longitude, double zoom);
/**

View File

@@ -1,160 +0,0 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.annotation.SuppressLint;
/**
* Event that represents users' gestures on map, for the details of gestures,
* please refer to {@link com.mapbox.mapboxsdk.constants.TelemetryConstants}
*/
@SuppressLint("ParcelCreator")
class MapClickEvent extends MapBaseEvent {
private static final String EVENT_NAME = "map.click";
private final String gesture;
private final String cellularNetworkType;
private final String carrier;
private final String orientation;
private final double lat;
private final double lng;
private final double zoom;
private final int batteryLevel;
private final boolean pluggedIn;
private final boolean wifi;
MapClickEvent(PhoneState phoneState, MapState mapState) {
super(phoneState);
this.gesture = mapState.getGesture();
this.lat = mapState.getLatitude();
this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.batteryLevel = phoneState.getBatteryLevel();
this.pluggedIn = phoneState.isPluggedIn();
this.cellularNetworkType = phoneState.getCellularNetworkType();
this.orientation = phoneState.getOrientation();
this.carrier = phoneState.getCarrier();
this.wifi = phoneState.isWifi();
}
@Override
String getEventName() {
return EVENT_NAME;
}
String getGesture() {
return gesture;
}
String getCellularNetworkType() {
return cellularNetworkType;
}
String getCarrier() {
return carrier;
}
String getOrientation() {
return orientation;
}
double getLat() {
return lat;
}
double getLng() {
return lng;
}
double getZoom() {
return zoom;
}
int getBatteryLevel() {
return batteryLevel;
}
boolean isPluggedIn() {
return pluggedIn;
}
boolean isWifi() {
return wifi;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MapClickEvent that = (MapClickEvent) o;
if (Double.compare(that.lat, lat) != 0) {
return false;
}
if (Double.compare(that.lng, lng) != 0) {
return false;
}
if (Double.compare(that.zoom, zoom) != 0) {
return false;
}
if (batteryLevel != that.batteryLevel) {
return false;
}
if (pluggedIn != that.pluggedIn) {
return false;
}
if (wifi != that.wifi) {
return false;
}
if (gesture != null ? !gesture.equals(that.gesture) : that.gesture != null) {
return false;
}
if (cellularNetworkType != null ? !cellularNetworkType.equals(that.cellularNetworkType) :
that.cellularNetworkType != null) {
return false;
}
if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) {
return false;
}
return orientation != null ? orientation.equals(that.orientation) : that.orientation == null;
}
@Override
public int hashCode() {
int result;
long temp;
result = gesture != null ? gesture.hashCode() : 0;
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (orientation != null ? orientation.hashCode() : 0);
temp = Double.doubleToLongBits(lat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(lng);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + batteryLevel;
result = 31 * result + (pluggedIn ? 1 : 0);
result = 31 * result + (wifi ? 1 : 0);
return result;
}
@Override
public String toString() {
return "MapClickEvent{"
+ ", gesture='" + gesture + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
+ ", carrier='" + carrier + '\''
+ ", orientation='" + orientation + '\''
+ ", lat=" + lat
+ ", lng=" + lng
+ ", zoom=" + zoom
+ ", batteryLevel=" + batteryLevel
+ ", pluggedIn=" + pluggedIn
+ ", wifi=" + wifi
+ '}';
}
}

View File

@@ -1,147 +0,0 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.annotation.SuppressLint;
/**
* When user drag map should send this event.
*/
@SuppressLint("ParcelCreator")
class MapDragendEvent extends MapBaseEvent {
private static final String EVENT_NAME = "map.dragend";
private final String orientation;
private final String carrier;
private final String cellularNetworkType;
private final int batteryLevel;
private final double lat;
private final double lng;
private final double zoom;
private final boolean pluggedIn;
private final boolean wifi;
MapDragendEvent(PhoneState phoneState, MapState mapState) {
super(phoneState);
this.lat = mapState.getLatitude();
this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.batteryLevel = phoneState.getBatteryLevel();
this.pluggedIn = phoneState.isPluggedIn();
this.cellularNetworkType = phoneState.getCellularNetworkType();
this.wifi = phoneState.isWifi();
this.orientation = phoneState.getOrientation();
this.carrier = phoneState.getCarrier();
}
@Override
String getEventName() {
return EVENT_NAME;
}
String getOrientation() {
return orientation;
}
String getCarrier() {
return carrier;
}
String getCellularNetworkType() {
return cellularNetworkType;
}
int getBatteryLevel() {
return batteryLevel;
}
double getLat() {
return lat;
}
double getLng() {
return lng;
}
double getZoom() {
return zoom;
}
boolean isPluggedIn() {
return pluggedIn;
}
boolean isWifi() {
return wifi;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MapDragendEvent that = (MapDragendEvent) o;
if (batteryLevel != that.batteryLevel) {
return false;
}
if (Double.compare(that.lat, lat) != 0) {
return false;
}
if (Double.compare(that.lng, lng) != 0) {
return false;
}
if (Double.compare(that.zoom, zoom) != 0) {
return false;
}
if (pluggedIn != that.pluggedIn) {
return false;
}
if (wifi != that.wifi) {
return false;
}
if (orientation != null ? !orientation.equals(that.orientation) : that.orientation != null) {
return false;
}
if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) {
return false;
}
return cellularNetworkType != null ? cellularNetworkType.equals(that.cellularNetworkType) :
that.cellularNetworkType == null;
}
@Override
public int hashCode() {
int result;
long temp;
result = orientation != null ? orientation.hashCode() : 0;
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + batteryLevel;
temp = Double.doubleToLongBits(lat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(lng);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (pluggedIn ? 1 : 0);
result = 31 * result + (wifi ? 1 : 0);
return result;
}
@Override
public String toString() {
return "MapDragendEvent{"
+ ", orientation='" + orientation + '\''
+ ", carrier='" + carrier + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
+ ", batteryLevel=" + batteryLevel
+ ", lat=" + lat
+ ", lng=" + lng
+ ", zoom=" + zoom
+ ", pluggedIn=" + pluggedIn
+ ", wifi=" + wifi
+ '}';
}
}

View File

@@ -49,17 +49,9 @@ class MapEventFactory {
return offlineEvent;
}
static MapClickEvent buildMapClickEvent(@NonNull PhoneState phoneState, @NonNull MapState mapState) {
return new MapClickEvent(phoneState, mapState);
}
static MapDragendEvent buildMapDragendEvent(@NonNull PhoneState phoneState, @NonNull MapState mapState) {
return new MapDragendEvent(phoneState, mapState);
}
static PerformanceEvent buildPerformanceEvent(@NonNull PhoneState phoneState, @NonNull String sessionId,
@NonNull Bundle data) {
return new PerformanceEvent(phoneState, sessionId, data);
}
}
}

View File

@@ -1,40 +0,0 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.support.annotation.FloatRange;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
public class MapState {
private double latitude;
private double longitude;
private double zoom;
private String gesture;
MapState(double latitude, double longitude, @FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
this.latitude = latitude;
this.longitude = longitude;
this.zoom = zoom;
}
String getGesture() {
return gesture;
}
void setGesture(String gesture) {
this.gesture = gesture;
}
double getLatitude() {
return latitude;
}
double getLongitude() {
return longitude;
}
double getZoom() {
return zoom;
}
}

View File

@@ -55,18 +55,20 @@ public class TelemetryImpl implements TelemetryDefinition {
* @param latitude the latitude value of the gesture focal point
* @param longitude the longitude value of the gesture focal point
* @param zoom current zoom of the map
* @deprecated since 7.5.0, this event is no longer supported
*/
@Deprecated
@Override
public void onGestureInteraction(String eventType, double latitude, double longitude,
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
to = MapboxConstants.MAXIMUM_ZOOM) double zoom) {
MapState state = new MapState(latitude, longitude, zoom);
state.setGesture(eventType);
telemetry.push(MapEventFactory.buildMapClickEvent(new PhoneState(appContext), state));
//no-op
}
/**
* Set the end-user selected state to participate or opt-out in telemetry collection.
*
* @param enabledTelemetry true if enabled, false otherwise
*/
@Override
public void setUserTelemetryRequestState(boolean enabledTelemetry) {
@@ -100,6 +102,11 @@ public class TelemetryImpl implements TelemetryDefinition {
return telemetry.updateSessionIdRotationInterval(new SessionInterval(interval));
}
/**
* Register an offline region creation event.
*
* @param offlineDefinition the offline region definition
*/
@Override
public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefinition) {
telemetry.push(MapEventFactory.buildOfflineDownloadStartEvent(new PhoneState(appContext),
@@ -110,6 +117,11 @@ public class TelemetryImpl implements TelemetryDefinition {
);
}
/**
* Register a performance event
*
* @param data performance event data
*/
@Override
public void onPerformanceEvent(Bundle data) {
if (data == null) {