use of org.infobip.mobile.messaging.geo.GeoLatLng in project mobile-messaging-sdk-android by infobip.
the class GeoTransitionHelper method resolveTransitionFromIntent.
/**
* Resolves transition information from geofencing intent
*
* @param intent geofencing intent
* @return transition information
* @throws RuntimeException if information cannot be resolved
*/
static GeoTransition resolveTransitionFromIntent(Intent intent) throws RuntimeException {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent == null) {
throw new RuntimeException("Geofencing event is null, cannot process");
}
if (geofencingEvent.hasError()) {
if (geofencingEvent.getErrorCode() == GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE) {
throw new GeofenceNotAvailableException();
}
throw new RuntimeException("ERROR: " + GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode()));
}
GeoEventType event = supportedTransitionEvents.get(geofencingEvent.getGeofenceTransition());
if (event == null) {
throw new RuntimeException("Transition is not supported: " + geofencingEvent.getGeofenceTransition());
}
Set<String> triggeringRequestIds = new ArraySet<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
triggeringRequestIds.add(geofence.getRequestId());
}
Location location = geofencingEvent.getTriggeringLocation();
return new GeoTransition(event, triggeringRequestIds, new GeoLatLng(location.getLatitude(), location.getLongitude()));
}
use of org.infobip.mobile.messaging.geo.GeoLatLng in project mobile-messaging-sdk-android by infobip.
the class GeoReportHelper method createNewMessageForReport.
/**
* Creates new message based on geofencing report
*
* @param report geofencing report for any supported event
* @param reportingResult result of reporting geo events to server
* @param originalMessage original signaling message
* @return new message based on triggering event, area and original signaling message
*/
private static Message createNewMessageForReport(@NonNull final GeoReport report, @NonNull GeoReportingResult reportingResult, @NonNull Message originalMessage) {
GeoLatLng triggeringLocation = report.getTriggeringLocation();
if (triggeringLocation == null) {
triggeringLocation = new GeoLatLng(null, null);
}
List<Area> areas = new ArrayList<>();
if (report.getArea() != null) {
areas.add(report.getArea());
}
Geo geo;
Geo originalMessageGeo = GeoDataMapper.geoFromInternalData(originalMessage.getInternalData());
if (originalMessageGeo != null) {
geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), originalMessageGeo.getDeliveryTime(), originalMessageGeo.getExpiryTime(), originalMessageGeo.getStartTime(), originalMessageGeo.getCampaignId(), areas, originalMessageGeo.getEvents(), originalMessage.getSentTimestamp(), originalMessage.getContentUrl());
} else {
geo = new Geo(triggeringLocation.getLat(), triggeringLocation.getLng(), null, null, null, null, areas, null, Time.now(), originalMessage.getContentUrl());
}
String internalData = GeoDataMapper.geoToInternalData(geo);
return new Message(getMessageIdFromReport(report, reportingResult), originalMessage.getTitle(), originalMessage.getBody(), originalMessage.getSound(), originalMessage.isVibrate(), originalMessage.getIcon(), // enforcing non-silent
false, originalMessage.getCategory(), originalMessage.getFrom(), Time.now(), 0, Time.now(), originalMessage.getCustomPayload(), internalData, originalMessage.getDestination(), originalMessage.getStatus(), originalMessage.getStatusMessage(), originalMessage.getContentUrl());
}
Aggregations