@situm/react-native 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +656 -0
- package/ReactNativeSitumPlugin.podspec +22 -0
- package/SECURITY-POLICY.md +9 -0
- package/android/.gradle/5.6.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.4/gc.properties +0 -0
- package/android/.idea/.name +1 -0
- package/android/.idea/codeStyles/Project.xml +116 -0
- package/android/.idea/encodings.xml +6 -0
- package/android/.idea/misc.xml +31 -0
- package/android/.idea/sonarlint/issuestore/index.pb +15 -0
- package/android/.project +34 -0
- package/android/build.gradle +45 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/android/gradlew +172 -0
- package/android/gradlew.bat +84 -0
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/com/situm/plugin/PluginHelper.java +989 -0
- package/android/src/main/java/com/situm/plugin/SitumMapper.java +1206 -0
- package/android/src/main/java/com/situm/plugin/SitumPackage.java +29 -0
- package/android/src/main/java/com/situm/plugin/SitumPlugin.java +84 -0
- package/android/src/main/java/com/situm/plugin/SitumPluginImpl.java +344 -0
- package/android/src/main/java/com/situm/plugin/utils/ReactNativeJson.java +122 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/android/src/main/res/values/strings.xml +3 -0
- package/android/src/main/res/values/styles.xml +9 -0
- package/ios/Constants.h +14 -0
- package/ios/Constants.m +14 -0
- package/ios/RNSitumReactNativePlugin.xcodeproj/project.pbxproj +272 -0
- package/ios/SitumLocationWrapper.h +112 -0
- package/ios/SitumLocationWrapper.m +1132 -0
- package/ios/SitumPlugin.h +15 -0
- package/ios/SitumPlugin.m +911 -0
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/sdk/index.js +399 -0
- package/lib/commonjs/sdk/index.js.map +1 -0
- package/lib/commonjs/sdk/nativeInterface.js +20 -0
- package/lib/commonjs/sdk/nativeInterface.js.map +1 -0
- package/lib/commonjs/sdk/types/index.d.js +6 -0
- package/lib/commonjs/sdk/types/index.d.js.map +1 -0
- package/lib/commonjs/sdk/utils.js +22 -0
- package/lib/commonjs/sdk/utils.js.map +1 -0
- package/lib/commonjs/utils/requestPermission.js +73 -0
- package/lib/commonjs/utils/requestPermission.js.map +1 -0
- package/lib/commonjs/wayfinding/components/MapView.js +220 -0
- package/lib/commonjs/wayfinding/components/MapView.js.map +1 -0
- package/lib/commonjs/wayfinding/hooks/index.js +401 -0
- package/lib/commonjs/wayfinding/hooks/index.js.map +1 -0
- package/lib/commonjs/wayfinding/index.js +45 -0
- package/lib/commonjs/wayfinding/index.js.map +1 -0
- package/lib/commonjs/wayfinding/store/index.js +237 -0
- package/lib/commonjs/wayfinding/store/index.js.map +1 -0
- package/lib/commonjs/wayfinding/store/utils.js +44 -0
- package/lib/commonjs/wayfinding/store/utils.js.map +1 -0
- package/lib/commonjs/wayfinding/styles/colors.js +18 -0
- package/lib/commonjs/wayfinding/styles/colors.js.map +1 -0
- package/lib/commonjs/wayfinding/types/index.d.js +6 -0
- package/lib/commonjs/wayfinding/types/index.d.js.map +1 -0
- package/lib/commonjs/wayfinding/utils/index.js +11 -0
- package/lib/commonjs/wayfinding/utils/index.js.map +1 -0
- package/lib/commonjs/wayfinding/utils/mapper.js +106 -0
- package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/sdk/index.js +390 -0
- package/lib/module/sdk/index.js.map +1 -0
- package/lib/module/sdk/nativeInterface.js +18 -0
- package/lib/module/sdk/nativeInterface.js.map +1 -0
- package/lib/module/sdk/types/index.d.js +2 -0
- package/lib/module/sdk/types/index.d.js.map +1 -0
- package/lib/module/sdk/utils.js +15 -0
- package/lib/module/sdk/utils.js.map +1 -0
- package/lib/module/utils/requestPermission.js +67 -0
- package/lib/module/utils/requestPermission.js.map +1 -0
- package/lib/module/wayfinding/components/MapView.js +207 -0
- package/lib/module/wayfinding/components/MapView.js.map +1 -0
- package/lib/module/wayfinding/hooks/index.js +392 -0
- package/lib/module/wayfinding/hooks/index.js.map +1 -0
- package/lib/module/wayfinding/index.js +12 -0
- package/lib/module/wayfinding/index.js.map +1 -0
- package/lib/module/wayfinding/store/index.js +202 -0
- package/lib/module/wayfinding/store/index.js.map +1 -0
- package/lib/module/wayfinding/store/utils.js +34 -0
- package/lib/module/wayfinding/store/utils.js.map +1 -0
- package/lib/module/wayfinding/styles/colors.js +11 -0
- package/lib/module/wayfinding/styles/colors.js.map +1 -0
- package/lib/module/wayfinding/types/index.d.js +2 -0
- package/lib/module/wayfinding/types/index.d.js.map +1 -0
- package/lib/module/wayfinding/utils/index.js +4 -0
- package/lib/module/wayfinding/utils/index.js.map +1 -0
- package/lib/module/wayfinding/utils/mapper.js +100 -0
- package/lib/module/wayfinding/utils/mapper.js.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/sdk/index.d.ts +269 -0
- package/lib/typescript/src/sdk/index.d.ts.map +1 -0
- package/lib/typescript/src/sdk/nativeInterface.d.ts +2 -0
- package/lib/typescript/src/sdk/nativeInterface.d.ts.map +1 -0
- package/lib/typescript/src/sdk/utils.d.ts +7 -0
- package/lib/typescript/src/sdk/utils.d.ts.map +1 -0
- package/lib/typescript/src/utils/requestPermission.d.ts +3 -0
- package/lib/typescript/src/utils/requestPermission.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/components/MapView.d.ts +36 -0
- package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/hooks/index.d.ts +53 -0
- package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/index.d.ts +5 -0
- package/lib/typescript/src/wayfinding/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/store/index.d.ts +103 -0
- package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/store/utils.d.ts +9 -0
- package/lib/typescript/src/wayfinding/store/utils.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/styles/colors.d.ts +8 -0
- package/lib/typescript/src/wayfinding/styles/colors.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/utils/index.d.ts +3 -0
- package/lib/typescript/src/wayfinding/utils/index.d.ts.map +1 -0
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts +17 -0
- package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -0
- package/package.json +130 -0
- package/security.txt +4 -0
- package/src/index.ts +6 -0
- package/src/sdk/index.ts +656 -0
- package/src/sdk/nativeInterface.ts +18 -0
- package/src/sdk/types/index.d.ts +718 -0
- package/src/sdk/utils.ts +16 -0
- package/src/utils/requestPermission.ts +94 -0
- package/src/wayfinding/components/MapView.tsx +312 -0
- package/src/wayfinding/hooks/index.ts +539 -0
- package/src/wayfinding/index.tsx +11 -0
- package/src/wayfinding/store/index.tsx +254 -0
- package/src/wayfinding/store/utils.ts +40 -0
- package/src/wayfinding/styles/colors.tsx +6 -0
- package/src/wayfinding/types/index.d.ts +56 -0
- package/src/wayfinding/utils/index.ts +5 -0
- package/src/wayfinding/utils/mapper.ts +129 -0
|
@@ -0,0 +1,989 @@
|
|
|
1
|
+
package com.situm.plugin;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.graphics.Bitmap;
|
|
5
|
+
import android.text.TextUtils;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.Callback;
|
|
10
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
12
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
13
|
+
import com.facebook.react.bridge.WritableMap;
|
|
14
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
15
|
+
import com.situm.plugin.utils.ReactNativeJson;
|
|
16
|
+
|
|
17
|
+
import org.json.JSONArray;
|
|
18
|
+
import org.json.JSONException;
|
|
19
|
+
import org.json.JSONObject;
|
|
20
|
+
import org.locationtech.jts.geom.Coordinate;
|
|
21
|
+
import org.locationtech.jts.geom.GeometryFactory;
|
|
22
|
+
import org.locationtech.jts.geom.Polygon;
|
|
23
|
+
|
|
24
|
+
import java.util.ArrayList;
|
|
25
|
+
import java.util.Collection;
|
|
26
|
+
import java.util.HashMap;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
import java.util.Map;
|
|
29
|
+
import java.util.Objects;
|
|
30
|
+
|
|
31
|
+
import androidx.annotation.NonNull;
|
|
32
|
+
import es.situm.sdk.SitumSdk;
|
|
33
|
+
import es.situm.sdk.communication.CommunicationManager;
|
|
34
|
+
import es.situm.sdk.directions.DirectionsRequest;
|
|
35
|
+
import es.situm.sdk.error.Error;
|
|
36
|
+
import es.situm.sdk.location.LocationListener;
|
|
37
|
+
import es.situm.sdk.location.LocationRequest;
|
|
38
|
+
import es.situm.sdk.location.LocationStatus;
|
|
39
|
+
import es.situm.sdk.model.cartography.Building;
|
|
40
|
+
import es.situm.sdk.model.cartography.BuildingInfo;
|
|
41
|
+
import es.situm.sdk.model.cartography.Floor;
|
|
42
|
+
import es.situm.sdk.model.cartography.Geofence;
|
|
43
|
+
import es.situm.sdk.model.cartography.Poi;
|
|
44
|
+
import es.situm.sdk.model.cartography.PoiCategory;
|
|
45
|
+
import es.situm.sdk.model.cartography.Point;
|
|
46
|
+
import es.situm.sdk.model.directions.Route;
|
|
47
|
+
import es.situm.sdk.model.location.Location;
|
|
48
|
+
import es.situm.sdk.model.navigation.NavigationProgress;
|
|
49
|
+
import es.situm.sdk.model.realtime.RealTimeData;
|
|
50
|
+
import es.situm.sdk.navigation.NavigationListener;
|
|
51
|
+
import es.situm.sdk.navigation.NavigationManager;
|
|
52
|
+
import es.situm.sdk.navigation.NavigationRequest;
|
|
53
|
+
import es.situm.sdk.realtime.RealTimeListener;
|
|
54
|
+
import es.situm.sdk.realtime.RealTimeManager;
|
|
55
|
+
import es.situm.sdk.realtime.RealTimeRequest;
|
|
56
|
+
import es.situm.sdk.utils.Handler;
|
|
57
|
+
import es.situm.sdk.v1.SitumEvent;
|
|
58
|
+
import es.situm.sdk.location.GeofenceListener;
|
|
59
|
+
|
|
60
|
+
import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_CHANGED;
|
|
61
|
+
import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_ERROR;
|
|
62
|
+
import static com.situm.plugin.SitumPlugin.EVENT_LOCATION_STATUS_CHANGED;
|
|
63
|
+
import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_ERROR;
|
|
64
|
+
import static com.situm.plugin.SitumPlugin.EVENT_NAVIGATION_UPDATE;
|
|
65
|
+
import static com.situm.plugin.SitumPlugin.EVENT_REALTIME_ERROR;
|
|
66
|
+
import static com.situm.plugin.SitumPlugin.EVENT_REALTIME_UPDATE;
|
|
67
|
+
import static com.situm.plugin.SitumPlugin.EVENT_ENTER_GEOFENCES;
|
|
68
|
+
import static com.situm.plugin.SitumPlugin.EVENT_EXIT_GEOFENCES;
|
|
69
|
+
import static com.situm.plugin.utils.ReactNativeJson.convertJsonToArray;
|
|
70
|
+
import static com.situm.plugin.utils.ReactNativeJson.convertJsonToMap;
|
|
71
|
+
import static com.situm.plugin.utils.ReactNativeJson.convertMapToJson;
|
|
72
|
+
|
|
73
|
+
public class PluginHelper {
|
|
74
|
+
|
|
75
|
+
private static final String TAG = "PluginHelper";
|
|
76
|
+
|
|
77
|
+
private GeometryFactory geometryFactory = new GeometryFactory();
|
|
78
|
+
|
|
79
|
+
private LocationListener locationListener;
|
|
80
|
+
private LocationRequest locationRequest;
|
|
81
|
+
private NavigationListener navigationListener;
|
|
82
|
+
private NavigationRequest navigationRequest;
|
|
83
|
+
|
|
84
|
+
private boolean emitEnterGeofences = false;
|
|
85
|
+
private boolean emitExitGeofences = false;
|
|
86
|
+
|
|
87
|
+
private volatile CommunicationManager cmInstance;
|
|
88
|
+
|
|
89
|
+
private volatile NavigationManager nmInstance;
|
|
90
|
+
private RealTimeListener realtimeListener;
|
|
91
|
+
private volatile RealTimeManager rmInstance;
|
|
92
|
+
|
|
93
|
+
private Route computedRoute;
|
|
94
|
+
private Location computedLocation;
|
|
95
|
+
private Map<Geofence, Polygon> geofencePolygonMap = new HashMap<>();
|
|
96
|
+
|
|
97
|
+
private CommunicationManager getCommunicationManagerInstance() {
|
|
98
|
+
if (cmInstance == null) { // Check for the first time
|
|
99
|
+
synchronized (CommunicationManager.class) { // Check for the second time.
|
|
100
|
+
// if there is no instance available... create new one
|
|
101
|
+
if (cmInstance == null)
|
|
102
|
+
cmInstance = SitumSdk.communicationManager();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return cmInstance;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void setCommunicationManager(CommunicationManager communicationManager) {
|
|
109
|
+
cmInstance = communicationManager;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private RealTimeManager getRealtimeManagerInstance() {
|
|
113
|
+
if (rmInstance == null) {
|
|
114
|
+
synchronized (RealTimeManager.class) { // Check for the second time.
|
|
115
|
+
// if there is no instance available... create new one
|
|
116
|
+
if (rmInstance == null)
|
|
117
|
+
rmInstance = SitumSdk.realtimeManager();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return rmInstance;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private NavigationManager getNavigationManagerInstance() {
|
|
124
|
+
if (nmInstance == null) { // Check for the first time
|
|
125
|
+
synchronized (NavigationManager.class) { // Check for the second time.
|
|
126
|
+
// if there is no instance available... create new one
|
|
127
|
+
if (nmInstance == null)
|
|
128
|
+
nmInstance = SitumSdk.navigationManager();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return nmInstance;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public void setNavigationManager(NavigationManager navigationManager) {
|
|
135
|
+
nmInstance = navigationManager;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public void fetchBuildings(Callback success, Callback error) {
|
|
139
|
+
try {
|
|
140
|
+
getCommunicationManagerInstance().fetchBuildings(new Handler<Collection<Building>>() {
|
|
141
|
+
public void onSuccess(Collection<Building> buildings) {
|
|
142
|
+
try {
|
|
143
|
+
Log.d(PluginHelper.TAG, "onSuccess: Buildings fetched successfully.");
|
|
144
|
+
JSONArray jsonArrayBuildings = new JSONArray();
|
|
145
|
+
|
|
146
|
+
for (Building building : buildings) {
|
|
147
|
+
Log.i(PluginHelper.TAG,
|
|
148
|
+
"onSuccess: " + building.getIdentifier() + " - " + building.getName());
|
|
149
|
+
JSONObject jsonBuilding = SitumMapper.buildingToJsonObject(building);
|
|
150
|
+
jsonArrayBuildings.put(jsonBuilding);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (buildings.isEmpty()) {
|
|
154
|
+
Log.e(PluginHelper.TAG, "onSuccess: you have no buildings. Create one in the Dashboard");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
invokeCallback(success, convertJsonToArray(jsonArrayBuildings));
|
|
158
|
+
} catch (JSONException e) {
|
|
159
|
+
invokeCallback(error, e.getMessage());
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@Override
|
|
164
|
+
public void onFailure(Error e) {
|
|
165
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
166
|
+
invokeCallback(error, e.getMessage());
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
} catch (Exception e) {
|
|
170
|
+
invokeCallback(error, e.getMessage());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// building, floors, events, indoorPois, outdoorPois, ¿geofences? ¿Paths?
|
|
175
|
+
public void fetchTilesFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
176
|
+
try {
|
|
177
|
+
JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
|
|
178
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
|
|
179
|
+
|
|
180
|
+
getCommunicationManagerInstance().fetchTilesFromBuilding(building.getIdentifier(), new Handler<String>() {
|
|
181
|
+
@Override
|
|
182
|
+
public void onSuccess(String url) {
|
|
183
|
+
try {
|
|
184
|
+
Log.d(PluginHelper.TAG, "onSuccess: fetch building tiles offline fetched successfully.");
|
|
185
|
+
|
|
186
|
+
JSONObject jsonObject = new JSONObject();
|
|
187
|
+
jsonObject.put("results", url);
|
|
188
|
+
|
|
189
|
+
invokeCallback(success, ReactNativeJson.convertJsonToMap(jsonObject));
|
|
190
|
+
} catch (JSONException e) {
|
|
191
|
+
invokeCallback(error, e.getMessage());
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@Override
|
|
196
|
+
public void onFailure(Error e) {
|
|
197
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
198
|
+
invokeCallback(error, e.getMessage());
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
} catch (Exception e) {
|
|
203
|
+
Log.e(TAG, "Unexpected error in building info response", e.getCause());
|
|
204
|
+
invokeCallback(error, e.getMessage());
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// building, floors, events, indoorPois, outdoorPois, ¿geofences? ¿Paths?
|
|
209
|
+
public void fetchBuildingInfo(ReadableMap buildingMap, Callback success, Callback error) {
|
|
210
|
+
try {
|
|
211
|
+
JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
|
|
212
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
|
|
213
|
+
|
|
214
|
+
getCommunicationManagerInstance().fetchBuildingInfo(building, new Handler<BuildingInfo>() {
|
|
215
|
+
@Override
|
|
216
|
+
public void onSuccess(BuildingInfo object) {
|
|
217
|
+
try {
|
|
218
|
+
Log.d(PluginHelper.TAG, "onSuccess: building info fetched successfully.");
|
|
219
|
+
|
|
220
|
+
JSONObject jsonObject = SitumMapper.buildingInfoToJsonObject(object); // Include geofences to
|
|
221
|
+
// parse ? This needs to
|
|
222
|
+
// be on sdk
|
|
223
|
+
|
|
224
|
+
invokeCallback(success, ReactNativeJson.convertJsonToMap(jsonObject));
|
|
225
|
+
} catch (JSONException e) {
|
|
226
|
+
invokeCallback(error, e.getMessage());
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@Override
|
|
231
|
+
public void onFailure(Error e) {
|
|
232
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
233
|
+
invokeCallback(error, e.getMessage());
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
} catch (Exception e) {
|
|
238
|
+
Log.e(TAG, "Unexpected error in building info response", e.getCause());
|
|
239
|
+
invokeCallback(error, e.getMessage());
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public void fetchFloorsFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
244
|
+
try {
|
|
245
|
+
JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
|
|
246
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
|
|
247
|
+
|
|
248
|
+
getCommunicationManagerInstance().fetchFloorsFromBuilding(building, new Handler<Collection<Floor>>() {
|
|
249
|
+
@Override
|
|
250
|
+
public void onSuccess(Collection<Floor> floors) {
|
|
251
|
+
try {
|
|
252
|
+
Log.d(PluginHelper.TAG, "onSuccess: Floors fetched successfully.");
|
|
253
|
+
JSONArray jsonArrayFloors = new JSONArray();
|
|
254
|
+
|
|
255
|
+
for (Floor floor : floors) {
|
|
256
|
+
Log.i(PluginHelper.TAG, "onSuccess: " + floor.getIdentifier());
|
|
257
|
+
JSONObject jsonFloor = SitumMapper.floorToJsonObject(floor);
|
|
258
|
+
jsonArrayFloors.put(jsonFloor);
|
|
259
|
+
}
|
|
260
|
+
if (floors.isEmpty()) {
|
|
261
|
+
Log.e(PluginHelper.TAG, "onSuccess: you have no floors defined for this building");
|
|
262
|
+
}
|
|
263
|
+
invokeCallback(success, convertJsonToArray(jsonArrayFloors));
|
|
264
|
+
} catch (JSONException e) {
|
|
265
|
+
invokeCallback(error, e.getMessage());
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@Override
|
|
270
|
+
public void onFailure(Error e) {
|
|
271
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
272
|
+
invokeCallback(error, e.getMessage());
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
} catch (Exception e) {
|
|
276
|
+
Log.e(TAG, "Unexpected error in floor response", e.getCause());
|
|
277
|
+
invokeCallback(error, e.getMessage());
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
public void fetchMapFromFloor(ReadableMap buildingMap, Callback success, Callback error) {
|
|
282
|
+
try {
|
|
283
|
+
JSONObject jsonFloor = ReactNativeJson.convertMapToJson(buildingMap);
|
|
284
|
+
Floor floor = SitumMapper.floorJsonObjectToFloor(jsonFloor);
|
|
285
|
+
|
|
286
|
+
getCommunicationManagerInstance().fetchMapFromFloor(floor, new Handler<Bitmap>() {
|
|
287
|
+
@Override
|
|
288
|
+
public void onSuccess(Bitmap bitmap) {
|
|
289
|
+
try {
|
|
290
|
+
Log.d(PluginHelper.TAG, "onSuccess: Map fetched successfully");
|
|
291
|
+
invokeCallback(success, SitumMapper.bitmapToString(bitmap).getString("data"));
|
|
292
|
+
} catch (JSONException e) {
|
|
293
|
+
invokeCallback(error, e.getMessage());
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
@Override
|
|
298
|
+
public void onFailure(Error e) {
|
|
299
|
+
Log.e(PluginHelper.TAG, "onFailure: " + error);
|
|
300
|
+
invokeCallback(error, e.getMessage());
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
} catch (Exception e) {
|
|
304
|
+
Log.e(TAG, "Unexpected error in map download", e.getCause());
|
|
305
|
+
invokeCallback(error, e.getMessage());
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public void fetchGeofencesFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
310
|
+
try {
|
|
311
|
+
JSONObject jsonBuilding = ReactNativeJson.convertMapToJson(buildingMap);
|
|
312
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonBuilding);
|
|
313
|
+
|
|
314
|
+
getCommunicationManagerInstance().fetchGeofencesFromBuilding(building, new Handler<List<Geofence>>() {
|
|
315
|
+
@Override
|
|
316
|
+
public void onSuccess(List<Geofence> geofences) {
|
|
317
|
+
try {
|
|
318
|
+
Log.d(PluginHelper.TAG, "onSuccess: Geofences fetched successfully.");
|
|
319
|
+
JSONArray jsonArrayGeofences = new JSONArray();
|
|
320
|
+
|
|
321
|
+
for (Geofence geofence : geofences) {
|
|
322
|
+
Log.i(PluginHelper.TAG, "onSuccess: " + geofence.getIdentifier());
|
|
323
|
+
JSONObject jsonoGeofence = SitumMapper.geofenceToJsonObject(geofence);
|
|
324
|
+
jsonArrayGeofences.put(jsonoGeofence);
|
|
325
|
+
}
|
|
326
|
+
if (geofences.isEmpty()) {
|
|
327
|
+
Log.e(PluginHelper.TAG, "onSuccess: you have no geofences defined for this building");
|
|
328
|
+
}
|
|
329
|
+
invokeCallback(success, convertJsonToArray(jsonArrayGeofences));
|
|
330
|
+
|
|
331
|
+
createAndAssignPolygonsToGeofences(geofences);
|
|
332
|
+
} catch (JSONException e) {
|
|
333
|
+
invokeCallback(error, e.getMessage());
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
@Override
|
|
338
|
+
public void onFailure(Error e) {
|
|
339
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
340
|
+
invokeCallback(error, e.getMessage());
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
} catch (Exception e) {
|
|
345
|
+
Log.e(TAG, "Unexpected error in building info response", e.getCause());
|
|
346
|
+
invokeCallback(error, e.getMessage());
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
public void startPositioning(final ReadableMap locationRequestMap,
|
|
351
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter) {
|
|
352
|
+
try {
|
|
353
|
+
if (locationListener != null) {
|
|
354
|
+
SitumSdk.locationManager().removeLocationListener(locationListener);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
JSONObject jsonRequst = ReactNativeJson.convertMapToJson(locationRequestMap);
|
|
358
|
+
LocationRequest.Builder locationBuilder = new LocationRequest.Builder();
|
|
359
|
+
SitumMapper.locationRequestJSONObjectToLocationRequest(jsonRequst, locationBuilder);
|
|
360
|
+
LocationRequest locationRequest = locationBuilder.build();
|
|
361
|
+
|
|
362
|
+
locationListener = new LocationListener() {
|
|
363
|
+
public void onLocationChanged(Location location) {
|
|
364
|
+
try {
|
|
365
|
+
PluginHelper.this.computedLocation = location; // This is for testing purposes
|
|
366
|
+
Log.i(PluginHelper.TAG, "onLocationChanged() called with: location = [" + location + "]");
|
|
367
|
+
JSONObject jsonObject = SitumMapper.locationToJsonObject(location);
|
|
368
|
+
|
|
369
|
+
eventEmitter.emit(EVENT_LOCATION_CHANGED, convertJsonToMap(jsonObject));
|
|
370
|
+
|
|
371
|
+
} catch (JSONException e) {
|
|
372
|
+
eventEmitter.emit(EVENT_LOCATION_ERROR, e.getMessage());
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
public void onStatusChanged(@NonNull LocationStatus status) {
|
|
377
|
+
try {
|
|
378
|
+
Log.i(PluginHelper.TAG, "onStatusChanged() called with: status = [" + status + "]");
|
|
379
|
+
JSONObject jsonObject = SitumMapper.locationStatusToJsonObject(status);
|
|
380
|
+
eventEmitter.emit(EVENT_LOCATION_STATUS_CHANGED, convertJsonToMap(jsonObject));
|
|
381
|
+
} catch (JSONException e) {
|
|
382
|
+
eventEmitter.emit(EVENT_LOCATION_ERROR, e.getMessage());
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
public void onError(@NonNull Error error) {
|
|
387
|
+
Log.e(PluginHelper.TAG, "onError() called with: error = [" + error + "]");
|
|
388
|
+
locationListener = null;
|
|
389
|
+
eventEmitter.emit(EVENT_LOCATION_ERROR, error.getMessage());
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
try {
|
|
394
|
+
SitumSdk.locationManager().addLocationListener(locationListener);
|
|
395
|
+
SitumSdk.locationManager().requestLocationUpdates(locationRequest);
|
|
396
|
+
} catch (Exception e) {
|
|
397
|
+
Log.e(PluginHelper.TAG, "onError() called with: error = [" + e + "]");
|
|
398
|
+
}
|
|
399
|
+
} catch (Exception e) {
|
|
400
|
+
Log.e(TAG, "Unexpected error building response", e.getCause());
|
|
401
|
+
eventEmitter.emit(EVENT_LOCATION_ERROR, e.getMessage());
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
public void stopPositioning(Callback callback) {
|
|
406
|
+
try {
|
|
407
|
+
SitumSdk.locationManager().removeUpdates();
|
|
408
|
+
WritableMap map = Arguments.createMap();
|
|
409
|
+
map.putBoolean("success", true);
|
|
410
|
+
map.putString("message", "Stopped Successfully");
|
|
411
|
+
invokeCallback(callback, map);
|
|
412
|
+
} catch (Exception e) {
|
|
413
|
+
invokeCallback(callback, e.getMessage());
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
public void requestDirections(ReadableArray requestArray, Callback success, Callback error,
|
|
418
|
+
ReactApplicationContext context) {
|
|
419
|
+
try {
|
|
420
|
+
JSONObject jsonBuilding = convertMapToJson(Objects.requireNonNull(requestArray.getMap(0)));
|
|
421
|
+
JSONObject jsonFrom = convertMapToJson(Objects.requireNonNull(requestArray.getMap(1)));
|
|
422
|
+
JSONObject jsonTo = convertMapToJson(Objects.requireNonNull(requestArray.getMap(2)));
|
|
423
|
+
JSONObject jsonOptions = null;
|
|
424
|
+
if (requestArray.size() >= 4) {
|
|
425
|
+
jsonOptions = convertMapToJson(Objects.requireNonNull(requestArray.getMap(3)));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
DirectionsRequest directionRequest = SitumMapper.jsonObjectToDirectionsRequest(jsonBuilding, jsonFrom,
|
|
429
|
+
jsonTo, jsonOptions);
|
|
430
|
+
|
|
431
|
+
SitumSdk.directionsManager().requestDirections(directionRequest, new Handler<Route>() {
|
|
432
|
+
@Override
|
|
433
|
+
public void onSuccess(Route route) {
|
|
434
|
+
try {
|
|
435
|
+
PluginHelper.this.computedRoute = route;
|
|
436
|
+
JSONObject jsonRoute = SitumMapper.routeToJsonObject(route);
|
|
437
|
+
Log.i(TAG, "onSuccess: Route calculated successfully" + route);
|
|
438
|
+
invokeCallback(success, convertJsonToMap(jsonRoute));
|
|
439
|
+
} catch (JSONException e) {
|
|
440
|
+
invokeCallback(error, e.getMessage());
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
@Override
|
|
445
|
+
public void onFailure(Error e) {
|
|
446
|
+
Log.e(TAG, "onError:" + e.getMessage());
|
|
447
|
+
invokeCallback(error, e.getMessage());
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
} catch (Exception e) {
|
|
451
|
+
e.printStackTrace();
|
|
452
|
+
invokeCallback(error, e.getMessage());
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
public void fetchPoiCategories(Callback success, Callback error) {
|
|
457
|
+
getCommunicationManagerInstance().fetchPoiCategories(new Handler<Collection<PoiCategory>>() {
|
|
458
|
+
@Override
|
|
459
|
+
public void onSuccess(Collection<PoiCategory> poiCategories) {
|
|
460
|
+
try {
|
|
461
|
+
Log.d(PluginHelper.TAG, "onSuccess: POI Categories fetched successfully.");
|
|
462
|
+
JSONArray jsonaPoiCategories = new JSONArray();
|
|
463
|
+
for (PoiCategory poiCategory : poiCategories) {
|
|
464
|
+
Log.i(PluginHelper.TAG, "onSuccess: " + poiCategory.getCode() + " - " + poiCategory.getName());
|
|
465
|
+
JSONObject jsonoPoiCategory = SitumMapper.poiCategoryToJsonObject(poiCategory);
|
|
466
|
+
jsonaPoiCategories.put(jsonoPoiCategory);
|
|
467
|
+
}
|
|
468
|
+
if (poiCategories.isEmpty()) {
|
|
469
|
+
Log.e(PluginHelper.TAG, "onSuccess: you have no categories defined for POIs");
|
|
470
|
+
}
|
|
471
|
+
invokeCallback(success, convertJsonToArray(jsonaPoiCategories));
|
|
472
|
+
} catch (JSONException e) {
|
|
473
|
+
invokeCallback(error, e.getMessage());
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
@Override
|
|
478
|
+
public void onFailure(Error e) {
|
|
479
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
480
|
+
invokeCallback(error, e.getMessage());
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
public void fetchPoiCategoryIconNormal(ReadableMap categoryMap, Callback success, Callback error) {
|
|
486
|
+
try {
|
|
487
|
+
JSONObject jsonoCategory = convertMapToJson(categoryMap);
|
|
488
|
+
PoiCategory category = SitumMapper.poiCategoryFromJsonObject(jsonoCategory);
|
|
489
|
+
getCommunicationManagerInstance().fetchPoiCategoryIconNormal(category, new Handler<Bitmap>() {
|
|
490
|
+
@Override
|
|
491
|
+
public void onSuccess(Bitmap bitmap) {
|
|
492
|
+
try {
|
|
493
|
+
Log.d(PluginHelper.TAG, "onSuccess: Poi icon fetched successfully");
|
|
494
|
+
JSONObject jsonoMap = SitumMapper.bitmapToString(bitmap);
|
|
495
|
+
invokeCallback(success, convertJsonToMap(jsonoMap));
|
|
496
|
+
} catch (JSONException e) {
|
|
497
|
+
invokeCallback(error, e.getMessage());
|
|
498
|
+
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
@Override
|
|
503
|
+
public void onFailure(Error e) {
|
|
504
|
+
Log.e(PluginHelper.TAG, "onFailure: " + e);
|
|
505
|
+
invokeCallback(error, e.getMessage());
|
|
506
|
+
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
} catch (Exception e) {
|
|
510
|
+
Log.e(TAG, "Unexpected error in situm POI response", e.getCause());
|
|
511
|
+
invokeCallback(error, e.getMessage());
|
|
512
|
+
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
public void fetchPoiCategoryIconSelected(ReadableMap categoryMap, Callback success, Callback error) {
|
|
517
|
+
try {
|
|
518
|
+
JSONObject jsonoCategory = convertMapToJson(categoryMap);
|
|
519
|
+
PoiCategory category = SitumMapper.poiCategoryFromJsonObject(jsonoCategory);
|
|
520
|
+
getCommunicationManagerInstance().fetchPoiCategoryIconSelected(category, new Handler<Bitmap>() {
|
|
521
|
+
@Override
|
|
522
|
+
public void onSuccess(Bitmap bitmap) {
|
|
523
|
+
try {
|
|
524
|
+
Log.d(PluginHelper.TAG, "onSuccess: Poi icon fetched successfully");
|
|
525
|
+
JSONObject jsonoMap = SitumMapper.bitmapToString(bitmap);
|
|
526
|
+
invokeCallback(success, convertJsonToMap(jsonoMap));
|
|
527
|
+
} catch (JSONException e) {
|
|
528
|
+
invokeCallback(error, e.getMessage());
|
|
529
|
+
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
@Override
|
|
534
|
+
public void onFailure(Error e) {
|
|
535
|
+
Log.e(PluginHelper.TAG, "onFailure: " + e);
|
|
536
|
+
invokeCallback(error, e.getMessage());
|
|
537
|
+
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
} catch (Exception e) {
|
|
541
|
+
Log.e(TAG, "Unexpected error in situm POI response", e.getCause());
|
|
542
|
+
invokeCallback(error, e.getMessage());
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
public void requestNavigationUpdates(ReadableMap options,
|
|
547
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter, Context context) {
|
|
548
|
+
// 1) Parse and check arguments
|
|
549
|
+
|
|
550
|
+
if (this.computedRoute == null) {
|
|
551
|
+
Log.d(TAG, "Situm >> There is not an stored route so you are not allowed to navigate");
|
|
552
|
+
eventEmitter.emit(EVENT_NAVIGATION_ERROR,
|
|
553
|
+
"Compute a valid route with requestDirections before trying to navigate within a route");
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
// try??
|
|
557
|
+
Route route = this.computedRoute; // args.getJSONObject(0); // Retrieve route from arguments, we do this since
|
|
558
|
+
// Route object has internal properties that we do not want to expose
|
|
559
|
+
// 2) Build Navigation Arguments
|
|
560
|
+
// 2.1) Build Navigation Request
|
|
561
|
+
Log.d(TAG, "requestNavigationUpdates executed: passed route: " + route);
|
|
562
|
+
NavigationRequest.Builder builder = new NavigationRequest.Builder().route(route);
|
|
563
|
+
|
|
564
|
+
try {
|
|
565
|
+
JSONObject navigationJSONOptions = convertMapToJson(options);
|
|
566
|
+
|
|
567
|
+
if (navigationJSONOptions.has(SitumMapper.DISTANCE_TO_IGNORE_FIRST_INDICATION)) {
|
|
568
|
+
Double distanceToIgnoreFirstIndication = navigationJSONOptions
|
|
569
|
+
.getDouble(SitumMapper.DISTANCE_TO_IGNORE_FIRST_INDICATION);
|
|
570
|
+
builder.distanceToIgnoreFirstIndication(distanceToIgnoreFirstIndication);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (navigationJSONOptions.has(SitumMapper.OUTSIDE_ROUTE_THRESHOLD)) {
|
|
574
|
+
Double outsideRouteThreshold = navigationJSONOptions.getDouble(SitumMapper.OUTSIDE_ROUTE_THRESHOLD);
|
|
575
|
+
builder.outsideRouteThreshold(outsideRouteThreshold);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (navigationJSONOptions.has(SitumMapper.DISTANCE_TO_GOAL_THRESHOLD)) {
|
|
579
|
+
Double distanceToGoalThreshold = navigationJSONOptions
|
|
580
|
+
.getDouble(SitumMapper.DISTANCE_TO_GOAL_THRESHOLD);
|
|
581
|
+
builder.distanceToGoalThreshold(distanceToGoalThreshold);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (navigationJSONOptions.has(SitumMapper.DISTANCE_TO_CHANGE_FLOOR_THRESHOLD)) {
|
|
585
|
+
Double distanceToChangeFloorThreshold = navigationJSONOptions
|
|
586
|
+
.getDouble(SitumMapper.DISTANCE_TO_CHANGE_FLOOR_THRESHOLD);
|
|
587
|
+
builder.distanceToChangeFloorThreshold(distanceToChangeFloorThreshold);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (navigationJSONOptions.has(SitumMapper.DISTANCE_TO_CHANGE_INDICATION_THRESHOLD)) {
|
|
591
|
+
Double distanceToChangeIndicationThreshold = navigationJSONOptions
|
|
592
|
+
.getDouble(SitumMapper.DISTANCE_TO_CHANGE_INDICATION_THRESHOLD);
|
|
593
|
+
builder.distanceToChangeIndicationThreshold(distanceToChangeIndicationThreshold);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
if (navigationJSONOptions.has(SitumMapper.INDICATIONS_INTERVAL)) {
|
|
597
|
+
Long indicationsInterval = navigationJSONOptions.getLong(SitumMapper.INDICATIONS_INTERVAL);
|
|
598
|
+
builder.indicationsInterval(indicationsInterval);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (navigationJSONOptions.has(SitumMapper.TIME_TO_FIRST_INDICATION)) {
|
|
602
|
+
Long timeToFirstIndication = navigationJSONOptions.getLong(SitumMapper.TIME_TO_FIRST_INDICATION);
|
|
603
|
+
builder.timeToFirstIndication(timeToFirstIndication);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if (navigationJSONOptions.has(SitumMapper.ROUND_INDICATION_STEP)) {
|
|
607
|
+
Integer roundIndicationsStep = navigationJSONOptions.getInt(SitumMapper.ROUND_INDICATION_STEP);
|
|
608
|
+
builder.roundIndicationsStep(roundIndicationsStep);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (navigationJSONOptions.has(SitumMapper.TIME_TO_IGNORE_UNEXPECTED_FLOOR_CHANGES)) {
|
|
612
|
+
Integer timeToIgnoreUnexpectedFloorChanges = navigationJSONOptions
|
|
613
|
+
.getInt(SitumMapper.TIME_TO_IGNORE_UNEXPECTED_FLOOR_CHANGES);
|
|
614
|
+
builder.timeToIgnoreUnexpectedFloorChanges(timeToIgnoreUnexpectedFloorChanges);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (navigationJSONOptions.has(SitumMapper.IGNORE_LOW_QUALITY_LOCATIONS)) {
|
|
618
|
+
Boolean ignoreLowQualityLocations = navigationJSONOptions
|
|
619
|
+
.getBoolean(SitumMapper.IGNORE_LOW_QUALITY_LOCATIONS);
|
|
620
|
+
builder.ignoreLowQualityLocations(ignoreLowQualityLocations);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
} catch (Exception e) {
|
|
624
|
+
// TODO: handle exception
|
|
625
|
+
Log.d(TAG, "Situm >> Unable to retrieve navigation options. Applying default ones");
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
navigationRequest = builder.build();
|
|
629
|
+
|
|
630
|
+
// 2.2) Build Navigation Callback
|
|
631
|
+
navigationListener = new NavigationListener() {
|
|
632
|
+
public void onProgress(NavigationProgress progress) {
|
|
633
|
+
Log.d(TAG, "On progress received: " + progress);
|
|
634
|
+
try {
|
|
635
|
+
JSONObject jsonProgress = SitumMapper.navigationProgressToJsonObject(progress, context);
|
|
636
|
+
try {
|
|
637
|
+
jsonProgress.put("type", "progress");
|
|
638
|
+
} catch (JSONException e) {
|
|
639
|
+
Log.e(TAG, "error inserting type in navigation progress");
|
|
640
|
+
}
|
|
641
|
+
eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonProgress));
|
|
642
|
+
|
|
643
|
+
} catch (Exception e) {
|
|
644
|
+
Log.d(TAG, "On Error parsing progress: " + progress);
|
|
645
|
+
eventEmitter.emit(EVENT_NAVIGATION_ERROR, e.getMessage());
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
;
|
|
650
|
+
|
|
651
|
+
public void onDestinationReached() {
|
|
652
|
+
Log.d(TAG, "On destination reached: ");
|
|
653
|
+
JSONObject jsonResult = new JSONObject();
|
|
654
|
+
try {
|
|
655
|
+
jsonResult.put("type", "destinationReached");
|
|
656
|
+
jsonResult.put("message", "Destination reached");
|
|
657
|
+
eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonResult));
|
|
658
|
+
} catch (JSONException e) {
|
|
659
|
+
Log.e(TAG, "error inserting type in destination reached");
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
;
|
|
665
|
+
|
|
666
|
+
public void onUserOutsideRoute() {
|
|
667
|
+
Log.d(TAG, "On user outside route: ");
|
|
668
|
+
JSONObject jsonResult = new JSONObject();
|
|
669
|
+
try {
|
|
670
|
+
jsonResult.put("type", "userOutsideRoute");
|
|
671
|
+
jsonResult.put("message", "User outside route");
|
|
672
|
+
eventEmitter.emit(EVENT_NAVIGATION_UPDATE, convertJsonToMap(jsonResult));
|
|
673
|
+
|
|
674
|
+
} catch (JSONException e) {
|
|
675
|
+
Log.e(TAG, "error inserting type in user outside route");
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
getNavigationManagerInstance().requestNavigationUpdates(navigationRequest, navigationListener);
|
|
682
|
+
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
public void updateNavigationWithLocation(ReadableMap locationMap, Callback success, Callback error) {
|
|
686
|
+
try {
|
|
687
|
+
// 1) Check for location arguments
|
|
688
|
+
JSONObject jsonLocation = convertMapToJson(locationMap);
|
|
689
|
+
|
|
690
|
+
// 2) Create a Location Object from argument
|
|
691
|
+
Location actualLocation = SitumMapper.jsonLocationObjectToLocation(jsonLocation); // Location Objet from
|
|
692
|
+
// JSON
|
|
693
|
+
// Location actualLocation = PluginHelper.computedLocation;
|
|
694
|
+
Log.i(TAG, "UpdateNavigation with Location: " + actualLocation);
|
|
695
|
+
|
|
696
|
+
// 3) Connect interfaces
|
|
697
|
+
getNavigationManagerInstance().updateWithLocation(actualLocation);
|
|
698
|
+
invokeCallback(success, "Navigation updated");
|
|
699
|
+
} catch (Exception e) {
|
|
700
|
+
e.printStackTrace();
|
|
701
|
+
invokeCallback(error, e.getMessage());
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
public void removeNavigationUpdates(Callback callback) {
|
|
706
|
+
Log.i(TAG, "Remove navigation updates");
|
|
707
|
+
boolean success = getNavigationManagerInstance().removeUpdates();
|
|
708
|
+
WritableMap map = Arguments.createMap();
|
|
709
|
+
map.putBoolean("success", success);
|
|
710
|
+
invokeCallback(callback, map);
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
public void fetchIndoorPOIsFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
714
|
+
try {
|
|
715
|
+
JSONObject jsonoBuilding = convertMapToJson(buildingMap);
|
|
716
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonoBuilding);
|
|
717
|
+
getCommunicationManagerInstance().fetchIndoorPOIsFromBuilding(building, new HashMap<String, Object>(),
|
|
718
|
+
new Handler<Collection<Poi>>() {
|
|
719
|
+
@Override
|
|
720
|
+
public void onSuccess(Collection<Poi> pois) {
|
|
721
|
+
try {
|
|
722
|
+
Log.d(PluginHelper.TAG, "onSuccess: Pois fetched successfully.");
|
|
723
|
+
JSONArray jsonaPois = new JSONArray();
|
|
724
|
+
|
|
725
|
+
for (Poi poi : pois) {
|
|
726
|
+
Log.i(PluginHelper.TAG,
|
|
727
|
+
"onSuccess: " + poi.getIdentifier() + " - " + poi.getName() + "-"
|
|
728
|
+
+ poi.getCustomFields());
|
|
729
|
+
|
|
730
|
+
Log.d(PluginHelper.TAG, "Some log that should appear");
|
|
731
|
+
JSONObject jsonoPoi = SitumMapper.poiToJsonObject(poi);
|
|
732
|
+
jsonaPois.put(jsonoPoi);
|
|
733
|
+
}
|
|
734
|
+
if (pois.isEmpty()) {
|
|
735
|
+
Log.e(PluginHelper.TAG,
|
|
736
|
+
"onSuccess: you have no indoor pois defined for this building");
|
|
737
|
+
}
|
|
738
|
+
invokeCallback(success, convertJsonToArray(jsonaPois));
|
|
739
|
+
} catch (JSONException e) {
|
|
740
|
+
invokeCallback(error, e.getMessage());
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
@Override
|
|
745
|
+
public void onFailure(Error e) {
|
|
746
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
747
|
+
invokeCallback(error, e.getMessage());
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
} catch (Exception e) {
|
|
751
|
+
Log.e(TAG, "Unexpected error in poi response", e.getCause());
|
|
752
|
+
invokeCallback(error, e.getMessage());
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
public void fetchOutdoorPOIsFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
757
|
+
try {
|
|
758
|
+
JSONObject jsonoBuilding = convertMapToJson(buildingMap);
|
|
759
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonoBuilding);
|
|
760
|
+
getCommunicationManagerInstance().fetchOutdoorPOIsFromBuilding(building, new HashMap<String, Object>(),
|
|
761
|
+
new Handler<Collection<Poi>>() {
|
|
762
|
+
@Override
|
|
763
|
+
public void onSuccess(Collection<Poi> pois) {
|
|
764
|
+
try {
|
|
765
|
+
Log.d(PluginHelper.TAG, "onSuccess: Floors fetched successfully.");
|
|
766
|
+
JSONArray jsonaPois = new JSONArray();
|
|
767
|
+
|
|
768
|
+
for (Poi poi : pois) {
|
|
769
|
+
Log.i(PluginHelper.TAG,
|
|
770
|
+
"onSuccess: " + poi.getIdentifier() + " - " + poi.getName());
|
|
771
|
+
JSONObject jsonoPoi = SitumMapper.poiToJsonObject(poi);
|
|
772
|
+
jsonaPois.put(jsonoPoi);
|
|
773
|
+
}
|
|
774
|
+
if (pois.isEmpty()) {
|
|
775
|
+
Log.e(PluginHelper.TAG,
|
|
776
|
+
"onSuccess: you have no outdoor pois defined for this building");
|
|
777
|
+
}
|
|
778
|
+
invokeCallback(success, convertJsonToArray(jsonaPois));
|
|
779
|
+
} catch (JSONException e) {
|
|
780
|
+
invokeCallback(error, e.getMessage());
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
@Override
|
|
785
|
+
public void onFailure(Error e) {
|
|
786
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
787
|
+
invokeCallback(error, e.getMessage());
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
} catch (Exception e) {
|
|
791
|
+
Log.e(TAG, "Unexpected error in poi response", e.getCause());
|
|
792
|
+
invokeCallback(error, e.getMessage());
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
public void fetchEventsFromBuilding(ReadableMap buildingMap, Callback success, Callback error) {
|
|
797
|
+
try {
|
|
798
|
+
JSONObject jsonoBuilding = convertMapToJson(buildingMap);
|
|
799
|
+
Building building = SitumMapper.buildingJsonObjectToBuilding(jsonoBuilding);
|
|
800
|
+
getCommunicationManagerInstance().fetchEventsFromBuilding(building, new HashMap<String, Object>(),
|
|
801
|
+
new Handler<Collection<SitumEvent>>() {
|
|
802
|
+
@Override
|
|
803
|
+
public void onSuccess(Collection<SitumEvent> situmEvents) {
|
|
804
|
+
try {
|
|
805
|
+
Log.d(PluginHelper.TAG, "onSuccess: Floors fetched successfully.");
|
|
806
|
+
JSONArray jsonaEvents = new JSONArray();
|
|
807
|
+
for (SitumEvent situmEvent : situmEvents) {
|
|
808
|
+
Log.i(PluginHelper.TAG,
|
|
809
|
+
"onSuccess: " + situmEvent.getId() + " - " + situmEvent.getName());
|
|
810
|
+
JSONObject jsonoSitumEvent = SitumMapper.situmEventToJsonObject(situmEvent);
|
|
811
|
+
jsonaEvents.put(jsonoSitumEvent);
|
|
812
|
+
}
|
|
813
|
+
if (situmEvents.isEmpty()) {
|
|
814
|
+
Log.e(PluginHelper.TAG, "onSuccess: you have no events defined for this building");
|
|
815
|
+
}
|
|
816
|
+
invokeCallback(success, convertJsonToArray(jsonaEvents));
|
|
817
|
+
} catch (JSONException e) {
|
|
818
|
+
invokeCallback(error, e.getMessage());
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
@Override
|
|
823
|
+
public void onFailure(Error e) {
|
|
824
|
+
Log.e(PluginHelper.TAG, "onFailure:" + e);
|
|
825
|
+
invokeCallback(error, e.getMessage());
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
} catch (Exception e) {
|
|
829
|
+
Log.e(TAG, "Unexpected error in poi response", e.getCause());
|
|
830
|
+
invokeCallback(error, e.getMessage());
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
public void requestRealTimeUpdates(ReadableMap options,
|
|
835
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter) {
|
|
836
|
+
try {
|
|
837
|
+
// Convert request to native
|
|
838
|
+
JSONObject jsonRequest = convertMapToJson(options);
|
|
839
|
+
RealTimeRequest request = SitumMapper.jsonObjectRealtimeRequest(jsonRequest);
|
|
840
|
+
// Call
|
|
841
|
+
|
|
842
|
+
realtimeListener = new RealTimeListener() {
|
|
843
|
+
|
|
844
|
+
@Override
|
|
845
|
+
public void onUserLocations(RealTimeData realTimeData) {
|
|
846
|
+
Log.d(TAG, "Success retrieving realtime data" + realTimeData);
|
|
847
|
+
|
|
848
|
+
try {
|
|
849
|
+
// Parse information
|
|
850
|
+
JSONObject jsonResult = SitumMapper.realtimeDataToJson(realTimeData);
|
|
851
|
+
|
|
852
|
+
eventEmitter.emit(EVENT_REALTIME_UPDATE, convertJsonToMap(jsonResult));
|
|
853
|
+
} catch (Exception e) {
|
|
854
|
+
Log.d(TAG, "Error exception realtime data" + e);
|
|
855
|
+
eventEmitter.emit(EVENT_REALTIME_ERROR, e.getMessage());
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
@Override
|
|
861
|
+
public void onError(Error e) {
|
|
862
|
+
Log.e(TAG, "Error request realtime data" + e);
|
|
863
|
+
eventEmitter.emit(EVENT_REALTIME_ERROR, e.getMessage());
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
};
|
|
867
|
+
try {
|
|
868
|
+
getRealtimeManagerInstance().requestRealTimeUpdates(request, realtimeListener);
|
|
869
|
+
} catch (Exception e) {
|
|
870
|
+
Log.e(PluginHelper.TAG, "onError() called with: error = [" + e + "]");
|
|
871
|
+
}
|
|
872
|
+
} catch (Exception e) {
|
|
873
|
+
Log.d(TAG, "exception: " + e);
|
|
874
|
+
|
|
875
|
+
e.printStackTrace();
|
|
876
|
+
eventEmitter.emit(EVENT_REALTIME_ERROR, e.getMessage());
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
public void removeRealTimeUpdates() {
|
|
881
|
+
Log.i(TAG, "Remove realtime updates");
|
|
882
|
+
getRealtimeManagerInstance().removeRealTimeUpdates();
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
public void checkIfPointIsInsideGeoFence(ReadableMap map, Callback callback) {
|
|
886
|
+
if (geofencePolygonMap.isEmpty()) {
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
try {
|
|
891
|
+
String floorId = null;
|
|
892
|
+
if (map.hasKey("floorIdentifier")) {
|
|
893
|
+
floorId = map.getString("floorIdentifier");
|
|
894
|
+
}
|
|
895
|
+
ReadableMap latLngMap = map.getMap("coordinate");
|
|
896
|
+
org.locationtech.jts.geom.Point point = geometryFactory
|
|
897
|
+
.createPoint(new Coordinate(latLngMap.getDouble("latitude"), latLngMap.getDouble("longitude")));
|
|
898
|
+
|
|
899
|
+
Geofence geofence = null;
|
|
900
|
+
|
|
901
|
+
for (Map.Entry<Geofence, Polygon> entry : geofencePolygonMap.entrySet()) {
|
|
902
|
+
if (!TextUtils.isEmpty(floorId) && !entry.getKey().getFloorIdentifier().equals(floorId)) {
|
|
903
|
+
continue;
|
|
904
|
+
}
|
|
905
|
+
if (point.within(entry.getValue())) {
|
|
906
|
+
geofence = entry.getKey();
|
|
907
|
+
Log.i(TAG, "The point is inside the geofence: " + entry.getKey().getName());
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
WritableMap responseMap = Arguments.createMap();
|
|
912
|
+
responseMap.putBoolean("isInsideGeofence", geofence != null);
|
|
913
|
+
if (geofence != null) {
|
|
914
|
+
WritableMap geofenceMap = Arguments.createMap();
|
|
915
|
+
geofenceMap.putString("name", geofence.getName());
|
|
916
|
+
geofenceMap.putString("identifier", geofence.getIdentifier());
|
|
917
|
+
|
|
918
|
+
responseMap.putMap("geofence", geofenceMap);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
invokeCallback(callback, responseMap);
|
|
922
|
+
|
|
923
|
+
} catch (Exception e) {
|
|
924
|
+
WritableMap error = Arguments.createMap();
|
|
925
|
+
error.putString("error", e.getMessage());
|
|
926
|
+
invokeCallback(callback, error);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
public void invalidateCache() {
|
|
931
|
+
geofencePolygonMap = new HashMap<>();
|
|
932
|
+
getCommunicationManagerInstance().invalidateCache();
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
private void createAndAssignPolygonsToGeofences(List<Geofence> geofences) {
|
|
936
|
+
if (geofences.isEmpty()) {
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
for (Geofence geofence : geofences) {
|
|
940
|
+
List<Coordinate> jtsCoordinates = new ArrayList<>();
|
|
941
|
+
for (Point point : geofence.getPolygonPoints()) {
|
|
942
|
+
Coordinate coordinate = new Coordinate(point.getCoordinate().getLatitude(),
|
|
943
|
+
point.getCoordinate().getLongitude());
|
|
944
|
+
jtsCoordinates.add(coordinate);
|
|
945
|
+
}
|
|
946
|
+
if (!jtsCoordinates.isEmpty()) {
|
|
947
|
+
Polygon polygon = geometryFactory.createPolygon(jtsCoordinates.toArray(new Coordinate[0]));
|
|
948
|
+
geofencePolygonMap.put(geofence, polygon);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
private void invokeCallback(Callback callback, Object args) {
|
|
954
|
+
if (callback != null) {
|
|
955
|
+
callback.invoke(args);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
public void onEnterGeofences(DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter) {
|
|
960
|
+
emitEnterGeofences = true;
|
|
961
|
+
createAndSetGeofenceListener(eventEmitter);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
public void onExitGeofences(DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter) {
|
|
965
|
+
emitExitGeofences = true;
|
|
966
|
+
createAndSetGeofenceListener(eventEmitter);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
private void createAndSetGeofenceListener(DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter) {
|
|
970
|
+
GeofenceListener geofenceListener = new GeofenceListener() {
|
|
971
|
+
public void onEnteredGeofences(List<Geofence> enteredGeofences) {
|
|
972
|
+
if (emitEnterGeofences) {
|
|
973
|
+
emitGeofences(EVENT_ENTER_GEOFENCES, enteredGeofences);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
public void onExitedGeofences(List<Geofence> exitedGeofences) {
|
|
978
|
+
if (emitExitGeofences) {
|
|
979
|
+
emitGeofences(EVENT_EXIT_GEOFENCES, exitedGeofences);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
private void emitGeofences(String event, List<Geofence> geofences) {
|
|
984
|
+
eventEmitter.emit(event, SitumMapper.mapList(geofences));
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
SitumSdk.locationManager().setGeofenceListener(geofenceListener);
|
|
988
|
+
}
|
|
989
|
+
}
|