redesign homepage

This commit is contained in:
BinTianqi
2024-03-08 16:21:09 +08:00
parent 6da2b2efbc
commit f92d5723f3
5 changed files with 45 additions and 57 deletions

View File

@@ -1087,7 +1087,9 @@ API31及以上弃用请使用[密码复杂度要求](#密码复杂度要求)
## 其他功能
### 手表模式
### ~~手表模式~~
正在修改预计在5.0版本重新加入。
在Android owner的设置中打开

View File

@@ -6,6 +6,8 @@
使用安卓的Device Admin和Device Owner特权完全掌控你的设备。
**从v4.2开始,重写代码,重新设计,界面会发生很大改变。**
### 优点
- 开源。Device owner权限可能比root权限更危险闭源软件的安全性没有保证

View File

@@ -21,8 +21,8 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material3.*
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
@@ -121,12 +121,9 @@ fun MyScaffold(){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Scaffold(
topBar = {
if(!sharedPref.getBoolean("isWear",false)){
TopAppBar(
title = {Text(text = stringResource(topBarName) , color = MaterialTheme.colorScheme.onSurface, modifier = Modifier.padding(bottom = 2.dp))},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surface
),
title = {Text(text = stringResource(topBarName) , color = colorScheme.onSurface, modifier = Modifier.padding(bottom = 2.dp))},
colors = TopAppBarDefaults.topAppBarColors( containerColor = colorScheme.surfaceVariant ),
navigationIcon = {
AnimatedVisibility(
visible = topBarName!=R.string.app_name,
@@ -145,22 +142,6 @@ fun MyScaffold(){
}
}
)
}
},
floatingActionButton = {
if(sharedPref.getBoolean("isWear",false)&&topBarName!=R.string.app_name){
FloatingActionButton(
onClick = {
focusMgr.clearFocus()
navCtrl.navigateUp()
},
modifier = Modifier.size(35.dp),
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
contentColor = MaterialTheme.colorScheme.tertiary
) {
Icon(imageVector = Icons.Outlined.Home, contentDescription = null)
}
}
}
) {
val profileInited = sharedPref.getBoolean("ManagedProfileActivated",false)
@@ -169,7 +150,10 @@ fun MyScaffold(){
NavHost(
navController = navCtrl,
startDestination = "HomePage",
modifier = Modifier.fillMaxSize().padding(top = it.calculateTopPadding()).imePadding(),
modifier = Modifier
.fillMaxSize()
.background(color = if(isSystemInDarkTheme()) { colorScheme.background }else{ colorScheme.primary.copy(alpha = 0.05F) })
.padding(top = it.calculateTopPadding()).imePadding(),
enterTransition = Animations(myContext).navHostEnterTransition,
exitTransition = Animations(myContext).navHostExitTransition,
popEnterTransition = Animations(myContext).navHostPopEnterTransition,
@@ -199,40 +183,35 @@ fun HomePage(navCtrl:NavHostController){
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
val activateType =
if(isDeviceOwner(myDpm)){"Device Owner"}
else if(isProfileOwner(myDpm)){if(VERSION.SDK_INT>=24&&myDpm.isManagedProfile(myComponent)){"工作资料"}else{"Profile Owner"}}
else if(myDpm.isAdminActive(myComponent)){"Device Admin"}
else{""}
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false)
else if(isProfileOwner(myDpm)){if(VERSION.SDK_INT>=24&&myDpm.isManagedProfile(myComponent)){stringResource(R.string.work_profile)}else{"Profile Owner"}}
else if(myDpm.isAdminActive(myComponent)){"Device Admin"} else{""}
caCert = byteArrayOf()
Column(modifier = Modifier.verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally) {
if(isWear){ Spacer(Modifier.padding(vertical = 3.dp)) }
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = if (!isWear) { 5.dp } else { 2.dp }, horizontal = if (!isWear) { 8.dp } else { 4.dp })
.padding(vertical = 8.dp, horizontal = 8.dp)
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.7F))
.background(color = colorScheme.primaryContainer)
.clickable(onClick = { navCtrl.navigate("Permissions") })
.padding(
horizontal = 5.dp,
vertical = if (!isWear) { 14.dp } else { 2.dp }
),
.padding(vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.fillMaxWidth(0.06F))
Icon(
painter = painterResource(if(myDpm.isAdminActive(myComponent)){ R.drawable.check_fill0 }else{ R.drawable.block_fill0 }),
painter = painterResource(if(myDpm.isAdminActive(myComponent)){ R.drawable.check_circle_fill1 }else{ R.drawable.block_fill0 }),
contentDescription = null,
modifier = Modifier.padding(horizontal = if(!isWear){10.dp}else{6.dp}),
tint = MaterialTheme.colorScheme.tertiary
tint = colorScheme.primary
)
Spacer(modifier = Modifier.fillMaxWidth(0.05F))
Column {
Text(
text = if(isDeviceOwner(myDpm)||myDpm.isAdminActive(myComponent)||isProfileOwner(myDpm)){"已激活"}else{"未激活"},
text = if(myDpm.isAdminActive(myComponent)){"已激活"}else{"未激活"},
style = typography.headlineSmall,
color = MaterialTheme.colorScheme.onTertiaryContainer
color = colorScheme.onPrimaryContainer,
modifier = Modifier.padding(bottom = 2.dp)
)
if(activateType!=""){ Text(activateType) }
if(activateType!=""){ Text(text = activateType, color = colorScheme.onPrimaryContainer, modifier = Modifier.padding(start = 2.dp)) }
}
}
HomePageItem(R.string.device_ctrl, R.drawable.mobile_phone_fill0, "DeviceControl", navCtrl)
@@ -249,32 +228,28 @@ fun HomePage(navCtrl:NavHostController){
@Composable
fun HomePageItem(name:Int, imgVector:Int, navTo:String, myNav:NavHostController){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear", false)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = if (!isWear) { 4.dp } else { 2.dp }, horizontal = if (!isWear) { 7.dp } else { 4.dp })
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.7F))
.clip(RoundedCornerShape(25))
.clickable(onClick = { myNav.navigate(navTo) })
.padding(vertical = if(isWear){6.dp}else{10.dp}, horizontal = 6.dp),
.padding(vertical = 13.dp),
verticalAlignment = Alignment.CenterVertically
) {
Spacer(modifier = Modifier.fillMaxWidth(0.08F))
Icon(
painter = painterResource(imgVector),
contentDescription = null,
modifier = Modifier.padding(horizontal = if(!sharedPref.getBoolean("isWear",false)){12.dp}else{6.dp}),
tint = MaterialTheme.colorScheme.primary
tint = colorScheme.onBackground
)
Spacer(modifier = Modifier.fillMaxWidth(0.05F))
Column {
Text(
text = stringResource(name),
style = typography.headlineSmall,
color = MaterialTheme.colorScheme.onPrimaryContainer
color = colorScheme.onBackground,
modifier = Modifier.padding(bottom = 2.dp)
)
Spacer(Modifier.padding(top = 2.dp))
}
}
}
@@ -284,7 +259,7 @@ fun RadioButtonItem(
text:String,
selected:()->Boolean,
operation:()->Unit,
textColor:Color = MaterialTheme.colorScheme.onBackground
textColor:Color = colorScheme.onBackground
){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false)
@@ -304,7 +279,7 @@ fun CheckBoxItem(
text:String,
checked:()->Boolean,
operation:()->Unit,
textColor:Color = MaterialTheme.colorScheme.onBackground
textColor:Color = colorScheme.onBackground
){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false)
@@ -334,7 +309,7 @@ fun isProfileOwner(dpm:DevicePolicyManager): Boolean {
@SuppressLint("ModifierFactoryExtensionFunction", "ComposableModifierFactory")
@Composable
@Stable
fun sections(bgColor:Color=MaterialTheme.colorScheme.primaryContainer,onClick:()->Unit={},clickable:Boolean=false):Modifier{
fun sections(bgColor:Color=colorScheme.primaryContainer,onClick:()->Unit={},clickable:Boolean=false):Modifier{
val backgroundColor = if(isSystemInDarkTheme()){bgColor.copy(0.3F)}else{bgColor.copy(0.8F)}
return if(!LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE).getBoolean("isWear",false)){
Modifier

View File

@@ -104,7 +104,7 @@ fun AndroidOwnerTheme(
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.surface.toArgb()
window.statusBarColor = colorScheme.surfaceVariant.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
}
}

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="#FF000000"
android:pathData="m424,664 l282,-282 -56,-56 -226,226 -114,-114 -56,56 170,170ZM480,880q-83,0 -156,-31.5T197,763q-54,-54 -85.5,-127T80,480q0,-83 31.5,-156T197,197q54,-54 127,-85.5T480,80q83,0 156,31.5T763,197q54,54 85.5,127T880,480q0,83 -31.5,156T763,763q-54,54 -127,85.5T480,880Z"/>
</vector>