├── start_up
├── consumer-rules.pro
├── .gitignore
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jccppp
│ │ │ │ └── start
│ │ │ │ ├── jk
│ │ │ │ ├── IAcBaseCallBack.java
│ │ │ │ ├── ConditionalJumpLogin.java
│ │ │ │ ├── IOnLoginNext.java
│ │ │ │ ├── StartForResult.java
│ │ │ │ └── IAcCallBack.kt
│ │ │ │ ├── LaunchUtil.kt
│ │ │ │ ├── config
│ │ │ │ └── LaunchAcConfig.kt
│ │ │ │ ├── AcCallBackHelper.kt
│ │ │ │ ├── ArgumentProperty.kt
│ │ │ │ └── LaunchExt.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jccppp
│ │ │ └── start
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jccppp
│ │ └── start
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── misc.xml
├── gradle.xml
└── jarRepositories.xml
├── settings.gradle
├── app
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_login.xml
│ │ │ │ ├── activity_one.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jcppp
│ │ │ │ └── launchac
│ │ │ │ ├── LoginActivity.kt
│ │ │ │ ├── MyApplication.kt
│ │ │ │ ├── OneActivity.kt
│ │ │ │ ├── LoginFragHelper.kt
│ │ │ │ ├── MyApplication2.java
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jcppp
│ │ │ └── launchac
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jcppp
│ │ └── launchac
│ │ └── ExampleInstrumentedTest.kt
├── .gitignore
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/start_up/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 |
2 | rootProject.name = "LaunchAc"
3 | include ':app'
4 | include ':start_up'
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LaunchAc
3 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .gradle
3 | build.gradle
4 | *.iml
5 | .idea
6 | *.apk
7 | /local.properties
8 | .DS_Store
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/start_up/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | .gradle
3 | build.gradle
4 | *.iml
5 | .idea
6 | *.apk
7 | /local.properties
8 | .DS_Store
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jccppp/LaunchAc/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/jk/IAcBaseCallBack.java:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.jk;
2 |
3 | public interface IAcBaseCallBack {
4 |
5 | void invoke(T t);
6 | }
7 |
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/jk/ConditionalJumpLogin.java:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.jk;
2 |
3 | public interface ConditionalJumpLogin {
4 |
5 | boolean jump(boolean isLogin);
6 | }
7 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/start_up/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/jk/IOnLoginNext.java:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.jk;
2 |
3 | /**
4 | * @Author :zwz
5 | * @Date : 2022/11/2 17:05
6 | * @Description : 描述
7 | */
8 | public interface IOnLoginNext {
9 |
10 | void isLogin();
11 | }
12 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 06 21:52:34 CST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/jk/StartForResult.java:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.jk;
2 |
3 | import android.content.Intent;
4 |
5 | import org.jetbrains.annotations.Nullable;
6 |
7 | public interface StartForResult {
8 |
9 | void result(int code, @Nullable Intent data);
10 | }
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jcppp/launchac/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/start_up/src/test/java/com/jccppp/start/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/LoginActivity.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import androidx.appcompat.app.AppCompatActivity
6 |
7 | class LoginActivity : AppCompatActivity() {
8 |
9 | companion object {
10 | var isLogin = false
11 | }
12 |
13 | override fun onCreate(savedInstanceState: Bundle?) {
14 | super.onCreate(savedInstanceState)
15 | setContentView(R.layout.activity_login)
16 |
17 | findViewById(R.id.view).setOnClickListener {
18 | isLogin = true
19 | setResult(RESULT_OK)
20 | finish()
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/jk/IAcCallBack.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.jk
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.Intent
6 | import androidx.activity.result.ActivityResultLauncher
7 | import androidx.lifecycle.LifecycleOwner
8 | import java.util.concurrent.LinkedBlockingDeque
9 |
10 | /**
11 | * @Author :zwz
12 | * @Date : 2021/11/25 19:21
13 | * @Description : 描述
14 | */
15 | interface IAcCallBack {
16 |
17 | fun getResultDeque(): LinkedBlockingDeque
18 |
19 | fun getResultLauncher(): ActivityResultLauncher
20 |
21 | fun Host.initAcCallBackHelper()
22 |
23 | fun getAcCallContext(): Context?
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_one.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jcppp/launchac/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jcppp.launchac", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/start_up/src/androidTest/java/com/jccppp/start/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.jccppp.start.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/start_up/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
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
21 |
22 |
--------------------------------------------------------------------------------
/start_up/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'org.jetbrains.kotlin.android'
4 | //id 'com.github.dcendents.android-maven'
5 | }
6 | group = 'com.github.jccppp'
7 |
8 | android {
9 | compileSdk 32
10 |
11 | defaultConfig {
12 | minSdk 16
13 | targetSdk 32
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles "consumer-rules.pro"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | kotlinOptions {
30 | jvmTarget = '1.8'
31 | }
32 | }
33 |
34 | dependencies {
35 |
36 | implementation 'androidx.appcompat:appcompat:1.4.2'
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/MyApplication.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import android.app.Application
4 | import android.content.Intent
5 | import com.jccppp.start.LaunchUtil
6 | import com.jccppp.start.config.LaunchAcConfig
7 |
8 | class MyApplication : Application() {
9 |
10 | override fun onCreate() {
11 | super.onCreate()
12 |
13 | /* LaunchUtil.init({
14 | LoginActivity.isLogin
15 | }, { ac, login ->
16 | LoginFragHelper.login(ac) {
17 | login.isLogin()
18 |
19 | }
20 | })*/
21 |
22 | LaunchUtil.init(LaunchAcConfig.create {
23 | copyGlobal(false).intent {
24 | it.putExtra("canShu", "11111")
25 | }
26 | }, {
27 | LoginActivity.isLogin
28 | }) { ac, login ->
29 | LoginFragHelper.login(ac) {
30 | if (it) //登陆成功
31 | login.isLogin()
32 | else {
33 | //登录失败
34 | }
35 | }
36 | }
37 |
38 | }
39 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
16 |
19 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/OneActivity.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import android.app.Activity
4 | import android.os.Bundle
5 | import android.view.View
6 | import android.widget.Toast
7 | import androidx.appcompat.app.AppCompatActivity
8 | import com.jccppp.start.argument
9 | import com.jccppp.start.argumentNullable
10 | import com.jccppp.start.launchAc
11 | import com.jccppp.start.setBack
12 |
13 | class OneActivity : Activity() {
14 |
15 | private var canShu by argumentNullable() //可空
16 | // private var canShu by argument("") // 不为空,如未传值则取默认值
17 | //等价 intent?.getStringExtra("canShu")
18 |
19 | // private var aaaa by argumentNullable("custom")
20 | private var aaaa by argument("","custom")
21 | //指定key为 "custom" 等价 intent?.getStringExtra("custom")
22 |
23 | override fun onCreate(savedInstanceState: Bundle?) {
24 | super.onCreate(savedInstanceState)
25 | setContentView(R.layout.activity_one)
26 |
27 | if (!canShu.isNullOrEmpty())
28 | Toast.makeText(this, "上个页面传值$canShu", Toast.LENGTH_LONG).show()
29 |
30 | findViewById(R.id.view).setOnClickListener {
31 | setBack("data" to "哈哈啊哈")
32 | }
33 |
34 |
35 | //可以二次赋值
36 | canShu = ""
37 | }
38 | }
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/LaunchUtil.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import androidx.fragment.app.FragmentActivity
6 | import com.jccppp.start.config.LaunchAcConfig
7 | import com.jccppp.start.jk.IOnLoginNext
8 |
9 | /**
10 | * @Author :zwz
11 | * @Date : 2022/6/7 9:40
12 | * @Description : 描述
13 | */
14 | object LaunchUtil {
15 |
16 | private var config: LaunchAcConfig? = null
17 | private var isLogin: (() -> Boolean)? = null
18 | private var startLogin: ((Context, IOnLoginNext) -> Unit)? = null
19 |
20 | @JvmStatic
21 | fun init(
22 | isLogin: () -> Boolean,
23 | startLogin: (Context, IOnLoginNext) -> Unit
24 | ) {
25 | init(null, isLogin, startLogin)
26 | }
27 |
28 | @JvmStatic
29 | fun init(
30 | config: LaunchAcConfig?,
31 | isLogin: () -> Boolean, //是否登录
32 | startLogin: (Context, IOnLoginNext) -> Unit //未登录唤起登录
33 | ) {
34 | this.config = config
35 | this.isLogin = isLogin
36 | this.startLogin = startLogin
37 |
38 | }
39 |
40 | fun getConfig() = config
41 |
42 | fun getIsLogin(): Boolean {
43 | if (isLogin == null) return true
44 | return isLogin!!.invoke()
45 | }
46 |
47 | fun getStartLogin(ac: Context, next: IOnLoginNext) {
48 | startLogin?.invoke(ac, next)
49 | }
50 | }
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | compileSdk 32
8 |
9 | defaultConfig {
10 | applicationId "com.jcppp.launchac"
11 | minSdk 21
12 | targetSdk 32
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | kotlinOptions {
30 | jvmTarget = '1.8'
31 | }
32 | }
33 |
34 | dependencies {
35 |
36 | implementation 'androidx.core:core-ktx:1.7.0'
37 | implementation 'androidx.appcompat:appcompat:1.3.0'
38 | implementation 'com.google.android.material:material:1.4.0'
39 | implementation project(':start_up')
40 | // implementation 'com.github.jccppp:launchac:0.0.1'
41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
42 | testImplementation 'junit:junit:4.13.2'
43 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
44 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45 | }
--------------------------------------------------------------------------------
/.idea/jarRepositories.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 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/LoginFragHelper.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.FragmentActivity
9 | import com.jccppp.start.AcCallBackHelper
10 | import com.jccppp.start.jk.IAcCallBack
11 | import com.jccppp.start.launchAc
12 |
13 | class LoginFragHelper : Fragment(), IAcCallBack by AcCallBackHelper() {
14 |
15 | companion object {
16 |
17 | private val TAG = "LoginFragHelper"
18 |
19 | fun login(activity: Context, call: ((Boolean) -> Unit)) {
20 | if (activity is FragmentActivity) {
21 | val supportFragmentManager = activity.supportFragmentManager
22 | val findFragment = supportFragmentManager.findFragmentByTag(TAG)
23 |
24 | if (findFragment is LoginFragHelper) {
25 | findFragment.call = call
26 | findFragment.goLogo()
27 | } else {
28 | supportFragmentManager.beginTransaction()
29 | .add(LoginFragHelper().also { it.call = call }, TAG)
30 | .commitAllowingStateLoss()
31 | }
32 | }
33 | }
34 |
35 | }
36 |
37 | var call: ((Boolean) -> Unit)? = null
38 |
39 | override fun onCreate(savedInstanceState: Bundle?) {
40 | super.onCreate(savedInstanceState)
41 | initAcCallBackHelper()
42 | goLogo()
43 |
44 | }
45 |
46 | fun goLogo() {
47 | launchAc() {
48 | result { code, data ->
49 | call?.invoke(code == AppCompatActivity.RESULT_OK)
50 | parentFragmentManager.beginTransaction().remove(this@LoginFragHelper)
51 | .commitAllowingStateLoss()
52 | }
53 | }
54 |
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/config/LaunchAcConfig.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start.config
2 |
3 | import android.content.Intent
4 | import com.jccppp.start.jk.ConditionalJumpLogin
5 | import com.jccppp.start.jk.IAcBaseCallBack
6 | import com.jccppp.start.jk.StartForResult
7 |
8 | class LaunchAcConfig private constructor(
9 | val withLogin: Boolean?,
10 | val result: StartForResult?,
11 | val condition: ConditionalJumpLogin?,
12 | val intent: IAcBaseCallBack?,
13 | val copyGlobal: Boolean,
14 | ) {
15 |
16 | companion object {
17 | @JvmStatic
18 | fun create(init: (Builder.() -> Unit)? = null): LaunchAcConfig {
19 | val builder = Builder()
20 | if (init != null)
21 | builder.init()
22 | return builder.build()
23 | }
24 | }
25 |
26 | constructor(builder: Builder) : this(
27 | builder.withLogin,
28 | builder.result,
29 | builder.condition,
30 | builder.intent,
31 | builder.copyGlobal,
32 | )
33 |
34 | class Builder {
35 | var withLogin: Boolean? = null
36 | private set
37 | var result: ((Int,Intent?) -> Unit)? = null
38 | private set
39 | var condition: ((Boolean) -> Boolean)? = null
40 | private set
41 | var intent: ((Intent) -> Unit)? = null
42 | private set
43 | var copyGlobal: Boolean = false
44 | private set
45 |
46 |
47 | fun withLogin(withLogin: Boolean = true) = apply {
48 | this.withLogin = withLogin
49 | }
50 |
51 | fun result(result: (code:Int,result:Intent?) -> Unit) = apply {
52 | this.result = result
53 | }
54 |
55 | fun condition(condition: (isLogin:Boolean) -> Boolean) = apply {
56 | this.condition = condition
57 | }
58 |
59 | fun intent(intent: (intent:Intent)->Unit) = apply {
60 | this.intent = intent
61 | }
62 |
63 | fun copyGlobal(copyGlobal: Boolean ) = apply {
64 | this.copyGlobal = copyGlobal
65 | }
66 |
67 |
68 | fun build(): LaunchAcConfig {
69 |
70 | return LaunchAcConfig(this)
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/MyApplication2.java:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.content.Intent;
7 |
8 | import androidx.fragment.app.FragmentActivity;
9 |
10 | import com.jccppp.start.LaunchUtil;
11 | import com.jccppp.start.config.LaunchAcConfig;
12 | import com.jccppp.start.jk.IOnLoginNext;
13 |
14 | import kotlin.Unit;
15 | import kotlin.jvm.functions.Function0;
16 | import kotlin.jvm.functions.Function1;
17 | import kotlin.jvm.functions.Function2;
18 |
19 | public class MyApplication2 extends Application {
20 |
21 | @Override
22 | public void onCreate() {
23 | super.onCreate();
24 |
25 | LaunchUtil.init(LaunchAcConfig.create(new Function1() {
26 | @Override
27 | public Unit invoke(LaunchAcConfig.Builder builder) {
28 | builder.copyGlobal(true).intent(new Function1() {
29 | @Override
30 | public Unit invoke(Intent intent) {
31 | intent.putExtra("canShu","11111");
32 | return null;
33 | }
34 | }).result(new Function2() {
35 | @Override
36 | public Unit invoke(Integer integer, Intent intent) {
37 | return null;
38 | }
39 | });
40 |
41 | return null;
42 | }
43 | }), new Function0() {
44 | @Override
45 | public Boolean invoke() {
46 | return LoginActivity.Companion.isLogin();
47 | }
48 | }, new Function2() {
49 | @Override
50 | public Unit invoke(Context fragmentActivity, IOnLoginNext iOnLoginNext) {
51 | LoginFragHelper.Companion.login(fragmentActivity, new Function1() {
52 | @Override
53 | public Unit invoke(Boolean aBoolean) {
54 | iOnLoginNext.isLogin();
55 | return null;
56 | }
57 | });
58 | return null;
59 | }
60 | });
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jcppp/launchac/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.jcppp.launchac
2 |
3 | import android.os.Bundle
4 | import android.view.View
5 | import android.widget.Toast
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.fragment.app.FragmentActivity
8 | import com.jccppp.start.*
9 | import com.jccppp.start.jk.IAcCallBack
10 |
11 | class MainActivity : FragmentActivity(), IAcCallBack by AcCallBackHelper() {
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_main)
15 |
16 | initAcCallBackHelper()
17 |
18 | findViewById(R.id.tv1).setOnClickListener {
19 | launchAc()
20 | }
21 |
22 | findViewById(R.id.tv6).setOnClickListener {
23 | applicationContext.launchAc {
24 | copyGlobal(true)
25 | }
26 | }
27 |
28 |
29 | findViewById(R.id.tv2).setOnClickListener {
30 | launchAc("canShu" to "hello1", "custom" to "hello3") {
31 | copyGlobal(true)
32 | }
33 | }
34 | findViewById(R.id.tv3).setOnClickListener {
35 | launchAc() {
36 | withLogin()
37 | }
38 | }
39 | var index = 1
40 |
41 | findViewById(R.id.tv4).setOnClickListener {
42 | launchAc("canShu" to "hello2") {
43 | condition { isLogin ->
44 | val jump = index++ % 2 == 0
45 | if (!jump) Toast.makeText(
46 | this@MainActivity,
47 | "条件不符合跳转",
48 | Toast.LENGTH_LONG
49 | )
50 | .show()
51 | jump
52 | }
53 |
54 | }
55 |
56 | }
57 | findViewById(R.id.tv5).setOnClickListener {
58 |
59 | launchAc() {
60 | result { code, data ->
61 | if (code == RESULT_OK) Toast.makeText(
62 | this@MainActivity,
63 | "OneActivity页面传值${data?.getStringExtra("data")}",
64 | Toast.LENGTH_LONG
65 | ).show()
66 | }
67 | }
68 |
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
27 |
28 |
34 |
35 |
39 |
40 |
46 |
47 |
51 |
52 |
58 |
59 |
63 |
64 |
70 |
71 |
75 |
76 |
82 |
83 |
87 |
88 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | **一个帮助你简单启动Activity的框架,带登录判断,带参数携带**
3 |
4 | **原理基于Kotlin扩展函数**
5 |
6 | #### 请添加仓库地址
7 | ```
8 | maven { url 'https://jitpack.io' }
9 | ```
10 |
11 | ```
12 | implementation 'com.github.jccppp:launchac:1.4.0'
13 | ```
14 |
15 |
16 | ####开始使用
17 |
18 | **1、** 在Fragment or Activity 中启动一个新的Activity
19 |
20 | ```
21 | launchAc()
22 | ```
23 | **等价于**
24 |
25 | ```
26 | val intent = Intent(this,OneActivity::class.java)
27 |
28 | startActivity(intent)
29 | ```
30 |
31 |
32 | 跳转新Activity并携带参数
33 |
34 |
35 |
36 | ```
37 | launchAc("canShu" to "hello1", "custom" to 1)
38 | ```
39 | **等价于**
40 | ```
41 | val intent = Intent(this,OneActivity::class.java)
42 | intent.putExtra("canShu","hello1")
43 | intent.putExtra("custom",1)
44 | startActivity(intent)
45 | ```
46 | 在OneActivity接收参数可使用
47 | ```
48 | private var canShu by argumentNullable() 注: 变量名称必须与传参时的"canShu"一致
49 | ```
50 | 或者指定参数名
51 |
52 | ```
53 | private var aaaa by argument(1,"custom") 注:此时参数名就可以为aaaa或者随意,因为已指定key为"custom"
54 | ```
55 |
56 | 也可直接使用
57 | ```
58 | val custom = intent.getStringExtra("custom")
59 | ```
60 |
61 | **2、** 在Fragment or Activity 中启动一个新的Activity并且带回调。ps:就是以前的 onActivityResult
62 |
63 |
64 | 注意⚠️先 实现 IAcCallBack 接口并委托 AcCallBackHelper
65 |
66 |
67 |
68 |
69 |
70 | IAcCallBack by AcCallBackHelper()
71 | 并在onCreate时候调用 initAcCallBackHelper 方法
72 |
73 |
74 | ```
75 |
76 | launchAc() {
77 | result { code, data ->
78 | if (code == RESULT_OK) Toast.makeText(
79 | this@MainActivity,
80 | "OneActivity页面传值${data?.getStringExtra("data")}",
81 | Toast.LENGTH_LONG
82 | ).show()
83 | }
84 | }
85 | ```
86 | **等价于**
87 | ```
88 | val intent = Intent(this,OneActivity::class.java)
89 | startActivityForResult(intent,requestCode)
90 |
91 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
92 | super.onActivityResult(requestCode, resultCode, data)
93 | if(requestCode){
94 |
95 | }
96 | }
97 |
98 | ```
99 |
100 | ####进阶使用 使用场景
101 |
102 | 可使用判断是否符合已登录才可跳转的Activity,如我的用户信息界面等。
103 | 假设用户未登录并且想打开UserInfoActivity界面
104 | 点击跳转UserInfoActivity(未登录)->跳转登录界面->登录成功->自动跳转至UserInfoActivity界面
105 |
106 |
107 | **1、首先初始化下(建议在MyApplication的onCreate初始化,本框架不会获取任何隐私相关,只是单纯初始化,无合规风险,在此初始化可规避内存不足重建导致初始化失败问题)**
108 |
109 |
110 |
111 |
112 | * Kotlin代码
113 |
114 | ```
115 | LaunchUtil.init({
116 | LoginActivity.isLogin
117 | }, { ac, login ->
118 | LoginFragHelper.login(ac) {
119 | login.isLogin(it)
120 | }
121 | })
122 | ```
123 | 参数1、传入你判断是否登录
124 | ```
125 | {
126 | LoginActivity.isLogin //boolean类型
127 | }
128 | ```
129 | ```
130 | { ac, login ->
131 | //未登录条件触发 ac为发起的Acitivity的 可用来启动LoginActivity,login 调用 login.isLogin(boolean//传入是否登录成功)
132 | //看不懂请看 LoginFragHelper demo
133 | }
134 | ```
135 |
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/AcCallBackHelper.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import androidx.activity.result.ActivityResult
6 | import androidx.activity.result.ActivityResultCallback
7 | import androidx.activity.result.ActivityResultLauncher
8 | import androidx.activity.result.contract.ActivityResultContracts
9 | import androidx.fragment.app.Fragment
10 | import androidx.fragment.app.FragmentActivity
11 | import androidx.lifecycle.LifecycleOwner
12 | import androidx.savedstate.SavedStateRegistryOwner
13 | import com.jccppp.start.jk.IAcCallBack
14 | import com.jccppp.start.jk.StartForResult
15 | import java.util.*
16 | import java.util.concurrent.LinkedBlockingDeque
17 |
18 | /**
19 | * @Author :zwz
20 | * @Date : 2021/11/25 18:53
21 | * @Description : 描述
22 | */
23 | class AcCallBackHelper : IAcCallBack {
24 |
25 | private lateinit var startActivityResultDeque: LinkedBlockingDeque
26 | private lateinit var activityForResult: ActivityResultLauncher
27 |
28 | private var msaContext: FragmentActivity? = null
29 |
30 | companion object {
31 | private const val SAVE_STATE_KEY = "mas_save_state"
32 | private const val SAVE_STATE_BUNDLE_KEY = "mas_bundle_tag"
33 | private val msaResultSaveState =
34 | LinkedHashMap>()
35 |
36 | }
37 |
38 | private val activityResultCallback = object : ActivityResultCallback {
39 | override fun onActivityResult(result: ActivityResult?) {
40 | result ?: return
41 | startActivityResultDeque.pollFirst()?.result(result.resultCode, result.data)
42 | }
43 | }
44 |
45 |
46 | /**
47 | * {@inheritDoc}
48 | */
49 | override fun Host.initAcCallBackHelper() {
50 | when (this) {
51 | is FragmentActivity -> {
52 | msaContext = this
53 | startActivityResultDeque = bindHostSaveState() ?: LinkedBlockingDeque()
54 | activityForResult = registerForActivityResult(
55 | ActivityResultContracts.StartActivityForResult(),
56 | activityResultCallback
57 | )
58 | }
59 | is Fragment -> {
60 | msaContext = activity
61 | startActivityResultDeque = bindHostSaveState() ?: LinkedBlockingDeque()
62 | activityForResult = registerForActivityResult(
63 | ActivityResultContracts.StartActivityForResult(),
64 | activityResultCallback
65 | )
66 | }
67 | }
68 | }
69 |
70 | override fun getAcCallContext() = msaContext
71 |
72 | private fun SavedStateRegistryOwner.bindHostSaveState(): LinkedBlockingDeque? {
73 | val saveStateKey = savedStateRegistry.consumeRestoredStateForKey(SAVE_STATE_KEY)
74 | ?.getString(SAVE_STATE_BUNDLE_KEY) ?: UUID.randomUUID().toString()
75 |
76 | savedStateRegistry.registerSavedStateProvider(SAVE_STATE_KEY) {
77 | Bundle().apply {
78 | if (::startActivityResultDeque.isInitialized) {
79 | msaResultSaveState[saveStateKey] = startActivityResultDeque
80 | putString(SAVE_STATE_BUNDLE_KEY, saveStateKey)
81 | }
82 | }
83 | }
84 |
85 | return msaResultSaveState.remove(saveStateKey)
86 | }
87 |
88 | override fun getResultDeque() = startActivityResultDeque
89 |
90 | override fun getResultLauncher() = activityForResult
91 |
92 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/ArgumentProperty.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import android.app.Activity
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.os.Parcelable
7 | import androidx.fragment.app.Fragment
8 | import java.io.Serializable
9 | import kotlin.properties.ReadWriteProperty
10 | import kotlin.reflect.KProperty
11 |
12 |
13 | fun Fragment.argumentNullable(setKey: String? = null) =
14 | FragmentArgumentPropertyNullable(setKey)
15 |
16 | fun Fragment.argument(defaultValue: T? = null, setKey: String? = null) =
17 | FragmentArgumentProperty(defaultValue, setKey)
18 |
19 | fun Activity.argumentNullable(setKey: String? = null) =
20 | ActivityArgumentDelegateNullable(setKey)
21 |
22 | fun Activity.argument(defaultValue: T? = null, setKey: String? = null) =
23 | ActivityArgumentProperty(defaultValue, setKey)
24 |
25 |
26 | class FragmentArgumentProperty(
27 | private val defaultValue: T? = null,
28 | private val setKey: String?
29 | ) :
30 | ReadWriteProperty {
31 |
32 | var value: T? = null
33 |
34 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T {
35 | return value ?: thisRef.arguments?.getValue(setKey ?: property.name).also { value = it }
36 | ?: defaultValue
37 | ?: throw IllegalStateException("Property ${property.name} could not be read")
38 | }
39 |
40 | override fun setValue(thisRef: Fragment, property: KProperty<*>, value: T) {
41 | this.value = value
42 | }
43 | }
44 |
45 | class FragmentArgumentPropertyNullable(private val setKey: String?) :
46 | ReadWriteProperty {
47 |
48 | var value: T? = null
49 |
50 | override fun getValue(thisRef: Fragment, property: KProperty<*>): T? {
51 | return value ?: thisRef.arguments?.getValue(setKey ?: property.name).also { value = it }
52 | }
53 |
54 | override fun setValue(thisRef: Fragment, property: KProperty<*>, value: T?) {
55 | this.value = value
56 | }
57 | }
58 |
59 | // --------------------------------------------------------------------------------------
60 | // Activity
61 | // --------------------------------------------------------------------------------------
62 |
63 | class ActivityArgumentProperty(private val defaultValue: T?, private val setKey: String?) :
64 | ReadWriteProperty {
65 |
66 | var value: T? = null
67 |
68 | override fun getValue(thisRef: Activity, property: KProperty<*>): T {
69 | return value ?: (thisRef.intent?.extras?.getValue(setKey ?: property.name) as? T).also {
70 | value = it
71 | } ?: defaultValue
72 | ?: throw IllegalStateException("Property ${property.name} could not be read")
73 | }
74 |
75 | override fun setValue(thisRef: Activity, property: KProperty<*>, value: T) {
76 | this.value = value
77 | }
78 | }
79 |
80 | class ActivityArgumentDelegateNullable(private val setKey: String?) :
81 | ReadWriteProperty {
82 |
83 | var value: T? = null
84 |
85 | override fun getValue(thisRef: Activity, property: KProperty<*>): T? {
86 | return value ?: thisRef.intent?.extras?.getValue(setKey ?: property.name).also {
87 | value = it
88 | }
89 | }
90 |
91 | override fun setValue(thisRef: Activity, property: KProperty<*>, value: T?) {
92 | "" to 1
93 | this.value = value
94 | }
95 | }
96 |
97 | // --------------------------------------------------------------------------------------
98 |
99 | operator fun Bundle.set(key: String, value: T?) {
100 | if (value != null)
101 | when (value) {
102 | is Boolean -> putBoolean(key, value)
103 | is Byte -> putByte(key, value)
104 | is Char -> putChar(key, value)
105 | is Short -> putShort(key, value)
106 | is Int -> putInt(key, value)
107 | is Long -> putLong(key, value)
108 | is Float -> putFloat(key, value)
109 | is Double -> putDouble(key, value)
110 | is String -> putString(key, value)
111 | is CharSequence -> putCharSequence(key, value)
112 | is Serializable -> putSerializable(key, value) // also ArrayList
113 | is Parcelable -> putParcelable(key, value)
114 | is Bundle -> putBundle(key, value)
115 | is BooleanArray -> putBooleanArray(key, value)
116 | is ByteArray -> putByteArray(key, value)
117 | is CharArray -> putCharArray(key, value)
118 | is ShortArray -> putShortArray(key, value)
119 | is IntArray -> putIntArray(key, value)
120 | is LongArray -> putLongArray(key, value)
121 | is FloatArray -> putFloatArray(key, value)
122 | is DoubleArray -> putDoubleArray(key, value)
123 | is ArrayList<*> -> throw IllegalStateException("ArrayList<*> $key is not supported")
124 | is Array<*> -> throw IllegalStateException("Array<*> $key is not supported")
125 | else -> throw IllegalStateException("Type $key is not supported")
126 | }
127 | }
128 |
129 | fun Bundle.getValue(key: String): T? {
130 | @Suppress("UNCHECKED_CAST")
131 | return get(key) as? T?
132 | }
133 |
134 | operator fun Intent.set(key: String, value: T?) {
135 | when (value) {
136 | is Boolean? -> putExtra(key, value)
137 | is Byte? -> putExtra(key, value)
138 | is Char? -> putExtra(key, value)
139 | is Short? -> putExtra(key, value)
140 | is Int? -> putExtra(key, value)
141 | is Long? -> putExtra(key, value)
142 | is Float? -> putExtra(key, value)
143 | is Double? -> putExtra(key, value)
144 | is String? -> putExtra(key, value)
145 | is CharSequence? -> putExtra(key, value)
146 | is Serializable? -> putExtra(key, value)
147 | is Parcelable? -> putExtra(key, value)
148 | is Bundle? -> putExtra(key, value)
149 | is BooleanArray? -> putExtra(key, value)
150 | is ByteArray? -> putExtra(key, value)
151 | is CharArray? -> putExtra(key, value)
152 | is ShortArray? -> putExtra(key, value)
153 | is IntArray? -> putExtra(key, value)
154 | is LongArray? -> putExtra(key, value)
155 | is FloatArray? -> putExtra(key, value)
156 | is DoubleArray? -> putExtra(key, value)
157 | is ArrayList<*>? -> throw IllegalStateException("ArrayList<*> $key is not supported")
158 | is Array<*>? -> throw IllegalStateException("Array<*> $key is not supported")
159 | else -> throw IllegalStateException("Type $key is not supported")
160 | }
161 | }
--------------------------------------------------------------------------------
/start_up/src/main/java/com/jccppp/start/LaunchExt.kt:
--------------------------------------------------------------------------------
1 | package com.jccppp.start
2 |
3 | import android.app.Activity
4 | import android.app.Application
5 | import android.content.Context
6 | import android.content.Intent
7 | import android.os.Bundle
8 | import androidx.fragment.app.Fragment
9 | import com.jccppp.start.config.LaunchAcConfig
10 | import com.jccppp.start.jk.IAcBaseCallBack
11 | import com.jccppp.start.jk.IAcCallBack
12 | import com.jccppp.start.jk.IOnLoginNext
13 | import com.jccppp.start.jk.StartForResult
14 |
15 |
16 | inline fun Activity.launchAc(
17 | vararg parameter: Pair,
18 | noinline builder: (LaunchAcConfig.Builder.() -> Unit)? = null
19 | ) {
20 |
21 | val javaClass: Class<*> = AC::class.java
22 |
23 | var create: LaunchAcConfig? = null
24 |
25 | if (builder != null) {
26 | create = LaunchAcConfig.create(builder)
27 | }
28 |
29 | insideStartUpActivityWithLoginForResult(javaClass, this, create, parameter = parameter)
30 | }
31 |
32 |
33 | inline fun Fragment.launchAc(
34 | vararg parameter: Pair,
35 | noinline builder: (LaunchAcConfig.Builder.() -> Unit)? = null
36 | ) {
37 |
38 | val javaClass: Class<*> = AC::class.java
39 |
40 | var create: LaunchAcConfig? = null
41 |
42 | if (builder != null) {
43 | create = LaunchAcConfig.create(builder)
44 | }
45 |
46 | insideStartUpActivityWithLoginForResult(javaClass, this, create, parameter = parameter)
47 |
48 | }
49 |
50 | inline fun Context.launchAc(
51 | vararg parameter: Pair,
52 | noinline builder: (LaunchAcConfig.Builder.() -> Unit)? = null
53 | ) {
54 |
55 | val javaClass: Class<*> = AC::class.java
56 |
57 | var create: LaunchAcConfig? = null
58 |
59 | if (builder != null) {
60 | create = LaunchAcConfig.create(builder)
61 | }
62 |
63 | insideStartUpActivityWithLoginForResult(javaClass, this, create, parameter = parameter)
64 |
65 | }
66 |
67 |
68 |
69 | //外部就不要调佣这个了,除非没有符合条件的
70 | fun insideStartUpActivityWithLoginForResult(
71 | javaClass: Class<*>,
72 | any: Any,
73 | mConfig: LaunchAcConfig?,
74 | vararg parameter: Pair,
75 | ) {
76 |
77 | val globalConfig = LaunchUtil.getConfig()
78 |
79 | val copy = (mConfig?.copyGlobal ?: globalConfig?.copyGlobal) == true
80 |
81 | val withLogin = mConfig?.withLogin ?: if (copy) globalConfig?.withLogin else null
82 |
83 | val isLogin = LaunchUtil.getIsLogin()
84 |
85 | val stop = (mConfig?.condition ?: if (copy) globalConfig?.condition else null)?.jump(
86 | isLogin
87 | ) == false
88 |
89 | val intent = mConfig?.intent ?: if (copy) globalConfig?.intent else null
90 |
91 | val result = mConfig?.result ?: if (copy) globalConfig?.result else null
92 |
93 | if (stop) {
94 | return
95 | }
96 |
97 | if (withLogin == true) {
98 | if (isLogin) {
99 | _jump(any, javaClass, intent, result, parameter = parameter)
100 | } else {
101 | val ac: Context? =
102 | if (any is Activity) {
103 | any
104 | } else if (any is Fragment) {
105 | any.requireActivity()
106 | } else if (any is IAcCallBack) {
107 | any.getAcCallContext()!!
108 | } else if (any is Context) {
109 | any
110 | } else null
111 |
112 | val onNext = IOnLoginNext {
113 | _jump(
114 | any,
115 | javaClass,
116 | intent,
117 | result,
118 | parameter = parameter
119 | )
120 | }
121 |
122 | if (ac != null) {
123 | LaunchUtil.getStartLogin(ac, onNext)
124 | } else {
125 | onNext.isLogin()
126 | }
127 |
128 | }
129 |
130 | } else {
131 | _jump(any, javaClass, intent, result, parameter = parameter)
132 | }
133 |
134 |
135 | }
136 |
137 | private fun _jump(
138 | any: Any,
139 | javaClass: Class<*>,
140 | intent: IAcBaseCallBack?,
141 | result: StartForResult?,
142 | vararg parameter: Pair
143 | ) {
144 | if (any is IAcCallBack) {
145 | any._jump(javaClass, intent, result, parameter = parameter)
146 | } else if (any is Fragment) {
147 | any._jump(javaClass, intent, parameter = parameter)
148 | } else if (any is Context) {
149 | any._jump(javaClass, intent, parameter = parameter)
150 | }
151 |
152 | }
153 |
154 | private fun Fragment._jump(
155 | javaClass: Class<*>,
156 | intent: IAcBaseCallBack?,
157 | vararg parameter: Pair,
158 | ) {
159 |
160 | requireActivity()._jump(javaClass, intent, parameter = parameter)
161 |
162 | }
163 |
164 | private fun Context._jump(
165 | javaClass: Class<*>,
166 | intent: IAcBaseCallBack?,
167 | vararg parameter: Pair,
168 | ) {
169 | startActivity(Intent(this, javaClass).also { i ->
170 | intent?.invoke(i)
171 | i.add(*parameter)
172 | if (this is Application) {
173 | i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
174 | }
175 | })
176 | }
177 |
178 |
179 | private fun IAcCallBack._jump(
180 | javaClass: Class<*>,
181 | intent: IAcBaseCallBack?,
182 | result: StartForResult?,
183 | vararg parameter: Pair,
184 | ) {
185 |
186 | if (result != null) {
187 | getResultDeque().offerFirst(result)
188 | getAcCallContext()?.let {
189 | getResultLauncher().launch(Intent(it, javaClass).also { i ->
190 | intent?.invoke(i)
191 | i.add(*parameter)
192 | })
193 | }
194 | } else {
195 | getAcCallContext()?.let {
196 | it._jump(javaClass, intent, parameter = parameter)
197 | }
198 | }
199 | }
200 |
201 | //设置bundle
202 | fun T.setBundle(
203 | vararg parameter: Pair,
204 | control: ((Bundle) -> Unit)? = null
205 | ): T = apply {
206 | arguments = Bundle().apply {
207 | parameter.forEach {
208 | this[it.first] = it.second
209 | }
210 | control?.invoke(this)
211 | }
212 | }
213 |
214 |
215 | private fun Intent.add(vararg parameter: Pair) = apply {
216 | parameter.forEach {
217 | this[it.first] = it.second
218 | }
219 | }
220 |
221 | fun Fragment.setBack(
222 | vararg parameter: Pair,
223 | resultCode: Int = Activity.RESULT_OK,
224 | finish: Boolean = true,
225 | ) {
226 | requireActivity().setBack(*parameter, resultCode = resultCode, finish = finish)
227 | }
228 |
229 | fun Activity.setBack(
230 | vararg parameter: Pair,
231 | resultCode: Int = Activity.RESULT_OK,
232 | finish: Boolean = true,
233 | ) {
234 | setResult(resultCode, Intent().also {
235 | it.add(*parameter)
236 | })
237 |
238 | if (finish) finish()
239 | }
240 |
241 | fun Context?.setBack(
242 | vararg parameter: Pair,
243 | resultCode: Int = Activity.RESULT_OK,
244 | finish: Boolean = true,
245 | ) {
246 | (this as? Activity)?.setBack(*parameter, resultCode = resultCode, finish = finish)
247 | }
248 |
249 |
--------------------------------------------------------------------------------