├── .gitignore
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── blue
│ │ └── hellorouter
│ │ ├── BaseApplication.kt
│ │ ├── MainActivity.kt
│ │ └── interceptor
│ │ ├── LoginInterceptor.kt
│ │ └── NetworkInterceptor.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ └── activity_main.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
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── module-a
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── blue
│ │ └── modulea
│ │ ├── java
│ │ └── JavaModuleActivity.java
│ │ └── kotlin
│ │ └── KotlinModuleActivity.kt
│ └── res
│ ├── layout
│ └── modulea_activity_main.xml
│ └── values
│ └── strings.xml
├── module-b
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── blue
│ │ └── moduleb
│ │ ├── ModuleBActivity.kt
│ │ └── service
│ │ ├── java
│ │ └── TestBRouterService.java
│ │ └── kotlin
│ │ └── TestBRouterService.kt
│ └── res
│ ├── layout
│ └── moduleb_activity_main.xml
│ └── values
│ └── strings.xml
├── settings.gradle
├── xrouter-annotation
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── blue
│ └── xrouter
│ └── annotation
│ ├── Router.java
│ ├── RouterApp.java
│ └── RouterInterceptor.java
├── xrouter-compileonly
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── blue
│ └── xrouter
│ └── XRouterAppInit.java
├── xrouter-compiler
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── blue
│ └── xrouter
│ └── compiler
│ └── RouterProcessor.java
└── xrouter-core
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── blue
│ └── xrouter
│ ├── XRouter.kt
│ ├── XRouterAsyncMethod.kt
│ ├── XRouterCallBack.kt
│ ├── XRouterConfig.kt
│ ├── XRouterInterceptor.kt
│ ├── XRouterInterceptorCallback.kt
│ ├── XRouterParams.kt
│ ├── XRouterResult.kt
│ ├── XRouterSyncMethod.kt
│ └── tools
│ └── Logger.kt
└── res
└── values
└── strings.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | /.idea
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-XRouter
2 | [[点击查看中文版]](https://www.jianshu.com/p/15d8cc6cf19b)
3 | This is a lightweight and simple routing framework that provides jump routing and method routing.
4 | [](https://android-arsenal.com/api?level=14) [](https://github.com/michaelxs/Android-XRouter/blob/master/LICENSE)
5 | ## Feature
6 | - Based on `Kotlin`
7 | - Support free assembly of different modules to achieve differential compilation
8 | - Provide page routing and interceptors
9 | - Provide method routing including: synchronous and asynchronous
10 | - Simple and convenient
11 | - No reflection, high efficiency
12 | - Super lightweight, less than 42 KB
13 | ## Setup
14 | 1.Add jcenter repository to root's build.gradle
15 | ```groovy
16 | allprojects {
17 | repositories {
18 | ...
19 | jcenter()
20 | }
21 | }
22 | ```
23 | 2.Apply kapt in app's build.gradle and module's build.gradle
24 | ```groovy
25 | ...
26 | apply plugin: 'kotlin-kapt'
27 | ```
28 | 3.Add dependencies in app's build.gradle and module's build.gradle (please use the latest version)
29 | ```groovy
30 | dependencies {
31 | ...
32 | implementation 'com.xuyefeng:xrouter-core:1.1.3'
33 | kapt 'com.xuyefeng:xrouter-compiler:1.0.6'
34 | }
35 | ```
36 | 4.Register routing in app's build.gradle and module's build.gradle
37 | ```groovy
38 | kapt {
39 | arguments {
40 | arg("XRouterModule", project.getName())
41 | }
42 | }
43 | ```
44 | 5.Register routing app in app's build.gradle
45 | ```groovy
46 | kapt {
47 | arguments {
48 | arg("XRouterApp", project.getName() + ",modulea,moduleb")
49 | }
50 | }
51 | ```
52 | - The Routing App consists of three routing modules, app, module, and moduleb. Corresponding to the project name of the route module registered in step 4
53 | - Here you can dynamically set XRouterApp based on a freely assembled module
54 |
55 | 6.Initialize XRouter
56 | ```kotlin
57 | @RouterApp
58 | class BaseApplication : Application() {
59 |
60 | override fun onCreate() {
61 | super.onCreate()
62 | XRouter.init(this, BuildConfig.DEBUG)
63 | }
64 | }
65 | ```
66 | - It is recommended to initialize in Application and add annotations @RouterApp
67 | - In debug mode, you can use XRouter as a tag to filter log information
68 | 
69 | ## Usage
70 | #### Page routing
71 | 1.Annotation page (supports one page for multiple routing addresses)
72 | ```kotlin
73 | @Router("www.baidu.com")
74 | class MainActivity : AppCompatActivity()
75 |
76 | @Router("www.baidu.com", "www.google.com")
77 | class MainActivity : AppCompatActivity()
78 | ```
79 | 2.Jump page
80 | ```kotlin
81 | // Common jump
82 | XRouter.with(context).target("www.google.com").jump()
83 |
84 | // Custom intentFlags
85 | XRouter.with(context)
86 | .target("www.google.com")
87 | .intentFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
88 | .jump()
89 |
90 | // Custom jump animation
91 | XRouter.with(context)
92 | .target("www.google.com")
93 | .transition(android.R.anim.fade_in, android.R.anim.fade_out)
94 | .jump()
95 |
96 | // Splicing parameters by url
97 | XRouter.with(context)
98 | .target("www.google.com?name=blue&age=18")
99 | .jump()
100 |
101 | // Passing parameters through the bundle
102 | XRouter.with(context)
103 | .target("www.google.com")
104 | .data("name", "blue")
105 | .data("age", 18)
106 | .data(Bundle())
107 | .jump()
108 |
109 | // StartActivityForResult
110 | XRouter.with(context)
111 | .target("www.google.com")
112 | .requestCode(1001)
113 | .jump()
114 |
115 | // Routing results, only concerned about success
116 | XRouter.with(context)
117 | .target("www.google.com")
118 | .jump {
119 | // jump success to do sth
120 | }
121 |
122 | // Routing results, only concerned with failure
123 | XRouter.with(context)
124 | .target("www.google.com")
125 | .jump({
126 | // jump failure to do sth
127 | })
128 |
129 | // Routing results, including failures and successes
130 | XRouter.with(context)
131 | .target("www.google.com")
132 | .jump({
133 | // jump failure to do sth
134 | }, {
135 | // jump success to do sth
136 | })
137 | ```
138 | 3.Interceptor
139 | ```kotlin
140 | @RouterInterceptor(priority = 8)
141 | public class LoginInterceptor implements XRouterInterceptor {
142 | @Override
143 | public void onInit(@NotNull Context context) {
144 | // do something in application init
145 | }
146 | @Override
147 | public void onProcess(@NotNull XRouterInterceptorCallback callback) {
148 | // check login status
149 | ...
150 | // check success
151 | callback.onContinue();
152 | // or check failure
153 | callback.onIntercept("check login error");
154 | }
155 | }
156 | ```
157 | - The parameter priority determines the priority of the interceptor. The default is 5. The higher the value, the higher the priority
158 | - Multiple interceptors can be defined, executed sequentially according to priority
159 | - The onInit method is called when the XRouter is initialized and can be used for interceptor initialization
160 | - The onProcess method is called in the page route and can be used for page blocking. The classic scenario is that the login status needs to be detected during the page routing process. If the login status is invalid, the original route is terminated and changed to jump to the login interface
161 | #### Method routing
162 | 1.Annotation method
163 | ```kotlin
164 | @Router("toast")
165 | fun toast(context: Context, routerParams: XRouterParams): XRouterResult {
166 | Toast.makeText(context, "toast from other module", Toast.LENGTH_SHORT).show()
167 | return XRouterResult.Builder().build()
168 | }
169 |
170 | @Router("getSum", async = true)
171 | fun getSum(context: Context, routerParams: XRouterParams, callback: XRouterCallback?) {
172 | // get object data
173 | val fragment = routerParams.obj as Fragment
174 | // get data
175 | val a = routerParams.data.getInt("a")
176 | val b = routerParams.data.getInt("b")
177 | ...
178 | val sum = a + b
179 | val result = XRouterResult.Builder().data("sum", sum).obj(fragment).build()
180 | callback?.onRouterSuccess(result)
181 | // or
182 | callback?.onRouterError(result)
183 | }
184 | ```
185 | - Annotated methods need to be global static methods
186 | - The name of the annotation can be different from the method name, the name of the annotation is used to find the target method, and the method name is used to execute the method
187 | - The default is synchronous routing. You can enable asynchronous routing through the annotation parameter async
188 | - The parameters received by all synchronous routes are Context and XRouterParams. Please keep the same way
189 | - The parameters received by all asynchronous routes are Context, XRouterParams, and XRouterCallback. Please keep the same syntax
190 | - The parameters passed by the route can be obtained through XRouterParams. The parameters of the route result can be set by XRouterResult. Both pass the parameters by bundle, and obj passes the object data
191 |
192 | 2.Call method
193 | ```kotlin
194 | // No-parameter routing
195 | XRouter.with(context).target("toast").route()
196 |
197 | // Passing parameters through the bundle
198 | XRouter.with(context)
199 | .target("doSomething")
200 | .data("name", "blue")
201 | .data("age", 18)
202 | .route()
203 |
204 | // Object passing
205 | XRouter.with(context)
206 | .target("doSomething")
207 | .obj(Fragment())
208 | .route()
209 |
210 | // Synchronous route acquisition result
211 | val result = XRouter.with(context)
212 | .target("getSum")
213 | .data("a", 1)
214 | .data("b", 2)
215 | .route()
216 |
217 | // Asynchronous routing gets results, only concerned about success
218 | XRouter.with(context)
219 | .target("getSum")
220 | .data("a", 1)
221 | .data("b", 2)
222 | .route {
223 | // get params
224 | val sum = it.getData().getInt("sum")
225 | val fragment = it.getObj() as Fragment
226 | // route success to do sth
227 | }
228 |
229 | // Asynchronous routing gets results, only cares about failure
230 | XRouter.with(context)
231 | .target("getSum")
232 | .data("a", 1)
233 | .data("b", 2)
234 | .route ({
235 | // route failure to do sth
236 | })
237 |
238 | // Asynchronous route gets the result, including failure and success
239 | XRouter.with(context)
240 | .target("getSum")
241 | .data("a", 1)
242 | .data("b", 2)
243 | .route ({
244 | // route failure to do sth
245 | },{
246 | // get params
247 | val sum = it.getData().getInt("sum")
248 | val fragment = it.getObj() as Fragment
249 | // route success to do sth
250 | })
251 | ```
252 | #### ProGuard
253 | ```
254 | -keep class com.blue.xrouter.** {*;}
255 | -keep interface com.blue.xrouter.** {*;}
256 | ```
257 | ## License
258 | [Apache-2.0](https://opensource.org/licenses/Apache-2.0)
259 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion 26
8 | defaultConfig {
9 | applicationId "com.blue.hellorouter"
10 | minSdkVersion 14
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | dataBinding {
22 | enabled = true
23 | }
24 |
25 | flavorDimensions "default"
26 | productFlavors {
27 | dev {
28 | minSdkVersion 21
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation fileTree(dir: 'libs', include: ['*.jar'])
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
36 | implementation 'com.android.support:appcompat-v7:26.1.0'
37 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
38 | // databinding
39 | kapt "com.android.databinding:compiler:3.0.0"
40 | implementation project(':xrouter-core')
41 | kapt project(':xrouter-compiler')
42 |
43 | switch (BUILD_TYPE) {
44 | case "all":
45 | println "=====implementation project : module-a、module-b"
46 | implementation project(':module-a')
47 | implementation project(':module-b')
48 | break
49 | case "a":
50 | println "=====implementation project : module-a"
51 | implementation project(':module-a')
52 | break
53 | case "b":
54 | println "=====implementation project : module-b"
55 | implementation project(':module-b')
56 | break
57 | }
58 | }
59 |
60 | kapt {
61 | arguments {
62 | arg("XRouterModule", project.getName())
63 | switch (BUILD_TYPE) {
64 | case "all":
65 | arg("XRouterApp", project.getName() + ",modulea,moduleb")
66 | break
67 | case "a":
68 | arg("XRouterApp", "modulea")
69 | break
70 | case "b":
71 | arg("XRouterApp", "moduleb")
72 | break
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blue/hellorouter/BaseApplication.kt:
--------------------------------------------------------------------------------
1 | package com.blue.hellorouter
2 |
3 | import android.app.Application
4 | import com.blue.xrouter.XRouter
5 | import com.blue.xrouter.annotation.RouterApp
6 |
7 | /**
8 | * Created by blue on 2018/10/9.
9 | */
10 | @RouterApp
11 | class BaseApplication : Application() {
12 |
13 | override fun onCreate() {
14 | super.onCreate()
15 | XRouter.init(this, BuildConfig.DEBUG)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/blue/hellorouter/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.blue.hellorouter
2 |
3 | import android.os.Bundle
4 | import android.support.v7.app.AppCompatActivity
5 | import com.blue.xrouter.XRouter
6 | import kotlinx.android.synthetic.main.activity_main.*
7 |
8 | class MainActivity : AppCompatActivity() {
9 |
10 | override fun onCreate(savedInstanceState: Bundle?) {
11 | super.onCreate(savedInstanceState)
12 | setContentView(R.layout.activity_main)
13 |
14 | // java demo
15 | btn.setOnClickListener {
16 | // start activity in module routera
17 | XRouter.with(this)
18 | .target("www.JavaModuleActivity.com")
19 | .jump()
20 | }
21 |
22 | // kotlin demo
23 | btn2.setOnClickListener {
24 | // start activity in module routera
25 | XRouter.with(this)
26 | .target("www.KotlinModuleActivity.com")
27 | .jump()
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/blue/hellorouter/interceptor/LoginInterceptor.kt:
--------------------------------------------------------------------------------
1 | package com.blue.hellorouter.interceptor
2 |
3 | import android.content.Context
4 | import com.blue.xrouter.XRouterInterceptor
5 | import com.blue.xrouter.XRouterInterceptorCallback
6 | import com.blue.xrouter.annotation.RouterInterceptor
7 |
8 | /**
9 | * Created by blue on 2018/10/30.
10 | */
11 | @RouterInterceptor()
12 | class LoginInterceptor : XRouterInterceptor {
13 |
14 | override fun onInit(context: Context) {
15 | // init something
16 | }
17 |
18 | override fun onProcess(callback: XRouterInterceptorCallback) {
19 | // check login status
20 | callback.onContinue()
21 | // callback.onIntercept("check login error")
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/blue/hellorouter/interceptor/NetworkInterceptor.kt:
--------------------------------------------------------------------------------
1 | package com.blue.hellorouter.interceptor
2 |
3 | import android.content.Context
4 | import com.blue.xrouter.XRouterInterceptor
5 | import com.blue.xrouter.XRouterInterceptorCallback
6 | import com.blue.xrouter.annotation.RouterInterceptor
7 |
8 | /**
9 | * Created by blue on 2018/10/30.
10 | */
11 | @RouterInterceptor(priority = 8)
12 | class NetworkInterceptor : XRouterInterceptor {
13 |
14 | override fun onInit(context: Context) {
15 | // init something
16 | }
17 |
18 | override fun onProcess(callback: XRouterInterceptorCallback) {
19 | // check network status
20 | callback.onContinue()
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/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 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
17 |
18 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HelloRouter
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | BUILD_TYPE = getBuildType()
3 | }
4 |
5 | def getBuildType() {
6 | Object object = project.findProperty("type")
7 | String result = "nothing"
8 | if (object != null) {
9 | result = object.toString()
10 | }
11 | println "=====Current build type : $result"
12 | return result
13 | }
14 |
15 | buildscript {
16 | ext.kotlin_version = '1.2.31'
17 | repositories {
18 | google()
19 | jcenter()
20 | }
21 | dependencies {
22 | classpath 'com.android.tools.build:gradle:3.0.1'
23 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
24 | classpath 'com.novoda:bintray-release:0.5.0'
25 |
26 | // NOTE: Do not place your application dependencies here; they belong
27 | // in the individual module build.gradle files
28 | }
29 | }
30 |
31 | allprojects {
32 | repositories {
33 | google()
34 | jcenter()
35 | }
36 | }
37 |
38 | task clean(type: Delete) {
39 | delete rootProject.buildDir
40 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelxs/Android-XRouter/ce1167c08253aeac69a1ee8e935c10c640a14104/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Oct 09 16:55:00 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/module-a/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module-a/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion 26
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | dataBinding {
24 | enabled = true
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(include: ['*.jar'], dir: 'libs')
30 | implementation 'com.android.support:appcompat-v7:26.1.0'
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | // databinding
33 | kapt "com.android.databinding:compiler:3.0.0"
34 | implementation project(':xrouter-core')
35 | kapt project(':xrouter-compiler')
36 | }
37 |
38 | kapt {
39 | arguments {
40 | arg("XRouterModule", "modulea")
41 | }
42 | }
--------------------------------------------------------------------------------
/module-a/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 |
--------------------------------------------------------------------------------
/module-a/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/module-a/src/main/java/com/blue/modulea/java/JavaModuleActivity.java:
--------------------------------------------------------------------------------
1 | package com.blue.modulea.java;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.databinding.DataBindingUtil;
7 | import android.os.Bundle;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.view.View;
12 | import android.widget.AdapterView;
13 | import android.widget.ArrayAdapter;
14 | import android.widget.Toast;
15 |
16 | import com.blue.modulea.R;
17 | import com.blue.modulea.databinding.ModuleaActivityMainBinding;
18 | import com.blue.xrouter.XRouter;
19 | import com.blue.xrouter.XRouterCallback;
20 | import com.blue.xrouter.XRouterResult;
21 | import com.blue.xrouter.annotation.Router;
22 |
23 | import org.jetbrains.annotations.NotNull;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * Created by blue on 2018/10/12.
30 | */
31 | @Router("www.JavaModuleActivity.com")
32 | public class JavaModuleActivity extends AppCompatActivity {
33 |
34 | private ModuleaActivityMainBinding binding;
35 | private Context context;
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | binding = DataBindingUtil.setContentView(this, R.layout.modulea_activity_main);
41 |
42 | context = this;
43 |
44 | ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getListData());
45 | binding.listView.setAdapter(adapter);
46 | binding.listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
47 | @Override
48 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
49 | switch (position) {
50 | case 0:
51 | XRouter.with(context)
52 | .target("www.ModuleBActivity.com")
53 | .intentFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
54 | .jump();
55 | break;
56 | case 1:
57 | XRouter.with(context)
58 | .target("hello.world")
59 | .transition(android.R.anim.fade_in, android.R.anim.fade_out)
60 | .jump();
61 | break;
62 | case 2:
63 | XRouter.with(context)
64 | .target("www.ModuleBActivity.com?name=tom&age=24")
65 | .jump();
66 | break;
67 | case 3:
68 | XRouter.with(context)
69 | .target("hello.world")
70 | .data("name", "blue")
71 | .data("age", 18)
72 | .jump();
73 | break;
74 | case 4:
75 | XRouter.with(context)
76 | .target("www.google.com")
77 | .jump(new XRouterCallback() {
78 | @Override
79 | public void onRouterError(@NotNull XRouterResult routerResult) {
80 | Toast.makeText(context, "target activity is not find", Toast.LENGTH_SHORT).show();
81 | }
82 | });
83 |
84 | break;
85 | case 5:
86 | XRouter.with(context)
87 | .target("www.ModuleBActivity.com")
88 | .requestCode(1001)
89 | .jump();
90 | break;
91 | case 6:
92 | XRouter.with(context)
93 | .target("toast_java")
94 | .route();
95 | break;
96 | case 7:
97 | XRouter.with(context)
98 | .target("getSum_java")
99 | .data("a", 1)
100 | .data("b", 2)
101 | .obj(new Fragment())
102 | .route(new XRouterCallback() {
103 | @Override
104 | public void onRouterSuccess(@NotNull XRouterResult routerResult) {
105 | super.onRouterSuccess(routerResult);
106 | binding.tv.setText(String.format("getSum() result is : %s", routerResult.getData().getInt("result")));
107 | }
108 | });
109 | break;
110 | case 8:
111 | XRouterResult result = XRouter.with(context).target("getFragment_java").route();
112 | if (result.getObj() != null && result.getObj() instanceof Fragment) {
113 | Fragment fragment = (Fragment) result.getObj();
114 | binding.tv.setText(String.format("getFragment() result is : %s", fragment));
115 | }
116 | break;
117 | }
118 | }
119 | });
120 | }
121 |
122 | private List getListData() {
123 | List data = new ArrayList<>();
124 | data.add("route ModuleBActivity\nby \"www.RouterBActivity.com\"");
125 | data.add("route ModuleBActivity\nby \"hello.world\" with transition");
126 | data.add("route ModuleBActivity with data in url");
127 | data.add("route ModuleBActivity with data in bundle");
128 | data.add("route ModuleBActivity with callback");
129 | data.add("route ModuleBActivity for result");
130 | data.add("route method async : toast()");
131 | data.add("route method async : getSum()\nwith params and callback");
132 | data.add("route method sync : getFragment()");
133 | return data;
134 | }
135 |
136 | @Override
137 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
138 | super.onActivityResult(requestCode, resultCode, data);
139 | if (requestCode == 1001 && resultCode == Activity.RESULT_OK) {
140 | Toast.makeText(this, "finish for result", Toast.LENGTH_SHORT).show();
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/module-a/src/main/java/com/blue/modulea/kotlin/KotlinModuleActivity.kt:
--------------------------------------------------------------------------------
1 | package com.blue.modulea.kotlin
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.databinding.DataBindingUtil
6 | import android.os.Bundle
7 | import android.support.v4.app.Fragment
8 | import android.support.v7.app.AppCompatActivity
9 | import android.widget.AdapterView
10 | import android.widget.ArrayAdapter
11 | import android.widget.Toast
12 | import com.blue.modulea.R
13 | import com.blue.modulea.databinding.ModuleaActivityMainBinding
14 | import com.blue.xrouter.XRouter
15 | import com.blue.xrouter.annotation.Router
16 | import kotlinx.android.synthetic.main.modulea_activity_main.*
17 |
18 | /**
19 | * Created by blue on 2018/9/29.
20 | */
21 | @Router("www.KotlinModuleActivity.com")
22 | class KotlinModuleActivity : AppCompatActivity() {
23 |
24 | private lateinit var binding: ModuleaActivityMainBinding
25 |
26 | override fun onCreate(savedInstanceState: Bundle?) {
27 | super.onCreate(savedInstanceState)
28 | binding = DataBindingUtil.setContentView(this, R.layout.modulea_activity_main)
29 |
30 | val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, getListData())
31 | listView.adapter = adapter
32 | listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
33 | when (position) {
34 | 0 -> {
35 | XRouter.with(this)
36 | .target("www.ModuleBActivity.com")
37 | .intentFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
38 | .jump()
39 | }
40 | 1 -> {
41 | XRouter.with(this)
42 | .target("hello.world")
43 | .transition(android.R.anim.fade_in, android.R.anim.fade_out)
44 | .jump()
45 | }
46 | 2 -> {
47 | XRouter.with(this)
48 | .target("www.ModuleBActivity.com?name=tom&age=24")
49 | .jump()
50 | }
51 | 3 -> {
52 | XRouter.with(this)
53 | .target("hello.world")
54 | .data("name", "blue")
55 | .data("age", 18)
56 | .jump()
57 | }
58 | 4 -> {
59 | XRouter.with(this)
60 | .target("www.google.com")
61 | .jump({
62 | Toast.makeText(this@KotlinModuleActivity, "target activity is not find", Toast.LENGTH_SHORT).show()
63 | })
64 | }
65 | 5 -> {
66 | XRouter.with(this)
67 | .target("www.ModuleBActivity.com")
68 | .requestCode(1001)
69 | .jump()
70 | }
71 | 6 -> {
72 | XRouter.with(this)
73 | .target("toast_kotlin")
74 | .route()
75 | }
76 | 7 -> {
77 | XRouter.with(this)
78 | .target("getSum_kotlin")
79 | .data("a", 1)
80 | .data("b", 2)
81 | .obj(Fragment())
82 | .route {
83 | binding.tv.text = String.format("getSum() result is : %s", it.getData().getInt("result"))
84 | }
85 | }
86 | 8 -> {
87 | val result = XRouter.with(this).target("getFragment_kotlin").route()
88 | result.getObj()?.let {
89 | if (it is Fragment) {
90 | binding.tv.text = String.format("getFragment() result is : %s", it)
91 | }
92 | }
93 | }
94 | }
95 | }
96 | }
97 |
98 | private fun getListData(): MutableList {
99 | val data = mutableListOf()
100 | data.add("route ModuleBActivity\nby \"www.RouterBActivity.com\"")
101 | data.add("route ModuleBActivity\nby \"hello.world\" with transition")
102 | data.add("route ModuleBActivity with data in url")
103 | data.add("route ModuleBActivity with data in bundle")
104 | data.add("route ModuleBActivity with callback")
105 | data.add("route ModuleBActivity for result")
106 | data.add("route method async : toast()")
107 | data.add("route method async : getSum()\nwith params and callback")
108 | data.add("route method sync : getFragment()")
109 | return data
110 | }
111 |
112 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
113 | super.onActivityResult(requestCode, resultCode, data)
114 | if (requestCode == 1001 && resultCode == Activity.RESULT_OK) {
115 | Toast.makeText(this, "finish for result", Toast.LENGTH_SHORT).show()
116 | }
117 | }
118 | }
--------------------------------------------------------------------------------
/module-a/src/main/res/layout/modulea_activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
16 |
17 |
24 |
25 |
29 |
30 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/module-a/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module-a
3 |
4 |
--------------------------------------------------------------------------------
/module-b/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/module-b/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 |
6 | android {
7 | compileSdkVersion 26
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 26
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | dataBinding {
23 | enabled = true
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(include: ['*.jar'], dir: 'libs')
30 | implementation 'com.android.support:appcompat-v7:26.1.0'
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
32 | // databinding
33 | kapt "com.android.databinding:compiler:3.0.0"
34 | implementation project(':xrouter-core')
35 | kapt project(':xrouter-compiler')
36 | }
37 |
38 | kapt {
39 | arguments {
40 | arg("XRouterModule", "moduleb")
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/module-b/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 |
--------------------------------------------------------------------------------
/module-b/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/module-b/src/main/java/com/blue/moduleb/ModuleBActivity.kt:
--------------------------------------------------------------------------------
1 | package com.blue.moduleb
2 |
3 | import android.app.Activity
4 | import android.databinding.DataBindingUtil
5 | import android.os.Bundle
6 | import android.support.v7.app.AppCompatActivity
7 | import com.blue.moduleb.databinding.ModulebActivityMainBinding
8 | import com.blue.xrouter.annotation.Router
9 |
10 | /**
11 | * Created by blue on 2018/9/29.
12 | */
13 | @Router("www.ModuleBActivity.com", "hello.world")
14 | class ModuleBActivity : AppCompatActivity() {
15 |
16 | private lateinit var binding: ModulebActivityMainBinding
17 |
18 | private val name by lazy { intent.data?.getQueryParameter("name") ?: intent.getStringExtra("name") }
19 | private val age by lazy {
20 | intent.data?.let {
21 | it.getQueryParameter("age")?.toInt() ?: -1
22 | } ?: let {
23 | intent.getIntExtra("age", -1)
24 | }
25 | }
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | binding = DataBindingUtil.setContentView(this, R.layout.moduleb_activity_main)
30 |
31 | binding.result = "params : {name : $name , age : $age}"
32 |
33 | binding.btn.setOnClickListener {
34 | setResult(Activity.RESULT_OK)
35 | finish()
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/module-b/src/main/java/com/blue/moduleb/service/java/TestBRouterService.java:
--------------------------------------------------------------------------------
1 | package com.blue.moduleb.service.java;
2 |
3 |
4 | import android.content.Context;
5 | import android.support.v4.app.Fragment;
6 | import android.widget.Toast;
7 |
8 | import com.blue.xrouter.XRouterCallback;
9 | import com.blue.xrouter.XRouterParams;
10 | import com.blue.xrouter.XRouterResult;
11 | import com.blue.xrouter.annotation.Router;
12 |
13 | /**
14 | * java provides service
15 | * Created by blue on 2018/10/12.
16 | */
17 |
18 | public class TestBRouterService {
19 |
20 | @Router(value = "toast_java")
21 | public static XRouterResult toast(Context context, XRouterParams routerParams) {
22 | Toast.makeText(context, "toast from other module", Toast.LENGTH_SHORT).show();
23 | return new XRouterResult.Builder().build();
24 | }
25 |
26 | @Router(value = "getSum_java", async = true)
27 | public static void getSum(Context context, XRouterParams routerParams, XRouterCallback callback) {
28 | Fragment fragment = (Fragment) routerParams.getObj();
29 | // TODO
30 | int a = routerParams.getData().getInt("a");
31 | int b = routerParams.getData().getInt("b");
32 | int result = a + b;
33 |
34 | if (callback != null) {
35 | callback.onRouterSuccess(new XRouterResult.Builder().data("result", result).build());
36 | }
37 | }
38 |
39 | @Router("getFragment_java")
40 | public static XRouterResult getFragment(Context context, XRouterParams routerParams) {
41 | Fragment fragment = new Fragment();
42 | return new XRouterResult.Builder().obj(fragment).build();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/module-b/src/main/java/com/blue/moduleb/service/kotlin/TestBRouterService.kt:
--------------------------------------------------------------------------------
1 | package com.blue.moduleb.service.kotlin
2 |
3 | import android.content.Context
4 | import android.support.v4.app.Fragment
5 | import android.widget.Toast
6 | import com.blue.xrouter.XRouterCallback
7 | import com.blue.xrouter.XRouterParams
8 | import com.blue.xrouter.XRouterResult
9 | import com.blue.xrouter.annotation.Router
10 |
11 | /**
12 | * kotlin provides service
13 | * Created by blue on 2018/9/28.
14 | */
15 |
16 | @Router("toast_kotlin")
17 | fun toast(context: Context, routerParams: XRouterParams): XRouterResult {
18 | Toast.makeText(context, "toast from other module", Toast.LENGTH_SHORT).show()
19 | return XRouterResult.Builder().build()
20 | }
21 |
22 | @Router("getSum_kotlin", async = true)
23 | fun getSum(context: Context, routerParams: XRouterParams, callback: XRouterCallback?) {
24 | val fragment = routerParams.obj as Fragment
25 | // TODO
26 | val a = routerParams.data.getInt("a")
27 | val b = routerParams.data.getInt("b")
28 | val result = a + b
29 |
30 | callback?.onRouterSuccess(XRouterResult.Builder().data("result", result).build())
31 | }
32 |
33 | @Router("getFragment_kotlin")
34 | fun getFragment(context: Context, routerParams: XRouterParams): XRouterResult {
35 | val fragment = Fragment()
36 | return XRouterResult.Builder().obj(fragment).build()
37 | }
--------------------------------------------------------------------------------
/module-b/src/main/res/layout/moduleb_activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
15 |
16 |
21 |
22 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/module-b/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | module-b
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':xrouter-annotation', ':xrouter-compileonly', ':xrouter-core', ':xrouter-compiler', ':module-b', ':module-a'
2 |
--------------------------------------------------------------------------------
/xrouter-annotation/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/xrouter-annotation/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | dependencies {
5 | implementation fileTree(dir: 'libs', include: ['*.jar'])
6 | }
7 |
8 | sourceCompatibility = "1.7"
9 | targetCompatibility = "1.7"
10 |
11 | publish {
12 | userOrg = 'andrew007vip007'
13 | groupId = 'com.xuyefeng'
14 | artifactId = 'xrouter-annotation'
15 | publishVersion = '1.0.1'
16 | desc = 'This is a lightweight and simple routing framework that provides jump routing and method routing.'
17 | website = 'https://github.com/michaelxs/Android-XRouter.git'
18 | }
19 |
20 | tasks.withType(Javadoc) {
21 | enabled = false
22 | }
--------------------------------------------------------------------------------
/xrouter-annotation/src/main/java/com/blue/xrouter/annotation/Router.java:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter.annotation;
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 | /**
9 | * Created by blue on 2018/10/2.
10 | */
11 |
12 | @Target({ElementType.TYPE, ElementType.METHOD})
13 | @Retention(RetentionPolicy.CLASS)
14 | public @interface Router {
15 | String[] value();
16 |
17 | boolean async() default false;
18 | }
--------------------------------------------------------------------------------
/xrouter-annotation/src/main/java/com/blue/xrouter/annotation/RouterApp.java:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter.annotation;
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 | /**
9 | * Created by blue on 2018/10/2.
10 | */
11 |
12 | @Target({ElementType.TYPE})
13 | @Retention(RetentionPolicy.CLASS)
14 | public @interface RouterApp {
15 | }
--------------------------------------------------------------------------------
/xrouter-annotation/src/main/java/com/blue/xrouter/annotation/RouterInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter.annotation;
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 | /**
9 | * Created by blue on 2018/10/2.
10 | */
11 |
12 | @Target({ElementType.TYPE})
13 | @Retention(RetentionPolicy.CLASS)
14 | public @interface RouterInterceptor {
15 | int priority() default 5;
16 | }
--------------------------------------------------------------------------------
/xrouter-compileonly/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/xrouter-compileonly/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | dependencies {
4 | implementation fileTree(dir: 'libs', include: ['*.jar'])
5 | }
6 |
7 | sourceCompatibility = "1.7"
8 | targetCompatibility = "1.7"
--------------------------------------------------------------------------------
/xrouter-compileonly/src/main/java/com/blue/xrouter/XRouterAppInit.java:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter;
2 |
3 | /**
4 | * Created by blue on 2018/10/3.
5 | */
6 |
7 | public class XRouterAppInit {
8 | public static void init() {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/xrouter-compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/xrouter-compiler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | dependencies {
5 | implementation fileTree(include: ['*.jar'], dir: 'libs')
6 | compile 'com.google.auto.service:auto-service:1.0-rc3'
7 | compile 'com.squareup:javapoet:1.8.0'
8 | // compile 'com.xuyefeng:xrouter-annotation:1.0.1'
9 | compile project(':xrouter-annotation')
10 | }
11 |
12 | sourceCompatibility = "1.7"
13 | targetCompatibility = "1.7"
14 |
15 | publish {
16 | userOrg = 'andrew007vip007'
17 | groupId = 'com.xuyefeng'
18 | artifactId = 'xrouter-compiler'
19 | publishVersion = '1.0.6'
20 | desc = 'This is a lightweight and simple routing framework that provides jump routing and method routing.'
21 | website = 'https://github.com/michaelxs/Android-XRouter.git'
22 | }
23 |
24 | tasks.withType(Javadoc) {
25 | enabled = false
26 | }
27 |
--------------------------------------------------------------------------------
/xrouter-compiler/src/main/java/com/blue/xrouter/compiler/RouterProcessor.java:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter.compiler;
2 |
3 | import com.blue.xrouter.annotation.Router;
4 | import com.blue.xrouter.annotation.RouterApp;
5 | import com.blue.xrouter.annotation.RouterInterceptor;
6 | import com.google.auto.service.AutoService;
7 | import com.squareup.javapoet.JavaFile;
8 | import com.squareup.javapoet.MethodSpec;
9 | import com.squareup.javapoet.TypeSpec;
10 |
11 | import java.util.HashSet;
12 | import java.util.Map;
13 | import java.util.Set;
14 |
15 | import javax.annotation.processing.AbstractProcessor;
16 | import javax.annotation.processing.Filer;
17 | import javax.annotation.processing.Messager;
18 | import javax.annotation.processing.ProcessingEnvironment;
19 | import javax.annotation.processing.Processor;
20 | import javax.annotation.processing.RoundEnvironment;
21 | import javax.lang.model.SourceVersion;
22 | import javax.lang.model.element.Element;
23 | import javax.lang.model.element.ElementKind;
24 | import javax.lang.model.element.Modifier;
25 | import javax.lang.model.element.TypeElement;
26 | import javax.tools.Diagnostic;
27 |
28 | /**
29 | * Created by blue on 2018/10/2.
30 | */
31 | @AutoService(Processor.class)
32 | public class RouterProcessor extends AbstractProcessor {
33 |
34 | private static final boolean DEBUG = true;
35 | private static final String PACKAGE_NAME = "com.blue.xrouter";
36 | private static final String XROUTER_APP = "XRouterApp";
37 | private static final String XROUTER_MODULE = "XRouterModule";
38 |
39 | private static final String XROUTER_APP_INIT = "XRouterAppInit";
40 | private static final String XROUTER_MODULE_INIT = "XRouterModuleInit_";
41 |
42 | private Messager messager;
43 | private Filer filer;
44 | private String routerApp = "";
45 | private String routerModule = "";
46 |
47 | @Override
48 | public synchronized void init(ProcessingEnvironment processingEnv) {
49 | super.init(processingEnv);
50 | messager = processingEnv.getMessager();
51 | filer = processingEnv.getFiler();
52 | Map map = processingEnv.getOptions();
53 | Set keys = map.keySet();
54 | for (String key : keys) {
55 | if (XROUTER_APP.equals(key)) {
56 | this.routerApp = map.get(key);
57 | }
58 | if (XROUTER_MODULE.equals(key)) {
59 | this.routerModule = map.get(key);
60 | }
61 | }
62 | debug("apt init");
63 | debug("XRouterApp:" + routerApp);
64 | debug("XRouterModule:" + routerModule);
65 | }
66 |
67 | @Override
68 | public Set getSupportedAnnotationTypes() {
69 | Set ret = new HashSet<>();
70 | ret.add(RouterApp.class.getCanonicalName());
71 | ret.add(Router.class.getCanonicalName());
72 | ret.add(RouterInterceptor.class.getCanonicalName());
73 | return ret;
74 | }
75 |
76 | @Override
77 | public SourceVersion getSupportedSourceVersion() {
78 | return SourceVersion.latestSupported();
79 | }
80 |
81 | @Override
82 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnvironment) {
83 | if (set == null || set.size() == 0) {
84 | return false;
85 | }
86 | debug("process apt with " + set.toString());
87 | generateRouterApp(roundEnvironment);
88 | generateRouterModule(roundEnvironment);
89 |
90 | return true;
91 | }
92 |
93 | private void generateRouterApp(RoundEnvironment roundEnvironment) {
94 | Set extends Element> routerAppList = roundEnvironment.getElementsAnnotatedWith(RouterApp.class);
95 | if (routerAppList != null && routerAppList.size() > 0) {
96 | debug("generateRouterApp");
97 | MethodSpec.Builder initMethod = MethodSpec.methodBuilder("init")
98 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
99 |
100 | if (!routerApp.isEmpty()) {
101 | String[] moduleNames = routerApp.split("[,]");
102 | for (String module : moduleNames) {
103 | debug("add module:" + module);
104 | initMethod.addStatement("com.blue.xrouter.tools.Logger.INSTANCE.d($S, $S)", "XRouter", "--- init module:" + module + " ---");
105 | initMethod.addStatement(XROUTER_MODULE_INIT + module + ".registerPage()");
106 | initMethod.addStatement(XROUTER_MODULE_INIT + module + ".registerSyncMethod()");
107 | initMethod.addStatement(XROUTER_MODULE_INIT + module + ".registerAsyncMethod()");
108 | initMethod.addStatement(XROUTER_MODULE_INIT + module + ".registerInterceptor()");
109 | }
110 | }
111 |
112 | TypeSpec routerAppInit = TypeSpec.classBuilder(XROUTER_APP_INIT)
113 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
114 | .addMethod(initMethod.build())
115 | .build();
116 |
117 | try {
118 | JavaFile.builder(PACKAGE_NAME, routerAppInit).build().writeTo(filer);
119 | debug("generateRouterApp success");
120 | } catch (Throwable e) {
121 | e.printStackTrace();
122 | error(e.getMessage());
123 | }
124 | }
125 | }
126 |
127 | private void generateRouterModule(RoundEnvironment roundEnvironment) {
128 | Set extends Element> routerList = roundEnvironment.getElementsAnnotatedWith(Router.class);
129 | Set extends Element> routerInterceptorList = roundEnvironment.getElementsAnnotatedWith(RouterInterceptor.class);
130 | if (!routerModule.isEmpty()) {
131 | debug("generateRouterModule");
132 | MethodSpec.Builder registerPage = MethodSpec.methodBuilder("registerPage")
133 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
134 |
135 | MethodSpec.Builder registerSyncMethod = MethodSpec.methodBuilder("registerSyncMethod")
136 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
137 |
138 | MethodSpec.Builder registerAsyncMethod = MethodSpec.methodBuilder("registerAsyncMethod")
139 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
140 |
141 | MethodSpec.Builder registerInterceptor = MethodSpec.methodBuilder("registerInterceptor")
142 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL, Modifier.STATIC);
143 |
144 | if (routerList != null && routerList.size() > 0) {
145 | debug("generateRouter");
146 | for (Element element : routerList) {
147 | Router router = element.getAnnotation(Router.class);
148 | if (element.getKind() == ElementKind.CLASS) {
149 | TypeElement typeElement = (TypeElement) element;
150 | for (String target : router.value()) {
151 | registerPage.addStatement("com.blue.xrouter.XRouter.INSTANCE.registerPage($S, $T.class)", target, typeElement.asType());
152 | }
153 | } else if (element.getKind() == ElementKind.METHOD) {
154 | TypeElement typeElement = (TypeElement) element.getEnclosingElement();
155 | for (String target : router.value()) {
156 | if (router.async()) {
157 | registerAsyncMethod.addStatement("com.blue.xrouter.XRouter.INSTANCE.registerAsyncMethod($S, " +
158 | "new XRouterAsyncMethod() {\n" +
159 | " public void invoke(android.content.Context context, com.blue.xrouter.XRouterParams routerParams, XRouterCallback callback) {\n" +
160 | " $T.$N(context, routerParams, callback);\n" +
161 | " }\n" +
162 | "}) ", target, typeElement.asType(), element.getSimpleName());
163 | } else {
164 | registerSyncMethod.addStatement("com.blue.xrouter.XRouter.INSTANCE.registerSyncMethod($S, " +
165 | "new XRouterSyncMethod() {\n" +
166 | " public XRouterResult invoke(android.content.Context context, com.blue.xrouter.XRouterParams routerParams) {\n" +
167 | " return $T.$N(context, routerParams);\n" +
168 | " }\n" +
169 | "}) ", target, typeElement.asType(), element.getSimpleName());
170 | }
171 | }
172 | } else {
173 | error("process Router by unknown type");
174 | }
175 | }
176 | }
177 |
178 | if (routerInterceptorList != null && routerInterceptorList.size() > 0) {
179 | debug("generateRouterInterceptor");
180 | for (Element element : routerInterceptorList) {
181 | RouterInterceptor routerInterceptor = element.getAnnotation(RouterInterceptor.class);
182 | if (element.getKind() == ElementKind.CLASS) {
183 | TypeElement typeElement = (TypeElement) element;
184 | int target = routerInterceptor.priority();
185 | registerInterceptor.addStatement("com.blue.xrouter.XRouter.INSTANCE.registerInterceptor($L, new $T())", target, typeElement.asType());
186 | } else {
187 | error("process RouterInterceptor by unknown type");
188 | }
189 | }
190 | }
191 |
192 | TypeSpec routerInit = TypeSpec.classBuilder(XROUTER_MODULE_INIT + routerModule)
193 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
194 | .addMethod(registerPage.build())
195 | .addMethod(registerSyncMethod.build())
196 | .addMethod(registerAsyncMethod.build())
197 | .addMethod(registerInterceptor.build())
198 | .build();
199 |
200 | try {
201 | JavaFile.builder(PACKAGE_NAME, routerInit).build().writeTo(filer);
202 | debug("generateRouterModule success");
203 | } catch (Throwable e) {
204 | e.printStackTrace();
205 | error(e.getMessage());
206 | }
207 | }
208 | }
209 |
210 | private void error(String error) {
211 | messager.printMessage(Diagnostic.Kind.ERROR, error);
212 | }
213 |
214 | private void debug(String msg) {
215 | if (DEBUG) {
216 | messager.printMessage(Diagnostic.Kind.NOTE, msg);
217 | }
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/xrouter-core/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/xrouter-core/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'kotlin-kapt'
5 | apply plugin: 'com.novoda.bintray-release'
6 |
7 | android {
8 | compileSdkVersion 26
9 |
10 | defaultConfig {
11 | minSdkVersion 14
12 | targetSdkVersion 26
13 | versionCode 1
14 | versionName "1.0"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 |
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(include: ['*.jar'], dir: 'libs')
28 | implementation 'com.android.support:appcompat-v7:26.1.0'
29 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
30 |
31 | compileOnly project(':xrouter-compileonly')
32 | // compile 'com.xuyefeng:xrouter-annotation:1.0.1'
33 | compile project(':xrouter-annotation')
34 | }
35 |
36 | publish {
37 | userOrg = 'andrew007vip007'
38 | groupId = 'com.xuyefeng'
39 | artifactId = 'xrouter-core'
40 | publishVersion = '1.1.4'
41 | desc = 'This is a lightweight and simple routing framework that provides jump routing and method routing.'
42 | website = 'https://github.com/michaelxs/Android-XRouter.git'
43 | }
44 |
45 | tasks.withType(Javadoc) {
46 | enabled = false
47 | }
48 |
--------------------------------------------------------------------------------
/xrouter-core/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 |
--------------------------------------------------------------------------------
/xrouter-core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouter.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.net.Uri
7 | import com.blue.xrouter.tools.Logger
8 |
9 | /**
10 | * router manager
11 | * Created by blue on 2018/9/28.
12 | */
13 | object XRouter {
14 |
15 | private val TAG = "XRouter"
16 |
17 | private val pagesMapping by lazy { mutableMapOf>() }
18 |
19 | private val syncMethodMapping by lazy { mutableMapOf() }
20 | private val asyncMethodMapping by lazy { mutableMapOf() }
21 |
22 | private val interceptorMap by lazy { mutableMapOf() }
23 | private val interceptorPriorityList by lazy { mutableListOf() }
24 | private var interceptorIndex = 0
25 |
26 | @JvmStatic
27 | fun init(context: Context, isDebug: Boolean = false) {
28 | Logger.setDebug(isDebug)
29 | Logger.d(TAG, "XRouter init")
30 | XRouterAppInit.init()
31 | interceptorMap.values.forEach { it.onInit(context) }
32 | }
33 |
34 | fun registerPage(pageName: String, routerPage: Class) {
35 | Logger.d(TAG, "registerPage:$pageName")
36 | pagesMapping.put(pageName, routerPage)
37 | }
38 |
39 | fun registerSyncMethod(methodName: String, routerMethod: XRouterSyncMethod) {
40 | Logger.d(TAG, "registerSyncMethod:$methodName")
41 | syncMethodMapping.put(methodName, routerMethod)
42 | }
43 |
44 | fun registerAsyncMethod(methodName: String, routerMethod: XRouterAsyncMethod) {
45 | Logger.d(TAG, "registerAsyncMethod:$methodName")
46 | asyncMethodMapping.put(methodName, routerMethod)
47 | }
48 |
49 | fun registerInterceptor(priority: Int, routerInterceptor: XRouterInterceptor) {
50 | Logger.d(TAG, "registerInterceptor:${routerInterceptor.javaClass.canonicalName}(priority=$priority)")
51 | interceptorMap.put(priority, routerInterceptor)
52 |
53 | interceptorPriorityList.clear()
54 | interceptorPriorityList.addAll(interceptorMap.keys.sortedDescending())
55 | }
56 |
57 | /**
58 | * recommend
59 | */
60 | @JvmStatic
61 | fun with(context: Context) = XRouterConfig(context)
62 |
63 | /**
64 | * page route
65 | */
66 | fun jump(routerConfig: XRouterConfig, routerCallback: XRouterCallback? = null) {
67 | Logger.d(TAG, "--- start page route ---")
68 | Logger.d(TAG, "routerConfig:$routerConfig")
69 | if (interceptorMap.isNotEmpty()) {
70 | interceptorIndex = 0
71 | invokeIntercept(routerConfig, routerCallback)
72 | } else {
73 | Logger.d(TAG, "interceptorMap is empty")
74 | invokeJump(routerConfig, routerCallback)
75 | }
76 | }
77 |
78 | fun invokeIntercept(routerConfig: XRouterConfig, routerCallback: XRouterCallback? = null) {
79 | interceptorMap[interceptorPriorityList[interceptorIndex]]?.let {
80 | Logger.d(TAG, "invoke intercept:${it.javaClass.canonicalName}(priority=${interceptorPriorityList[interceptorIndex]})")
81 | it.onProcess(object : XRouterInterceptorCallback {
82 | override fun onContinue() {
83 | Logger.d(TAG, "onContinue")
84 | if (interceptorIndex == interceptorMap.size - 1) {
85 | invokeJump(routerConfig, routerCallback)
86 | } else {
87 | interceptorIndex++
88 | invokeIntercept(routerConfig, routerCallback)
89 | }
90 | }
91 |
92 | override fun onIntercept(msg: String) {
93 | Logger.w(TAG, "onIntercept:$msg")
94 | routerCallback?.onRouterError(XRouterResult.Builder().build())
95 | }
96 |
97 | })
98 | } ?: routerCallback?.onRouterError(XRouterResult.Builder().build())
99 | }
100 |
101 | fun invokeJump(routerConfig: XRouterConfig, routerCallback: XRouterCallback? = null) {
102 | Logger.d(TAG, "invoke jump")
103 | if (routerConfig.getTarget().isNotBlank()) {
104 | // get only scheme+authority+path
105 | var page = routerConfig.getTarget()
106 | if (routerConfig.getTarget().contains("?")) {
107 | page = routerConfig.getTarget().split("[?]".toRegex()).toTypedArray()[0]
108 | } else if (routerConfig.getTarget().contains("#")) {
109 | page = routerConfig.getTarget().split("[#]".toRegex()).toTypedArray()[0]
110 | }
111 | Logger.d(TAG, "page:$page")
112 | if (pagesMapping.containsKey(page)) {
113 | Logger.d(TAG, "find page success")
114 | val intent = Intent().apply {
115 | setClass(routerConfig.context, pagesMapping[page])
116 | if (routerConfig.getIntentFlags() != -1) {
117 | flags = routerConfig.getIntentFlags()
118 | }
119 | if (routerConfig.context !is Activity) {
120 | addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
121 | }
122 | data = Uri.parse(routerConfig.getTarget())
123 | putExtras(routerConfig.getData())
124 | }
125 | if (routerConfig.context is Activity) {
126 | if (routerConfig.getRequestCode() != -1) {
127 | Logger.d(TAG, "activity startActivityForResult")
128 | routerConfig.context.startActivityForResult(intent, routerConfig.getRequestCode())
129 | } else {
130 | Logger.d(TAG, "activity startActivity")
131 | routerConfig.context.startActivity(intent)
132 | }
133 | if (routerConfig.getEnterAnim() != -1 && routerConfig.getExitAnim() != -1) {
134 | Logger.d(TAG, "overridePendingTransition")
135 | routerConfig.context.overridePendingTransition(routerConfig.getEnterAnim(), routerConfig.getExitAnim())
136 | }
137 | routerCallback?.onRouterSuccess(XRouterResult.Builder().build())
138 | } else {
139 | Logger.d(TAG, "context startActivity")
140 | routerConfig.context.startActivity(intent)
141 | routerCallback?.onRouterSuccess(XRouterResult.Builder().build())
142 | }
143 | } else {
144 | Logger.d(TAG, "find page error")
145 | routerCallback?.onRouterError(XRouterResult.Builder().build())
146 | }
147 | } else {
148 | Logger.d(TAG, "target is blank")
149 | routerCallback?.onRouterError(XRouterResult.Builder().build())
150 | }
151 | }
152 |
153 | /**
154 | * method async route
155 | */
156 | fun call(routerConfig: XRouterConfig, routerCallback: XRouterCallback? = null) {
157 | Logger.d(TAG, "--- start method async route ---")
158 | Logger.d(TAG, "routerConfig:$routerConfig")
159 | val targetService = asyncMethodMapping[routerConfig.getTarget()]
160 | targetService?.let {
161 | Logger.d(TAG, "find method success")
162 | it.invoke(routerConfig.context, XRouterParams(routerConfig.getData(), routerConfig.getObj()), routerCallback)
163 | } ?: let {
164 | Logger.d(TAG, "find method error")
165 | routerCallback?.onRouterError(XRouterResult.Builder().build())
166 | }
167 | }
168 |
169 | /**
170 | * method sync route
171 | */
172 | fun get(routerConfig: XRouterConfig): XRouterResult {
173 | Logger.d(TAG, "--- start method sync route ---")
174 | Logger.d(TAG, "routerConfig:$routerConfig")
175 | val targetService = syncMethodMapping[routerConfig.getTarget()]
176 | targetService?.let {
177 | Logger.d(TAG, "find method success")
178 | val routerResult = it.invoke(routerConfig.context, XRouterParams(routerConfig.getData(), routerConfig.getObj()))
179 | Logger.d(TAG, "routerResult:$routerResult")
180 | return routerResult
181 | } ?: let {
182 | Logger.d(TAG, "find method error")
183 | return XRouterResult.Builder().build()
184 | }
185 | }
186 |
187 | @JvmStatic
188 | fun containsPage(target: String): Boolean {
189 | var page = target
190 | if (target.contains("?")) {
191 | page = target.split("[?]".toRegex()).toTypedArray()[0]
192 | } else if (target.contains("#")) {
193 | page = target.split("[#]".toRegex()).toTypedArray()[0]
194 | }
195 | return pagesMapping.containsKey(page)
196 | }
197 |
198 | @JvmStatic
199 | fun containsMethod(target: String) = !(!syncMethodMapping.containsKey(target) && !asyncMethodMapping.containsKey(target))
200 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterAsyncMethod.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.content.Context
4 |
5 | /**
6 | * Created by blue on 2018/10/2.
7 | */
8 | interface XRouterAsyncMethod {
9 |
10 | fun invoke(context: Context,
11 | routerParams: XRouterParams,
12 | callback: XRouterCallback? = null)
13 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterCallBack.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import com.blue.xrouter.tools.Logger
4 |
5 | /**
6 | * Created by blue on 2018/9/29.
7 | */
8 | open class XRouterCallback {
9 |
10 | /**
11 | * data bundle limit 1Mb
12 | */
13 | open fun onRouterSuccess(routerResult: XRouterResult) {
14 | Logger.d("XRouter", "routerResult:$routerResult")
15 | }
16 |
17 | open fun onRouterError(routerResult: XRouterResult) {
18 | }
19 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterConfig.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.os.Parcelable
6 | import org.json.JSONException
7 | import org.json.JSONObject
8 | import java.io.Serializable
9 |
10 | /**
11 | * Created by blue on 2018/9/30.
12 | */
13 | class XRouterConfig(
14 | val context: Context
15 | ) {
16 |
17 | private var target = ""
18 |
19 | private var requestCode = -1
20 |
21 | private var intentFlags = -1
22 |
23 | private var enterAnim = -1
24 | private var exitAnim = -1
25 |
26 | private var obj: Any? = null
27 |
28 | private var data = Bundle()
29 |
30 | fun target(target: String): XRouterConfig {
31 | this.target = target
32 | return this
33 | }
34 |
35 | fun requestCode(requestCode: Int): XRouterConfig {
36 | this.requestCode = requestCode
37 | return this
38 | }
39 |
40 | fun intentFlags(intentFlags: Int): XRouterConfig {
41 | this.intentFlags = intentFlags
42 | return this
43 | }
44 |
45 | fun transition(enterAnim: Int, exitAnim: Int): XRouterConfig {
46 | this.enterAnim = enterAnim
47 | this.exitAnim = exitAnim
48 | return this
49 | }
50 |
51 | fun obj(obj: Any?): XRouterConfig {
52 | this.obj = obj
53 | return this
54 | }
55 |
56 | fun data(key: String, value: Byte): XRouterConfig {
57 | data.putByte(key, value)
58 | return this
59 | }
60 |
61 | fun data(key: String, value: Short): XRouterConfig {
62 | data.putShort(key, value)
63 | return this
64 | }
65 |
66 | fun data(key: String, value: Int): XRouterConfig {
67 | data.putInt(key, value)
68 | return this
69 | }
70 |
71 | fun data(key: String, value: Long): XRouterConfig {
72 | data.putLong(key, value)
73 | return this
74 | }
75 |
76 | fun data(key: String, value: Float): XRouterConfig {
77 | data.putFloat(key, value)
78 | return this
79 | }
80 |
81 | fun data(key: String, value: Double): XRouterConfig {
82 | data.putDouble(key, value)
83 | return this
84 | }
85 |
86 | fun data(key: String, value: Boolean): XRouterConfig {
87 | data.putBoolean(key, value)
88 | return this
89 | }
90 |
91 | fun data(key: String, value: String?): XRouterConfig {
92 | data.putString(key, value)
93 | return this
94 | }
95 |
96 | fun data(key: String, value: CharSequence?): XRouterConfig {
97 | data.putCharSequence(key, value)
98 | return this
99 | }
100 |
101 | fun data(key: String, value: Parcelable?): XRouterConfig {
102 | data.putParcelable(key, value)
103 | return this
104 | }
105 |
106 | fun data(key: String, value: Serializable?): XRouterConfig {
107 | data.putSerializable(key, value)
108 | return this
109 | }
110 |
111 | fun data(bundle: Bundle?): XRouterConfig {
112 | bundle?.let { data.putAll(it) }
113 | return this
114 | }
115 |
116 | @JvmOverloads
117 | fun jump(routerCallback: XRouterCallback? = null) {
118 | XRouter.jump(this, routerCallback)
119 | }
120 |
121 | fun jump(errorBlock: ((XRouterResult) -> Unit)? = null, successBlock: ((XRouterResult) -> Unit)? = null) {
122 | XRouter.jump(this, object : XRouterCallback() {
123 |
124 | override fun onRouterSuccess(routerResult: XRouterResult) {
125 | super.onRouterSuccess(routerResult)
126 | successBlock?.invoke(routerResult)
127 | }
128 |
129 | override fun onRouterError(routerResult: XRouterResult) {
130 | errorBlock?.invoke(routerResult)
131 | }
132 | })
133 | }
134 |
135 | fun route() = XRouter.get(this)
136 |
137 | fun route(routerCallback: XRouterCallback? = null) {
138 | XRouter.call(this, routerCallback)
139 | }
140 |
141 | fun route(errorBlock: ((XRouterResult) -> Unit)? = null, successBlock: ((XRouterResult) -> Unit)? = null) {
142 | XRouter.call(this, object : XRouterCallback() {
143 |
144 | override fun onRouterSuccess(routerResult: XRouterResult) {
145 | super.onRouterSuccess(routerResult)
146 | successBlock?.invoke(routerResult)
147 | }
148 |
149 | override fun onRouterError(routerResult: XRouterResult) {
150 | errorBlock?.invoke(routerResult)
151 | }
152 | })
153 | }
154 |
155 | fun getTarget() = target
156 |
157 | fun getRequestCode() = requestCode
158 |
159 | fun getIntentFlags() = intentFlags
160 |
161 | fun getEnterAnim() = enterAnim
162 |
163 | fun getExitAnim() = exitAnim
164 |
165 | fun getObj() = obj
166 |
167 | fun getData() = data
168 |
169 | override fun toString(): String {
170 | return try {
171 | val jsonObject = JSONObject()
172 | jsonObject.put("target", target)
173 | jsonObject.put("requestCode", requestCode)
174 | jsonObject.put("intentFlags", intentFlags)
175 | jsonObject.put("enterAnim", enterAnim)
176 | jsonObject.put("exitAnim", exitAnim)
177 | jsonObject.put("data", data)
178 | obj?.let { jsonObject.put("any", it) }
179 | jsonObject.toString(4)
180 | } catch (e: JSONException) {
181 | e.message ?: ""
182 | }
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterInterceptor.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.content.Context
4 |
5 | /**
6 | * Created by blue on 2018/10/30.
7 | */
8 | interface XRouterInterceptor {
9 |
10 | fun onInit(context: Context)
11 |
12 | fun onProcess(callback: XRouterInterceptorCallback)
13 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterInterceptorCallback.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | /**
4 | * Created by blue on 2018/10/30.
5 | */
6 | interface XRouterInterceptorCallback {
7 |
8 | fun onContinue()
9 |
10 | fun onIntercept(msg: String)
11 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterParams.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.os.Bundle
4 |
5 | /**
6 | * Created by blue on 2018/10/30.
7 | */
8 | class XRouterParams(
9 | val data: Bundle,
10 | val obj: Any? = null
11 | )
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterResult.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.os.Bundle
4 | import android.os.Parcelable
5 | import org.json.JSONException
6 | import org.json.JSONObject
7 | import java.io.Serializable
8 |
9 | /**
10 | * Created by blue on 2018/10/30.
11 | */
12 | class XRouterResult private constructor(builder: Builder) {
13 | private var data: Bundle = Bundle()
14 | private var obj: Any? = null
15 |
16 | init {
17 | this.data = builder.getData()
18 | this.obj = builder.getObj()
19 | }
20 |
21 | fun getObj() = obj
22 |
23 | fun getData() = data
24 |
25 | class Builder {
26 | private var data: Bundle = Bundle()
27 | private var obj: Any? = null
28 |
29 | fun obj(obj: Any?): Builder {
30 | this.obj = obj
31 | return this
32 | }
33 |
34 | fun data(key: String, value: Byte): Builder {
35 | data.putByte(key, value)
36 | return this
37 | }
38 |
39 | fun data(key: String, value: Short): Builder {
40 | data.putShort(key, value)
41 | return this
42 | }
43 |
44 | fun data(key: String, value: Int): Builder {
45 | data.putInt(key, value)
46 | return this
47 | }
48 |
49 | fun data(key: String, value: Long): Builder {
50 | data.putLong(key, value)
51 | return this
52 | }
53 |
54 | fun data(key: String, value: Float): Builder {
55 | data.putFloat(key, value)
56 | return this
57 | }
58 |
59 | fun data(key: String, value: Double): Builder {
60 | data.putDouble(key, value)
61 | return this
62 | }
63 |
64 | fun data(key: String, value: Boolean): Builder {
65 | data.putBoolean(key, value)
66 | return this
67 | }
68 |
69 | fun data(key: String, value: String?): Builder {
70 | data.putString(key, value)
71 | return this
72 | }
73 |
74 | fun data(key: String, value: CharSequence?): Builder {
75 | data.putCharSequence(key, value)
76 | return this
77 | }
78 |
79 | fun data(key: String, value: Parcelable?): Builder {
80 | data.putParcelable(key, value)
81 | return this
82 | }
83 |
84 | fun data(key: String, value: Serializable?): Builder {
85 | data.putSerializable(key, value)
86 | return this
87 | }
88 |
89 | fun data(bundle: Bundle?): Builder {
90 | bundle?.let { data.putAll(it) }
91 | return this
92 | }
93 |
94 | fun build(): XRouterResult {
95 | return XRouterResult(this)
96 | }
97 |
98 | fun getObj() = obj
99 |
100 | fun getData() = data
101 | }
102 |
103 | override fun toString(): String {
104 | return try {
105 | val jsonObject = JSONObject()
106 | jsonObject.put("data", data)
107 | obj?.let { jsonObject.put("any", it) }
108 | jsonObject.toString(4)
109 | } catch (e: JSONException) {
110 | e.message ?: ""
111 | }
112 | }
113 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/XRouterSyncMethod.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter
2 |
3 | import android.content.Context
4 |
5 | /**
6 | * Created by blue on 2018/10/2.
7 | */
8 | interface XRouterSyncMethod {
9 |
10 | fun invoke(context: Context,
11 | routerParams: XRouterParams
12 | ): XRouterResult
13 | }
--------------------------------------------------------------------------------
/xrouter-core/src/main/java/com/blue/xrouter/tools/Logger.kt:
--------------------------------------------------------------------------------
1 | package com.blue.xrouter.tools
2 |
3 | import android.util.Log
4 |
5 | /**
6 | * log tools
7 | */
8 | object Logger {
9 |
10 | private val ERROR = 1
11 | private val WARN = 2
12 | private val INFO = 3
13 | private val DEBUG = 4
14 | private val VERBOSE = 5
15 |
16 | var LOG_LEVEL = ERROR
17 |
18 | fun e(tag: String, msg: String) {
19 | if (LOG_LEVEL >= ERROR)
20 | Log.e(tag, msg)
21 | }
22 |
23 | fun w(tag: String, msg: String) {
24 | if (LOG_LEVEL >= WARN)
25 | Log.w(tag, msg)
26 | }
27 |
28 | fun i(tag: String, msg: String) {
29 | if (LOG_LEVEL >= INFO)
30 | Log.i(tag, msg)
31 | }
32 |
33 | fun d(tag: String, msg: String) {
34 | if (LOG_LEVEL >= DEBUG)
35 | Log.d(tag, msg)
36 | }
37 |
38 | fun v(tag: String, msg: String) {
39 | if (LOG_LEVEL >= VERBOSE)
40 | Log.v(tag, msg)
41 | }
42 |
43 | fun setDebug(isDebug: Boolean) {
44 | LOG_LEVEL = if (isDebug) {
45 | DEBUG
46 | } else {
47 | ERROR
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/xrouter-core/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | xrouter-core
3 |
4 |
--------------------------------------------------------------------------------