Skip to content

Commit

Permalink
Merge pull request #15 from aouaki/master
Browse files Browse the repository at this point in the history
Add Android support
  • Loading branch information
negativetwelve authored Oct 24, 2016
2 parents ae66371 + 47fbab5 commit cad1cbf
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 1 deletion.
33 changes: 33 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

repositories {
maven {
url 'http://sdk.uxcam.com/android/'
}
}

dependencies {
compile 'com.android.support:appcompat-v7:24.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.uxcam:uxcam:2.5.1@aar'
compile 'com.facebook.react:react-native:+'
testCompile 'junit:junit:4.12'
}
17 changes: 17 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.4.1_1/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
4 changes: 4 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rnuxcam.rnuxcam">

</manifest>
102 changes: 102 additions & 0 deletions android/src/main/java/com/rnuxcam/rnuxcam/UXCamModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.rnuxcam.rnuxcam;

import com.uxcam.UXCam;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.Promise;

import java.util.HashMap;

public class UXCamModule extends ReactContextBaseJavaModule {

public UXCamModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Override
public String getName() {
return "RNUXCam";
}

@SuppressWarnings("unused")
@ReactMethod
public void startWithKey(String key) {
UXCam.startApplicationWithKeyForCordova(getCurrentActivity(), key);
}

@SuppressWarnings("unused")
@ReactMethod
public void tagScreenName(String screenName) {
UXCam.tagScreenName(screenName);
}

@SuppressWarnings("unused")
@ReactMethod
public void tagUserName(String userName) {
UXCam.tagUsersName(userName);
}

@SuppressWarnings("unused")
@ReactMethod
public void addTag(String tag, ReadableMap properties) {
HashMap<String, String> map = new HashMap<String, String>();

ReadableMapKeySetIterator iterator = properties.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();
String value = properties.getString(key);
map.put(key, value);
}
UXCam.addTagWithProperties(tag, map);
}

@SuppressWarnings("unused")
@ReactMethod
public void markUserAsFavorite() {
UXCam.markSessionAsFavorite();
}

@SuppressWarnings("unused")
@ReactMethod
public void urlForCurrentUser(Promise promise) {
String url = UXCam.urlForCurrentUser();
if (url == null || url.isEmpty()) {
String code = "no_url";
String message = "Could not retrieve the url for the current user.";
Throwable error = new Throwable(message);
promise.reject(code, message, error);
} else {
promise.resolve(url);
}
}

@SuppressWarnings("unused")
@ReactMethod
public void urlForCurrentSession(Promise promise) {
String url = UXCam.urlForCurrentSession();
if (url == null || url.isEmpty()) {
String code = "no_url";
String message = "Could not retrieve the url for the current session.";
Throwable error = new Throwable(message);
promise.reject(code, message, error);
} else {
promise.resolve(url);
}
}

@SuppressWarnings("unused")
@ReactMethod
public void occludeSensitiveScreen(boolean occlude) {
UXCam.occludeSensitiveScreen(occlude);
}

@SuppressWarnings("unused")
@ReactMethod
public void stopApplicationAndUploadData() {
UXCam.stopApplicationAndUploadData();
}
}
31 changes: 31 additions & 0 deletions android/src/main/java/com/rnuxcam/rnuxcam/UXCamPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.rnuxcam.rnuxcam;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class UXCamPackage implements ReactPackage {

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new com.rnuxcam.rnuxcam.UXCamModule(reactContext));
return modules;
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
21 changes: 20 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,26 @@ You're done! :tada:

### Android

Coming soon!
Run the following:

```bash
react-native link react-native-ux-cam
```

Then add the following to your file `android/app/build.gradle` (or add the maven url to your existing repositories section):
```gradle
repositories {
maven {
url 'http://sdk.uxcam.com/android/'
}
}
```

And add this to your file `android/app/src/main/AndroidManifest.xml`, inside your `<application>` tag:
```xml
<service android:name="com.uxcam.service.HttpPostService"/>
```


## Usage

Expand Down

0 comments on commit cad1cbf

Please sign in to comment.