Skip to content

Commit

Permalink
完善接口
Browse files Browse the repository at this point in the history
  • Loading branch information
peidongbiao committed Jun 21, 2021
1 parent 2d521aa commit 8d0ab26
Show file tree
Hide file tree
Showing 68 changed files with 1,513 additions and 177 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# PlatformPlugin
为JS、RN、Flutter提供统一平台能力接口。
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
plugins {
id 'com.android.library'
id 'com.github.dcendents.android-maven'
}
group = rootProject.ext.group

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 22
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.pei.platformplugin.dsbridge;

import com.pei.platformplugin.PluginCallback;
import com.pei.platformplugin.PluginResult;

import org.json.JSONException;
import org.json.JSONObject;

import wendu.dsbridge.CompletionHandler;

public class CompletionHandlerCallbackAdapter implements PluginCallback {

CompletionHandler<JSONObject> mCompletionHandler;

public CompletionHandlerCallbackAdapter(CompletionHandler<JSONObject> completionHandler) {
mCompletionHandler = completionHandler;
}

@Override
public void onResult(PluginResult result) {
JSONObject object = new JSONObject();
try {
object.put("errorCode", result.getErrorCode());
object.put("errorMsg", result.getErrorMsg());
object.put("success", result.isSuccessful());
object.put("data", result.getData());
} catch (JSONException e) {
e.printStackTrace();
}
mCompletionHandler.complete(object);
}
}
1 change: 1 addition & 0 deletions adapter-flutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
42 changes: 42 additions & 0 deletions adapter-flutter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'com.android.library'
id 'com.github.dcendents.android-maven'
}
group = rootProject.ext.group

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':library')
compileOnly "io.flutter:flutter_embedding_release:1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7"
}
Empty file.
21 changes: 21 additions & 0 deletions adapter-flutter/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pei.platformplugin.flutter;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.pei.platformplugin.flutter.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions adapter-flutter/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pei.platformplugin.flutter">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pei.platformplugin.flutter;

import com.pei.platformplugin.JSONObjectArguments;
import com.pei.platformplugin.MapArguments;
import com.pei.platformplugin.PluginArguments;

import org.json.JSONObject;

import java.util.Map;

import io.flutter.plugin.common.MethodChannel;

public abstract class BaseMethodCallHandler implements MethodChannel.MethodCallHandler {

protected PluginArguments toArguments(Object args) {
PluginArguments arguments;
if (args instanceof Map) {
arguments = new MapArguments((Map<?,?>) args);
} else if (args instanceof JSONObject) {
arguments = new JSONObjectArguments((JSONObject) args);
} else {
throw new ClassCastException();
}
return arguments;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pei.platformplugin.flutter;

import com.pei.platformplugin.PluginCallback;
import com.pei.platformplugin.PluginResult;

import io.flutter.plugin.common.MethodChannel;

public class MethodChannelResultCallbackAdapter implements PluginCallback {

MethodChannel.Result mResult;

public MethodChannelResultCallbackAdapter(MethodChannel.Result result) {
mResult = result;
}

@Override
public void onResult(PluginResult result) {
if (result.isSuccessful()) {
mResult.success(result.getData());
} else {
mResult.error(result.getErrorCode(), result.getErrorMsg(), null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pei.platformplugin.flutter;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
1 change: 1 addition & 0 deletions adapter-react-native/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions adapter-react-native/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'com.android.library'
id 'com.github.dcendents.android-maven'
}
group = rootProject.ext.group

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':library')
}
Empty file.
Binary file added adapter-react-native/libs/react-native-0.55.4.aar
Binary file not shown.
21 changes: 21 additions & 0 deletions adapter-react-native/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pei.platformplugin.reactnative;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.pei.platformplugin.reactnative.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions adapter-react-native/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pei.platformplugin.reactnative">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.pei.platformplugin.reactnative;

import com.facebook.react.bridge.Arguments;
import com.pei.platformplugin.PluginResult;

import java.util.List;
import java.util.Map;

class ReactNativeAdapter {


protected Object convertResult(PluginResult result) {
if (PluginResult.TYPE_MAP.equals(result.getDataType())) {
@SuppressWarnings("unchecked")
Map<String,Object> map = (Map<String, Object>) result.getData();
return Arguments.makeNativeMap(map);
} else if (PluginResult.TYPE_LIST.equals(result.getDataType())) {
@SuppressWarnings("rawtypes")
List list = (List) result.getData();
return Arguments.fromList(list);
} else {
return result.getData();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pei.platformplugin.reactnative;


import com.facebook.react.bridge.Callback;
import com.pei.platformplugin.PluginCallback;
import com.pei.platformplugin.PluginResult;

public class ReactNativeCallbackAdapter extends ReactNativeAdapter implements PluginCallback {

Callback mSuccess;
Callback mFailure;

public ReactNativeCallbackAdapter(Callback success, Callback failure) {
mSuccess = success;
mFailure = failure;
}

@Override
public void onResult(PluginResult result) {
if (result.isSuccessful() && mSuccess != null) {
mSuccess.invoke(convertResult(result));
} else if (!result.isSuccessful() && mFailure != null) {
mFailure.invoke(result.getErrorCode(), result.getErrorMsg());
}
}
}
Loading

0 comments on commit 8d0ab26

Please sign in to comment.