-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
peidongbiao
committed
Jun 21, 2021
1 parent
2d521aa
commit 8d0ab26
Showing
68 changed files
with
1,513 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# PlatformPlugin | ||
为JS、RN、Flutter提供统一平台能力接口。 |
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
platform-plugin-dsbridge/build.gradle → adapter-dsbridge/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
...ridge/src/main/java/com/pei/platformplugin/dsbridge/CompletionHandlerCallbackAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
...-flutter/src/androidTest/java/com/pei/platformplugin/flutter/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
26 changes: 26 additions & 0 deletions
26
adapter-flutter/src/main/java/com/pei/platformplugin/flutter/BaseMethodCallHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...tter/src/main/java/com/pei/platformplugin/flutter/MethodChannelResultCallbackAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
adapter-flutter/src/test/java/com/pei/platformplugin/flutter/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
...tive/src/androidTest/java/com/pei/platformplugin/reactnative/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
25 changes: 25 additions & 0 deletions
25
...ter-react-native/src/main/java/com/pei/platformplugin/reactnative/ReactNativeAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...t-native/src/main/java/com/pei/platformplugin/reactnative/ReactNativeCallbackAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
Oops, something went wrong.