summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkevin <kevin.li@mapbox.com>2019-04-09 14:53:40 +0800
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2019-04-18 16:00:12 +0200
commit2b576d24f09909c54e3251801ffdb6aca5a7f12d (patch)
tree59bf7f04d75a2a05f9719d058403dd523ae03a5e
parentc6793dd1a21cb4186ffafb0fb1b6305de16aba2b (diff)
downloadqtlocation-mapboxgl-2b576d24f09909c54e3251801ffdb6aca5a7f12d.tar.gz
Polish codes and add test cases
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java151
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java149
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java133
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java201
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapState.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java106
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java77
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java162
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java12
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java126
10 files changed, 580 insertions, 541 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
index 324aea16ca..91e8c0f6f3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapClickEvent.java
@@ -1,86 +1,85 @@
package com.mapbox.mapboxsdk.module.telemetry;
-import android.content.Context;
+import android.annotation.SuppressLint;
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")
+/**
+ * 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 Event {
+ private final String event = "map.click";
+ private final String created;
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;
+ private final String cellularNetworkType;
+ private final String carrier;
+ private final String orientation;
+ private final double latitude;
+ private final double longitude;
+ private final double zoom;
+ private final int batteryLevel;
+ private final boolean pluggedIn;
+ private final boolean wifi;
+
+ MapClickEvent(PhoneState phoneState, MapState mapState) {
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 = "";
+ this.created = phoneState.getCreated();
+ this.batteryLevel = phoneState.getBatteryLevel();
+ this.pluggedIn = phoneState.isPluggedIn();
+ this.cellularNetworkType = phoneState.getCellularNetworkType();
+ this.orientation = phoneState.getOrientation();
+ this.carrier = phoneState.getCarrier();
+ this.wifi = phoneState.isWifi();
+ }
+
+ String getCreated() {
+ return created;
+ }
+
+ String getGesture() {
+ return gesture;
+ }
+
+ String getCellularNetworkType() {
+ return cellularNetworkType;
}
- MapClickEvent setDeviceInfo(Context context) {
- this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
- this.pluggedIn = TelemetryUtils.isPluggedIn(context);
- this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
- return this;
+ String getCarrier() {
+ return carrier;
}
- void setOrientation(String orientation) {
- this.orientation = orientation;
+ String getOrientation() {
+ return orientation;
}
- void setCarrier(String carrier) {
- this.carrier = carrier;
+ double getLatitude() {
+ return latitude;
}
- void setWifi(boolean wifi) {
- this.wifi = wifi;
+ double getLongitude() {
+ return longitude;
}
- 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;
+ double getZoom() {
+ return zoom;
+ }
+
+ int getBatteryLevel() {
+ return batteryLevel;
+ }
+
+ boolean isPluggedIn() {
+ return pluggedIn;
+ }
+
+ boolean isWifi() {
+ return wifi;
}
@Override
@@ -90,33 +89,5 @@ class MapClickEvent extends Event implements Parcelable {
@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];
- }
- };
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
index 830617fb72..36c75112f1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapDragendEvent.java
@@ -1,82 +1,78 @@
package com.mapbox.mapboxsdk.module.telemetry;
-import android.content.Context;
+import android.annotation.SuppressLint;
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();
+
+/**
+ * When user drag map should send this event.
+ */
+@SuppressLint("ParcelCreator")
+class MapDragendEvent extends Event {
+ private final String event = "map.dragend";
+ private final String created;
+ 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) {
+ this.lat = mapState.getLatitude();
+ this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
- this.created = TelemetryUtils.obtainCurrentDate();
- this.batteryLevel = 0;
- this.pluggedIn = false;
- this.cellularNetworkType = "";
+ this.created = phoneState.getCreated();
+ this.batteryLevel = phoneState.getBatteryLevel();
+ this.pluggedIn = phoneState.isPluggedIn();
+ this.cellularNetworkType = phoneState.getCellularNetworkType();
+ this.wifi = phoneState.isWifi();
+ this.orientation = phoneState.getOrientation();
+ this.carrier = phoneState.getCarrier();
+ }
+
+ String getCreated() {
+ return created;
}
- MapDragendEvent setDeviceInfo(Context context) {
- this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
- this.pluggedIn = TelemetryUtils.isPluggedIn(context);
- this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
- return this;
+ String getOrientation() {
+ return orientation;
}
- void setOrientation(String orientation) {
- this.orientation = orientation;
+ String getCarrier() {
+ return carrier;
}
- void setCarrier(String carrier) {
- this.carrier = carrier;
+ String getCellularNetworkType() {
+ return cellularNetworkType;
}
- void setWifi(boolean wifi) {
- this.wifi = wifi;
+ int getBatteryLevel() {
+ return batteryLevel;
}
- 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;
+ double getLat() {
+ return lat;
+ }
+
+ double getLng() {
+ return lng;
+ }
+
+ double getZoom() {
+ return zoom;
+ }
+
+ boolean isPluggedIn() {
+ return pluggedIn;
+ }
+
+ boolean isWifi() {
+ return wifi;
}
@Override
@@ -86,32 +82,5 @@ class MapDragendEvent extends Event implements Parcelable {
@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];
- }
- };
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java
index 05d0cc0615..e041f2ae31 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactory.java
@@ -1,141 +1,50 @@
package com.mapbox.mapboxsdk.module.telemetry;
-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.TelemetryUtils;
-import java.util.HashMap;
-import java.util.Map;
+class MapEventFactory {
-public class MapEventFactory {
- 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 Map<Integer, String> ORIENTATIONS = new HashMap<Integer, String>() {
- {
- put(Configuration.ORIENTATION_LANDSCAPE, LANDSCAPE);
- put(Configuration.ORIENTATION_PORTRAIT, PORTRAIT);
- }
- };
-
- private final Context appContext;
-
- MapEventFactory(Context appContext) {
- this.appContext = appContext;
- }
-
- Event buildMapLoadEvent() {
+ static MapLoadEvent buildMapLoadEvent(@NonNull PhoneState phoneState) {
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;
+ return new MapLoadEvent(userId, phoneState);
}
- Event buildOfflineDownloadStartEvent(String shapeForOfflineRegion,
- Double minZoom, Double maxZoom,
- String styleURL) {
+ static OfflineDownloadStartEvent buildOfflineDownloadStartEvent(PhoneState phoneState,
+ String shapeForOfflineRegion,
+ Double minZoom, Double maxZoom,
+ String styleURL) {
OfflineDownloadStartEvent offlineEvent =
- new OfflineDownloadStartEvent(shapeForOfflineRegion, minZoom, maxZoom);
+ new OfflineDownloadStartEvent(phoneState, shapeForOfflineRegion, minZoom, maxZoom);
offlineEvent.setStyleURL(styleURL);
return offlineEvent;
}
- public Event buildOfflineDownloadCompleteEvent(String shapeForOfflineRegion,
- Double minZoom, Double maxZoom,
- String styleURL,
- Long sizeOfResourcesCompleted,
- Long numberOfTilesCompleted,
- String state) {
+ static OfflineDownloadEndEvent buildOfflineDownloadCompleteEvent(PhoneState phoneState,
+ String shapeForOfflineRegion,
+ Double minZoom, Double maxZoom,
+ String styleURL,
+ Long sizeOfResourcesCompleted,
+ Long numberOfTilesCompleted,
+ String state) {
OfflineDownloadEndEvent offlineEvent =
- new OfflineDownloadEndEvent(shapeForOfflineRegion, minZoom, maxZoom);
+ new OfflineDownloadEndEvent(phoneState, shapeForOfflineRegion, minZoom, maxZoom);
offlineEvent.setStyleURL(styleURL);
offlineEvent.setSizeOfResourcesCompleted(sizeOfResourcesCompleted);
offlineEvent.setNumberOfTilesCompleted(numberOfTilesCompleted);
+ offlineEvent.setState(state);
return offlineEvent;
}
- 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;
- }
-
- 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;
- }
-
- private String obtainOrientation(Context context) {
- return ORIENTATIONS.get(context.getResources().getConfiguration().orientation);
- }
-
- private float obtainAccessibilityFontScaleSize(Context context) {
- return context.getResources().getConfiguration().fontScale;
- }
-
- 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)) {
- return NO_CARRIER;
- }
-
- return carrierName;
- }
-
- private float obtainDisplayDensity(Context context) {
- DisplayMetrics displayMetrics = new DisplayMetrics();
- ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
-
- return displayMetrics.density;
- }
-
- private boolean isConnectedToWifi(Context context) {
- try {
- WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- //noinspection MissingPermission
- WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
-
- return isWifiConnected(wifiMgr, wifiInfo);
- } catch (Exception exception) {
- return false;
- }
- }
-
- private boolean isWifiConnected(WifiManager wifiMgr, WifiInfo wifiInfo) {
- return wifiMgr.isWifiEnabled() && networkConnected(wifiInfo);
+ static MapClickEvent buildMapClickEvent(@NonNull PhoneState phoneState, @NonNull MapState mapState) {
+ return new MapClickEvent(phoneState, mapState);
}
- private boolean networkConnected(WifiInfo wifiInfo) {
- return wifiInfo.getNetworkId() != NO_NETWORK;
+ static MapDragendEvent buildMapDragendEvent(@NonNull PhoneState phoneState, @NonNull MapState mapState) {
+ return new MapDragendEvent(phoneState, mapState);
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
index 132b620086..e0a7f17e01 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapLoadEvent.java
@@ -1,112 +1,101 @@
package com.mapbox.mapboxsdk.module.telemetry;
-import android.content.Context;
+import android.annotation.SuppressLint;
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();
+import com.mapbox.mapboxsdk.BuildConfig;
+
+/**
+ * Event will be sent while map is loaded.
+ */
+@SuppressLint("ParcelCreator")
+class MapLoadEvent extends Event {
+ private final String event = "map.load";
+ private final String operatingSystem = "Android - " + Build.VERSION.RELEASE;
+ private final String sdkIdentifier = BuildConfig.MAPBOX_SDK_IDENTIFIER;
+ private final String sdkVersion = BuildConfig.MAPBOX_SDK_VERSION;
+ private final String model = Build.MODEL;
+ private final String created;
+ private final String userId;
+ private final String carrier;
+ private final String cellularNetworkType;
+ private final String orientation;
+ private final float resolution;
+ private final float accessibilityFontScale;
+ private final int batteryLevel;
+ private final boolean pluggedIn;
+ private final boolean wifi;
+
+
+ MapLoadEvent(String userId, PhoneState phoneState) {
+ this.created = phoneState.getCreated();
this.userId = userId;
- this.batteryLevel = 0;
- this.pluggedIn = false;
- this.cellularNetworkType = "";
+ this.batteryLevel = phoneState.getBatteryLevel();
+ this.pluggedIn = phoneState.isPluggedIn();
+ this.cellularNetworkType = phoneState.getCellularNetworkType();
+ this.carrier = phoneState.getCarrier();
+ this.resolution = phoneState.getResolution();
+ this.accessibilityFontScale = phoneState.getAccessibilityFontScale();
+ this.wifi = phoneState.isWifi();
+ this.orientation = phoneState.getOrientation();
}
- MapLoadEvent setDeviceInfo(Context context) {
- this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
- this.pluggedIn = TelemetryUtils.isPluggedIn(context);
- this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
- return this;
+ String getOperatingSystem() {
+ return operatingSystem;
}
- void setResolution(float resolution) {
- this.resolution = resolution;
+ String getSdkIdentifier() {
+ return sdkIdentifier;
}
- void setAccessibilityFontScale(float accessibilityFontScale) {
- this.accessibilityFontScale = accessibilityFontScale;
+ String getSdkVersion() {
+ return sdkVersion;
}
- void setOrientation(String orientation) {
- this.orientation = orientation;
+ String getModel() {
+ return model;
}
- void setCarrier(String carrier) {
- this.carrier = carrier;
+ String getCreated() {
+ return created;
}
- void setWifi(boolean wifi) {
- this.wifi = wifi;
+ String getUserId() {
+ return userId;
}
- void setSdkIdentifier(String sdkIdentifier) {
- this.sdkIdentifier = sdkIdentifier;
+ String getCarrier() {
+ return carrier;
}
- void setSdkVersion(String sdkVersion) {
- this.sdkVersion = sdkVersion;
+ String getCellularNetworkType() {
+ return cellularNetworkType;
}
- 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();
+ String getOrientation() {
+ return orientation;
+ }
+
+ float getResolution() {
+ return resolution;
+ }
+
+ float getAccessibilityFontScale() {
+ return accessibilityFontScale;
+ }
+
+ int getBatteryLevel() {
+ return batteryLevel;
+ }
+
+ boolean isPluggedIn() {
+ return pluggedIn;
+ }
+
+ boolean isWifi() {
+ return wifi;
}
@Override
@@ -116,47 +105,5 @@ class MapLoadEvent extends Event implements Parcelable {
@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];
- }
- };
+ }
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapState.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapState.java
index 507ed2906f..d44be49224 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapState.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/MapState.java
@@ -6,13 +6,13 @@ public class MapState {
private double zoom;
private String gesture;
- public MapState(double latitude, double longitude, double zoom) {
+ MapState(double latitude, double longitude, double zoom) {
this.latitude = latitude;
this.longitude = longitude;
this.zoom = zoom;
}
- public void setGesture(String gesture) {
+ void setGesture(String gesture) {
this.gesture = gesture;
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
index 71d59eb3bb..cbc79c7b60 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadEndEvent.java
@@ -1,79 +1,78 @@
package com.mapbox.mapboxsdk.module.telemetry;
+import android.annotation.SuppressLint;
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")
+/**
+ * Event will be sent while offline download end.
+ */
+@SuppressLint("ParcelCreator")
+public class OfflineDownloadEndEvent extends Event {
+ private final String event = "map.offlineDownload.end";
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) {
+ void setStyleURL(String styleURL) {
this.styleURL = styleURL;
}
- public void setSizeOfResourcesCompleted(Long sizeOfResourcesCompleted) {
+ void setSizeOfResourcesCompleted(Long sizeOfResourcesCompleted) {
this.sizeOfResourcesCompleted = sizeOfResourcesCompleted;
}
- public void setNumberOfTilesCompleted(Long numberOfTilesCompleted) {
+ void setNumberOfTilesCompleted(Long numberOfTilesCompleted) {
this.numberOfTilesCompleted = numberOfTilesCompleted;
}
- public void setState(String state) {
+ void setState(String state) {
this.state = state;
}
- OfflineDownloadEndEvent(String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
- this.event = OFFLINE_DOWNLOAD_COMPLETE;
- this.created = TelemetryUtils.obtainCurrentDate();
+ OfflineDownloadEndEvent(PhoneState phoneState, String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
+ this.created = phoneState.getCreated();
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();
+ String getCreated() {
+ return created;
+ }
+ Double getMinZoom() {
+ return minZoom;
+ }
+
+ Double getMaxZoom() {
+ return maxZoom;
+ }
+
+ String getShapeForOfflineRegion() {
+ return shapeForOfflineRegion;
+ }
+
+ String getStyleURL() {
+ return styleURL;
+ }
+
+ Long getSizeOfResourcesCompleted() {
+ return sizeOfResourcesCompleted;
+ }
+
+ Long getNumberOfTilesCompleted() {
+ return numberOfTilesCompleted;
+ }
+
+ String getState() {
+ return state;
}
@Override
@@ -83,26 +82,5 @@ public class OfflineDownloadEndEvent extends Event implements Parcelable {
@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];
- }
- };
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
index a7f28ac371..ab39e2d820 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/OfflineDownloadStartEvent.java
@@ -1,54 +1,51 @@
package com.mapbox.mapboxsdk.module.telemetry;
+import android.annotation.SuppressLint;
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")
+/**
+ * Event will be sent while offline download start.
+ */
+@SuppressLint("ParcelCreator")
+public class OfflineDownloadStartEvent extends Event {
+ private final String event = "map.offlineDownload.start";
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) {
+ void setStyleURL(String styleURL) {
this.styleURL = styleURL;
}
- OfflineDownloadStartEvent(String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
- this.event = OFFLINE_DOWNLOAD_START;
- this.created = TelemetryUtils.obtainCurrentDate();
+ OfflineDownloadStartEvent(PhoneState phoneState, String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
+ this.created = phoneState.getCreated();
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();
+ String getCreated() {
+ return created;
+ }
+
+ Double getMinZoom() {
+ return minZoom;
+ }
+
+ Double getMaxZoom() {
+ return maxZoom;
+ }
+
+ String getShapeForOfflineRegion() {
+ return shapeForOfflineRegion;
+ }
+
+ String getStyleURL() {
+ return styleURL;
}
@Override
@@ -58,23 +55,5 @@ public class OfflineDownloadStartEvent extends Event implements Parcelable {
@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];
- }
- };
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
new file mode 100644
index 0000000000..8cd388357b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/PhoneState.java
@@ -0,0 +1,162 @@
+package com.mapbox.mapboxsdk.module.telemetry;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.DisplayMetrics;
+import android.view.WindowManager;
+
+import com.mapbox.android.telemetry.TelemetryUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Class that holds kinds of states of the current phone.
+ */
+class PhoneState {
+ static final String LANDSCAPE = "Landscape";
+ static final String PORTRAIT = "Portrait";
+ private static final String NO_CARRIER = "EMPTY_CARRIER";
+ private static final int NO_NETWORK = -1;
+
+ private static final Map<Integer, String> ORIENTATIONS = new HashMap<Integer, String>() {
+ {
+ put(Configuration.ORIENTATION_LANDSCAPE, LANDSCAPE);
+ put(Configuration.ORIENTATION_PORTRAIT, PORTRAIT);
+ }
+ };
+
+ private String created;
+ private String cellularNetworkType;
+ private String orientation;
+ private String carrier;
+ private int batteryLevel;
+ private boolean pluggedIn;
+ private boolean wifi;
+ private float accessibilityFontScale;
+ private float resolution;
+
+ PhoneState() {
+
+ }
+
+ PhoneState(Context context) {
+ this.created = TelemetryUtils.obtainCurrentDate();
+ this.batteryLevel = TelemetryUtils.obtainBatteryLevel(context);
+ this.pluggedIn = TelemetryUtils.isPluggedIn(context);
+ this.cellularNetworkType = TelemetryUtils.obtainCellularNetworkType(context);
+ this.orientation = ORIENTATIONS.get(context.getResources().getConfiguration().orientation);
+ this.accessibilityFontScale = context.getResources().getConfiguration().fontScale;
+ this.carrier = obtainCellularCarrier(context);
+ this.resolution = obtainDisplayDensity(context);
+ this.wifi = isConnectedToWifi(context);
+ }
+
+ 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)) {
+ return NO_CARRIER;
+ }
+ return carrierName;
+ }
+
+ private float obtainDisplayDensity(Context context) {
+ DisplayMetrics displayMetrics = new DisplayMetrics();
+ ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
+ return displayMetrics.density;
+ }
+
+ private boolean isConnectedToWifi(Context context) {
+ try {
+ WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+ if (wifiMgr == null) {
+ return false;
+ }
+ //noinspection MissingPermission
+ WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
+ return wifiMgr.isWifiEnabled() && wifiInfo.getNetworkId() != NO_NETWORK;
+ } catch (Exception exception) {
+ return false;
+ }
+ }
+
+ String getCreated() {
+ return created;
+ }
+
+ void setCreated(String created) {
+ this.created = created;
+ }
+
+ int getBatteryLevel() {
+ return batteryLevel;
+ }
+
+ void setBatteryLevel(int batteryLevel) {
+ this.batteryLevel = batteryLevel;
+ }
+
+ boolean isPluggedIn() {
+ return pluggedIn;
+ }
+
+ void setPluggedIn(boolean pluggedIn) {
+ this.pluggedIn = pluggedIn;
+ }
+
+ String getCellularNetworkType() {
+ return cellularNetworkType;
+ }
+
+ void setCellularNetworkType(String cellularNetworkType) {
+ this.cellularNetworkType = cellularNetworkType;
+ }
+
+ String getOrientation() {
+ return orientation;
+ }
+
+ void setOrientation(String orientation) {
+ this.orientation = orientation;
+ }
+
+ String getCarrier() {
+ return carrier;
+ }
+
+ void setCarrier(String carrier) {
+ this.carrier = carrier;
+ }
+
+ boolean isWifi() {
+ return wifi;
+ }
+
+ void setWifi(boolean wifi) {
+ this.wifi = wifi;
+ }
+
+ float getAccessibilityFontScale() {
+ return accessibilityFontScale;
+ }
+
+ void setAccessibilityFontScale(float accessibilityFontScale) {
+ this.accessibilityFontScale = accessibilityFontScale;
+ }
+
+ float getResolution() {
+ return resolution;
+ }
+
+ void setResolution(float resolution) {
+ this.resolution = resolution;
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java
index 026045ef66..5b14fe249a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/module/telemetry/TelemetryImpl.java
@@ -21,18 +21,16 @@ public class TelemetryImpl implements TelemetryDefinition {
@Nullable
private MapboxTelemetry telemetry;
- private MapEventFactory mapEventFactory;
+ private Context appContext;
public TelemetryImpl() {
- Context appContext = Mapbox.getApplicationContext();
+ appContext = Mapbox.getApplicationContext();
String accessToken = Mapbox.getAccessToken();
telemetry = new MapboxTelemetry(appContext, accessToken, BuildConfig.MAPBOX_EVENTS_USER_AGENT);
TelemetryEnabler.State telemetryState = TelemetryEnabler.retrieveTelemetryStateFromPreferences();
if (TelemetryEnabler.State.ENABLED.equals(telemetryState)) {
telemetry.enable();
}
- mapEventFactory = new MapEventFactory(appContext);
-
}
/**
@@ -43,7 +41,7 @@ public class TelemetryImpl implements TelemetryDefinition {
AppUserTurnstile turnstileEvent = new AppUserTurnstile(BuildConfig.MAPBOX_SDK_IDENTIFIER,
BuildConfig.MAPBOX_SDK_VERSION);
telemetry.push(turnstileEvent);
- telemetry.push(mapEventFactory.buildMapLoadEvent());
+ telemetry.push(MapEventFactory.buildMapLoadEvent(new PhoneState(appContext)));
}
/**
@@ -58,7 +56,7 @@ public class TelemetryImpl implements TelemetryDefinition {
public void onGestureInteraction(String eventType, double latitude, double longitude, double zoom) {
MapState state = new MapState(latitude, longitude, zoom);
state.setGesture(eventType);
- telemetry.push(mapEventFactory.buildMapClickEvent(state));
+ telemetry.push(MapEventFactory.buildMapClickEvent(new PhoneState(appContext), state));
}
/**
@@ -98,7 +96,7 @@ public class TelemetryImpl implements TelemetryDefinition {
@Override
public void onCreateOfflineRegion(@NonNull OfflineRegionDefinition offlineDefinition) {
- telemetry.push(mapEventFactory.buildOfflineDownloadStartEvent(
+ telemetry.push(MapEventFactory.buildOfflineDownloadStartEvent(new PhoneState(appContext),
offlineDefinition instanceof OfflineTilePyramidRegionDefinition ? "tileregion" : "shaperegion",
offlineDefinition.getMinZoom(),
offlineDefinition.getMaxZoom(),
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java
new file mode 100644
index 0000000000..dfefb92aee
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/module/telemetry/MapEventFactoryTest.java
@@ -0,0 +1,126 @@
+package com.mapbox.mapboxsdk.module.telemetry;
+
+import android.os.Build;
+
+import com.mapbox.mapboxsdk.BuildConfig;
+import com.mapbox.mapboxsdk.constants.TelemetryConstants;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class MapEventFactoryTest {
+ private static final float FONT_SCALE = 1.f;
+ private static final double LATITUDE = 10.0;
+ private static final double LONGITUDE = 11.0;
+ private static final double ZOOM = 10.0;
+ private static final int BATTERY_LEVEL = 50;
+ private static final String CARRIER = "carrier";
+ private static final String NETWORK_TYPE = "network";
+ private static final String CREATED = "2019-04-09";
+ private static final boolean PLUGIN = true;
+ private static final float RESOLUTION = 1024.f;
+ private static final boolean WIFI = true;
+ private static final String SHAPE = "shape";
+ private static final Double MIN_ZOOM = 1.0;
+ private static final Double MAX_ZOOM = 10.0;
+ private static final String STYLE_URL = "style url";
+ private static final Long SIZE_OF_RESOURCES_COMPLETED = 100L;
+ private static final Long NUMBER_OF_TILE_COMPLETED = 1000L;
+ private static final String STATE = "state";
+
+ MapState mapState;
+ PhoneState phoneState;
+
+ @Before
+ public void setUp() {
+ mapState = new MapState(LATITUDE, LONGITUDE, ZOOM);
+ phoneState = new PhoneState();
+ phoneState.setAccessibilityFontScale(FONT_SCALE);
+ phoneState.setBatteryLevel(BATTERY_LEVEL);
+ phoneState.setCarrier(CARRIER);
+ phoneState.setCellularNetworkType(NETWORK_TYPE);
+ phoneState.setCreated(CREATED);
+ phoneState.setOrientation(PhoneState.LANDSCAPE);
+ phoneState.setPluggedIn(PLUGIN);
+ phoneState.setResolution(RESOLUTION);
+ phoneState.setWifi(WIFI);
+ }
+
+ @Test
+ public void testClickEvent() {
+ mapState.setGesture(TelemetryConstants.DOUBLE_TAP);
+ MapClickEvent mapClickEvent = MapEventFactory.buildMapClickEvent(phoneState, mapState);
+ assertEquals(LATITUDE, mapClickEvent.getLatitude(), 0);
+ assertEquals(LONGITUDE, mapClickEvent.getLongitude(), 0);
+ assertEquals(ZOOM, mapClickEvent.getZoom(), 0);
+ assertEquals(BATTERY_LEVEL, mapClickEvent.getBatteryLevel());
+ assertEquals(CARRIER, mapClickEvent.getCarrier());
+ assertEquals(NETWORK_TYPE, mapClickEvent.getCellularNetworkType());
+ assertEquals(CREATED, mapClickEvent.getCreated());
+ assertEquals(TelemetryConstants.DOUBLE_TAP, mapClickEvent.getGesture());
+ assertEquals(PhoneState.LANDSCAPE, mapClickEvent.getOrientation());
+ assertEquals(PLUGIN, mapClickEvent.isPluggedIn());
+ assertEquals(WIFI, mapClickEvent.isWifi());
+ }
+
+ @Test
+ public void testMapLoadEvent() {
+ MapLoadEvent mapLoadEvent = MapEventFactory.buildMapLoadEvent(phoneState);
+ assertEquals("Android - " + Build.VERSION.RELEASE, mapLoadEvent.getOperatingSystem());
+ assertEquals(Build.MODEL, mapLoadEvent.getModel());
+ assertNotNull(mapLoadEvent.getUserId());
+ assertEquals(BATTERY_LEVEL, mapLoadEvent.getBatteryLevel());
+ assertEquals(CARRIER, mapLoadEvent.getCarrier());
+ assertEquals(NETWORK_TYPE, mapLoadEvent.getCellularNetworkType());
+ assertEquals(CREATED, mapLoadEvent.getCreated());
+ assertEquals(PhoneState.LANDSCAPE, mapLoadEvent.getOrientation());
+ assertEquals(BuildConfig.MAPBOX_SDK_IDENTIFIER, mapLoadEvent.getSdkIdentifier());
+ assertEquals(BuildConfig.MAPBOX_SDK_VERSION, mapLoadEvent.getSdkVersion());
+ assertEquals(PLUGIN, mapLoadEvent.isPluggedIn());
+ assertEquals(WIFI, mapLoadEvent.isWifi());
+ assertEquals(FONT_SCALE, mapLoadEvent.getAccessibilityFontScale(), 0);
+ }
+
+ @Test
+ public void testMapDraggedEvent() {
+ MapDragendEvent mapDraggedEvent = MapEventFactory.buildMapDragendEvent(phoneState, mapState);
+ assertEquals(LATITUDE, mapDraggedEvent.getLat(), 0);
+ assertEquals(LONGITUDE, mapDraggedEvent.getLng(), 0);
+ assertEquals(ZOOM, mapDraggedEvent.getZoom(), 0);
+ assertEquals(BATTERY_LEVEL, mapDraggedEvent.getBatteryLevel());
+ assertEquals(CARRIER, mapDraggedEvent.getCarrier());
+ assertEquals(NETWORK_TYPE, mapDraggedEvent.getCellularNetworkType());
+ assertEquals(CREATED, mapDraggedEvent.getCreated());
+ assertEquals(PhoneState.LANDSCAPE, mapDraggedEvent.getOrientation());
+ assertEquals(PLUGIN, mapDraggedEvent.isPluggedIn());
+ assertEquals(WIFI, mapDraggedEvent.isWifi());
+ }
+
+ @Test
+ public void testOfflineDownloadEndEvent() {
+ OfflineDownloadEndEvent offlineDownloadEndEvent = MapEventFactory.buildOfflineDownloadCompleteEvent(phoneState,
+ SHAPE, MIN_ZOOM, MAX_ZOOM, STYLE_URL, SIZE_OF_RESOURCES_COMPLETED, NUMBER_OF_TILE_COMPLETED, STATE);
+ assertEquals(SHAPE, offlineDownloadEndEvent.getShapeForOfflineRegion());
+ assertEquals(MIN_ZOOM, offlineDownloadEndEvent.getMinZoom());
+ assertEquals(MAX_ZOOM, offlineDownloadEndEvent.getMaxZoom());
+ assertEquals(STYLE_URL, offlineDownloadEndEvent.getStyleURL());
+ assertEquals(SIZE_OF_RESOURCES_COMPLETED, offlineDownloadEndEvent.getSizeOfResourcesCompleted());
+ assertEquals(NUMBER_OF_TILE_COMPLETED, offlineDownloadEndEvent.getNumberOfTilesCompleted());
+ assertEquals(STATE, offlineDownloadEndEvent.getState());
+ assertEquals(CREATED, offlineDownloadEndEvent.getCreated());
+ }
+
+ @Test
+ public void testOfflineDownloadStartEvent() {
+ OfflineDownloadStartEvent offlineDownloadStartEvent = MapEventFactory.buildOfflineDownloadStartEvent(phoneState,
+ SHAPE, MIN_ZOOM, MAX_ZOOM, STYLE_URL);
+ assertEquals(SHAPE, offlineDownloadStartEvent.getShapeForOfflineRegion());
+ assertEquals(MIN_ZOOM, offlineDownloadStartEvent.getMinZoom());
+ assertEquals(MAX_ZOOM, offlineDownloadStartEvent.getMaxZoom());
+ assertEquals(STYLE_URL, offlineDownloadStartEvent.getStyleURL());
+ assertEquals(CREATED, offlineDownloadStartEvent.getCreated());
+ }
+}