From aea35e8fa1d984b26d43fd3099cfeb13915555e2 Mon Sep 17 00:00:00 2001 From: Huang Yu Date: Wed, 13 Jan 2016 15:53:44 -0800 Subject: [PATCH] add android versoin --- app/build.gradle | 17 ++++++++++ app/src/main/AndroidManifest.xml | 3 ++ .../bitgo/randombytes/RandomBytesModule.java | 31 +++++++++++++++++ .../bitgo/randombytes/RandomBytesPackage.java | 34 +++++++++++++++++++ build.gradle | 18 ++++++++++ settings.gradle | 2 ++ 6 files changed, 105 insertions(+) create mode 100644 app/build.gradle create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/bitgo/randombytes/RandomBytesModule.java create mode 100644 app/src/main/java/com/bitgo/randombytes/RandomBytesPackage.java create mode 100644 build.gradle create mode 100644 settings.gradle diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..f71b1b7 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } +} + +dependencies { + compile 'com.facebook.react:react-native:0.13.+' +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..dbfc316 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/app/src/main/java/com/bitgo/randombytes/RandomBytesModule.java b/app/src/main/java/com/bitgo/randombytes/RandomBytesModule.java new file mode 100644 index 0000000..b2a06c3 --- /dev/null +++ b/app/src/main/java/com/bitgo/randombytes/RandomBytesModule.java @@ -0,0 +1,31 @@ +package com.bitgo.randombytes; + +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.Callback; + +import com.facebook.react.bridge.ReactContextBaseJavaModule; + +import java.security.SecureRandom; + +import android.util.Base64; + +class RandomBytesModule extends ReactContextBaseJavaModule { + + public RandomBytesModule(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return "RNRandomBytes"; + } + @ReactMethod + public void randomBytes(int size, Callback success) { + SecureRandom sr = new SecureRandom(); + byte[] output = new byte[size]; + sr.nextBytes(output); + String string = Base64.encodeToString(output, Base64.DEFAULT); + success.invoke(null, string); + } +} diff --git a/app/src/main/java/com/bitgo/randombytes/RandomBytesPackage.java b/app/src/main/java/com/bitgo/randombytes/RandomBytesPackage.java new file mode 100644 index 0000000..839e1d8 --- /dev/null +++ b/app/src/main/java/com/bitgo/randombytes/RandomBytesPackage.java @@ -0,0 +1,34 @@ +package com.bitgo.randombytes; + +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 RandomBytesPackage implements ReactPackage { + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + + modules.add(new RandomBytesModule(reactContext)); + + return modules; + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List> createJSModules() { + return Collections.emptyList(); + } +} diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..cfc3084 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.3.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + mavenLocal() + jcenter() + } +} diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..9f2d24e --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'randombytes' +include ':app'