├── .gitignore ├── LICENSE ├── README.md ├── README_CN.md ├── Rabbits ├── .gitignore ├── annotations │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── annotations │ │ └── Page.java ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── kyleduo │ │ │ └── rabbits │ │ │ └── demo │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ │ └── web.html │ │ ├── ic_launcher-web.png │ │ ├── java │ │ │ └── com │ │ │ │ └── kyleduo │ │ │ │ └── rabbits │ │ │ │ └── demo │ │ │ │ ├── DemoApplication.java │ │ │ │ ├── DumpFragment.java │ │ │ │ ├── EmbeddedFragment.java │ │ │ │ ├── FragmentContainerActivity.java │ │ │ │ ├── InterceptorActivity.java │ │ │ │ ├── ListingFragment.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── SecondFragment.java │ │ │ │ ├── TestActivity.java │ │ │ │ ├── TestFragment.java │ │ │ │ ├── WebFragment.java │ │ │ │ ├── base │ │ │ │ ├── BaseActivity.java │ │ │ │ └── BaseFragment.java │ │ │ │ └── utils │ │ │ │ ├── Constants.java │ │ │ │ └── UriUtils.java │ │ └── res │ │ │ ├── anim │ │ │ ├── fadein.xml │ │ │ └── fadeout.xml │ │ │ ├── layout │ │ │ ├── activity_common.xml │ │ │ ├── activity_main.xml │ │ │ ├── activity_test.xml │ │ │ ├── fragment_web.xml │ │ │ ├── item.xml │ │ │ ├── item_section_header.xml │ │ │ └── toolbar.xml │ │ │ ├── menu │ │ │ └── menu_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_background.png │ │ │ ├── ic_launcher_foreground.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_background.png │ │ │ ├── ic_launcher_foreground.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_background.png │ │ │ ├── ic_launcher_foreground.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_background.png │ │ │ ├── ic_launcher_foreground.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ ├── ic_launcher_background.png │ │ │ ├── ic_launcher_foreground.png │ │ │ └── ic_launcher_round.png │ │ │ ├── values-v23 │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── ExampleUnitTest.java ├── build.gradle ├── compiler │ ├── .gitignore │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── compiler │ │ ├── PageInfo.java │ │ └── RabbitsCompiler.java ├── gradle.properties ├── gradle │ ├── gradle-bintray-upload.gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── rabbits │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── kyleduo │ │ │ └── rabbits │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── kyleduo │ │ │ │ └── rabbits │ │ │ │ ├── AbstractNavigation.java │ │ │ │ ├── Action.java │ │ │ │ ├── ActionParser.java │ │ │ │ ├── ActivityNavigator.java │ │ │ │ ├── CleanUpInterceptor.java │ │ │ │ ├── Interceptor.java │ │ │ │ ├── InternalInterceptor.java │ │ │ │ ├── Logger.java │ │ │ │ ├── Navigation.java │ │ │ │ ├── NavigationImpl.java │ │ │ │ ├── Navigator.java │ │ │ │ ├── NavigatorInterceptor.java │ │ │ │ ├── PatternInterceptor.java │ │ │ │ ├── Rabbit.java │ │ │ │ ├── RabbitConfig.java │ │ │ │ ├── RabbitResult.java │ │ │ │ ├── RealDispatcher.java │ │ │ │ ├── RouteTable.java │ │ │ │ ├── TargetAssembler.java │ │ │ │ ├── TargetInfo.java │ │ │ │ ├── URLEncodeUtils.java │ │ │ │ └── rules │ │ │ │ ├── DomainRule.java │ │ │ │ ├── Element.java │ │ │ │ ├── NotRule.java │ │ │ │ ├── PathRule.java │ │ │ │ ├── QueryRule.java │ │ │ │ ├── Rule.java │ │ │ │ ├── RuleSet.java │ │ │ │ ├── Rules.java │ │ │ │ ├── SchemeRule.java │ │ │ │ ├── TargetFlagsRule.java │ │ │ │ └── UriRule.java │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── ExampleUnitTest.java ├── settings.gradle ├── submodule1 │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── kyleduo │ │ │ └── rabbits │ │ │ └── demo │ │ │ └── submodule1 │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── kyleduo │ │ │ │ └── rabbits │ │ │ │ └── demo │ │ │ │ └── submodule1 │ │ │ │ ├── BaseActivity.java │ │ │ │ ├── SMActivity.java │ │ │ │ ├── SMActivity2.java │ │ │ │ └── SMTestActivity.java │ │ └── res │ │ │ ├── layout │ │ │ ├── act_sm1_test.xml │ │ │ ├── act_sub_module_1.xml │ │ │ ├── act_sub_module_2.xml │ │ │ └── toolbar_sm1.xml │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── demo │ │ └── submodule1 │ │ └── ExampleUnitTest.java └── submodule2 │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kyleduo │ │ └── rabbits │ │ └── demo │ │ └── submodule2 │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── kyleduo │ │ │ └── rabbits │ │ │ └── demo │ │ │ └── submodule2 │ │ │ ├── BaseActivity.java │ │ │ └── SM2Activity.java │ └── res │ │ ├── layout │ │ ├── act_sm2.xml │ │ └── toolbar_sm2.xml │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── kyleduo │ └── rabbits │ └── demo │ └── submodule2 │ └── ExampleUnitTest.java └── demo ├── demo.apk └── preview.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.ap_ 3 | 4 | # Files for the ART/Dalvik VM 5 | *.dex 6 | 7 | # Java class files 8 | *.class 9 | 10 | # Generated files 11 | bin/ 12 | gen/ 13 | out/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | # Intellij 35 | *.iml 36 | .idea/workspace.xml 37 | 38 | # Keystore files 39 | *.jks 40 | 41 | .idea/ 42 | #gradle.properties 43 | 44 | .DS_Store 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rabbits 2 | 3 | [中文 README](./README_CN.md) [Blog](https://blog.kyleduo.com/2018/03/22/rabbits-100/) 4 | 5 | > **NOTICE** Rabbits has a lot of changes after version 1.0.0. If you’re using Rabbits, read wiki before update. 6 | 7 | ![version](https://img.shields.io/badge/version-1.0.2-blue.svg) 8 | 9 | ### Demo 10 | 11 | [Download Link](./demo/demo.apk) 12 | 13 | ![preview](demo/preview.png) 14 | 15 | 16 | 17 | ### Quick Glance 18 | 19 | ```java 20 | @Page(value="/test", alias="TEST_ACT", variety=["/test_variety", "/test/{param}"]) 21 | public class TestActivity extends AppCompatActivity {} 22 | 23 | // somewhere else 24 | public class MainActivity extends AppCompatActivity { 25 | public void onButtonClicked() { 26 | // every statement works same 27 | Rabbit.from(this).to(P.TEST_ACT).putExtra("param", "value").start(); 28 | Rabbit.from(this).to("/test?param=value").start(); 29 | Rabbit.from(this).to(P.P_TEST_PARAM("value")).start(); 30 | } 31 | } 32 | ``` 33 | 34 | 35 | 36 | ### Changes in version 1.0.0 37 | 38 | I released Rabbits last year and have been using it since then. Everything works fine and the “**From-To-Start**” pattern make me almost forget the `new Intent()` stuff. Rabbits simplify the navigation between pages hosted by Activities and Fragments and, with URI as the protocol, navigation between web pages and native pages becomes easier. 39 | 40 | Even though the usage is easier and intuitive, I found some which can be improved. There are 3 points which are more important. 41 | 42 | 1. `mappings.json`. When I first design Rabbits, I design by separating App client from the backend. But in practice, it’s much reasonable and flexible to let backend control the behavior of App. 43 | 2. `Interceptor`. Interceptor is important when you need to control the process of navigation, adding some params or redirecting to another page. It looks silly that you need check whether the url is the one you want when using Interceptor. The condition of url should be bound to the interceptor so only the urls you want can enter the process method, which is that logical. 44 | 3. `obtain`. It’s not consistent when you try to obtain a Fragment object using Rabbits since the towering `obtain` API. 45 | 46 | Therefore, I’ve rethought the design of Rabbits and browsed other router libraries to learn what is really needed of a router. However, my decision is to keep Rabbits simple and make it’s usage much more easier. Rabbits 1.0.0 focus just one thing, navigation through pages. 47 | 48 | Since I redesigned Rabbits from the bottom. Almost all of the APIs have changed. I’m going to list some significant and obvious change below, the others about the new version can be found in wiki. 49 | 50 | 1. `mappings.json` has been removed. You need to annotated name on every page’s class. `@Page()` has changed and you can use it like this: `@Page("/page/path")`. 51 | 2. Initialization API has changed a lot but the new API becomes more fluent and you can finish the initialization by a single link of invocations. 52 | 3. `P` class is still there. Since `mappings.json` is gone so Rabbits generate P using url path specified in `@Page` or you can provide a `alias` field to name that page a friendly name. Field generated from a path may looks like this: **P_PAGE_PATH**. Yes, there is a prefix, `P_`. 53 | 4. The execution chain has been redesigned and interceptors are recommended set during initialization phase. 54 | 5. Usage of in multiple-module become so easy and dependency between modules in different layers become less. 55 | 56 | ### Use with Gradle 57 | 58 | ```groovy 59 | dependencies { 60 | implementation "com.kyleduo.rabbits:rabbits:{latest-version}" 61 | annotationProcessor "com.kyleduo.rabbits:compiler:{latest-version}" 62 | } 63 | ``` 64 | 65 | ### From-To-Start pattern 66 | 67 | The From-To-Start pattern is quite simple and intuitive since navigation is just from on page to another. 68 | 69 | ```java 70 | // MainActivity.java 71 | Rabbit.from(this).to(P.P_TEST).start(); 72 | ``` 73 | ### ProGuard rules 74 | 75 | Since Rabbits generate routing table in compile phase and no reflection during navigation, you just need add this line in your ProGuard rules file. 76 | ``` 77 | -keep class com.kyleduo.rabbits.Router { *; } 78 | ``` 79 | ### Migration 80 | 81 | If you have been using Rabbits before 1.0.0, read the wiki first before update. 82 | 83 | ### Thanks 84 | 85 | [OKHttp](https://github.com/square/okhttp): I learnt how to implement interceptor chain from OKHttp. 86 | 87 | [ARouter](https://github.com/alibaba/ARouter): The idea`flags` is from ARouter. 88 | 89 | 90 | License 91 | --- 92 | 93 | Licensed under the Apache License, Version 2.0 (the "License"); 94 | you may not use this file except in compliance with the License. 95 | You may obtain a copy of the License at 96 | 97 | http://www.apache.org/licenses/LICENSE-2.0 98 | 99 | Unless required by applicable law or agreed to in writing, software 100 | distributed under the License is distributed on an "AS IS" BASIS, 101 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 102 | See the License for the specific language governing permissions and 103 | limitations under the License. 104 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # Rabbits 2 | 3 | [EN](./README.md) [Blog](https://blog.kyleduo.com/2018/03/22/rabbits-100/) 4 | 5 | 6 | **注意:** Rabbits在1.0.0版本上有非常大的改变,如果你正在使用,请在更新之前阅读wiki。 7 | 8 | 9 | 10 | ### Demo 11 | 12 | [下载链接](./demo/demo.apk) 13 | 14 | ![preview](demo/preview.png) 15 | 16 | 17 | 18 | ### Quick Glance 19 | 20 | ```java 21 | @Page(value="/test", alias="TEST_ACT", variety=["/test_variety", "/test/{param}"]) 22 | public class TestActivity extends AppCompatActivity {} 23 | 24 | // somewhere else 25 | public class MainActivity extends AppCompatActivity { 26 | public void onButtonClicked() { 27 | // every statement works same 28 | Rabbit.from(this).to(P.TEST_ACT).putExtra("param", "value").start(); 29 | Rabbit.from(this).to("/test?param=value").start(); 30 | Rabbit.from(this).to(P.P_TEST_PARAM("value")).start(); 31 | } 32 | } 33 | ``` 34 | 35 | 36 | 37 | ### 1.0.0版本的变化 38 | 39 | 我在去年开源了Rabbits并且一直使用到现在。期间运行良好并且符合项目的需求,“From-To-Start”模式让我几乎已经忘掉了`new Intent()`这种写法。Rabbits简化了页面之间的导航,不管是Activity之间还是Fragment之间。由于使用URI作为跳转协议,网页和原生页面之间的跳转页变得更加简单。 40 | 41 | 虽然使用上很简单并且符合直觉,我还是发现了一些需要改变的地方。下面是三个主要的切入点: 42 | 43 | 1. `mappings.json`。最开始设计Rabbits 的时候,我把客户端和服务端分开考量。但实际上由后端对App的行为进行控制更灵活也更合理。 44 | 2. `Interceptor`。如果你希望控制导航的流程,比如添加参数或者重定向到另一个页面,Interceptor就变得非常有用。在拦截器里面判断这个请求是否需要被拦截很傻。Url是否要被拦截的条件应该和拦截器绑定到一起,这样的话只有需要被拦截的请求才会执行到拦截器的处理方法。这才是合理的。 45 | 3. `obtain`。使用原有的`obtain`API获取目标Fragment或者Intent的调用过程并不连贯。 46 | 47 | 因此,我重新思考了Rabbits的设计,并且也参考了其他路由库来寻找有哪些其他特性也是一个路由库的必备特性。然而,我觉得让Rabbits继续保持简单小巧,并且让它的使用变得更加简单。Rabbits 1.0.0只专注一件事:页面间的导航。 48 | 49 | 因为我自底向上的重新设计了Rabbits,几乎所有的API都发生了改变。让我来列举一些比较明显且重要的改变,其他的请到wiki中查看。 50 | 51 | 1. `mappings.json`被移除。你现在需要在每个页面的类上设置页面的注解。`@Page`已经改变了,现在你可以这样使用:`@Page("/page/path")`. 52 | 2. 初始化API发生了很大的变化,但是新的API更加简单,一个链式调用就可以完成初始化。 53 | 3. `P`文件得以保留。因为`mappings.json`被移除所以Rabbits使用url生成P文件的字段。你也可以在`@Page`注解中提供`alias`属性来对页面进行友好的命名。从url生成的P文件的字段大概长这个样子:**P_PAGE_PATH**,有一个前缀`P_`。:) 54 | 4. 重新设计了路由的执行链,建议在初始化阶段设置拦截器。 55 | 5. 多Module中的使用更加简单,同时多个Module之间的耦合更少了。 56 | 57 | ### 在Gradle中使用 58 | 59 | ```groovy 60 | dependencies { 61 | implementation "com.kyleduo.rabbits:rabbits:{latest-version}" 62 | annotationProcessor "com.kyleduo.rabbits:compiler:{latest-version}" 63 | } 64 | ``` 65 | 66 | ### From-To-Start 模式 67 | 68 | 因为路由就是从一个页面到另一个页面,所以From-To-Start模式非常符合直觉并且易用。 69 | 70 | ```java 71 | // MainActivity.java 72 | Rabbit.from(this).to(P.P_TEST).start(); 73 | ``` 74 | 75 | ### ProGuard 防混淆规则 76 | 77 | 因为Rabbits在编译阶段生成路由表并且在导航执行阶段没有类名加载,你只需要对路由表类进行防混淆,在ProGuard规则文件中添加如下内容: 78 | 79 | ``` 80 | -keep class com.kyleduo.rabbits.Router { *; } 81 | ``` 82 | 83 | ### 迁移 84 | 85 | 如果你在使用1.0.0之前的版本,升级前请阅读wiki。 86 | 87 | ### 感谢 88 | 89 | [OKHttp](https://github.com/square/okhttp): 我从OKHttp中学习了拦截器链条的实现。 90 | 91 | [ARouter](https://github.com/alibaba/ARouter): `flags`的想法来自于ARouter。 92 | 93 | ## License 94 | 95 | ``` 96 | Licensed under the Apache License, Version 2.0 (the "License"); 97 | you may not use this file except in compliance with the License. 98 | You may obtain a copy of the License at 99 | 100 | http://www.apache.org/licenses/LICENSE-2.0 101 | 102 | Unless required by applicable law or agreed to in writing, software 103 | distributed under the License is distributed on an "AS IS" BASIS, 104 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 105 | See the License for the specific language governing permissions and 106 | limitations under the License. 107 | ``` 108 | 109 | -------------------------------------------------------------------------------- /Rabbits/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | /publish.sh 11 | -------------------------------------------------------------------------------- /Rabbits/annotations/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Rabbits/annotations/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | dependencies { 4 | implementation fileTree(dir: 'libs', include: ['*.jar']) 5 | } 6 | 7 | sourceCompatibility = "1.7" 8 | targetCompatibility = "1.7" 9 | 10 | ext { 11 | POM_ARTIFACT_ID='annotations' 12 | POM_NAME='Rabbits-Annotations' 13 | POM_PACKAGING='aar' 14 | } 15 | 16 | apply from: rootProject.file('gradle/gradle-bintray-upload.gradle') -------------------------------------------------------------------------------- /Rabbits/annotations/src/main/java/com/kyleduo/rabbits/annotations/Page.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Annotation for a single page. 10 | * 11 | * Created by kyle on 2016/12/07. 12 | */ 13 | 14 | @Target({ElementType.TYPE}) 15 | @Retention(RetentionPolicy.CLASS) 16 | public @interface Page { 17 | /** 18 | * Main url pattern, whole url or path. 19 | *

20 | * 1. /foo/bar 21 | * 2. foo://foo.bar/foo/bar 22 | * 3. /foo/{bar:i} 23 | * 24 | * @return url pattern 25 | */ 26 | String value(); 27 | 28 | /** 29 | * Used when this page can match multiple urls. 30 | * Exp. 31 | * /seg1/seg2/{id} 32 | * /seg1/seg2 33 | * /seg1/seg2/view 34 | * /seg1/seg2/detail 35 | * 36 | * @return other urls that can mark this page than the main one. 37 | */ 38 | String[] variety() default {}; 39 | 40 | /** 41 | * Flags related to this Page, like Intent flags. You can give meanings to each bit and 42 | * response to different flags in your interceptors. 43 | * 44 | * @return flags in int value 45 | */ 46 | int flags() default 0; 47 | 48 | /** 49 | * Used to generate a constant you can use in your code against writing hard-coded urls. 50 | * 51 | * @return alias 52 | */ 53 | String alias() default ""; 54 | } 55 | -------------------------------------------------------------------------------- /Rabbits/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Rabbits/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | buildToolsVersion buildToolsVersion 6 | defaultConfig { 7 | applicationId "com.kyleduo.rabbits.demo" 8 | minSdkVersion 14 9 | targetSdkVersion 27 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | 14 | javaCompileOptions { 15 | annotationProcessorOptions { 16 | arguments = [rabbits_submodules: "sm1"] 17 | } 18 | } 19 | } 20 | 21 | signingConfigs { 22 | releaseConfig { 23 | storeFile file("demo.jks") 24 | storePassword "12345678" 25 | keyAlias "demo" 26 | keyPassword "12345678" 27 | } 28 | } 29 | 30 | buildTypes { 31 | debug { 32 | minifyEnabled true 33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 34 | } 35 | 36 | release { 37 | minifyEnabled false 38 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 39 | signingConfig signingConfigs.releaseConfig 40 | } 41 | } 42 | } 43 | 44 | dependencies { 45 | implementation fileTree(include: ['*.jar'], dir: 'libs') 46 | implementation project(':submodule1') 47 | // App's dependencies, including test 48 | implementation "com.android.support:support-annotations:$supportVersion" 49 | implementation "com.android.support:appcompat-v7:$supportVersion" 50 | implementation "com.android.support:recyclerview-v7:$supportVersion" 51 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 52 | exclude group: 'com.android.support', module: 'support-annotations' 53 | }) 54 | androidTestImplementation('com.android.support.test:runner:0.5', { 55 | exclude group: 'com.android.support', module: 'support-annotations' 56 | }) 57 | testImplementation 'junit:junit:4.12' 58 | // Rabbits 59 | implementation project(':rabbits') 60 | annotationProcessor project(':compiler') 61 | // Fragmentation 62 | implementation 'me.yokeyword:fragmentation:0.10.0' 63 | } 64 | -------------------------------------------------------------------------------- /Rabbits/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kyle/Documents/developer/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class com.kyleduo.rabbits.Router { *; } -------------------------------------------------------------------------------- /Rabbits/app/src/androidTest/java/com/kyleduo/rabbits/demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.support.test.filters.LargeTest; 4 | 5 | /** 6 | * Instrumentation test, which will execute on an Android device. 7 | * 8 | * @see Testing documentation 9 | */ 10 | @LargeTest 11 | public class ExampleInstrumentedTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/assets/web.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test web page 5 | 19 | 20 | 21 | 22 |

23 | Used in a web page. 24 |

25 | 26 |

27 | Rabbits is quite useful when you need handle navigation between web and native. 28 |

29 | 30 |

31 | Load normally. 32 |

33 |

34 | https://kyleduo.com 35 |

36 |
37 |

38 | Additional allowed domains. These domains will be treated as the default one: rabbits.kyleduo.com 39 |

40 |

41 | https://blog.kyleduo.com 42 |

43 |
44 |

45 | Intercepted by RouteTable, navigating to native page. 46 |

47 |

48 | https://rabbits.kyleduo.com 49 |

50 |

51 | https://rabbits.kyleduo.com/test/this 52 | is a param 53 |

54 |

55 | https://rabbits.kyleduo.com/test/listing 56 |

57 |

58 | https://rabbits.kyleduo.com/test/listing?a=b#/sharp 59 |

60 |

61 | https://rabbits.kyleduo.com/sm1/activity 62 |

63 |
64 |

65 | Green channel. By default, this url will open the home page like the one above, but the exists of greenChannel forbid this happen. 66 |

67 |

68 | This feature should implemented by the user and the rule can be any. 69 |

70 |

71 | https://blog.kyleduo.com?greenChannel=1 72 |

73 |

74 | https://blog.kyleduo.com?ignore=1 75 |

76 |
77 |

78 | Custom control param. 79 |

80 |

81 | https://rabbits.kyleduo.com/test/customParam?redirect=1 82 |

83 |
84 |

85 | Special uri. 86 |

87 |

88 | tel:10010 89 |

90 | 91 | 92 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyleduo/Rabbits/bacc53128b2acf700ea64d4729605121e61dd727/Rabbits/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.app.AlertDialog; 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.content.DialogInterface; 7 | import android.net.Uri; 8 | import android.text.TextUtils; 9 | import android.widget.Toast; 10 | 11 | import com.kyleduo.rabbits.Action; 12 | import com.kyleduo.rabbits.Interceptor; 13 | import com.kyleduo.rabbits.Navigator; 14 | import com.kyleduo.rabbits.P; 15 | import com.kyleduo.rabbits.Rabbit; 16 | import com.kyleduo.rabbits.RabbitConfig; 17 | import com.kyleduo.rabbits.RabbitResult; 18 | import com.kyleduo.rabbits.TargetInfo; 19 | import com.kyleduo.rabbits.demo.base.BaseActivity; 20 | import com.kyleduo.rabbits.demo.base.BaseFragment; 21 | import com.kyleduo.rabbits.demo.utils.Constants; 22 | import com.kyleduo.rabbits.rules.Rule; 23 | import com.kyleduo.rabbits.rules.RuleSet; 24 | import com.kyleduo.rabbits.rules.Rules; 25 | 26 | import me.yokeyword.fragmentation.SupportFragment; 27 | 28 | /** 29 | * Created by kyle on 2016/12/8. 30 | */ 31 | 32 | public class DemoApplication extends Application { 33 | @SuppressWarnings("unused") 34 | private static final String TAG = "DemoApplication"; 35 | 36 | private static DemoApplication sApp; 37 | 38 | public static DemoApplication get() { 39 | return sApp; 40 | } 41 | 42 | @Override 43 | public void onCreate() { 44 | super.onCreate(); 45 | sApp = this; 46 | 47 | Rabbit.init( 48 | RabbitConfig.get() 49 | .schemes("demo", "http", "https") 50 | .domains("rabbits.kyleduo.com", "blog.kyleduo.com", "rabbits.kyleduo.com") 51 | .debug(true)) 52 | // do not open any native pages when there is a query named 'greenChannel' 53 | // and it's value equals '1'. This useful when use Rabbit as a bridge between 54 | // native and web page. 55 | .addInterceptor(new Interceptor() { 56 | @Override 57 | public RabbitResult intercept(Dispatcher dispatcher) { 58 | dispatcher.action().discard(); 59 | return dispatcher.dispatch(dispatcher.action()); 60 | } 61 | }, Rules.set(RuleSet.Relation.OR, Rules.query("greenChannel").is("1"), Rules.query("ignore").is("1"))) 62 | .addInterceptor(new Interceptor() { 63 | @Override 64 | public RabbitResult intercept(Dispatcher dispatcher) { 65 | dispatcher.action().setRedirect(true); 66 | return dispatcher.dispatch(dispatcher.action()); 67 | } 68 | }, Rules.query("redirect").is("1")) 69 | .addInterceptor(new Interceptor() { 70 | @Override 71 | public RabbitResult intercept(Dispatcher dispatcher) { 72 | // ignore other following interceptors. 73 | dispatcher.action().getExtras().putString("param", "rules"); 74 | dispatcher.action().setIgnoreInterceptors(true); 75 | Toast.makeText(DemoApplication.this, "Interceptor by Rules", Toast.LENGTH_SHORT).show(); 76 | return dispatcher.dispatch(dispatcher.action()); 77 | } 78 | }, Rules.set(RuleSet.Relation.AND, Rules.scheme().startsWith("demo"), Rules.domain().contains("kyleduo"), Rules.path().contains("/rules"))) 79 | .addInterceptor(new Interceptor() { 80 | @Override 81 | public RabbitResult intercept(final Dispatcher dispatcher) { 82 | final Action action = dispatcher.action(); 83 | if (action.getFrom() instanceof Context) { 84 | action.getExtras().putString("param", "set in interceptor"); 85 | new AlertDialog.Builder((Context) action.getFrom()) 86 | .setTitle("Intercepted") 87 | .setMessage("The navigation has been intercepted by interceptor. \n\nA param has been set in the interceptor.") 88 | .setPositiveButton("Go on", new DialogInterface.OnClickListener() { 89 | @Override 90 | public void onClick(DialogInterface dialog, int which) { 91 | dispatcher.dispatch(action); 92 | } 93 | }) 94 | .setNegativeButton("Cancel", null).create().show(); 95 | return null; 96 | } 97 | return dispatcher.dispatch(action); 98 | } 99 | }, Rules.flags().has(1)) 100 | // add Interceptor with totally custom rules 101 | .addInterceptor(new Interceptor() { 102 | @Override 103 | public RabbitResult intercept(Dispatcher dispatcher) { 104 | return null; 105 | } 106 | }, new Rule() { 107 | @Override 108 | public boolean verify(Action action) { 109 | return false; 110 | } 111 | }) 112 | .registerNavigator(TargetInfo.TYPE_FRAGMENT_V4, new FragmentNavigator()) 113 | .registerFallbackNavigator(new FallbackNavigator()); 114 | } 115 | 116 | public static class FragmentNavigator implements Navigator { 117 | 118 | @Override 119 | public RabbitResult perform(Action action) { 120 | Object from = action.getFrom(); 121 | Object target = action.getTarget(); 122 | 123 | boolean isBase = target instanceof BaseFragment; 124 | 125 | if (!isBase) { 126 | return RabbitResult.error("Target invalid"); 127 | } 128 | 129 | if ((action.getTargetFlags() & Constants.FLAG_FRAG_EMBED) > 0) { 130 | if (from instanceof BaseFragment) { 131 | if (action.isRedirect()) { 132 | ((BaseFragment) from).replaceFragment((SupportFragment) target, false); 133 | } else { 134 | ((BaseFragment) from).start((SupportFragment) target); 135 | } 136 | return RabbitResult.success(); 137 | } else if (from instanceof BaseActivity) { 138 | if (((BaseActivity) from).getTopFragment() != null) { 139 | if (action.isRedirect()) { 140 | ((BaseActivity) from).getTopFragment().replaceFragment((SupportFragment) target, false); 141 | } else { 142 | ((BaseActivity) from).start((SupportFragment) target); 143 | } 144 | } 145 | return RabbitResult.success(); 146 | } 147 | } 148 | 149 | return Rabbit.from(from) 150 | .to(P.P_FRAGMENT_CONTAINER) 151 | .action(action) 152 | .putExtra(FragmentContainerActivity.KEY_FRAG_URL, action.getOriginUrl()) 153 | .start(); 154 | } 155 | } 156 | 157 | public static class FallbackNavigator implements Navigator { 158 | 159 | @Override 160 | public RabbitResult perform(Action action) { 161 | Uri uri = action.createUri(); 162 | if (TextUtils.isEmpty(uri.getScheme()) || !uri.getScheme().startsWith("http")) { 163 | uri = uri.buildUpon().scheme("https").build(); 164 | } 165 | if (TextUtils.isEmpty(uri.getAuthority())) { 166 | uri = uri.buildUpon().authority("kyleduo.com").build(); 167 | } 168 | return Rabbit.from(action.getFrom()) 169 | .to(P.P_WEB) 170 | .putExtra(WebFragment.KEY_URL, uri.toString()) 171 | .start(); 172 | } 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/DumpFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.util.TypedValue; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ScrollView; 10 | import android.widget.TextView; 11 | 12 | import com.kyleduo.rabbits.Rabbit; 13 | import com.kyleduo.rabbits.annotations.Page; 14 | import com.kyleduo.rabbits.demo.base.BaseFragment; 15 | 16 | /** 17 | * Created by kyle on 2016/12/12. 18 | */ 19 | @Page("/dump") 20 | public class DumpFragment extends BaseFragment { 21 | 22 | @Override 23 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 24 | ScrollView sv = new ScrollView(getActivity()); 25 | sv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 26 | 27 | TextView tv = new TextView(getActivity()); 28 | tv.setText(Rabbit.dump()); 29 | tv.setTextColor(0xFFA6ABB0); 30 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); 31 | int padding = (int) (getResources().getDisplayMetrics().density * 16); 32 | tv.setPadding(padding, padding, padding, padding); 33 | tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 34 | sv.addView(tv); 35 | 36 | return sv; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/EmbeddedFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import com.kyleduo.rabbits.annotations.Page; 4 | import com.kyleduo.rabbits.demo.base.BaseFragment; 5 | import com.kyleduo.rabbits.demo.utils.Constants; 6 | 7 | /** 8 | * Created by kyle on 28/02/2018. 9 | */ 10 | 11 | @Page(value = "/test_embedded", flags = Constants.FLAG_FRAG_EMBED) 12 | public class EmbeddedFragment extends BaseFragment { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/FragmentContainerActivity.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | 7 | import com.kyleduo.rabbits.RabbitResult; 8 | import com.kyleduo.rabbits.Rabbit; 9 | import com.kyleduo.rabbits.annotations.Page; 10 | import com.kyleduo.rabbits.demo.base.BaseActivity; 11 | import com.kyleduo.rabbits.demo.base.BaseFragment; 12 | 13 | import me.yokeyword.fragmentation.SupportFragment; 14 | 15 | /** 16 | * Created by kyle on 2016/12/12. 17 | */ 18 | @Page("/fragment_container") 19 | public class FragmentContainerActivity extends BaseActivity { 20 | public static final String KEY_FRAG_URL = "frag_url"; 21 | 22 | @Override 23 | protected void onCreate(@Nullable Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_common); 26 | 27 | if (getTopFragment() == null) { 28 | String uri = getIntent().getStringExtra(KEY_FRAG_URL); 29 | Bundle extras = getIntent().getExtras(); 30 | if (extras != null) { 31 | extras.remove(KEY_FRAG_URL); 32 | } 33 | if (uri != null) { 34 | RabbitResult ret = Rabbit.from(this) 35 | .to(uri) 36 | .putExtras(extras) 37 | .obtain(); 38 | Object target = ret.getTarget(); 39 | if (target instanceof BaseFragment) { 40 | loadRootFragment(R.id.common_fragment_container, (SupportFragment) target); 41 | } 42 | } 43 | } 44 | } 45 | 46 | @Override 47 | protected void onNewIntent(Intent intent) { 48 | super.onNewIntent(intent); 49 | String pattern = intent.getStringExtra(Rabbit.KEY_PATTERN); 50 | Bundle extras = intent.getExtras(); 51 | if (extras != null) { 52 | extras.remove(KEY_FRAG_URL); 53 | } 54 | BaseFragment fragment = (BaseFragment) Rabbit.from(this) 55 | .to(intent.getStringExtra(KEY_FRAG_URL)) 56 | .putExtras(extras) 57 | .obtain().getTarget(); 58 | 59 | if (fragment == null) { 60 | return; 61 | } 62 | 63 | SupportFragment topFragment = getTopFragment(); 64 | if (topFragment != null && topFragment.getArguments().getString(Rabbit.KEY_PATTERN, "").equals(pattern)) { 65 | topFragment.replaceFragment(fragment, false); 66 | } else if (topFragment == null) { 67 | loadRootFragment(R.id.common_fragment_container, fragment); 68 | } else { 69 | start(fragment); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/InterceptorActivity.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.kyleduo.rabbits.P; 9 | import com.kyleduo.rabbits.Rabbit; 10 | import com.kyleduo.rabbits.annotations.Page; 11 | import com.kyleduo.rabbits.demo.base.BaseActivity; 12 | 13 | @Page(value = "/test/interceptor", flags = 1, variety = {"/test/rules"}) 14 | public class InterceptorActivity extends BaseActivity { 15 | 16 | @SuppressLint("SetTextI18n") 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_test); 21 | 22 | TextView tv = (TextView) findViewById(R.id.params_tv); 23 | tv.setText("param = " + getIntent().getStringExtra("param")); 24 | 25 | findViewById(R.id.back_home_bt).setOnClickListener(new View.OnClickListener() { 26 | @Override 27 | public void onClick(View view) { 28 | Rabbit.from(InterceptorActivity.this) 29 | .to(P.P_) 30 | .clearTop() 31 | .singleTop() 32 | .start(); 33 | } 34 | }); 35 | } 36 | 37 | @Override 38 | protected void onResume() { 39 | super.onResume(); 40 | setTitle(getIntent().getStringExtra(Rabbit.KEY_PATTERN) + "@" + this.getClass().getSimpleName()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/ListingFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import com.kyleduo.rabbits.annotations.Page; 4 | import com.kyleduo.rabbits.demo.base.BaseFragment; 5 | 6 | /** 7 | * Created by kyle on 2016/12/12. 8 | */ 9 | @Page("/test/listing") 10 | public class ListingFragment extends BaseFragment { 11 | } 12 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | import android.widget.Toast; 13 | 14 | import com.kyleduo.rabbits.P; 15 | import com.kyleduo.rabbits.Rabbit; 16 | import com.kyleduo.rabbits.RabbitResult; 17 | import com.kyleduo.rabbits.annotations.Page; 18 | import com.kyleduo.rabbits.demo.base.BaseActivity; 19 | 20 | import java.lang.ref.WeakReference; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | @Page("/") 25 | public class MainActivity extends BaseActivity { 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | ViewGroup view = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.activity_main, null); 31 | setContentView(view); 32 | 33 | List
data = new ArrayList<>(); 34 | 35 | data.add(new Section( 36 | "Standard Usages", 37 | "/test", 38 | "/test?param=value", 39 | "/test/value", 40 | "demo://rabbits.kyleduo.com/test/value", 41 | "/test_variety", 42 | "xxx://xxx.xxx/xxx?param=xxx" 43 | )); 44 | data.add(new Section("startForResult", "Result: " + P.P_SECOND_ID(1))); 45 | data.add(new Section("Interceptors", "/test/interceptor", "/test/rules")); 46 | data.add(new Section("Fallback", "https://kyleduo.com")); 47 | data.add(new Section("Control", "Redirect: /test/redirect", "Anim: /test/animation", "IgnoreInterceptor: /test/interceptor?not_intercepted", "IgnoreFallback: https://kyleduo.com")); 48 | data.add(new Section("Fragment", "/test_fragment", "/web")); 49 | data.add(new Section("Dump route table", "/dump")); 50 | data.add(new Section("Multiple modules", "/sm1/activity", "/sm2/activity")); 51 | data.add(new Section("copyright @kyleduo 2018")); 52 | data.add(new Section("")); 53 | 54 | RecyclerView rv = (RecyclerView) findViewById(R.id.recycler_view); 55 | rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 56 | rv.setAdapter(new TestAdapter(this, data)); 57 | } 58 | 59 | @Override 60 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 61 | super.onActivityResult(requestCode, resultCode, data); 62 | if (requestCode == 100) { 63 | if (resultCode == Activity.RESULT_OK && data != null) { 64 | Toast.makeText(this, "Result: " + data.getStringExtra("result"), Toast.LENGTH_SHORT).show(); 65 | } else { 66 | Toast.makeText(this, "Result: " + resultCode, Toast.LENGTH_SHORT).show(); 67 | } 68 | } 69 | } 70 | 71 | static class Section { 72 | String name; 73 | List items; 74 | 75 | Section(String name, String... items) { 76 | this.name = name; 77 | this.items = new ArrayList<>(); 78 | if (items != null) { 79 | for (String item : items) { 80 | this.items.add(new Item(item)); 81 | } 82 | } 83 | } 84 | } 85 | 86 | static class Item { 87 | String name; 88 | 89 | Item(String name) { 90 | this.name = name; 91 | } 92 | } 93 | 94 | static class IndexPath { 95 | int section; 96 | int index; 97 | 98 | IndexPath(int section, int index) { 99 | this.section = section; 100 | this.index = index; 101 | } 102 | 103 | static IndexPath create(int section, int index) { 104 | return new IndexPath(section, index); 105 | } 106 | } 107 | 108 | static class SectionViewHolder extends RecyclerView.ViewHolder { 109 | 110 | TextView titleTv; 111 | 112 | SectionViewHolder(View itemView) { 113 | super(itemView); 114 | titleTv = (TextView) itemView.findViewById(R.id.section_title); 115 | } 116 | } 117 | 118 | static class ItemViewHolder extends RecyclerView.ViewHolder { 119 | 120 | TextView titleTv; 121 | 122 | ItemViewHolder(View itemView) { 123 | super(itemView); 124 | titleTv = (TextView) itemView.findViewById(R.id.item_title); 125 | } 126 | } 127 | 128 | static class TestAdapter extends RecyclerView.Adapter { 129 | List
mData; 130 | List mIndexPaths; 131 | private WeakReference mActRef; 132 | 133 | TestAdapter(MainActivity activity, List
data) { 134 | mActRef = new WeakReference<>(activity); 135 | mData = data; 136 | mIndexPaths = new ArrayList<>(); 137 | for (int i = 0; i < mData.size(); i++) { 138 | mIndexPaths.add(IndexPath.create(i, -1)); 139 | Section s = mData.get(i); 140 | for (int j = 0; j < s.items.size(); j++) { 141 | mIndexPaths.add(IndexPath.create(i, j)); 142 | } 143 | } 144 | } 145 | 146 | @Override 147 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 148 | if (viewType == 0) { 149 | View view = LayoutInflater.from(DemoApplication.get()).inflate(R.layout.item_section_header, parent, false); 150 | return new SectionViewHolder(view); 151 | } else if (viewType == 1) { 152 | View view = LayoutInflater.from(DemoApplication.get()).inflate(R.layout.item, parent, false); 153 | final ItemViewHolder holder = new ItemViewHolder(view); 154 | view.setOnClickListener(new View.OnClickListener() { 155 | @Override 156 | public void onClick(View v) { 157 | int position = holder.getAdapterPosition(); 158 | IndexPath indexPath = mIndexPaths.get(position); 159 | if (indexPath.index >= 0) { 160 | Item item = mData.get(indexPath.section).items.get(indexPath.index); 161 | String url = item.name; 162 | RabbitResult result; 163 | if (url.startsWith("Redirect: ")) { 164 | url = url.substring(10); 165 | result = Rabbit.from(mActRef.get()).to(url).redirect().start(); 166 | } else if (url.startsWith("Anim: ")) { 167 | url = url.substring(6); 168 | result = Rabbit.from(mActRef.get()).to(url).setTransitionAnimations(new int[]{R.anim.fadein, R.anim.fadeout}).start(); 169 | } else if (url.startsWith("IgnoreInterceptor: ")) { 170 | url = url.substring(19); 171 | result = Rabbit.from(mActRef.get()).to(url).ignoreInterceptors().start(); 172 | } else if (url.startsWith("IgnoreFallback: ")) { 173 | url = url.substring(16); 174 | result = Rabbit.from(mActRef.get()).to(url).ignoreFallback().start(); 175 | } else if (url.startsWith("Result: ")) { 176 | url = url.substring(8); 177 | result = Rabbit.from(mActRef.get()).to(url).startForResult(100); 178 | } else { 179 | result = Rabbit.from(mActRef.get()).to(url).start(); 180 | } 181 | if (result.isFinished() && !result.isSuccess()) { 182 | Toast.makeText(mActRef.get(), "Navigation Fail", Toast.LENGTH_SHORT).show(); 183 | } 184 | } 185 | } 186 | }); 187 | return holder; 188 | } 189 | return null; 190 | } 191 | 192 | @Override 193 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 194 | int type = getItemViewType(position); 195 | IndexPath indexPath = mIndexPaths.get(position); 196 | if (type == 0) { 197 | ((SectionViewHolder) holder).titleTv.setText(mData.get(indexPath.section).name); 198 | } else if (type == 1) { 199 | ((ItemViewHolder) holder).titleTv.setText(mData.get(indexPath.section).items.get(indexPath.index).name); 200 | } 201 | } 202 | 203 | @Override 204 | public int getItemCount() { 205 | return mIndexPaths.size(); 206 | } 207 | 208 | @Override 209 | public int getItemViewType(int position) { 210 | IndexPath indexPath = mIndexPaths.get(position); 211 | return indexPath.index == -1 ? 0 : 1; 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/SecondFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.LinearLayout; 12 | 13 | import com.kyleduo.rabbits.P; 14 | import com.kyleduo.rabbits.Rabbit; 15 | import com.kyleduo.rabbits.annotations.Page; 16 | import com.kyleduo.rabbits.demo.base.BaseFragment; 17 | 18 | /** 19 | * Created by kyle on 2016/12/12. 20 | */ 21 | @Page("/second/{id:l}") 22 | public class SecondFragment extends BaseFragment { 23 | @Nullable 24 | @Override 25 | public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 26 | LinearLayout ll = (LinearLayout) super.onCreateView(inflater, container, savedInstanceState); 27 | assert ll != null; 28 | 29 | Button button = new Button(getActivity()); 30 | button.setText("Open Embedded Fragment"); 31 | button.setTextColor(0xFF49A1FF); 32 | button.setBackgroundDrawable(null); 33 | button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 34 | button.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View view) { 37 | Rabbit.from(SecondFragment.this) 38 | .to(P.P_TEST_EMBEDDED) 39 | .putExtra("param", "send to embedded fragment") 40 | .start(); 41 | } 42 | }); 43 | ll.addView(button); 44 | 45 | 46 | Button button1 = new Button(getActivity()); 47 | button1.setText("Set Result"); 48 | button1.setTextColor(0xFF49A1FF); 49 | button1.setBackgroundDrawable(null); 50 | button1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 51 | button1.setOnClickListener(new View.OnClickListener() { 52 | @Override 53 | public void onClick(View view) { 54 | Intent intent = new Intent(); 55 | intent.putExtra("result", "Result content"); 56 | getActivity().setResult(Activity.RESULT_OK, intent); 57 | getActivity().finish(); 58 | } 59 | }); 60 | ll.addView(button1); 61 | 62 | return ll; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.TextView; 7 | 8 | import com.kyleduo.rabbits.P; 9 | import com.kyleduo.rabbits.Rabbit; 10 | import com.kyleduo.rabbits.annotations.Page; 11 | import com.kyleduo.rabbits.demo.base.BaseActivity; 12 | 13 | @Page(value = "/test", variety = {"/test_variety", "/test/{param}", "xxx://xxx.xxx/xxx"}) 14 | public class TestActivity extends BaseActivity { 15 | 16 | @SuppressLint("SetTextI18n") 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_test); 21 | 22 | TextView tv = (TextView) findViewById(R.id.params_tv); 23 | tv.setText("param = " + getIntent().getStringExtra("param")); 24 | 25 | findViewById(R.id.back_home_bt).setOnClickListener(new View.OnClickListener() { 26 | @Override 27 | public void onClick(View view) { 28 | Rabbit.from(TestActivity.this) 29 | .to(P.P_) 30 | .clearTop() 31 | .singleTop() 32 | .start(); 33 | } 34 | }); 35 | } 36 | 37 | @Override 38 | protected void onResume() { 39 | super.onResume(); 40 | setTitle(getIntent().getStringExtra(Rabbit.KEY_PATTERN) + "@" + this.getClass().getSimpleName()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/TestFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Button; 11 | import android.widget.LinearLayout; 12 | import android.widget.Toast; 13 | 14 | import com.kyleduo.rabbits.P; 15 | import com.kyleduo.rabbits.Rabbit; 16 | import com.kyleduo.rabbits.annotations.Page; 17 | import com.kyleduo.rabbits.demo.base.BaseFragment; 18 | 19 | import java.util.Random; 20 | 21 | /** 22 | * Created by kyle on 2016/12/12. 23 | */ 24 | @Page("/test_fragment") 25 | public class TestFragment extends BaseFragment { 26 | @Nullable 27 | @Override 28 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 29 | LinearLayout ll = (LinearLayout) super.onCreateView(inflater, container, savedInstanceState); 30 | assert ll != null; 31 | 32 | Button button = createButton("Start Second Fragment"); 33 | button.setOnClickListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View view) { 36 | Rabbit.from(TestFragment.this) 37 | .to(P.P_SECOND_ID(new Random().nextInt(10))) 38 | .start(); 39 | } 40 | }); 41 | ll.addView(button); 42 | 43 | Button button1 = createButton("Redirect to Second Fragment"); 44 | button1.setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View view) { 47 | Rabbit.from(TestFragment.this) 48 | .to(P.P_SECOND_ID(new Random().nextInt(10))) 49 | .redirect() 50 | .start(); 51 | } 52 | }); 53 | ll.addView(button1); 54 | 55 | Button button2 = createButton("start for Result in Fragment"); 56 | button2.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View view) { 59 | Rabbit.from(TestFragment.this) 60 | .to(P.P_SECOND_ID(new Random().nextInt(10))) 61 | .startForResult(100); 62 | } 63 | }); 64 | ll.addView(button2); 65 | 66 | return ll; 67 | } 68 | 69 | private Button createButton(String text) { 70 | Button button = new Button(getActivity()); 71 | button.setText(text); 72 | button.setTextColor(0xFF49A1FF); 73 | button.setBackgroundDrawable(null); 74 | button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 75 | return button; 76 | } 77 | 78 | @Override 79 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 80 | super.onActivityResult(requestCode, resultCode, data); 81 | if (requestCode == 100) { 82 | if (resultCode == Activity.RESULT_OK && data != null) { 83 | Toast.makeText(getActivity(), "Result: " + data.getStringExtra("result"), Toast.LENGTH_SHORT).show(); 84 | } else { 85 | Toast.makeText(getActivity(), "Result: " + resultCode, Toast.LENGTH_SHORT).show(); 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/WebFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.webkit.WebChromeClient; 11 | import android.webkit.WebResourceError; 12 | import android.webkit.WebResourceRequest; 13 | import android.webkit.WebView; 14 | import android.webkit.WebViewClient; 15 | 16 | import com.kyleduo.rabbits.Interceptor; 17 | import com.kyleduo.rabbits.Rabbit; 18 | import com.kyleduo.rabbits.RabbitResult; 19 | import com.kyleduo.rabbits.annotations.Page; 20 | import com.kyleduo.rabbits.demo.base.BaseFragment; 21 | import com.kyleduo.rabbits.rules.Rules; 22 | 23 | /** 24 | * Created by kyle on 2016/12/12. 25 | */ 26 | @Page("/web") 27 | public class WebFragment extends BaseFragment { 28 | public static final String KEY_URL = "url"; 29 | 30 | private WebView mWebView; 31 | 32 | @SuppressLint("SetJavaScriptEnabled") 33 | @Nullable 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 36 | mWebView = (WebView) LayoutInflater.from(getActivity()).inflate(R.layout.fragment_web, container, false); 37 | mWebView.setWebViewClient(new DefaultWebViewClient()); 38 | mWebView.setWebChromeClient(new WebChromeClient()); 39 | mWebView.getSettings().setUseWideViewPort(false); 40 | mWebView.getSettings().setJavaScriptEnabled(true); 41 | return mWebView; 42 | } 43 | 44 | @Override 45 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 46 | super.onActivityCreated(savedInstanceState); 47 | Bundle extras = getArguments(); 48 | String url = "file:///android_asset/web.html"; 49 | if (extras != null) { 50 | url = extras.getString(KEY_URL, url); 51 | } 52 | mWebView.loadUrl(url); 53 | } 54 | 55 | @Override 56 | public void onDestroy() { 57 | if (mWebView != null) { 58 | mWebView.destroy(); 59 | } 60 | super.onDestroy(); 61 | } 62 | 63 | private class DefaultWebViewClient extends WebViewClient { 64 | 65 | @Override 66 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 67 | boolean ret = Rabbit.from(WebFragment.this) 68 | .to(url) 69 | .addInterceptor(new Interceptor() { 70 | @Override 71 | public RabbitResult intercept(Dispatcher dispatcher) { 72 | Intent intent = new Intent(Intent.ACTION_DIAL, dispatcher.action().getUri()); 73 | startActivity(intent); 74 | return RabbitResult.success(); 75 | } 76 | }, Rules.scheme().is("tel")) 77 | .ignoreFallback() 78 | .start() 79 | .isSuccess(); 80 | return ret || super.shouldOverrideUrlLoading(view, url); 81 | } 82 | 83 | @Override 84 | public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { 85 | super.onReceivedError(view, request, error); 86 | } 87 | } 88 | 89 | @Override 90 | public boolean onBackPressedSupport() { 91 | if (mWebView.canGoBack()) { 92 | mWebView.goBack(); 93 | return true; 94 | } 95 | return super.onBackPressedSupport(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/base/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo.base; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.Toolbar; 7 | 8 | import com.kyleduo.rabbits.demo.R; 9 | 10 | import me.yokeyword.fragmentation.SupportActivity; 11 | import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator; 12 | import me.yokeyword.fragmentation.anim.FragmentAnimator; 13 | 14 | /** 15 | * Created by kyle on 2016/12/12. 16 | */ 17 | 18 | public class BaseActivity extends SupportActivity { 19 | 20 | @Override 21 | protected FragmentAnimator onCreateFragmentAnimator() { 22 | return new DefaultHorizontalAnimator(); 23 | } 24 | 25 | @Override 26 | protected void onCreate(@Nullable Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | 29 | new Handler().post(new Runnable() { 30 | @Override 31 | public void run() { 32 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 33 | setSupportActionBar(toolbar); 34 | 35 | toolbar.setTitleTextColor(0xFF7A8790); 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.util.TypedValue; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | import com.kyleduo.rabbits.Rabbit; 13 | import com.kyleduo.rabbits.demo.R; 14 | 15 | import java.util.Set; 16 | 17 | import me.yokeyword.fragmentation.SupportFragment; 18 | 19 | /** 20 | * Created by kyle on 2016/12/12. 21 | */ 22 | 23 | public class BaseFragment extends SupportFragment { 24 | 25 | @Nullable 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 28 | LinearLayout ll = new LinearLayout(getActivity()); 29 | ll.setBackgroundColor(0xFFFFFFFF); 30 | ll.setOrientation(LinearLayout.VERTICAL); 31 | int padding = (int) (getResources().getDisplayMetrics().density * 16); 32 | ll.setPadding(padding, padding, padding, padding); 33 | ll.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 34 | TextView tv = createInfoTextView(); 35 | ll.addView(tv); 36 | return ll; 37 | } 38 | 39 | protected TextView createInfoTextView() { 40 | TextView tv = new TextView(getActivity()); 41 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 42 | tv.setLayoutParams(lp); 43 | tv.setTextColor(getResources().getColor(R.color.textColor)); 44 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); 45 | 46 | StringBuilder params = new StringBuilder(); 47 | params.append("These are the params being used when opening this page.\n\n"); 48 | Set keys = getArguments().keySet(); 49 | for (String key : keys) { 50 | Object value = getArguments().get(key); 51 | params.append(key).append("\n\t->\t").append(value == null ? "null" : value.toString()).append('\n').append('\n'); 52 | } 53 | tv.setText(params.toString()); 54 | return tv; 55 | } 56 | 57 | @Override 58 | public void onSupportVisible() { 59 | super.onSupportVisible(); 60 | getActivity().setTitle(getArguments().getString(Rabbit.KEY_PATTERN) + "@" + this.getClass().getSimpleName()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo.utils; 2 | 3 | /** 4 | * Created by kyle on 27/02/2018. 5 | */ 6 | 7 | public class Constants { 8 | // indicate fragment can embed in other Activity than common. 9 | public static final int FLAG_FRAG_EMBED = 1 << 1; 10 | } 11 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/java/com/kyleduo/rabbits/demo/utils/UriUtils.java: -------------------------------------------------------------------------------- 1 | package com.kyleduo.rabbits.demo.utils; 2 | 3 | import android.net.Uri; 4 | 5 | /** 6 | * Created by kyle on 2017/1/6. 7 | */ 8 | 9 | public class UriUtils { 10 | public static boolean matchPath(Uri uri, String path) { 11 | return uri != null && uri.getPath() != null && uri.getPath().equals(path); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/res/anim/fadein.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/res/anim/fadeout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/res/layout/activity_common.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Rabbits/app/src/main/res/layout/activity_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | 19 | 20 |