Skip to content

Commit

Permalink
Updating underlying iOS & Android SDKs to 3.2.0 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kierangraham committed Nov 29, 2016
1 parent d7c999a commit 2df6edc
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 102 deletions.
12 changes: 7 additions & 5 deletions plugin.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-predict-io"
version="3.1.0">
version="3.2.0">

<name>PredictIOPlugin</name>

Expand All @@ -17,9 +17,10 @@
</config-file>

<header-file src="src/ios/PredictIO.h" />
<header-file src="src/ios/PIOTripSegment.h" />
<header-file src="src/ios/PredictIOPlugin.h" />
<source-file src="src/ios/PredictIOPlugin.m" />
<header-file src="src/ios/PIOTripSegment.h" />
<header-file src="src/ios/PredictIOPlugin.h" />
<header-file src="src/ios/PIOZone.h" />
<source-file src="src/ios/PredictIOPlugin.m" />
<source-file src="src/ios/libPredictIOSDK.a" framework="true" />

<framework src="CoreTelephony.framework" />
Expand Down Expand Up @@ -86,10 +87,11 @@
</config-file>

<source-file src="src/android/PredictIOPlugin.java" target-dir="src/io/predict/plugin/" />
<source-file src="src/android/predict-io-3.2.0.jar" target-dir="libs" />
<source-file src="src/android/PredictIOForegroundService.java" target-dir="src/io/predict/plugin/" />
<source-file src="src/android/predict-io-3.1.0.jar" target-dir="libs" />

<framework src="com.google.android.gms:play-services-location:9.4.0" />
<framework src="com.google.android.gms:play-services-base:9.4.0" />
<framework src="com.google.android.gms:play-services-maps:9.4.0" />
</platform>
</plugin>
72 changes: 58 additions & 14 deletions src/android/PredictIOPlugin.java
Expand Up @@ -7,6 +7,7 @@
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.google.android.gms.common.ConnectionResult;
Expand All @@ -21,6 +22,7 @@
import org.json.JSONObject;

import io.predict.PIOTripSegment;
import io.predict.PIOZone;
import io.predict.PredictIO;
import io.predict.PredictIOListener;
import io.predict.PredictIOStatus;
Expand Down Expand Up @@ -230,7 +232,7 @@ private void stopTracker(CallbackContext callbackContext) {
}
}

public Context getApplicationContext() {
private Context getApplicationContext() {
return this.cordova.getActivity().getApplicationContext();
}

Expand All @@ -248,9 +250,9 @@ public void searchingInPerimeter(Location location) {
}

@Override
public void arrivalSuspected(PIOTripSegment tripSegment) {
public void suspectedArrival(PIOTripSegment tripSegment) {
String param = getJsonParams(tripSegment);
evaluateJavascript("arrivalSuspected('" + param + "')");
evaluateJavascript("suspectedArrival('" + param + "')");
}

@Override
Expand All @@ -260,9 +262,21 @@ public void arrived(PIOTripSegment tripSegment) {
}

@Override
public void departureCanceled(PIOTripSegment tripSegment) {
public void traveledByAirplane(PIOTripSegment tripSegment) {
String param = getJsonParams(tripSegment);
evaluateJavascript("departureCanceled('" + param + "')");
evaluateJavascript("traveledByAirplane('" + param + "')");
}

@Override
public void beingStationaryAfterArrival(PIOTripSegment tripSegment) {
String param = getJsonParams(tripSegment);
evaluateJavascript("beingStationaryAfterArrival('" + param + "')");
}

@Override
public void canceledDeparture(PIOTripSegment tripSegment) {
String param = getJsonParams(tripSegment);
evaluateJavascript("canceledDeparture('" + param + "')");
}

@Override
Expand All @@ -273,9 +287,9 @@ public void didUpdateLocation(Location location) {
}

@Override
public void transportationMode(PIOTripSegment tripSegment) {
public void detectedTransportationMode(PIOTripSegment tripSegment) {
String param = getJsonParams(tripSegment);
evaluateJavascript("transportationMode('" + param + "')");
evaluateJavascript("detectedTransportationMode('" + param + "')");
}

private String getJsonParams(Location location) {
Expand All @@ -295,19 +309,21 @@ private String getJsonParams(PIOTripSegment tripSegment) {
JSONObject jsonParam = new JSONObject();
try {
jsonParam.put("UUID", tripSegment.UUID);
if (tripSegment.departureTime != null) {
jsonParam.put("departureTime", tripSegment.departureTime.getTime());
}
jsonParam.put("departureTime", tripSegment.departureTime != null ? tripSegment.departureTime.getTime() : null);
if (tripSegment.departureLocation != null) {
jsonParam.put("departureLatitude", tripSegment.departureLocation.getLatitude());
jsonParam.put("departureLongitude", tripSegment.departureLocation.getLongitude());
} else {
jsonParam.put("departureLatitude", null);
jsonParam.put("departureLongitude", null);
}
if (tripSegment.arrivalTime != null) {
jsonParam.put("arrivalTime", tripSegment.arrivalTime.getTime());
}
jsonParam.put("arrivalTime", tripSegment.arrivalTime != null ? tripSegment.arrivalTime.getTime() : null);
if (tripSegment.arrivalLocation != null) {
jsonParam.put("arrivalLatitude", tripSegment.arrivalLocation.getLatitude());
jsonParam.put("arrivalLongitude", tripSegment.arrivalLocation.getLongitude());
} else {
jsonParam.put("arrivalLatitude", null);
jsonParam.put("arrivalLongitude", null);
}
if (tripSegment.transportationMode != null) {
String transportationMode = "Undetermined";
Expand All @@ -319,13 +335,41 @@ private String getJsonParams(PIOTripSegment tripSegment) {
transportationMode = "Bicycle";
}
jsonParam.put("transportationMode", transportationMode);
} else {
jsonParam.put("transportationMode", null);
}
jsonParam.put("stationaryAfterArrival", tripSegment.stationaryAfterArrival);
jsonParam.put("departureZone", getZoneParams(tripSegment.departureZone));
jsonParam.put("arrivalZone", getZoneParams(tripSegment.arrivalZone));
} catch (JSONException e) {
e.printStackTrace();
}
return jsonParam.toString();
}

@Nullable
private JSONObject getZoneParams(PIOZone pioZone) throws JSONException {
if (pioZone != null && pioZone.center != null) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("zoneCenterLatitude", pioZone.center.latitude);
jsonObject.put("zoneCenterLongitude", pioZone.center.longitude);
jsonObject.put("zoneRadius", pioZone.radius);
if (pioZone.zoneType != null) {
String zoneType = "Other";
if (pioZone.zoneType == PIOZone.PIOZoneType.HOME) {
zoneType = "Home";
} else if (pioZone.zoneType == PIOZone.PIOZoneType.WORK) {
zoneType = "Work";
}
jsonObject.put("zoneType", zoneType);
} else {
jsonObject.put("zoneType", null);
}
return jsonObject;
}
return null;
}

private void evaluateJavascript(final String js) {
if (webView != null && webView.getView() != null) {
webView.getView().post(new Runnable() {
Expand All @@ -350,4 +394,4 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
break;
}
}
}
}
Binary file not shown.
29 changes: 21 additions & 8 deletions src/ios/PIOTripSegment.h
Expand Up @@ -2,12 +2,13 @@
// PIOTripSegment.h
// PredictIOSDK
//
// Created by Abdul Haseeb on 8/8/16.
// Created by Abdul Haseeb on 08/08/2016.
// Copyright (c) 2016 predict.io by ParkTAG GmbH. All rights reserved.
// SDK Version 3.1.0
// SDK Version 3.2.0

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import "PIOZone.h"

/*
* PredictIOStatus
Expand Down Expand Up @@ -70,11 +71,23 @@ typedef NS_ENUM(int, LogLevel) {
/** @brief Predicted mode of transport */
@property (assign, readonly) TransportationMode transportationMode;

- (id)initWithUUID:(NSString *)UUID
departureLocation:(CLLocation *)departureLocation
arrivalLocation:(CLLocation *)arrivalLocation
departureTime:(NSDate *)departureTime
arrivalTime:(NSDate *)arrivalTime
transportationMode:(TransportationMode)transportationMode;
/** @brief Departure Zone */
@property (strong, readonly) PIOZone *departureZone;

/** @brief Arrival Zone */
@property (strong, readonly) PIOZone *arrivalZone;

/** @brief Stationary after arrival at destination **/
@property (assign, readonly) BOOL stationaryAfterArrival;

- (instancetype)initWithUUID:(NSString *)UUID
departureLocation:(CLLocation *)departureLocation
arrivalLocation:(CLLocation *)arrivalLocation
departureTime:(NSDate *)departureTime
arrivalTime:(NSDate *)arrivalTime
transportationMode:(TransportationMode)transportationMode
departureZone:(PIOZone *)departureZone
arrivalZone:(PIOZone *)arrivalZone
stationaryAfterArrival:(BOOL)stationaryAfterArrival;

@end
34 changes: 34 additions & 0 deletions src/ios/PIOZone.h
@@ -0,0 +1,34 @@
//
// PIOZone.h
// PredictIOSDK
//
// Created by Umer on 09/06/2016.
// Copyright (c) 2016 predict.io by ParkTAG GmbH. All rights reserved.
// SDK Version 3.2.0
//

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

typedef NS_ENUM(int, PIOZoneType) {
// some arbitrary zone
PIOZoneTypeOther = 0,

// home zone
PIOZoneTypeHome,

// work zone
PIOZoneTypeWork
};

@interface PIOZone : NSObject

@property (assign, readonly) PIOZoneType zoneType;
@property (assign, readonly) CLLocationDistance radius;
@property (assign, readonly) CLLocationCoordinate2D center;

- (instancetype)initWithCenter:(CLLocationCoordinate2D)center
radius:(CLLocationDistance)radius
zoneType:(PIOZoneType)zoneType;

@end

0 comments on commit 2df6edc

Please sign in to comment.