@woosmap/react-native-plugin-geofencing 0.1.2 → 0.1.3

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.
@@ -32,334 +32,424 @@ import java.util.Iterator;
32
32
 
33
33
  @ReactModule(name = PluginGeofencingModule.NAME)
34
34
  public class PluginGeofencingModule extends ReactContextBaseJavaModule implements PermissionListener, LifecycleEventListener {
35
- public static final String NAME = "PluginGeofencing";
36
-
37
- private ReactApplicationContext reactContext;
38
- private Woosmap woosmap;
39
- private static final int PERMISSIONS_REQUEST_CODE = 150; // random request code
40
- private Promise mPermissionsRequestPromise;
41
- private WoosLocationReadyListener locationReadyListener;
42
-
43
- public PluginGeofencingModule(ReactApplicationContext reactContext) {
44
- super(reactContext);
45
- this.reactContext = reactContext;
46
- this.reactContext.addLifecycleEventListener(this);
47
- }
35
+ public static final String NAME = "PluginGeofencing";
36
+
37
+ private ReactApplicationContext reactContext;
38
+ private Woosmap woosmap;
39
+ private static final int PERMISSIONS_REQUEST_CODE = 150; // random request code
40
+ private Promise mPermissionsRequestPromise;
41
+ private WoosLocationReadyListener locationReadyListener;
42
+ private WoosRegionReadyListener regionReadyListener;
43
+
44
+ public PluginGeofencingModule(ReactApplicationContext reactContext) {
45
+ super(reactContext);
46
+ this.reactContext = reactContext;
47
+ this.reactContext.addLifecycleEventListener(this);
48
+ }
48
49
 
49
- @Override
50
- @NonNull
51
- public String getName() {
52
- return NAME;
53
- }
50
+ @Override
51
+ @NonNull
52
+ public String getName() {
53
+ return NAME;
54
+ }
54
55
 
55
56
 
56
- // Example method
57
- // See https://reactnative.dev/docs/native-modules-android
58
- @ReactMethod
59
- public void multiply(int a, int b, Promise promise) {
60
- promise.resolve(a * b);
61
- }
57
+ // Example method
58
+ // See https://reactnative.dev/docs/native-modules-android
59
+ @ReactMethod
60
+ public void multiply(int a, int b, Promise promise) {
61
+ promise.resolve(a * b);
62
+ }
62
63
 
63
64
 
64
- @ReactMethod
65
- public void initialize(ReadableMap map, Promise promise) {
66
- String trackingProfile = "";
67
- try {
68
- if (woosmap != null) {
69
- promise.resolve(WoosmapMessageAndKey.successMessage);
70
- return;
71
- } else if (hasPermission(false)) {
72
- //check required permission first
73
- if (map.hasKey(WoosmapMessageAndKey.profileTrackingKey)) {
74
- if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.liveTracking)) {
75
- trackingProfile = Woosmap.ConfigurationProfile.liveTracking;
76
- } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.passiveTracking)) {
77
- trackingProfile = Woosmap.ConfigurationProfile.passiveTracking;
78
- } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.visitsTracking)) {
79
- trackingProfile = Woosmap.ConfigurationProfile.visitsTracking;
80
- } else {
81
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
82
- return;
83
- }
84
- }
85
- woosmap = Woosmap.getInstance().initializeWoosmap(reactContext);
86
- if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
87
- WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
88
- }
89
- // Set the Delay of Duration data
90
- WoosmapSettings.numberOfDayDataDuration = 30;
91
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
92
- this.woosmap.createWoosmapNotifChannel();
93
- }
94
- this.woosmap.onResume();
95
- if (!trackingProfile.isEmpty()) {
96
- woosmap.startTracking(trackingProfile);
65
+ @ReactMethod
66
+ public void initialize(ReadableMap map, Promise promise) {
67
+ String trackingProfile = "";
68
+ try {
69
+ if (woosmap != null) {
70
+ promise.resolve(WoosmapMessageAndKey.successMessage);
71
+ return;
72
+ } else if (hasPermission(false)) {
73
+ //check required permission first
74
+ if (map.hasKey(WoosmapMessageAndKey.profileTrackingKey)) {
75
+ if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.liveTracking)) {
76
+ trackingProfile = Woosmap.ConfigurationProfile.liveTracking;
77
+ } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.passiveTracking)) {
78
+ trackingProfile = Woosmap.ConfigurationProfile.passiveTracking;
79
+ } else if (map.getString(WoosmapMessageAndKey.profileTrackingKey).equals(Woosmap.ConfigurationProfile.visitsTracking)) {
80
+ trackingProfile = Woosmap.ConfigurationProfile.visitsTracking;
81
+ } else {
82
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
83
+ return;
97
84
  }
98
- promise.resolve(WoosmapMessageAndKey.successMessage);
99
- } else {
100
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
101
85
  }
102
- } catch (Exception ex) {
103
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
86
+ woosmap = Woosmap.getInstance().initializeWoosmap(reactContext);
87
+ if (map.hasKey(WoosmapMessageAndKey.woosmapPrivateKeyString)) {
88
+ WoosmapSettings.privateKeyWoosmapAPI = map.getString(WoosmapMessageAndKey.woosmapPrivateKeyString);
89
+ }
90
+ // Set the Delay of Duration data
91
+ WoosmapSettings.numberOfDayDataDuration = 30;
92
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
93
+ this.woosmap.createWoosmapNotifChannel();
94
+ }
95
+ this.woosmap.onResume();
96
+ if (!trackingProfile.isEmpty()) {
97
+ woosmap.startTracking(trackingProfile);
98
+ }
99
+ promise.resolve(WoosmapMessageAndKey.successMessage);
100
+ } else {
101
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionNotGrantedMessage);
104
102
  }
105
-
103
+ } catch (Exception ex) {
104
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
106
105
  }
107
106
 
108
- private boolean isWoosmapInitialized() {
109
- if (woosmap == null) {
110
- return false;
111
- }
112
- return true;
107
+ }
108
+
109
+ private boolean isWoosmapInitialized() {
110
+ if (woosmap == null) {
111
+ return false;
113
112
  }
113
+ return true;
114
+ }
114
115
 
115
- @ReactMethod
116
- private void requestPermissions(ReadableArray data, Promise promise) {
117
- try {
118
- if (data.isNull(0)) {
119
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionValueNotProvided);
120
- }
121
- boolean isBackground = data.getBoolean(0);
122
- PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
123
- mPermissionsRequestPromise = promise;
124
- if (activity != null) {
125
- if (Build.VERSION.SDK_INT >= 23) {
126
- if (isBackground && Build.VERSION.SDK_INT >= 29) {
127
- activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
128
- } else {
129
- activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
130
- }
116
+ @ReactMethod
117
+ private void requestPermissions(ReadableArray data, Promise promise) {
118
+ try {
119
+ if (data.isNull(0)) {
120
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.permissionValueNotProvided);
121
+ }
122
+ boolean isBackground = data.getBoolean(0);
123
+ PermissionAwareActivity activity = (PermissionAwareActivity) getCurrentActivity();
124
+ mPermissionsRequestPromise = promise;
125
+ if (activity != null) {
126
+ if (Build.VERSION.SDK_INT >= 23) {
127
+ if (isBackground && Build.VERSION.SDK_INT >= 29) {
128
+ activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
129
+ } else {
130
+ activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSIONS_REQUEST_CODE, this);
131
131
  }
132
132
  }
133
- } catch (Exception ex) {
134
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
135
133
  }
134
+ } catch (Exception ex) {
135
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
136
136
  }
137
+ }
137
138
 
138
139
 
139
- @Override
140
- public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
141
- if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
142
- providePermissionStatus(mPermissionsRequestPromise);
143
- mPermissionsRequestPromise = null;
144
- }
145
- return true;
140
+ @Override
141
+ public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
142
+ if (requestCode == PERMISSIONS_REQUEST_CODE && mPermissionsRequestPromise != null) {
143
+ providePermissionStatus(mPermissionsRequestPromise);
144
+ mPermissionsRequestPromise = null;
146
145
  }
146
+ return true;
147
+ }
147
148
 
148
- private void providePermissionStatus(final Promise promise) {
149
- try {
150
- if (promise == null) {
151
- return;
152
- }
153
- Activity activity = getCurrentActivity();
154
- if (activity == null) {
155
- promise.resolve(WoosmapMessageAndKey.unknownMessage);
156
- return;
157
- }
149
+ private void providePermissionStatus(final Promise promise) {
150
+ try {
151
+ if (promise == null) {
152
+ return;
153
+ }
154
+ Activity activity = getCurrentActivity();
155
+ if (activity == null) {
156
+ promise.resolve(WoosmapMessageAndKey.unknownMessage);
157
+ return;
158
+ }
158
159
 
159
- boolean foreground = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
160
- boolean background = foreground;
161
- boolean denied = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
160
+ boolean foreground = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
161
+ boolean background = foreground;
162
+ boolean denied = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION);
162
163
 
163
- if (Build.VERSION.SDK_INT >= 29) {
164
- background = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
165
- }
164
+ if (Build.VERSION.SDK_INT >= 29) {
165
+ background = ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
166
+ }
166
167
 
167
- if (background) {
168
- promise.resolve(WoosmapMessageAndKey.backgroundPermissionGrantedMessage);
169
- } else if (foreground) {
170
- promise.resolve(WoosmapMessageAndKey.foregroundPermissionGrantedMessage);
171
- } else if (denied) {
172
- promise.resolve(WoosmapMessageAndKey.deniedPermissionMessage);
173
- } else {
174
- promise.resolve(WoosmapMessageAndKey.unknownMessage);
175
- }
176
- } catch (Exception ex) {
168
+ if (background) {
169
+ promise.resolve(WoosmapMessageAndKey.backgroundPermissionGrantedMessage);
170
+ } else if (foreground) {
171
+ promise.resolve(WoosmapMessageAndKey.foregroundPermissionGrantedMessage);
172
+ } else if (denied) {
173
+ promise.resolve(WoosmapMessageAndKey.deniedPermissionMessage);
174
+ } else {
177
175
  promise.resolve(WoosmapMessageAndKey.unknownMessage);
178
176
  }
177
+ } catch (Exception ex) {
178
+ promise.resolve(WoosmapMessageAndKey.unknownMessage);
179
179
  }
180
+ }
181
+
182
+ @ReactMethod
183
+ public void getPermissionsStatus(final Promise promise) {
184
+ providePermissionStatus(promise);
185
+ }
186
+
187
+ private boolean hasPermission(boolean isBackground) {
188
+ try {
189
+ Activity activity = getCurrentActivity();
190
+ if (activity == null) {
191
+ return false;
192
+ }
193
+ if (!isBackground) {
194
+ return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
195
+ }
196
+ if (isBackground && Build.VERSION.SDK_INT >= 29) {
197
+ return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
198
+ }
180
199
 
181
- @ReactMethod
182
- public void getPermissionsStatus(final Promise promise) {
183
- providePermissionStatus(promise);
200
+ } catch (Exception ex) {
201
+ Log.e(NAME, ex.toString());
184
202
  }
203
+ return false;
204
+ }
185
205
 
186
- private boolean hasPermission(boolean isBackground) {
187
- try {
188
- Activity activity = getCurrentActivity();
189
- if (activity == null) {
190
- return false;
191
- }
192
- if (!isBackground) {
193
- return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
194
- }
195
- if (isBackground && Build.VERSION.SDK_INT >= 29) {
196
- return ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED;
197
- }
198
206
 
199
- } catch (Exception ex) {
200
- Log.e(NAME, ex.toString());
201
- }
202
- return false;
207
+ @Override
208
+ public void onHostResume() {
209
+ if (woosmap != null) {
210
+ woosmap.onResume();
203
211
  }
212
+ }
204
213
 
214
+ @Override
215
+ public void onHostPause() {
216
+ if (woosmap != null) {
217
+ woosmap.onPause();
218
+ }
219
+ }
205
220
 
206
- @Override
207
- public void onHostResume() {
208
- if (woosmap != null) {
209
- woosmap.onResume();
221
+ @Override
222
+ public void onHostDestroy() {
223
+ if (woosmap != null) {
224
+ woosmap.onDestroy();
225
+ }
226
+ }
227
+
228
+ @ReactMethod
229
+ public void setWoosmapApiKey(ReadableArray data, Promise promise) {
230
+ try {
231
+ if (isWoosmapInitialized()) {
232
+ String apiKey = "";
233
+ if (!data.isNull(0)) {
234
+ apiKey = data.getString(0);
235
+ }
236
+ if (!apiKey.isEmpty()) {
237
+ WoosmapSettings.privateKeyWoosmapAPI = apiKey;
238
+ promise.resolve(WoosmapMessageAndKey.successMessage);
239
+ } else {
240
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
241
+ }
242
+ } else {
243
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
210
244
  }
245
+
246
+ } catch (Exception ex) {
247
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
211
248
  }
249
+ }
212
250
 
213
- @Override
214
- public void onHostPause() {
215
- if (woosmap != null) {
216
- woosmap.onPause();
251
+ @ReactMethod
252
+ public void startTracking(ReadableArray data, Promise promise) {
253
+ try {
254
+ if (isWoosmapInitialized()) {
255
+ if (data.isNull(0)) {
256
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.trackingProfileNotProvided);
257
+ }
258
+
259
+ String trackingProfile = data.getString(0);
260
+ if (trackingProfile.equals(Woosmap.ConfigurationProfile.liveTracking) ||
261
+ trackingProfile.equals(Woosmap.ConfigurationProfile.passiveTracking) ||
262
+ trackingProfile.equals(Woosmap.ConfigurationProfile.visitsTracking)) {
263
+ woosmap.startTracking(trackingProfile);
264
+ promise.resolve(WoosmapMessageAndKey.successMessage);
265
+ } else {
266
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
267
+ }
268
+ } else {
269
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
217
270
  }
271
+ } catch (Exception ex) {
272
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
218
273
  }
274
+ }
219
275
 
220
- @Override
221
- public void onHostDestroy() {
222
- if (woosmap != null) {
223
- woosmap.onDestroy();
276
+ @ReactMethod
277
+ public void stopTracking(Promise promise) {
278
+ try {
279
+ if (isWoosmapInitialized()) {
280
+ woosmap.stopTracking();
281
+ promise.resolve(WoosmapMessageAndKey.successMessage);
282
+ } else {
283
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
224
284
  }
285
+
286
+ } catch (Exception ex) {
287
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
225
288
  }
226
- @ReactMethod
227
- public void setWoosmapApiKey(ReadableArray data, Promise promise) {
228
- try {
229
- if (isWoosmapInitialized()) {
230
- String apiKey = "";
231
- if (!data.isNull(0)) {
232
- apiKey = data.getString(0);
233
- }
234
- if (!apiKey.isEmpty()) {
235
- WoosmapSettings.privateKeyWoosmapAPI = apiKey;
236
- promise.resolve(WoosmapMessageAndKey.successMessage);
237
- } else {
238
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapKeyNotProvide);
239
- }
289
+ }
290
+
291
+ @ReactMethod
292
+ public void watchLocation(String watchID, Promise promise) {
293
+ try {
294
+ if (isWoosmapInitialized()) {
295
+ if (locationReadyListener == null) {
296
+ locationReadyListener = new WoosLocationReadyListener(reactContext);
297
+ woosmap.setLocationReadyListener(locationReadyListener);
298
+ promise.resolve(watchID);
240
299
  } else {
241
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
300
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchAlreadyStarted);
242
301
  }
302
+ } else {
303
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
304
+ }
305
+ } catch (Exception ex) {
306
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
307
+ }
308
+ }
243
309
 
244
- } catch (Exception ex) {
245
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
310
+ @ReactMethod
311
+ public void clearLocationWatch(String watchID, Promise promise) {
312
+ try {
313
+ if (locationReadyListener != null) {
314
+ woosmap.setLocationReadyListener(null);
315
+ locationReadyListener = null;
316
+ promise.resolve(watchID);
317
+ } else {
318
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchNotStarted);
246
319
  }
320
+ } catch (Exception ex) {
321
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
247
322
  }
323
+ }
248
324
 
249
- @ReactMethod
250
- public void startTracking(ReadableArray data, Promise promise) {
251
- try {
252
- if (isWoosmapInitialized()) {
253
- if (data.isNull(0)) {
254
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.trackingProfileNotProvided);
325
+ @ReactMethod
326
+ private void setSFMCCredentials(ReadableMap map, Promise promise) {
327
+ try {
328
+ if (isWoosmapInitialized()) {
329
+ if (!map.toHashMap().isEmpty()) {
330
+ HashMap<String, String> SFMCInfo = new HashMap<>();
331
+ String key;
332
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCauthenticationBaseURIkey)) {
333
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCauthenticationBaseURIkey);
334
+ }
335
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCrestBaseURIkey)) {
336
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCrestBaseURIkey);
337
+ }
338
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_idkey)) {
339
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_idkey);
340
+ }
341
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_secretkey)) {
342
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCclient_secretkey);
343
+ }
344
+ if (!map.hasKey(WoosmapMessageAndKey.SMFCcontactKey)) {
345
+ throw new Exception(WoosmapMessageAndKey.keyMissingMessage + ": " + WoosmapMessageAndKey.SMFCcontactKey);
255
346
  }
256
347
 
257
- String trackingProfile = data.getString(0);
258
- if (trackingProfile.equals(Woosmap.ConfigurationProfile.liveTracking) ||
259
- trackingProfile.equals(Woosmap.ConfigurationProfile.passiveTracking) ||
260
- trackingProfile.equals(Woosmap.ConfigurationProfile.visitsTracking)) {
261
- woosmap.startTracking(trackingProfile);
262
- promise.resolve(WoosmapMessageAndKey.successMessage);
263
- } else {
264
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.invalidProfileTrackingError);
348
+ Iterator<String> keys = map.toHashMap().keySet().iterator();
349
+
350
+ while (keys.hasNext()) {
351
+ key = keys.next();
352
+ SFMCInfo.put(key, map.getString(key));
265
353
  }
354
+ WoosmapSettings.SFMCCredentials = SFMCInfo;
355
+ promise.resolve(WoosmapMessageAndKey.successMessage);
266
356
  } else {
267
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
357
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.credentialEmptyMessage);
268
358
  }
269
- } catch (Exception ex) {
270
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
359
+ } else {
360
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
271
361
  }
362
+
363
+ } catch (Exception ex) {
364
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
272
365
  }
366
+ }
273
367
 
274
- @ReactMethod
275
- public void stopTracking(Promise promise) {
276
- try {
277
- if (isWoosmapInitialized()) {
278
- woosmap.stopTracking();
279
- promise.resolve(WoosmapMessageAndKey.successMessage);
368
+ @ReactMethod
369
+ public void watchRegions(String watchID, Promise promise) {
370
+ try {
371
+ if (isWoosmapInitialized()) {
372
+ if (regionReadyListener == null) {
373
+ regionReadyListener = new WoosRegionReadyListener(reactContext);
374
+ woosmap.setRegionLogReadyListener(regionReadyListener);
375
+ woosmap.setRegionReadyListener(regionReadyListener);
376
+ promise.resolve(watchID);
280
377
  } else {
281
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
378
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchAlreadyStarted);
282
379
  }
283
-
284
- } catch (Exception ex) {
285
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
380
+ } else {
381
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
286
382
  }
383
+ } catch (Exception ex) {
384
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
287
385
  }
288
- @ReactMethod
289
- public void watchLocation(String watchID,Promise promise){
290
- try {
291
- if(isWoosmapInitialized()){
292
- if(locationReadyListener==null){
293
- locationReadyListener=new WoosLocationReadyListener(reactContext);
294
- woosmap.setLocationReadyListener(locationReadyListener);
295
- promise.resolve(watchID);
296
- }else {
297
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchAlreadyStarted);
298
- }
299
- }else {
300
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
301
- }
302
- }catch (Exception ex){
303
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
386
+ }
387
+
388
+ @ReactMethod
389
+ public void clearRegionsWatch(String watchID, Promise promise) {
390
+ try {
391
+ if (regionReadyListener != null) {
392
+ woosmap.setRegionLogReadyListener(null);
393
+ woosmap.setRegionReadyListener(null);
394
+ regionReadyListener = null;
395
+ promise.resolve(watchID);
396
+ } else {
397
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.regionWatchNotStarted);
304
398
  }
399
+ } catch (Exception ex) {
400
+ promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
305
401
  }
306
- @ReactMethod
307
- public void clearLocationWatch(String watchID,Promise promise){
308
- try {
309
- if(locationReadyListener!=null){
310
- woosmap.setLocationReadyListener(null);
311
- locationReadyListener=null;
312
- promise.resolve(watchID);
402
+ }
403
+
404
+ @ReactMethod
405
+ public void setPoiRadius(String radius,Promise promise){
406
+ try{
407
+ if (isWoosmapInitialized()){
408
+ if (radius.isEmpty()){
409
+ throw new Exception(WoosmapMessageAndKey.radiusEmptyMessage);
410
+ }
411
+ if(onlyContainsNumbers(radius)){
412
+ WoosmapSettings.poiRadius=Integer.parseInt(radius);
413
+ promise.resolve(WoosmapMessageAndKey.successMessage);
414
+ }else if(onlyContainsDouble(radius)){
415
+ double d=Double.parseDouble(radius);
416
+ WoosmapSettings.poiRadius=(int) Math.round(d);
417
+ promise.resolve(WoosmapMessageAndKey.successMessage);
313
418
  }else {
314
- promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.locationWatchNotStarted);
419
+ WoosmapSettings.poiRadiusNameFromResponse=radius;
420
+ promise.resolve(WoosmapMessageAndKey.successMessage);
315
421
  }
316
- }catch (Exception ex){
317
- promise.reject(WoosmapMessageAndKey.errorCode, ex.getMessage());
422
+ }else {
423
+ promise.reject(WoosmapMessageAndKey.errorCode, WoosmapMessageAndKey.woosmapNotInitialized);
318
424
  }
319
425
  }
320
- @ReactMethod
321
- private void setSFMCCredentials(ReadableMap map, Promise promise){
322
- try{
323
- if(isWoosmapInitialized()){
324
- if (!map.toHashMap().isEmpty()){
325
- HashMap<String, String> SFMCInfo = new HashMap<>();
326
- String key;
327
- if (!map.hasKey(WoosmapMessageAndKey.SMFCauthenticationBaseURIkey)){
328
- throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCauthenticationBaseURIkey);
329
- }
330
- if (!map.hasKey(WoosmapMessageAndKey.SMFCrestBaseURIkey)){
331
- throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCrestBaseURIkey);
332
- }
333
- if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_idkey)){
334
- throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCclient_idkey );
335
- }
336
- if (!map.hasKey(WoosmapMessageAndKey.SMFCclient_secretkey)){
337
- throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCclient_secretkey );
338
- }
339
- if (!map.hasKey(WoosmapMessageAndKey.SMFCcontactKey)){
340
- throw new Exception(WoosmapMessageAndKey.keyMissingMessage+": "+WoosmapMessageAndKey.SMFCcontactKey );
341
- }
342
-
343
- Iterator<String> keys = map.toHashMap().keySet().iterator();
344
-
345
- while (keys.hasNext()){
346
- key = keys.next();
347
- SFMCInfo.put(key,map.getString(key));
348
- }
349
- WoosmapSettings.SFMCCredentials = SFMCInfo;
350
- promise.resolve(WoosmapMessageAndKey.successMessage);
351
- }
352
- else{
353
- promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.credentialEmptyMessage);
354
- }
355
- }else {
356
- promise.reject(WoosmapMessageAndKey.errorCode,WoosmapMessageAndKey.woosmapNotInitialized);
357
- }
426
+ catch (Exception ex){
427
+ promise.reject(WoosmapMessageAndKey.errorCode,ex.getMessage());
428
+ }
429
+ }
358
430
 
359
- }
360
- catch (Exception ex){
361
- promise.reject(WoosmapMessageAndKey.errorCode,ex.getMessage());
362
- }
431
+ /**
432
+ *
433
+ * @param text string for checking if it contains only number or not.
434
+ * @return true boolean value if string is only number else false.
435
+ */
436
+ private boolean onlyContainsNumbers(String text) {
437
+ try {
438
+ Long.parseLong(text);
439
+ return true;
440
+ } catch (NumberFormatException ex) {
441
+ return false;
363
442
  }
443
+ }
364
444
 
445
+ private boolean onlyContainsDouble(String text) {
446
+ try {
447
+ Double.parseDouble(text);
448
+ return true;
449
+ } catch (NumberFormatException ex) {
450
+ return false;
451
+ }
365
452
  }
453
+
454
+
455
+ }
@@ -0,0 +1,49 @@
1
+ package com.reactnativeplugingeofencing;
2
+
3
+ import android.content.Context;
4
+
5
+ import com.facebook.react.ReactApplication;
6
+ import com.facebook.react.ReactInstanceManager;
7
+ import com.facebook.react.ReactNativeHost;
8
+ import com.facebook.react.bridge.ReactContext;
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
10
+ import com.webgeoservices.woosmapgeofencing.Woosmap;
11
+ import com.webgeoservices.woosmapgeofencing.database.Region;
12
+ import com.webgeoservices.woosmapgeofencing.database.RegionLog;
13
+
14
+ public class WoosRegionReadyListener implements Woosmap.RegionReadyListener,Woosmap.RegionLogReadyListener {
15
+
16
+ private ReactNativeHost reactNativeHost;
17
+ private Context context;
18
+ public WoosRegionReadyListener(Context context){
19
+ this.context=context;
20
+ }
21
+ private void sendEvent(final String eventName, final Object data) {
22
+ final ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
23
+ ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
24
+ if (reactContext != null) {
25
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
26
+ }
27
+ }
28
+ @Override
29
+ public void RegionLogReadyCallback(RegionLog regionLog) {
30
+ try {
31
+ ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
32
+ reactNativeHost = reactApplication.getReactNativeHost();
33
+ sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(regionLog));
34
+ }catch (Exception ex){
35
+ sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
36
+ }
37
+ }
38
+
39
+ @Override
40
+ public void RegionReadyCallback(Region region) {
41
+ try {
42
+ ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
43
+ reactNativeHost = reactApplication.getReactNativeHost();
44
+ sendEvent(WoosmapMessageAndKey.regionSuccessCallbackName, WoosmapUtil.getRegionWritableMap(region));
45
+ }catch (Exception ex){
46
+ sendEvent(WoosmapMessageAndKey.regionErrorCallbackName, ex.getMessage());
47
+ }
48
+ }
49
+ }
@@ -26,6 +26,13 @@ public class WoosmapMessageAndKey {
26
26
  protected static String SMFCclient_secretkey="client_secret";
27
27
  protected static String SMFCcontactKey="contactKey";
28
28
  protected static String credentialEmptyMessage="Credentials cannot be empty.";
29
+ protected static String regionSuccessCallbackName="woosmapgeofenceRegionDidChange";
30
+ protected static String regionErrorCallbackName="woosmapgeofenceRegionError";
31
+ protected static String regionWatchAlreadyStarted="Region watch already added";
32
+ protected static String regionWatchNotStarted="region watch not started";
33
+ protected static String radiusEmptyMessage="Radius value can not be empty";
34
+ protected static String invalidRadiusMessage="POI Radius should be an integer or a string.";
35
+
29
36
 
30
37
 
31
38
 
@@ -7,6 +7,8 @@ import com.facebook.react.bridge.WritableArray;
7
7
  import com.facebook.react.bridge.WritableMap;
8
8
  import com.facebook.react.bridge.WritableNativeArray;
9
9
  import com.facebook.react.bridge.WritableNativeMap;
10
+ import com.webgeoservices.woosmapgeofencing.database.Region;
11
+ import com.webgeoservices.woosmapgeofencing.database.RegionLog;
10
12
 
11
13
  import org.json.JSONArray;
12
14
  import org.json.JSONException;
@@ -30,5 +32,40 @@ public class WoosmapUtil {
30
32
  }
31
33
  return map;
32
34
  }
35
+ public static WritableMap getRegionWritableMap(RegionLog regionLog){
36
+ WritableMap map=new WritableNativeMap();
37
+ try{
38
+ map.putDouble("longitude", regionLog.lng);
39
+ map.putDouble("latitude", regionLog.lat);
40
+ map.putDouble("date", regionLog.dateTime);
41
+ map.putBoolean("didenter", regionLog.didEnter);
42
+ map.putString("identifier", regionLog.identifier);
43
+ map.putDouble("radius", regionLog.radius);
44
+ map.putBoolean("frompositiondetection", regionLog.isCurrentPositionInside);
45
+ return map;
46
+ }
47
+ catch (Exception ex){
48
+ Log.e(TAG,ex.toString());
49
+ }
50
+ return null;
51
+ }
52
+
53
+ public static WritableMap getRegionWritableMap(Region region){
54
+ WritableMap map=new WritableNativeMap();
55
+ try{
56
+ map.putDouble("longitude", region.lng);
57
+ map.putDouble("latitude", region.lat);
58
+ map.putDouble("date", region.dateTime);
59
+ map.putBoolean("didenter", region.didEnter);
60
+ map.putString("identifier", region.identifier);
61
+ map.putDouble("radius", region.radius);
62
+ map.putBoolean("frompositiondetection", region.isCurrentPositionInside);
63
+ return map;
64
+ }
65
+ catch (Exception ex){
66
+ Log.e(TAG,ex.toString());
67
+ }
68
+ return null;
69
+ }
33
70
 
34
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/react-native-plugin-geofencing",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "This react-native plugin extends the functionality offered by the Woosmap Geofencing Mobile SDKs. Find more about the Woosmap Geofencing SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- </Workspace>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>IDEDidComputeMac32BitWarning</key>
6
- <true/>
7
- </dict>
8
- </plist>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>WoosmapGeofencingPlugin.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>