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 |
--------------------------------------------------------------------------------