├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_module_one.xml
│ │ │ │ ├── activity_module_two.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── im
│ │ │ │ └── wangchao
│ │ │ │ └── mrouterapp
│ │ │ │ ├── App.java
│ │ │ │ ├── ModuleTwoProvider.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── OneInterceptor.java
│ │ │ │ ├── GlobalLevelOneInterceptor.java
│ │ │ │ ├── GlobalLevelTwoInterceptor.java
│ │ │ │ ├── ModuleOneService.java
│ │ │ │ ├── ModuleTwoActivity.java
│ │ │ │ └── ModuleOneActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── im
│ │ │ └── wangchao
│ │ │ └── mrouterapp
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── im
│ │ └── wangchao
│ │ └── mrouterapp
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── mrouter
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── im
│ │ │ └── wangchao
│ │ │ └── mrouter
│ │ │ ├── IProvider.java
│ │ │ ├── IRouterService.java
│ │ │ ├── exception
│ │ │ └── TargetClassNotFoundException.java
│ │ │ ├── RouterCallback.java
│ │ │ ├── internal
│ │ │ ├── Utils.java
│ │ │ ├── RealInterceptorRequestChain.java
│ │ │ ├── RealInterceptorPopChain.java
│ │ │ └── RealInterceptorPushChain.java
│ │ │ ├── ForwardServiceInterceptor.java
│ │ │ ├── IInterceptor.java
│ │ │ ├── ILoader.java
│ │ │ ├── ILoaderImpl.java
│ │ │ ├── RealCallInterceptor.java
│ │ │ ├── RouterRepository.java
│ │ │ ├── Router.java
│ │ │ ├── RouteIntent.java
│ │ │ └── RouterServiceCenter.java
│ ├── test
│ │ └── java
│ │ │ └── im
│ │ │ └── wangchao
│ │ │ └── mrouter
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── im
│ │ └── wangchao
│ │ └── mrouter
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
├── gradle.properties
└── build.gradle
├── example-module
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ └── activity_example.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── im
│ │ │ └── wangchao
│ │ │ └── examplemodule
│ │ │ ├── ExampleProvider.java
│ │ │ ├── ExampleActivity.java
│ │ │ ├── ExampleInterceptor.java
│ │ │ ├── ExampleRouterService.java
│ │ │ └── GlobalExampleInterceptor.java
│ ├── test
│ │ └── java
│ │ │ └── im
│ │ │ └── wangchao
│ │ │ └── examplemodule
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── im
│ │ └── wangchao
│ │ └── examplemodule
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── mrouter-compiler
├── .gitignore
├── build.gradle
├── gradle.properties
└── src
│ └── main
│ └── java
│ └── im
│ └── wangchao
│ └── mrouter
│ └── compiler
│ ├── RouterLoaderProcessor.java
│ └── BuildLoaderClass.java
├── mrouter-plugin
├── .gitignore
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── gradle-plugins
│ │ │ └── im.wangchao.mrouter.properties
│ │ ├── groovy
│ │ └── im
│ │ │ └── wangchao
│ │ │ └── mrouter
│ │ │ └── plugin
│ │ │ ├── RouterPlugin.groovy
│ │ │ └── transform
│ │ │ └── RouterTransform.groovy
│ │ └── java
│ │ └── im
│ │ └── wangchao
│ │ └── mrouter
│ │ └── plugin
│ │ ├── Utils.java
│ │ └── RouterClassVisitor.java
├── gradle.properties
└── build.gradle
├── mrouter-annotations
├── .gitignore
├── build.gradle
├── src
│ └── main
│ │ └── java
│ │ └── im
│ │ └── wangchao
│ │ └── mrouter
│ │ └── annotations
│ │ ├── RouterService.java
│ │ ├── Route.java
│ │ ├── Provider.java
│ │ ├── Interceptor.java
│ │ └── Constants.java
└── gradle.properties
├── upload.sh
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mrouter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/example-module/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mrouter-compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mrouter-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mrouter-annotations/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/upload.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | source ~/.bash_profile
3 | ./gradlew bintrayUpload --stacktrace
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
Description : IProvider.
5 | *Author : wangchao.
6 | *Date : 2017/11/16.
7 | *Time : 下午3:58.
8 | */ 9 | public interface IProvider { 10 | 11 | /** 12 | * 接收请求方法 13 | * 14 | * @param route RouteIntent 15 | * @param callback 回调函数 16 | */ 17 | void onReceiver(RouteIntent route, RouterCallback callback); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/test/java/im/wangchao/mrouterapp/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouterapp; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /mrouter/src/test/java/im/wangchao/mrouter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /example-module/src/test/java/im/wangchao/examplemodule/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/IRouterService.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | *Description : RouterService.
7 | *Author : wangchao.
8 | *Date : 2017/11/10.
9 | *Time : 下午1:34.
10 | */ 11 | public interface IRouterService { 12 | void push(Context context, RouteIntent route, int requestCode, RouterCallback callback); 13 | 14 | void pop(Context context, RouteIntent route, int resultCode, RouterCallback callback); 15 | } 16 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/exception/TargetClassNotFoundException.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter.exception; 2 | 3 | import im.wangchao.mrouter.RouteIntent; 4 | 5 | /** 6 | *Description : TargetClassNotFoundException.
7 | *Author : wangchao.
8 | *Date : 2017/12/7.
9 | *Time : 下午5:24.
10 | */ 11 | public class TargetClassNotFoundException extends RuntimeException{ 12 | 13 | public TargetClassNotFoundException(RouteIntent route){ 14 | super(String.format("Can not found target class with Uri(%s).", route.uri())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/RouterCallback.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | /** 4 | *Description : RouterRequestCallback.
5 | *Author : wangchao.
6 | *Date : 2017/11/16.
7 | *Time : 下午4:12.
8 | */ 9 | public interface RouterCallback { 10 | 11 | /** 12 | * 响应成功 13 | * @param route RouterIntent 14 | */ 15 | void onSuccess(RouteIntent route); 16 | 17 | /** 18 | * 响应失败 19 | * @param route RouterIntent 20 | * @param e 相关异常信息,可能为null 21 | */ 22 | void onFailure(RouteIntent route, Exception e); 23 | } 24 | -------------------------------------------------------------------------------- /mrouter-compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | 3 | dependencies { 4 | implementation fileTree(dir: 'libs', include: ['*.jar']) 5 | implementation 'com.google.auto.service:auto-service:1.0-rc2' 6 | implementation 'com.google.auto:auto-common:0.6' 7 | implementation 'com.squareup:javapoet:1.9.0' 8 | // implementation project(':mrouter-annotations') 9 | implementation 'im.wangchao:mrouter-annotations:0.1.3' 10 | } 11 | 12 | sourceCompatibility = rootProject.ext.sourceCompatibilityVersion 13 | targetCompatibility = rootProject.ext.targetCompatibilityVersion 14 | 15 | //apply from: 'https://raw.githubusercontent.com/motcwang/Utils/master/bintray-publish/bintray-java.gradle' -------------------------------------------------------------------------------- /example-module/src/main/res/layout/activity_example.xml: -------------------------------------------------------------------------------- 1 | 2 |Description : RouterService.
10 | *Author : wangchao.
11 | *Date : 2017/11/10.
12 | *Time : 下午3:21.
13 | */ 14 | @Target(ElementType.TYPE) 15 | @Retention(RetentionPolicy.CLASS) 16 | public @interface RouterService { 17 | 18 | /** 19 | * RouterService name,eg. Scheme://Authority/Path, scheme is the name. 20 | */ 21 | String value(); 22 | } 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/internal/Utils.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter.internal; 2 | 3 | import im.wangchao.mrouter.RouteIntent; 4 | import im.wangchao.mrouter.RouterCallback; 5 | 6 | /** 7 | *Description : Utils.
8 | *Author : wangchao.
9 | *Date : 2017/12/7.
10 | *Time : 下午5:42.
11 | */ 12 | public class Utils { 13 | private Utils(){ 14 | throw new AssertionError(); 15 | } 16 | 17 | public static void callbackOrThrow(RouteIntent route, RouterCallback callback, Exception e) throws Exception { 18 | if (callback != null){ 19 | callback.onFailure(route, e); 20 | } else { 21 | throw e; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example-module/src/main/java/im/wangchao/examplemodule/ExampleProvider.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 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 : ExampleProvider.
10 | *Author : wangchao.
11 | *Date : 2017/11/24.
12 | *Time : 下午4:11.
13 | */ 14 | @Provider(name = "test", routerName = "example") 15 | public class ExampleProvider implements IProvider{ 16 | @Override public void onReceiver(RouteIntent route, RouterCallback callback) { 17 | callback.onSuccess(route.newBuilder().addParameter("result", "example-success").build()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example-module/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 | -------------------------------------------------------------------------------- /mrouter-annotations/src/main/java/im/wangchao/mrouter/annotations/Route.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | import static im.wangchao.mrouter.annotations.Constants.ROUTER_SERVICE_NAME; 9 | 10 | /** 11 | *Description : Route.
12 | *Author : wangchao.
13 | *Date : 2017/11/11.
14 | *Time : 下午2:00.
15 | */ 16 | @Target(ElementType.TYPE) 17 | @Retention(RetentionPolicy.CLASS) 18 | public @interface Route { 19 | 20 | /** 21 | * The path to this Route. 22 | */ 23 | String path(); 24 | 25 | /** 26 | * The Route that belongs to this RouterService. 27 | */ 28 | String routerName() default ROUTER_SERVICE_NAME; 29 | } 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrouter/src/androidTest/java/im/wangchao/mrouter/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 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.mrouter.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_module_one.xml: -------------------------------------------------------------------------------- 1 | 2 |Description : Provider.
12 | *Author : wangchao.
13 | *Date : 2017/11/17.
14 | *Time : 上午8:23.
15 | */ 16 | @Target(ElementType.TYPE) 17 | @Retention(RetentionPolicy.CLASS) 18 | public @interface Provider { 19 | 20 | /** 21 | * The name for this Provider. Scheme://Authority/Path, authority is the name. 22 | */ 23 | String name(); 24 | 25 | /** 26 | * The interceptor that belongs to this RouterService. 27 | */ 28 | String routerName() default ROUTER_SERVICE_NAME; 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 |Description : RouterPlugin.
12 | *Author : wangchao.
13 | *Date : 2017/11/22.
14 | *Time : 下午3:29.
15 | */ 16 | class RouterPlugin implements PluginDescription : Interceptor.
13 | *Author : wangchao.
14 | *Date : 2017/11/10.
15 | *Time : 下午3:43.
16 | */ 17 | @Target(ElementType.TYPE) 18 | @Retention(RetentionPolicy.CLASS) 19 | public @interface Interceptor { 20 | 21 | /** 22 | * The interceptor that belongs to this RouterService. 23 | */ 24 | String routerName() default ROUTER_SERVICE_NAME; 25 | 26 | /** 27 | * The priority of interceptor. The smaller the more priority. 28 | */ 29 | int priority() default INTERCEPTOR_DEFAULT_PRIORITY; 30 | } 31 | -------------------------------------------------------------------------------- /example-module/src/main/java/im/wangchao/examplemodule/ExampleActivity.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 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.Router; 9 | import im.wangchao.mrouter.annotations.Route; 10 | 11 | /** 12 | *Description : ExampleActivity.
13 | *Author : wangchao.
14 | *Date : 2017/11/24.
15 | *Time : 下午4:02.
16 | */ 17 | @Route(path = "/test", routerName = "example") 18 | public class ExampleActivity extends AppCompatActivity { 19 | 20 | @Override protected void onCreate(@Nullable Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_example); 23 | Log.e("wcwcwc", "receive params: v0 = " + getIntent().getStringExtra("v0")); 24 | 25 | findViewById(R.id.button).setOnClickListener(v -> { 26 | Router.push(this, "one:///one"); 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrouter/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 | -keep public class * implements im.wangchao.mrouter.ILoader{ public *;} 23 | -keep public class * implements im.wangchao.mrouter.IRouterService{ public *;} 24 | -keep public class * implements im.wangchao.mrouter.IInterceptor{ public *;} 25 | -keep public class * implements im.wangchao.mrouter.IProvider{ public *;} 26 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/ForwardServiceInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | *Description : ForwardServiceInterceptor.
7 | *Author : wangchao.
8 | *Date : 2017/11/20.
9 | *Time : 上午10:54.
10 | */ 11 | /*package*/ class ForwardServiceInterceptor implements IInterceptor { 12 | 13 | private final IRouterService mRouterService; 14 | 15 | ForwardServiceInterceptor(IRouterService routerService){ 16 | mRouterService = routerService; 17 | } 18 | 19 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 20 | mRouterService.push(context, chain.route(), requestCode, callback); 21 | return null; 22 | } 23 | 24 | @Override public RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback) { 25 | mRouterService.pop(context, chain.route(), resultCode, callback); 26 | return null; 27 | } 28 | 29 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mrouter/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | PROJ_GROUP=im.wangchao 20 | PROJ_VERSION=0.1.11 21 | PROJ_NAME=mrouter 22 | PROJ_WEBSITEURL= 23 | PROJ_ISSUETRACKERURL=https://github.com/motcwang/MRouter/issues 24 | PROJ_VCSURL=git@github.com:motcwang/MRouter.git 25 | PROJ_DESCRIPTION= 26 | PROJ_ARTIFACTID=mrouter 27 | PROJ_PACKAGING=aar 28 | 29 | DEVELOPER_ID=mot 30 | DEVELOPER_NAME=Wang Chao 31 | DEVELOPER_EMAIL=magician.of.technique@aliyun.com -------------------------------------------------------------------------------- /mrouter-plugin/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | PROJ_GROUP=im.wangchao 20 | PROJ_VERSION=0.1.0 21 | PROJ_NAME=mrouter-plugin 22 | PROJ_WEBSITEURL= 23 | PROJ_ISSUETRACKERURL=https://github.com/motcwang/MRouter/issues 24 | PROJ_VCSURL=git@github.com:motcwang/MRouter.git 25 | PROJ_DESCRIPTION= 26 | PROJ_ARTIFACTID=mrouter-plugin 27 | PROJ_PACKAGING=jar 28 | 29 | DEVELOPER_ID=mot 30 | DEVELOPER_NAME=Wang Chao 31 | DEVELOPER_EMAIL=magician.of.technique@aliyun.com -------------------------------------------------------------------------------- /mrouter-compiler/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | PROJ_GROUP=im.wangchao 20 | PROJ_VERSION=0.1.4 21 | PROJ_NAME=mrouter-compiler 22 | PROJ_WEBSITEURL= 23 | PROJ_ISSUETRACKERURL=https://github.com/motcwang/MRouter/issues 24 | PROJ_VCSURL=git@github.com:motcwang/MRouter.git 25 | PROJ_DESCRIPTION= 26 | PROJ_ARTIFACTID=mrouter-compiler 27 | PROJ_PACKAGING=jar 28 | 29 | DEVELOPER_ID=mot 30 | DEVELOPER_NAME=Wang Chao 31 | DEVELOPER_EMAIL=magician.of.technique@aliyun.com -------------------------------------------------------------------------------- /mrouter-annotations/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | PROJ_GROUP=im.wangchao 20 | PROJ_VERSION=0.1.3 21 | PROJ_NAME=mrouter-annotations 22 | PROJ_WEBSITEURL= 23 | PROJ_ISSUETRACKERURL=https://github.com/motcwang/MRouter/issues 24 | PROJ_VCSURL=git@github.com:motcwang/MRouter.git 25 | PROJ_DESCRIPTION= 26 | PROJ_ARTIFACTID=mrouter-annotations 27 | PROJ_PACKAGING=jar 28 | 29 | DEVELOPER_ID=mot 30 | DEVELOPER_NAME=Wang Chao 31 | DEVELOPER_EMAIL=magician.of.technique@aliyun.com -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_module_two.xml: -------------------------------------------------------------------------------- 1 | 2 |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 | -------------------------------------------------------------------------------- /example-module/src/main/java/im/wangchao/examplemodule/ExampleInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 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 : ExampleInterceptor.
13 | *Author : wangchao.
14 | *Date : 2017/11/24.
15 | *Time : 下午4:08.
16 | */ 17 | @Interceptor(routerName = "example") 18 | public class ExampleInterceptor implements IInterceptor { 19 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 20 | Log.e("wcwcwc", "ExampleInterceptor: 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", "ExampleInterceptor: 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", "ExampleInterceptor: request()"); 31 | return chain.proceed(chain.route(), callback); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example-module/src/main/java/im/wangchao/examplemodule/ExampleRouterService.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 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 : ExampleRouterService.
16 | *Author : wangchao.
17 | *Date : 2017/11/24.
18 | *Time : 下午4:07.
19 | */ 20 | @RouterService("example") 21 | public class ExampleRouterService implements IRouterService { 22 | 23 | @Override public void push(Context context, RouteIntent route, int requestCode, RouterCallback callback) { 24 | Log.e("wcwcwc", "ExampleRouterService : 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 | 34 | @Override public void pop(Context context, RouteIntent route, int resultCode, RouterCallback callback) { 35 | Log.e("wcwcwc", "Module one service: pop()"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example-module/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | minSdkVersion 15 7 | targetSdkVersion 26 8 | versionCode 1 9 | versionName "1.0" 10 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 11 | javaCompileOptions { 12 | annotationProcessorOptions { 13 | arguments = [ moduleName : project.getName() ] 14 | } 15 | } 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | compileOptions { 24 | sourceCompatibility rootProject.ext.sourceCompatibilityVersion 25 | targetCompatibility rootProject.ext.targetCompatibilityVersion 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | 32 | implementation 'com.android.support:appcompat-v7:26.1.0' 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 36 | 37 | // compileOnly 'im.wangchao:mrouter:0.1.3' 38 | // annotationProcessor 'im.wangchao:mrouter-compiler:0.1.2' 39 | 40 | compileOnly project(':mrouter') 41 | annotationProcessor project(':mrouter-compiler') 42 | } 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example-module/src/main/java/im/wangchao/examplemodule/GlobalExampleInterceptor.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.examplemodule; 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 : GlobalExampleInterceptor.
13 | *Author : wangchao.
14 | *Date : 2017/11/24.
15 | *Time : 下午4:09.
16 | */ 17 | @Interceptor(priority = 2) 18 | public class GlobalExampleInterceptor implements IInterceptor { 19 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 20 | Log.e("wcwcwc", "GlobalExampleInterceptor: push() priority = 2"); 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", "GlobalExampleInterceptor: pop() priority = 2"); 26 | return chain.proceed(context, chain.route(), resultCode, callback); 27 | } 28 | 29 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 30 | Log.e("wcwcwc", "GlobalExampleInterceptor: request() priority = 2"); 31 | return chain.proceed(chain.route(), callback); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mrouter-annotations/src/main/java/im/wangchao/mrouter/annotations/Constants.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter.annotations; 2 | 3 | /** 4 | *Description : Contants.
5 | *Author : wangchao.
6 | *Date : 2017/9/5.
7 | *Time : 下午1:21.
8 | */ 9 | public final class Constants { 10 | public static final String ROUTER_SERVICE_NAME = "router"; 11 | 12 | public static final String APP_MODULE_NAME = "App"; 13 | public static final String CLASSS_PACKAGE = "im.wangchao.mrouter.loaders"; 14 | public static final String CLASS_ILOADER_SUFFIX = "_RouterLoader_AutoGeneration"; 15 | 16 | public static final String CLASS_ILOADER = "im.wangchao.mrouter.ILoader"; 17 | public static final String CLASS_IINTERCEPTOR = "im.wangchao.mrouter.IInterceptor"; 18 | public static final String CLASS_IROUTERSERVICE = "im.wangchao.mrouter.IRouterService"; 19 | public static final String CLASS_IPROVIDER = "im.wangchao.mrouter.IProvider"; 20 | 21 | public static final int INTERCEPTOR_DEFAULT_PRIORITY = 999; 22 | 23 | public static String getClassName(String simpleName){ 24 | return CLASSS_PACKAGE.concat(".").concat(simpleName); 25 | } 26 | 27 | public static String getLoaderClassName(String moduleName) { 28 | return moduleName.toUpperCase().concat(CLASS_ILOADER_SUFFIX); 29 | } 30 | 31 | public static String getLoaderClassPath(String moduleName) { 32 | return CLASSS_PACKAGE.concat(".").concat(getLoaderClassName(moduleName)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/internal/RealInterceptorRequestChain.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter.internal; 2 | 3 | import java.util.List; 4 | 5 | import im.wangchao.mrouter.IInterceptor; 6 | import im.wangchao.mrouter.RouteIntent; 7 | import im.wangchao.mrouter.RouterCallback; 8 | 9 | /** 10 | *Description : RealInterceptorRequestChain.
11 | *Author : wangchao.
12 | *Date : 2017/11/17.
13 | *Time : 下午6:01.
14 | */ 15 | public final class RealInterceptorRequestChain implements IInterceptor.RequestChain { 16 | 17 | private final ListDescription : RealInterceptorPopChain.
13 | *Author : wangchao.
14 | *Date : 2017/11/17.
15 | *Time : 下午6:01.
16 | */ 17 | public final class RealInterceptorPopChain implements IInterceptor.PopChain { 18 | 19 | private final ListDescription : RealInterceptorChain.
13 | *Author : wangchao.
14 | *Date : 2017/11/17.
15 | *Time : 下午5:32.
16 | */ 17 | public final class RealInterceptorPushChain implements IInterceptor.PushChain { 18 | 19 | private final ListDescription : 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 | -------------------------------------------------------------------------------- /mrouter/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | minSdkVersion 15 7 | targetSdkVersion 26 8 | versionCode 1 9 | versionName "1.0" 10 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 11 | consumerProguardFiles 'proguard-rules.pro' 12 | javaCompileOptions { 13 | annotationProcessorOptions { 14 | arguments = [ moduleName : project.getName() ] 15 | } 16 | } 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | packagingOptions { 25 | exclude 'META-INF/services/javax.annotation.processing.Processor' 26 | } 27 | compileOptions { 28 | sourceCompatibility rootProject.ext.sourceCompatibilityVersion 29 | targetCompatibility rootProject.ext.targetCompatibilityVersion 30 | } 31 | lintOptions { 32 | textReport true 33 | textOutput 'stdout' 34 | } 35 | } 36 | 37 | dependencies { 38 | implementation fileTree(dir: 'libs', include: ['*.jar']) 39 | 40 | implementation 'com.android.support:appcompat-v7:26.1.0' 41 | testImplementation 'junit:junit:4.12' 42 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 43 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 44 | 45 | api 'im.wangchao:mrouter-annotations:0.1.3' 46 | // api project(':mrouter-annotations') 47 | // annotationProcessor project(':mrouter-compiler') 48 | } 49 | 50 | apply from: 'https://raw.githubusercontent.com/motcwang/Utils/master/bintray-publish/bintray.gradle' -------------------------------------------------------------------------------- /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/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/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 |Description : Interceptor.
7 | *Author : wangchao.
8 | *Date : 2017/11/10.
9 | *Time : 上午11:27.
10 | */ 11 | public interface IInterceptor { 12 | 13 | /** 14 | * 拦截 push 方法 15 | * @param context 当前页面 Context 16 | * @param chain push 拦截链 17 | * @param requestCode 请求码 18 | */ 19 | RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback); 20 | 21 | /** 22 | * 拦截 pop 方法 23 | * @param context 当前页面 Context 24 | * @param chain pop 拦截链 25 | * @param resultCode 返回码 26 | */ 27 | RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback); 28 | 29 | /** 30 | * 拦截 request 方法 31 | * @param chain request 拦截链 32 | * @param callback 回调函数 33 | */ 34 | RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback); 35 | 36 | interface PushChain { 37 | 38 | RouteIntent route(); 39 | 40 | /** 41 | * 继续执行下一个拦截器 42 | * 43 | * @param context 当前页面 Context 44 | * @param route RouteIntent 45 | * @param requestCode 请求码 46 | */ 47 | RouteIntent proceed(Context context, RouteIntent route, int requestCode, RouterCallback callback); 48 | } 49 | 50 | interface PopChain { 51 | 52 | RouteIntent route(); 53 | 54 | /** 55 | * 继续执行下一个拦截器 56 | * 57 | * @param context 当前页面 Context 58 | * @param route RouteIntent 59 | * @param resultCode 返回码 60 | */ 61 | RouteIntent proceed(Context context, RouteIntent route, int resultCode, RouterCallback callback); 62 | } 63 | 64 | interface RequestChain { 65 | 66 | RouteIntent route(); 67 | 68 | /** 69 | * 继续执行下一个拦截器 70 | * @param route RouteIntent 71 | * @param callback 回调函数 72 | */ 73 | RouteIntent proceed(RouteIntent route, RouterCallback callback); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/ILoader.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | *Description : ILoader.
8 | *Author : wangchao.
9 | *Date : 2017/11/11.
10 | *Time : 下午3:55.
11 | */ 12 | public interface ILoader { 13 | // 加载 Interceptor 14 | // 加载 RouterService 15 | // 加载 Route 16 | // 加载 IProvider 17 | 18 | /** 19 | * 加载所有 IInterceptor 到目标集合 20 | * @param target 需要加载数据的数据集,key:RouterService Name 21 | */ 22 | void loadInterceptors(MapDescription : Utils.
5 | *Author : wangchao.
6 | *Date : 2017/11/21.
7 | *Time : 下午4:07.
8 | */ 9 | public class Utils { 10 | // 11 | // /** 12 | // * 将该jar包解压到指定目录 13 | // * @param jarPath jar包的绝对路径 14 | // * @param destDirPath jar包解压后的保存路径 15 | // * @return 返回该jar包中包含的所有class的完整类名类名集合,其中一条数据如:com.aitski.hotpatch.Xxxx.class 16 | // */ 17 | // public static List unzipJar(String jarPath, String destDirPath) { 18 | // 19 | // List list = new ArrayList() 20 | // if (jarPath.endsWith('.jar')) { 21 | // 22 | // JarFile jarFile = new JarFile(jarPath) 23 | // EnumerationDescription : RouterClassVisitor.
14 | *Author : wangchao.
15 | *Date : 2017/11/22.
16 | *Time : 下午1:30.
17 | */ 18 | public class RouterClassVisitor extends ClassVisitor { 19 | private Project project; 20 | private ListDescription : ILoader Template.
11 | *Author : wangchao.
12 | *Date : 2017/11/15.
13 | *Time : 上午10:44.
14 | */ 15 | public class ILoaderImpl implements ILoader{ 16 | private static final ListDescription : RouterTransform.
18 | *Author : wangchao.
19 | *Date : 2017/11/22.
20 | *Time : 下午3:28.
21 | */ 22 | class RouterTransform extends Transform{ 23 | 24 | Project project 25 | 26 | RouterTransform(Project project){ 27 | this.project = project 28 | } 29 | 30 | @Override String getName() { 31 | return "RouterTransform" 32 | } 33 | 34 | @Override SetDescription : RealCallInterceptor.
20 | *Author : wangchao.
21 | *Date : 2017/11/18.
22 | *Time : 上午9:04.
23 | */ 24 | /*package*/ class RealCallInterceptor implements IInterceptor { 25 | 26 | @Override public RouteIntent pushInterceptor(Context context, PushChain chain, int requestCode, RouterCallback callback) { 27 | final RouteIntent route = chain.route(); 28 | final Intent intent = route.getPushIntent(context); 29 | 30 | if (requestCode > 0) { 31 | ActivityCompat.startActivityForResult((Activity) context, intent, requestCode, null); 32 | } else { 33 | ActivityCompat.startActivity(context, intent, null); 34 | } 35 | if (route.flags() == FLAG_ACTIVITY_PUSH_AND_POP && context instanceof Activity){ 36 | ((Activity) context).finish(); 37 | } 38 | 39 | if (callback != null){ 40 | callback.onSuccess(route); 41 | } 42 | return null; 43 | } 44 | 45 | @Override public RouteIntent popInterceptor(Context context, PopChain chain, int resultCode, RouterCallback callback) { 46 | final RouteIntent route = chain.route(); 47 | final Uri uri = route.uri(); 48 | // Scheme is RouterService name. 49 | final String scheme = uri.getScheme(); 50 | final String path = uri.getPath(); 51 | 52 | final Intent intent = route.getPopIntent(); 53 | 54 | if (TextUtils.equals(uri.toString(), DEFAULT_POP_URI)){ 55 | if (resultCode == RESULT_CANCELED){ 56 | final Runnable backPressed = () -> { 57 | android.app.FragmentManager fragmentManager = ((Activity) context).getFragmentManager(); 58 | 59 | if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && fragmentManager.isStateSaved()) 60 | || !fragmentManager.popBackStackImmediate()) { 61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 62 | ((Activity) context).finishAfterTransition(); 63 | } else { 64 | ((Activity) context).finish(); 65 | } 66 | } 67 | }; 68 | if (context instanceof FragmentActivity){ 69 | FragmentManager fragmentManager = ((FragmentActivity) context).getSupportFragmentManager(); 70 | final boolean isStateSaved = fragmentManager.isStateSaved(); 71 | if (isStateSaved && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) { 72 | // Older versions will throw an exception from the framework 73 | // FragmentManager.popBackStackImmediate(), so we'll just 74 | // return here. The Activity is likely already on its way out 75 | // since the fragmentManager has already been saved. 76 | return null; 77 | } 78 | if (isStateSaved || !fragmentManager.popBackStackImmediate()) { 79 | backPressed.run(); 80 | } 81 | } else { 82 | backPressed.run(); 83 | } 84 | } else { 85 | ((Activity) context).setResult(resultCode, intent); 86 | ((Activity) context).finish(); 87 | } 88 | } else { 89 | final String targetClass = RouterRepository.getTargetClass(scheme, path); 90 | if (TextUtils.isEmpty(targetClass)){ 91 | intent.setAction(Intent.ACTION_VIEW); 92 | intent.setData(uri); 93 | } else { 94 | ComponentName componentName = new ComponentName(context, targetClass); 95 | intent.setComponent(componentName); 96 | } 97 | context.startActivity(intent); 98 | } 99 | 100 | if (callback != null){ 101 | callback.onSuccess(route); 102 | } 103 | return null; 104 | } 105 | 106 | @Override public RouteIntent requestInterceptor(RequestChain chain, RouterCallback callback) { 107 | final RouteIntent route = chain.route(); 108 | final Uri uri = route.uri(); 109 | // Scheme is RouterService name. 110 | final String scheme = uri.getScheme(); 111 | final String authority = uri.getAuthority(); 112 | 113 | IProvider provider = RouterRepository.getProvider(scheme, authority); 114 | provider.onReceiver(route, callback); 115 | return null; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/RouterRepository.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.TreeMap; 10 | 11 | import im.wangchao.mrouter.annotations.Constants; 12 | 13 | import static im.wangchao.mrouter.RouterServiceCenter.NAME; 14 | 15 | /** 16 | *Description : RouterRepository.
17 | *Author : wangchao.
18 | *Date : 2017/11/15.
19 | *Time : 下午3:45.
20 | */ 21 | /*package*/ class RouterRepository { 22 | private static volatile RouterRepository sInstance; 23 | 24 | private MapDescription : Router. 11 | * app://module/path
12 | *Author : wangchao.
13 | *Date : 2017/11/10.
14 | *Time : 上午9:26.
15 | */ 16 | public final class Router { 17 | private static boolean sInit; 18 | 19 | private Router(){} 20 | 21 | /** 22 | * Router 模块初始化方法,一般在 Application::onCreate 中调用 23 | */ 24 | public static void init(){ 25 | RouterRepository.init(); 26 | sInit = true; 27 | } 28 | 29 | public static void push(Context context, String uri){ 30 | push(context, uri, null, null); 31 | } 32 | 33 | public static void push(Context context, String uri, RouterCallback callback){ 34 | push(context, uri, null, callback); 35 | } 36 | 37 | public static void push(Context context, String uri, Bundle bundle){ 38 | push(context, uri, bundle, -1); 39 | } 40 | 41 | public static void push(Context context, String uri, Bundle bundle, RouterCallback callback){ 42 | push(context, uri, bundle, -1, callback); 43 | } 44 | 45 | public static void push(Context context, String uri, int flags){ 46 | push(context, uri, null, flags); 47 | } 48 | 49 | public static void push(Context context, String uri, int flags, RouterCallback callback){ 50 | push(context, uri, null, flags, callback); 51 | } 52 | 53 | public static void push(Context context, String uri, Bundle bundle, int flags){ 54 | pushForResult(context, uri, bundle, flags, -1); 55 | } 56 | 57 | public static void push(Context context, String uri, Bundle bundle, int flags, RouterCallback callback){ 58 | pushForResult(context, uri, bundle, flags, -1, callback); 59 | } 60 | 61 | public static void pushForResult(Context context, String uri, int requestCode){ 62 | pushForResult(context, uri, null, -1, requestCode); 63 | } 64 | 65 | public static void pushForResult(Context context, String uri, int requestCode, RouterCallback callback){ 66 | pushForResult(context, uri, null, -1, requestCode, callback); 67 | } 68 | 69 | public static void pushForResult(Context context, String uri, Bundle bundle, int requestCode){ 70 | pushForResult(context, uri, bundle, -1, requestCode); 71 | } 72 | 73 | public static void pushForResult(Context context, String uri, Bundle bundle, int requestCode, RouterCallback callback){ 74 | pushForResult(context, uri, bundle, -1, requestCode, callback); 75 | } 76 | 77 | public static void pushForResult(Context context, String uri, int requestCode, int flags){ 78 | pushForResult(context, uri, null, flags, requestCode); 79 | } 80 | 81 | public static void pushForResult(Context context, String uri, int requestCode, int flags, RouterCallback callback){ 82 | pushForResult(context, uri, null, flags, requestCode, callback); 83 | } 84 | 85 | public static void pushForResult(Context context, String uri, Bundle bundle, int requestCode, int flags){ 86 | push(context, RouteIntent.of(uri, bundle, flags), requestCode, null); 87 | } 88 | 89 | public static void pushForResult(Context context, String uri, Bundle bundle, int requestCode, int flags, RouterCallback callback){ 90 | push(context, RouteIntent.of(uri, bundle, flags), requestCode, callback); 91 | } 92 | 93 | public static void pop(Context context){ 94 | pop(context, DEFAULT_POP_URI, null, Activity.RESULT_CANCELED); 95 | } 96 | 97 | public static void pop(Context context, RouterCallback callback){ 98 | pop(context, DEFAULT_POP_URI, null, Activity.RESULT_CANCELED, callback); 99 | } 100 | 101 | public static void pop(Context context, String uri, Bundle bundle){ 102 | pop(context, uri, bundle, Activity.RESULT_OK); 103 | } 104 | 105 | public static void pop(Context context, String uri, Bundle bundle, RouterCallback callback){ 106 | pop(context, uri, bundle, Activity.RESULT_OK, callback); 107 | } 108 | 109 | public static void pop(Context context, String uri, int resultCode){ 110 | pop(context, uri, null, resultCode); 111 | } 112 | 113 | public static void pop(Context context, Bundle bundle, int resultCode){ 114 | pop(context, DEFAULT_POP_URI, bundle, resultCode); 115 | } 116 | 117 | public static void pop(Context context, Bundle bundle, int resultCode, RouterCallback callback){ 118 | pop(context, DEFAULT_POP_URI, bundle, resultCode, callback); 119 | } 120 | 121 | public static void pop(Context context, String uri, Bundle bundle, int resultCode){ 122 | pop(context, RouteIntent.of(uri, bundle), resultCode, null); 123 | } 124 | 125 | public static void pop(Context context, String uri, Bundle bundle, int resultCode, RouterCallback callback){ 126 | pop(context, RouteIntent.of(uri, bundle), resultCode, callback); 127 | } 128 | 129 | public static void request(String uri){ 130 | request(uri, null, null); 131 | } 132 | 133 | public static void request(String uri, RouterCallback callback){ 134 | request(uri, null, callback); 135 | } 136 | 137 | public static void request(String uri, Bundle bundle){ 138 | request(uri, bundle, null); 139 | } 140 | 141 | public static void request(String uri, Bundle bundle, RouterCallback callback){ 142 | request(RouteIntent.of(uri, bundle), callback); 143 | } 144 | 145 | /** 146 | * 当前页面入栈 147 | * 148 | * @param context 当前页面 Context 149 | * @param route RouteIntent 150 | * @param requestCode 请求码 151 | */ 152 | public static void push(Context context, RouteIntent route, int requestCode, RouterCallback callback){ 153 | check(); 154 | RouterRepository.getRouterServiceCenter().push(context, route, requestCode, callback); 155 | } 156 | 157 | /** 158 | * 当前页面出栈 159 | * 160 | * @param context 当前页面 Context 161 | * @param route RouteIntent 162 | * @param resultCode 响应码 163 | */ 164 | public static void pop(Context context, RouteIntent route, int resultCode, RouterCallback callback){ 165 | check(); 166 | RouterRepository.getRouterServiceCenter().pop(context, route, resultCode, callback); 167 | } 168 | 169 | /** 170 | * 模块之间请求数据 171 | * 172 | * @param route RouteIntent 173 | * @param callback RouterCallback 174 | */ 175 | public static void request(RouteIntent route, RouterCallback callback){ 176 | check(); 177 | RouterRepository.getRouterServiceCenter().onReceiver(route, callback); 178 | } 179 | 180 | private static void check(){ 181 | if (!sInit){ 182 | throw new RuntimeException("You must invoke Router.init() first."); 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /mrouter/src/main/java/im/wangchao/mrouter/RouteIntent.java: -------------------------------------------------------------------------------- 1 | package im.wangchao.mrouter; 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.Bundle; 9 | import android.text.TextUtils; 10 | 11 | import java.util.Set; 12 | 13 | import im.wangchao.mrouter.annotations.Constants; 14 | 15 | /** 16 | *Description : Route.
17 | *Author : wangchao.
18 | *Date : 2017/11/10.
19 | *Time : 上午10:41.
20 | */ 21 | public final class RouteIntent { 22 | public static final String DEFAULT_POP_PATH = "/finish"; 23 | public static final String DEFAULT_POP_URI = Constants.ROUTER_SERVICE_NAME.concat("://").concat(DEFAULT_POP_PATH); 24 | 25 | public static final int FLAG_ACTIVITY_PUSH_AND_POP = -2; 26 | public static final int FLAG_CLEAR_CURRENT_TASK_AND_NEW = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK; 27 | 28 | // uri 29 | private final Uri mUri; 30 | // params 31 | private final Bundle mBundle; 32 | // start/pop flags 33 | private final int mFlags; 34 | // target class, maybe null. 35 | private final String mTargetClass; 36 | 37 | public static RouteIntent of(String uri){ 38 | return new Builder().uri(uri).build(); 39 | } 40 | 41 | public static RouteIntent of(String uri, Bundle bundle){ 42 | return new Builder().uri(uri).bundle(bundle).build(); 43 | } 44 | 45 | public static RouteIntent of(String uri, int flags){ 46 | return new Builder().uri(uri).flags(flags).build(); 47 | } 48 | 49 | public static RouteIntent of(String uri, Bundle bundle, int flags){ 50 | return new Builder().uri(uri).bundle(bundle).flags(flags).build(); 51 | } 52 | 53 | public static RouteIntent popIntent(){ 54 | return popIntent(null); 55 | } 56 | 57 | public static RouteIntent popIntent(Bundle bundle){ 58 | return new Builder().uri(DEFAULT_POP_URI).bundle(bundle).build(); 59 | } 60 | 61 | private RouteIntent(Builder builder){ 62 | mUri = builder.mUri; 63 | mBundle = builder.mBundle; 64 | mFlags = builder.mFlags; 65 | mTargetClass = builder.mTargetClass; 66 | } 67 | 68 | public Uri uri(){ 69 | return mUri; 70 | } 71 | 72 | public Bundle bundle(){ 73 | return mBundle; 74 | } 75 | 76 | public int flags(){ 77 | return mFlags; 78 | } 79 | 80 | public String targetClass(){ 81 | return mTargetClass; 82 | } 83 | 84 | public Intent getPushIntent(Context context){ 85 | Intent intent = new Intent(); 86 | if (TextUtils.isEmpty(mTargetClass)){ 87 | intent.setAction(Intent.ACTION_VIEW); 88 | intent.setData(mUri); 89 | } else { 90 | ComponentName component = new ComponentName(context, mTargetClass); 91 | intent.setComponent(component); 92 | } 93 | intent.putExtras(mBundle); 94 | // Set flags. 95 | if (-1 != mFlags && FLAG_ACTIVITY_PUSH_AND_POP != mFlags) { 96 | intent.setFlags(mFlags); 97 | } else if (!(context instanceof Activity)) { 98 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 99 | } 100 | 101 | return intent; 102 | } 103 | 104 | public Intent getPopIntent(){ 105 | Intent intent = new Intent(); 106 | intent.putExtras(mBundle); 107 | if (-1 != mFlags){ 108 | intent.addFlags(mFlags); 109 | } else { 110 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 111 | } 112 | return intent; 113 | } 114 | 115 | public Builder newBuilder(){ 116 | return new Builder(this); 117 | } 118 | 119 | public static final class Builder { 120 | Uri mUri; 121 | Bundle mBundle; 122 | int mFlags; 123 | String mTargetClass; 124 | boolean mIsUriChanged; 125 | 126 | public Builder(){ 127 | mBundle = new Bundle(); 128 | mFlags = -1; 129 | mTargetClass = null; 130 | mIsUriChanged = false; 131 | } 132 | 133 | private Builder(RouteIntent route){ 134 | mUri = route.mUri; 135 | mBundle = route.mBundle; 136 | mFlags = route.mFlags; 137 | mTargetClass = route.mTargetClass; 138 | mIsUriChanged = false; 139 | } 140 | 141 | public Builder uri(String uri){ 142 | mUri = Uri.parse(uri); 143 | mIsUriChanged = true; 144 | return this; 145 | } 146 | 147 | public Builder uri(Uri uri){ 148 | mUri = uri; 149 | mIsUriChanged = true; 150 | return this; 151 | } 152 | 153 | public Builder bundle(Bundle bundle){ 154 | if (bundle != null){ 155 | mBundle = bundle; 156 | } 157 | return this; 158 | } 159 | 160 | public Builder flags(int flags){ 161 | mFlags = flags; 162 | return this; 163 | } 164 | 165 | public Builder targetClass(String targetClass){ 166 | mTargetClass = targetClass; 167 | return this; 168 | } 169 | 170 | public Builder addAll(Bundle bundle){ 171 | if (bundle != null){ 172 | mBundle.putAll(bundle); 173 | } 174 | return this; 175 | } 176 | 177 | public Builder addParameter(String key, Bundle value){ 178 | mBundle.putBundle(key, value); 179 | return this; 180 | } 181 | 182 | public Builder addParameter(String key, String value){ 183 | mBundle.putString(key, value); 184 | return this; 185 | } 186 | 187 | public Builder addParameter(String key, float value){ 188 | mBundle.putFloat(key, value); 189 | return this; 190 | } 191 | 192 | public Builder addParameter(String key, int value){ 193 | mBundle.putInt(key, value); 194 | return this; 195 | } 196 | 197 | public Builder addParameter(String key, double value){ 198 | mBundle.putDouble(key, value); 199 | return this; 200 | } 201 | 202 | public Builder addParameter(String key, long value){ 203 | mBundle.putLong(key, value); 204 | return this; 205 | } 206 | 207 | public RouteIntent build(){ 208 | if (mUri == null) throw new NullPointerException("Route.Builder mUri can not be null."); 209 | if (mBundle == null) throw new NullPointerException("Route.Builder mBundle can not be null."); 210 | 211 | if (mIsUriChanged){ 212 | SetDescription : RouterProcessor.
29 | *Author : wangchao.
30 | *Date : 2017/11/11.
31 | *Time : 下午3:17.
32 | */ 33 | @AutoService(Processor.class) 34 | public class RouterLoaderProcessor extends AbstractProcessor { 35 | 36 | private Elements mElementUtils; 37 | private Filer mFiler; 38 | private String mModuleName; 39 | 40 | @Override public synchronized void init(ProcessingEnvironment processingEnv) { 41 | super.init(processingEnv); 42 | mElementUtils = processingEnv.getElementUtils(); 43 | mFiler = processingEnv.getFiler(); 44 | 45 | // javaCompileOptions{ 46 | // annotationProcessorOptions{ 47 | // arguments = [ moduleName : project.getName(), appModule : "1" ] // the module is Application 48 | // } 49 | // } 50 | MapDescription : RouterServiceCenter.
18 | *Author : wangchao.
19 | *Date : 2017/11/10.
20 | *Time : 下午1:47.
21 | */ 22 | /*package*/ class RouterServiceCenter implements IRouterService, IProvider{ 23 | static final String NAME = Constants.ROUTER_SERVICE_NAME; 24 | 25 | @Override public void push(Context context, RouteIntent route, int requestCode, RouterCallback callback) { 26 | try { 27 | final Uri uri = route.uri(); 28 | // Scheme is RouterService name. 29 | final String scheme = uri.getScheme(); 30 | final String path = uri.getPath(); 31 | 32 | ListDescription : BuildClass.
33 | *Author : wangchao.
34 | *Date : 2017/9/5.
35 | *Time : 上午11:15.
36 | */ 37 | /*package*/ class BuildLoaderClass { 38 | 39 | private static class InterceptorPriority{ 40 | String cls; 41 | int priority = INTERCEPTOR_DEFAULT_PRIORITY; 42 | InterceptorPriority(int priority, String cls){ 43 | this.priority = priority; 44 | this.cls = cls; 45 | } 46 | 47 | int getPriority(){ 48 | return priority; 49 | } 50 | } 51 | 52 | private static final String FIELD_ROUTES = "mRoutes"; 53 | private static final String FIELD_ROUTERSERVICES = "mRouterServices"; 54 | private static final String FIELD_INTERCEPTORS = "mInterceptors"; 55 | private static final String FIELD_PROVIDERS = "mProviders"; 56 | private static final String FIELD_LOADERS = "mLoaders"; 57 | 58 | private Map