Skip to content

Commit

Permalink
新增jsBridge的demo,演示:jsBridge面向组件的封装及跨进程通信(WebActivity在子进程中)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckybilly committed Sep 16, 2018
1 parent 9bb1660 commit 5e58dd7
Show file tree
Hide file tree
Showing 32 changed files with 729 additions and 25 deletions.
8 changes: 8 additions & 0 deletions demo/src/main/java/com/billy/cc/demo/MainActivity.java
Expand Up @@ -34,6 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
, R.id.componentBGetData
, R.id.componentBLogin
, R.id.componentKt
, R.id.test_sub_process
);
}

Expand Down Expand Up @@ -121,6 +122,13 @@ public void onResult(CC cc, CCResult ccResult) {
.build()
.callAsyncCallbackOnMainThread(printResultCallback);
break;
case R.id.test_sub_process:
CC.obtainBuilder("webComponent")
.setActionName("openUrl")
.setContext(this)
.addParam("url", "file:///android_asset/demo.html")
.build().call();
break;
default:
break;
}
Expand Down
1 change: 0 additions & 1 deletion demo/src/main/java/com/billy/cc/demo/MyApp.java
Expand Up @@ -15,7 +15,6 @@ public void onCreate() {
super.onCreate();
CC.enableVerboseLog(true);
CC.enableDebug(true);
CC.init(this);
CC.enableRemoteCC(true);
}
}
10 changes: 8 additions & 2 deletions demo/src/main/res/layout/activity_main.xml
Expand Up @@ -67,17 +67,23 @@
android:text="@string/async_b_login"
/>
<Button
android:id="@+id/test_lifecycle"
android:id="@+id/test_sub_process"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/life_cycle_relationship"
android:text="@string/call_sub_process"
/>
<Button
android:id="@+id/componentKt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/call_kotlin_component"
/>
<Button
android:id="@+id/test_lifecycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/life_cycle_relationship"
/>
</com.google.android.flexbox.FlexboxLayout>
</ScrollView>

Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/values-zh-rCN/strings.xml
Expand Up @@ -17,4 +17,5 @@
<string name="life_cycle_relationship">(Activity/Fragment)生命周期关联,登录AOP</string>
<string name="call_fragment_method">与跨组件的fragment对象通信</string>
<string name="call_kotlin_component">调用kotlin组件</string>
<string name="call_sub_process">调用子进程</string>
</resources>
1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Expand Up @@ -17,5 +17,6 @@
<string name="life_cycle_relationship">(Activity/Fragment) lifecycle with login AOP</string>
<string name="call_fragment_method">send message to fragment</string>
<string name="call_kotlin_component">kotlin</string>
<string name="call_sub_process">call sub process</string>

</resources>
4 changes: 1 addition & 3 deletions demo_component_b/src/main/AndroidManifest.xml
Expand Up @@ -3,8 +3,6 @@

<application>
<activity android:name="com.billy.cc.demo.component.b.ActivityB" />
<activity android:name="com.billy.cc.demo.component.b.LoginActivity"
android:process=":processB"
/>
<activity android:name="com.billy.cc.demo.component.b.LoginActivity"/>
</application>
</manifest>
4 changes: 1 addition & 3 deletions demo_component_b/src/main/debug/AndroidManifest.xml
Expand Up @@ -15,8 +15,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.billy.cc.demo.component.b.LoginActivity"
android:process=":processB"
/>
<activity android:name="com.billy.cc.demo.component.b.LoginActivity" />
</application>
</manifest>

This file was deleted.

Expand Up @@ -3,7 +3,6 @@
import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.IComponent;
import com.billy.cc.core.component.annotation.SubProcess;
import com.billy.cc.demo.component.b.processor.IActionProcessor;

import java.util.HashMap;
Expand All @@ -18,7 +17,7 @@
* 2. 在普通方法中注册: 可以自定义调用时机
* 本类示例的是第2种方式,在onCall方法中注册,在组件第一次被调用时才注册,类似于懒加载
*
* 自定义cc-settings.gradle, 在autoregister.registerInfo中添加配置,例如(cc-settings-demo-b.gradle):
* 自定义cc-settings.gradle, 在autoregister.registerInfo中添加配置,例如(cc-settings-demo.gradle):
*
autoregister {
registerInfo = [
Expand All @@ -38,7 +37,6 @@
* @author billy.qi
* @since 17/11/20 21:00
*/
@SubProcess(name = ":processB")
public class ComponentB implements IComponent {

private AtomicBoolean initialized = new AtomicBoolean(false);
Expand Down
@@ -0,0 +1,30 @@
package com.billy.cc.demo.component.b.processor;

import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.demo.component.b.Global;


/**
* 获取当前登录用户信息
* @author billy.qi
*/
public class GetLoginUserProcessor implements IActionProcessor {

@Override
public String getActionName() {
return "getLoginUser";
}

@Override
public boolean onActionCall(CC cc) {
if (Global.loginUser != null) {
//already login, return username
CCResult result = CCResult.success(Global.KEY_USER, Global.loginUser);
CC.sendCCResult(cc.getCallId(), result);
} else {
CC.sendCCResult(cc.getCallId(), CCResult.error("no login user"));
}
return false;
}
}
@@ -0,0 +1,25 @@
package com.billy.cc.demo.component.b.processor;

import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.demo.component.b.Global;


/**
* 退出登录
* @author billy.qi
*/
public class LogoutProcessor implements IActionProcessor {

@Override
public String getActionName() {
return "logout";
}

@Override
public boolean onActionCall(CC cc) {
Global.loginUser = null;
CC.sendCCResult(cc.getCallId(), CCResult.success());
return false;
}
}
1 change: 1 addition & 0 deletions demo_component_jsbridge/.gitignore
@@ -0,0 +1 @@
/build
34 changes: 34 additions & 0 deletions demo_component_jsbridge/build.gradle
@@ -0,0 +1,34 @@
apply from: rootProject.file("cc-settings-demo.gradle")

android {
compileSdkVersion rootProject.compileVersion
buildToolsVersion rootProject.buildVersion

defaultConfig {
minSdkVersion 9 // support v7 minSdkVersion is 9
targetSdkVersion rootProject.compileVersion
versionCode 1
versionName "1.0"


}
resourcePrefix "demo_jsbridge_"

buildTypes {
release {
postprocessing {
removeUnusedCode false
removeUnusedResources false
obfuscate false
optimizeCode false
proguardFile 'proguard-rules.pro'
}
}
}

}

dependencies {
implementation "com.android.support:appcompat-v7:${rootProject.supportVersion}"
api 'com.github.lzyzsd:jsbridge:1.0.4'
}
21 changes: 21 additions & 0 deletions demo_component_jsbridge/proguard-rules.pro
@@ -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
7 changes: 7 additions & 0 deletions demo_component_jsbridge/src/main/AndroidManifest.xml
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.billy.cc.demo.component.jsbridge">

<application>
<activity android:name=".WebActivity" android:process=":web" />
</application>
</manifest>

0 comments on commit 5e58dd7

Please sign in to comment.