Add map events

This commit is contained in:
kevin
2019-04-04 13:46:01 +08:00
committed by Łukasz Paczos
parent 023b314a99
commit 55c8abfc61
8 changed files with 665 additions and 111 deletions

View File

@@ -0,0 +1,122 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;
class MapClickEvent extends Event implements Parcelable {
private static final String MAP_CLICK = "map.click";
@SerializedName("event")
private final String event;
@SerializedName("created")
private String created;
@SerializedName("gesture")
private final String gesture;
@SerializedName("lat")
private double latitude;
@SerializedName("lng")
private double longitude;
@SerializedName("zoom")
private double zoom;
@SerializedName("orientation")
private String orientation = null;
@SerializedName("batteryLevel")
private Integer batteryLevel;
@SerializedName("pluggedIn")
private Boolean pluggedIn;
@SerializedName("carrier")
private String carrier = null;
@SerializedName("cellularNetworkType")
private String cellularNetworkType;
@SerializedName("wifi")
private Boolean wifi = null;
MapClickEvent(MapState mapState) {
this.event = MAP_CLICK;
this.gesture = mapState.getGesture();
this.latitude = mapState.getLatitude();
this.longitude = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.created = TelemetryUtils.obtainCurrentDate();
this.batteryLevel = 0;
this.pluggedIn = false;
this.cellularNetworkType = "";
}
MapClickEvent setDeviceInfo(Context context) {
this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
this.pluggedIn = TelemetryUtils.isPluggedIn(context);
this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
return this;
}
void setOrientation(String orientation) {
this.orientation = orientation;
}
void setCarrier(String carrier) {
this.carrier = carrier;
}
void setWifi(boolean wifi) {
this.wifi = wifi;
}
private MapClickEvent(Parcel in) {
event = in.readString();
created = in.readString();
gesture = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
zoom = in.readDouble();
orientation = in.readString();
batteryLevel = in.readInt();
pluggedIn = in.readByte() != 0x00;
carrier = in.readString();
cellularNetworkType = in.readString();
byte wifiVal = in.readByte();
wifi = wifiVal == 0x02 ? null : wifiVal != 0x00;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(event);
dest.writeString(created);
dest.writeString(gesture);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeDouble(zoom);
dest.writeString(orientation);
dest.writeInt(batteryLevel);
dest.writeByte((byte) (pluggedIn ? 0x01 : 0x00));
dest.writeString(carrier);
dest.writeString(cellularNetworkType);
if (wifi == null) {
dest.writeByte((byte) (0x02));
} else {
dest.writeByte((byte) (wifi ? 0x01 : 0x00));
}
}
public static final Creator<MapClickEvent> CREATOR = new Creator<MapClickEvent>() {
@Override
public MapClickEvent createFromParcel(Parcel in) {
return new MapClickEvent(in);
}
@Override
public MapClickEvent[] newArray(int size) {
return new MapClickEvent[size];
}
};
}

View File

@@ -0,0 +1,117 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;
class MapDragendEvent extends Event implements Parcelable {
private static final String MAP_DRAGEND = "map.dragend";
@SerializedName("event")
private final String event;
@SerializedName("created")
private String created;
@SerializedName("lat")
private double latitude;
@SerializedName("lng")
private double longitude;
@SerializedName("zoom")
private double zoom;
@SerializedName("orientation")
private String orientation = null;
@SerializedName("batteryLevel")
private int batteryLevel;
@SerializedName("pluggedIn")
private Boolean pluggedIn;
@SerializedName("carrier")
private String carrier = null;
@SerializedName("cellularNetworkType")
private String cellularNetworkType;
@SerializedName("wifi")
private Boolean wifi = null;
MapDragendEvent(MapState mapState) {
this.event = MAP_DRAGEND;
this.latitude = mapState.getLatitude();
this.longitude = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.created = TelemetryUtils.obtainCurrentDate();
this.batteryLevel = 0;
this.pluggedIn = false;
this.cellularNetworkType = "";
}
MapDragendEvent setDeviceInfo(Context context) {
this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
this.pluggedIn = TelemetryUtils.isPluggedIn(context);
this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
return this;
}
void setOrientation(String orientation) {
this.orientation = orientation;
}
void setCarrier(String carrier) {
this.carrier = carrier;
}
void setWifi(boolean wifi) {
this.wifi = wifi;
}
private MapDragendEvent(Parcel in) {
event = in.readString();
created = in.readString();
latitude = in.readDouble();
longitude = in.readDouble();
zoom = in.readDouble();
orientation = in.readString();
batteryLevel = in.readInt();
pluggedIn = in.readByte() != 0x00;
carrier = in.readString();
cellularNetworkType = in.readString();
byte wifiVal = in.readByte();
wifi = wifiVal == 0x02 ? null : wifiVal != 0x00;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(event);
dest.writeString(created);
dest.writeDouble(latitude);
dest.writeDouble(longitude);
dest.writeDouble(zoom);
dest.writeString(orientation);
dest.writeInt(batteryLevel);
dest.writeByte((byte) (pluggedIn ? 0x01 : 0x00));
dest.writeString(carrier);
dest.writeString(cellularNetworkType);
if (wifi == null) {
dest.writeByte((byte) (0x02));
} else {
dest.writeByte((byte) (wifi ? 0x01 : 0x00));
}
}
public static final Creator<MapDragendEvent> CREATOR = new Creator<MapDragendEvent>() {
@Override
public MapDragendEvent createFromParcel(Parcel in) {
return new MapDragendEvent(in);
}
@Override
public MapDragendEvent[] newArray(int size) {
return new MapDragendEvent[size];
}
};
}

View File

@@ -4,36 +4,23 @@ import android.content.Context;
import android.content.res.Configuration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.support.annotation.NonNull;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.MapBuildEvent;
import com.mapbox.android.telemetry.MapClickEvent;
import com.mapbox.android.telemetry.MapDragendEvent;
import com.mapbox.android.telemetry.MapLoadEvent;
import com.mapbox.android.telemetry.MapState;
import com.mapbox.android.telemetry.MapboxTelemetry;
import com.mapbox.android.telemetry.OfflineDownloadEndEvent;
import com.mapbox.android.telemetry.OfflineDownloadStartEvent;
import com.mapbox.android.telemetry.TelemetryUtils;
import java.util.HashMap;
import java.util.Map;
public class MapEventFactory {
private static final String APPLICATION_CONTEXT_CANT_BE_NULL = "Create a MapboxTelemetry instance before calling "
+ "this method.";
private static final String LANDSCAPE = "Landscape";
private static final String PORTRAIT = "Portrait";
private static final String NO_CARRIER = "EMPTY_CARRIER";
private static final int NO_NETWORK = -1;
private static final String NOT_A_LOAD_MAP_EVENT_TYPE = "Type must be a load map event.";
private static final String NOT_A_GESTURE_MAP_EVENT_TYPE = "Type must be a gesture map event.";
private static final String NOT_OFFLINEDOWNLOAD_EVENT_TYPE = "Type must be an offline download map event.";
private static final String MAP_STATE_ILLEGAL_NULL = "MapState cannot be null.";
private static final Map<Integer, String> ORIENTATIONS = new HashMap<Integer, String>() {
{
@@ -41,42 +28,27 @@ public class MapEventFactory {
put(Configuration.ORIENTATION_PORTRAIT, PORTRAIT);
}
};
private final Map<Event.Type, MapBuildEvent> BUILD_EVENT_MAP_GESTURE = new HashMap<Event.Type, MapBuildEvent>() {
{
put(Event.Type.MAP_CLICK, new MapBuildEvent() {
@Override
public Event build(MapState mapState) {
return buildMapClickEvent(mapState);
}
});
put(Event.Type.MAP_DRAGEND, new MapBuildEvent() {
@Override
public Event build(MapState mapState) {
return buildMapDragendEvent(mapState);
}
});
}
};
public MapEventFactory() {
if (MapboxTelemetry.applicationContext == null) {
throw new IllegalStateException(APPLICATION_CONTEXT_CANT_BE_NULL);
}
private final Context appContext;
MapEventFactory(Context appContext) {
this.appContext = appContext;
}
public Event createMapLoadEvent(Event.Type type) {
checkLoad(type);
return buildMapLoadEvent();
Event buildMapLoadEvent() {
String userId = TelemetryUtils.retrieveVendorId();
MapLoadEvent mapLoadEvent = new MapLoadEvent(userId).setDeviceInfo(appContext);
mapLoadEvent.setOrientation(obtainOrientation(appContext));
mapLoadEvent.setAccessibilityFontScale(obtainAccessibilityFontScaleSize(appContext));
mapLoadEvent.setCarrier(obtainCellularCarrier(appContext));
mapLoadEvent.setResolution(obtainDisplayDensity(appContext));
mapLoadEvent.setWifi(isConnectedToWifi(appContext));
return mapLoadEvent;
}
public Event createMapGestureEvent(Event.Type type, MapState mapState) {
checkGesture(type, mapState);
return BUILD_EVENT_MAP_GESTURE.get(type).build(mapState);
}
public Event createOfflineDownloadStartEvent(String shapeForOfflineRegion,
Double minZoom, Double maxZoom,
String styleURL) {
Event buildOfflineDownloadStartEvent(String shapeForOfflineRegion,
Double minZoom, Double maxZoom,
String styleURL) {
OfflineDownloadStartEvent offlineEvent =
new OfflineDownloadStartEvent(shapeForOfflineRegion, minZoom, maxZoom);
@@ -84,12 +56,12 @@ public class MapEventFactory {
return offlineEvent;
}
public Event createOfflineDownloadCompleteEvent(String shapeForOfflineRegion,
Double minZoom, Double maxZoom,
String styleURL,
Long sizeOfResourcesCompleted,
Long numberOfTilesCompleted,
String state) {
public Event buildOfflineDownloadCompleteEvent(String shapeForOfflineRegion,
Double minZoom, Double maxZoom,
String styleURL,
Long sizeOfResourcesCompleted,
Long numberOfTilesCompleted,
String state) {
OfflineDownloadEndEvent offlineEvent =
new OfflineDownloadEndEvent(shapeForOfflineRegion, minZoom, maxZoom);
@@ -99,20 +71,20 @@ public class MapEventFactory {
return offlineEvent;
}
private MapClickEvent buildMapClickEvent(MapState mapState) {
MapClickEvent mapClickEvent = new MapClickEvent(mapState).setDeviceInfo(MapboxTelemetry.applicationContext);
mapClickEvent.setOrientation(obtainOrientation(MapboxTelemetry.applicationContext));
mapClickEvent.setCarrier(obtainCellularCarrier(MapboxTelemetry.applicationContext));
mapClickEvent.setWifi(obtainConnectedToWifi(MapboxTelemetry.applicationContext));
MapClickEvent buildMapClickEvent(@NonNull MapState mapState) {
MapClickEvent mapClickEvent = new MapClickEvent(mapState).setDeviceInfo(appContext);
mapClickEvent.setOrientation(obtainOrientation(appContext));
mapClickEvent.setCarrier(obtainCellularCarrier(appContext));
mapClickEvent.setWifi(isConnectedToWifi(appContext));
return mapClickEvent;
}
private MapDragendEvent buildMapDragendEvent(MapState mapState) {
MapDragendEvent mapDragendEvent = new MapDragendEvent(mapState).setDeviceInfo(MapboxTelemetry.applicationContext);
mapDragendEvent.setOrientation(obtainOrientation(MapboxTelemetry.applicationContext));
mapDragendEvent.setCarrier(obtainCellularCarrier(MapboxTelemetry.applicationContext));
mapDragendEvent.setWifi(obtainConnectedToWifi(MapboxTelemetry.applicationContext));
MapDragendEvent buildMapDragendEvent(@NonNull MapState mapState) {
MapDragendEvent mapDragendEvent = new MapDragendEvent(mapState).setDeviceInfo(appContext);
mapDragendEvent.setOrientation(obtainOrientation(appContext));
mapDragendEvent.setCarrier(obtainCellularCarrier(appContext));
mapDragendEvent.setWifi(isConnectedToWifi(appContext));
return mapDragendEvent;
}
@@ -127,6 +99,7 @@ public class MapEventFactory {
private String obtainCellularCarrier(Context context) {
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(manager == null) return NO_CARRIER;
String carrierName = manager.getNetworkOperatorName();
if (TextUtils.isEmpty(carrierName)) {
@@ -143,10 +116,6 @@ public class MapEventFactory {
return displayMetrics.density;
}
private Boolean obtainConnectedToWifi(Context context) {
return isConnectedToWifi(context);
}
private boolean isConnectedToWifi(Context context) {
try {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@@ -164,43 +133,7 @@ public class MapEventFactory {
}
private boolean networkConnected(WifiInfo wifiInfo) {
if (wifiInfo.getNetworkId() != NO_NETWORK) {
return true;
}
return false;
return wifiInfo.getNetworkId() != NO_NETWORK;
}
private MapLoadEvent buildMapLoadEvent() {
String userId = TelemetryUtils.retrieveVendorId();
MapLoadEvent mapLoadEvent = new MapLoadEvent(userId).setDeviceInfo(MapboxTelemetry.applicationContext);
mapLoadEvent.setOrientation(obtainOrientation(MapboxTelemetry.applicationContext));
mapLoadEvent.setAccessibilityFontScale(obtainAccessibilityFontScaleSize(MapboxTelemetry.applicationContext));
mapLoadEvent.setCarrier(obtainCellularCarrier(MapboxTelemetry.applicationContext));
mapLoadEvent.setResolution(obtainDisplayDensity(MapboxTelemetry.applicationContext));
mapLoadEvent.setWifi(obtainConnectedToWifi(MapboxTelemetry.applicationContext));
return mapLoadEvent;
}
private void checkLoad(Event.Type type) {
if (type != Event.Type.MAP_LOAD) {
throw new IllegalArgumentException(NOT_A_LOAD_MAP_EVENT_TYPE);
}
}
private void checkGesture(Event.Type type, MapState mapState) {
checkGestureMapEvent(type);
isNotNull(mapState);
}
private void checkGestureMapEvent(Event.Type type) {
if (!Event.mapGestureEventTypes.contains(type)) {
throw new IllegalArgumentException(NOT_A_GESTURE_MAP_EVENT_TYPE);
}
}
private void isNotNull(MapState mapState) {
if (mapState == null) {
throw new IllegalArgumentException(MAP_STATE_ILLEGAL_NULL);
}
}
}

View File

@@ -0,0 +1,162 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.content.Context;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;
class MapLoadEvent extends Event implements Parcelable {
private static final String MAP_LOAD = "map.load";
private static final String OPERATING_SYSTEM = "Android - " + Build.VERSION.RELEASE;
@SerializedName("event")
private final String event;
@SerializedName("created")
private String created;
@SerializedName("userId")
private String userId;
@SerializedName("model")
private String model = null;
@SerializedName("operatingSystem")
private String operatingSystem = null;
@SerializedName("resolution")
private Float resolution = null;
@SerializedName("accessibilityFontScale")
private Float accessibilityFontScale = null;
@SerializedName("orientation")
private String orientation = null;
@SerializedName("batteryLevel")
private Integer batteryLevel;
@SerializedName("pluggedIn")
private Boolean pluggedIn;
@SerializedName("carrier")
private String carrier = null;
@SerializedName("cellularNetworkType")
private String cellularNetworkType;
@SerializedName("wifi")
private Boolean wifi = null;
@SerializedName("sdkIdentifier")
private String sdkIdentifier = null;
@SerializedName("sdkVersion")
private String sdkVersion = null;
MapLoadEvent(String userId) {
this.event = MAP_LOAD;
this.model = Build.MODEL;
this.operatingSystem = OPERATING_SYSTEM;
this.created = TelemetryUtils.obtainCurrentDate();
this.userId = userId;
this.batteryLevel = 0;
this.pluggedIn = false;
this.cellularNetworkType = "";
}
MapLoadEvent setDeviceInfo(Context context) {
this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
this.pluggedIn = TelemetryUtils.isPluggedIn(context);
this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
return this;
}
void setResolution(float resolution) {
this.resolution = resolution;
}
void setAccessibilityFontScale(float accessibilityFontScale) {
this.accessibilityFontScale = accessibilityFontScale;
}
void setOrientation(String orientation) {
this.orientation = orientation;
}
void setCarrier(String carrier) {
this.carrier = carrier;
}
void setWifi(boolean wifi) {
this.wifi = wifi;
}
void setSdkIdentifier(String sdkIdentifier) {
this.sdkIdentifier = sdkIdentifier;
}
void setSdkVersion(String sdkVersion) {
this.sdkVersion = sdkVersion;
}
private MapLoadEvent(Parcel in) {
event = in.readString();
created = in.readString();
userId = in.readString();
model = in.readString();
operatingSystem = in.readString();
resolution = in.readByte() == 0x00 ? null : in.readFloat();
accessibilityFontScale = in.readByte() == 0x00 ? null : in.readFloat();
orientation = in.readString();
batteryLevel = in.readInt();
pluggedIn = in.readByte() != 0x00;
carrier = in.readString();
cellularNetworkType = in.readString();
byte wifiVal = in.readByte();
wifi = wifiVal == 0x02 ? null : wifiVal != 0x00;
sdkIdentifier = in.readString();
sdkVersion = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(event);
dest.writeString(created);
dest.writeString(userId);
dest.writeString(model);
dest.writeString(operatingSystem);
if (resolution == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeFloat(resolution);
}
if (accessibilityFontScale == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeFloat(accessibilityFontScale);
}
dest.writeString(orientation);
dest.writeInt(batteryLevel);
dest.writeByte((byte) (pluggedIn ? 0x01 : 0x00));
dest.writeString(carrier);
dest.writeString(cellularNetworkType);
if (wifi == null) {
dest.writeByte((byte) (0x02));
} else {
dest.writeByte((byte) (wifi ? 0x01 : 0x00));
}
dest.writeString(sdkIdentifier);
dest.writeString(sdkVersion);
}
@SuppressWarnings("unused")
public static final Creator<MapLoadEvent> CREATOR = new Creator<MapLoadEvent>() {
@Override
public MapLoadEvent createFromParcel(Parcel in) {
return new MapLoadEvent(in);
}
@Override
public MapLoadEvent[] newArray(int size) {
return new MapLoadEvent[size];
}
};
}

View File

@@ -0,0 +1,35 @@
package com.mapbox.mapboxsdk.module.telemetry;
public class MapState {
private double latitude;
private double longitude;
private double zoom;
private String gesture;
public MapState(double latitude, double longitude, double zoom) {
this.latitude = latitude;
this.longitude = longitude;
this.zoom = zoom;
}
public void setGesture(String gesture) {
this.gesture = gesture;
}
String getGesture() {
return gesture;
}
double getLatitude() {
return latitude;
}
double getLongitude() {
return longitude;
}
double getZoom() {
return zoom;
}
}

View File

@@ -0,0 +1,108 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;
public class OfflineDownloadEndEvent extends Event implements Parcelable {
private static final String OFFLINE_DOWNLOAD_COMPLETE = "map.offlineDownload.end";
@SerializedName("event")
private final String event;
@SerializedName("created")
private final String created;
@SerializedName("minZoom")
private final Double minZoom;
@SerializedName("maxZoom")
private final Double maxZoom;
@SerializedName("shapeForOfflineRegion")
private final String shapeForOfflineRegion;
@SerializedName("styleURL")
private String styleURL;
@SerializedName("sizeOfResourcesCompleted")
private Long sizeOfResourcesCompleted;
@SerializedName("numberOfTilesCompleted")
private Long numberOfTilesCompleted;
@SerializedName("state")
private String state;
public void setStyleURL(String styleURL) {
this.styleURL = styleURL;
}
public void setSizeOfResourcesCompleted(Long sizeOfResourcesCompleted) {
this.sizeOfResourcesCompleted = sizeOfResourcesCompleted;
}
public void setNumberOfTilesCompleted(Long numberOfTilesCompleted) {
this.numberOfTilesCompleted = numberOfTilesCompleted;
}
public void setState(String state) {
this.state = state;
}
OfflineDownloadEndEvent(String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
this.event = OFFLINE_DOWNLOAD_COMPLETE;
this.created = TelemetryUtils.obtainCurrentDate();
this.shapeForOfflineRegion = shapeForOfflineRegion;
this.minZoom = minZoom;
this.maxZoom = maxZoom;
}
private OfflineDownloadEndEvent(Parcel in) {
event = in.readString();
created = in.readString();
shapeForOfflineRegion = in.readString();
minZoom = in.readDouble();
maxZoom = in.readDouble();
styleURL = in.readString();
sizeOfResourcesCompleted = in.readLong();
numberOfTilesCompleted = in.readLong();
state = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(event);
dest.writeString(created);
dest.writeString(shapeForOfflineRegion);
dest.writeDouble(minZoom);
dest.writeDouble(maxZoom);
dest.writeString(styleURL);
dest.writeLong(sizeOfResourcesCompleted);
dest.writeLong(numberOfTilesCompleted);
dest.writeString(state);
}
public static final Creator<OfflineDownloadEndEvent> CREATOR = new Creator<OfflineDownloadEndEvent>() {
@Override
public OfflineDownloadEndEvent createFromParcel(Parcel in) {
return new OfflineDownloadEndEvent(in);
}
@Override
public OfflineDownloadEndEvent[] newArray(int size) {
return new OfflineDownloadEndEvent[size];
}
};
}

View File

@@ -0,0 +1,80 @@
package com.mapbox.mapboxsdk.module.telemetry;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.gson.annotations.SerializedName;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.TelemetryUtils;
public class OfflineDownloadStartEvent extends Event implements Parcelable {
private static final String OFFLINE_DOWNLOAD_START = "map.offlineDownload.start";
@SerializedName("event")
private final String event;
@SerializedName("created")
private final String created;
@SerializedName("minZoom")
private final Double minZoom;
@SerializedName("maxZoom")
private final Double maxZoom;
@SerializedName("shapeForOfflineRegion")
private final String shapeForOfflineRegion;
@SerializedName("styleURL")
private String styleURL;
public void setStyleURL(String styleURL) {
this.styleURL = styleURL;
}
OfflineDownloadStartEvent(String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
this.event = OFFLINE_DOWNLOAD_START;
this.created = TelemetryUtils.obtainCurrentDate();
this.shapeForOfflineRegion = shapeForOfflineRegion;
this.minZoom = minZoom;
this.maxZoom = maxZoom;
}
private OfflineDownloadStartEvent(Parcel in) {
event = in.readString();
created = in.readString();
shapeForOfflineRegion = in.readString();
minZoom = in.readDouble();
maxZoom = in.readDouble();
styleURL = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(event);
dest.writeString(created);
dest.writeString(shapeForOfflineRegion);
dest.writeDouble(minZoom);
dest.writeDouble(maxZoom);
dest.writeString(styleURL);
}
public static final Creator<OfflineDownloadStartEvent> CREATOR = new Creator<OfflineDownloadStartEvent>() {
@Override
public OfflineDownloadStartEvent createFromParcel(Parcel in) {
return new OfflineDownloadStartEvent(in);
}
@Override
public OfflineDownloadStartEvent[] newArray(int size) {
return new OfflineDownloadStartEvent[size];
}
};
}

View File

@@ -5,8 +5,6 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.android.telemetry.AppUserTurnstile;
import com.mapbox.android.telemetry.Event;
import com.mapbox.android.telemetry.MapState;
import com.mapbox.android.telemetry.MapboxTelemetry;
import com.mapbox.android.telemetry.TelemetryEnabler;
import com.mapbox.android.telemetry.SessionInterval;
@@ -23,7 +21,7 @@ public class TelemetryImpl implements TelemetryDefinition {
@Nullable
private MapboxTelemetry telemetry;
private MapEventFactory mapEventFactory;
public TelemetryImpl() {
Context appContext = Mapbox.getApplicationContext();
String accessToken = Mapbox.getAccessToken();
@@ -32,6 +30,8 @@ public class TelemetryImpl implements TelemetryDefinition {
if (TelemetryEnabler.State.ENABLED.equals(telemetryState)) {
telemetry.enable();
}
mapEventFactory = new MapEventFactory(appContext);
}
/**
@@ -42,8 +42,7 @@ public class TelemetryImpl implements TelemetryDefinition {
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));
telemetry.push(mapEventFactory.buildMapLoadEvent());
}
/**
@@ -56,10 +55,9 @@ public class TelemetryImpl implements TelemetryDefinition {
*/
@Override
public void onGestureInteraction(String eventType, double latitude, double longitude, double zoom) {
MapEventFactory mapEventFactory = new MapEventFactory();
MapState state = new MapState(latitude, longitude, zoom);
state.setGesture(eventType);
telemetry.push(mapEventFactory.createMapGestureEvent(Event.Type.MAP_CLICK, state));
telemetry.push(mapEventFactory.buildMapClickEvent(state));
}
/**
@@ -99,8 +97,7 @@ public class TelemetryImpl implements TelemetryDefinition {
@Override
public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefinition) {
MapEventFactory mapEventFactory = new MapEventFactory();
telemetry.push(mapEventFactory.createOfflineDownloadStartEvent(
telemetry.push(mapEventFactory.buildOfflineDownloadStartEvent(
offlineDefinition instanceof OfflineTilePyramidRegionDefinition ? "tileregion" : "shaperegion",
offlineDefinition.getMinZoom(),
offlineDefinition.getMaxZoom(),