├── .gitignore ├── LICENSE ├── README.md ├── annotation ├── .gitignore ├── build.gradle ├── gradle_push.gradle └── src │ └── main │ └── java │ └── com │ └── joybar │ └── annotation │ ├── guider │ ├── CodeMaker.java │ └── utils │ │ ├── AnnotationUtil.java │ │ ├── FileUtils.java │ │ ├── StringUtil.java │ │ └── TypeUtil.java │ └── router │ └── annotation │ ├── RegisterModule.java │ └── RegisterRouter.java ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── joybar │ │ └── androidrouter │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── joybar │ │ │ └── androidrouter │ │ │ ├── App.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── app_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 │ └── test │ └── java │ └── com │ └── joybar │ └── androidrouter │ └── ExampleUnitTest.java ├── build.gradle ├── compiler ├── .gitignore ├── build.gradle ├── gradle_push.gradle └── src │ └── main │ └── java │ └── com │ └── joybar │ └── compiler │ ├── RegisterRouterProcessor.java │ ├── data │ └── RouterModule.java │ └── helper │ ├── CompilerHelper.java │ └── RouterInject.java ├── config.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── librouter ├── .gitignore ├── build.gradle ├── gradle_push.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── joybar │ │ └── librouter │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── joybar │ │ │ └── librouter │ │ │ ├── application │ │ │ └── ApplicationService.java │ │ │ ├── guider │ │ │ ├── Builder.java │ │ │ ├── annotation │ │ │ │ ├── BigData.java │ │ │ │ ├── DataParam.java │ │ │ │ └── RegisterLaunch.java │ │ │ ├── routerguider │ │ │ │ ├── BigDataManager.java │ │ │ │ └── RouterGuider.java │ │ │ ├── routertable │ │ │ │ ├── RouterTable$$Moduleshop.java │ │ │ │ └── RouterTable$$Moduleuser.java │ │ │ └── sh │ │ │ │ └── route.sh │ │ │ ├── routercore │ │ │ ├── IRouterManagerService.java │ │ │ ├── InterceptorCallback.java │ │ │ ├── Router.java │ │ │ ├── RouterRequest.java │ │ │ ├── RouterService.java │ │ │ ├── Rule.java │ │ │ ├── interceptor │ │ │ │ ├── RouteInterceptor.java │ │ │ │ └── TestInterceptor.java │ │ │ └── utils │ │ │ │ └── CheckUtils.java │ │ │ └── routerservice │ │ │ ├── RouterServiceManager.java │ │ │ ├── exception │ │ │ └── RouterServiceException.java │ │ │ └── inters │ │ │ ├── IBaseService.java │ │ │ └── IServiceCallBack.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── joybar │ └── librouter │ └── ExampleUnitTest.java ├── moduleshop ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── joybar │ │ └── moduleshop │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── debug │ │ └── AndroidManifest.xml │ ├── doc │ │ ├── debug.jks │ │ └── test_realese.jks │ ├── java │ │ └── com │ │ │ └── joybar │ │ │ └── moduleshop │ │ │ ├── FinishWithResultActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── ReceiveParamActivity.java │ │ │ ├── ShopService.java │ │ │ └── application │ │ │ ├── ShopApplication.java │ │ │ ├── ShopDebugApplication.java │ │ │ └── ShopReleaseApplication.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── shop_activity_finish_with_result.xml │ │ ├── shop_activity_main.xml │ │ └── shop_activity_receive_param.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── joybar │ └── moduleshop │ └── ExampleUnitTest.java ├── moduleuser ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── joybar │ │ └── moduleuser │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── debug │ │ └── AndroidManifest.xml │ ├── doc │ │ ├── debug.jks │ │ └── test_realese.jks │ ├── java │ │ └── com │ │ │ └── joybar │ │ │ └── moduleuser │ │ │ ├── MainActivity.java │ │ │ └── application │ │ │ ├── UserApplication.java │ │ │ ├── UserDebugApplication.java │ │ │ └── UserReleaseApplication.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── user_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 │ └── test │ └── java │ └── com │ └── joybar │ └── moduleuser │ └── ExampleUnitTest.java ├── route.sh ├── screenshots ├── screenshot.gif ├── screenshot.jpg └── screenshot1.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Git Ignore File indicating untracked files 2 | 3 | # Gradle Files 4 | .gradle/ 5 | build/ 6 | /*/build/ 7 | 8 | # Local Configuration File 9 | local.properties 10 | 11 | # .iml 12 | *.iml 13 | 14 | # .idea 15 | /*/.idea/ 16 | .idea/ 17 | 18 | 19 | /*/class/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Joy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-Router 2 | 一个使用简单方便的Android router框架, 3 | 一个完整的Android模块化开发示例 4 | 5 | ![image](https://github.com/myjoybar/Android-Router/blob/master/screenshots/screenshot.gif) 6 | 7 | [Blog地址](https://blog.csdn.net/yalinfendou/article/details/78822749) 8 | ## Features 9 | - 支持动态注入路由 10 | - 支持注解方式注入路由 11 | - 支持Bundle传参 12 | - 支持module之间传大容量的数据 13 | - 支持添加拦截器 14 | - 支持module单独作为Application编译 15 | - 支持module之间同步或者异步服务调用 16 | - 支持主app的Application在各个module内调用 17 | - 路由引导模块:自动生成module的调用方法 ( Thank for [Obo](https://github.com/OboBear)) 18 | 19 | 20 | 21 | ## Installation 22 | ### Gradle Dependency 23 | ##### Add the library to your project build.gradle 24 | ```gradle 25 | compile 'com.joybar.router:librouter:1.1.7' 26 | compile 'com.joybar.router:compiler:1.1.7' 27 | compile 'com.joybar.router:annotation:1.1.7' 28 | ``` 29 | 30 | ## Structure 31 | - app: 一个空壳,本身不实现任何业务逻辑,最终打包成完整的release APK 32 | - moduleshop:实现shop相关的业务逻辑,可单独编译成APK 33 | - moduleuser:实现user相关的业务逻辑,可单独编译成APK,和其它module通过router通信 34 | - librouter:router实现的核心类 35 | 36 | 37 | ![image](https://github.com/myjoybar/Android-Router/blob/master/screenshots/screenshot1.png) 38 | 39 | ## Sample Usage 40 | 41 | ### Step1(初始化) 42 | 43 | 方式一:动态注入路由 44 | 45 | ```java 46 | Router.registerRouters(new Router.RouterTable() { 47 | @Override 48 | public List buildRuleList() { 49 | List ruleList = new ArrayList<>(); 50 | ruleList.add(new Rule("user", "user_main", com.joybar.moduleuser.MainActivity.class)); 51 | ruleList.add(new Rule("shop", "shop_main", com.joybar.moduleshop.MainActivity.class)); 52 | return ruleList; 53 | } 54 | }); 55 | 56 | ``` 57 | 58 | 方式二:注解方式注入路由 59 | 60 | ```java 61 | @RouterRegister(module = "user", path = "user_main") 62 | public class MainActivity extends AppCompatActivity { 63 | ... 64 | } 65 | 66 | ``` 67 | ```java 68 | @RouterRegister(module = "shop", path = "shop_main") 69 | public class MainActivity extends AppCompatActivity { 70 | ... 71 | } 72 | 73 | ``` 74 | 并在Application或者初始页面初始化注解路由器 75 | 76 | ```java 77 | //参数为module name 78 | RouterInject.registerModule("shop"); 79 | RouterInject.registerModule("user"); 80 | ``` 81 | 82 | ### Step2(生成路由引导模块,可选) 83 | 84 | #### 1. 添加注解(注解@RegisterLaunch只会读取方法参数,而launch方法本身可供模块内部调用) 85 | 86 | ```java 87 | @RegisterLaunch 88 | public static void launch(Context context,String address){ 89 | Intent intent = new Intent(context,ReceiveParamActivity.class); 90 | Bundle bundle = new Bundle(); 91 | bundle.putString("address",address); 92 | intent.putExtras(bundle); 93 | context.startActivity(intent); 94 | } 95 | 96 | @RegisterLaunch 97 | public static void launch(Context context,String name,int id){ 98 | Intent intent = new Intent(context,ReceiveParamActivity.class); 99 | Bundle bundle = new Bundle(); 100 | bundle.putInt("id",id); 101 | bundle.putString("name",name); 102 | intent.putExtras(bundle); 103 | context.startActivity(intent); 104 | } 105 | 106 | ``` 107 | 108 | #### 2. 在此添加需要生成路由引导模块的module,运行Builder#main 109 | 110 | ```java 111 | public class Builder { 112 | 113 | public static void main(String[] args) { 114 | System.out.println("=============start build============="); 115 | CodeMaker.autoGenerateModuleMethodName("moduleshop","/baselib/src/main/java","com.joy.baselib.guider.routertable"); 116 | System.out.println("=============end build============="); 117 | } 118 | 119 | } 120 | ``` 121 | #### 3.在参数指定的路径下生成RouterTable$$Moduleuser和RouterTable$$Moduleshop以及相关的调用方法 122 | 123 | RouterTable$$Moduleshop 为自动生成的类,其方法可供其他Module调用 124 | 125 | ```java 126 | public final class RouterTable$$Moduleshop { 127 | public static RouterGuider launchFinishWithResult() { 128 | // This class was generated automatically 2017-12-11 18:23:03 129 | // module=shop,path=finish_with_result 130 | RouterGuider routerGuider = new RouterGuider("shop", "finish_with_result"); 131 | return routerGuider; 132 | } 133 | 134 | public static RouterGuider launchMain() { 135 | // This class was generated automatically 2017-12-11 18:23:03 136 | // module=shop,path=main 137 | RouterGuider routerGuider = new RouterGuider("shop", "main"); 138 | return routerGuider; 139 | } 140 | 141 | public static RouterGuider launchPostModuleData() { 142 | // This class was generated automatically 2017-12-11 18:23:03 143 | // module=shop,path=post_module_data 144 | RouterGuider routerGuider = new RouterGuider("shop", "post_module_data"); 145 | return routerGuider; 146 | } 147 | 148 | public static RouterGuider launchReceiveParam(String name, Integer id) { 149 | // This class was generated automatically 2017-12-11 18:23:03 150 | // module=shop,path=receive_param 151 | RouterGuider routerGuider = new RouterGuider("shop", "receive_param"); 152 | routerGuider.withString("name", name); 153 | routerGuider.withInt("id", id); 154 | return routerGuider; 155 | } 156 | 157 | public static RouterGuider launchReceiveParam(String address) { 158 | // This class was generated automatically 2017-12-11 18:23:03 159 | // module=shop,path=receive_param 160 | RouterGuider routerGuider = new RouterGuider("shop", "receive_param"); 161 | routerGuider.withString("address", address); 162 | return routerGuider; 163 | } 164 | } 165 | 166 | ``` 167 | ### Step3(使用) 168 | 169 | #### 1. 直接启动Activity 170 | 171 | 方式一: 172 | 173 | ```java 174 | Router.create() 175 | .buildRule(new Rule("shop", "main")) 176 | .navigate(context); 177 | ``` 178 | 179 | 方式二 **(推荐 )** 180 | 181 | - RouteTable$$Moduleshop为自动生成的类 182 | - 此类按照moduleuser开发者指定的规则生成 183 | - 对于使用者来说,只需关注RouteTable$$moduleuser中的对外公开的方法即可 184 | 185 | ```java 186 | RouterTable$$Moduleshop 187 | .launchMain() 188 | .navigate(context); 189 | ``` 190 | #### 2. startActivityForResult方式启动Activity 191 | ```java 192 | RouterTable$$Moduleshop.launchFinishWithResult() 193 | .navigate(MainActivity 194 | .this, 2);; 195 | 196 | // OR 197 | // Router.create() 198 | // .buildRule(new Rule("shop", "finish_with_result")) 199 | // .navigate(MainActivity 200 | // .this, 2); 201 | ``` 202 | 203 | #### 3. Activity之间参数传递 204 | 205 | ```java 206 | RouterTable$$Moduleshop 207 | .launchReceiveParam("obo", 23) 208 | .navigate(context); 209 | 210 | // OR 211 | // final Bundle bundle = new Bundle(); 212 | // bundle.putInt("id", 123); 213 | // bundle.putString("name", "obo"); 214 | // Router.create() 215 | // .buildRule(new Rule("shop", "receive_param")) 216 | // .withExtra(bundle) 217 | // .navigate(context); 218 | ``` 219 | 220 | #### 4. 为Router 添加拦截器 221 | 222 | ```java 223 | RouterTable$$Moduleshop.launchMain() 224 | .withRouteInterceptor(new TestInterceptor(mContext)) 225 | .withCallBack(new InterceptorCallback() { 226 | @Override 227 | public void onIntercept(Object result) { 228 | Toast.makeText(mContext, result.toString(), Toast.LENGTH_LONG).show(); 229 | } 230 | 231 | @Override 232 | public void onContinue() { 233 | Toast.makeText(mContext, "continue", Toast.LENGTH_LONG).show(); 234 | } 235 | }) 236 | .navigate(mContext); 237 | ``` 238 | #### 5. modlue之间同步或者异步调用服务 239 | 240 | 241 | ##### Step1 在module创建service类并实现IBaseService 242 | ```java 243 | public class ShopService implements IBaseService { 244 | private static final String SERVICE_CMD_TEST = "cmd_test"; 245 | private static final String SERVICE_CMD_LOGIN = "cmd_login"; 246 | 247 | @Override 248 | public Object execute(String cmd, Object... args) { 249 | Object obj[] = args; 250 | String msg = ""; 251 | if (obj != null && obj.length != 0) { 252 | msg = Arrays.toString(obj); 253 | } 254 | if (SERVICE_CMD_TEST.equals(cmd)) { 255 | return "成功同步调用 Shop service " + SERVICE_CMD_TEST + "服务,返回值:" + msg; 256 | } 257 | return null; 258 | } 259 | 260 | @Override 261 | public void executeAsync(String cmd, IServiceCallBack iServiceCallBack, Object... args) { 262 | 263 | if (SERVICE_CMD_LOGIN.equals(cmd)) { 264 | 265 | try { 266 | Thread.sleep(500); 267 | } catch (InterruptedException e) { 268 | e.printStackTrace(); 269 | } 270 | 271 | if ("Tom".equals(args[0]) && "123456".equals(args[1])) { 272 | iServiceCallBack.onSuccess("登录成功"); 273 | } else { 274 | iServiceCallBack.onFailure(new RouterServiceException("用户名或者密码错误")); 275 | } 276 | 277 | } 278 | } 279 | 280 | @Override 281 | public String moduleServiceName() { 282 | 283 | return "RSShopService"; 284 | } 285 | } 286 | ``` 287 | ##### Step2 在module对应的AndroidManifest文件中注册meta信息 288 | ```java 289 | 292 | ``` 293 | ##### Step3 在Application中初始化 294 | ```java 295 | RouterServiceManager.getInstance().init(this);// 注册组件之间服务路由 296 | 297 | ``` 298 | ##### Step4 在User module中使用 299 | ```java 300 | //调用同步服务 301 | IBaseService service = RouterServiceManager.getInstance().getService("RSShopService"); 302 | String result = (String) service.execute("cmd_test","ABCDE"); 303 | Toast.makeText(mContext, "User module " + result,Toast.LENGTH_LONG).show(); 304 | 305 | 306 | //调用异步服务 307 | IBaseService service = RouterServiceManager.getInstance().getService("RSShopService"); 308 | String userName = "Tom"; 309 | String pwd = "123456"; 310 | service.executeAsync("cmd_login", new IServiceCallBack() { 311 | 312 | @Override 313 | public void onSuccess(Object result) { 314 | 315 | Toast.makeText(mContext, result.toString(), Toast.LENGTH_LONG).show(); 316 | 317 | } 318 | 319 | @Override 320 | public void onFailure(RouterServiceException routerServiceException) { 321 | Toast.makeText(mContext, routerServiceException.getMessage(), Toast.LENGTH_LONG).show(); 322 | } 323 | }, userName, pwd); 324 | 325 | 326 | ``` 327 | 328 | 329 | #### 6. 其它 330 | 331 | ##### 1.单独编译module: 332 | step1. config.gradle 333 | 334 | ```java 335 | isDebugType = false //主App工程 336 | project.ext.set("is_debug_type", "false") //module 工程 337 | ``` 338 | step2. 执行 ./gradlew :moduleshop:assembleRelease 或者./gradlew :moduleshop:assembleDebug 339 | 340 | ##### 2.为保证各个module能在主App的relase版本共用Application,以及每个module的application在debug和release状态下调用方法不变,请实现ApplicationService 接口 341 | 342 | 343 | ## License 344 | 345 | Copyright 2017 MyJoybar 346 | 347 | Licensed under the Apache License, Version 2.0 (the "License"); 348 | you may not use this file except in compliance with the License. 349 | You may obtain a copy of the License at 350 | 351 | http://www.apache.org/licenses/LICENSE-2.0 352 | 353 | Unless required by applicable law or agreed to in writing, software 354 | distributed under the License is distributed on an "AS IS" BASIS, 355 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 356 | See the License for the specific language governing permissions and 357 | limitations under the License. 358 | -------------------------------------------------------------------------------- /annotation/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /annotation/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | dependencies { 3 | implementation fileTree(dir: 'libs', include: ['*.jar']) 4 | compile 'com.squareup:javapoet:1.9.0' 5 | } 6 | 7 | sourceCompatibility = "1.7" 8 | targetCompatibility = "1.7" 9 | 10 | apply from: 'gradle_push.gradle' -------------------------------------------------------------------------------- /annotation/gradle_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | def VERSION = "1.1.7" 5 | def GROUP = "com.joybar.router" 6 | def ARTIFACT_ID = 'annotation' 7 | group = GROUP 8 | version = VERSION 9 | 10 | def siteUrl = 'https://github.com/myjoybar/Android-Router' 11 | def issuesUrl = 'https://github.com/myjoybar/Android-Router/issues' 12 | def gitUrl = 'https://github.com/myjoybar/Android-Router.git' 13 | 14 | task sourcesJar(type: Jar, dependsOn: classes) { 15 | from sourceSets.main.allSource 16 | classifier = 'sources' 17 | } 18 | 19 | task javadocJar(type: Jar, dependsOn: javadoc) { 20 | classifier = 'javadoc' 21 | from javadoc.destinationDir 22 | } 23 | artifacts { 24 | archives javadocJar 25 | archives sourcesJar 26 | } 27 | 28 | 29 | publishing { 30 | publications { 31 | bintray(MavenPublication) { 32 | groupId GROUP 33 | artifactId ARTIFACT_ID 34 | version VERSION 35 | 36 | artifact sourcesJar 37 | from components.java 38 | } 39 | } 40 | } 41 | 42 | 43 | bintray { 44 | Properties properties = new Properties() 45 | boolean hasLocalFile = false 46 | if (project.rootProject.file('local.properties').exists()) { 47 | hasLocalFile = true 48 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 49 | } 50 | user = hasLocalFile ? properties.getProperty("bintray.user") : "" 51 | key = hasLocalFile ? properties.getProperty("bintray.apikey") : "" 52 | 53 | publications = ['bintray'] 54 | pkg { 55 | repo = "Andorid-Maven" 56 | name = "router-annotation" 57 | websiteUrl = siteUrl 58 | issueTrackerUrl = issuesUrl 59 | vcsUrl = gitUrl 60 | desc = "Annotation for Router library." 61 | labels = ["Android", "Router", "annotation"] 62 | licenses = ["Apache-2.0"] 63 | publicDownloadNumbers = true 64 | publish = true 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/guider/CodeMaker.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.guider; 2 | 3 | 4 | import com.joybar.annotation.guider.utils.FileUtils; 5 | import com.joybar.annotation.guider.utils.StringUtil; 6 | import com.joybar.annotation.guider.utils.TypeUtil; 7 | import com.squareup.javapoet.ClassName; 8 | import com.squareup.javapoet.JavaFile; 9 | import com.squareup.javapoet.MethodSpec; 10 | import com.squareup.javapoet.TypeName; 11 | import com.squareup.javapoet.TypeSpec; 12 | 13 | import java.io.BufferedReader; 14 | import java.io.File; 15 | import java.io.FileReader; 16 | import java.io.IOException; 17 | import java.text.SimpleDateFormat; 18 | import java.util.Date; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import javax.lang.model.element.Modifier; 24 | 25 | public class CodeMaker { 26 | 27 | private static final String ANNOTATION_ROUTER = "@RegisterRouter"; 28 | private static final String ANNOTATION_LAUNCH = "@RegisterLaunch"; 29 | private static final String PARAM_PATH = "path"; 30 | private static final String PARAM_MODULE = "module"; 31 | private static String ROUTER_GUIDER_PKN = "com.joybar.librouter.guider.routertable"; 32 | private static String FILE_PATH = "/librouter/src/main/java"; 33 | private static final String LOCAL_ROUTE_NAME = "routerGuider"; 34 | private static final String METHOD_PREFIX = "launch"; 35 | private static final String ROUTER_GUIDER_PAK = "com.joybar.librouter.guider.routerguider"; 36 | 37 | 38 | // public static void main(String []args) { 39 | // System.out.println("args.length = " + args.length); 40 | // autoGenerateModuleMethodName("module_shop"); 41 | // } 42 | 43 | private static final String ROUTER_GUIDER_CLASS_PREFIX = "RouterTable$$"; 44 | private static final String ROUTER_GUIDER_CLASS_FILE_PATH = "/src/main/java/"; 45 | 46 | 47 | public static void autoGenerateModuleMethodName(String moduleName, String filePath, String routerGuiderPckName) { 48 | 49 | System.out.println("==================moduleName=" + moduleName + "=================="); 50 | System.out.println("==================filePath=" + filePath + "=================="); 51 | System.out.println("==================routerGuiderPckName=" + routerGuiderPckName + "=================="); 52 | FILE_PATH = filePath; 53 | ROUTER_GUIDER_PKN = routerGuiderPckName; 54 | 55 | String classBuilderName = ROUTER_GUIDER_CLASS_PREFIX+ StringUtil.getTypeWithFirstUpperCase(moduleName); 56 | TypeSpec.Builder classBuilder = TypeSpec.classBuilder(classBuilderName).addModifiers(Modifier.PUBLIC, Modifier.FINAL); 57 | File workFile = new File(moduleName +ROUTER_GUIDER_CLASS_FILE_PATH); 58 | List files = FileUtils.getAllFiles(workFile); 59 | System.out.println("files.size() = " + files.size()); 60 | 61 | int i = 0; 62 | for (File file : files) { 63 | System.out.println("===================" + moduleName + i++ + "=================="); 64 | StringBuffer stringBuffer = new StringBuffer(""); 65 | try { 66 | FileReader fileReader = new FileReader(file); 67 | BufferedReader bufferedReader = new BufferedReader(fileReader); 68 | String s; 69 | while ((s = bufferedReader.readLine()) != null) { 70 | stringBuffer.append(s); 71 | } 72 | } catch (IOException e) { 73 | e.printStackTrace(); 74 | } 75 | decoString(stringBuffer.toString(), classBuilder); 76 | } 77 | JavaFile javaFile = JavaFile.builder(ROUTER_GUIDER_PKN, classBuilder.build()).build(); 78 | try { 79 | javaFile.writeTo(new File(System.getProperty("user.dir") + FILE_PATH)); 80 | } catch (IOException e) { 81 | e.printStackTrace(); 82 | } 83 | } 84 | 85 | 86 | public static void autoGenerateModuleMethodName(String moduleName) { 87 | 88 | System.out.println("==================moduleName=" + moduleName + "=================="); 89 | 90 | String classBuilderName = ROUTER_GUIDER_CLASS_PREFIX+ StringUtil.getTypeWithFirstUpperCase(moduleName); 91 | TypeSpec.Builder classBuilder = TypeSpec.classBuilder(classBuilderName).addModifiers(Modifier.PUBLIC, Modifier.FINAL); 92 | File workFile = new File(moduleName + ROUTER_GUIDER_CLASS_FILE_PATH); 93 | List files = FileUtils.getAllFiles(workFile); 94 | System.out.println("files.size() = " + files.size()); 95 | 96 | int i = 0; 97 | for (File file : files) { 98 | System.out.println("===================" + moduleName + i++ + "=================="); 99 | StringBuffer stringBuffer = new StringBuffer(""); 100 | try { 101 | FileReader fileReader = new FileReader(file); 102 | BufferedReader bufferedReader = new BufferedReader(fileReader); 103 | String s; 104 | while ((s = bufferedReader.readLine()) != null) { 105 | stringBuffer.append(s); 106 | } 107 | } catch (IOException e) { 108 | e.printStackTrace(); 109 | } 110 | decoString(stringBuffer.toString(), classBuilder); 111 | } 112 | JavaFile javaFile = JavaFile.builder(ROUTER_GUIDER_PKN, classBuilder.build()).build(); 113 | try { 114 | javaFile.writeTo(new File(System.getProperty("user.dir") + FILE_PATH)); 115 | } catch (IOException e) { 116 | e.printStackTrace(); 117 | } 118 | } 119 | 120 | 121 | static void decoString(String fileString, TypeSpec.Builder builder) { 122 | if (fileString.contains(ANNOTATION_ROUTER)) { 123 | String paramRouterStr = StringUtil.getFirstParamsStrByAnnotation(fileString, ANNOTATION_ROUTER); 124 | Map paramRouterMap = StringUtil.getParamMapByAnnotationParamsStr(paramRouterStr); 125 | String module = paramRouterMap.get(PARAM_MODULE); 126 | module = module == null ? "" : module; 127 | String path = paramRouterMap.get(PARAM_PATH); 128 | path = path == null ? "" : path; 129 | System.out.println("module = " + module+", path = " + path); 130 | List> list = StringUtil.getParamMapListByMethodParamsStr(fileString, ANNOTATION_LAUNCH); 131 | if (null == list || list.size() == 0) { 132 | System.out.println("generate method with annotation @RegisterRouter" ); 133 | MethodSpec methodSpec = getMethodSpecWith(module, path, null); 134 | builder.addMethod(methodSpec); 135 | } else { 136 | System.out.println("generate method with annotation @RegisterLaunch, size = " +list.size()); 137 | for (Map paramMap : list) { 138 | MethodSpec methodSpec = getMethodSpecWith(module, path, paramMap); 139 | builder.addMethod(methodSpec); 140 | } 141 | } 142 | } 143 | 144 | } 145 | 146 | public static MethodSpec getMethodSpecWith(String module, String path, Map paramMap) { 147 | System.out.println("------- "); 148 | 149 | ClassName classRouterGuider = ClassName.get(ROUTER_GUIDER_PAK, "RouterGuider"); 150 | Date d = new Date(); 151 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 152 | String methodName = METHOD_PREFIX + StringUtil.upperCaseFirst(StringUtil.underlineToCamel(path)); 153 | MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addComment("This " + 154 | "class was generated automatically " + sdf.format(d)).addComment("module=" + module + "," + "path=" + path).returns(classRouterGuider); 155 | 156 | methodBuilder.addStatement("$T $N = new $T($S, $S)", classRouterGuider, LOCAL_ROUTE_NAME, classRouterGuider, module, path); 157 | 158 | if (null != paramMap) { 159 | Iterator> it = paramMap.entrySet().iterator(); 160 | while (it.hasNext()) { 161 | Map.Entry entry = it.next(); 162 | String key = entry.getKey(); 163 | String value = entry.getValue(); 164 | TypeName type = TypeUtil.getTypeNameWithStr(key); 165 | System.out.println("key = " + key + ",value = " + value + ",type = " + type); 166 | if (null == type) { 167 | continue; 168 | } 169 | methodBuilder.addParameter(type, value); 170 | methodBuilder.addStatement("$N.with" + "" + StringUtil.getTypeWithFirstUpperCase(key) + "($S, $N)", LOCAL_ROUTE_NAME, value, value); 171 | 172 | } 173 | } 174 | methodBuilder.addStatement("return $N", LOCAL_ROUTE_NAME); 175 | return methodBuilder.build(); 176 | 177 | } 178 | 179 | 180 | } 181 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/guider/utils/AnnotationUtil.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.guider.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by obo on 2017/11/28. 8 | */ 9 | 10 | public class AnnotationUtil { 11 | public static Map getAnnotationParams(String annotationContent) { 12 | Map annotationParams = new HashMap<>(); 13 | String[] paramSplites = annotationContent.split(","); 14 | for (String param : paramSplites) { 15 | String[] annotationKeyValueSplites = param.split("="); 16 | if (annotationKeyValueSplites.length == 2) { 17 | String key = annotationKeyValueSplites[0].trim(); 18 | String value = annotationKeyValueSplites[1].trim().replace("\"", ""); 19 | annotationParams.put(key, value); 20 | } 21 | } 22 | return annotationParams; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/guider/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.guider.utils; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by obo on 2017/11/28. 9 | */ 10 | 11 | public class FileUtils { 12 | public static List getAllFiles(File workFile) { 13 | List files = new ArrayList<>(); 14 | File[] sonFiles = workFile.listFiles(); 15 | 16 | for (File sonFile : sonFiles) { 17 | if (sonFile.isDirectory()) { 18 | files.addAll(getAllFiles(sonFile)); 19 | } else { 20 | files.add(sonFile); 21 | } 22 | } 23 | return files; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/guider/utils/StringUtil.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.guider.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * Created by obo on 2017/11/24. 11 | */ 12 | 13 | public class StringUtil { 14 | public static String getTypeWithFirstUpperCase(String typeString) { 15 | String[] splitString = typeString.split("\\."); 16 | String availableString = splitString[splitString.length - 1]; 17 | return (availableString.charAt(0) + "").toUpperCase() + availableString.substring(1).toLowerCase(); 18 | } 19 | 20 | public static String upperCaseFirst(String str) { 21 | char[] ch = str.toCharArray(); 22 | if (ch[0] >= 'a' && ch[0] <= 'z') { 23 | ch[0] = (char) (ch[0] - 32); 24 | } 25 | return new String(ch); 26 | } 27 | 28 | public static String getGroupName(String path) { 29 | String[] pathSplit = path.split("/"); 30 | System.out.println("pathSplit.length = " + pathSplit.length); 31 | return pathSplit[1]; 32 | } 33 | 34 | public static Map getParamMap(String fileString, String annotation) { 35 | Map paramMap = new HashMap<>(); 36 | int startPosition = 0; 37 | int currentIndex = -1; 38 | while ((currentIndex = fileString.indexOf(annotation, startPosition)) != -1) { 39 | for (int i = currentIndex + annotation.length(); i < fileString.length(); i++) { 40 | if (fileString.charAt(i) == ';') { 41 | String content = fileString.substring(currentIndex + annotation.length() + 1, i); 42 | System.out.println("content = " + content); 43 | String[] splite = content.trim().split("\\s+"); 44 | 45 | System.out.println("size = " + splite.length); 46 | System.out.println("splite = " + splite[splite.length - 2] + " " + splite[splite.length - 1]); 47 | paramMap.put(splite[splite.length - 1], splite[splite.length - 2]); 48 | startPosition = i; 49 | break; 50 | } 51 | } 52 | } 53 | return paramMap; 54 | } 55 | 56 | public static String getFirstParamsStrByAnnotation(String fileString, String annotationName) { 57 | 58 | int index = fileString.indexOf(annotationName); 59 | StringBuffer sb = new StringBuffer(); 60 | // int indexLeftBracket = 0; 61 | boolean start = false; 62 | for (int i = index + annotationName.length(); i < fileString.length(); i++) { 63 | if (start) { 64 | sb.append(fileString.charAt(i)); 65 | } 66 | if (fileString.charAt(i) == '(') { 67 | start = true; 68 | } 69 | if (fileString.charAt(i) == ')') { 70 | sb.deleteCharAt(sb.length() - 1); 71 | break; 72 | } 73 | 74 | } 75 | return sb.toString(); 76 | 77 | } 78 | 79 | 80 | public static List> getParamMapListByMethodParamsStr(String fileStr, String annotationStr) { 81 | int startPosition = 0; 82 | int currentIndex = -1; 83 | List> list = new ArrayList<>(); 84 | 85 | while ((currentIndex = fileStr.indexOf(annotationStr, startPosition)) != -1) { 86 | String paramsStr = StringUtil.getFirstParamsStrByAnnotation(fileStr, annotationStr); 87 | System.out.println("annotation paramsStr = " + paramsStr); 88 | Map paramMap = new HashMap<>(); 89 | String[] paramArray = paramsStr.toString().split(","); 90 | for (int i = 0; i < paramArray.length; i++) { 91 | String paramStr = paramArray[i].trim(); 92 | String[] param = paramStr.toString().split(" "); 93 | String key = param[0].trim(); 94 | String value = param[1].trim(); 95 | System.out.println("paramStr " + i + "_" + paramStr + ", key = " + key + ", key = " + value); 96 | for (int k = 0; k < 2; k++) { 97 | paramMap.put(param[0].trim(), param[1].trim()); 98 | } 99 | } 100 | list.add(paramMap); 101 | 102 | int startPositionNew = currentIndex + paramsStr.length() + 2; 103 | fileStr = fileStr.substring(startPositionNew, fileStr.length()); 104 | 105 | } 106 | return list; 107 | } 108 | 109 | public static Map getParamMapByAnnotationParamsStr(String paramsStr) { 110 | Map paramMap = new HashMap<>(); 111 | String[] paramArray = paramsStr.toString().split(","); 112 | for (int i = 0; i < paramArray.length; i++) { 113 | String paramStr = paramArray[i]; 114 | String[] param = paramStr.toString().split("="); 115 | for (int k = 0; k < 2; k++) { 116 | param[1] = param[1].replace("\"", ""); 117 | paramMap.put(param[0].trim(), param[1].trim()); 118 | } 119 | } 120 | Iterator> it = paramMap.entrySet().iterator(); 121 | while (it.hasNext()) { 122 | Map.Entry entry = it.next(); 123 | System.out.println("key= " + entry.getKey() + " value= " + entry.getValue()); 124 | } 125 | return paramMap; 126 | } 127 | 128 | public static String underlineToCamel(String param) { 129 | if (param == null || "".equals(param.trim())) { 130 | return ""; 131 | } 132 | int len = param.length(); 133 | StringBuilder sb = new StringBuilder(len); 134 | for (int i = 0; i < len; i++) { 135 | char c = param.charAt(i); 136 | if (c == '_') { 137 | if (++i < len) { 138 | sb.append(Character.toUpperCase(param.charAt(i))); 139 | } 140 | } else { 141 | sb.append(c); 142 | } 143 | } 144 | return sb.toString(); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/guider/utils/TypeUtil.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.guider.utils; 2 | 3 | import com.squareup.javapoet.ClassName; 4 | import com.squareup.javapoet.TypeName; 5 | 6 | /** 7 | * Created by obo on 2017/11/27. 8 | */ 9 | 10 | public class TypeUtil { 11 | public static final String BOOL = "boolean"; 12 | public static final String INT = "int"; 13 | public static final String BYTE = "byte"; 14 | public static final String SHORT = "short"; 15 | public static final String VOID = "void"; 16 | public static final String LONG = "long"; 17 | public static final String CHAR = "char"; 18 | public static final String FLOAT = "float"; 19 | public static final String DOUBLE = "double"; 20 | public static final String BITMAP = "Bitmap"; 21 | 22 | 23 | public static final String STRING = "String"; 24 | public static final String OBJECT = "Object"; 25 | 26 | 27 | public static TypeName getTypeNameWithStr(String typeStr) { 28 | TypeName typeName = null; 29 | switch (typeStr) { 30 | case BOOL: 31 | case BYTE: 32 | case SHORT: 33 | case VOID: 34 | case LONG: 35 | case CHAR: 36 | case FLOAT: 37 | case DOUBLE: 38 | typeName = ClassName.get("java.lang", StringUtil.getTypeWithFirstUpperCase(typeStr)); 39 | break; 40 | case INT: 41 | typeName = ClassName.get("java.lang", "Integer"); 42 | break; 43 | case STRING: 44 | typeName = ClassName.get("java.lang", StringUtil.getTypeWithFirstUpperCase(typeStr)); 45 | break; 46 | case BITMAP: 47 | typeName = ClassName.get("android.graphics", "Bitmap"); 48 | break; 49 | } 50 | return typeName; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/router/annotation/RegisterModule.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.router.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | 7 | @Retention(RetentionPolicy.CLASS) 8 | public @interface RegisterModule { 9 | String[] moduleNames(); 10 | } 11 | -------------------------------------------------------------------------------- /annotation/src/main/java/com/joybar/annotation/router/annotation/RegisterRouter.java: -------------------------------------------------------------------------------- 1 | package com.joybar.annotation.router.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 joybar on 04/11/2017. 10 | */ 11 | @Target(ElementType.TYPE) 12 | @Retention(RetentionPolicy.CLASS) 13 | public @interface RegisterRouter { 14 | String module() default ""; 15 | 16 | String path() default ""; 17 | 18 | boolean isAutoRegistered() default true; 19 | } 20 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion rootProject.ext.android.compileSdkVersion 5 | buildToolsVersion rootProject.ext.android.buildToolsVersion 6 | defaultConfig { 7 | applicationId rootProject.ext.android.applicationId 8 | minSdkVersion rootProject.ext.android.minSdkVersion 9 | targetSdkVersion rootProject.ext.android.targetSdkVersion 10 | versionCode rootProject.ext.android.versionCode 11 | versionName rootProject.ext.android.versionName 12 | resourcePrefix 'app_' 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | javaCompileOptions { 15 | annotationProcessorOptions { 16 | includeCompileClasspath true 17 | } 18 | } 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 24 | buildConfigField "boolean", "IS_DEBUG_TYPE", project.is_debug_type 25 | } 26 | debug { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | buildConfigField "boolean", "IS_DEBUG_TYPE", project.is_debug_type 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation fileTree(include: ['*.jar'], dir: 'libs') 36 | implementation rootProject.ext.dependencies.supportv7 37 | implementation rootProject.ext.dependencies.constraintlayout 38 | testImplementation 'junit:junit:4.12' 39 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 40 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 41 | implementation project(':moduleshop') 42 | implementation project(':moduleuser') 43 | 44 | } 45 | -------------------------------------------------------------------------------- /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/androidTest/java/com/joybar/androidrouter/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.androidrouter; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.joybar.androidrouter", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/joybar/androidrouter/App.java: -------------------------------------------------------------------------------- 1 | package com.joybar.androidrouter; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.joybar.annotation.router.annotation.RegisterModule; 8 | import com.joybar.compiler.helper.RouterInject; 9 | import com.joybar.librouter.application.ApplicationService; 10 | import com.joybar.librouter.routercore.Router; 11 | import com.joybar.librouter.routercore.Rule; 12 | import com.joybar.librouter.routerservice.RouterServiceManager; 13 | import com.joybar.moduleshop.application.ShopApplication; 14 | import com.joybar.moduleuser.application.UserReleaseApplication; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by obo on 2017/11/28. 21 | */ 22 | @RegisterModule(moduleNames = {"user", "shop"}) 23 | public class App extends Application implements ApplicationService { 24 | 25 | private static App INSTANCE = null; 26 | private static final String TAG = "App"; 27 | 28 | public static App getInstance() { 29 | Log.d(TAG, "get application"); 30 | return INSTANCE; 31 | } 32 | 33 | @Override 34 | protected void attachBaseContext(Context base) { 35 | super.attachBaseContext(base); 36 | INSTANCE = this; 37 | } 38 | 39 | @Override 40 | public void onCreate() { 41 | super.onCreate(); 42 | registerRouter(); 43 | } 44 | 45 | 46 | 47 | private void registerRouter(){ 48 | //RouterGuider.inject(this); 49 | initRouterByAnnotation();// 注册Activity 路由 50 | // OR 51 | // initRouterByDynamic(); // 注册Activity 路由 52 | loadModuleApplicationService(); //加载每个module的Application,使其完成初始化工作 53 | RouterServiceManager.getInstance().init(this);// 注册组件之间服务路由 54 | 55 | } 56 | 57 | private void initRouterByAnnotation() { 58 | 59 | //参数为module name 60 | RouterInject.registerModule("shop"); 61 | RouterInject.registerModule("user"); 62 | 63 | 64 | // RouterInject.inject("com.joybar.moduleuser.MainActivity"); 65 | // RouterInject.inject("com.joybar.moduleshop.MainActivity"); 66 | // RouterInject.inject("com.joybar.moduleshop.ReceiveParamActivity"); 67 | // RouterInject.inject("com.joybar.moduleshop.FinishWithResultActivity"); 68 | // RouterInject.inject("com.joybar.moduleshop.PostModuleDataActivity"); 69 | 70 | } 71 | 72 | private void initRouterByDynamic() { 73 | //需要把每个注册的页面添加到路由表里面,不推荐 74 | Router.registerRouters(new Router.RouterTable() { 75 | @Override 76 | public List buildRuleList() { 77 | List ruleList = new ArrayList<>(); 78 | ruleList.add(new Rule("user", "main", com.joybar.moduleuser.MainActivity.class)); 79 | ruleList.add(new Rule("shop", "main", com.joybar.moduleshop.MainActivity.class)); 80 | ruleList.add(new Rule("shop", "receive_param", com.joybar.moduleshop.ReceiveParamActivity.class)); 81 | ruleList.add(new Rule("shop", "finish_with_result", com.joybar.moduleshop.FinishWithResultActivity.class)); 82 | return ruleList; 83 | } 84 | }); 85 | } 86 | 87 | 88 | @Override 89 | public void loadModuleApplicationService() { 90 | UserReleaseApplication.getInstance().loadModuleApplicationService(); 91 | ShopApplication.getInstance().loadModuleApplicationService(); 92 | } 93 | 94 | @Override 95 | public Application getApplication() { 96 | return getInstance(); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/joybar/androidrouter/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.joybar.androidrouter; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | 6 | import com.joybar.librouter.guider.routertable.RouterTable$$Moduleuser; 7 | 8 | 9 | public class MainActivity extends AppCompatActivity { 10 | 11 | private static final String TAG = "MainActivity"; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | gotoUserMain(); 18 | } 19 | 20 | private void gotoUserMain() { 21 | RouterTable$$Moduleuser 22 | .launchMain() 23 | .navigate(MainActivity.this); 24 | finish(); 25 | } 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /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/app_activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /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/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/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 | AndroidRouter 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/joybar/androidrouter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.androidrouter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | apply from: "config.gradle" 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.0.0' 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0' 14 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /compiler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /compiler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java-library' 2 | 3 | dependencies { 4 | implementation fileTree(include: ['*.jar'], dir: 'libs') 5 | implementation project(':annotation') 6 | compile 'com.google.auto.service:auto-service:1.0-rc2' 7 | compile 'com.squareup:javapoet:1.9.0' 8 | } 9 | 10 | sourceCompatibility = "1.7" 11 | targetCompatibility = "1.7" 12 | 13 | apply from: 'gradle_push.gradle' -------------------------------------------------------------------------------- /compiler/gradle_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'com.jfrog.bintray' 3 | 4 | def VERSION = "1.1.7" 5 | def GROUP = 'com.joybar.router' 6 | def ARTIFACT_ID = 'compiler' 7 | 8 | group = GROUP 9 | version = VERSION 10 | 11 | def siteUrl = 'https://github.com/myjoybar/Android-Router' 12 | def issuesUrl = 'https://github.com/myjoybar/Android-Router/issues' 13 | def gitUrl = 'https://github.com/myjoybar/Android-Router.git' 14 | 15 | task sourcesJar(type: Jar, dependsOn: classes) { 16 | from sourceSets.main.allSource 17 | classifier = 'sources' 18 | } 19 | 20 | artifacts { 21 | archives sourcesJar 22 | } 23 | 24 | publishing { 25 | publications { 26 | bintray(MavenPublication) { 27 | groupId GROUP 28 | artifactId ARTIFACT_ID 29 | version VERSION 30 | 31 | artifact sourcesJar 32 | from components.java 33 | } 34 | } 35 | } 36 | 37 | bintray { 38 | Properties properties = new Properties() 39 | boolean hasLocalFile = false 40 | if (project.rootProject.file('local.properties').exists()) { 41 | hasLocalFile = true 42 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 43 | } 44 | user = hasLocalFile ? properties.getProperty("bintray.user") : "" 45 | key = hasLocalFile ? properties.getProperty("bintray.apikey") : "" 46 | 47 | publications = ['bintray'] 48 | pkg { 49 | repo = "Andorid-Maven" 50 | name = "router-compiler" 51 | websiteUrl = siteUrl 52 | issueTrackerUrl = issuesUrl 53 | vcsUrl = gitUrl 54 | desc = "Annotation compiler for Router library." 55 | labels = ["Android", "Router", "annotation", "compiler"] 56 | licenses = ["Apache-2.0"] 57 | publicDownloadNumbers = true 58 | publish = true 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/joybar/compiler/RegisterRouterProcessor.java: -------------------------------------------------------------------------------- 1 | package com.joybar.compiler; 2 | 3 | import com.google.auto.service.AutoService; 4 | import com.joybar.annotation.router.annotation.RegisterModule; 5 | import com.joybar.annotation.router.annotation.RegisterRouter; 6 | import com.joybar.compiler.data.RouterModule; 7 | import com.joybar.compiler.helper.CompilerHelper; 8 | import com.squareup.javapoet.JavaFile; 9 | import com.squareup.javapoet.MethodSpec; 10 | import com.squareup.javapoet.TypeSpec; 11 | 12 | import java.io.IOException; 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.HashSet; 16 | import java.util.List; 17 | import java.util.Set; 18 | 19 | import javax.annotation.processing.AbstractProcessor; 20 | import javax.annotation.processing.Filer; 21 | import javax.annotation.processing.ProcessingEnvironment; 22 | import javax.annotation.processing.Processor; 23 | import javax.annotation.processing.RoundEnvironment; 24 | import javax.lang.model.SourceVersion; 25 | import javax.lang.model.element.Element; 26 | import javax.lang.model.element.Modifier; 27 | import javax.lang.model.element.TypeElement; 28 | 29 | /** 30 | * Created by joybar on 04/11/2017. 31 | */ 32 | @AutoService(Processor.class) 33 | public class RegisterRouterProcessor extends AbstractProcessor { 34 | private Filer mFiler; 35 | 36 | @Override 37 | public synchronized void init(ProcessingEnvironment processingEnv) { 38 | super.init(processingEnv); 39 | mFiler = processingEnv.getFiler(); 40 | } 41 | 42 | @Override 43 | public boolean process(Set annotations, RoundEnvironment roundEnv) { 44 | for (TypeElement element : annotations) { 45 | if (element.getQualifiedName().toString().equals(RegisterRouter.class.getCanonicalName())) { 46 | handleRegisterRouter(roundEnv); 47 | } 48 | } 49 | 50 | 51 | return false; 52 | } 53 | 54 | @Override 55 | public Set getSupportedAnnotationTypes() { 56 | Set set = new HashSet<>(); 57 | set.add(RegisterRouter.class.getCanonicalName()); 58 | set.add(RegisterModule.class.getCanonicalName()); 59 | return set; 60 | } 61 | 62 | @Override 63 | public SourceVersion getSupportedSourceVersion() { 64 | return SourceVersion.latestSupported(); 65 | } 66 | 67 | private String[] handleRegisterModules(RoundEnvironment roundEnv) { 68 | Set registerModuleSet = roundEnv.getElementsAnnotatedWith(RegisterModule.class); 69 | String[] moduleNames = null; 70 | if (registerModuleSet != null && registerModuleSet.size() > 0) { 71 | Element modules = registerModuleSet.iterator().next(); 72 | moduleNames = modules.getAnnotation(RegisterModule.class).moduleNames(); 73 | } 74 | return moduleNames; 75 | } 76 | 77 | private void handleRegisterRouter(RoundEnvironment roundEnv) { 78 | System.out.println("--------start handleRegisterRouter--------"); 79 | List routerModuleList = new ArrayList<>(0); 80 | Set registerRouterSet = roundEnv.getElementsAnnotatedWith(RegisterRouter.class); 81 | for (Element e : registerRouterSet) { 82 | if (!(e instanceof TypeElement)) { 83 | continue; 84 | } 85 | TypeElement typeElement = (TypeElement) e; 86 | 87 | String module = typeElement.getAnnotation(RegisterRouter.class).module(); 88 | module = module == null ? "" : module; 89 | String path = typeElement.getAnnotation(RegisterRouter.class).path(); 90 | path = path == null ? "" : path; 91 | boolean isAutoRegistered = typeElement.getAnnotation(RegisterRouter.class).isAutoRegistered(); 92 | String classFullName = typeElement.getQualifiedName().toString(); 93 | System.out.println("fullName=" + classFullName + ", SimpleName=" + typeElement.getSimpleName() + ", module=" + module + ", path=" + path); 94 | generateRouterRegisterClass(module, path, classFullName); 95 | RouterModule routerModule = new RouterModule(classFullName, module, path, isAutoRegistered); 96 | routerModuleList.add(routerModule); 97 | } 98 | 99 | generateRouterRule(routerModuleList); 100 | 101 | } 102 | 103 | private void generateRouterRegisterClass(String module, String path, String classFullName) { 104 | try { 105 | String pkgName = CompilerHelper.ROUTER_MANAGER_PKN; 106 | String className = CompilerHelper.getCombineClassFullName(classFullName) + CompilerHelper.ROUTER_MANAGER_CLASS_NAME_SUFFIX; 107 | String methodName = CompilerHelper.ROUTER_MANAGER_METHOD_NAME; 108 | MethodSpec registerRouter = computeAddRouter(methodName, module, path, classFullName); 109 | 110 | TypeSpec routerManger = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC).addMethod(registerRouter).build(); 111 | JavaFile javaFile = JavaFile.builder(pkgName, routerManger).build(); 112 | javaFile.writeTo(mFiler); 113 | } catch (IOException e) { 114 | e.printStackTrace(); 115 | } 116 | } 117 | 118 | private void generateRouterRule(List moduleList) { 119 | System.out.println("moduleList = " + Arrays.toString(moduleList.toArray())); 120 | try { 121 | String pkgName = CompilerHelper.ROUTER_MANAGER_TABLE_PKN; 122 | String className = CompilerHelper.ROUTER_MANAGER_TABLE_CLASS_NAME + moduleList.get(0).module; 123 | String methodName = CompilerHelper.ROUTER_MANAGER_TABLE_METHOD_NAME; 124 | MethodSpec registerRouter = computeRouterTable(methodName, moduleList); 125 | 126 | TypeSpec routerManger = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC).addMethod(registerRouter).build(); 127 | JavaFile javaFile = JavaFile.builder(pkgName, routerManger).build(); 128 | javaFile.writeTo(mFiler); 129 | } catch (IOException e) { 130 | e.printStackTrace(); 131 | } 132 | 133 | } 134 | 135 | private MethodSpec computeRouterTable(String methodName, List routerModuleList) { 136 | 137 | MethodSpec.Builder builder = 138 | MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addComment(CompilerHelper.getCommentInfo()).returns(void.class); 139 | for (int i = 0; i < routerModuleList.size(); i++) { 140 | builder.addStatement(CompilerHelper.ROUTER_MANAGER_TABLE_ROUTERINJECT + "(\"" + routerModuleList.get(i).classFullName + "\"" + ")"); 141 | } 142 | return builder.build(); 143 | 144 | } 145 | 146 | 147 | private MethodSpec computeAddRouter(String methodName, String module, String path, String classFullName) { 148 | return MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addComment(CompilerHelper.getCommentInfo()).returns(void.class).addStatement(CompilerHelper.ROUTER + "(\"" + module + "\"," + "\"" + path + "\"," + classFullName + CompilerHelper.CLASS_SUFFIX + ")").build(); 149 | 150 | } 151 | 152 | 153 | } 154 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/joybar/compiler/data/RouterModule.java: -------------------------------------------------------------------------------- 1 | package com.joybar.compiler.data; 2 | 3 | public class RouterModule { 4 | public String classFullName = ""; 5 | public String module = ""; 6 | public String path = ""; 7 | public boolean isAutoRegistered = false; 8 | 9 | public RouterModule(String classFullName, String module, String path, boolean isAutoRegistered) { 10 | this.classFullName = classFullName; 11 | this.module = module; 12 | this.path = path; 13 | this.isAutoRegistered = isAutoRegistered; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return "RouterModule{" + "classFullName='" + classFullName + '\'' + ", module='" + module + '\'' + ", path='" + path + '\'' + ", " + 19 | "isAutoRegistered=" + isAutoRegistered + '}'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/joybar/compiler/helper/CompilerHelper.java: -------------------------------------------------------------------------------- 1 | package com.joybar.compiler.helper; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /** 7 | * Created by joybar on 19/11/2017. 8 | */ 9 | 10 | public class CompilerHelper { 11 | public static final String ROUTER_MANAGER_PKN = "com.joybar.routermanager.helper"; 12 | public static final String ROUTER_MANAGER_CLASS_NAME_SUFFIX = "$RouterRegister"; 13 | public static final String ROUTER_MANAGER_METHOD_NAME = "registerRouter"; 14 | public static final String CLASS_SUFFIX = ".class"; 15 | public static final String ROUTER = " com.joybar.librouter.routercore.Router.registerRouter"; 16 | public static final String COMMENT = "This class was generated automatically "; 17 | 18 | public static final String ROUTER_MANAGER_TABLE_PKN = "com.joybar.routermanager.helper.table"; 19 | public static final String ROUTER_MANAGER_TABLE_CLASS_NAME = "RouterTable_"; 20 | public static final String ROUTER_MANAGER_TABLE_METHOD_NAME = "createRouterTable"; 21 | public static final String ROUTER_MANAGER_TABLE_ROUTERINJECT= "com.joybar.compiler.helper.RouterInject.inject"; 22 | 23 | 24 | public static String getCombineClassFullName(String classFullName){ 25 | return classFullName.replace(".", "_"); 26 | } 27 | 28 | public static String getCommentInfo() { 29 | Date d = new Date(); 30 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 31 | return COMMENT + sdf.format(d); 32 | } 33 | 34 | public static void autoRegister(String className){ 35 | RouterInject.inject(className); 36 | } 37 | 38 | 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /compiler/src/main/java/com/joybar/compiler/helper/RouterInject.java: -------------------------------------------------------------------------------- 1 | package com.joybar.compiler.helper; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | 6 | /** 7 | * Created by joybar on 19/11/2017. 8 | */ 9 | 10 | public class RouterInject { 11 | 12 | public static void registerModule(String moduleName) { 13 | String className = CompilerHelper.ROUTER_MANAGER_TABLE_CLASS_NAME + moduleName; 14 | try { 15 | className = CompilerHelper.ROUTER_MANAGER_TABLE_PKN + "." + className; 16 | System.out.println("registerModule classFullName=" + className); 17 | Class clazz = Class.forName(className); 18 | Method method = clazz.getDeclaredMethod(CompilerHelper.ROUTER_MANAGER_TABLE_METHOD_NAME); 19 | System.out.println("method=" + method); 20 | method.invoke(null); 21 | } catch (ClassNotFoundException e) { 22 | e.printStackTrace(); 23 | } catch (NoSuchMethodException e) { 24 | e.printStackTrace(); 25 | } catch (InvocationTargetException e) { 26 | e.printStackTrace(); 27 | } catch (IllegalAccessException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | 32 | 33 | public static void inject(String classPath) { 34 | String className = CompilerHelper.getCombineClassFullName(classPath) + CompilerHelper.ROUTER_MANAGER_CLASS_NAME_SUFFIX; 35 | try { 36 | className = CompilerHelper.ROUTER_MANAGER_PKN + "." + className; 37 | System.out.println("inject classFullName=" + className); 38 | Class clazz = Class.forName(className); 39 | Method method = clazz.getDeclaredMethod(CompilerHelper.ROUTER_MANAGER_METHOD_NAME); 40 | System.out.println("method=" + method); 41 | method.invoke(null); 42 | } catch (ClassNotFoundException e) { 43 | e.printStackTrace(); 44 | } catch (NoSuchMethodException e) { 45 | e.printStackTrace(); 46 | } catch (InvocationTargetException e) { 47 | e.printStackTrace(); 48 | } catch (IllegalAccessException e) { 49 | e.printStackTrace(); 50 | } 51 | 52 | } 53 | 54 | 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /config.gradle: -------------------------------------------------------------------------------- 1 | 2 | ext { 3 | android = [ 4 | applicationId:"com.joybar.androidrouter", 5 | compileSdkVersion: 26, 6 | targetSdkVersion : 26, 7 | minSdkVersion : 14, 8 | buildToolsVersion: "26.0.2", 9 | versionCode:6, 10 | versionName:"1.2.1" 11 | ] 12 | 13 | 14 | dependencies = [ 15 | supportv4 : "com.android.support:support-v4:26.1.0", 16 | supportv7 : "com.android.support:appcompat-v7:26.1.0", 17 | recyclerviewv7 : 'com.android.support:recyclerview-v7:26.1.0', 18 | constraintlayout : 'com.android.support.constraint:constraint-layout:1.0.2' 19 | ] 20 | 21 | staging = [ 22 | versionCode:348, 23 | versionName:'"3.0.4"', 24 | 25 | ] 26 | production = [ 27 | versionCode:190, 28 | versionName:'"3.0.3"' 29 | ] 30 | 31 | isDebugType = false //module 32 | isPrintLog= false 33 | 34 | } 35 | project.ext.set("is_debug_type", "false") //主APP 36 | project.ext.set("is_print_log", "false") 37 | 38 | -------------------------------------------------------------------------------- /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/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 19 15:41:11 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-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 | -------------------------------------------------------------------------------- /librouter/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /librouter/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | android { 3 | compileSdkVersion rootProject.ext.android.compileSdkVersion 4 | 5 | 6 | 7 | defaultConfig { 8 | minSdkVersion rootProject.ext.android.minSdkVersion 9 | targetSdkVersion rootProject.ext.android.targetSdkVersion 10 | versionCode rootProject.ext.android.versionCode 11 | versionName rootProject.ext.android.versionName 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | javaCompileOptions { 15 | annotationProcessorOptions { 16 | includeCompileClasspath true 17 | } 18 | } 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(include: ['*.jar'], dir: 'libs') 32 | implementation rootProject.ext.dependencies.supportv7 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 35 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 36 | api project(':annotation') 37 | api project(':compiler') 38 | } 39 | 40 | apply from: 'gradle_push.gradle' 41 | -------------------------------------------------------------------------------- /librouter/gradle_push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group = "com.joybar.router" 5 | version = "1.1.7" 6 | 7 | def siteUrl = 'https://github.com/myjoybar/Android-Router' 8 | def issuesUrl = 'https://github.com/myjoybar/Android-Router/issues' 9 | def gitUrl = 'https://github.com/myjoybar/Android-Router.git' 10 | def ARTIFACT_ID = 'librouter' 11 | 12 | task sourcesJar(type: Jar) { 13 | from android.sourceSets.main.java.srcDirs 14 | classifier = 'sources' 15 | } 16 | 17 | task javadoc(type: Javadoc) { 18 | options.encoding = 'UTF-8' 19 | source = android.sourceSets.main.java.srcDirs 20 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 21 | failOnError false 22 | } 23 | 24 | task javadocJar(type: Jar, dependsOn: javadoc) { 25 | from javadoc.getDestinationDir() 26 | classifier = 'javadoc' 27 | } 28 | 29 | artifacts { 30 | archives javadocJar 31 | archives sourcesJar 32 | } 33 | 34 | install { 35 | repositories.mavenInstaller { 36 | // This generates POM.xml with proper parameters 37 | pom { 38 | project { 39 | packaging 'aar' 40 | // Add your description here 41 | description 'A simple and easy to use Android Router' 42 | name ARTIFACT_ID 43 | url siteUrl 44 | // Set your license 45 | licenses { 46 | license { 47 | name 'The Apache Software License, Version 2.0' 48 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 49 | } 50 | } 51 | developers { 52 | developer { 53 | id 'joybar' 54 | name 'joybar' 55 | email 'myjoybar@gmail.com' 56 | } 57 | } 58 | scm { 59 | connection gitUrl 60 | developerConnection gitUrl 61 | url siteUrl 62 | } 63 | } 64 | } 65 | } 66 | } 67 | 68 | Properties properties = new Properties() 69 | 70 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 71 | bintray { 72 | user = properties.getProperty("bintray.user") 73 | key = properties.getProperty("bintray.apikey") 74 | configurations = ['archives'] 75 | pkg { 76 | repo = "Andorid-Maven" 77 | name = ARTIFACT_ID 78 | websiteUrl = siteUrl 79 | vcsUrl = gitUrl 80 | issueTrackerUrl = issuesUrl 81 | licenses = ["Apache-2.0"] 82 | publish = true 83 | } 84 | } 85 | //./gradlew install 86 | //./gradlew bintrayUpload 87 | 88 | //./gradlew javadocJar 89 | //./gradlew sourcesJar 90 | //./gradlew install 91 | //./gradlew bintrayUpload 92 | -------------------------------------------------------------------------------- /librouter/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 | -------------------------------------------------------------------------------- /librouter/src/androidTest/java/com/joybar/librouter/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.joybar.librouter.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /librouter/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/application/ApplicationService.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.application; 2 | 3 | import android.app.Application; 4 | 5 | /** 6 | * Created by joybar on 03/12/2017. 7 | */ 8 | 9 | public interface ApplicationService { 10 | void loadModuleApplicationService(); //初始化工作 11 | Application getApplication(); //获取主APP的Application或者module在debug时自己的application 12 | } 13 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/Builder.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider; 2 | 3 | 4 | import com.joybar.annotation.guider.CodeMaker; 5 | 6 | /** 7 | * Created by joybar on 02/12/2017. 8 | */ 9 | 10 | public class Builder { 11 | 12 | private static String ROUTER_GUIDER_PKN = "com.joy.testmodule.guider.routertable"; 13 | private static String FILE_PATH = "/app/src/main/java"; 14 | 15 | 16 | public static void main(String[] args) { 17 | System.out.println("=============start build============="); 18 | CodeMaker.autoGenerateModuleMethodName("moduleshop"); 19 | CodeMaker.autoGenerateModuleMethodName("moduleuser"); 20 | System.out.println("=============end build============="); 21 | } 22 | 23 | /** 24 | * 25 | * @param moduleName 26 | * @param filePath 27 | * @param packName 28 | */ 29 | public static void buildGuiderJavaFile(String moduleName, String filePath, String packName) { 30 | CodeMaker.autoGenerateModuleMethodName(moduleName, filePath, packName); 31 | //CodeMaker.autoGenerateModuleMethodName("moduleshop","/baselib/src/main/java","com.joy.baselib.guider.routertable"); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/annotation/BigData.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.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 obo on 2017/11/24. 10 | */ 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface BigData { 14 | String key() default ""; 15 | } 16 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/annotation/DataParam.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.annotation; 2 | 3 | /** 4 | * Created by obo 5 | */ 6 | 7 | public @interface DataParam { 8 | } 9 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/annotation/RegisterLaunch.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.annotation; 2 | 3 | /** 4 | * Created by joybar on 2017/12/5. 5 | */ 6 | 7 | public @interface RegisterLaunch { 8 | } 9 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/routerguider/BigDataManager.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.routerguider; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by obo on 2017/11/27. 8 | */ 9 | 10 | final class BigDataManager { 11 | private static Map bigData = new HashMap<>(); 12 | 13 | static void putBigData(String key, Object object) { 14 | bigData.put(key, object); 15 | } 16 | 17 | static Object removeBigData(String key) { 18 | return bigData.remove(key); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/routerguider/RouterGuider.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.routerguider; 2 | 3 | import android.app.Activity; 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.graphics.Bitmap; 7 | import android.os.Bundle; 8 | import android.os.Parcelable; 9 | 10 | import com.joybar.librouter.routercore.InterceptorCallback; 11 | import com.joybar.librouter.routercore.Router; 12 | import com.joybar.librouter.routercore.Rule; 13 | import com.joybar.librouter.guider.annotation.BigData; 14 | import com.joybar.librouter.routercore.interceptor.RouteInterceptor; 15 | 16 | import java.io.Serializable; 17 | import java.lang.reflect.Field; 18 | 19 | /** 20 | * Created by obo on 2017/11/23. 21 | */ 22 | public class RouterGuider { 23 | 24 | private Rule rule; 25 | private Bundle bundle = new Bundle(); 26 | private InterceptorCallback mNavigationCallback; 27 | private RouteInterceptor interceptor; 28 | 29 | public static void init(Application application) { 30 | } 31 | public static void inject(Object activity) { 32 | 33 | Field []fields = activity.getClass().getDeclaredFields(); 34 | for (Field field : fields) { 35 | if (field.getAnnotation(BigData.class) != null) { 36 | Object data = BigDataManager.removeBigData(field.getName()); 37 | if (data != null) { 38 | try { 39 | field.set(activity, data); 40 | } catch (IllegalAccessException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | } 45 | } 46 | } 47 | 48 | public RouterGuider(String module, String path) { 49 | rule = new Rule(module, path); 50 | } 51 | 52 | 53 | public void navigate( Context context) { 54 | Router.create() 55 | .buildRule(rule) 56 | .addInterceptor(interceptor) 57 | .withInterceptorCallback(mNavigationCallback) 58 | .withExtra(bundle) 59 | .navigate(context); 60 | } 61 | 62 | public void navigate( Context context, int flag) { 63 | Router.create() 64 | .buildRule(rule) 65 | .addInterceptor(interceptor) 66 | .withInterceptorCallback(mNavigationCallback) 67 | .withExtra(bundle) 68 | .navigate(context,flag); 69 | } 70 | 71 | 72 | public void navigate( Activity activity, int requestCode) { 73 | Router.create() 74 | .buildRule(rule) 75 | .addInterceptor(interceptor) 76 | .withInterceptorCallback(mNavigationCallback) 77 | .withExtra(bundle) 78 | .navigate(activity,requestCode); 79 | } 80 | 81 | public RouterGuider withCallBack(InterceptorCallback navigationCallback) { 82 | mNavigationCallback = navigationCallback; 83 | return this; 84 | } 85 | 86 | public RouterGuider withRouteInterceptor(RouteInterceptor interceptor) { 87 | this.interceptor = interceptor; 88 | return this; 89 | } 90 | 91 | public RouterGuider withBundle(Bundle bundle) { 92 | return this; 93 | } 94 | 95 | public RouterGuider withInt(String key, int value) { 96 | bundle.putInt(key, value); 97 | return this; 98 | } 99 | 100 | public RouterGuider withLong(String key, long value) { 101 | bundle.putLong(key, value); 102 | return this; 103 | } 104 | 105 | public RouterGuider withString(String key, String value) { 106 | bundle.putString(key, value); 107 | return this; 108 | } 109 | 110 | public RouterGuider withSerializable(String key, Serializable value) { 111 | bundle.putSerializable(key, value); 112 | return this; 113 | } 114 | 115 | public RouterGuider withParcelable(String key, Parcelable value) { 116 | bundle.putParcelable(key, value); 117 | return this; 118 | } 119 | 120 | public RouterGuider withObject(String key, Object value) { 121 | return this; 122 | } 123 | 124 | public RouterGuider withShort(String key, short value) { 125 | bundle.putShort(key, value); 126 | return this; 127 | } 128 | 129 | public RouterGuider withBoolean(String key, boolean value) { 130 | bundle.putBoolean(key, value); 131 | return this; 132 | } 133 | 134 | public RouterGuider withByte(String key, byte value) { 135 | bundle.putByte(key, value); 136 | return this; 137 | } 138 | 139 | public RouterGuider withChar(String key, char value) { 140 | bundle.putChar(key, value); 141 | return this; 142 | } 143 | 144 | public RouterGuider withBigBitmap(String key, Bitmap value) { 145 | BigDataManager.putBigData(key, value); 146 | return this; 147 | } 148 | 149 | // Animation 150 | public RouterGuider withTransition(int enterAnim, int exitAnim) { 151 | return this; 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/routertable/RouterTable$$Moduleshop.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.routertable; 2 | 3 | import com.joybar.librouter.guider.routerguider.RouterGuider; 4 | import java.lang.Integer; 5 | import java.lang.String; 6 | 7 | public final class RouterTable$$Moduleshop { 8 | public static RouterGuider launchFinishWithResult() { 9 | // This class was generated automatically 2019-04-01 13:46:39 10 | // module=shop,path=finish_with_result 11 | RouterGuider routerGuider = new RouterGuider("shop", "finish_with_result"); 12 | return routerGuider; 13 | } 14 | 15 | public static RouterGuider launchMain() { 16 | // This class was generated automatically 2019-04-01 13:46:39 17 | // module=shop,path=main 18 | RouterGuider routerGuider = new RouterGuider("shop", "main"); 19 | return routerGuider; 20 | } 21 | 22 | public static RouterGuider launchReceiveParam(String address) { 23 | // This class was generated automatically 2019-04-01 13:46:39 24 | // module=shop,path=receive_param 25 | RouterGuider routerGuider = new RouterGuider("shop", "receive_param"); 26 | routerGuider.withString("address", address); 27 | return routerGuider; 28 | } 29 | 30 | public static RouterGuider launchReceiveParam(String name, Integer id) { 31 | // This class was generated automatically 2019-04-01 13:46:39 32 | // module=shop,path=receive_param 33 | RouterGuider routerGuider = new RouterGuider("shop", "receive_param"); 34 | routerGuider.withString("name", name); 35 | routerGuider.withInt("id", id); 36 | return routerGuider; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/routertable/RouterTable$$Moduleuser.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.guider.routertable; 2 | 3 | import com.joybar.librouter.guider.routerguider.RouterGuider; 4 | 5 | public final class RouterTable$$Moduleuser { 6 | public static RouterGuider launchMain() { 7 | // This class was generated automatically 2019-04-01 13:46:39 8 | // module=user,path=main 9 | RouterGuider routerGuider = new RouterGuider("user", "main"); 10 | return routerGuider; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/guider/sh/route.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "start" 3 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/IRouterManagerService.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | 7 | import com.joybar.librouter.routercore.interceptor.RouteInterceptor; 8 | 9 | 10 | /** 11 | * Created by joybar on 12/11/2017. 12 | */ 13 | 14 | public interface IRouterManagerService { 15 | 16 | IRouterManagerService buildRule(Rule rule); 17 | 18 | IRouterManagerService withExtra(Bundle bundle); 19 | 20 | IRouterManagerService withInterceptorCallback(InterceptorCallback interceptorCallback); 21 | 22 | IRouterManagerService addInterceptor(RouteInterceptor routeInterceptor); 23 | 24 | boolean isIntercepted(); 25 | 26 | void navigate(Context context); 27 | 28 | void navigate(Context context,int flag); 29 | 30 | void navigate(Activity activity,int requestCode); 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/InterceptorCallback.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | /** 4 | * Created by joybar on 12/11/2017. 5 | */ 6 | 7 | public interface InterceptorCallback { 8 | void onIntercept(Object result); 9 | void onContinue(); 10 | } 11 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/Router.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | /** 8 | * Created by joybar on 2017/11/13. 9 | */ 10 | 11 | public class Router { 12 | 13 | public static Map ruleMap = new HashMap<>(); 14 | 15 | public static void registerRouter(String module, String path, Class clazz) { 16 | Rule rule = new Rule(module, path, clazz); 17 | ruleMap.put(rule, rule); 18 | } 19 | 20 | 21 | public static void registerRouters(RouterTable routeTable) { 22 | List rules = routeTable.buildRuleList(); 23 | if (null != rules && rules.size() != 0) { 24 | for (Rule rule : rules) { 25 | ruleMap.put(rule, rule); 26 | } 27 | } 28 | } 29 | 30 | 31 | public static IRouterManagerService create() { 32 | RouterService routerService = new RouterService(); 33 | return routerService; 34 | } 35 | 36 | 37 | public interface RouterTable { 38 | List buildRuleList(); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/RouterRequest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | import android.os.Bundle; 4 | 5 | /** 6 | * Created by joybar on 12/11/2017. 7 | */ 8 | 9 | public class RouterRequest { 10 | 11 | private Rule rule; 12 | private InterceptorCallback interceptorCallback; 13 | private Bundle bundle; 14 | 15 | public Rule getRule() { 16 | return rule; 17 | } 18 | 19 | public void setRule(Rule rule) { 20 | this.rule = rule; 21 | } 22 | 23 | public InterceptorCallback getInterceptorCallback() { 24 | return interceptorCallback; 25 | } 26 | 27 | public void setInterceptorCallback(InterceptorCallback interceptorCallback) { 28 | this.interceptorCallback = interceptorCallback; 29 | } 30 | 31 | public Bundle getBundle() { 32 | return bundle; 33 | } 34 | 35 | public void setBundle(Bundle bundle) { 36 | this.bundle = bundle; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/RouterService.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | 9 | import com.joybar.librouter.routercore.interceptor.RouteInterceptor; 10 | import com.joybar.librouter.routercore.utils.CheckUtils; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by joybar on 12/11/2017. 17 | */ 18 | 19 | public class RouterService implements IRouterManagerService { 20 | 21 | private RouterRequest routerRequest; 22 | private List routeInterceptors; 23 | 24 | public RouterService() { 25 | routerRequest = new RouterRequest(); 26 | routeInterceptors = new ArrayList<>(); 27 | } 28 | 29 | @Override 30 | public IRouterManagerService buildRule(Rule rule) { 31 | CheckUtils.checkNotNull(rule); 32 | Rule registerRule = Router.ruleMap.get(rule); 33 | if (registerRule == null) { 34 | throw new IllegalArgumentException("You cannot build an unregistered rule"+": "+rule.toString() +",have you registered it?"); 35 | } 36 | routerRequest.setRule(registerRule); 37 | return this; 38 | } 39 | 40 | 41 | @Override 42 | public void navigate(Context context) { 43 | if (!isIntercepted()) { 44 | CheckUtils.checkNotNull(context); 45 | context.startActivity(buildIntent(context)); 46 | } 47 | } 48 | 49 | @Override 50 | public void navigate(Context context, int flag) { 51 | if (!isIntercepted()) { 52 | CheckUtils.checkNotNull(context); 53 | Intent intent = buildIntent(context); 54 | intent.addFlags(flag); 55 | context.startActivity(intent); 56 | } 57 | } 58 | 59 | @Override 60 | public void navigate(Activity activity, int requestCode) { 61 | if (!isIntercepted()) { 62 | CheckUtils.checkNotNull(activity); 63 | activity.startActivityForResult(buildIntent(activity), 64 | requestCode); 65 | } 66 | } 67 | 68 | 69 | private Intent buildIntent(Context context) { 70 | Class klass = routerRequest.getRule().getClazz(); 71 | if (klass == null) { 72 | throw new RuntimeException("class can not be null in RouterRequest,have you set it " + 73 | "in your RouterService"); 74 | } 75 | Intent intent = new Intent(context, routerRequest.getRule().getClazz()); 76 | Bundle bundle = routerRequest.getBundle(); 77 | if (bundle != null) { 78 | intent.putExtras(routerRequest.getBundle()); 79 | } 80 | return intent; 81 | } 82 | 83 | 84 | @Override 85 | public IRouterManagerService withInterceptorCallback(InterceptorCallback interceptorCallback) { 86 | if(null!=interceptorCallback){ 87 | routerRequest.setInterceptorCallback(interceptorCallback); 88 | } 89 | return this; 90 | } 91 | 92 | @Override 93 | public IRouterManagerService addInterceptor(RouteInterceptor routeInterceptor) { 94 | if(null!=routeInterceptor){ 95 | routeInterceptors.add(routeInterceptor); 96 | } 97 | return this; 98 | } 99 | 100 | @Override 101 | public boolean isIntercepted() { 102 | if(null!=routeInterceptors&&routeInterceptors.size()!=0){ 103 | for (RouteInterceptor interceptor : routeInterceptors) { 104 | if (interceptor.isIntercepted(routerRequest)) { 105 | InterceptorCallback interceptorCallback = routerRequest.getInterceptorCallback(); 106 | if (null != interceptorCallback) { 107 | interceptorCallback.onIntercept("this router request is intercepted"); 108 | } 109 | return true; 110 | } 111 | } 112 | InterceptorCallback interceptorCallback = routerRequest.getInterceptorCallback(); 113 | if (null != interceptorCallback) { 114 | interceptorCallback.onContinue(); 115 | } 116 | } 117 | return false; 118 | } 119 | 120 | @Override 121 | public IRouterManagerService withExtra(Bundle bundle) { 122 | if(null!=bundle){ 123 | routerRequest.setBundle(bundle); 124 | } 125 | return this; 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/Rule.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore; 2 | 3 | /** 4 | * Created by joybar on 04/11/2017. 5 | */ 6 | 7 | public class Rule { 8 | 9 | private String module = ""; 10 | private String path = ""; 11 | private Class clazz = null; 12 | 13 | public Rule(String path) { 14 | this.path = path; 15 | } 16 | 17 | public Rule(String module, String path) { 18 | this.module = module; 19 | this.path = path; 20 | } 21 | 22 | public Rule(String module, String path, Class clazz) { 23 | this.module = module; 24 | this.path = path; 25 | this.clazz = clazz; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | return module.hashCode() + path.hashCode(); 31 | } 32 | 33 | @Override 34 | public boolean equals(Object obj) { 35 | 36 | if (obj == this) { 37 | return true; 38 | } 39 | if (obj instanceof Rule) { 40 | Rule rule = (Rule) obj; 41 | return (module.equals(rule.module) && path.equals(rule.path) && module.equals(rule.module)); 42 | } 43 | return super.equals(obj); 44 | } 45 | 46 | public String getModule() { 47 | return module; 48 | } 49 | 50 | public void setModule(String module) { 51 | this.module = module; 52 | } 53 | 54 | public String getPath() { 55 | return path; 56 | } 57 | 58 | public void setPath(String path) { 59 | this.path = path; 60 | } 61 | 62 | public Class getClazz() { 63 | return clazz; 64 | } 65 | 66 | public void setClazz(Class clazz) { 67 | this.clazz = clazz; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return "Rule{" + "module='" + module + '\'' + ", path='" + path + '\'' + ", clazz=" + 73 | clazz + '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/interceptor/RouteInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore.interceptor; 2 | 3 | 4 | import com.joybar.librouter.routercore.RouterRequest; 5 | 6 | /** 7 | * Created by joybar on 15/11/2017. 8 | */ 9 | 10 | public interface RouteInterceptor { 11 | boolean isIntercepted(RouterRequest routerRequest); 12 | } 13 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/interceptor/TestInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore.interceptor; 2 | 3 | 4 | import android.content.Context; 5 | 6 | import com.joybar.librouter.routercore.RouterRequest; 7 | 8 | /** 9 | * Created by joybar on 15/11/2017. 10 | */ 11 | 12 | public class TestInterceptor implements RouteInterceptor { 13 | 14 | private Context mContext; 15 | 16 | public TestInterceptor(Context context) { 17 | this.mContext = context; 18 | } 19 | 20 | @Override 21 | public boolean isIntercepted(RouterRequest routerRequest) { 22 | //Toast.makeText(mContext, "I am a test interceptor", Toast.LENGTH_LONG).show(); 23 | return false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routercore/utils/CheckUtils.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routercore.utils; 2 | 3 | 4 | /** 5 | * Created by joybar on 2017/5/3. 6 | */ 7 | 8 | public class CheckUtils { 9 | public static T checkNotNull(T reference) { 10 | if (reference == null) { 11 | throw new NullPointerException(); 12 | } else { 13 | return reference; 14 | } 15 | } 16 | 17 | public static T checkNotNull(T reference, Object errorMessage) { 18 | if (reference == null) { 19 | throw new NullPointerException(String.valueOf(errorMessage)); 20 | } else { 21 | return reference; 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routerservice/RouterServiceManager.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routerservice; 2 | 3 | import android.content.Context; 4 | import android.content.pm.ApplicationInfo; 5 | import android.content.pm.PackageManager; 6 | 7 | import com.joybar.librouter.routerservice.inters.IBaseService; 8 | 9 | import java.util.HashMap; 10 | 11 | public class RouterServiceManager { 12 | 13 | 14 | private static final String ROUTER_SERVICE_NAME_PREFIX = "RS"; 15 | private Context mContext; 16 | private HashMap serviceTable = new HashMap<>(); 17 | 18 | 19 | private static class RouterServiceManagerHolder { 20 | private static RouterServiceManager INSTANCE = new RouterServiceManager(); 21 | } 22 | 23 | public static RouterServiceManager getInstance() { 24 | return RouterServiceManagerHolder.INSTANCE; 25 | 26 | } 27 | 28 | public void init(Context context) { 29 | this.mContext = context; 30 | registerAllModuleService(); 31 | } 32 | 33 | 34 | private void registerAllModuleService() { 35 | 36 | try { 37 | ApplicationInfo applicationInfo = mContext.getApplicationContext().getPackageManager().getApplicationInfo(mContext.getPackageName(), 38 | PackageManager.GET_META_DATA); 39 | for (String key : applicationInfo.metaData.keySet()) { 40 | if (key.startsWith(ROUTER_SERVICE_NAME_PREFIX)) { 41 | String componentClassName = applicationInfo.metaData.get(key).toString(); 42 | IBaseService baseService = (IBaseService) Class.forName(componentClassName).newInstance(); 43 | serviceTable.put(key, baseService); 44 | } 45 | } 46 | } catch (PackageManager.NameNotFoundException e) { 47 | e.printStackTrace(); 48 | } catch (InstantiationException e) { 49 | e.printStackTrace(); 50 | } catch (IllegalAccessException e) { 51 | e.printStackTrace(); 52 | } catch (ClassNotFoundException e) { 53 | e.printStackTrace(); 54 | } 55 | 56 | } 57 | 58 | 59 | public IBaseService getService(String serviceName){ 60 | if(serviceTable.containsKey(serviceName)){ 61 | return serviceTable.get(serviceName); 62 | }else{ 63 | throw new IllegalStateException(String.format("%s is not register in serviceTable,have you declared it in AndroidManifest or call the " + 64 | "registerAllModuleService method in your application", 65 | serviceName)); 66 | } 67 | 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routerservice/exception/RouterServiceException.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routerservice.exception; 2 | 3 | public class RouterServiceException extends Exception { 4 | 5 | public RouterServiceException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routerservice/inters/IBaseService.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routerservice.inters; 2 | 3 | public interface IBaseService { 4 | 5 | Object execute(String cmd, Object... args); 6 | 7 | void executeAsync(String cmd, IServiceCallBack iServiceCallBack, Object... args); 8 | 9 | String moduleServiceName(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /librouter/src/main/java/com/joybar/librouter/routerservice/inters/IServiceCallBack.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter.routerservice.inters; 2 | 3 | import com.joybar.librouter.routerservice.exception.RouterServiceException; 4 | 5 | public interface IServiceCallBack { 6 | 7 | void onSuccess(Object result); 8 | void onFailure(RouterServiceException routerServiceException); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /librouter/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | librouter 3 | 4 | -------------------------------------------------------------------------------- /librouter/src/test/java/com/joybar/librouter/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.librouter; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /moduleshop/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /moduleshop/build.gradle: -------------------------------------------------------------------------------- 1 | def isDebug = rootProject.ext.isDebugType 2 | if (isDebug) { 3 | apply plugin: 'com.android.application' 4 | } else { 5 | apply plugin: 'com.android.library' 6 | } 7 | //./gradlew :moduleshop:assembleRelease 8 | //./gradlew :moduleshop:assembleDebug 9 | android { 10 | 11 | compileSdkVersion rootProject.ext.android.compileSdkVersion 12 | buildToolsVersion rootProject.ext.android.buildToolsVersion 13 | 14 | sourceSets { 15 | main { 16 | if (isDebug) { 17 | manifest.srcFile 'src/main/debug/AndroidManifest.xml' 18 | } else { 19 | manifest.srcFile 'src/main/AndroidManifest.xml' 20 | } 21 | } 22 | } 23 | defaultConfig { 24 | minSdkVersion rootProject.ext.android.minSdkVersion 25 | targetSdkVersion rootProject.ext.android.targetSdkVersion 26 | versionCode rootProject.ext.android.versionCode 27 | versionName rootProject.ext.android.versionName 28 | if (!isDebug) { 29 | resourcePrefix 'shop_' 30 | } 31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 32 | javaCompileOptions { 33 | annotationProcessorOptions { 34 | includeCompileClasspath true 35 | } 36 | } 37 | } 38 | 39 | signingConfigs { 40 | config { 41 | storeFile file("./src/main/doc/test_realese.jks") 42 | keyAlias "test" 43 | storePassword "123456" 44 | keyPassword "123456" 45 | } 46 | debug { 47 | storeFile file("./src/main/doc/debug.jks") 48 | keyAlias "debug" 49 | storePassword "123456" 50 | keyPassword "123456" 51 | } 52 | } 53 | 54 | buildTypes { 55 | release { 56 | if (isDebug) { 57 | signingConfig signingConfigs.config 58 | } 59 | minifyEnabled false 60 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 61 | buildConfigField "boolean", "IS_DEBUG_TYPE", project.is_debug_type 62 | } 63 | debug { 64 | if (!isDebug) { 65 | signingConfig signingConfigs.debug 66 | } 67 | minifyEnabled false 68 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 69 | buildConfigField "boolean", "IS_DEBUG_TYPE", project.is_debug_type 70 | } 71 | } 72 | 73 | } 74 | 75 | dependencies { 76 | implementation fileTree(include: ['*.jar'], dir: 'libs') 77 | implementation rootProject.ext.dependencies.supportv7 78 | implementation rootProject.ext.dependencies.constraintlayout 79 | testImplementation 'junit:junit:4.12' 80 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 81 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 82 | api project(':librouter') 83 | } 84 | 85 | preBuild << { 86 | String cmd = "sh inrouter/maker/route.sh " + project.getName() 87 | def cmdResult = cmd.execute().text.trim() 88 | println cmdResult 89 | } -------------------------------------------------------------------------------- /moduleshop/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 | -------------------------------------------------------------------------------- /moduleshop/src/androidTest/java/com/joybar/moduleshop/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.joybar.moduleshop.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /moduleshop/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /moduleshop/src/main/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /moduleshop/src/main/doc/debug.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/moduleshop/src/main/doc/debug.jks -------------------------------------------------------------------------------- /moduleshop/src/main/doc/test_realese.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myjoybar/Android-Router/085d714992a41dfc60dee48bb1a97b8da65a76cc/moduleshop/src/main/doc/test_realese.jks -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/FinishWithResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.joybar.annotation.router.annotation.RegisterRouter; 9 | 10 | @RegisterRouter(module = "shop", path = "finish_with_result") 11 | public class FinishWithResultActivity extends AppCompatActivity { 12 | private static final String TAG = "FinishWithResultActivity"; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.shop_activity_finish_with_result); 18 | findViewById(R.id.btn_finish_with_result).setOnClickListener(new View.OnClickListener() { 19 | @Override 20 | public void onClick(View v) { 21 | Intent mIntent = new Intent(); 22 | mIntent.putExtra("Result01", "1000"); 23 | FinishWithResultActivity.this.setResult(3, mIntent); 24 | finish(); 25 | } 26 | }); 27 | 28 | } 29 | 30 | 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.widget.TextView; 6 | 7 | import com.joybar.annotation.router.annotation.RegisterRouter; 8 | import com.joybar.moduleshop.application.ShopApplication; 9 | 10 | @RegisterRouter(module = "shop", path = "main") 11 | public class MainActivity extends AppCompatActivity { 12 | private static final String TAG = "MainActivity"; 13 | private TextView mTextView; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.shop_activity_main); 19 | ShopApplication.getInstance().getApplication(); 20 | mTextView = findViewById(R.id.tv_des); 21 | mTextView.setText("我从Module User 跳转过来"); 22 | 23 | } 24 | 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/ReceiveParamActivity.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.TextView; 8 | 9 | import com.joybar.annotation.router.annotation.RegisterRouter; 10 | import com.joybar.librouter.guider.annotation.DataParam; 11 | import com.joybar.librouter.guider.annotation.RegisterLaunch; 12 | 13 | @RegisterRouter(module = "shop", path = "receive_param") 14 | public class ReceiveParamActivity extends AppCompatActivity { 15 | 16 | private TextView tvDes; 17 | @DataParam 18 | public int id; 19 | @DataParam 20 | public String name; 21 | @DataParam 22 | public String address; 23 | 24 | @RegisterLaunch 25 | public static void launch(Context context,String address){ 26 | Intent intent = new Intent(context,ReceiveParamActivity.class); 27 | Bundle bundle = new Bundle(); 28 | bundle.putString("address",address); 29 | intent.putExtras(bundle); 30 | context.startActivity(intent); 31 | } 32 | 33 | @RegisterLaunch 34 | public static void launch(Context context,String name,int id){ 35 | Intent intent = new Intent(context,ReceiveParamActivity.class); 36 | Bundle bundle = new Bundle(); 37 | bundle.putInt("id",id); 38 | bundle.putString("name",name); 39 | intent.putExtras(bundle); 40 | context.startActivity(intent); 41 | } 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.shop_activity_receive_param); 47 | initView(); 48 | initData(); 49 | } 50 | 51 | private void initView() { 52 | tvDes = findViewById(R.id.tv_des); 53 | } 54 | 55 | private void initData() { 56 | Bundle mExtras = getIntent().getExtras(); 57 | int id = mExtras.getInt("id", 0); 58 | String name = mExtras.getString("name", ""); 59 | tvDes.setText("我从Module User 跳转过来"+"\n"+"接受到的参数"+"\n"+"\n"+" ID:" + id + "," + "name:" + name); 60 | 61 | } 62 | 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/ShopService.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop; 2 | 3 | import com.joybar.librouter.routerservice.exception.RouterServiceException; 4 | import com.joybar.librouter.routerservice.inters.IBaseService; 5 | import com.joybar.librouter.routerservice.inters.IServiceCallBack; 6 | 7 | import java.util.Arrays; 8 | 9 | public class ShopService implements IBaseService { 10 | private static final String SERVICE_CMD_TEST = "cmd_test"; 11 | private static final String SERVICE_CMD_LOGIN = "cmd_login"; 12 | 13 | @Override 14 | public Object execute(String cmd, Object... args) { 15 | Object obj[] = args; 16 | String msg = ""; 17 | if (obj != null && obj.length != 0) { 18 | msg = Arrays.toString(obj); 19 | } 20 | if (SERVICE_CMD_TEST.equals(cmd)) { 21 | return "成功同步调用 Shop service " + SERVICE_CMD_TEST + "服务,返回值:" + msg; 22 | } 23 | return null; 24 | } 25 | 26 | @Override 27 | public void executeAsync(String cmd, IServiceCallBack iServiceCallBack, Object... args) { 28 | 29 | if (SERVICE_CMD_LOGIN.equals(cmd)) { 30 | 31 | try { 32 | Thread.sleep(500); 33 | } catch (InterruptedException e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | if ("Tom".equals(args[0]) && "123456".equals(args[1])) { 38 | iServiceCallBack.onSuccess("登录成功"); 39 | } else { 40 | iServiceCallBack.onFailure(new RouterServiceException("用户名或者密码错误")); 41 | } 42 | 43 | } 44 | } 45 | 46 | @Override 47 | public String moduleServiceName() { 48 | 49 | return "RSShopService"; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/application/ShopApplication.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop.application; 2 | 3 | import android.app.Application; 4 | 5 | import com.joybar.librouter.application.ApplicationService; 6 | import com.joybar.moduleshop.BuildConfig; 7 | 8 | /** 9 | * Created by joybar on 2017/12/4. 10 | */ 11 | 12 | public class ShopApplication implements ApplicationService { 13 | 14 | private static final String TAG = "UserApplication"; 15 | 16 | private ShopApplication() { 17 | } 18 | 19 | private static class UserApplicationHolder { 20 | private static final ShopApplication INSTANCE = new ShopApplication(); 21 | } 22 | 23 | public static final ShopApplication getInstance() { 24 | return UserApplicationHolder.INSTANCE; 25 | } 26 | 27 | 28 | @Override 29 | public void loadModuleApplicationService() { 30 | if (BuildConfig.IS_DEBUG_TYPE) { 31 | ShopDebugApplication.getInstance().loadModuleApplicationService(); 32 | } else { 33 | ShopReleaseApplication.getInstance().loadModuleApplicationService(); 34 | } 35 | } 36 | 37 | @Override 38 | public Application getApplication() { 39 | if (BuildConfig.IS_DEBUG_TYPE) { 40 | return ShopDebugApplication.getInstance().getApplication(); 41 | } else { 42 | return ShopReleaseApplication.getInstance().getApplication(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/application/ShopDebugApplication.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop.application; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.joybar.librouter.application.ApplicationService; 8 | 9 | 10 | /** 11 | * Created by joybar on 2017/12/4. 12 | */ 13 | 14 | public class ShopDebugApplication extends Application implements ApplicationService { 15 | 16 | 17 | private static final String TAG = "ShopDebugApplication"; 18 | private static ShopDebugApplication INSTANCE = null; 19 | 20 | public static ShopDebugApplication getInstance() { 21 | Log.d(TAG,"get ShopDebugApplication"); 22 | return INSTANCE; 23 | } 24 | 25 | @Override 26 | protected void attachBaseContext(Context base) { 27 | super.attachBaseContext(base); 28 | INSTANCE = this; 29 | } 30 | 31 | 32 | @Override 33 | public Application getApplication() { 34 | return getInstance(); 35 | } 36 | 37 | @Override 38 | public void loadModuleApplicationService() { 39 | Log.d(TAG, "load shop debug application"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /moduleshop/src/main/java/com/joybar/moduleshop/application/ShopReleaseApplication.java: -------------------------------------------------------------------------------- 1 | package com.joybar.moduleshop.application; 2 | 3 | import android.app.Application; 4 | import android.util.Log; 5 | 6 | import com.joybar.librouter.application.ApplicationService; 7 | 8 | import java.lang.reflect.InvocationTargetException; 9 | import java.lang.reflect.Method; 10 | 11 | /** 12 | * Created by joybar on 03/12/2017. 13 | */ 14 | 15 | public class ShopReleaseApplication implements ApplicationService { 16 | private static final String TAG = "ShopReleaseApplication"; 17 | private static Application application; 18 | 19 | private ShopReleaseApplication() { 20 | } 21 | 22 | private static class ShopReleaseApplicationHolder { 23 | private static final ShopReleaseApplication INSTANCE = new ShopReleaseApplication(); 24 | } 25 | 26 | public static final ShopReleaseApplication getInstance() { 27 | return ShopReleaseApplicationHolder.INSTANCE; 28 | } 29 | 30 | @Override 31 | public Application getApplication() { 32 | Log.d(TAG,"get ShopReleaseApplication"); 33 | if (null == application) { 34 | try { 35 | Class clazz = Class.forName("com.joybar.androidrouter.App"); 36 | Method method = clazz.getMethod("getInstance"); 37 | application = (Application) method.invoke(null); 38 | return application; 39 | } catch (ClassNotFoundException e) { 40 | e.printStackTrace(); 41 | } catch (NoSuchMethodException e) { 42 | e.printStackTrace(); 43 | } catch (IllegalAccessException e) { 44 | e.printStackTrace(); 45 | } catch (InvocationTargetException e) { 46 | e.printStackTrace(); 47 | } 48 | } 49 | return application; 50 | } 51 | 52 | @Override 53 | public void loadModuleApplicationService() { 54 | Log.d(TAG, "load shop release application"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /moduleshop/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /moduleshop/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 | -------------------------------------------------------------------------------- /moduleshop/src/main/res/layout/shop_activity_finish_with_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | 20 | 30 | 31 |