[android]added generic performance event (#13795)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.mapbox.mapboxsdk.maps;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
|
||||
|
||||
/**
|
||||
* Definition of TelemetryImpl collection
|
||||
* Definition of TelemetryImpl collection.
|
||||
* Use{@link TelemetryDefinition} for posting the event.
|
||||
*/
|
||||
public interface TelemetryDefinition {
|
||||
|
||||
@@ -46,4 +49,11 @@ public interface TelemetryDefinition {
|
||||
* @param offlineDefinition the offline region definition
|
||||
*/
|
||||
void onCreateOfflineRegion(OfflineRegionDefinition offlineDefinition);
|
||||
|
||||
/**
|
||||
* Register a performance event.
|
||||
*
|
||||
* @param data performance event data
|
||||
*/
|
||||
void onPerformanceEvent(Bundle data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import com.mapbox.android.telemetry.Event;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Generic Performance Event that can be used for performance measurements.
|
||||
* Customer measurements can be added to the bundle.
|
||||
*/
|
||||
public class PerformanceEvent extends Event {
|
||||
private static final String PERFORMANCE_TRACE = "performance.trace";
|
||||
|
||||
private final String event;
|
||||
|
||||
private final String created;
|
||||
|
||||
private final String sessionId;
|
||||
|
||||
private final Bundle data;
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMAT =
|
||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
|
||||
|
||||
PerformanceEvent(String sessionId, Bundle data) {
|
||||
this.event = PERFORMANCE_TRACE;
|
||||
this.created = DATE_FORMAT.format(new Date());
|
||||
this.sessionId = sessionId;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
private PerformanceEvent(Parcel in) {
|
||||
this.event = in.readString();
|
||||
this.created = in.readString();
|
||||
this.sessionId = in.readString();
|
||||
this.data = in.readBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeString(event);
|
||||
parcel.writeString(created);
|
||||
parcel.writeString(sessionId);
|
||||
parcel.writeBundle(data);
|
||||
}
|
||||
|
||||
public static final Creator<PerformanceEvent> CREATOR = new Creator<PerformanceEvent>() {
|
||||
@Override
|
||||
public PerformanceEvent createFromParcel(Parcel in) {
|
||||
return new PerformanceEvent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PerformanceEvent[] newArray(int size) {
|
||||
return new PerformanceEvent[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mapbox.mapboxsdk.module.telemetry;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.mapbox.android.telemetry.AppUserTurnstile;
|
||||
@@ -17,6 +18,8 @@ import com.mapbox.mapboxsdk.maps.TelemetryDefinition;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineRegionDefinition;
|
||||
import com.mapbox.mapboxsdk.offline.OfflineTilePyramidRegionDefinition;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TelemetryImpl implements TelemetryDefinition {
|
||||
|
||||
@Nullable
|
||||
@@ -105,4 +108,11 @@ public class TelemetryImpl implements TelemetryDefinition {
|
||||
offlineDefinition.getStyleURL())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPerformanceEvent(Bundle data) {
|
||||
if (data != null && !data.isEmpty()) {
|
||||
telemetry.push(new PerformanceEvent(UUID.randomUUID().toString(), data));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user