add stubs for android implementation

This commit is contained in:
Andy Prock 2015-12-21 13:57:43 -08:00
parent a742459272
commit c67d90052b
6 changed files with 231 additions and 1 deletions

31
android/build.gradle Normal file
View File

@ -0,0 +1,31 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "0.2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// needed for https://github.com/square/okio/issues/58
lintOptions {
warning 'InvalidPackage'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.facebook.react:react-native:0.11.+'
}

17
android/proguard-rules.pro vendored Normal file
View File

@ -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.3.3/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 *;
#}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.peel.react" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
</manifest>

View File

@ -0,0 +1,132 @@
/**
* TcpSockets.java
* react-native-tcp
*
* Created by Andy Prock on 12/21/15.
*/
package com.peel.react;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import java.io.IOException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;
/**
* The NativeModule in charge of storing active {@link TcpSocketClient}s, and acting as an api layer.
*/
public final class TcpSockets extends ReactContextBaseJavaModule {
private static final String TAG = "TcpSockets";
private boolean mShuttingDown = false;
public TcpSockets(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return TAG;
}
@Override
public void initialize() {
mShuttingDown = false;
}
@Override
public void onCatalystInstanceDestroy() {
mShuttingDown = true;
}
/**
* Creates a {@link TcpSocketClient} with the given ID
*/
@ReactMethod
public void createSocket(final Integer cId) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "TcpSockets.createSocket unimplemented.");
WritableMap eventParams = Arguments.createMap();
eventParams.putString("event", "error");
eventParams.putString("data", "TcpSockets.createSocket unimplemented");
ReactContext reactContext = TcpSockets.this.getReactApplicationContext();
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("tcp-" + cId + "-event", eventParams);
}
}.execute();
}
@ReactMethod
public void connect(final Integer cId, final @Nullable String host, final Integer port, final ReadableMap options) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "TcpSockets.connect unimplemented.");
WritableMap eventParams = Arguments.createMap();
eventParams.putString("event", "error");
eventParams.putString("data", "TcpSockets.connect unimplemented");
ReactContext reactContext = TcpSockets.this.getReactApplicationContext();
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit("tcp-" + cId + "-event", eventParams);
}
}.execute();
}
@ReactMethod
public void write(final Integer cId, final String base64String, final boolean encoded, final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "TcpSockets.write unimplemented.");
callback.invoke("unimplemented." + cId);
}
}.execute();
}
@ReactMethod
public void end(final Integer cId, final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "TcpSockets.end unimplemented.");
callback.invoke("unimplemented." + cId);
}
}.execute();
}
@ReactMethod
public void destroy(final Integer cId, final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
FLog.e(TAG, "TcpSockets.destroy unimplemented.");
callback.invoke("unimplemented." + cId);
}
}.execute();
}
}

View File

@ -0,0 +1,43 @@
/**
* TcpSocketsModule.java
* react-native-tcp
*
* Created by Andy Prock on 12/21/15.
*/
package com.peel.react;
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 final class TcpSocketsModule implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<NativeModule>();
modules.add(new TcpSockets(reactContext));
return modules;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(
ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

View File

@ -106,7 +106,7 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0720;
ORGANIZATIONNAME = "Tradle, Inc.";
ORGANIZATIONNAME = "Peel, Inc.";
TargetAttributes = {
58B511DA1A9E6C8500147676 = {
CreatedOnToolsVersion = 6.1.1;