fix material color problems

This commit is contained in:
BinTianqi
2024-01-30 13:14:37 +08:00
parent d5df4facde
commit 0e72d71560
7 changed files with 63 additions and 42 deletions

View File

@@ -6,6 +6,7 @@ import android.content.Context
import android.os.Build.VERSION
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@@ -166,7 +167,9 @@ fun DeviceControl(){
if(isDeviceOwner(myDpm)){
SysUpdatePolicy(myDpm,myComponent,myContext)
}
Column(modifier = sections(MaterialTheme.colorScheme.errorContainer)) {
Column(modifier = sections(if(isSystemInDarkTheme())
{MaterialTheme.colorScheme.errorContainer}else{MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.6F)})
) {
var flag by remember{ mutableIntStateOf(0) }
var confirmed by remember{ mutableStateOf(false) }
Text(text = "清除数据",style = typography.titleLarge,modifier = Modifier.padding(6.dp),color = MaterialTheme.colorScheme.onErrorContainer)
@@ -187,7 +190,7 @@ fun DeviceControl(){
) {
Text(text = if(confirmed){"取消"}else{"确定"})
}
Row(horizontalArrangement = Arrangement.SpaceBetween) {
Row(modifier = Modifier.fillMaxWidth(),horizontalArrangement = Arrangement.SpaceBetween) {
Button(
onClick = {myDpm.wipeData(flag)},
colors = ButtonDefaults.buttonColors(

View File

@@ -172,10 +172,7 @@ fun HomePage(navCtrl:NavHostController){
val myContext = LocalContext.current
val myDpm = myContext.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
val myComponent = ComponentName(myContext,MyDeviceAdminReceiver::class.java)
val isda = myDpm.isAdminActive(myComponent)
val isdo = myDpm.isDeviceOwnerApp("com.binbin.androidowner")
val activateType = if(isDeviceOwner(myDpm)){"Device Owner"}else if(isProfileOwner(myDpm)){"Profile Owner"}else if(isda){"Device Admin"}else{""}
val isActivated = if(isdo||isda){"已激活"}else{"未激活"}
val activateType = if(isDeviceOwner(myDpm)){"Device Owner"}else if(isProfileOwner(myDpm)){"Profile Owner"}else if(myDpm.isAdminActive(myComponent)){"Device Admin"}else{""}
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Column(modifier = Modifier.verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally) {
if(sharedPref.getBoolean("isWear",false)){
@@ -186,7 +183,7 @@ fun HomePage(navCtrl:NavHostController){
.fillMaxWidth()
.padding(vertical = if (!sharedPref.getBoolean("isWear", false)) { 5.dp } else { 2.dp }, horizontal = if (!sharedPref.getBoolean("isWear", false)) { 8.dp } else { 4.dp })
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.tertiaryContainer)
.background(color = MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F))
.clickable(onClick = { navCtrl.navigate("Permissions") })
.padding(
horizontal = 5.dp,
@@ -195,7 +192,7 @@ fun HomePage(navCtrl:NavHostController){
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = if(isda){
painter = if(myDpm.isAdminActive(myComponent)){
painterResource(R.drawable.check_fill0)
}else{
painterResource(R.drawable.block_fill0)
@@ -206,14 +203,13 @@ fun HomePage(navCtrl:NavHostController){
)
Column {
Text(
text = isActivated,
text = if(isDeviceOwner(myDpm)||myDpm.isAdminActive(myComponent)||isProfileOwner(myDpm)){"已激活"}else{"未激活"},
style = MaterialTheme.typography.headlineSmall,
color = MaterialTheme.colorScheme.onTertiaryContainer
)
if(activateType!=""){
Text(
text = activateType,
color = MaterialTheme.colorScheme.onTertiaryContainer
text = activateType
)
}
}
@@ -234,9 +230,9 @@ fun HomePageItem(name:Int, imgVector:Int, description:Int, navTo:String, myNav:N
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = if (!sharedPref.getBoolean("isWear", false)) { 5.dp } else { 2.dp }, horizontal = if (!sharedPref.getBoolean("isWear", false)) { 8.dp } else { 4.dp })
.padding(vertical = if (!sharedPref.getBoolean("isWear", false)) { 4.dp } else { 2.dp }, horizontal = if (!sharedPref.getBoolean("isWear", false)) { 7.dp } else { 4.dp })
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.primaryContainer)
.background(color = MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.8F))
.clickable(onClick = { myNav.navigate(navTo) })
.padding(6.dp),
verticalAlignment = Alignment.CenterVertically
@@ -256,8 +252,7 @@ fun HomePageItem(name:Int, imgVector:Int, description:Int, navTo:String, myNav:N
)
if(!sharedPref.getBoolean("isWear",false)){
Text(
text = stringResource(description),
color = MaterialTheme.colorScheme.onPrimaryContainer
text = stringResource(description)
)
}
}
@@ -295,19 +290,20 @@ fun isProfileOwner(dpm:DevicePolicyManager): Boolean {
@SuppressLint("ModifierFactoryExtensionFunction")
@Composable
fun sections(bgColor:Color=MaterialTheme.colorScheme.primaryContainer):Modifier{
val backgroundColor = if(isSystemInDarkTheme()){bgColor.copy(0.4F)}else{bgColor.copy(0.6F)}
return if(!LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE).getBoolean("isWear",false)){
Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp)
.clip(RoundedCornerShape(14.dp))
.background(color = bgColor)
.background(color = backgroundColor)
.padding(vertical = 10.dp, horizontal = 10.dp)
}else{
Modifier
.fillMaxWidth()
.padding(horizontal = 3.dp, vertical = 3.dp)
.clip(RoundedCornerShape(10.dp))
.background(color = bgColor)
.background(color = backgroundColor)
.padding(vertical = 2.dp, horizontal = 3.dp)
}
}

View File

@@ -58,6 +58,7 @@ fun Password(){
var newPwd by remember{ mutableStateOf("") }
val focusMgr = LocalFocusManager.current
val isWear = sharedPref.getBoolean("isWear",false)
val titleColor = MaterialTheme.colorScheme.onPrimaryContainer
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
@@ -110,7 +111,7 @@ fun Password(){
horizontalAlignment = Alignment.Start,
modifier = sections()
) {
Text(text = "密码重置令牌", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "密码重置令牌", style = typography.titleLarge,color = titleColor)
Row(
modifier = if(!isWear){Modifier.fillMaxWidth()}else{Modifier.horizontalScroll(rememberScrollState())},
horizontalArrangement = Arrangement.SpaceBetween
@@ -159,7 +160,7 @@ fun Password(){
modifier = sections()
) {
var confirmed by remember{ mutableStateOf(false) }
Text(text = "修改密码",style = MaterialTheme.typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "修改密码",style = MaterialTheme.typography.titleLarge,color = titleColor)
TextField(
value = newPwd,
onValueChange = {newPwd=it},
@@ -238,7 +239,7 @@ fun Password(){
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
selectedItem=myDpm.requiredPasswordComplexity
}
Text(text = "密码复杂度要求", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "密码复杂度要求", style = typography.titleLarge,color = titleColor)
Text(text = "不是实际密码复杂度",
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
Text(text = "设置密码复杂度将会取代密码质量",
@@ -299,7 +300,7 @@ fun Password(){
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
selectedItem=myDpm.getPasswordQuality(myComponent)
}
Text(text = "密码质量要求", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "密码质量要求", style = typography.titleLarge,color = titleColor)
if(expanded){
Text(text = "不是实际密码质量",
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})}

View File

@@ -52,6 +52,7 @@ fun DpmPermissions(navCtrl:NavHostController){
val focusManager = LocalFocusManager.current
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false)
val titleColor = MaterialTheme.colorScheme.onPrimaryContainer
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally
@@ -69,7 +70,7 @@ fun DpmPermissions(navCtrl:NavHostController){
verticalAlignment = Alignment.CenterVertically
) {
Column {
Text(text = "Device Admin", fontSize = if(!isWear){22.sp}else{20.sp},color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "Device Admin", fontSize = if(!isWear){22.sp}else{20.sp},color = titleColor)
Text(text = if(isda){"已激活"}else{"未激活"})
}
if(!isWear)
@@ -94,7 +95,7 @@ fun DpmPermissions(navCtrl:NavHostController){
}
if(!isda){
Column(
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer),
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F)),
horizontalAlignment = Alignment.Start
) {
SelectionContainer {
@@ -112,7 +113,7 @@ fun DpmPermissions(navCtrl:NavHostController){
verticalAlignment = Alignment.CenterVertically
) {
Column {
Text(text = "Profile Owner", fontSize = if(!isWear){22.sp}else{20.sp},color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "Profile Owner", fontSize = if(!isWear){22.sp}else{20.sp},color = titleColor)
Text(if(isProfileOwner(myDpm)){"已激活"}else{"未激活"})
}
if(isProfileOwner(myDpm)&&VERSION.SDK_INT>=24&&!isWear){
@@ -132,7 +133,7 @@ fun DpmPermissions(navCtrl:NavHostController){
}
if(!isProfileOwner(myDpm)){
Column(
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer),
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F)),
horizontalAlignment = Alignment.Start
) {
if(!isDeviceOwner(myDpm)){
@@ -156,7 +157,7 @@ fun DpmPermissions(navCtrl:NavHostController){
verticalAlignment = Alignment.CenterVertically
) {
Column {
Text(text = "Device Owner", fontSize = if(!isWear){22.sp}else{20.sp},color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "Device Owner", fontSize = if(!isWear){22.sp}else{20.sp},color = titleColor)
Text(if(isDeviceOwner(myDpm)){"已激活"}else{"未激活"})
}
if(isDeviceOwner(myDpm)&&!isWear){
@@ -176,7 +177,7 @@ fun DpmPermissions(navCtrl:NavHostController){
}
if(!isDeviceOwner(myDpm)&&!isProfileOwner(myDpm)){
Column(
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer),
modifier = sections(MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F)),
horizontalAlignment = Alignment.Start
) {
SelectionContainer {
@@ -194,7 +195,7 @@ fun DpmPermissions(navCtrl:NavHostController){
Text(
text = "注意!在这里撤销权限不会清除配置。比如:被停用的应用会保持停用状态",
color = MaterialTheme.colorScheme.onErrorContainer,
modifier = sections(MaterialTheme.colorScheme.errorContainer),
modifier = sections(MaterialTheme.colorScheme.errorContainer.copy(alpha = 0.8F)),
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium}
)
}
@@ -202,7 +203,7 @@ fun DpmPermissions(navCtrl:NavHostController){
Column(
modifier = sections()
) {
Text(text = "设备信息", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "设备信息", style = typography.titleLarge,color = titleColor)
val orgDevice = myDpm.isOrganizationOwnedDeviceWithManagedProfile
Text("由组织拥有的受管理资料设备:$orgDevice",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
if(isDeviceOwner(myDpm)|| isProfileOwner(myDpm)){
@@ -233,7 +234,7 @@ fun DpmPermissions(navCtrl:NavHostController){
if(VERSION.SDK_INT>=31&&(isProfileOwner(myDpm)|| isDeviceOwner(myDpm))){
Column(modifier = sections()) {
val specificId:String = myDpm.enrollmentSpecificId
Text(text = "设备唯一标识码", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "设备唯一标识码", style = typography.titleLarge,color = titleColor)
Text("(恢复出厂设置不变)",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
if(specificId!=""){
Text(specificId)
@@ -247,7 +248,7 @@ fun DpmPermissions(navCtrl:NavHostController){
}
if(isDeviceOwner(myDpm) || isProfileOwner(myDpm)){
Column(modifier = sections()) {
Text(text = "不受控制的账号类型", style = typography.titleLarge,color = MaterialTheme.colorScheme.onPrimaryContainer)
Text(text = "不受控制的账号类型", style = typography.titleLarge,color = titleColor)
Text("作用未知",style=if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
var noManageAccount = myDpm.accountTypesWithManagementDisabled?.toMutableList()
var accountlist by remember{ mutableStateOf("") }
@@ -382,7 +383,7 @@ fun DeviceOwnerInfo(
Column(modifier = sections()) {
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
val isWear = sharedPref.getBoolean("isWear",false)
Text(text = stringResource(name), style = typography.titleLarge, softWrap = false)
Text(text = stringResource(name), style = typography.titleLarge, softWrap = false, color = MaterialTheme.colorScheme.onPrimaryContainer)
if(desc!=R.string.place_holder){
Text(
text = stringResource(desc),modifier = Modifier.padding(top = 6.dp),

View File

@@ -3,6 +3,7 @@ package com.binbin.androidowner
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build.VERSION
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@@ -47,6 +48,21 @@ fun AppSetting(navCtrl:NavHostController){
}
)
}
if(VERSION.SDK_INT>=32){
Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 3.dp),horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {
Text(text = "动态取色", style = MaterialTheme.typography.titleLarge)
Switch(
checked = sharedPref.getBoolean("dynamicColor",false),
onCheckedChange = {
sharedPref.edit().putBoolean("dynamicColor",!sharedPref.getBoolean("dynamicColor",false)).apply()
navCtrl.navigate("HomePage") {
popUpTo(navCtrl.graph.findStartDestination().id) { saveState = true }
}
}
)
}
Text("打开或关闭动态取色需要重启应用")
}
}
Column(modifier = sections()) {
Column(

View File

@@ -76,8 +76,7 @@ fun UserRestriction(){
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
}
if(isWear){
Text(text = "部分功能在手表上无效",
style = if(!isWear){typography.bodyLarge}else{typography.bodyMedium})
Text(text = "部分功能在手表上无效", style = typography.bodyMedium)
}
}
@@ -157,13 +156,13 @@ fun SectionTab(txt:String,getSection:()->Boolean,setSection:()->Unit){
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = if(!sharedPref.getBoolean("isWear",false)){8.dp}else{4.dp},
vertical = if(!sharedPref.getBoolean("isWear",false)){6.dp}else{3.dp})
vertical = if(!sharedPref.getBoolean("isWear",false)){5.dp}else{2.dp})
.clip(RoundedCornerShape(15.dp))
.background(
color = if (getSection()) {
MaterialTheme.colorScheme.tertiaryContainer
MaterialTheme.colorScheme.tertiaryContainer.copy(alpha = 0.8F)
} else {
MaterialTheme.colorScheme.primaryContainer
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.8F)
}
)
.clickable(onClick = setSection)
@@ -338,7 +337,7 @@ private class restrictionData{
}
if(VERSION.SDK_INT>=28){list += Restriction(UserManager.DISALLOW_SYSTEM_ERROR_DIALOGS,R.string.sys_err_dialog,"",R.drawable.android_fill0)}
list += Restriction(UserManager.DISALLOW_FACTORY_RESET,R.string.factory_reset,"",R.drawable.android_fill0)
list += Restriction(UserManager.DISALLOW_SAFE_BOOT,R.string.safe_boot,"",R.drawable.android_fill0)
list += Restriction(UserManager.DISALLOW_SAFE_BOOT,R.string.safe_boot,"",R.drawable.security_fill0)
list += Restriction(UserManager.DISALLOW_DEBUGGING_FEATURES,R.string.debug_features,"",R.drawable.adb_fill0)
return list
}

View File

@@ -1,7 +1,9 @@
package com.binbin.androidowner.ui.theme
import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.Build.VERSION
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
@@ -82,13 +84,16 @@ private val LightColorScheme = lightColorScheme(
@Composable
fun AndroidOwnerTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val context = LocalContext.current
val sharedPref = context.getSharedPreferences("data", Context.MODE_PRIVATE)
if(!sharedPref.contains("dynamicColor")&&VERSION.SDK_INT>=32){
sharedPref.edit().putBoolean("dynamicColor",true).apply()
}
val dynamicColor = sharedPref.getBoolean("dynamicColor",false)
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
dynamicColor && VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}