Search in sources :

Example 1 with GeoLatLng

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()));
}
Also used : ArraySet(android.support.v4.util.ArraySet) GeoLatLng(org.infobip.mobile.messaging.geo.GeoLatLng) GeoEventType(org.infobip.mobile.messaging.geo.GeoEventType) GeofencingEvent(com.google.android.gms.location.GeofencingEvent) Geofence(com.google.android.gms.location.Geofence) Location(android.location.Location)

Example 2 with GeoLatLng

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());
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) GeoLatLng(org.infobip.mobile.messaging.geo.GeoLatLng) ArrayList(java.util.ArrayList)

Aggregations

GeoLatLng (org.infobip.mobile.messaging.geo.GeoLatLng)2 Location (android.location.Location)1 ArraySet (android.support.v4.util.ArraySet)1 Geofence (com.google.android.gms.location.Geofence)1 GeofencingEvent (com.google.android.gms.location.GeofencingEvent)1 ArrayList (java.util.ArrayList)1 Message (org.infobip.mobile.messaging.Message)1 Area (org.infobip.mobile.messaging.geo.Area)1 Geo (org.infobip.mobile.messaging.geo.Geo)1 GeoEventType (org.infobip.mobile.messaging.geo.GeoEventType)1