Skip to content

Commit

Permalink
SDK 3.4 support (#48)
Browse files Browse the repository at this point in the history
* update to SDK 3.4.2
* add wayfinding A->B route request support
* cleanup some iOS cruft
* set IAWrapper at runtime for iOS (so no need for custom Info.plist anymore)
* add time based filter support
* add LP/cart-mode support
  • Loading branch information
matti-ida authored Feb 24, 2021
1 parent a130c49 commit 3190b31
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 88 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 3.4.0 - February 2021
----------------
* Update IndoorAtlas SDKs to 3.4.2
* Add wayfinding A->B route request support
* Add time based location updates support
* Add low power and cart-mode support

Version 3.3.2 - November 2020
----------------
* Update IndoorAtlas SDKs to 3.3.6
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "cordova-plugin-indooratlas",
"version": "3.3.2",
"version": "3.4.0",
"description": "Cordova plugin using IndoorAtlas SDK.",
"cordova": {
"id": "cordova-plugin-indooratlas",
"platforms": [
"android",
"ios"
"ios"
]
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-indooratlas"
version="3.3.2">
version="3.4.0">

<name>IndoorAtlas</name>
<description>IndoorAtlas Cordova Plugin.</description>
Expand Down
91 changes: 77 additions & 14 deletions src/android/IALocationPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
import com.indooratlas.android.sdk.IALocationManager;
import com.indooratlas.android.sdk.IALocationRequest;
import com.indooratlas.android.sdk.IARegion;
import com.indooratlas.android.sdk.IARoute;
import com.indooratlas.android.sdk.IAOrientationRequest;
import com.indooratlas.android.sdk.IAOrientationListener;
import com.indooratlas.android.sdk.IAWayfindingListener;
import com.indooratlas.android.sdk.IAWayfindingRequest;
import com.indooratlas.android.sdk.IAGeofence;
import com.indooratlas.android.sdk.IAGeofenceRequest;
import com.indooratlas.android.sdk.resources.IALatLngFloor;
import com.indooratlas.android.sdk.resources.IALatLngFloorCompatible;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
Expand All @@ -30,6 +34,8 @@
import org.json.JSONException;
import org.json.JSONObject;

import static com.ialocation.plugin.IndoorLocationListener.getRouteJSONFromIARoute;

/**
* Cordova Plugin which implements IndoorAtlas positioning service.
* IndoorAtlas.initialize method should always be called before starting positioning session.
Expand Down Expand Up @@ -168,9 +174,13 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
String watchId = args.getString(0);
clearRegionWatch(watchId);
callbackContext.success();
} else if ("setDistanceFilter".equals(action)) {
} else if ("setOutputThresholds".equals(action)) {
float distance = (float) args.getDouble(0);
setDistanceFilter(distance, callbackContext);
float interval = (float) args.getDouble(1);
setOutputThresholds(distance, interval, callbackContext);
} else if ("setPositioningMode".equals(action)) {
String mode = args.getString(0);
setPositioningMode(mode, callbackContext);
} else if ("getTraceId".equals(action)) {
getTraceId(callbackContext);
} else if ("getFloorCertainty".equals(action)) {
Expand All @@ -196,6 +206,18 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
double lon = args.getDouble(1);
int floor = args.getInt(2);
requestWayfindingUpdates(lat, lon, floor, callbackContext);
} else if ("requestWayfindingRoute".equals(action)) {
JSONObject _from = args.getJSONObject(0);
JSONObject _to = args.getJSONObject(1);
IALatLngFloor from = new IALatLngFloor(
_from.getDouble("latitude"),
_from.getDouble("longitude"),
_from.getInt("floor"));
IALatLngFloor to = new IALatLngFloor(
_to.getDouble("latitude"),
_to.getDouble("longitude"),
_to.getInt("floor"));
requestWayfindingRoute(from, to, callbackContext);
} else if ("removeWayfindingUpdates".equals(action)) {
removeWayfindingUpdates();
} else if ("watchGeofences".equals(action)) {
Expand Down Expand Up @@ -387,6 +409,28 @@ public void run() {
});
}

private void requestWayfindingRoute(
IALatLngFloorCompatible from,
IALatLngFloorCompatible to,
CallbackContext callbackContext
) {
IAWayfindingListener listener = new IAWayfindingListener() {
@Override
public void onWayfindingUpdate(IARoute route) {
PluginResult pluginResult;
pluginResult = new PluginResult(PluginResult.Status.OK, getRouteJSONFromIARoute(route));
pluginResult.setKeepCallback(false);
callbackContext.sendPluginResult(pluginResult);
}
};
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mLocationManager.requestWayfindingRoute(from, to, listener);
}
});
}

private IAGeofence geofenceFromJsonObject(JSONObject geoJson) {
try {
List<double[]> iaEdges = new ArrayList<>();
Expand Down Expand Up @@ -596,24 +640,43 @@ protected void startPositioning(CallbackContext callbackContext) {
callbackContext.error(PositionError.getErrorObject(PositionError.INITIALIZATION_ERROR));
}
}

private void setPositioningMode(String mode, CallbackContext callbackContext) {
int priority;
switch (mode) {
case "HIGH_ACCURACY": priority = IALocationRequest.PRIORITY_HIGH_ACCURACY; break;
case "LOW_POWER": priority = IALocationRequest.PRIORITY_LOW_POWER; break;
case "CART": priority = IALocationRequest.PRIORITY_CART_MODE; break;
default:
callbackContext.error(PositionError.getErrorObject(PositionError.INVALID_POSITIONING_MODE));
return;
}
mLocationRequest.setPriority(priority);
}

private void setDistanceFilter(float distance, CallbackContext callbackContext) {
private void setOutputThresholds(float distance, float interval, CallbackContext callbackContext) {
if (distance < 0 || interval < 0) {
callbackContext.error(PositionError.getErrorObject(PositionError.INVALID_OUTPUT_THRESHOLD_VALUE));
return;
}
final boolean wasRunning = mLocationServiceRunning;
if (wasRunning) stopPositioning();
if (distance >= 0) {
mLocationRequest.setSmallestDisplacement(distance);
JSONObject successObject = new JSONObject();
try {
successObject.put("message","Distance filter set");
} catch (JSONException ex) {
Log.e(TAG, ex.toString());
throw new IllegalStateException(ex.getMessage());
}
callbackContext.success(successObject);
if (wasRunning) startPositioning();
} else {
callbackContext.error(PositionError.getErrorObject(PositionError.INVALID_VALUE));
}
if (interval >= 0) {
// convert to milliseconds
mLocationRequest.setFastestInterval((long)(interval * 1000));
}
JSONObject successObject = new JSONObject();
try {
successObject.put("message","Output thresholds set");
} catch (JSONException ex) {
Log.e(TAG, ex.toString());
throw new IllegalStateException(ex.getMessage());
}
callbackContext.success(successObject);
if (wasRunning) startPositioning();
}

private void getTraceId(CallbackContext callbackContext) {
Expand Down
7 changes: 4 additions & 3 deletions src/android/IndoorLocationListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,15 @@ private JSONObject getLocationJSONFromIALocation(IALocation iaLocation) {
}
}

private JSONObject getRouteJSONFromIARoute(IARoute route) {
static JSONObject getRouteJSONFromIARoute(IARoute route) {
JSONObject obj = new JSONObject();
try {
JSONArray jsonArray = new JSONArray();
for (IARoute.Leg leg : route.getLegs()) {
jsonArray.put(jsonObjectFromRoutingLeg(leg));
}
obj.put("legs", jsonArray);
obj.put("error", route.getError().name());
} catch(JSONException e) {
Log.e("IAWAYFINDER", "json error with route");
}
Expand All @@ -351,7 +352,7 @@ private JSONObject getRouteJSONFromIARoute(IARoute route) {
/**
* Create JSON object from the given RoutingLeg object
*/
private JSONObject jsonObjectFromRoutingLeg(IARoute.Leg routingLeg) {
private static JSONObject jsonObjectFromRoutingLeg(IARoute.Leg routingLeg) {
JSONObject obj = new JSONObject();
try {
obj.put("begin", jsonObjectFromRoutingPoint(routingLeg.getBegin()));
Expand All @@ -368,7 +369,7 @@ private JSONObject jsonObjectFromRoutingLeg(IARoute.Leg routingLeg) {
/**
* Create JSON object from RoutingPoint object
*/
private JSONObject jsonObjectFromRoutingPoint(IARoute.Point routingPoint) {
private static JSONObject jsonObjectFromRoutingPoint(IARoute.Point routingPoint) {
JSONObject obj = new JSONObject();
try {
obj.put("latitude", routingPoint.getLatitude());
Expand Down
17 changes: 10 additions & 7 deletions src/android/PositionError.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class PositionError {
public static final int FLOOR_PLAN_UNAVAILABLE = 6;
public static final int UNSPECIFIED_ERROR = 7;
public static final int FLOOR_PLAN_UNDEFINED = 8;
public static final int INVALID_VALUE = 9;

public static final int INVALID_OUTPUT_THRESHOLD_VALUE = 9;
public static final int INVALID_POSITIONING_MODE = 10;

/**
* Returns an error JSON object with given errorCode and message
* @param errorCode
Expand Down Expand Up @@ -77,13 +78,15 @@ public static JSONObject getErrorObject(int errorCode) {
errorObject.put("code", errorCode);
errorObject.put("message", "Floor plan undefined. See ~/www/jsAPIKeys.js file");
break;
case INVALID_VALUE:
errorObject.put("code", errorCode);
errorObject.put("message", "Distance value should be positive");
case UNSPECIFIED_ERROR:
case INVALID_OUTPUT_THRESHOLD_VALUE:
errorObject.put("code", errorCode);
errorObject.put("message", "Unspecified error");
errorObject.put("message", "Distance and time filter values should be positive");
break;
case INVALID_POSITIONING_MODE:
errorObject.put("code", errorCode);
errorObject.put("message", "Invalid positioning mode");
break;
case UNSPECIFIED_ERROR:
default:
errorObject.put("code", errorCode);
errorObject.put("message", "Unspecified error");
Expand Down
2 changes: 1 addition & 1 deletion src/android/indooratlas.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ repositories {

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.indooratlas.android:indooratlas-android-sdk:3.3.6'
implementation 'com.indooratlas.android:indooratlas-android-sdk:3.4.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ INDOORATLAS_API
@property (nonatomic, readonly) NSInteger level;

/**
* Certainty that <IALocation> floor has the correct value.
* Certainty that `IALocation` floor has the correct value.
*/
@property (nonatomic, readonly) IACertainty certainty;

Expand Down
Loading

0 comments on commit 3190b31

Please sign in to comment.