Add hashcode(), equals() and toString() methods to Events class.
This commit is contained in:
@@ -82,6 +82,91 @@ class MapClickEvent extends Event {
|
||||
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.latitude, latitude) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Double.compare(that.longitude, longitude) != 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 (created != null ? !created.equals(that.created) : that.created != null) {
|
||||
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 = event.hashCode();
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * 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(latitude);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(longitude);
|
||||
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{"
|
||||
+ "event='" + event + '\''
|
||||
+ ", created='" + created + '\''
|
||||
+ ", gesture='" + gesture + '\''
|
||||
+ ", cellularNetworkType='" + cellularNetworkType + '\''
|
||||
+ ", carrier='" + carrier + '\''
|
||||
+ ", orientation='" + orientation + '\''
|
||||
+ ", latitude=" + latitude
|
||||
+ ", longitude=" + longitude
|
||||
+ ", zoom=" + zoom
|
||||
+ ", batteryLevel=" + batteryLevel
|
||||
+ ", pluggedIn=" + pluggedIn
|
||||
+ ", wifi=" + wifi
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
||||
@@ -75,6 +75,86 @@ class MapDragendEvent extends Event {
|
||||
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 (created != null ? !created.equals(that.created) : that.created != null) {
|
||||
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 = event.hashCode();
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * 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{"
|
||||
+ "event='" + event + '\''
|
||||
+ ", created='" + created + '\''
|
||||
+ ", orientation='" + orientation + '\''
|
||||
+ ", carrier='" + carrier + '\''
|
||||
+ ", cellularNetworkType='" + cellularNetworkType + '\''
|
||||
+ ", batteryLevel=" + batteryLevel
|
||||
+ ", lat=" + lat
|
||||
+ ", lng=" + lng
|
||||
+ ", zoom=" + zoom
|
||||
+ ", pluggedIn=" + pluggedIn
|
||||
+ ", wifi=" + wifi
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapbox.android.telemetry.TelemetryUtils;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegion;
|
||||
|
||||
class MapEventFactory {
|
||||
|
||||
@@ -13,7 +16,10 @@ class MapEventFactory {
|
||||
|
||||
static OfflineDownloadStartEvent buildOfflineDownloadStartEvent(PhoneState phoneState,
|
||||
String shapeForOfflineRegion,
|
||||
Double minZoom, Double maxZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom,
|
||||
String styleURL) {
|
||||
|
||||
OfflineDownloadStartEvent offlineEvent =
|
||||
@@ -24,11 +30,14 @@ class MapEventFactory {
|
||||
|
||||
static OfflineDownloadEndEvent buildOfflineDownloadCompleteEvent(PhoneState phoneState,
|
||||
String shapeForOfflineRegion,
|
||||
Double minZoom, Double maxZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom,
|
||||
String styleURL,
|
||||
Long sizeOfResourcesCompleted,
|
||||
Long numberOfTilesCompleted,
|
||||
String state) {
|
||||
@OfflineRegion.DownloadState int state) {
|
||||
|
||||
OfflineDownloadEndEvent offlineEvent =
|
||||
new OfflineDownloadEndEvent(phoneState, shapeForOfflineRegion, minZoom, maxZoom);
|
||||
|
||||
@@ -98,6 +98,95 @@ class MapLoadEvent extends Event {
|
||||
return wifi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MapLoadEvent that = (MapLoadEvent) o;
|
||||
|
||||
if (Float.compare(that.resolution, resolution) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Float.compare(that.accessibilityFontScale, accessibilityFontScale) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (batteryLevel != that.batteryLevel) {
|
||||
return false;
|
||||
}
|
||||
if (pluggedIn != that.pluggedIn) {
|
||||
return false;
|
||||
}
|
||||
if (wifi != that.wifi) {
|
||||
return false;
|
||||
}
|
||||
if (!operatingSystem.equals(that.operatingSystem)) {
|
||||
return false;
|
||||
}
|
||||
if (model != null ? !model.equals(that.model) : that.model != null) {
|
||||
return false;
|
||||
}
|
||||
if (created != null ? !created.equals(that.created) : that.created != null) {
|
||||
return false;
|
||||
}
|
||||
if (userId != null ? !userId.equals(that.userId) : that.userId != null) {
|
||||
return false;
|
||||
}
|
||||
if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) {
|
||||
return false;
|
||||
}
|
||||
if (cellularNetworkType != null ? !cellularNetworkType.equals(that.cellularNetworkType) :
|
||||
that.cellularNetworkType != null) {
|
||||
return false;
|
||||
}
|
||||
return orientation != null ? orientation.equals(that.orientation) : that.orientation == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = event.hashCode();
|
||||
result = 31 * result + operatingSystem.hashCode();
|
||||
result = 31 * result + sdkIdentifier.hashCode();
|
||||
result = 31 * result + sdkVersion.hashCode();
|
||||
result = 31 * result + (model != null ? model.hashCode() : 0);
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * result + (userId != null ? userId.hashCode() : 0);
|
||||
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
|
||||
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
|
||||
result = 31 * result + (orientation != null ? orientation.hashCode() : 0);
|
||||
result = 31 * result + (resolution != +0.0f ? Float.floatToIntBits(resolution) : 0);
|
||||
result = 31 * result + (accessibilityFontScale != +0.0f ? Float.floatToIntBits(accessibilityFontScale) : 0);
|
||||
result = 31 * result + batteryLevel;
|
||||
result = 31 * result + (pluggedIn ? 1 : 0);
|
||||
result = 31 * result + (wifi ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MapLoadEvent{"
|
||||
+ "event='" + event + '\''
|
||||
+ ", operatingSystem='" + operatingSystem + '\''
|
||||
+ ", sdkIdentifier='" + sdkIdentifier + '\''
|
||||
+ ", sdkVersion='" + sdkVersion + '\''
|
||||
+ ", model='" + model + '\''
|
||||
+ ", created='" + created + '\''
|
||||
+ ", userId='" + userId + '\''
|
||||
+ ", carrier='" + carrier + '\''
|
||||
+ ", cellularNetworkType='" + cellularNetworkType + '\''
|
||||
+ ", orientation='" + orientation + '\''
|
||||
+ ", resolution=" + resolution
|
||||
+ ", accessibilityFontScale=" + accessibilityFontScale
|
||||
+ ", batteryLevel=" + batteryLevel
|
||||
+ ", pluggedIn=" + pluggedIn
|
||||
+ ", wifi=" + wifi
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
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, double zoom) {
|
||||
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;
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Parcel;
|
||||
import android.support.annotation.FloatRange;
|
||||
|
||||
import com.mapbox.android.telemetry.Event;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegion;
|
||||
|
||||
/**
|
||||
* Event will be sent while offline download end.
|
||||
@@ -16,33 +19,37 @@ public class OfflineDownloadEndEvent extends Event {
|
||||
private final Double maxZoom;
|
||||
private final String shapeForOfflineRegion;
|
||||
private String styleURL;
|
||||
private Long sizeOfResourcesCompleted;
|
||||
private Long numberOfTilesCompleted;
|
||||
private String state;
|
||||
private long sizeOfResourcesCompleted;
|
||||
private long numberOfTilesCompleted;
|
||||
private int state;
|
||||
|
||||
OfflineDownloadEndEvent(PhoneState phoneState, String shapeForOfflineRegion,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom) {
|
||||
this.created = phoneState.getCreated();
|
||||
this.shapeForOfflineRegion = shapeForOfflineRegion;
|
||||
this.minZoom = minZoom;
|
||||
this.maxZoom = maxZoom;
|
||||
}
|
||||
|
||||
void setStyleURL(String styleURL) {
|
||||
this.styleURL = styleURL;
|
||||
}
|
||||
|
||||
void setSizeOfResourcesCompleted(Long sizeOfResourcesCompleted) {
|
||||
void setSizeOfResourcesCompleted(long sizeOfResourcesCompleted) {
|
||||
this.sizeOfResourcesCompleted = sizeOfResourcesCompleted;
|
||||
}
|
||||
|
||||
void setNumberOfTilesCompleted(Long numberOfTilesCompleted) {
|
||||
void setNumberOfTilesCompleted(long numberOfTilesCompleted) {
|
||||
this.numberOfTilesCompleted = numberOfTilesCompleted;
|
||||
}
|
||||
|
||||
void setState(String state) {
|
||||
void setState(@OfflineRegion.DownloadState int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
OfflineDownloadEndEvent(PhoneState phoneState, String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
|
||||
this.created = phoneState.getCreated();
|
||||
this.shapeForOfflineRegion = shapeForOfflineRegion;
|
||||
this.minZoom = minZoom;
|
||||
this.maxZoom = maxZoom;
|
||||
}
|
||||
|
||||
String getCreated() {
|
||||
return created;
|
||||
}
|
||||
@@ -63,18 +70,83 @@ public class OfflineDownloadEndEvent extends Event {
|
||||
return styleURL;
|
||||
}
|
||||
|
||||
Long getSizeOfResourcesCompleted() {
|
||||
long getSizeOfResourcesCompleted() {
|
||||
return sizeOfResourcesCompleted;
|
||||
}
|
||||
|
||||
Long getNumberOfTilesCompleted() {
|
||||
long getNumberOfTilesCompleted() {
|
||||
return numberOfTilesCompleted;
|
||||
}
|
||||
|
||||
String getState() {
|
||||
int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflineDownloadEndEvent that = (OfflineDownloadEndEvent) o;
|
||||
|
||||
if (sizeOfResourcesCompleted != that.sizeOfResourcesCompleted) {
|
||||
return false;
|
||||
}
|
||||
if (numberOfTilesCompleted != that.numberOfTilesCompleted) {
|
||||
return false;
|
||||
}
|
||||
if (state != that.state) {
|
||||
return false;
|
||||
}
|
||||
if (created != null ? !created.equals(that.created) : that.created != null) {
|
||||
return false;
|
||||
}
|
||||
if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) {
|
||||
return false;
|
||||
}
|
||||
if (maxZoom != null ? !maxZoom.equals(that.maxZoom) : that.maxZoom != null) {
|
||||
return false;
|
||||
}
|
||||
if (shapeForOfflineRegion != null ? !shapeForOfflineRegion.equals(that.shapeForOfflineRegion) :
|
||||
that.shapeForOfflineRegion != null) {
|
||||
return false;
|
||||
}
|
||||
return styleURL != null ? styleURL.equals(that.styleURL) : that.styleURL == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = event.hashCode();
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * result + (minZoom != null ? minZoom.hashCode() : 0);
|
||||
result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0);
|
||||
result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0);
|
||||
result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0);
|
||||
result = 31 * result + (int) (sizeOfResourcesCompleted ^ (sizeOfResourcesCompleted >>> 32));
|
||||
result = 31 * result + (int) (numberOfTilesCompleted ^ (numberOfTilesCompleted >>> 32));
|
||||
result = 31 * result + state;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OfflineDownloadEndEvent{"
|
||||
+ "event='" + event + '\''
|
||||
+ ", created='" + created + '\''
|
||||
+ ", minZoom=" + minZoom
|
||||
+ ", maxZoom=" + maxZoom
|
||||
+ ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\''
|
||||
+ ", styleURL='" + styleURL + '\''
|
||||
+ ", sizeOfResourcesCompleted=" + sizeOfResourcesCompleted
|
||||
+ ", numberOfTilesCompleted=" + numberOfTilesCompleted
|
||||
+ ", state=" + state
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Parcel;
|
||||
import android.support.annotation.FloatRange;
|
||||
|
||||
import com.mapbox.android.telemetry.Event;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
|
||||
/**
|
||||
* Event will be sent while offline download start.
|
||||
@@ -17,17 +19,21 @@ public class OfflineDownloadStartEvent extends Event {
|
||||
private final String shapeForOfflineRegion;
|
||||
private String styleURL;
|
||||
|
||||
void setStyleURL(String styleURL) {
|
||||
this.styleURL = styleURL;
|
||||
}
|
||||
|
||||
OfflineDownloadStartEvent(PhoneState phoneState, String shapeForOfflineRegion, Double minZoom, Double maxZoom) {
|
||||
OfflineDownloadStartEvent(PhoneState phoneState, String shapeForOfflineRegion,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double minZoom,
|
||||
@FloatRange(from = MapboxConstants.MINIMUM_ZOOM,
|
||||
to = MapboxConstants.MAXIMUM_ZOOM) Double maxZoom) {
|
||||
this.created = phoneState.getCreated();
|
||||
this.shapeForOfflineRegion = shapeForOfflineRegion;
|
||||
this.minZoom = minZoom;
|
||||
this.maxZoom = maxZoom;
|
||||
}
|
||||
|
||||
void setStyleURL(String styleURL) {
|
||||
this.styleURL = styleURL;
|
||||
}
|
||||
|
||||
String getCreated() {
|
||||
return created;
|
||||
}
|
||||
@@ -48,6 +54,56 @@ public class OfflineDownloadStartEvent extends Event {
|
||||
return styleURL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OfflineDownloadStartEvent that = (OfflineDownloadStartEvent) o;
|
||||
|
||||
if (created != null ? !created.equals(that.created) : that.created != null) {
|
||||
return false;
|
||||
}
|
||||
if (minZoom != null ? !minZoom.equals(that.minZoom) : that.minZoom != null) {
|
||||
return false;
|
||||
}
|
||||
if (maxZoom != null ? !maxZoom.equals(that.maxZoom) : that.maxZoom != null) {
|
||||
return false;
|
||||
}
|
||||
if (shapeForOfflineRegion != null ? !shapeForOfflineRegion.equals(that.shapeForOfflineRegion) :
|
||||
that.shapeForOfflineRegion != null) {
|
||||
return false;
|
||||
}
|
||||
return styleURL != null ? styleURL.equals(that.styleURL) : that.styleURL == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = event.hashCode();
|
||||
result = 31 * result + (created != null ? created.hashCode() : 0);
|
||||
result = 31 * result + (minZoom != null ? minZoom.hashCode() : 0);
|
||||
result = 31 * result + (maxZoom != null ? maxZoom.hashCode() : 0);
|
||||
result = 31 * result + (shapeForOfflineRegion != null ? shapeForOfflineRegion.hashCode() : 0);
|
||||
result = 31 * result + (styleURL != null ? styleURL.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OfflineDownloadStartEvent{"
|
||||
+ "event='" + event + '\''
|
||||
+ ", created='" + created + '\''
|
||||
+ ", minZoom=" + minZoom
|
||||
+ ", maxZoom=" + maxZoom
|
||||
+ ", shapeForOfflineRegion='" + shapeForOfflineRegion + '\''
|
||||
+ ", styleURL='" + styleURL + '\''
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -11,28 +12,15 @@ 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 Orientation orientation;
|
||||
private String carrier;
|
||||
private int batteryLevel;
|
||||
private boolean pluggedIn;
|
||||
@@ -44,19 +32,19 @@ class PhoneState {
|
||||
|
||||
}
|
||||
|
||||
PhoneState(Context context) {
|
||||
PhoneState(@NonNull 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.orientation = Orientation.getOrientation(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) {
|
||||
private String obtainCellularCarrier(@NonNull Context context) {
|
||||
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (manager == null) {
|
||||
return NO_CARRIER;
|
||||
@@ -68,13 +56,13 @@ class PhoneState {
|
||||
return carrierName;
|
||||
}
|
||||
|
||||
private float obtainDisplayDensity(Context context) {
|
||||
private float obtainDisplayDensity(@NonNull Context context) {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(displayMetrics);
|
||||
return displayMetrics.density;
|
||||
}
|
||||
|
||||
private boolean isConnectedToWifi(Context context) {
|
||||
private boolean isConnectedToWifi(@NonNull Context context) {
|
||||
try {
|
||||
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiMgr == null) {
|
||||
@@ -121,10 +109,10 @@ class PhoneState {
|
||||
}
|
||||
|
||||
String getOrientation() {
|
||||
return orientation;
|
||||
return orientation.getOrientation();
|
||||
}
|
||||
|
||||
void setOrientation(String orientation) {
|
||||
void setOrientation(Orientation orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
@@ -159,4 +147,25 @@ class PhoneState {
|
||||
void setResolution(float resolution) {
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
enum Orientation {
|
||||
ORIENTATION_PORTRAIT("Portrait"),
|
||||
ORIENTATION_LANDSCAPE("Landscape");
|
||||
private String orientation;
|
||||
|
||||
Orientation(String orientation) {
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public static Orientation getOrientation(int index) {
|
||||
if (Configuration.ORIENTATION_PORTRAIT == index) {
|
||||
return ORIENTATION_PORTRAIT;
|
||||
}
|
||||
return ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
public String getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.FloatRange;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
@@ -11,6 +12,7 @@ import com.mapbox.android.telemetry.SessionInterval;
|
||||
import com.mapbox.android.telemetry.TelemetryEnabler;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;
|
||||
@@ -53,7 +55,9 @@ public class TelemetryImpl implements TelemetryDefinition {
|
||||
* @param zoom current zoom of the map
|
||||
*/
|
||||
@Override
|
||||
public void onGestureInteraction(String eventType, double latitude, double longitude, double zoom) {
|
||||
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));
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.mapbox.mapboxsdk.BuildConfig;
|
||||
import com.mapbox.mapboxsdk.constants.TelemetryConstants;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegion;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -27,12 +29,13 @@ public class MapEventFactoryTest {
|
||||
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";
|
||||
private static final long SIZE_OF_RESOURCES_COMPLETED = 100L;
|
||||
private static final long NUMBER_OF_TILE_COMPLETED = 1000L;
|
||||
private static final int STATE = OfflineRegion.STATE_ACTIVE;
|
||||
|
||||
MapState mapState;
|
||||
PhoneState phoneState;
|
||||
private MapState mapState;
|
||||
private PhoneState phoneState;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -43,7 +46,7 @@ public class MapEventFactoryTest {
|
||||
phoneState.setCarrier(CARRIER);
|
||||
phoneState.setCellularNetworkType(NETWORK_TYPE);
|
||||
phoneState.setCreated(CREATED);
|
||||
phoneState.setOrientation(PhoneState.LANDSCAPE);
|
||||
phoneState.setOrientation(PhoneState.Orientation.ORIENTATION_LANDSCAPE);
|
||||
phoneState.setPluggedIn(PLUGIN);
|
||||
phoneState.setResolution(RESOLUTION);
|
||||
phoneState.setWifi(WIFI);
|
||||
@@ -61,9 +64,12 @@ public class MapEventFactoryTest {
|
||||
assertEquals(NETWORK_TYPE, mapClickEvent.getCellularNetworkType());
|
||||
assertEquals(CREATED, mapClickEvent.getCreated());
|
||||
assertEquals(TelemetryConstants.DOUBLE_TAP, mapClickEvent.getGesture());
|
||||
assertEquals(PhoneState.LANDSCAPE, mapClickEvent.getOrientation());
|
||||
assertEquals("Landscape", mapClickEvent.getOrientation());
|
||||
assertEquals(PLUGIN, mapClickEvent.isPluggedIn());
|
||||
assertEquals(WIFI, mapClickEvent.isWifi());
|
||||
String json = gson.toJson(mapClickEvent);
|
||||
MapClickEvent event = gson.fromJson(json, MapClickEvent.class);
|
||||
assertEquals(mapClickEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,12 +82,15 @@ public class MapEventFactoryTest {
|
||||
assertEquals(CARRIER, mapLoadEvent.getCarrier());
|
||||
assertEquals(NETWORK_TYPE, mapLoadEvent.getCellularNetworkType());
|
||||
assertEquals(CREATED, mapLoadEvent.getCreated());
|
||||
assertEquals(PhoneState.LANDSCAPE, mapLoadEvent.getOrientation());
|
||||
assertEquals("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);
|
||||
String json = gson.toJson(mapLoadEvent);
|
||||
MapLoadEvent event = gson.fromJson(json, MapLoadEvent.class);
|
||||
assertEquals(mapLoadEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,9 +103,12 @@ public class MapEventFactoryTest {
|
||||
assertEquals(CARRIER, mapDraggedEvent.getCarrier());
|
||||
assertEquals(NETWORK_TYPE, mapDraggedEvent.getCellularNetworkType());
|
||||
assertEquals(CREATED, mapDraggedEvent.getCreated());
|
||||
assertEquals(PhoneState.LANDSCAPE, mapDraggedEvent.getOrientation());
|
||||
assertEquals("Landscape", mapDraggedEvent.getOrientation());
|
||||
assertEquals(PLUGIN, mapDraggedEvent.isPluggedIn());
|
||||
assertEquals(WIFI, mapDraggedEvent.isWifi());
|
||||
String json = gson.toJson(mapDraggedEvent);
|
||||
MapDragendEvent event = gson.fromJson(json, MapDragendEvent.class);
|
||||
assertEquals(mapDraggedEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,6 +123,9 @@ public class MapEventFactoryTest {
|
||||
assertEquals(NUMBER_OF_TILE_COMPLETED, offlineDownloadEndEvent.getNumberOfTilesCompleted());
|
||||
assertEquals(STATE, offlineDownloadEndEvent.getState());
|
||||
assertEquals(CREATED, offlineDownloadEndEvent.getCreated());
|
||||
String json = gson.toJson(offlineDownloadEndEvent);
|
||||
OfflineDownloadEndEvent event = gson.fromJson(json, OfflineDownloadEndEvent.class);
|
||||
assertEquals(offlineDownloadEndEvent, event);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,5 +137,8 @@ public class MapEventFactoryTest {
|
||||
assertEquals(MAX_ZOOM, offlineDownloadStartEvent.getMaxZoom());
|
||||
assertEquals(STYLE_URL, offlineDownloadStartEvent.getStyleURL());
|
||||
assertEquals(CREATED, offlineDownloadStartEvent.getCreated());
|
||||
String json = gson.toJson(offlineDownloadStartEvent);
|
||||
OfflineDownloadStartEvent event = gson.fromJson(json, OfflineDownloadStartEvent.class);
|
||||
assertEquals(offlineDownloadStartEvent, event);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user