├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── encodings.xml ├── jarRepositories.xml ├── markdown-navigator-enh.xml ├── markdown-navigator.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── activitymessenger ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── wuyr │ │ └── activitymessenger │ │ ├── ActivityExtras.kt │ │ ├── ActivityMessenger.kt │ │ └── Extensions.kt │ └── res │ └── values │ └── strings.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # IntelliJ 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/assetWizardSettings.xml 41 | .idea/dictionaries 42 | .idea/libraries 43 | .idea/caches 44 | 45 | # Keystore files 46 | # Uncomment the following line if you do not want to check your keystore files in. 47 | #*.jks 48 | 49 | # External native build folder generated in Android Studio 2.2 and later 50 | .externalNativeBuild 51 | 52 | # Google Services (e.g. APIs or Firebase) 53 | google-services.json 54 | 55 | # Freeline 56 | freeline.py 57 | freeline/ 58 | freeline_project_description.json 59 | 60 | # fastlane 61 | fastlane/report.xml 62 | fastlane/Preview.html 63 | fastlane/screenshots 64 | fastlane/test_output 65 | fastlane/readme.md 66 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 | 116 | 118 |
119 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/markdown-navigator-enh.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 30 | 31 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Android 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | ## ActivityMessenger,借助Kotlin特性,简化Activity之间传参和回调的逻辑代码。 2 | ### 博客详情: 3 | 4 | ### 唠叨: 5 | #### 在日常开发中,每次使用startActivityForResult时,要做的事情都超级多: 6 | 7 | 1. 定义一个`RequestCode`; 8 | 9 | 2. 重写`onActivityResult`并在这里判断`RequestCode`和`ResultCode`; 10 | 11 | 3. 如果有携带参数,还要一个个通过`putExtra`方法`put`进*Intent*里; 12 | 13 | 4. 目标*Activity*处理完成后还要把数据一个个`put`进*Intent*中,`setResult`然后`finish`; 14 | 15 | 5. 如果参数是可序列化的泛型类对象(如*ArrayList\*),取出来的时候不但要显式强制转型,还要把 UNCHECKED_CAST 警告抑制; 16 |
17 | 18 | #### 在饱受这些繁琐折磨之后,便诞生出了**ActivityMessenger**。 19 | #### 它有以下特点: 20 | 21 | 1. `startActivityForResult`不用另外定义`RequestCode`; 22 | 23 | 2. 跟其他库一样,`startActivityForResult`不用重写`onActivityResult`方法,也不用判断`RequestCode`和`ResultCode`; 24 | 25 | 3. `startActivity`如有携带参数不须一个个调用`putExtra`方法; 26 | 27 | 4. 从*Intent*中取出数据时,无须调用对应类型的方法,如`getStringExtra()`、`getIntExtra()`、`getSerializableExtra()`等; 28 | 29 | 5. 如果参数是可序列化的泛型类对象(如*ArrayList\*),取出来的时候不用强制转型,也没有可怕的 ***UNCHECKED_CAST*** 警告了; 30 |
31 | 32 | ### 示例: 33 | ### startActivity: 34 | ***方式1***(假设`TestActivity`是要启动的Activity): 35 | ```kotlin 36 | //不携带参数 37 | startActivity() 38 | 39 | //携带参数(可连续多个键值对) 40 | startActivity("Key" to "Value") 41 | ``` 42 | ***方式2***(假设`TestActivity`是要启动的Activity): 43 | ```kotlin 44 | //不携带参数 45 | startActivity(TestActivity::class) 46 | 47 | //携带参数(可连续多个键值对) 48 | startActivity( 49 | TestActivity::class, 50 | "Key1" to "Value", 51 | "Key2" to 123 52 | ) 53 | ``` 54 |
55 | 56 | ### startActivityForResult: 57 | ***方式1***(假设`TestActivity`是要启动的Activity): 58 | ```kotlin 59 | //不携带参数 60 | startActivityForResult { 61 | if (it == null) { 62 | //未成功处理,即(ResultCode != RESULT_OK) 63 | } else { 64 | //处理成功,这里可以操作返回的intent 65 | } 66 | } 67 | 68 | //携带参数同startActivity。 69 | ``` 70 | ***方式2***(假设`TestActivity`是要启动的Activity): 71 | ```kotlin 72 | //不携带参数 73 | startActivityForResult(TestActivity::class) { 74 | if (it == null) { 75 | //未成功处理,即(ResultCode != RESULT_OK) 76 | } else { 77 | //处理成功,这里可以操作返回的intent 78 | } 79 | } 80 | 81 | //携带参数同startActivity。 82 | ``` 83 |
84 | 85 | ### finish: 86 | ```kotlin 87 | //退出并设置参数 88 | finish("Key1" to "Value1", "Key2" to 2) 89 | ``` 90 |
91 | 92 | ### getExtras(获取Intent参数): 93 | ***方式1*** 94 | ```kotlin 95 | //预先声明好类型 96 | var mData: List? = null 97 | mData = intent.get("Key1") 98 | ``` 99 | ***方式2*** 100 | ```kotlin 101 | //取出时再决定类型 102 | val result = intent.get("Key2") 103 | ``` 104 | 105 | ***方式3*** 106 | ```kotlin 107 | // 使用委托 108 | val key3 by extraAct("key3", "test") 109 | var key4: String? by extraAct("key4") 110 | ``` 111 |
112 | 113 | ### toIntent: 114 | ```kotlin 115 | val action = "android.media.action.IMAGE_CAPTURE" 116 | val intent = action.toIntent() 117 | ``` 118 |
119 | 120 | ### 使用方式: 121 | #### 添加依赖: 122 | ``` 123 | implementation 'com.wuyr:activitymessenger:1.2.2' 124 | ``` 125 | 126 | ### Demo源码地址: 127 | --- 128 | ### 感谢: 129 | #### Jowan: 130 | #### RxActivityResult: 131 | -------------------------------------------------------------------------------- /activitymessenger/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /activitymessenger/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.jfrog.bintray' 5 | apply plugin: 'com.github.dcendents.android-maven' 6 | 7 | def siteUrl = 'https://github.com/wuyr/ActivityMessenger' //需要修改 8 | def gitUrl = 'https://github.com/Ifxcyr/ActivityMessenger.git' //需要修改 9 | 10 | version = "1.2.3" 11 | group = "com.wuyr" 12 | 13 | android { 14 | compileSdkVersion 29 15 | defaultConfig { 16 | minSdkVersion 14 17 | targetSdkVersion 29 18 | versionCode 4 19 | versionName "1.2.2" 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 21 | } 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | } 29 | dependencies { 30 | compileOnly 'androidx.appcompat:appcompat:1.1.0' 31 | compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 32 | } 33 | 34 | Properties properties = new Properties() 35 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 36 | bintray { 37 | user = properties.getProperty("bintray.user") 38 | key = properties.getProperty("bintray.apikey") 39 | pkg { 40 | repo = 'ActivityMessenger' //需要修改 41 | name = 'ActivityMessenger' //需要修改 42 | websiteUrl = siteUrl 43 | vcsUrl = gitUrl 44 | licenses = ['Apache-2.0'] 45 | userOrg = 'wuyr' 46 | publish = true 47 | 48 | version { 49 | name = '1.2.2' 50 | desc = '简化startActivityForResult逻辑和优化put、getExtras方式,提供更方便的API' //需要修改 51 | released = new Date() 52 | vcsTag = '1.2.2' 53 | attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin'] 54 | } 55 | } 56 | configurations = ['archives'] 57 | } 58 | 59 | install { 60 | repositories.mavenInstaller { 61 | 62 | pom { 63 | project { 64 | packaging 'aar' 65 | 66 | name '陈小缘' 67 | description '简化startActivityForResult逻辑和优化put、getExtras方式,提供更方便的API' //需要修改 68 | url siteUrl 69 | 70 | licenses { 71 | license { 72 | name 'Apache-2.0' 73 | url 'https://raw.githubusercontent.com/Ifxcyr/ActivityMessenger/master/LICENSE' //需要修改 74 | } 75 | } 76 | developers { 77 | developer { 78 | id 'ifxcyr' 79 | name '陈小缘' 80 | email 'ifxcyr@gmail.com' 81 | } 82 | } 83 | scm { 84 | connection gitUrl 85 | developerConnection gitUrl 86 | url siteUrl 87 | } 88 | } 89 | } 90 | } 91 | } 92 | task sourcesJar(type: Jar) { 93 | from android.sourceSets.main.java.srcDirs 94 | classifier = 'sources' 95 | } 96 | task javadoc(type: Javadoc) { 97 | failOnError false 98 | source = android.sourceSets.main.java.srcDirs 99 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 100 | } 101 | task javadocJar(type: Jar, dependsOn: javadoc) { 102 | classifier = 'javadoc' 103 | from javadoc.destinationDir 104 | } 105 | artifacts { 106 | archives javadocJar 107 | archives sourcesJar 108 | } 109 | javadoc { 110 | options { 111 | encoding "UTF-8" 112 | charSet 'UTF-8' 113 | author true 114 | version true 115 | links "http://docs.oracle.com/javase/8/docs/api" 116 | } 117 | } -------------------------------------------------------------------------------- /activitymessenger/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 | -------------------------------------------------------------------------------- /activitymessenger/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /activitymessenger/src/main/java/com/wuyr/activitymessenger/ActivityExtras.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION", "unused") 2 | 3 | package com.wuyr.activitymessenger 4 | 5 | import android.app.Activity 6 | import android.app.Fragment 7 | import kotlin.properties.ReadWriteProperty 8 | import kotlin.reflect.KProperty 9 | 10 | /** 11 | * 获取Intent参数,Activity 12 | * 示例: 13 | *

14 | * 15 | * private var str: String? by extraAct("String") 16 | * private var str1 by extraAct("String1", "123") 17 | * private var int1 by extraAct("Int1", 123) 18 | * 19 | * Log.e("TestActivity", "str---------$str") // get 20 | * str = "str" // set 21 | * Log.e("TestActivity", "str1---------$str1") // get 22 | * str1 = "str1" // set 23 | * Log.e("TestActivity", "int1---------$int1") // get 24 | * int1 = 1000 // set 25 | *

26 | * 27 | * @author Jowan 28 | * Created on 2019/8/15. 29 | */ 30 | class ActivityExtras(private val extraName: String, private val defaultValue: T) : 31 | ReadWriteProperty { 32 | 33 | /** 34 | * getExtras字段对应的值 35 | */ 36 | private var extra: T? = null 37 | 38 | override fun getValue(thisRef: Activity, property: KProperty<*>): T { 39 | // 如果extra不为空则返回extra 40 | // 如果extra是空的,则判断intent的参数的值,如果值不为空,则将值赋予extra,并且返回 41 | // 如果intent参数的值也为空,则返回defaultValue,并且将值赋予extra 42 | return extra ?: thisRef.intent?.get(extraName)?.also { extra = it } 43 | ?: defaultValue.also { extra = it } 44 | } 45 | 46 | override fun setValue(thisRef: Activity, property: KProperty<*>, value: T) { 47 | extra = value 48 | } 49 | } 50 | 51 | /** 52 | * 获取Intent参数,Fragment 53 | * 示例同[ActivityExtras] 54 | */ 55 | class FragmentExtras(private val extraName: String, private val defaultValue: T) : 56 | ReadWriteProperty { 57 | 58 | /** 59 | * getExtras字段对应的值 60 | */ 61 | private var extra: T? = null 62 | 63 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T { 64 | // 如果extra不为空则返回extra 65 | // 如果extra是空的,则判断intent的参数的值,如果值不为空,则将值赋予extra,并且返回 66 | // 如果intent参数的值也为空,则返回defaultValue,并且将值赋予extra 67 | return extra ?: thisRef.arguments?.get(extraName)?.also { extra = it } 68 | ?: defaultValue.also { extra = it } 69 | } 70 | 71 | override fun setValue(thisRef: Fragment, property: KProperty<*>, value: T) { 72 | extra = value 73 | } 74 | } 75 | 76 | fun extraFrag(extraName: String): FragmentExtras = FragmentExtras(extraName, null) 77 | 78 | fun extraFrag(extraName: String, defaultValue: T): FragmentExtras = 79 | FragmentExtras(extraName, defaultValue) 80 | 81 | 82 | fun extraAct(extraName: String): ActivityExtras = ActivityExtras(extraName, null) 83 | 84 | fun extraAct(extraName: String, defaultValue: T): ActivityExtras = 85 | ActivityExtras(extraName, defaultValue) -------------------------------------------------------------------------------- /activitymessenger/src/main/java/com/wuyr/activitymessenger/ActivityMessenger.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress( 2 | "unused", 3 | "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE", 4 | "SpellCheckingInspection", "DEPRECATION" 5 | ) 6 | 7 | package com.wuyr.activitymessenger 8 | 9 | import android.app.Activity 10 | import android.app.Fragment 11 | import android.content.Context 12 | import android.content.Intent 13 | import kotlin.reflect.KClass 14 | 15 | /** 16 | * @author wuyr 17 | * @github https://github.com/wuyr/ActivityMessenger 18 | * @since 2019-08-05 上午11:56 19 | */ 20 | object ActivityMessenger { 21 | private var sRequestCode = 0 22 | set(value) { 23 | field = if (value >= Integer.MAX_VALUE) 1 else value 24 | } 25 | 26 | /** 27 | * 作用同[Activity.startActivity] 28 | * 示例: 29 | *
 30 |      *      //不携带参数
 31 |      *      ActivityMessenger.startActivity(this)
 32 |      *
 33 |      *      //携带参数(可连续多个键值对)
 34 |      *      ActivityMessenger.startActivity(this, "Key" to "Value")
 35 |      *  
36 | * 37 | * @param TARGET 要启动的Activity 38 | * @param starter 发起的Activity 39 | * @param params extras键值对 40 | */ 41 | inline fun startActivity( 42 | starter: Activity, vararg params: Pair 43 | ) = starter.startActivity(Intent(starter, TARGET::class.java).putExtras(*params)) 44 | 45 | /** 46 | * Fragment跳转,同[Activity.startActivity] 47 | * 示例: 48 | *
 49 |      *      //不携带参数
 50 |      *      ActivityMessenger.startActivity(this)
 51 |      *
 52 |      *      //携带参数(可连续多个键值对)
 53 |      *      ActivityMessenger.startActivity(this, "Key" to "Value")
 54 |      *  
55 | * 56 | * @param TARGET 要启动的Activity 57 | * @param starter 发起的Fragment 58 | * @param params extras键值对 59 | */ 60 | inline fun startActivity( 61 | starter: Fragment, vararg params: Pair 62 | ) = starter.startActivity(Intent(starter.activity, TARGET::class.java).putExtras(*params)) 63 | 64 | /** 65 | * Adapter跳转,同[Context.startActivity] 66 | * 示例: 67 | *
 68 |      *      //不携带参数
 69 |      *      ActivityMessenger.startActivity(context)
 70 |      *
 71 |      *      //携带参数(可连续多个键值对)
 72 |      *      ActivityMessenger.startActivity(context, "Key" to "Value")
 73 |      *  
74 | * 75 | * @param TARGET 要启动的Context 76 | * @param starter 发起的Fragment 77 | * @param params extras键值对 78 | */ 79 | inline fun startActivity( 80 | starter: Context, vararg params: Pair 81 | ) = starter.startActivity(Intent(starter, TARGET::class.java).putExtras(*params)) 82 | 83 | /** 84 | * 作用同[Activity.startActivity] 85 | * 示例: 86 | *
 87 |      *      //不携带参数
 88 |      *      ActivityMessenger.startActivity(this, TestActivity::class)
 89 |      *
 90 |      *      //携带参数(可连续多个键值对)
 91 |      *     ActivityMessenger.startActivity(
 92 |      *         this, TestActivity::class,
 93 |      *         "Key1" to "Value",
 94 |      *         "Key2" to 123
 95 |      *     )
 96 |      *  
97 | * 98 | * @param starter 发起的Activity 99 | * @param target 要启动的Activity 100 | * @param params extras键值对 101 | */ 102 | fun startActivity( 103 | starter: Activity, target: KClass, vararg params: Pair 104 | ) = starter.startActivity(Intent(starter, target.java).putExtras(*params)) 105 | 106 | /** 107 | * 作用同上,此方法为了兼容Java Class 108 | */ 109 | fun startActivity( 110 | starter: Activity, target: Class, vararg params: Pair 111 | ) = starter.startActivity(Intent(starter, target).putExtras(*params)) 112 | 113 | /** 114 | * Fragment跳转,同[Activity.startActivity] 115 | * 示例: 116 | *
117 |      *      //不携带参数
118 |      *      ActivityMessenger.startActivity(this, TestActivity::class)
119 |      *
120 |      *      //携带参数(可连续多个键值对)
121 |      *     ActivityMessenger.startActivity(
122 |      *         this, TestActivity::class,
123 |      *         "Key1" to "Value",
124 |      *         "Key2" to 123
125 |      *     )
126 |      *  
127 | * 128 | * @param starter 发起的Fragment 129 | * @param target 要启动的Activity 130 | * @param params extras键值对 131 | */ 132 | fun startActivity( 133 | starter: Fragment, target: KClass, vararg params: Pair 134 | ) = starter.startActivity(Intent(starter.activity, target.java).putExtras(*params)) 135 | 136 | /** 137 | * 作用同上,此方法为了兼容Java Class 138 | */ 139 | fun startActivity( 140 | starter: Fragment, target: Class, vararg params: Pair 141 | ) = starter.startActivity(Intent(starter.activity, target).putExtras(*params)) 142 | 143 | /** 144 | * Adapter里面跳转,同[Context.startActivity] 145 | * 示例: 146 | *
147 |      *      //不携带参数
148 |      *      ActivityMessenger.startActivity(context, TestActivity::class)
149 |      *
150 |      *      //携带参数(可连续多个键值对)
151 |      *     ActivityMessenger.startActivity(
152 |      *         context, TestActivity::class,
153 |      *         "Key1" to "Value",
154 |      *         "Key2" to 123
155 |      *     )
156 |      *  
157 | * 158 | * @param starter 发起的Context 159 | * @param target 要启动的Activity 160 | * @param params extras键值对 161 | */ 162 | fun startActivity( 163 | starter: Context, target: KClass, vararg params: Pair 164 | ) = starter.startActivity(Intent(starter, target.java).putExtras(*params)) 165 | 166 | /** 167 | * 作用同上,此方法为了兼容Java Class 168 | */ 169 | fun startActivity( 170 | starter: Context, target: Class, vararg params: Pair 171 | ) = starter.startActivity(Intent(starter, target).putExtras(*params)) 172 | 173 | /** 174 | * 作用同[Activity.startActivityForResult] 175 | * 示例: 176 | *
177 |      *      //不携带参数
178 |      *      ActivityMessenger.startActivityForResult {
179 |      *          if (it == null) {
180 |      *              //未成功处理,即(ResultCode != RESULT_OK)
181 |      *          } else {
182 |      *              //处理成功,这里可以操作返回的intent
183 |      *          }
184 |      *      }
185 |      *  
186 | * 携带参数同[startActivity] 187 | * 188 | * @param TARGET 要启动的Activity 189 | * @param starter 发起的Activity 190 | * @param params extras键值对 191 | * @param callback onActivityResult的回调 192 | */ 193 | inline fun startActivityForResult( 194 | starter: Activity, vararg params: Pair, 195 | crossinline callback: ((result: Intent?) -> Unit) 196 | ) = startActivityForResult(starter, TARGET::class, *params, callback = callback) 197 | 198 | /** 199 | * Fragment跳转,同[Activity.startActivityForResult] 200 | * 示例: 201 | *
202 |      *      //不携带参数
203 |      *      ActivityMessenger.startActivityForResult {
204 |      *          if (it == null) {
205 |      *              //未成功处理,即(ResultCode != RESULT_OK)
206 |      *          } else {
207 |      *              //处理成功,这里可以操作返回的intent
208 |      *          }
209 |      *      }
210 |      *  
211 | * 携带参数同[startActivity] 212 | * 213 | * @param TARGET 要启动的Activity 214 | * @param starter 发起的Activity 215 | * @param params extras键值对 216 | * @param callback onActivityResult的回调 217 | */ 218 | inline fun startActivityForResult( 219 | starter: Fragment, vararg params: Pair, 220 | crossinline callback: ((result: Intent?) -> Unit) 221 | ) = startActivityForResult(starter.activity, TARGET::class, *params, callback = callback) 222 | 223 | /** 224 | * 作用同[Activity.startActivityForResult] 225 | * 示例: 226 | *
227 |      *      //不携带参数
228 |      *      ActivityMessenger.startActivityForResult {resultCode, result->
229 |      *          if (resultCode == RESULT_OK) {
230 |      *              //处理成功,这里可以操作返回的intent
231 |      *          } else {
232 |      *             //未成功处理
233 |      *          }
234 |      *      }
235 |      *  
236 | * 携带参数同[startActivity] 237 | * 238 | * @param TARGET 要启动的Activity 239 | * @param starter 发起的Activity 240 | * @param params extras键值对 241 | * @param callback onActivityResult的回调 242 | */ 243 | inline fun startActivityForResult2( 244 | starter: Activity, vararg params: Pair, 245 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 246 | ) = startActivityForResult2(starter, TARGET::class, *params, callback = callback) 247 | 248 | /** 249 | * Fragment跳转,同[Activity.startActivityForResult] 250 | * 示例: 251 | *
252 |      *      //不携带参数
253 |      *      ActivityMessenger.startActivityForResult {resultCode, result->
254 |      *          if (resultCode == RESULT_OK) {
255 |      *              //处理成功,这里可以操作返回的intent
256 |      *          } else {
257 |      *             //未成功处理
258 |      *          }
259 |      *      }
260 |      *  
261 | * 携带参数同[startActivity] 262 | * 263 | * @param TARGET 要启动的Activity 264 | * @param starter 发起的Activity 265 | * @param params extras键值对 266 | * @param callback onActivityResult的回调 267 | */ 268 | inline fun startActivityForResult2( 269 | starter: Fragment, vararg params: Pair, 270 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 271 | ) = startActivityForResult2(starter.activity, TARGET::class, *params, callback = callback) 272 | 273 | /** 274 | * 作用同[Activity.startActivityForResult] 275 | * 示例: 276 | *
277 |      *      //不携带参数
278 |      *      ActivityMessenger.startActivityForResult(this, TestActivity::class) {
279 |      *          if (it == null) {
280 |      *              //未成功处理,即(ResultCode != RESULT_OK)
281 |      *          } else {
282 |      *              //处理成功,这里可以操作返回的intent
283 |      *          }
284 |      *      }
285 |      *  
286 | * 携带参数同[startActivity] 287 | * 288 | * @param starter 发起的Activity 289 | * @param target 要启动的Activity 290 | * @param params extras键值对 291 | * @param callback onActivityResult的回调 292 | */ 293 | inline fun startActivityForResult( 294 | starter: Activity?, target: KClass, 295 | vararg params: Pair, crossinline callback: ((result: Intent?) -> Unit) 296 | ) = starter.runIfNonNull { 297 | startActivityForResult(it, Intent(it, target.java).putExtras(*params), callback) 298 | } 299 | 300 | /** 301 | * 作用同上,此方法为了兼容Java Class 302 | */ 303 | inline fun startActivityForResult( 304 | starter: Activity?, target: Class, 305 | vararg params: Pair, crossinline callback: ((result: Intent?) -> Unit) 306 | ) = starter.runIfNonNull { 307 | startActivityForResult(it, Intent(it, target).putExtras(*params), callback) 308 | } 309 | 310 | /** 311 | * 作用同[Activity.startActivityForResult] 312 | * 示例: 313 | *
314 |      *      //不携带参数
315 |      *      ActivityMessenger.startActivityForResult(this, TestActivity::class) {resultCode, result->
316 |      *          if (resultCode == RESULT_OK) {
317 |      *              //处理成功,这里可以操作返回的intent
318 |      *          } else {
319 |      *             //未成功处理
320 |      *          }
321 |      *      }
322 |      *  
323 | * 携带参数同[startActivity] 324 | * 325 | * @param starter 发起的Activity 326 | * @param target 要启动的Activity 327 | * @param params extras键值对 328 | * @param callback onActivityResult的回调 329 | */ 330 | inline fun startActivityForResult2( 331 | starter: Activity?, target: KClass, 332 | vararg params: Pair, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 333 | ) = starter.runIfNonNull { 334 | startActivityForResult2(it, Intent(it, target.java).putExtras(*params), callback) 335 | } 336 | 337 | /** 338 | * 作用同上,此方法为了兼容Java Class 339 | */ 340 | inline fun startActivityForResult2( 341 | starter: Activity?, target: Class, 342 | vararg params: Pair, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 343 | ) = starter.runIfNonNull { 344 | startActivityForResult2(it, Intent(it, target).putExtras(*params), callback) 345 | } 346 | 347 | inline fun startActivityForResult( 348 | starter: Activity?, intent: Intent, crossinline callback: ((result: Intent?) -> Unit) 349 | ) = starter.runIfNonNull { 350 | val fragment = GhostFragment() 351 | fragment.init(++sRequestCode, intent) { result -> 352 | callback(result) 353 | it.fragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss() 354 | } 355 | it.fragmentManager.beginTransaction().add(fragment, GhostFragment::class.java.simpleName) 356 | .commitAllowingStateLoss() 357 | } 358 | 359 | inline fun startActivityForResult2( 360 | starter: Activity?, 361 | intent: Intent, 362 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 363 | ) = starter.runIfNonNull { 364 | val fragment = GhostFragment() 365 | fragment.init(++sRequestCode, intent) { resultCode, result -> 366 | callback(resultCode, result) 367 | it.fragmentManager.beginTransaction().remove(fragment).commitAllowingStateLoss() 368 | } 369 | it.fragmentManager.beginTransaction().add(fragment, GhostFragment::class.java.simpleName) 370 | .commitAllowingStateLoss() 371 | } 372 | 373 | /** 374 | * 作用同[Activity.finish] 375 | * 示例: 376 | *
377 |      *      ActivityMessenger.finish(this, "Key" to "Value")
378 |      *  
379 | * 380 | * @param src 发起的Activity 381 | * @param params extras键值对 382 | */ 383 | fun finish(src: Activity, vararg params: Pair) = src.run { 384 | setResult(Activity.RESULT_OK, Intent().putExtras(*params)) 385 | finish() 386 | } 387 | 388 | /** 389 | * Fragment调用,作用同[Activity.finish] 390 | * 示例: 391 | *
392 |      *      ActivityMessenger.finish(this, "Key" to "Value")
393 |      *  
394 | * 395 | * @param src 发起的Fragment 396 | * @param params extras键值对 397 | */ 398 | fun finish(src: Fragment, vararg params: Pair) = 399 | src.activity?.run { finish(this, *params) } 400 | } 401 | 402 | class GhostFragment : Fragment() { 403 | 404 | private var requestCode = -1 405 | private var intent: Intent? = null 406 | private var callback: ((result: Intent?) -> Unit)? = null 407 | private var callback2: ((resultCode: Int, result: Intent?) -> Unit)? = null 408 | 409 | fun init(requestCode: Int, intent: Intent, callback: ((result: Intent?) -> Unit)) { 410 | this.requestCode = requestCode 411 | this.intent = intent 412 | this.callback = callback 413 | } 414 | 415 | fun init(requestCode: Int, intent: Intent, callback: ((resultCode: Int, result: Intent?) -> Unit)) { 416 | this.requestCode = requestCode 417 | this.intent = intent 418 | this.callback2 = callback 419 | } 420 | 421 | private var activityStarted = false 422 | 423 | override fun onAttach(activity: Activity?) { 424 | super.onAttach(activity) 425 | if (!activityStarted) { 426 | activityStarted = true 427 | intent?.let { startActivityForResult(it, requestCode) } 428 | } 429 | } 430 | 431 | override fun onAttach(context: Context) { 432 | super.onAttach(context) 433 | if (!activityStarted) { 434 | activityStarted = true 435 | intent?.let { startActivityForResult(it, requestCode) } 436 | } 437 | } 438 | 439 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 440 | super.onActivityResult(requestCode, resultCode, data) 441 | if (requestCode == this.requestCode) { 442 | callback?.invoke(data) 443 | callback2?.invoke(resultCode, data) 444 | } 445 | } 446 | 447 | override fun onDetach() { 448 | super.onDetach() 449 | intent = null 450 | callback = null 451 | callback2 = null 452 | } 453 | } -------------------------------------------------------------------------------- /activitymessenger/src/main/java/com/wuyr/activitymessenger/Extensions.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION", "unused", "UNCHECKED_CAST") 2 | 3 | package com.wuyr.activitymessenger 4 | 5 | import android.app.Activity 6 | import android.app.Fragment 7 | import android.content.Intent 8 | import android.os.BaseBundle 9 | import android.os.Build 10 | import android.os.Bundle 11 | import android.os.Parcelable 12 | import com.wuyr.activitymessenger.ActivityMessenger.startActivity 13 | import com.wuyr.activitymessenger.IntentFieldMethod.internalMap 14 | import java.io.Serializable 15 | import java.lang.reflect.Field 16 | import java.lang.reflect.Method 17 | import java.util.function.BiFunction 18 | import kotlin.reflect.KClass 19 | 20 | /** 21 | * @author wuyr 22 | * @github https://github.com/wuyr/ActivityMessenger 23 | * @since 2020-04-28 下午2:08 24 | */ 25 | 26 | /** 27 | * [Intent]的扩展方法,此方法可无视类型直接获取到对应值 28 | * 如getStringExtra()、getIntExtra()、getSerializableExtra()等方法通通不用 29 | * 可以直接通过此方法来获取到对应的值,例如: 30 | *
 31 |  *     var mData: List? = null
 32 |  *     mData = intent.get("Data")
 33 |  * 
34 | * 而不用显式强制转型 35 | * 36 | * @param key 对应的Key 37 | * @return 对应的Value 38 | */ 39 | fun Intent?.get(key: String, defaultValue: O? = null) = this?.internalMap()?.get(key)?.let { 40 | if (Build.VERSION.SDK_INT >= 33 && it is BiFunction<*, *, *>) { 41 | runCatching { 42 | (it as BiFunction?, Array?>?, *>).apply(null, null).also { value -> 43 | internalMap()?.put(key, value) 44 | } as? O 45 | }.getOrElse { defaultValue } 46 | } else it as? O 47 | } ?: defaultValue 48 | 49 | /** 50 | * 作用同Intent.[get] 51 | */ 52 | fun Bundle?.get(key: String, defaultValue: O? = null) = this?.internalMap()?.get(key)?.let { 53 | if (Build.VERSION.SDK_INT >= 33 && it is BiFunction<*, *, *>) { 54 | runCatching { 55 | (it as BiFunction?, Array?>?, *>).apply(null, null).also { value -> 56 | internalMap()?.put(key, value) 57 | } as? O 58 | }.getOrElse { defaultValue } 59 | } else it as? O 60 | } ?: defaultValue 61 | 62 | /** 63 | * [Intent]的扩展方法,用来批量put键值对 64 | * 示例: 65 | *
 66 |  *      intent.putExtras(
 67 |  *          "Key1" to "Value",
 68 |  *          "Key2" to 123,
 69 |  *          "Key3" to false,
 70 |  *          "Key4" to arrayOf("4", "5", "6")
 71 |  *      )
 72 |  * 
73 | * 74 | * @param params 键值对 75 | */ 76 | fun Intent.putExtras(vararg params: Pair): Intent { 77 | if (params.isEmpty()) return this 78 | params.forEach { (key, value) -> 79 | when (value) { 80 | is Int -> putExtra(key, value) 81 | is Byte -> putExtra(key, value) 82 | is Char -> putExtra(key, value) 83 | is Long -> putExtra(key, value) 84 | is Float -> putExtra(key, value) 85 | is Short -> putExtra(key, value) 86 | is Double -> putExtra(key, value) 87 | is Boolean -> putExtra(key, value) 88 | is Bundle -> putExtra(key, value) 89 | is String -> putExtra(key, value) 90 | is IntArray -> putExtra(key, value) 91 | is ByteArray -> putExtra(key, value) 92 | is CharArray -> putExtra(key, value) 93 | is LongArray -> putExtra(key, value) 94 | is FloatArray -> putExtra(key, value) 95 | is Parcelable -> putExtra(key, value) 96 | is ShortArray -> putExtra(key, value) 97 | is DoubleArray -> putExtra(key, value) 98 | is BooleanArray -> putExtra(key, value) 99 | is CharSequence -> putExtra(key, value) 100 | is Array<*> -> { 101 | when { 102 | value.isArrayOf() -> 103 | putExtra(key, value as Array) 104 | value.isArrayOf() -> 105 | putExtra(key, value as Array) 106 | value.isArrayOf() -> 107 | putExtra(key, value as Array) 108 | else -> putExtra(key, value) 109 | } 110 | } 111 | is Serializable -> putExtra(key, value) 112 | } 113 | } 114 | return this 115 | } 116 | 117 | /** 118 | * 作用同[Activity.startActivity] 119 | * 示例: 120 | *
121 |  *      //不携带参数
122 |  *      startActivity()
123 |  *
124 |  *      //携带参数(可连续多个键值对)
125 |  *      startActivity("Key" to "Value")
126 |  *  
127 | * 128 | * @param TARGET 要启动的Activity 129 | * @param params extras键值对 130 | */ 131 | inline fun Activity.startActivity( 132 | vararg params: Pair 133 | ) = startActivity(Intent(this, TARGET::class.java).putExtras(*params)) 134 | 135 | inline fun Fragment.startActivity( 136 | vararg params: Pair 137 | ) = activity?.run { 138 | startActivity(Intent(this, TARGET::class.java).putExtras(*params)) 139 | } 140 | 141 | inline fun androidx.fragment.app.Fragment.startActivity( 142 | vararg params: Pair 143 | ) = activity?.run { 144 | startActivity(Intent(this, TARGET::class.java).putExtras(*params)) 145 | } 146 | 147 | /** 148 | * Fragment跳转,同[Activity.startActivity] 149 | * 示例: 150 | *
151 |  *      //不携带参数
152 |  *      startActivity(this, TestActivity::class)
153 |  *
154 |  *      //携带参数(可连续多个键值对)
155 |  *     startActivity(
156 |  *         TestActivity::class,
157 |  *         "Key1" to "Value",
158 |  *         "Key2" to 123
159 |  *     )
160 |  *  
161 | * 162 | * @param target 要启动的Activity 163 | * @param params extras键值对 164 | */ 165 | fun Activity.startActivity( 166 | target: KClass, vararg params: Pair 167 | ) = startActivity(Intent(this, target.java).putExtras(*params)) 168 | 169 | fun Fragment.startActivity( 170 | target: KClass, vararg params: Pair 171 | ) = activity?.run { 172 | startActivity(Intent(this, target.java).putExtras(*params)) 173 | } 174 | 175 | fun androidx.fragment.app.Fragment.startActivity( 176 | target: KClass, vararg params: Pair 177 | ) = activity?.run { 178 | startActivity(Intent(this, target.java).putExtras(*params)) 179 | } 180 | 181 | /** 182 | * 作用同上,以下三个方法为了兼容Java Class 183 | */ 184 | fun Activity.startActivity( 185 | target: Class, vararg params: Pair 186 | ) = startActivity(Intent(this, target).putExtras(*params)) 187 | 188 | fun Fragment.startActivity( 189 | target: Class, vararg params: Pair 190 | ) = activity?.run { 191 | startActivity(Intent(this, target).putExtras(*params)) 192 | } 193 | 194 | fun androidx.fragment.app.Fragment.startActivity( 195 | target: Class, vararg params: Pair 196 | ) = activity?.run { 197 | startActivity(Intent(this, target).putExtras(*params)) 198 | } 199 | 200 | /** 201 | * 作用同[Activity.startActivityForResult] 202 | * 示例: 203 | *
204 |  *      //不携带参数
205 |  *      startActivityForResult {
206 |  *          if (it == null) {
207 |  *              //未成功处理,即(ResultCode != RESULT_OK)
208 |  *          } else {
209 |  *              //处理成功,这里可以操作返回的intent
210 |  *          }
211 |  *      }
212 |  *  
213 | * 携带参数同[startActivity] 214 | * 215 | * @param TARGET 要启动的Activity 216 | * @param params extras键值对 217 | * @param callback onActivityResult的回调 218 | */ 219 | inline fun Activity.startActivityForResult( 220 | vararg params: Pair, crossinline callback: ((result: Intent?) -> Unit) 221 | ) = startActivityForResult(TARGET::class, *params, callback = callback) 222 | 223 | inline fun Fragment.startActivityForResult( 224 | vararg params: Pair, crossinline callback: ((result: Intent?) -> Unit) 225 | ) = activity?.startActivityForResult(TARGET::class, *params, callback = callback) 226 | 227 | inline fun androidx.fragment.app.Fragment.startActivityForResult( 228 | vararg params: Pair, crossinline callback: ((result: Intent?) -> Unit) 229 | ) = activity?.startActivityForResult(TARGET::class, *params, callback = callback) 230 | 231 | /** 232 | * 作用同[Activity.startActivityForResult] 233 | * 示例: 234 | *
235 |  *      //不携带参数
236 |  *      startActivityForResult {resultCode, result->
237 |  *          if (resultCode == RESULT_OK) {
238 |  *              //处理成功,这里可以操作返回的intent
239 |  *          } else {
240 |  *             //未成功处理
241 |  *          }
242 |  *      }
243 |  *  
244 | * 携带参数同[startActivity] 245 | * 246 | * @param TARGET 要启动的Activity 247 | * @param params extras键值对 248 | * @param callback onActivityResult的回调 249 | */ 250 | inline fun Activity.startActivityForResult2( 251 | vararg params: Pair, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 252 | ) = startActivityForResult2(TARGET::class, *params, callback = callback) 253 | 254 | inline fun Fragment.startActivityForResult2( 255 | vararg params: Pair, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 256 | ) = activity?.startActivityForResult2(TARGET::class, *params, callback = callback) 257 | 258 | inline fun androidx.fragment.app.Fragment.startActivityForResult2( 259 | vararg params: Pair, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 260 | ) = activity?.startActivityForResult2(TARGET::class, *params, callback = callback) 261 | 262 | /** 263 | * 作用同[Activity.startActivityForResult] 264 | * 示例: 265 | *
266 |  *      //不携带参数
267 |  *      startActivityForResult(this, TestActivity::class) {
268 |  *          if (it == null) {
269 |  *              //未成功处理,即(ResultCode != RESULT_OK)
270 |  *          } else {
271 |  *              //处理成功,这里可以操作返回的intent
272 |  *          }
273 |  *      }
274 |  *  
275 | * 携带参数同[startActivity] 276 | * 277 | * @param target 要启动的Activity 278 | * @param params extras键值对 279 | * @param callback onActivityResult的回调 280 | */ 281 | inline fun Activity.startActivityForResult( 282 | target: KClass, vararg params: Pair, 283 | crossinline callback: ((result: Intent?) -> Unit) 284 | ) = ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 285 | 286 | inline fun Fragment.startActivityForResult( 287 | target: KClass, vararg params: Pair, 288 | crossinline callback: ((result: Intent?) -> Unit) 289 | ) = activity?.run { 290 | ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 291 | } 292 | 293 | inline fun androidx.fragment.app.Fragment.startActivityForResult( 294 | target: KClass, vararg params: Pair, 295 | crossinline callback: ((result: Intent?) -> Unit) 296 | ) = activity?.run { 297 | ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 298 | } 299 | 300 | /** 301 | * 作用同上,以下三个方法为了兼容Java Class 302 | */ 303 | inline fun Activity.startActivityForResult( 304 | target: Class, vararg params: Pair, 305 | crossinline callback: ((result: Intent?) -> Unit) 306 | ) = ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 307 | 308 | inline fun Fragment.startActivityForResult( 309 | target: Class, vararg params: Pair, 310 | crossinline callback: ((result: Intent?) -> Unit) 311 | ) = activity?.run { 312 | ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 313 | } 314 | 315 | inline fun androidx.fragment.app.Fragment.startActivityForResult( 316 | target: Class, vararg params: Pair, 317 | crossinline callback: ((result: Intent?) -> Unit) 318 | ) = activity?.run { 319 | ActivityMessenger.startActivityForResult(this, target, *params, callback = callback) 320 | } 321 | 322 | /** 323 | * 作用同[Activity.startActivityForResult] 324 | * 示例: 325 | *
326 |  *      //不携带参数
327 |  *      startActivityForResult(this, TestActivity::class) {resultCode, result->
328 |  *          if (resultCode == RESULT_OK) {
329 |  *              //处理成功,这里可以操作返回的intent
330 |  *          } else {
331 |  *             //未成功处理
332 |  *          }
333 |  *      }
334 |  *  
335 | * 携带参数同[startActivity] 336 | * 337 | * @param target 要启动的Activity 338 | * @param params extras键值对 339 | * @param callback onActivityResult的回调 340 | */ 341 | inline fun Activity.startActivityForResult2( 342 | target: KClass, vararg params: Pair, 343 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 344 | ) = ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 345 | 346 | inline fun Fragment.startActivityForResult2( 347 | target: KClass, vararg params: Pair, 348 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 349 | ) = activity?.run { 350 | ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 351 | } 352 | 353 | inline fun androidx.fragment.app.Fragment.startActivityForResult2( 354 | target: KClass, vararg params: Pair, 355 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 356 | ) = activity?.run { 357 | ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 358 | } 359 | 360 | /** 361 | * 作用同上,以下三个方法为了兼容Java Class 362 | */ 363 | inline fun Activity.startActivityForResult2( 364 | target: Class, vararg params: Pair, 365 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 366 | ) = ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 367 | 368 | inline fun Fragment.startActivityForResult2( 369 | target: Class, vararg params: Pair, 370 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 371 | ) = activity?.run { 372 | ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 373 | } 374 | 375 | inline fun androidx.fragment.app.Fragment.startActivityForResult2( 376 | target: Class, vararg params: Pair, 377 | crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 378 | ) = activity?.run { 379 | ActivityMessenger.startActivityForResult2(this, target, *params, callback = callback) 380 | } 381 | 382 | /** 383 | * 作用同[Activity.startActivityForResult] 384 | * 385 | * @param intent intent 386 | * @param callback onActivityResult的回调 387 | */ 388 | inline fun Activity?.startActivityForResult( 389 | intent: Intent, crossinline callback: ((result: Intent?) -> Unit) 390 | ) = this?.run { 391 | ActivityMessenger.startActivityForResult(this, intent, callback) 392 | } 393 | 394 | inline fun Fragment.startActivityForResult( 395 | intent: Intent, crossinline callback: ((result: Intent?) -> Unit) 396 | ) = activity?.run { 397 | ActivityMessenger.startActivityForResult(this, intent, callback) 398 | } 399 | 400 | inline fun androidx.fragment.app.Fragment.startActivityForResult( 401 | intent: Intent, crossinline callback: ((result: Intent?) -> Unit) 402 | ) = activity?.run { 403 | ActivityMessenger.startActivityForResult(this, intent, callback) 404 | } 405 | 406 | inline fun Activity?.startActivityForResult2( 407 | intent: Intent, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 408 | ) = this?.run { 409 | ActivityMessenger.startActivityForResult2(this, intent, callback) 410 | } 411 | 412 | inline fun Fragment.startActivityForResult2( 413 | intent: Intent, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 414 | ) = activity?.run { 415 | ActivityMessenger.startActivityForResult2(this, intent, callback) 416 | } 417 | 418 | inline fun androidx.fragment.app.Fragment.startActivityForResult2( 419 | intent: Intent, crossinline callback: ((resultCode: Int, result: Intent?) -> Unit) 420 | ) = activity?.run { 421 | ActivityMessenger.startActivityForResult2(this, intent, callback) 422 | } 423 | 424 | /** 425 | * 作用同[Activity.finish] 426 | * 示例: 427 | *
428 |  *      finish(this, "Key" to "Value")
429 |  *  
430 | * 431 | * @param params extras键值对 432 | */ 433 | fun Activity.finish(vararg params: Pair) = run { 434 | setResult(Activity.RESULT_OK, Intent().putExtras(*params)) 435 | finish() 436 | } 437 | 438 | fun Activity.finish(intent: Intent) = run { 439 | setResult(Activity.RESULT_OK, intent) 440 | finish() 441 | } 442 | 443 | /** 444 | * String转Intent对象 445 | * 446 | * 示例: 447 | *
448 |  *      val action = "android.media.action.IMAGE_CAPTURE"
449 |  *      val intent = action.toIntent()
450 |  *  
451 | * 452 | * @param flags [Intent.setFlags] 453 | */ 454 | fun String.toIntent(flags: Int = 0): Intent = Intent(this).setFlags(flags) 455 | 456 | /** 457 | * 可空对象转非空对象 458 | */ 459 | inline fun O?.runIfNonNull(block: (O) -> Unit) { 460 | this?.let { block(it) } 461 | } 462 | 463 | /** 464 | * 不报错执行 465 | */ 466 | inline fun T.runSafely(block: (T) -> R) = try { 467 | block(this) 468 | } catch (e: Exception) { 469 | e.printStackTrace() 470 | null 471 | } 472 | 473 | internal object IntentFieldMethod { 474 | private val bundleClass = 475 | (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) BaseBundle::class else Bundle::class).java 476 | 477 | private val mExtras: Field? by lazy { 478 | Intent::class.java.getDeclaredField("mExtras").also { it.isAccessible = true } 479 | } 480 | 481 | private val mMap: Field? by lazy { 482 | runSafely { 483 | bundleClass.getDeclaredField("mMap").also { 484 | it.isAccessible = true 485 | } 486 | } 487 | } 488 | 489 | private val unparcel: Method? by lazy { 490 | runSafely { 491 | bundleClass.getDeclaredMethod("unparcel").also { 492 | it.isAccessible = true 493 | } 494 | } 495 | } 496 | 497 | internal fun Intent.internalMap() = runSafely { 498 | mMap?.get((mExtras?.get(this) as? Bundle).also { 499 | it?.run { unparcel?.invoke(this) } 500 | }) as? java.util.Map 501 | } 502 | 503 | internal fun Bundle.internalMap() = runSafely { 504 | unparcel?.invoke(it) 505 | mMap?.get(it) as? java.util.Map 506 | } 507 | } -------------------------------------------------------------------------------- /activitymessenger/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ActivityMessenger 3 | 4 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.72' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.6.3' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' 13 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # Kotlin code style for this project: "official" or "obsolete": 15 | kotlin.code.style=official 16 | android.useAndroidX=true 17 | android.enableJetifier=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ifxcyr/ActivityMessenger/2c190581329c6164ba2264a3bd92fe7892f0dd38/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 28 11:40:38 CST 2020 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-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':activitymessenger' 2 | --------------------------------------------------------------------------------