Skip to content

Commit

Permalink
Use Splashscreen to StartActivity.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
lings03 committed Jan 1, 2025
1 parent e562ea4 commit 6d653b4
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 93 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ dependencies {
implementation(libs.glide)
// pager2
implementation(libs.accompanist.pager)
// 依赖注入
// desugar
coreLibraryDesugaring(libs.desugar)
// 启动页
implementation(libs.androidx.core.splashscreen)
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<activity
android:name="top.lings.start.StartActivity"
android:exported="true"
android:theme="@style/Theme.ModManager">
android:theme="@style/Theme.ModManager.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/kotlin/top/laoxin/modmanager/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class App : Application() {
companion object {
private lateinit var sApp: App
lateinit var osVersion: OSVersion
var isHuawei = false
fun get(): App {
return sApp
}
Expand All @@ -80,13 +81,10 @@ class App : Application() {
// 鸿蒙4
val version = Build.VERSION.INCREMENTAL
Log.d("App初始化", "checkOsVersion: $version")
if (version.contains(
"Harmony",
true
) && (version.contains("4.0") || version.contains("4.2"))
) {
if ((version.contains("104.0") || version.contains("104.2")) && osVersion == OSVersion.OS_11) {
// 鸿蒙4目前仅可使用shizuku,故设置为14
osVersion = OSVersion.OS_14
isHuawei = true
}

Log.d("App", "checkOsVersion: $osVersion")
Expand Down
67 changes: 0 additions & 67 deletions app/src/main/kotlin/top/lings/start/Start.kt

This file was deleted.

38 changes: 20 additions & 18 deletions app/src/main/kotlin/top/lings/start/StartActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.graphics.toArgb
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import top.laoxin.modmanager.MainActivity
import top.laoxin.modmanager.ui.theme.ModManagerTheme
import top.lings.userAgreement.UserAgreementActivity
import java.util.concurrent.atomic.AtomicBoolean

class StartActivity : ComponentActivity() {
private val isKeepOnScreen = AtomicBoolean(true)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -25,33 +23,36 @@ class StartActivity : ComponentActivity() {
WindowCompat.setDecorFitsSystemWindows(window, false)
// 通过背景色使状态栏和导航栏透明
window.setBackgroundDrawableResource(android.R.color.transparent)

// 启用 Edge-to-Edge 模式
enableEdgeToEdge()

// 检查屏幕方向
checkOrientation()

setContent {
// 设置导航栏背景颜色和图标亮度
WindowInsetsControllerCompat(window, window.decorView).apply {
isAppearanceLightNavigationBars = true
@Suppress("DEPRECATION")
window.navigationBarColor = MaterialTheme.colorScheme.surfaceContainer.toArgb()
}
ModManagerTheme {
Start(onTimeout = ::jumpToActivity)
jumpToActivity()

// 保持SplashScreen
var splashScreen = installSplashScreen().apply {
setKeepOnScreenCondition {
isKeepOnScreen.get()
}
}

splashScreen.setOnExitAnimationListener { splashScreenViewProvider ->
splashScreenViewProvider.iconView.animate()
.alpha(0f)
.setDuration(300)
.withEndAction {
splashScreenViewProvider.remove()
}.start()
}
}

override fun onDestroy() {
super.onDestroy()
}

// 跳转到 MainActivity 或 UserAgreementActivity
// 检查用户协议状态并跳转到 MainActivity 或 UserAgreementActivity
fun jumpToActivity() {
// 检查用户协议状态并跳转到 MainActivity 或 UserAgreementActivity
val sharedPreferences = getSharedPreferences("AppLaunch", MODE_PRIVATE)
val isConfirm = sharedPreferences.getBoolean("isConfirm", false)

Expand All @@ -62,6 +63,7 @@ class StartActivity : ComponentActivity() {
}

startActivity(intent)
isKeepOnScreen.set(false)
finish()
}

Expand Down
Binary file added app/src/main/res/drawable/start.webp
Binary file not shown.
8 changes: 7 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
<resources>

<style name="Theme.ModManager" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowDisablePreview">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

<style name="Theme.ModManager.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/start</item>
<item name="windowSplashScreenAnimationDuration">500</item>
<item name="postSplashScreenTheme">@style/Theme.ModManager</item>
</style>

</resources>
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ accompanistPager = "0.36.0"
accompanistPermissions = "0.37.0"
accompanistSystemuicontroller = "0.36.0"
agp = "8.6.1"
coreSplashscreen = "1.0.1"
shizuku = "13.1.5"
coilCompose = "2.7.0"
commonsCompress = "1.27.1"
Expand Down Expand Up @@ -43,6 +44,7 @@ accompanist-pager = { module = "com.google.accompanist:accompanist-pager", versi
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" }
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanistSystemuicontroller" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreen" }
androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" }
androidx-rules = { group = "androidx.test", name = "rules", version.ref = "rules" }
androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
Expand Down

0 comments on commit 6d653b4

Please sign in to comment.