Skip to content

Commit

Permalink
Add Start Screen (#42)
Browse files Browse the repository at this point in the history
does not use androidx.core:core-splashscreen but might be replaced in the future.
  • Loading branch information
lings03 authored Dec 29, 2024
1 parent 56f3814 commit 6d57d97
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 58 deletions.
17 changes: 11 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,24 @@

<!--启动页-->
<activity
android:name="top.lings.userAgreement.UserAgreementActivity"
android:exported="true"
android:theme="@style/Theme.ModManager" />
<!--主页面-->
<activity
android:name=".MainActivity"
android:name="top.lings.start.StartActivity"
android:exported="true"
android:theme="@style/Theme.ModManager">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--用户协议-->
<activity
android:name="top.lings.userAgreement.UserAgreementActivity"
android:exported="true"
android:theme="@style/Theme.ModManager" />
<!--主页面-->
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.ModManager" />

<service
android:name=".userservice.gamestart.ProjectSnowStartService"
Expand Down
34 changes: 0 additions & 34 deletions app/src/main/kotlin/top/laoxin/modmanager/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package top.laoxin.modmanager

import android.content.Intent
import android.content.pm.ActivityInfo
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
Expand All @@ -21,7 +17,6 @@ import rikka.shizuku.Shizuku
import top.laoxin.modmanager.tools.PermissionTools
import top.laoxin.modmanager.ui.theme.ModManagerTheme
import top.laoxin.modmanager.ui.view.ModManagerApp
import top.lings.userAgreement.UserAgreementActivity

class MainActivity : ComponentActivity() {

Expand All @@ -33,38 +28,9 @@ class MainActivity : ComponentActivity() {
// 通过背景色使状态栏和导航栏透明
window.setBackgroundDrawableResource(android.R.color.transparent)

// 获取屏幕宽度
val screenWidthDp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = windowManager.currentWindowMetrics
val widthPixels = windowMetrics.bounds.width()
widthPixels / resources.displayMetrics.density
} else {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getMetrics(displayMetrics)
displayMetrics.widthPixels / displayMetrics.density
}

requestedOrientation = if (screenWidthDp >= 600) {
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} else {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}

// 添加 Shizuku 权限请求监听
Shizuku.addRequestPermissionResultListener(PermissionTools.REQUEST_PERMISSION_RESULT_LISTENER)

// 检查是否同意许可,跳转到 StartActivity 页面
val sharedPreferences = getSharedPreferences("AppLaunch", MODE_PRIVATE)
val isConfirm = sharedPreferences.getBoolean("isConfirm", false)

if (!isConfirm) {
val intent = Intent(this, UserAgreementActivity::class.java)
startActivity(intent)
finish()
return
}

enableEdgeToEdge()

setContent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package top.laoxin.modmanager.ui.state

import top.laoxin.modmanager.bean.ModBean
import top.laoxin.modmanager.ui.view.modview.NavigationIndex
import top.laoxin.modmanager.ui.view.modView.NavigationIndex
import java.io.File

data class ModUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.viewmodel.compose.viewModel
import top.laoxin.modmanager.App
import top.laoxin.modmanager.R
import top.laoxin.modmanager.ui.state.ModUiState
import top.laoxin.modmanager.ui.view.modview.ModPage
import top.laoxin.modmanager.ui.view.modview.ModTopBar
import top.laoxin.modmanager.ui.view.modView.ModPage
import top.laoxin.modmanager.ui.view.modView.ModTopBar
import top.laoxin.modmanager.ui.viewmodel.ConsoleViewModel
import top.laoxin.modmanager.ui.viewmodel.ModViewModel
import kotlin.math.abs
Expand All @@ -76,7 +77,6 @@ enum class NavigationIndex(
SETTINGS(R.string.settings, Icons.Filled.Settings)
}


@Composable
fun ModManagerApp() {
val modViewModel: ModViewModel = viewModel(factory = ModViewModel.Factory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

/*
* Copyright (C) 2023 The Android Open Source Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

import android.os.Environment
import androidx.activity.compose.BackHandler
Expand All @@ -12,7 +12,6 @@ import androidx.compose.animation.togetherWith
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -41,7 +40,6 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import top.laoxin.modmanager.R
import top.laoxin.modmanager.tools.ModTools
import top.laoxin.modmanager.ui.state.ModUiState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

import android.icu.text.SimpleDateFormat
import androidx.annotation.StringRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.laoxin.modmanager.ui.view.modview
package top.laoxin.modmanager.ui.view.modView

import android.content.res.Configuration
import androidx.compose.animation.AnimatedVisibility
Expand All @@ -21,15 +21,12 @@ import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.icons.filled.SelectAll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Snackbar
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ import top.laoxin.modmanager.tools.ToastUtils
import top.laoxin.modmanager.tools.specialGameTools.BaseSpecialGameTools
import top.laoxin.modmanager.ui.state.ModUiState
import top.laoxin.modmanager.ui.state.UserPreferencesState
import top.laoxin.modmanager.ui.view.modview.NavigationIndex
import top.laoxin.modmanager.ui.view.modView.NavigationIndex
import java.io.File
import kotlin.math.log

class ModViewModel(
userPreferencesRepository: UserPreferencesRepository,
Expand Down
67 changes: 67 additions & 0 deletions app/src/main/kotlin/top/lings/start/Start.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package top.lings.start

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import top.laoxin.modmanager.R

@Composable
fun Start(onTimeout: () -> Unit) {
val isTimedOut = rememberSaveable { mutableStateOf(false) }

LaunchedEffect(Unit) {
if (!isTimedOut.value) {
delay(1000)
isTimedOut.value = true
onTimeout()
}
}

Box(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.padding(WindowInsets.systemBars.asPaddingValues()),
contentAlignment = Alignment.Center
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Icon(
painter = painterResource(id = R.drawable.app_icon),
contentDescription = null,
tint = Color.Unspecified,
modifier = Modifier
.size(128.dp)
.clip(RoundedCornerShape(16.dp))
)
}
}
}

@Preview
@Composable
private fun Pre() {
MaterialTheme {
Start(onTimeout = {})
}
}
92 changes: 92 additions & 0 deletions app/src/main/kotlin/top/lings/start/StartActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package top.lings.start

import android.content.Intent
import android.content.pm.ActivityInfo
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.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.ui.graphics.toArgb
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import top.laoxin.modmanager.MainActivity
import top.lings.userAgreement.UserAgreementActivity

class StartActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// 设置全屏模式,使内容可以扩展到状态栏和导航栏区域
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()
}
MaterialTheme(
colorScheme = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
) {
Start(onTimeout = {
// 检查用户协议状态并跳转到 MainActivity 或 UserAgreementActivity
val sharedPreferences = getSharedPreferences("AppLaunch", MODE_PRIVATE)
val isConfirm = sharedPreferences.getBoolean("isConfirm", false)

val intent = if (isConfirm) {
Intent(this, MainActivity::class.java)
} else {
Intent(this, UserAgreementActivity::class.java)
}

startActivity(intent)
finish()
})
}
}
}

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

// 检查屏幕方向
fun checkOrientation() {
// 获取屏幕宽度
val screenWidthDp =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Android 11
val windowMetrics = windowManager.currentWindowMetrics
val widthPixels = windowMetrics.bounds.width()
widthPixels / resources.displayMetrics.density
} else {
// Android 10
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getMetrics(DisplayMetrics())
DisplayMetrics().widthPixels / DisplayMetrics().density
}

// 根据屏幕宽度设置屏幕方向
requestedOrientation = if (screenWidthDp >= 600) {
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} else {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
}
}
6 changes: 5 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

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

</resources>

0 comments on commit 6d57d97

Please sign in to comment.