├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── im │ │ └── wangchao │ │ └── mrouterapp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── im │ │ │ └── wangchao │ │ │ └── mrouterapp │ │ │ ├── App.java │ │ │ ├── GlobalLevelOneInterceptor.java │ │ │ ├── GlobalLevelTwoInterceptor.java │ │ │ ├── MainActivity.java │ │ │ ├── ModuleOneActivity.java │ │ │ ├── ModuleOneService.java │ │ │ ├── ModuleTwoActivity.java │ │ │ ├── ModuleTwoProvider.java │ │ │ └── OneInterceptor.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_module_one.xml │ │ └── activity_module_two.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── im │ └── wangchao │ └── mrouterapp │ └── ExampleUnitTest.java ├── build.gradle ├── example-module ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── im │ │ └── wangchao │ │ └── examplemodule │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── im │ │ │ └── wangchao │ │ │ └── examplemodule │ │ │ ├── ExampleActivity.java │ │ │ ├── ExampleInterceptor.java │ │ │ ├── ExampleProvider.java │ │ │ ├── ExampleRouterService.java │ │ │ └── GlobalExampleInterceptor.java │ └── res │ │ ├── layout │ │ └── activity_example.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── im │ └── wangchao │ └── examplemodule │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mrouter-annotations ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── im │ └── wangchao │ └── mrouter │ └── annotations │ ├── Constants.java │ ├── Interceptor.java │ ├── Provider.java │ ├── Route.java │ └── RouterService.java ├── mrouter-compiler ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ └── java │ └── im │ └── wangchao │ └── mrouter │ └── compiler │ ├── BuildLoaderClass.java │ └── RouterLoaderProcessor.java ├── mrouter-plugin ├── .gitignore ├── build.gradle ├── gradle.properties └── src │ └── main │ ├── groovy │ └── im │ │ └── wangchao │ │ └── mrouter │ │ └── plugin │ │ ├── RouterPlugin.groovy │ │ └── transform │ │ └── RouterTransform.groovy │ ├── java │ └── im │ │ └── wangchao │ │ └── mrouter │ │ └── plugin │ │ ├── RouterClassVisitor.java │ │ └── Utils.java │ └── resources │ └── META-INF │ └── gradle-plugins │ └── im.wangchao.mrouter.properties ├── mrouter ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── im │ │ └── wangchao │ │ └── mrouter │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── im │ │ │ └── wangchao │ │ │ └── mrouter │ │ │ ├── ForwardServiceInterceptor.java │ │ │ ├── IInterceptor.java │ │ │ ├── ILoader.java │ │ │ ├── ILoaderImpl.java │ │ │ ├── IProvider.java │ │ │ ├── IRouterService.java │ │ │ ├── RealCallInterceptor.java │ │ │ ├── RouteIntent.java │ │ │ ├── Router.java │ │ │ ├── RouterCallback.java │ │ │ ├── RouterRepository.java │ │ │ ├── RouterServiceCenter.java │ │ │ ├── exception │ │ │ └── TargetClassNotFoundException.java │ │ │ └── internal │ │ │ ├── RealInterceptorPopChain.java │ │ │ ├── RealInterceptorPushChain.java │ │ │ ├── RealInterceptorRequestChain.java │ │ │ └── Utils.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── im │ └── wangchao │ └── mrouter │ └── ExampleUnitTest.java ├── settings.gradle └── upload.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MRouter 2 | A Modularization Component. 3 | 4 | ## Gradle 5 | Add mrouter-plugin as a dependency in your main build.gradle in the root of your project: 6 | ```gradle 7 | buildscript { 8 | dependencies { 9 | classpath 'im.wangchao:mrouter-plugin:0.1.0' 10 | } 11 | } 12 | ``` 13 | 14 | Then you need to "apply" the plugin and add dependencies by adding the following lines to your app/build.gradle. 15 | ```gradle 16 | apply plugin: 'im.wangchao.mrouter' 17 | ... 18 | android { 19 | ... 20 | defaultConfig { 21 | ... 22 | javaCompileOptions { 23 | annotationProcessorOptions { 24 | arguments = [ moduleName : project.getName(), appModule: "1" ] 25 | } 26 | } 27 | } 28 | } 29 | ... 30 | dependencies { 31 | implementation 'im.wangchao:mrouter:0.1.11' 32 | annotationProcessor 'im.wangchao:mrouter-compiler:0.1.4' 33 | } 34 | ``` 35 | And other modules. 36 | ```gradle 37 | android { 38 | ... 39 | defaultConfig { 40 | ... 41 | javaCompileOptions { 42 | annotationProcessorOptions { 43 | arguments = [ moduleName : project.getName() ] 44 | } 45 | } 46 | } 47 | } 48 | ... 49 | dependencies { 50 | compileOnly 'im.wangchao:mrouter:0.1.11' 51 | annotationProcessor 'im.wangchao:mrouter-compiler:0.1.4' 52 | } 53 | ``` 54 | 55 | ## How to use 56 | ### 1.Initialization 57 | ```java 58 | public class App extend Application { 59 | 60 | ... 61 | 62 | @Override public void onCreate() { 63 | super.onCreate(); 64 | Router.init(); 65 | } 66 | 67 | ... 68 | } 69 | ``` 70 | ### 2.Configuration 71 | #### 2.1 Register Route 72 | **Use Custom RouterService** 73 | ```java 74 | @Route(path = "/one", routerName = "one") 75 | public class ModuleOneActivity extends AppCompatActivity { 76 | ... 77 | } 78 | ``` 79 | **Use Default RouterService** 80 | ```java 81 | @Route(path = "/two") 82 | public class ModuleTwoActivity extends AppCompatActivity { 83 | ... 84 | } 85 | ``` 86 | #### 2.2 Register RouterService 87 | ```java 88 | @RouterService("one") 89 | public class ModuleOneService implements IRouterService { 90 | ... 91 | } 92 | ``` 93 | #### 2.3 Register Interceptor 94 | **Global Interceptor** 95 | ```java 96 | @Interceptor(priority = 1) 97 | public class GlobalLevelOneInterceptor implements IInterceptor{ 98 | ... 99 | } 100 | ``` 101 | **Child Interceptor** 102 | ```java 103 | @Interceptor(routerName = "one") 104 | public class OneInterceptor implements IInterceptor { 105 | ... 106 | } 107 | ``` 108 | #### 2.4 Register Provider 109 | ```java 110 | @Provider(name = "test", routerName = "two") 111 | public class ModuleTwoProvider implements IProvider { 112 | ... 113 | } 114 | ``` 115 | ### 3.Use 116 | #### 3.1 Push/Pop 117 | ```java 118 | // push to Activity that configure @Route(path = "/two") 119 | Router.push(this, "router:///two")); 120 | ... 121 | // push to Activity that configure @Route(path = "/one", routerName = "one") 122 | Router.push(this, "one:///one") 123 | ... 124 | // Pop 125 | Router.pop(this); 126 | ``` 127 | #### 3.2 Request 128 | ```java 129 | Router.request("two://test", new RouterCallback() { 130 | @Override public void onSuccess(RouteIntent route) { 131 | String result = route.bundle().getString("result"); 132 | Log.e("wcwcwc", "result =>> " + result); 133 | } 134 | 135 | @Override public void onFailure(RouteIntent route, Exception e) { 136 | 137 | } 138 | }); 139 | ``` 140 | 141 | ### License 142 | 143 | Copyright 2019 Mot. All rights reserved. 144 | 145 | Licensed under the Apache License, Version 2.0 (the "License"); 146 | you may not use this file except in compliance with the License. 147 | You may obtain a copy of the License at 148 | 149 | http://www.apache.org/licenses/LICENSE-2.0 150 | 151 | Unless required by applicable law or agreed to in writing, software 152 | distributed under the License is distributed on an "AS IS" BASIS, 153 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 154 | See the License for the specific language governing permissions and 155 | limitations under the License. 156 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "im.wangchao.mrouterapp" 7 | minSdkVersion 15 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | multiDexEnabled true 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | javaCompileOptions { 14 | annotationProcessorOptions { 15 | arguments = [ moduleName : project.getName(), appModule: "1" ] 16 | } 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled true 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | lintOptions { 26 | abortOnError false 27 | } 28 | compileOptions { 29 | sourceCompatibility rootProject.ext.sourceCompatibilityVersion 30 | targetCompatibility rootProject.ext.targetCompatibilityVersion 31 | } 32 | dexOptions { 33 | javaMaxHeapSize '2g' 34 | jumboMode = true 35 | } 36 | } 37 | 38 | dependencies { 39 | implementation fileTree(dir: 'libs', include: ['*.jar']) 40 | implementation 'com.android.support:appcompat-v7:26.1.0' 41 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 42 | testImplementation 'junit:junit:4.12' 43 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 44 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 45 | implementation 'com.android.support:multidex:1.0.2' 46 | 47 | implementation project(':mrouter') 48 | annotationProcessor project(':mrouter-compiler') 49 | // implementation 'im.wangchao:mrouter:0.1.6' 50 | // annotationProcessor 'im.wangchao:mrouter-compiler:0.1.4' 51 | 52 | implementation project(':example-module') 53 | } 54 | 55 | apply plugin: 'im.wangchao.mrouter' -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | -ignorewarnings 24 | 25 | -printmapping mapping.txt 26 | 27 | -keep public class * extends android.app.Activity 28 | -keep public class * extends android.app.Application 29 | -keep public class * extends android.app.Service 30 | -keep public class * extends android.content.BroadcastReceiver 31 | -keep public class * extends android.content.ContentProvider 32 | -keep public class * extends android.app.backup.BackupAgentHelper 33 | -keep public class * extends android.preference.Preference 34 | -keep public class com.android.vending.licensing.ILicensingService 35 | 36 | -keepclasseswithmembers class * { 37 | public (android.content.Context, android.util.AttributeSet); 38 | } 39 | 40 | -keepclasseswithmembers class * { 41 | public (android.content.Context, android.util.AttributeSet, int); 42 | } 43 | 44 | -assumenosideeffects class android.util.Log { 45 | public static *** d(...); 46 | public static *** v(...); 47 | public static *** i(...); 48 | } 49 | 50 | # If your project uses WebView with JS, uncomment the following 51 | # and specify the fully qualified class name to the JavaScript interface 52 | # class: 53 | -keepclassmembers class fqcn.of.javascript.interface.for.webview { 54 | public *; 55 | } 56 | 57 | # Uncomment this to preserve the line number information for 58 | # debugging stack traces. 59 | -keepattributes SourceFile,LineNumberTable 60 | 61 | # If you keep the line number information, uncomment this to 62 | # hide the original source file name. 63 | -renamesourcefileattribute SourceFile 64 | 65 | -------------------------------------------------------------------------------- /app/src/androidTest/java/im/wangchao/mrouterapp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("im.wangchao.mrouterapp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/App.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.support.multidex.MultiDex; 6 | 7 | import im.wangchao.mrouter.Router; 8 | 9 | /** 10 | *

Description : App.

11 | *

Author : wangchao.

12 | *

Date : 2017/11/20.

13 | *

Time : 上午10:12.

14 | */ 15 | public class App extends Application { 16 | 17 | @Override protected void attachBaseContext(Context base) { 18 | super.attachBaseContext(base); 19 | MultiDex.install(base); 20 | } 21 | 22 | @Override public void onCreate() { 23 | super.onCreate(); 24 | Router.init(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/GlobalLevelOneInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import im.wangchao.mrouter.IInterceptor; 7 | import im.wangchao.mrouter.RouteIntent; 8 | import im.wangchao.mrouter.RouterCallback; 9 | import im.wangchao.mrouter.annotations.Interceptor; 10 | 11 | /** 12 | *

Description : GlobalInterceptor.

13 | *

Author : wangchao.

14 | *

Date : 2017/11/20.

15 | *

Time : 上午9:41.

16 | */ 17 | @Interceptor(priority = 1) 18 | public class GlobalLevelOneInterceptor implements IInterceptor{ 19 | 20 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 21 | Log.e("wcwcwc", "Global One Interceptor: push() priority = 1"); 22 | return chain.proceed(context, chain.route(), requestCode, callback); 23 | } 24 | 25 | @Override public RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback) { 26 | Log.e("wcwcwc", "Global One Interceptor: pop() priority = 1"); 27 | return chain.proceed(context, chain.route(), resultCode, callback); 28 | } 29 | 30 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 31 | Log.e("wcwcwc", "Global One Interceptor: request() priority = 1"); 32 | return chain.proceed(chain.route(), callback); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/GlobalLevelTwoInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import im.wangchao.mrouter.IInterceptor; 7 | import im.wangchao.mrouter.RouteIntent; 8 | import im.wangchao.mrouter.RouterCallback; 9 | import im.wangchao.mrouter.annotations.Interceptor; 10 | 11 | /** 12 | *

Description : GlobalLevelTwoIntercepor.

13 | *

Author : wangchao.

14 | *

Date : 2017/11/20.

15 | *

Time : 上午10:04.

16 | */ 17 | @Interceptor(priority = 3) 18 | public class GlobalLevelTwoInterceptor implements IInterceptor { 19 | 20 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 21 | Log.e("wcwcwc", "Global Two Interceptor: push() priority = 3"); 22 | return chain.proceed(context, chain.route(), requestCode, callback); 23 | } 24 | 25 | @Override public RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback) { 26 | Log.e("wcwcwc", "Global Two Interceptor: pop() priority = 3"); 27 | return chain.proceed(context, chain.route(), resultCode, callback); 28 | } 29 | 30 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 31 | Log.e("wcwcwc", "Global Two Interceptor: request() priority = 3"); 32 | return chain.proceed(chain.route(), callback); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | 7 | import im.wangchao.mrouter.RouteIntent; 8 | import im.wangchao.mrouter.Router; 9 | import im.wangchao.mrouter.RouterCallback; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | findViewById(R.id.jumpOne).setOnClickListener(v -> Router.push(this, "one:///one", new RouterCallback() { 18 | @Override public void onSuccess(RouteIntent route) { 19 | Log.e("wcwcwc", "push onSuccess: " + route.uri()); 20 | } 21 | 22 | @Override public void onFailure(RouteIntent route, Exception e) { 23 | 24 | } 25 | })); 26 | findViewById(R.id.jumpTwo).setOnClickListener(v -> Router.push(this, "router:///two")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/ModuleOneActivity.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | 8 | import im.wangchao.mrouter.RouteIntent; 9 | import im.wangchao.mrouter.Router; 10 | import im.wangchao.mrouter.RouterCallback; 11 | import im.wangchao.mrouter.annotations.Route; 12 | 13 | /** 14 | *

Description : Module1Activity.

15 | *

Author : wangchao.

16 | *

Date : 2017/11/20.

17 | *

Time : 上午9:36.

18 | */ 19 | @Route(path = "/one", routerName = "one") 20 | public class ModuleOneActivity extends AppCompatActivity { 21 | 22 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_module_one); 25 | findViewById(R.id.testBtn).setOnClickListener(v -> { 26 | Router.request("two://test", new RouterCallback() { 27 | @Override public void onSuccess(RouteIntent route) { 28 | String result = route.bundle().getString("result"); 29 | Log.e("wcwcwc", "result =>> " + result); 30 | } 31 | 32 | @Override public void onFailure(RouteIntent route, Exception e) { 33 | 34 | } 35 | }); 36 | }); 37 | } 38 | 39 | @Override public void onBackPressed() { 40 | Router.pop(this, new RouterCallback() { 41 | @Override public void onSuccess(RouteIntent route) { 42 | Log.e("wcwcwc", "pop success: " + route.uri()); 43 | } 44 | 45 | @Override public void onFailure(RouteIntent route, Exception e) { 46 | 47 | } 48 | }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/ModuleOneService.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.support.v4.app.ActivityCompat; 7 | import android.util.Log; 8 | 9 | import im.wangchao.mrouter.IRouterService; 10 | import im.wangchao.mrouter.RouteIntent; 11 | import im.wangchao.mrouter.RouterCallback; 12 | import im.wangchao.mrouter.annotations.RouterService; 13 | 14 | /** 15 | *

Description : ModuleOneService.

16 | *

Author : wangchao.

17 | *

Date : 2017/11/20.

18 | *

Time : 上午10:01.

19 | */ 20 | @RouterService("one") 21 | public class ModuleOneService implements IRouterService { 22 | 23 | @Override public void push(Context context, RouteIntent route, int requestCode, RouterCallback callback) { 24 | Log.e("wcwcwc", "Module one service: push() -> " + route.targetClass()); 25 | final Intent intent = route.getPushIntent(context); 26 | 27 | if (requestCode > 0) { 28 | ActivityCompat.startActivityForResult((Activity) context, intent, requestCode, null); 29 | } else { 30 | ActivityCompat.startActivity(context, intent, null); 31 | } 32 | 33 | if (callback != null){ 34 | callback.onSuccess(route); 35 | } 36 | } 37 | 38 | @Override public void pop(Context context, RouteIntent route, int resultCode, RouterCallback callback) { 39 | Log.e("wcwcwc", "Module one service: pop()"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/ModuleTwoActivity.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.util.Log; 7 | 8 | import im.wangchao.mrouter.RouteIntent; 9 | import im.wangchao.mrouter.Router; 10 | import im.wangchao.mrouter.RouterCallback; 11 | import im.wangchao.mrouter.annotations.Route; 12 | 13 | /** 14 | *

Description : Module2Activity.

15 | *

Author : wangchao.

16 | *

Date : 2017/11/20.

17 | *

Time : 上午9:37.

18 | */ 19 | @Route(path = "/two") 20 | public class ModuleTwoActivity extends AppCompatActivity { 21 | 22 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_module_two); 25 | findViewById(R.id.testBtn).setOnClickListener(v -> { 26 | Router.push(this, "example:///test?v0=111"); 27 | }); 28 | 29 | findViewById(R.id.requestBtn).setOnClickListener(v -> { 30 | Router.request("example://test", new RouterCallback() { 31 | @Override public void onSuccess(RouteIntent route) { 32 | String result = route.bundle().getString("result"); 33 | Log.e("wcwcwc", "result =>> " + result); 34 | } 35 | 36 | @Override public void onFailure(RouteIntent route, Exception e) { 37 | 38 | } 39 | }); 40 | }); 41 | } 42 | 43 | @Override public void onBackPressed() { 44 | Router.pop(this); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/ModuleTwoProvider.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import im.wangchao.mrouter.IProvider; 4 | import im.wangchao.mrouter.RouteIntent; 5 | import im.wangchao.mrouter.RouterCallback; 6 | import im.wangchao.mrouter.annotations.Provider; 7 | 8 | /** 9 | *

Description : ModuleTwoProvider.

10 | *

Author : wangchao.

11 | *

Date : 2017/11/20.

12 | *

Time : 上午10:02.

13 | */ 14 | @Provider(name = "test", routerName = "two") 15 | public class ModuleTwoProvider implements IProvider { 16 | 17 | @Override public void onReceiver(RouteIntent route, RouterCallback callback) { 18 | callback.onSuccess(route.newBuilder().addParameter("result", "haha").build()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/im/wangchao/mrouterapp/OneInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | 6 | import im.wangchao.mrouter.IInterceptor; 7 | import im.wangchao.mrouter.RouteIntent; 8 | import im.wangchao.mrouter.RouterCallback; 9 | import im.wangchao.mrouter.annotations.Interceptor; 10 | 11 | /** 12 | *

Description : OneInterceptor.

13 | *

Author : wangchao.

14 | *

Date : 2017/11/20.

15 | *

Time : 上午10:06.

16 | */ 17 | @Interceptor(routerName = "one") 18 | public class OneInterceptor implements IInterceptor { 19 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 20 | Log.e("wcwcwc", "One Interceptor: push()"); 21 | return chain.proceed(context, chain.route(), requestCode, callback); 22 | } 23 | 24 | @Override public RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback) { 25 | Log.e("wcwcwc", "One Interceptor: pop()"); 26 | return chain.proceed(context, chain.route(), resultCode, callback); 27 | } 28 | 29 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 30 | Log.e("wcwcwc", "One Interceptor: request()"); 31 | return chain.proceed(chain.route(), callback); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 |