stacks = new LinkedList<>();
14 |
15 | public static void add(Activity activity) {
16 | if (!stacks.contains(activity)) {
17 | stacks.add(activity);
18 | }
19 | }
20 |
21 | public static void remove(Activity activity) {
22 | if (stacks.contains(activity)) {
23 | stacks.remove(activity);
24 | }
25 | }
26 |
27 | public static Activity top() {
28 | return stacks.getLast();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/HostApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo;
2 |
3 | import android.app.Activity;
4 | import android.app.ProgressDialog;
5 | import android.net.Uri;
6 |
7 | import com.alibaba.fastjson.JSON;
8 | import com.lzh.compiler.parceler.Parceler;
9 | import com.lzh.compiler.parceler.annotation.FastJsonConverter;
10 | import com.lzh.nonview.router.Router;
11 | import com.lzh.nonview.router.RouterConfiguration;
12 | import com.lzh.nonview.router.anno.RouteConfig;
13 | import com.lzh.nonview.router.host.RouterHostService;
14 | import com.lzh.replugindemo.verify.RePluginVerification;
15 | import com.lzh.router.RouterRuleCreator;
16 | import com.lzh.router.replugin.core.IPluginCallback;
17 | import com.lzh.router.replugin.host.HostRouterConfiguration;
18 | import com.lzh.router.replugin.update.IUpdateCombine;
19 | import com.lzh.router.replugin.update.UpdateRePluginCallbacks;
20 | import com.qihoo360.replugin.RePluginApplication;
21 | import com.qihoo360.replugin.RePluginCallbacks;
22 | import com.qihoo360.replugin.RePluginConfig;
23 |
24 | import org.lzh.framework.updatepluginlib.UpdateConfig;
25 | import org.lzh.framework.updatepluginlib.base.UpdateChecker;
26 | import org.lzh.framework.updatepluginlib.base.UpdateParser;
27 | import org.lzh.framework.updatepluginlib.base.UpdateStrategy;
28 | import org.lzh.framework.updatepluginlib.model.CheckEntity;
29 | import org.lzh.framework.updatepluginlib.model.Update;
30 |
31 | // 指定生成路由的baseUrl。此baseUrl会与使用RouteRule所指定的path所组合。形成一个完整的路由地址。
32 | // 生成的路由表。参考下方添加路由规则的RouterRuleCreator类。
33 | @RouteConfig(baseUrl = "host://")
34 | public class HostApplication extends RePluginApplication{
35 |
36 | @Override
37 | public void onCreate() {
38 | super.onCreate();
39 |
40 | // 启动远程路由前。加入安全验证器。
41 | RouterHostService.setVerify(new RePluginVerification());
42 |
43 | HostRouterConfiguration.init("com.lzh.replugindemo", this);
44 | HostRouterConfiguration.get().setCallback(new PluginCallback());
45 | // 添加路由规则。
46 | RouterConfiguration.get().addRouteCreator(new RouterRuleCreator());
47 | Parceler.setDefaultConverter(FastJsonConverter.class);
48 |
49 | Router.DEBUG = true;
50 | }
51 |
52 | @Override
53 | protected RePluginConfig createConfig() {
54 | RePluginConfig config = super.createConfig();
55 | config.setUseHostClassIfNotFound(true);
56 | return config;
57 | }
58 |
59 | @Override
60 | protected RePluginCallbacks createCallbacks() {
61 | return new UpdateRePluginCallbacks(this,
62 | // 设置UpdateConfig。用于进行远程plugin更新。
63 | UpdateConfig.createConfig()
64 | .setUpdateChecker(new PluginChecker())
65 | .setUpdateParser(new JsonParser())
66 | .setUpdateStrategy(new PluginStrategy()),
67 | // 设置远程插件更新接口api组装。
68 | new HostUpdateCombine());
69 | }
70 |
71 | /**
72 | * 插件接口返回数据json解析器。在此解析出接口api更新信息。并下载。
73 | */
74 | private static class JsonParser implements UpdateParser {
75 | @Override
76 | public Update parse(String httpResponse) throws Exception {
77 |
78 | return JSON.parseObject(httpResponse, Update.class);
79 | }
80 | }
81 |
82 | /**
83 | * 对插件api通过上方JsonParser解析后的更新实体类进行检查。检查是否需要进行更新下载安装。
84 | */
85 | private static class PluginChecker implements UpdateChecker {
86 |
87 | @Override
88 | public boolean check(Update update) throws Exception {
89 | return true;
90 | }
91 | }
92 |
93 | /**
94 | * 插件的更新通知策略:显示检查到有插件可用时的弹窗以及下载进度条。
95 | */
96 | private static class PluginStrategy implements UpdateStrategy {
97 | @Override
98 | public boolean isShowUpdateDialog(Update update) {
99 | return true;
100 | }
101 |
102 | @Override
103 | public boolean isAutoInstall() {
104 | return true;
105 | }
106 |
107 | @Override
108 | public boolean isShowDownloadDialog() {
109 | return true;
110 | }
111 | }
112 |
113 | /**
114 | * 根据插件名组装出真正的插件api地址。
115 | */
116 | private static class HostUpdateCombine implements IUpdateCombine {
117 |
118 | @Override
119 | public CheckEntity combine(String alias) {
120 | return new CheckEntity().setUrl("https://raw.githubusercontent.com/JumeiRdGroup/Router/master/demos/RePluginDemo/mocked/api/" + alias + ".json");
121 | }
122 | }
123 |
124 | private static class PluginCallback implements IPluginCallback {
125 |
126 | ProgressDialog dialog;
127 |
128 | @Override
129 | public void onInvalidUri(Uri uri) {
130 | // 当uri为非法
131 | }
132 |
133 | @Override
134 | public void notFound(Uri uri, String alias) {
135 |
136 | }
137 |
138 | @Override
139 | public void onResume(Uri uri) {
140 |
141 | }
142 |
143 | @Override
144 | public void onStartLoading(Uri uri, String alias) {
145 | if (dialog != null) {
146 | return;
147 | }
148 | Activity top = ActivityStackHelper.top();
149 | dialog = new ProgressDialog(top);
150 | dialog.setTitle("加载插件" + alias + "中...");
151 | dialog.show();
152 | }
153 |
154 | @Override
155 | public void onLoadedCompleted(Uri uri, String alias) {
156 | if (dialog == null) {
157 | return;
158 | }
159 |
160 | dialog.dismiss();
161 | dialog = null;
162 | }
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | import com.lzh.nonview.router.Router;
11 | import com.lzh.nonview.router.RouterConfiguration;
12 | import com.lzh.nonview.router.activityresult.ActivityResultCallback;
13 | import com.lzh.nonview.router.anno.RouterRule;
14 |
15 | // 因为指定了baseUrl。 所以这里会使用baseUrl做组合。
16 | @RouterRule("main")
17 | public class MainActivity extends Activity {
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | ActivityStackHelper.add(this);
23 | setContentView(R.layout.activity_main);
24 | }
25 |
26 | public void onClick(View v) {
27 | Router.create(((TextView)v).getText().toString())
28 | .resultCallback(new ActivityResultCallback() {
29 | @Override
30 | public void onResult(int resultCode, Intent data) {
31 | Toast.makeText(MainActivity.this, "Host MainActivity Receive result" , Toast.LENGTH_SHORT).show();
32 | }
33 | })
34 | .open(this);
35 | }
36 |
37 | @Override
38 | protected void onDestroy() {
39 | super.onDestroy();
40 | ActivityStackHelper.remove(this);
41 | }
42 |
43 | @Override
44 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
45 | super.onActivityResult(requestCode, resultCode, data);
46 | RouterConfiguration.get().dispatchActivityResult(this, requestCode, resultCode, data);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/action/HostAction.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo.action;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import com.lzh.nonview.router.anno.RouterRule;
8 | import com.lzh.nonview.router.route.ActionSupport;
9 |
10 | /**
11 | * host的测试动作路由
12 | */
13 | @RouterRule("action")
14 | public class HostAction extends ActionSupport {
15 | @Override
16 | public void onRouteTrigger(Context context, Bundle bundle) {
17 | Toast.makeText(context, "Host Action invoked!", Toast.LENGTH_SHORT).show();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/action/UninstallAction.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo.action;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import com.lzh.compiler.parceler.annotation.Arg;
8 | import com.lzh.nonview.router.anno.RouterRule;
9 | import com.lzh.nonview.router.route.ActionSupport;
10 | import com.qihoo360.replugin.RePlugin;
11 |
12 | /**
13 | * 用于卸载指定外置插件的动作路由。
14 | */
15 | @RouterRule("uninstall")
16 | public class UninstallAction extends ActionSupport {
17 |
18 | @Arg
19 | String plugin;
20 |
21 | @Override
22 | public void onRouteTrigger(Context context, Bundle bundle) {
23 | if (RePlugin.isPluginInstalled(plugin)) {
24 | RePlugin.uninstall(plugin);
25 | Toast.makeText(context, "卸载插件" + plugin + "完成,请重启app生效", Toast.LENGTH_SHORT).show();
26 | } else {
27 | Toast.makeText(context, "当前无此插件:" + plugin, Toast.LENGTH_SHORT).show();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/pojo/User.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo.pojo;
2 |
3 | import java.io.Serializable;
4 |
5 | public class User implements Serializable{
6 | private String name;
7 | private int age;
8 |
9 | public User(String name, int age) {
10 | this.name = name;
11 | this.age = age;
12 | }
13 |
14 | public String getName() {
15 | return name;
16 | }
17 |
18 | public void setName(String name) {
19 | this.name = name;
20 | }
21 |
22 | public int getAge() {
23 | return age;
24 | }
25 |
26 | public void setAge(int age) {
27 | this.age = age;
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return "User{" +
33 | "name='" + name + '\'' +
34 | ", age=" + age +
35 | '}';
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/replugin/HostBinderGetter.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo.replugin;
2 |
3 | import android.os.IBinder;
4 | import android.os.RemoteException;
5 |
6 | import com.qihoo360.replugin.IBinderGetter;
7 |
8 | public class HostBinderGetter implements IBinderGetter {
9 |
10 | @Override
11 | public IBinder get() throws RemoteException {
12 | return null;
13 | }
14 |
15 | @Override
16 | public IBinder asBinder() {
17 | return null;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/java/com/lzh/replugindemo/verify/RePluginVerification.java:
--------------------------------------------------------------------------------
1 | package com.lzh.replugindemo.verify;
2 |
3 | import android.content.Context;
4 | import android.os.Binder;
5 | import android.os.Process;
6 |
7 | import com.lzh.nonview.router.host.RemoteVerify;
8 |
9 | /**
10 | * Created by haoge on 2017/8/17.
11 | */
12 |
13 | public class RePluginVerification implements RemoteVerify{
14 |
15 | @Override
16 | public boolean verify(Context context) throws Exception {
17 | return Process.myUid() == Binder.getCallingUid();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/anim/anim_fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/anim/anim_fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
44 |
49 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RePluginDemo
3 |
4 |
--------------------------------------------------------------------------------
/RePluginDemo/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | apply from: './version.gradle'
3 | buildscript {
4 | ext.RePlugin_version = "2.2.4"
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.3.3'
10 | classpath "com.qihoo360.replugin:replugin-host-gradle:$RePlugin_version"
11 | classpath "com.qihoo360.replugin:replugin-plugin-gradle:$RePlugin_version"
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/RePluginDemo/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/RePluginDemo/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/RePluginDemo/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 03 21:00:49 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/RePluginDemo/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/RePluginDemo/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/RePluginDemo/install.sh:
--------------------------------------------------------------------------------
1 | ./gradlew clean assembleDebug
2 | echo "build successful"
3 | rm ./app/src/main/assets/plugins/plugina.jar
4 | rm ./app/src/main/assets/plugins/usercenter.jar
5 | rm ./mocked/apk/remote.apk
6 | echo "delete last build apk successful"
7 | cp ./plugina/build/outputs/apk/plugina-debug.apk ./app/src/main/assets/plugins/plugina.jar
8 | cp ./usercenter/build/outputs/apk/usercenter-debug.apk ./app/src/main/assets/plugins/usercenter.jar
9 | cp ./remote/build/outputs/apk/remote-debug.apk ./mocked/apk/remote.apk
10 | echo "all successful"
--------------------------------------------------------------------------------
/RePluginDemo/installRelease.sh:
--------------------------------------------------------------------------------
1 | ./gradlew clean assembleRelease
2 | echo "build successful"
3 | rm ./app/src/main/assets/plugins/plugina.jar
4 | rm ./app/src/main/assets/plugins/usercenter.jar
5 | echo "delete last build apk successful"
6 | cp ./plugina/build/outputs/apk/plugina-release.apk ./app/src/main/assets/plugins/plugina.jar
7 | cp ./usercenter/build/outputs/apk/usercenter-release.apk ./app/src/main/assets/plugins/usercenter.jar
8 | echo "all successful"
--------------------------------------------------------------------------------
/RePluginDemo/mocked/api/remote.json:
--------------------------------------------------------------------------------
1 | {
2 | "updateContent": "需要下载远程插件,预计将耗费大约1M的流量,是否下载?",
3 | "updateUrl": "https://raw.githubusercontent.com/JumeiRdGroup/Router/master/demos/RePluginDemo/mocked/apk/remote.apk",
4 | "versionCode": 1,
5 | "versionName": "1.0"
6 | }
--------------------------------------------------------------------------------
/RePluginDemo/mocked/apk/remote.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/mocked/apk/remote.apk
--------------------------------------------------------------------------------
/RePluginDemo/plugina/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.lzh.plugina"
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | apply plugin: 'replugin-plugin-gradle'
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | if (useLocal) {
30 | compile project(':plugin')
31 | } else {
32 | compile "com.github.yjfnypeu.Router-RePlugin:plugin:${Router_RePlugin_version}"
33 | }
34 |
35 | annotationProcessor "com.github.yjfnypeu.Router:router-compiler:${ROUTER_VERSION}"
36 | annotationProcessor "com.jakewharton:butterknife-compiler:${ButterKnife_version}"
37 | compile "com.jakewharton:butterknife:${ButterKnife_version}"
38 |
39 | compile 'com.android.support:support-v4:25.3.1'// 提供用于兼容ActivityLauncher编写
40 | testCompile 'junit:junit:4.12'
41 | }
42 |
43 | repluginPluginConfig {
44 | appModule = ':app'
45 | //插件名
46 | pluginName = "plugina"
47 | //宿主app的包名
48 | hostApplicationId = "com.lzh.replugindemo"
49 | //宿主app的启动activity
50 | hostAppLauncherActivity = "com.lzh.replugindemo.MainActivity"
51 | }
--------------------------------------------------------------------------------
/RePluginDemo/plugina/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/java/com/lzh/plugina/PluginA.java:
--------------------------------------------------------------------------------
1 | package com.lzh.plugina;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.widget.Button;
7 | import android.widget.Toast;
8 |
9 | import com.lzh.nonview.router.Router;
10 | import com.lzh.nonview.router.RouterConfiguration;
11 | import com.lzh.nonview.router.activityresult.ActivityResultCallback;
12 | import com.lzh.nonview.router.anno.RouterRule;
13 |
14 | import butterknife.ButterKnife;
15 | import butterknife.OnClick;
16 |
17 | @RouterRule("main")
18 | public class PluginA extends Activity {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_plugin_a);
24 | ButterKnife.bind(this);
25 | }
26 |
27 | @OnClick({R.id.toHost, R.id.toLogin, R.id.triggerActionHost, R.id.triggerActionPluginA, R.id.triggerActionUserCenter})
28 | void click(Button v) {
29 | String url = v.getText().toString();
30 | Router.create(url)
31 | .resultCallback(new ActivityResultCallback() {
32 | @Override
33 | public void onResult(int resultCode, Intent data) {
34 | Toast.makeText(PluginA.this, "Plugin A Receive result" , Toast.LENGTH_SHORT).show();
35 | }
36 | })
37 | .open(this);
38 | }
39 |
40 | @Override
41 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
42 | super.onActivityResult(requestCode, resultCode, data);
43 | RouterConfiguration.get().dispatchActivityResult(this, requestCode, resultCode, data);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/java/com/lzh/plugina/PluginActionA.java:
--------------------------------------------------------------------------------
1 | package com.lzh.plugina;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.widget.Toast;
7 |
8 | import com.lzh.nonview.router.anno.RouterRule;
9 | import com.lzh.nonview.router.route.ActionSupport;
10 |
11 | @RouterRule("action")
12 | public class PluginActionA extends ActionSupport{
13 |
14 | @Override
15 | public void onRouteTrigger(Context context, Bundle bundle) {
16 | Object user = bundle.get("user");
17 | System.out.println("user = " + user);
18 | Toast.makeText(context, "Plugin Action A invoked!", Toast.LENGTH_SHORT).show();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/java/com/lzh/plugina/PluginApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzh.plugina;
2 |
3 | import android.app.Application;
4 |
5 | import com.lzh.nonview.router.RouterConfiguration;
6 | import com.lzh.nonview.router.anno.RouteConfig;
7 | import com.lzh.router.RouterRuleCreator;
8 | import com.lzh.router.replugin.plugin.PluginRouterConfiguration;
9 |
10 | @RouteConfig(baseUrl = "plugina://")
11 | public class PluginApplication extends Application{
12 |
13 | private static final String TAG = "ROUTER";
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 |
18 | PluginRouterConfiguration.init("com.lzh.replugindemo", "plugina", this);
19 | RouterConfiguration.get().addRouteCreator(new RouterRuleCreator());
20 | }
21 | }
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/anim/anim_fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/anim/anim_fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/anim/anim_marquee_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
11 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/anim/anim_marquee_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
11 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/layout/activity_plugin_a.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
32 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/plugina/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PluginA
3 |
4 |
--------------------------------------------------------------------------------
/RePluginDemo/plugina/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.lzh.remote"
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 |
23 | apply plugin: 'replugin-plugin-gradle'
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | if (useLocal) {
28 | compile project(':plugin')
29 | } else {
30 | compile "com.github.yjfnypeu.Router-RePlugin:plugin:${Router_RePlugin_version}"
31 | }
32 |
33 | annotationProcessor "com.github.yjfnypeu.Router:router-compiler:${ROUTER_VERSION}"
34 | annotationProcessor "com.jakewharton:butterknife-compiler:${ButterKnife_version}"
35 | // compile project(':stub')
36 | compile "com.github.yjfnypeu.Parceler:api:${PARCELER_VERSION}"
37 | compile "com.jakewharton:butterknife:${ButterKnife_version}"
38 | }
39 |
40 | repluginPluginConfig {
41 | appModule = ':app'
42 | //插件名
43 | pluginName = "remote"
44 | //宿主app的包名
45 | hostApplicationId = "com.lzh.replugindemo"
46 | //宿主app的启动activity
47 | hostAppLauncherActivity = "com.lzh.replugindemo.MainActivity"
48 | }
--------------------------------------------------------------------------------
/RePluginDemo/remote/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/java/com/lzh/remote/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.lzh.remote;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import com.lzh.nonview.router.Router;
9 | import com.lzh.nonview.router.anno.RouterRule;
10 |
11 | @RouterRule("main")
12 | public class MainActivity extends Activity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | }
19 |
20 | public void onClick(View view) {
21 | Button btn = (Button) view;
22 | Router.create(btn.getText().toString()).open(this);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/java/com/lzh/remote/RemoteApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzh.remote;
2 |
3 | import android.app.Application;
4 |
5 | import com.lzh.nonview.router.RouterConfiguration;
6 | import com.lzh.nonview.router.anno.RouteConfig;
7 | import com.lzh.router.RouterRuleCreator;
8 | import com.lzh.router.replugin.plugin.PluginRouterConfiguration;
9 |
10 | @RouteConfig(baseUrl = "remote://")
11 | public class RemoteApplication extends Application {
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | PluginRouterConfiguration.init("com.lzh.replugindemo", "remote", this);
17 | RouterConfiguration.get().addRouteCreator(new RouterRuleCreator());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/remote/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Remote
3 |
4 |
--------------------------------------------------------------------------------
/RePluginDemo/remote/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':usercenter', ':remote'
2 | include ':plugina'
3 |
4 | // 添加外部库
5 | def externalModules = [
6 | ':core',
7 | ':plugin',
8 | ':host'
9 | ] as String[]
10 |
11 | include externalModules
12 | externalModules.each {
13 | project(it).projectDir = new File("../${it.substring(1)}")
14 | }
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.lzh.usercenetr"
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | apply plugin: 'replugin-plugin-gradle'
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | compile "com.github.yjfnypeu.Parceler:api:${PARCELER_VERSION}"
27 | annotationProcessor "com.github.yjfnypeu.Router:router-compiler:${ROUTER_VERSION}"
28 | annotationProcessor "com.jakewharton:butterknife-compiler:${ButterKnife_version}"
29 |
30 | compile "com.jakewharton:butterknife:${ButterKnife_version}"
31 | testCompile 'junit:junit:4.12'
32 |
33 | if (useLocal) {
34 | compile project(':plugin')
35 | } else {
36 | compile "com.github.yjfnypeu.Router-RePlugin:plugin:${Router_RePlugin_version}"
37 | }
38 | }
39 |
40 |
41 | repluginPluginConfig {
42 | appModule = ':app'
43 | //插件名
44 | pluginName = "usercenter"
45 | //宿主app的包名
46 | hostApplicationId = "com.lzh.replugindemo"
47 | //宿主app的启动activity
48 | hostAppLauncherActivity = "com.lzh.replugindemo.MainActivity"
49 | }
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/java/com/lzh/usercenetr/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.lzh.usercenetr;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.EditText;
6 |
7 | import com.lzh.compiler.parceler.Parceler;
8 | import com.lzh.compiler.parceler.annotation.Arg;
9 | import com.lzh.nonview.router.anno.RouterRule;
10 |
11 | import butterknife.BindView;
12 | import butterknife.ButterKnife;
13 | import butterknife.OnClick;
14 |
15 | @RouterRule("login")
16 | public class LoginActivity extends Activity {
17 |
18 | @Arg
19 | String username;
20 | @Arg
21 | String password;
22 |
23 | @BindView(R.id.username)
24 | EditText name;
25 | @BindView(R.id.password)
26 | EditText word;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_login);
32 | Parceler.toEntity(this, getIntent());
33 | ButterKnife.bind(this);
34 | name.setText(username);
35 | word.setText(password);
36 | }
37 |
38 | @OnClick(R.id.login)
39 | void login() {
40 | finish();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/java/com/lzh/usercenetr/UCApplication.java:
--------------------------------------------------------------------------------
1 | package com.lzh.usercenetr;
2 |
3 | import android.app.Application;
4 |
5 | import com.lzh.nonview.router.RouterConfiguration;
6 | import com.lzh.nonview.router.anno.RouteConfig;
7 | import com.lzh.router.RouterRuleCreator;
8 | import com.lzh.router.replugin.plugin.PluginRouterConfiguration;
9 |
10 | @RouteConfig(baseUrl = "usercenter://")
11 | public class UCApplication extends Application {
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | RouterConfiguration.get().addRouteCreator(new RouterRuleCreator());
17 | PluginRouterConfiguration.init("com.lzh.replugindemo", "usercenter", this);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/java/com/lzh/usercenetr/UserCenterAction.java:
--------------------------------------------------------------------------------
1 | package com.lzh.usercenetr;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.widget.Toast;
6 |
7 | import com.lzh.nonview.router.anno.RouterRule;
8 | import com.lzh.nonview.router.route.ActionSupport;
9 |
10 | @RouterRule("action")
11 | public class UserCenterAction extends ActionSupport{
12 | @Override
13 | public void onRouteTrigger(Context context, Bundle bundle) {
14 | Toast.makeText(context, "UserCenter Action invoked", Toast.LENGTH_SHORT).show();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
24 |
25 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/RePluginDemo/usercenter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | UserCenetr
3 |
4 |
--------------------------------------------------------------------------------
/RePluginDemo/usercenter/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RePluginDemo/version.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | ROUTER_VERSION="2.7.2"
3 | PARCELER_VERSION="1.3.9"
4 | ButterKnife_version = "8.8.1"
5 | UpdatePlugin_version = "2.9.1"
6 | RePlugin_version = "2.2.4"
7 | Router_RePlugin_version = '0.8.0'
8 | useLocal = true // 指定当前使用的Router-RePlugin库。是使用本地的还是远程仓库的。
9 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | maven { url "https://jitpack.io" }
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
26 | apply from: 'RePluginDemo/version.gradle'
--------------------------------------------------------------------------------
/core/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/core/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | provided "com.qihoo360.replugin:replugin-plugin-lib:${RePlugin_version}"
26 | provided "com.github.yjfnypeu.Parceler:api:${PARCELER_VERSION}"
27 | provided "com.github.yjfnypeu.Router:router-api:${ROUTER_VERSION}"
28 | compile 'com.alibaba:fastjson:1.1.61.android'
29 | }
30 |
31 | apply from: '../javadoc.gradle'
--------------------------------------------------------------------------------
/core/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/IPluginCallback.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | import android.net.Uri;
4 |
5 | /**
6 | * 插件的回调。用于在对插件路由的接入过程中。出现的问题进行通知。
7 | * @author haoge
8 | */
9 | public interface IPluginCallback {
10 |
11 | /**
12 | * 当此uri所代表的路由为无效时。回调通知到此.
13 | *
14 | * 若通知到此,则代表未能通过此uri使用{@link IUriConverter}转换器获取到对应的插件别名进行启动
15 | *
16 | * @param uri uri
17 | */
18 | void onInvalidUri(Uri uri);
19 |
20 | /**
21 | * 当此uri所代表的路由未找到时且此uri所对应的插件也启动了的情况下。回调通知到此。
22 | *
23 | *
若通知到此。则代表此uri尚未被定义。可选择在此提示用于升级新版。
24 | *
25 | * @param uri uri
26 | * @param alias 插件别名。
27 | */
28 | void notFound(Uri uri, String alias);
29 |
30 | /**
31 | * 当此uri对应的插件被加载成功。且成功恢复时。回调通知到此。此回调运行于主线程中。
32 | * @param uri 恢复的路由uri
33 | */
34 | void onResume(Uri uri);
35 |
36 | /**
37 | * 当未匹配到此uri对应的路由规则且此uri所对应的插件别名尚未运行(即插件未运行),则启动RePlugin的加载插件功能,此为开始加载指定插件时的回调。
38 | *
39 | *
40 | * 此回调运行于主线程,可在此针对插件首次加载时,提供进度条通知。避免UI无反应导致用户多次点击
41 | *
42 | *
43 | * @param uri uri
44 | * @param alias 插件别名。
45 | */
46 | void onStartLoading(Uri uri, String alias);
47 |
48 | /**
49 | * 当加载指定插件完成后的回调,此处不在意是否插件加载成功。只是加载完成状态。
50 | *
51 | *
52 | * 此回调运行于主线程,可在此对{@link #onStartLoading(Uri, String)}中所做操作做个闭合,调用了{@link #onStartLoading(Uri, String)}的必定会调用此方法。
53 | *
54 | *
55 | * @param uri uri
56 | * @param alias 插件别名。
57 | */
58 | void onLoadedCompleted(Uri uri, String alias);
59 | }
60 |
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/IUriConverter.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | import android.net.Uri;
4 |
5 | /**
6 | * 当uri所对应的路由未找到时。对uri进行转换。转换为对应的需要加载的插件别名。提供给{@link RePluginRouteCallback} 做插件接入。
7 | *
8 | * @see IUriConverter#internal
9 | * Created by haoge on 2017/8/24.
10 | */
11 | public interface IUriConverter {
12 |
13 | /**
14 | * 将从uri中获取出正确的插件别名。或者返回null,代表此uri无效。
15 | * @param uri 未找到的路由uri
16 | * @return 根据uri转换后的插件别名。或者当别名为不支持时。返回null。
17 | */
18 | String transform(Uri uri);
19 |
20 | /**
21 | * 默认的插件路由规则转换器。此转换器的规则为:使用路由uri的scheme作为各自插件的别名。
22 | */
23 | IUriConverter internal = new IUriConverter() {
24 | @Override
25 | public String transform(Uri uri) {
26 | return uri.getScheme();
27 | }
28 | };
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/Keys.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | /**
4 | * 部分使用的Key值。统一存放
5 | * @author haoge on 2018/5/21
6 | */
7 | public final class Keys {
8 | public static final String KEY_RESUME_CONTEXT_INDEX = "RePlugin-Router:KEY_RESUME_CONTEXT_INDEX";
9 | public static final String KEY_URI_INDEX = "RePlugin-Router:KEY_URI_INDEX";
10 | public static final String KEY_EXTRAS_INDEX = "RePlugin-Router:KEY_EXTRAS_INDEX";
11 |
12 | public static final String KEY_EXTRAS = "RePlugin-Router:KEY_EXTRAS";
13 | public static final String KEY_URI = "RePlugin-Router:KEY_URI";
14 |
15 | public static final String KEY_ACTION = "RePlugin-Router:KEY_ACTION";
16 | }
17 |
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/RePluginRouteCallback.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.os.Handler;
9 | import android.os.Looper;
10 | import android.text.TextUtils;
11 | import android.util.SparseArray;
12 |
13 | import com.lzh.nonview.router.RouterConfiguration;
14 | import com.lzh.nonview.router.exception.NotFoundException;
15 | import com.lzh.nonview.router.extras.RouteBundleExtras;
16 | import com.lzh.nonview.router.module.RouteRule;
17 | import com.lzh.nonview.router.route.RouteCallback;
18 | import com.lzh.nonview.router.tools.CacheStore;
19 | import com.qihoo360.replugin.RePlugin;
20 |
21 | import java.util.concurrent.ExecutorService;
22 | import java.util.concurrent.Executors;
23 |
24 | /**
25 | * 针对RePlugin框架所配置的路由回调。将在此进行连接Router-RePlugin配置:
26 | *
27 | * Created by haoge on 2017/8/24.
28 | */
29 | public final class RePluginRouteCallback implements RouteCallback{
30 |
31 | private ExecutorService pool = Executors.newSingleThreadExecutor();
32 | private static RePluginRouteCallback instance = new RePluginRouteCallback();
33 | private String selfAlias;
34 | private RePluginRouteCallback() {}
35 | public static RePluginRouteCallback get() {
36 | return instance;
37 | }
38 |
39 | private IUriConverter converter = IUriConverter.internal;
40 | private IPluginCallback callback;
41 |
42 | private RouteCallback routeCallback;
43 |
44 | public void setAlias(String alias) {
45 | if (!TextUtils.isEmpty(alias)) {
46 | this.selfAlias = alias;
47 | }
48 | }
49 |
50 | public void setConverter(IUriConverter converter) {
51 | if (converter != null) {
52 | this.converter = converter;
53 | }
54 | }
55 |
56 | public void setCallback(IPluginCallback callback) {
57 | this.callback = callback;
58 | }
59 |
60 | public void setRouteCallback(RouteCallback routeCallback) {
61 | this.routeCallback = routeCallback;
62 | }
63 |
64 | @Override
65 | public void notFound(Uri uri, NotFoundException e) {
66 | if (routeCallback != null) {
67 | routeCallback.notFound(uri, e);
68 | }
69 |
70 | String alias = converter.transform(uri);
71 | if (TextUtils.isEmpty(alias)) {
72 | // 表示此uri非法。不处理
73 | if (callback != null) {
74 | callback.onInvalidUri(uri);
75 | }
76 | return;
77 | }
78 |
79 | // 用于判断此别名所代表的插件路由
80 | if (RouterConfiguration.get().isRegister(alias)) {
81 | // 当插件已被注册过。
82 | if (callback != null) {
83 | callback.notFound(uri, alias);
84 | }
85 | return;
86 | }
87 |
88 | // 将中转任务放入子线程中进行启动。避免阻塞UI线程。
89 | pool.execute(new StartBridgeTask(RouterConfiguration.get().restorContext(uri), alias, uri,RouterConfiguration.get().restoreExtras(uri)));
90 |
91 | }
92 |
93 | @Override
94 | public void onOpenSuccess(Uri uri, RouteRule rule) {
95 | if (routeCallback != null) {
96 | routeCallback.onOpenSuccess(uri, rule);
97 | }
98 | }
99 |
100 | @Override
101 | public void onOpenFailed(Uri uri, Throwable e) {
102 | if (routeCallback != null) {
103 | routeCallback.onOpenFailed(uri, e);
104 | } else {
105 | e.printStackTrace();
106 | }
107 | }
108 |
109 | public IPluginCallback getCallback() {
110 | return callback;
111 | }
112 |
113 | private static class StartBridgeTask implements Runnable {
114 | private static Handler main = new Handler(Looper.getMainLooper());
115 | Context context;
116 | String alias;
117 | Uri uri;
118 | RouteBundleExtras extras;
119 |
120 | StartBridgeTask(Context context, String alias, Uri uri, RouteBundleExtras extras) {
121 | this.context = context;
122 | this.alias = alias;
123 | this.uri = uri;
124 | this.extras = extras;
125 | }
126 |
127 | @Override
128 | public void run() {
129 | final IPluginCallback callback = RePluginRouteCallback.get().getCallback();
130 | main.post(new Runnable() {
131 | @Override
132 | public void run() {
133 | if (callback != null) {
134 | callback.onStartLoading(uri, alias);
135 | }
136 | }
137 | });
138 |
139 | // 请求加载插件并启动中间桥接页面.便于加载插件成功后恢复路由。
140 | Intent intent = new Intent();
141 | intent.setComponent(new ComponentName(alias, RouterBridgeActivity.class.getCanonicalName()));
142 | if (RePlugin.isPluginInstalled(alias)) {
143 | // 对于已安装、尚未启动的插件。将待启动的路由相关信息存入临时缓存中。待插件启动成功后通知回当前插件。进行恢复
144 | // 此种方式能最大程度的保留路由启动信息。但是因为有额外的缓存,所以只适用于此种已安装的插件。避免内存泄漏
145 | String selfAlias = RePluginRouteCallback.instance.selfAlias;
146 | intent.putExtra(Keys.KEY_ACTION, RouterResumeReceiver.obtainAction(selfAlias, TextUtils.isEmpty(selfAlias)));
147 | intent.putExtra(Keys.KEY_RESUME_CONTEXT_INDEX, CacheStore.get().put(context));
148 | intent.putExtra(Keys.KEY_URI_INDEX, CacheStore.get().put(uri));
149 | intent.putExtra(Keys.KEY_EXTRAS_INDEX, CacheStore.get().put(extras));
150 | } else {
151 | // 对于未安装的远程插件。传递路由信息。待下载完成、启动成功后直接进行恢复
152 | // 此种方式将会丢失路由回调、路由拦截器等启动信息。但是没有内存泄漏。适用于远程插件。
153 | intent.putExtra(Keys.KEY_URI, uri);
154 | intent.putExtra(Keys.KEY_EXTRAS, RouterResumeReceiver.copy(extras));
155 | }
156 | if (!(context instanceof Activity)) {
157 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
158 | }
159 | RePlugin.startActivity(context, intent);
160 |
161 | main.post(new Runnable() {
162 | @Override
163 | public void run() {
164 | if (callback != null) {
165 | callback.onLoadedCompleted(uri, alias);
166 | }
167 | }
168 | });
169 |
170 | main.postDelayed(new Runnable() {
171 | @Override
172 | public void run() {
173 | // 10秒后进行
174 | }
175 | }, 10 * 1000 * 1000);
176 | }
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/RouterBridgeActivity.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 |
8 | import com.lzh.nonview.router.Router;
9 | import com.lzh.nonview.router.extras.RouteBundleExtras;
10 |
11 | /**
12 | * 插件间跳转的中间桥接页面。当Router启动一个未被加载的插件的路由时。在加载插件成功后。将会跳转到此页面并恢复之前启动的路由。
13 | *
14 | * 外部不应该直接跳转至此页面。此页面跳转处应只存在于{@link RePluginRouteCallback}中
15 | */
16 | public class RouterBridgeActivity extends Activity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | Intent intent = getIntent();
22 |
23 | if (intent.hasExtra(Keys.KEY_URI)) {
24 | // 当含有URI值时。直接恢复路由
25 | Uri uri = intent.getParcelableExtra(Keys.KEY_URI);
26 | RouteBundleExtras extras = intent.getParcelableExtra(Keys.KEY_EXTRAS);
27 | Router.resume(uri, extras).open(this);
28 | } else {
29 | // 启动插件成功后,将其转回启动的插件(或宿主)中去进行路由恢复
30 | Intent resume = new Intent();
31 | String action = intent.getStringExtra(Keys.KEY_ACTION);
32 | resume.setAction(action);
33 | resume.putExtras(intent);
34 | sendBroadcast(resume);
35 | }
36 |
37 | finish();
38 | }
39 | }
--------------------------------------------------------------------------------
/core/src/main/java/com/lzh/router/replugin/core/RouterResumeReceiver.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.core;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.IntentFilter;
7 | import android.net.Uri;
8 |
9 | import com.lzh.nonview.router.Router;
10 | import com.lzh.nonview.router.extras.RouteBundleExtras;
11 | import com.lzh.nonview.router.tools.CacheStore;
12 |
13 | /**
14 | * 用于进行跨插件启动路由桥接、恢复的接收器。
15 | *
16 | * @author haoge on 2018/2/24.
17 | */
18 | public class RouterResumeReceiver extends BroadcastReceiver {
19 |
20 | @Override
21 | public void onReceive(Context context, Intent intent) {
22 | Uri uri;
23 | RouteBundleExtras extras;
24 | Context resume;
25 | if (intent.hasExtra(Keys.KEY_URI_INDEX)) {
26 | resume = CacheStore.get().get(intent.getIntExtra(Keys.KEY_RESUME_CONTEXT_INDEX, -1));
27 | extras = CacheStore.get().get(intent.getIntExtra(Keys.KEY_EXTRAS_INDEX, -1));
28 | uri = CacheStore.get().get(intent.getIntExtra(Keys.KEY_URI_INDEX, -1));
29 | } else {
30 | resume = context;
31 | extras = intent.getParcelableExtra(Keys.KEY_EXTRAS);
32 | uri = intent.getParcelableExtra(Keys.KEY_URI);
33 | }
34 |
35 | IPluginCallback callback = RePluginRouteCallback.get().getCallback();
36 | if (resume != null && uri != null) {
37 | Router.resume(uri, extras).open(resume);
38 | if (callback != null) {
39 | callback.onResume(uri);
40 | }
41 | }
42 | }
43 |
44 | public static void registerSelf(Context context, String alias, boolean isHost) {
45 | String action = obtainAction(alias, isHost);
46 |
47 | IntentFilter filter = new IntentFilter(action);
48 | context.registerReceiver(new RouterResumeReceiver(), filter);
49 | }
50 |
51 | public static void start(Context context, String alias, boolean isHost, Uri uri, RouteBundleExtras extras) {
52 | String action = obtainAction(alias, isHost);
53 |
54 | Intent intent = new Intent(action);
55 | intent.putExtra(Keys.KEY_URI, uri);
56 | intent.putExtra(Keys.KEY_EXTRAS, copy(extras));
57 | context.sendBroadcast(intent);
58 | }
59 |
60 | public static String obtainAction(String alias, boolean isHost) {
61 | String action;
62 | if (isHost) {
63 | action = "com.RePlugin.Router.Host";
64 | } else {
65 | action = "com.RePlugin.Router.Plugin." + alias;
66 | }
67 | return action;
68 | }
69 |
70 | public static RouteBundleExtras copy(RouteBundleExtras extras) {
71 | // 新版本的Router跨组件传输时,采用了临时缓存策略(使用CacheStore将一些不可序列化的数据进行临时存储)
72 | // 所以这里为了防止跨插件传递数据时导致内存泄漏。将这部分的数据移除
73 | // 简而言之,就是为此次路由配置的拦截器、回调等数据,将会失效
74 | RouteBundleExtras copy = new RouteBundleExtras();
75 | copy.addExtras(extras.getExtras());
76 | copy.addFlags(extras.getFlags());
77 | copy.setRequestCode(extras.getRequestCode());
78 | copy.setOutAnimation(extras.getOutAnimation());
79 | copy.setInAnimation(extras.getInAnimation());
80 | return copy;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yjfnypeu/Router-RePlugin/5fa86a6e3942b6294f5aaad3119766546f56aac7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 24 15:23:59 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/host/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/host/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "26.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile project(':core')
26 |
27 | provided "com.github.yjfnypeu.Parceler:api:${PARCELER_VERSION}"
28 | provided 'com.android.support:support-v4:25.3.1'// 提供用于兼容ActivityLauncher编写
29 | provided "com.github.yjfnypeu:UpdatePlugin:${UpdatePlugin_version}"
30 |
31 | compile "com.qihoo360.replugin:replugin-host-lib:${RePlugin_version}"
32 | compile "com.github.yjfnypeu.Router:router-host:${ROUTER_VERSION}"
33 | }
34 |
35 | apply from: '../javadoc.gradle'
--------------------------------------------------------------------------------
/host/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/host/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/host/HostActionLauncher.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.host;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 | import com.lzh.nonview.router.launcher.DefaultActionLauncher;
7 | import com.lzh.router.replugin.core.RouterResumeReceiver;
8 |
9 | /**
10 | * 针对RePlugin框架定制的宿主使用的动作路由启动器。
11 | */
12 | public class HostActionLauncher extends DefaultActionLauncher {
13 |
14 | @Override
15 | public void open(Context context) {
16 | String alias = remote.getString("alias");
17 | if (TextUtils.isEmpty(alias)) {
18 | // 代表在宿主中
19 | super.open(context);
20 | } else {
21 | // 桥接到指定插件并进行处理
22 | RouterResumeReceiver.start(context, alias, false, uri, extras);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/host/HostActivityLauncher.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.host;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.text.TextUtils;
8 |
9 | import com.lzh.nonview.router.activityresult.ActivityResultDispatcher;
10 | import com.lzh.nonview.router.launcher.DefaultActivityLauncher;
11 | import com.qihoo360.replugin.RePlugin;
12 |
13 | /**
14 | * 针对RePlugin框架定制的宿主使用的页面路由启动器
15 | */
16 | public class HostActivityLauncher extends DefaultActivityLauncher {
17 |
18 | @Override
19 | public Intent createIntent(Context context) {
20 | String alias = alias();
21 | if (TextUtils.isEmpty(alias)) {
22 | return super.createIntent(context);
23 | } else {
24 | Intent intent = RePlugin.createIntent(alias, rule.getRuleClz());
25 | intent.putExtras(bundle);
26 | intent.putExtras(extras.getExtras());
27 | intent.addFlags(extras.getFlags());
28 | return intent;
29 | }
30 | }
31 |
32 | @Override
33 | public void open(android.support.v4.app.Fragment fragment) {
34 | if (TextUtils.isEmpty(alias())) {
35 | super.open(fragment);
36 | } else {
37 | open(fragment.getActivity());
38 | }
39 | }
40 |
41 | @Override
42 | public void open(Fragment fragment) {
43 | if (TextUtils.isEmpty(alias())) {
44 | super.open(fragment);
45 | } else {
46 | open(fragment.getActivity());
47 | }
48 | }
49 |
50 | @Override
51 | public void open(Context context) {
52 | // 根据是否含有alias判断是否需要使用RePlugin进行跳转
53 | String alias = alias();
54 | if (TextUtils.isEmpty(alias)) {
55 | super.open(context);
56 | } else {
57 | Intent intent = createIntent(context);
58 | RePlugin.startActivityForResult(((Activity) context), intent, extras.getRequestCode());
59 | overridePendingTransition((Activity) context, extras);
60 | ActivityResultDispatcher.get().bindRequestArgs(((Activity) context), extras.getRequestCode(), resultCallback);
61 | }
62 | }
63 |
64 | private String alias() {
65 | // remote: 由其他组件通过IRemoteFactory接口创建的bundle并通过远程服务传递过来的共享数据。
66 | // 在此取出进行适配:(存取数据参考PluginRemoteFactory)
67 | // 若不含有别名。表示此路由匹配的页面。在当前插件中。或者在host中。
68 | if (remote == null || !remote.containsKey("alias")) {
69 | return null;
70 | }
71 | return remote.getString("alias");
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/host/HostRemoteFactory.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.host;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 |
6 | import com.lzh.nonview.router.module.RouteRule;
7 | import com.lzh.nonview.router.protocol.IRemoteFactory;
8 |
9 | class HostRemoteFactory implements IRemoteFactory {
10 | @Override
11 | public Bundle createRemote(Context application, RouteRule rule) {
12 | Bundle bundle = new Bundle();
13 | bundle.putBoolean("isHost", true);
14 | return bundle;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/host/HostRouterConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.host;
2 |
3 | import android.app.ActivityManager;
4 | import android.content.Context;
5 | import android.os.Process;
6 |
7 | import com.lzh.nonview.router.RouterConfiguration;
8 | import com.lzh.nonview.router.route.RouteCallback;
9 | import com.lzh.router.replugin.core.IPluginCallback;
10 | import com.lzh.router.replugin.core.IUriConverter;
11 | import com.lzh.router.replugin.core.RePluginRouteCallback;
12 | import com.lzh.router.replugin.core.RouterResumeReceiver;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * 宿主配置入口
18 | * Created by haoge on 2017/8/24.
19 | */
20 | @SuppressWarnings("unused")
21 | public final class HostRouterConfiguration {
22 |
23 | /**
24 | * 初始化加载。此方法每个插件只需要被加载一次。请尽早进行初始化。
25 | * @param hostPackage 宿主包名:用于指定启动、连接远程路由服务。为各插件提供路由索引功能
26 | * @param context 用于启动远程任务的。
27 | */
28 | public static void init(String hostPackage, Context context) {
29 | if (!inMainProcess(context)) {
30 | // 当为host时,此时会被多个子进程触发,在此只允许主进程的初始化操作
31 | return;
32 | }
33 |
34 | // 启动并连接远程路由服务。
35 | RouterConfiguration.get().startHostService(hostPackage, context);
36 | // 初始化callback.
37 | RouterConfiguration.get().setRemoteFactory(new HostRemoteFactory());
38 | RouterConfiguration.get().setCallback(RePluginRouteCallback.get());
39 | // 设置路由启动器
40 | RouterConfiguration.get().setActionLauncher(HostActionLauncher.class);
41 | RouterConfiguration.get().setActivityLauncher(HostActivityLauncher.class);
42 |
43 | RouterResumeReceiver.registerSelf(context, null, true);
44 | }
45 |
46 | public HostRouterConfiguration setCallback(IPluginCallback callback) {
47 | RePluginRouteCallback.get().setCallback(callback);
48 | return this;
49 | }
50 |
51 | public HostRouterConfiguration setRouteCallback(RouteCallback callback) {
52 | RePluginRouteCallback.get().setRouteCallback(callback);
53 | return this;
54 | }
55 |
56 | /**
57 | * 设置路由uri转换器。
58 | *
59 | * @see IUriConverter
60 | * @param converter non-null.
61 | * @return configuration
62 | */
63 | public HostRouterConfiguration setConverter(IUriConverter converter) {
64 | if (converter != null) {
65 | RePluginRouteCallback.get().setConverter(converter);
66 | }
67 | return this;
68 | }
69 |
70 | private static HostRouterConfiguration configuration = new HostRouterConfiguration();
71 | private HostRouterConfiguration() {}
72 | public static HostRouterConfiguration get() {
73 | return configuration;
74 | }
75 |
76 | private static boolean inMainProcess(Context context) {
77 | int mPid = Process.myPid();
78 | String packageName = context.getPackageName();
79 | ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
80 | List processes =
81 | manager.getRunningAppProcesses();
82 | for (ActivityManager.RunningAppProcessInfo info : processes) {
83 | if (mPid != info.pid) {
84 | continue;
85 | }
86 |
87 | return packageName.equals(info.processName);
88 | }
89 | return false;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/update/IUpdateCombine.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.update;
2 |
3 | import org.lzh.framework.updatepluginlib.model.CheckEntity;
4 |
5 | /**
6 | * 根据插件别名组装出远程插件地址。
7 | * Created by haoge on 2017/8/24.
8 | */
9 | public interface IUpdateCombine {
10 |
11 | /**
12 | * 根据插件别名组装合成使用的插件地址。
13 | * @param alias 插件别名
14 | * @return 组装后的更新接口实体类。
15 | */
16 | CheckEntity combine(String alias);
17 | }
18 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/update/RePluginInstall.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.update;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.widget.Toast;
6 |
7 | import com.qihoo360.replugin.RePlugin;
8 | import com.qihoo360.replugin.model.PluginInfo;
9 |
10 | import org.lzh.framework.updatepluginlib.base.InstallStrategy;
11 | import org.lzh.framework.updatepluginlib.model.Update;
12 |
13 |
14 | /**
15 | * 定制下载成功后安装操作。下载后进行安装并重启plugin intent.
16 | */
17 | class RePluginInstall implements InstallStrategy {
18 |
19 | private String pluginName;
20 | private Context context;
21 | private Intent intent;
22 |
23 | RePluginInstall(String pluginName, Context context, Intent intent) {
24 | this.pluginName = pluginName;
25 | this.context = context;
26 | this.intent = intent;
27 | }
28 |
29 | @Override
30 | public void install(Context context, String filename, Update update) {
31 | PluginInfo info = RePlugin.install(filename);
32 | if (!info.getAlias().equals(pluginName)) {
33 | // 校验是否插件的别名能匹配上。将不正确的卸载掉
34 | Toast.makeText(context, String.format("install plugin failed: need alias for %s but is %s", pluginName, info.getAlias()), Toast.LENGTH_SHORT).show();
35 | RePlugin.uninstall(info.getAlias());
36 | } else {
37 | RePlugin.startActivity(this.context, intent);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/host/src/main/java/com/lzh/router/replugin/update/UpdateRePluginCallbacks.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.update;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | import com.qihoo360.replugin.RePluginCallbacks;
7 |
8 | import org.lzh.framework.updatepluginlib.UpdateBuilder;
9 | import org.lzh.framework.updatepluginlib.UpdateConfig;
10 |
11 | /**
12 | * 接入UpdatePlugin框架,用于方便的进行远程插件下载、安装、启动配置。
13 | */
14 | public class UpdateRePluginCallbacks extends RePluginCallbacks{
15 |
16 | private IUpdateCombine combine;
17 | private UpdateConfig updateConfig;
18 |
19 | public UpdateRePluginCallbacks(Context context, UpdateConfig updateConfig, IUpdateCombine combine) {
20 | super(context);
21 | this.updateConfig = updateConfig;
22 | this.combine = combine;
23 | }
24 |
25 | @Override
26 | public boolean onPluginNotExistsForActivity(Context context, String plugin, Intent intent, int process) {
27 | UpdateBuilder.create(updateConfig)
28 | .setCheckEntity(combine.combine(plugin))
29 | .setInstallStrategy(new RePluginInstall(plugin, context, intent))
30 | .check();
31 | return true;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/javadoc.gradle:
--------------------------------------------------------------------------------
1 | // build a jar with source files
2 | task sourcesJar(type: Jar) {
3 | from android.sourceSets.main.java.srcDirs
4 | classifier = 'sources'
5 | }
6 |
7 | task javadoc(type: Javadoc) {
8 | failOnError false
9 | source = android.sourceSets.main.java.sourceFiles
10 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
11 | classpath += configurations.compile
12 | }
13 |
14 | // build a jar with javadoc
15 | task javadocJar(type: Jar, dependsOn: javadoc) {
16 | classifier = 'javadoc'
17 | from javadoc.destinationDir
18 | }
19 |
20 | artifacts {
21 | archives sourcesJar
22 | archives javadocJar
23 | }
--------------------------------------------------------------------------------
/plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "26.0.1"
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile project(':core')
25 |
26 | provided "com.github.yjfnypeu.Parceler:api:${PARCELER_VERSION}"
27 | provided 'com.android.support:support-v4:25.3.1'// 提供用于兼容ActivityLauncher编写
28 |
29 | compile "com.qihoo360.replugin:replugin-plugin-lib:${RePlugin_version}"
30 | compile "com.github.yjfnypeu.Router:router-api:${ROUTER_VERSION}"
31 | }
32 |
33 | apply from: '../javadoc.gradle'
--------------------------------------------------------------------------------
/plugin/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/haoge/Documents/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/plugin/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/plugin/src/main/java/com/lzh/router/replugin/plugin/PluginActionLauncher.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.plugin;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 |
6 | import com.lzh.nonview.router.launcher.DefaultActionLauncher;
7 | import com.lzh.router.replugin.core.RouterResumeReceiver;
8 |
9 | /**
10 | * 针对RePlugin框架定制的动作路由启动器。
11 | */
12 | public class PluginActionLauncher extends DefaultActionLauncher {
13 |
14 | @Override
15 | public void open(Context context) {
16 | String alias = alias();
17 | boolean isHost = isHost();
18 | if (isHost || !TextUtils.isEmpty(alias)) {
19 | RouterResumeReceiver.start(context, alias, isHost, uri, extras);
20 | } else {
21 | super.open(context);
22 | }
23 | }
24 |
25 | private String alias() {
26 | return remote.getString("alias");
27 | }
28 |
29 | private boolean isHost() {
30 | return remote.getBoolean("isHost");
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/plugin/src/main/java/com/lzh/router/replugin/plugin/PluginActivityLauncher.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.plugin;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.text.TextUtils;
8 |
9 | import com.lzh.nonview.router.activityresult.ActivityResultDispatcher;
10 | import com.lzh.nonview.router.launcher.DefaultActivityLauncher;
11 | import com.qihoo360.replugin.RePlugin;
12 |
13 | /**
14 | * 针对RePlugin框架定制的页面路由启动器
15 | */
16 | public class PluginActivityLauncher extends DefaultActivityLauncher {
17 |
18 |
19 | @Override
20 | public Intent createIntent(Context context) {
21 | String alias = alias();
22 | if (TextUtils.isEmpty(alias)) {
23 | return super.createIntent(context);
24 | } else {
25 | Intent intent = RePlugin.createIntent(alias, rule.getRuleClz());
26 | intent.putExtras(bundle);
27 | intent.putExtras(extras.getExtras());
28 | intent.addFlags(extras.getFlags());
29 | return intent;
30 | }
31 | }
32 |
33 | @Override
34 | public void open(android.support.v4.app.Fragment fragment) {
35 | if (TextUtils.isEmpty(alias())) {
36 | super.open(fragment);
37 | } else {
38 | open(fragment.getActivity());
39 | }
40 | }
41 |
42 | @Override
43 | public void open(Fragment fragment) {
44 | if (TextUtils.isEmpty(alias())) {
45 | super.open(fragment);
46 | } else {
47 | open(fragment.getActivity());
48 | }
49 | }
50 |
51 | @Override
52 | public void open(Context context) {
53 | // 根据是否含有alias判断是否需要使用RePlugin进行跳转
54 | if (TextUtils.isEmpty(alias())) {
55 | super.open(context);
56 | } else {
57 | Intent intent = createIntent(context);
58 | RePlugin.startActivityForResult(((Activity) context), intent, extras.getRequestCode());
59 | overridePendingTransition((Activity) context, extras);
60 | ActivityResultDispatcher.get().bindRequestArgs(((Activity) context), extras.getRequestCode(), resultCallback);
61 | }
62 | }
63 |
64 | private String alias() {
65 | String alias = remote.getString("alias");
66 | return alias;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/plugin/src/main/java/com/lzh/router/replugin/plugin/PluginRemoteFactory.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.plugin;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 |
6 | import com.lzh.nonview.router.module.RouteRule;
7 | import com.lzh.nonview.router.protocol.IRemoteFactory;
8 |
9 | /**
10 | * 插件远程数据创建器。用于对其他插件提供额外参数。供其他插件或宿主做路由启动。
11 | * Created by haoge on 2017/8/24.
12 | */
13 | class PluginRemoteFactory implements IRemoteFactory {
14 |
15 | String alias;
16 |
17 | public PluginRemoteFactory(String alias) {
18 | this.alias = alias;
19 | }
20 |
21 | @Override
22 | public Bundle createRemote(Context application, RouteRule rule) {
23 | Bundle bundle = new Bundle();
24 | bundle.putString("alias", alias);
25 | return bundle;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/plugin/src/main/java/com/lzh/router/replugin/plugin/PluginRouterConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.lzh.router.replugin.plugin;
2 |
3 | import android.content.Context;
4 |
5 | import com.lzh.nonview.router.RouterConfiguration;
6 | import com.lzh.nonview.router.route.RouteCallback;
7 | import com.lzh.router.replugin.core.IPluginCallback;
8 | import com.lzh.router.replugin.core.IUriConverter;
9 | import com.lzh.router.replugin.core.RePluginRouteCallback;
10 | import com.lzh.router.replugin.core.RouterResumeReceiver;
11 |
12 | /**
13 | * RePlugin插件配置入口。
14 | * Created by haoge on 2017/8/24.
15 | */
16 | @SuppressWarnings("unused")
17 | public final class PluginRouterConfiguration {
18 |
19 | /**
20 | * 初始化加载。此方法每个插件只需要被加载一次。请尽早进行初始化。
21 | * @param hostPackage 宿主包名:用于指定启动、连接远程路由服务。为各插件提供路由索引功能
22 | * @param alias 插件别名:路由启动器将会使用此别名作为唯一标识。
23 | * @param context 用于启动远程任务的。
24 | */
25 | public static void init(String hostPackage, String alias, Context context) {
26 | // 启动并连接远程路由服务。
27 | RouterConfiguration.get().startHostService(hostPackage, context, alias);
28 | // 提供远程数据创建工厂
29 | RouterConfiguration.get().setRemoteFactory(new PluginRemoteFactory(alias));
30 | // 初始化callback.
31 | RouterConfiguration.get().setCallback(RePluginRouteCallback.get());
32 | // 设置路由启动器
33 | RouterConfiguration.get().setActionLauncher(PluginActionLauncher.class);
34 | RouterConfiguration.get().setActivityLauncher(PluginActivityLauncher.class);
35 | // 设置自身的插件别名
36 | RePluginRouteCallback.get().setAlias(alias);
37 |
38 | RouterResumeReceiver.registerSelf(context, alias, false);
39 | }
40 |
41 | public PluginRouterConfiguration setCallback(IPluginCallback callback) {
42 | RePluginRouteCallback.get().setCallback(callback);
43 | return this;
44 | }
45 |
46 | public PluginRouterConfiguration setRouteCallback(RouteCallback callback) {
47 | RePluginRouteCallback.get().setRouteCallback(callback);
48 | return this;
49 | }
50 |
51 | /**
52 | * 设置路由uri转换器。
53 | *
54 | * @see IUriConverter
55 | * @param converter non-null.
56 | * @return configuration
57 | */
58 | public PluginRouterConfiguration setConverter(IUriConverter converter) {
59 | if (converter != null) {
60 | RePluginRouteCallback.get().setConverter(converter);
61 | }
62 | return this;
63 | }
64 |
65 | private static PluginRouterConfiguration configuration = new PluginRouterConfiguration();
66 | private PluginRouterConfiguration() {}
67 | public static PluginRouterConfiguration get() {
68 | return configuration;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':host', ':plugin', ':core'
2 |
--------------------------------------------------------------------------------