Skip to content

Commit

Permalink
Merge pull request #1 from roam-ai/RC-824
Browse files Browse the repository at this point in the history
Rc 824
  • Loading branch information
Jothi Priyadharshan authored Aug 5, 2022
2 parents 0acd415 + 1aa2cb7 commit 7aa8cc6
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 53 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.0.1

* First version of new Roam Cordova SDK
- First version of new Roam Cordova SDK

## 0.0.2

- Updated Android SDK v0.1.1
- Added `setForegroundNotification` method
- Fixed time and distance based tracking methods
- Fixed location listener
- Fixed `requestLocationPermission` and `requestBackgroundLocationPermission` methods
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Now that the location tracking is set up, you can subscribe to locations and eve
To do that, you need to set the location and event listener to `true` using the below method. By default the status will set to `false` and needs to be set to `true` in order to stream the location and events updates to the same device or other devices.

```javascript
cordova.plugins.roam.toggleListener(true, true,, function(success){
cordova.plugins.roam.toggleListener(true, true, function(success){
// do something on success
}, function(error){
// do something on error
Expand Down Expand Up @@ -303,6 +303,14 @@ cordova.plugins.roam.offEvents();
cordova.plugins.roam.offError();
```

## Set Foreground Notification

To set foreground notification, use the below method.

```javascript
cordova.plugins.roam.setForegroundNotification(boolean, "title", "description", "icon", "activity_path")
```

## Documentation

Please visit our [Developer Center](https://github.com/roam-ai/roam-cordova/wiki) for instructions on other SDK methods.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "roam-cordova",
"version": "0.0.1",
"version": "0.0.2",
"description": "This plugin allows to use the Roam.ai SDK in your React Native mobile application on iOS and Android.",
"homepage": "https://roam.ai",
"license": "MIT",
Expand Down
43 changes: 33 additions & 10 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin
id="roam-cordova"
version="0.0.1"
version="0.0.2"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>roam</name>
<js-module name="roam" src="www/roam.js">
<clobbers target="cordova.plugins.roam" />
</js-module>
<!-- Android Configuration -->


<!-- Android Configuration -->
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="roam">
<param name="android-package" value="com.roam.cordova.CDVRoam" />
</feature>
</config-file>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="roam">
<param name="android-package" value="com.roam.cordova.CDVRoam"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="com.roam.cordova.RoamCDVService" android:foregroundServiceType="location"/>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<receiver
android:name="com.roam.cordova.CDVRoam$RoamCordovaReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.roam.android.RECEIVED" />
</intent-filter>
</receiver>
</config-file>
<config-file parent="/*" target="AndroidManifest.xml">
<!--Network-->
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -23,6 +38,8 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- Service -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!--Restart-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!--Battery-->
Expand All @@ -32,10 +49,16 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.location.gps" />
</config-file>
<source-file src="src/android/CDVRoam.java" target-dir="src/com/roam/cordova/" />
<framework custom="true" src="src/android/roam-sdk.gradle" type="gradleReference" />
<source-file src="src/android/src/main/java/com/roam/cordova/CDVRoam.java" target-dir="src/com/roam/cordova/" />
<source-file src="src/android/src/main/java/com/roam/cordova/RoamCDVService.java" target-dir="src/com/roam/cordova"/>
<framework custom="true" src="src/android/src/main/java/com/roam/cordova/roam-sdk.gradle" type="gradleReference" />
</platform>
</plugin>




<!-- Android Configuration -->
</plugin>



Expand Down
15 changes: 15 additions & 0 deletions src/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.roam.cordova">

<application>
<receiver
android:name="com.roam.cordova.CDVRoam$RoamCordovaReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.roam.android.RECEIVED" />
</intent-filter>
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package com.roam.cordova;

import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.provider.Settings;

import androidx.annotation.NonNull;
import android.util.Log;

import com.google.gson.GsonBuilder;
import com.roam.sdk.Roam;
Expand All @@ -26,21 +22,16 @@
import com.roam.sdk.service.RoamReceiver;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;

import org.apache.cordova.CordovaWebView;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class CDVRoam extends CordovaPlugin {
private static CallbackContext locationCallbackContext;
private static CallbackContext eventsCallbackContext;
private static CallbackContext errorCallbackContext;
private static CallbackContext permissionCallbackContext;
private Activity context;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Expand All @@ -58,23 +49,23 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
return true;

case "requestLocationPermission":
this.requestLocationPermission(callbackContext);
this.requestLocationPermission();
return true;

case "checkLocationServices":
this.checkLocationServices(callbackContext);
return true;

case "requestLocationServices":
this.requestLocationServices(callbackContext);
this.requestLocationServices();
return true;

case "checkBackgroundLocationPermission":
this.checkBackgroundLocationPermission(callbackContext);
return true;

case "requestBackgroundLocationPermission":
this.requestBackgroundLocationPermission(callbackContext);
this.requestBackgroundLocationPermission();
return true;

case "getDeviceToken":
Expand Down Expand Up @@ -123,6 +114,15 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.toggleEvents(geofenceEvents, tripEvents, locationEvents, movingGeofenceEvents, callbackContext);
return true;

case "setForegroundNotification":
boolean enabled = args.getBoolean(0);
String notificationTitle = args.getString(1);
String notificationDescription = args.getString(2);
String notificationIcon = args.getString(3);
String notificationActivity = args.getString(4);
this.setForegroundNotification(enabled, notificationTitle, notificationDescription, notificationIcon, notificationActivity);
return true;

case "getEventsStatus":
this.getEventsStatus(callbackContext);
return true;
Expand Down Expand Up @@ -161,7 +161,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
case "startTrackingDistanceInterval":
int distance = args.getInt(0);
int stationary = args.getInt(1);
String dDesiredAccuracy = args.getString(3);
String dDesiredAccuracy = args.getString(2);
this.startTrackingDistanceInterval(distance, stationary, dDesiredAccuracy);

case "publishAndSave":
Expand Down Expand Up @@ -232,43 +232,52 @@ private void checkLocationPermission(CallbackContext callbackContext) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, status));
}

private void requestLocationPermission(CallbackContext callbackContext) {
permissionCallbackContext = callbackContext;
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
cordova.requestPermissions(this, Roam.REQUEST_CODE_LOCATION_PERMISSION, permissions);
private void requestLocationPermission() {
Roam.requestLocationPermission(cordova.getActivity());
}

private void checkLocationServices(CallbackContext callbackContext) {
String status = enabledStatus(Roam.checkLocationServices());
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, status));
}

private void requestLocationServices(CallbackContext callbackContext) {
permissionCallbackContext = callbackContext;
cordova.startActivityForResult(this, new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS), Roam.REQUEST_CODE_LOCATION_ENABLED);
private void requestLocationServices() {
Roam.requestLocationServices(cordova.getActivity());
}

private void checkBackgroundLocationPermission(CallbackContext callbackContext) {
String status = permissionsStatus(Roam.checkBackgroundLocationPermission());
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, status));
}

private void requestBackgroundLocationPermission(CallbackContext callbackContext) {
permissionCallbackContext = callbackContext;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
String[] permissions = {Manifest.permission.ACCESS_BACKGROUND_LOCATION};
cordova.requestPermissions(this, Roam.REQUEST_CODE_BACKGROUND_LOCATION_PERMISSION, permissions);
} else {
permissionCallbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "UNKNOWN"));
}
private void requestBackgroundLocationPermission() {
Roam.requestBackgroundLocationPermission(cordova.getActivity());
}

private void getDeviceToken(CallbackContext callbackContext) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, Roam.getDeviceToken()));
}

private void setForegroundNotification(boolean enabled, String title, String description, String image, String activity){
Log.e("TAG", "setForegroundNotification: " + enabled + title + description + image + activity);
try{
String[] split = image.split("/");
String firstSubString = split[0];
String secondSubString = split[1];
int resId = cordova.getActivity().getResources()
.getIdentifier(
secondSubString,
firstSubString,
cordova.getActivity().getPackageName()
);
Roam.setForegroundNotification(enabled, title, description, resId, activity);
} catch (Exception e){
e.printStackTrace();
}
}

private void createUser(String description, final CallbackContext callbackContext) {
Roam.createUser(description, new RoamCallback() {
Roam.createUser(description,null, new RoamCallback() {
@Override
public void onSuccess(RoamUser roamUser) {
String serializedUser = new GsonBuilder().create().toJson(roamUser);
Expand Down Expand Up @@ -387,13 +396,13 @@ public void onFailure(RoamError roamError) {
private void updateCurrentLocation(int accuracy, String desiredAccuracy) {
switch (desiredAccuracy) {
case "MEDIUM":
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.MEDIUM, accuracy);
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.MEDIUM, accuracy, null);
break;
case "LOW":
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.LOW, accuracy);
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.LOW, accuracy, null);
break;
default:
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.HIGH, accuracy);
Roam.updateCurrentLocation(RoamTrackingMode.DesiredAccuracy.HIGH, accuracy, null);
break;
}
}
Expand Down Expand Up @@ -458,16 +467,29 @@ private void startTracking(String trackingMode){
switch (trackingMode) {
case "ACTIVE":
Roam.startTracking(RoamTrackingMode.ACTIVE);
startReceiverService();
break;
case "BALANCED":
Roam.startTracking(RoamTrackingMode.BALANCED);
startReceiverService();
break;
case "PASSIVE":
Roam.startTracking(RoamTrackingMode.PASSIVE);
startReceiverService();
break;
}
}

private void startReceiverService(){
Activity activity = cordova.getActivity();
activity.startService(new Intent(activity, RoamCDVService.class));
}

private void stopReceiverService(){
Activity activity = cordova.getActivity();
activity.stopService(new Intent(activity, RoamCDVService.class));
}

private void startTrackingTimeInterval(int timeInterval, String desiredAccuracy) {
RoamTrackingMode.Builder builder = new RoamTrackingMode.Builder(timeInterval);
switch (desiredAccuracy) {
Expand All @@ -482,6 +504,7 @@ private void startTrackingTimeInterval(int timeInterval, String desiredAccuracy)
break;
}
Roam.startTracking(builder.build());
startReceiverService();
}

private void startTrackingDistanceInterval(int distance, int stationary, String desiredAccuracy) {
Expand All @@ -498,12 +521,15 @@ private void startTrackingDistanceInterval(int distance, int stationary, String
break;
}
Roam.startTracking(builder.build());
startReceiverService();
}

private void stopTracking() {
Roam.stopTracking();
stopReceiverService();
}


public void publishAndSave() {
RoamPublish roamPublish = new RoamPublish.Builder().build();
Roam.publishAndSave(roamPublish);
Expand Down
Loading

0 comments on commit 7aa8cc6

Please sign in to comment.