Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[Android]Add MapEventFactory #14309

Merged
merged 12 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/android/MapboxGLAndroidSDK/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dependency-graph-mapbox-libraries.png
src/test/resources/mobile-event*
1 change: 1 addition & 0 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
testImplementation dependenciesList.mockk
testImplementation dependenciesList.robolectric
testImplementation dependenciesList.kotlinLib
testImplementation dependenciesList.commonsIO
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mapbox.mapboxsdk.module.telemetry;

import android.annotation.SuppressLint;
import android.os.Parcel;

import com.mapbox.android.telemetry.Event;

/**
* Base event class for telemetry events.
*/
@SuppressLint("ParcelCreator")
public abstract class MapBaseEvent extends Event {
private final String event;
private final String created;

MapBaseEvent(PhoneState phoneState) {
this.event = getEventName();
this.created = phoneState.getCreated();
}

abstract String getEventName();

public String getEvent() {
return event;
}

public String getCreated() {
return created;
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.mapbox.mapboxsdk.module.telemetry;

import android.annotation.SuppressLint;

/**
* Event that represents users' gestures on map, for the details of gestures,
* please refer to {@link com.mapbox.mapboxsdk.constants.TelemetryConstants}
*/
@SuppressLint("ParcelCreator")
tobrun marked this conversation as resolved.
Show resolved Hide resolved
class MapClickEvent extends MapBaseEvent {
private static final String EVENT_NAME = "map.click";
private final String gesture;
private final String cellularNetworkType;
private final String carrier;
private final String orientation;
private final double lat;
private final double lng;
private final double zoom;
private final int batteryLevel;
private final boolean pluggedIn;
private final boolean wifi;

MapClickEvent(PhoneState phoneState, MapState mapState) {
super(phoneState);
this.gesture = mapState.getGesture();
this.lat = mapState.getLatitude();
this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.batteryLevel = phoneState.getBatteryLevel();
this.pluggedIn = phoneState.isPluggedIn();
this.cellularNetworkType = phoneState.getCellularNetworkType();
this.orientation = phoneState.getOrientation();
this.carrier = phoneState.getCarrier();
this.wifi = phoneState.isWifi();
}

@Override
String getEventName() {
return EVENT_NAME;
}

String getGesture() {
return gesture;
}

String getCellularNetworkType() {
return cellularNetworkType;
}

String getCarrier() {
return carrier;
}

String getOrientation() {
return orientation;
}

double getLat() {
return lat;
}

double getLng() {
return lng;
}

double getZoom() {
return zoom;
}

int getBatteryLevel() {
return batteryLevel;
}

boolean isPluggedIn() {
return pluggedIn;
}

boolean isWifi() {
return wifi;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

MapClickEvent that = (MapClickEvent) o;

if (Double.compare(that.lat, lat) != 0) {
return false;
}
if (Double.compare(that.lng, lng) != 0) {
return false;
}
if (Double.compare(that.zoom, zoom) != 0) {
return false;
}
if (batteryLevel != that.batteryLevel) {
return false;
}
if (pluggedIn != that.pluggedIn) {
return false;
}
if (wifi != that.wifi) {
return false;
}
if (gesture != null ? !gesture.equals(that.gesture) : that.gesture != null) {
return false;
}
if (cellularNetworkType != null ? !cellularNetworkType.equals(that.cellularNetworkType) :
that.cellularNetworkType != null) {
return false;
}
if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) {
return false;
}
return orientation != null ? orientation.equals(that.orientation) : that.orientation == null;
}

@Override
public int hashCode() {
int result;
long temp;
result = gesture != null ? gesture.hashCode() : 0;
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (orientation != null ? orientation.hashCode() : 0);
temp = Double.doubleToLongBits(lat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(lng);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + batteryLevel;
result = 31 * result + (pluggedIn ? 1 : 0);
result = 31 * result + (wifi ? 1 : 0);
return result;
}

@Override
public String toString() {
return "MapClickEvent{"
+ ", gesture='" + gesture + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
+ ", carrier='" + carrier + '\''
+ ", orientation='" + orientation + '\''
+ ", lat=" + lat
+ ", lng=" + lng
+ ", zoom=" + zoom
+ ", batteryLevel=" + batteryLevel
+ ", pluggedIn=" + pluggedIn
+ ", wifi=" + wifi
+ '}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.mapbox.mapboxsdk.module.telemetry;

import android.annotation.SuppressLint;

/**
* When user drag map should send this event.
*/
@SuppressLint("ParcelCreator")
class MapDragendEvent extends MapBaseEvent {
private static final String EVENT_NAME = "map.dragend";
private final String orientation;
private final String carrier;
private final String cellularNetworkType;
private final int batteryLevel;
private final double lat;
private final double lng;
private final double zoom;
private final boolean pluggedIn;
private final boolean wifi;

MapDragendEvent(PhoneState phoneState, MapState mapState) {
super(phoneState);
this.lat = mapState.getLatitude();
this.lng = mapState.getLongitude();
this.zoom = mapState.getZoom();
this.batteryLevel = phoneState.getBatteryLevel();
this.pluggedIn = phoneState.isPluggedIn();
this.cellularNetworkType = phoneState.getCellularNetworkType();
this.wifi = phoneState.isWifi();
this.orientation = phoneState.getOrientation();
this.carrier = phoneState.getCarrier();
}

@Override
String getEventName() {
return EVENT_NAME;
}

String getOrientation() {
return orientation;
}

String getCarrier() {
return carrier;
}

String getCellularNetworkType() {
return cellularNetworkType;
}

int getBatteryLevel() {
return batteryLevel;
}

double getLat() {
return lat;
}

double getLng() {
return lng;
}

double getZoom() {
return zoom;
}

boolean isPluggedIn() {
return pluggedIn;
}

boolean isWifi() {
return wifi;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

MapDragendEvent that = (MapDragendEvent) o;

if (batteryLevel != that.batteryLevel) {
return false;
}
if (Double.compare(that.lat, lat) != 0) {
return false;
}
if (Double.compare(that.lng, lng) != 0) {
return false;
}
if (Double.compare(that.zoom, zoom) != 0) {
return false;
}
if (pluggedIn != that.pluggedIn) {
return false;
}
if (wifi != that.wifi) {
return false;
}
if (orientation != null ? !orientation.equals(that.orientation) : that.orientation != null) {
return false;
}
if (carrier != null ? !carrier.equals(that.carrier) : that.carrier != null) {
return false;
}
return cellularNetworkType != null ? cellularNetworkType.equals(that.cellularNetworkType) :
that.cellularNetworkType == null;
}

@Override
public int hashCode() {
int result;
long temp;
result = orientation != null ? orientation.hashCode() : 0;
result = 31 * result + (carrier != null ? carrier.hashCode() : 0);
result = 31 * result + (cellularNetworkType != null ? cellularNetworkType.hashCode() : 0);
result = 31 * result + batteryLevel;
temp = Double.doubleToLongBits(lat);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(lng);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(zoom);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (pluggedIn ? 1 : 0);
result = 31 * result + (wifi ? 1 : 0);
return result;
}

@Override
public String toString() {
return "MapDragendEvent{"
+ ", orientation='" + orientation + '\''
+ ", carrier='" + carrier + '\''
+ ", cellularNetworkType='" + cellularNetworkType + '\''
+ ", batteryLevel=" + batteryLevel
+ ", lat=" + lat
+ ", lng=" + lng
+ ", zoom=" + zoom
+ ", pluggedIn=" + pluggedIn
+ ", wifi=" + wifi
+ '}';
}
}
Loading