system bars'color will follow the app

This commit is contained in:
BinTianqi
2024-01-19 09:45:14 +08:00
parent 13fa0d7b4d
commit 8c72d19847
11 changed files with 183 additions and 91 deletions

View File

@@ -59,7 +59,7 @@ dependencies {
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.material3:material3:1.1.1")
implementation("androidx.navigation:navigation-compose:2.7.6")
implementation("com.google.accompanist:accompanist-systemuicontroller:0.33.2-alpha")
testImplementation("junit:junit:4.13.2")

View File

@@ -18,6 +18,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:theme="@style/Theme.AndroidOwner">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -121,7 +121,7 @@ private fun DeviceCtrlItem(
Row(
modifier = Modifier
.fillMaxWidth()
.padding(5.dp)
.padding(horizontal = 6.dp, vertical = 4.dp)
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.primaryContainer)
.padding(8.dp),

View File

@@ -5,7 +5,6 @@ import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
@@ -14,7 +13,6 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
@@ -49,24 +47,18 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
window.decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
//getWindow().setStatusBarColor(Color.White)
super.onCreate(savedInstanceState)
val context = applicationContext
val dpm = context.getSystemService(DEVICE_POLICY_SERVICE) as DevicePolicyManager
val adminComponent = ComponentName(context,MyDeviceAdminReceiver::class.java)
setContent {
val sysUiCtrl = rememberSystemUiController()
val sf = MaterialTheme.colorScheme.surface
val useDarkIcon = !isSystemInDarkTheme()
SideEffect {
sysUiCtrl.run {
setNavigationBarColor(sf,useDarkIcon)
setStatusBarColor(Color.White.copy(alpha = 0F),useDarkIcon)
}
}
AndroidOwnerTheme {
SideEffect {
sysUiCtrl.setNavigationBarColor(Color.Transparent,useDarkIcon)
sysUiCtrl.setStatusBarColor(Color.Transparent,useDarkIcon)
}
MyScaffold(dpm,adminComponent,context)
}
}
@@ -128,7 +120,6 @@ fun MyScaffold(mainDpm:DevicePolicyManager, mainComponent:ComponentName, mainCon
startDestination = "HomePage",
modifier = Modifier
.padding(top = it.calculateTopPadding())
.navigationBarsPadding()
){
composable(route = "HomePage", content = { HomePage(navCtrl,mainDpm,mainComponent)})
composable(route = "DeviceControl", content = { DeviceControl(mainDpm,mainComponent)})
@@ -144,7 +135,8 @@ fun MyScaffold(mainDpm:DevicePolicyManager, mainComponent:ComponentName, mainCon
fun HomePage(navCtrl:NavHostController,myDpm:DevicePolicyManager,myComponent:ComponentName){
val isda = myDpm.isAdminActive(myComponent)
val isdo = myDpm.isDeviceOwnerApp("com.binbin.androidowner")
val activated = if(isdo){"Device Owner 已激活"}else if(isda){"Device Admin已激活"}else{"未激活"}
val activateType = if(isdo){"Device Owner"}else if(isda){"Device Admin"}else{""}
val isActivated = if(isdo||isda){"已激活"}else{"未激活"}
Column {
Row(
modifier = Modifier
@@ -153,7 +145,7 @@ fun HomePage(navCtrl:NavHostController,myDpm:DevicePolicyManager,myComponent:Com
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.tertiaryContainer)
.clickable(onClick = { navCtrl.navigate("Permissions") })
.padding(horizontal = 5.dp, vertical = 12.dp),
.padding(horizontal = 5.dp, vertical = 14.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
@@ -168,14 +160,16 @@ fun HomePage(navCtrl:NavHostController,myDpm:DevicePolicyManager,myComponent:Com
)
Column {
Text(
text = stringResource(R.string.permission),
text = isActivated,
style = MaterialTheme.typography.headlineSmall,
color = MaterialTheme.colorScheme.onTertiaryContainer
)
Text(
text = activated,
color = MaterialTheme.colorScheme.onTertiaryContainer
)
if(activateType!=""){
Text(
text = activateType,
color = MaterialTheme.colorScheme.onTertiaryContainer
)
}
}
}
HomePageItem(R.string.device_ctrl, R.drawable.mobile_phone_fill0, R.string.device_ctrl_desc, "DeviceControl", navCtrl)

View File

@@ -50,7 +50,7 @@ fun DpmPermissions(myDpm: DevicePolicyManager, myComponent: ComponentName, myCon
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 10.dp)
.clip(RoundedCornerShape(8))
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.primaryContainer)
.padding(10.dp),
horizontalArrangement = Arrangement.SpaceBetween,
@@ -83,7 +83,7 @@ fun DpmPermissions(myDpm: DevicePolicyManager, myComponent: ComponentName, myCon
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 10.dp)
.clip(RoundedCornerShape(8))
.clip(RoundedCornerShape(15))
.background(color = MaterialTheme.colorScheme.primaryContainer)
.padding(10.dp),
horizontalArrangement = Arrangement.SpaceBetween,

View File

@@ -18,6 +18,7 @@ import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
@@ -84,8 +85,8 @@ private fun UserRestrictionItem(restriction:String, itemName:Int, restrictionDes
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp, horizontal = 8.dp)
.clip(RoundedCornerShape(10))
.padding(vertical = 4.dp, horizontal = 8.dp)
.clip(RoundedCornerShape(20))
.background(color = MaterialTheme.colorScheme.secondaryContainer)
.padding(5.dp),
verticalAlignment = Alignment.CenterVertically,
@@ -98,7 +99,7 @@ private fun UserRestrictionItem(restriction:String, itemName:Int, restrictionDes
painter = painterResource(leadIcon),
contentDescription = null,
modifier = Modifier.padding(horizontal = 8.dp),
tint = MaterialTheme.colorScheme.onPrimaryContainer
tint = MaterialTheme.colorScheme.secondary
)
Column(
modifier = Modifier.align(Alignment.CenterVertically)
@@ -107,7 +108,7 @@ private fun UserRestrictionItem(restriction:String, itemName:Int, restrictionDes
text = stringResource(itemName),
style = MaterialTheme.typography.titleLarge
)
if(restrictionDescription!=""){Text(restrictionDescription)}
if(restrictionDescription!=""){Text(text = restrictionDescription, color = MaterialTheme.colorScheme.onSecondaryContainer)}
}
}
if(isdo&&VERSION.SDK_INT>=24){
@@ -124,12 +125,9 @@ private fun UserRestrictionItem(restriction:String, itemName:Int, restrictionDes
myDpm.clearUserRestriction(myComponent,restriction)
}
strictState = myDpm.getUserRestrictions(myComponent).getBoolean(restriction)
},
enabled = isdo
)
}else{
}
}
}

View File

@@ -2,10 +2,62 @@ package com.binbin.androidowner.ui.theme
import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val md_theme_light_primary = Color(0xFF006A65)
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val md_theme_light_primaryContainer = Color(0xFF70F7EE)
val md_theme_light_onPrimaryContainer = Color(0xFF00201E)
val md_theme_light_secondary = Color(0xFF4A6361)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFCCE8E5)
val md_theme_light_onSecondaryContainer = Color(0xFF051F1E)
val md_theme_light_tertiary = Color(0xFF48607B)
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFFD0E4FF)
val md_theme_light_onTertiaryContainer = Color(0xFF001D34)
val md_theme_light_error = Color(0xFFBA1A1A)
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410002)
val md_theme_light_background = Color(0xFFFAFDFB)
val md_theme_light_onBackground = Color(0xFF191C1C)
val md_theme_light_surface = Color(0xFFFAFDFB)
val md_theme_light_onSurface = Color(0xFF191C1C)
val md_theme_light_surfaceVariant = Color(0xFFDAE5E3)
val md_theme_light_onSurfaceVariant = Color(0xFF3F4947)
val md_theme_light_outline = Color(0xFF6F7978)
val md_theme_light_inverseOnSurface = Color(0xFFEFF1F0)
val md_theme_light_inverseSurface = Color(0xFF2D3130)
val md_theme_light_inversePrimary = Color(0xFF4FDAD1)
val md_theme_light_surfaceTint = Color(0xFF006A65)
val md_theme_light_outlineVariant = Color(0xFFBEC9C7)
val md_theme_light_scrim = Color(0xFF000000)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val md_theme_dark_primary = Color(0xFF4FDAD1)
val md_theme_dark_onPrimary = Color(0xFF003734)
val md_theme_dark_primaryContainer = Color(0xFF00504C)
val md_theme_dark_onPrimaryContainer = Color(0xFF70F7EE)
val md_theme_dark_secondary = Color(0xFFB0CCC9)
val md_theme_dark_onSecondary = Color(0xFF1C3533)
val md_theme_dark_secondaryContainer = Color(0xFF324B49)
val md_theme_dark_onSecondaryContainer = Color(0xFFCCE8E5)
val md_theme_dark_tertiary = Color(0xFFB0C9E7)
val md_theme_dark_onTertiary = Color(0xFF18324A)
val md_theme_dark_tertiaryContainer = Color(0xFF304962)
val md_theme_dark_onTertiaryContainer = Color(0xFFD0E4FF)
val md_theme_dark_error = Color(0xFFFFB4AB)
val md_theme_dark_errorContainer = Color(0xFF93000A)
val md_theme_dark_onError = Color(0xFF690005)
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
val md_theme_dark_background = Color(0xFF191C1C)
val md_theme_dark_onBackground = Color(0xFFE0E3E2)
val md_theme_dark_surface = Color(0xFF191C1C)
val md_theme_dark_onSurface = Color(0xFFE0E3E2)
val md_theme_dark_surfaceVariant = Color(0xFF3F4947)
val md_theme_dark_onSurfaceVariant = Color(0xFFBEC9C7)
val md_theme_dark_outline = Color(0xFF889391)
val md_theme_dark_inverseOnSurface = Color(0xFF191C1C)
val md_theme_dark_inverseSurface = Color(0xFFE0E3E2)
val md_theme_dark_inversePrimary = Color(0xFF006A65)
val md_theme_dark_surfaceTint = Color(0xFF4FDAD1)
val md_theme_dark_outlineVariant = Color(0xFF3F4947)
val md_theme_dark_scrim = Color(0xFF000000)

View File

@@ -16,25 +16,67 @@ import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
primaryContainer = md_theme_dark_primaryContainer,
onPrimaryContainer = md_theme_dark_onPrimaryContainer,
secondary = md_theme_dark_secondary,
onSecondary = md_theme_dark_onSecondary,
secondaryContainer = md_theme_dark_secondaryContainer,
onSecondaryContainer = md_theme_dark_onSecondaryContainer,
tertiary = md_theme_dark_tertiary,
onTertiary = md_theme_dark_onTertiary,
tertiaryContainer = md_theme_dark_tertiaryContainer,
onTertiaryContainer = md_theme_dark_onTertiaryContainer,
error = md_theme_dark_error,
errorContainer = md_theme_dark_errorContainer,
onError = md_theme_dark_onError,
onErrorContainer = md_theme_dark_onErrorContainer,
background = md_theme_dark_background,
onBackground = md_theme_dark_onBackground,
surface = md_theme_dark_surface,
onSurface = md_theme_dark_onSurface,
surfaceVariant = md_theme_dark_surfaceVariant,
onSurfaceVariant = md_theme_dark_onSurfaceVariant,
outline = md_theme_dark_outline,
inverseOnSurface = md_theme_dark_inverseOnSurface,
inverseSurface = md_theme_dark_inverseSurface,
inversePrimary = md_theme_dark_inversePrimary,
surfaceTint = md_theme_dark_surfaceTint,
outlineVariant = md_theme_dark_outlineVariant,
scrim = md_theme_dark_scrim
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
onPrimaryContainer = md_theme_light_onPrimaryContainer,
secondary = md_theme_light_secondary,
onSecondary = md_theme_light_onSecondary,
secondaryContainer = md_theme_light_secondaryContainer,
onSecondaryContainer = md_theme_light_onSecondaryContainer,
tertiary = md_theme_light_tertiary,
onTertiary = md_theme_light_onTertiary,
tertiaryContainer = md_theme_light_tertiaryContainer,
onTertiaryContainer = md_theme_light_onTertiaryContainer,
error = md_theme_light_error,
errorContainer = md_theme_light_errorContainer,
onError = md_theme_light_onError,
onErrorContainer = md_theme_light_onErrorContainer,
background = md_theme_light_background,
onBackground = md_theme_light_onBackground,
surface = md_theme_light_surface,
onSurface = md_theme_light_onSurface,
surfaceVariant = md_theme_light_surfaceVariant,
onSurfaceVariant = md_theme_light_onSurfaceVariant,
outline = md_theme_light_outline,
inverseOnSurface = md_theme_light_inverseOnSurface,
inverseSurface = md_theme_light_inverseSurface,
inversePrimary = md_theme_light_inversePrimary,
surfaceTint = md_theme_light_surfaceTint,
outlineVariant = md_theme_light_outlineVariant,
scrim = md_theme_light_scrim
)
@Composable

View File

@@ -1,55 +1,59 @@
<resources>
<string name="app_name">Android Owner</string>
<string name="bluetooth">蓝牙</string>
<string name="airplane_mode">飞行模式</string>
<string name="config_wifi">配置Wi-Fi</string>
<string name="debug_features">调试功能</string>
<string name="config_location">配置位置信息</string>
<string name="config_mobile_network">配置移动数据</string>
<string name="create_windows">创建窗口</string>
<string name="allow">允许</string>
<string name="disallow">禁止</string>
<string name="is_disallow">是否禁止:</string>
<string name="adjust_volume">调整音量</string>
<string name="config_brightness">调整亮度</string>
<string name="install_apps">安装应用</string>
<string name="sms">短信</string>
<string name="apps_ctrl">控制应用</string>
<string name="apps_ctrl_description">包括清空存储空间、清空缓存</string>
<string name="create_windows_description">包括Toast和浮动通知</string>
<string name="permission">权限</string>
<string name="device_ctrl">设备控制</string>
<string name="ui_ctrl">UI控制</string>
<string name="app_manage">应用管理</string>
<string name="user_restrict">用户限制</string>
<string name="place_holder" />
<string name="permission_desc">授权与取消授权DeviceAdmin或DeviceOwner</string>
<string name="device_ctrl_desc">控制一些软件、硬件</string>
<string name="ui_ctrl_desc">目前没啥功能</string>
<string name="app_manage_desc">非DeviceOwner勿入</string>
<string name="user_restrict_desc">限制一些功能</string>
<string name="autofill">自动填充服务</string>
<string name="camera_toggle">切换相机</string>
<string name="bt_share">蓝牙分享</string>
<string name="disable_cam">禁用相机</string>
<string name="disable_scrcap">禁止截屏</string>
<string name="master_mute">全局静音</string>
<string name="aosp_scrrec_also_work">对AOSP的录屏也起作用</string>
<string name="hide_status_bar">隐藏状态栏</string>
<string name="may_hide_notifi_icon_only">也许只能隐藏状态栏上的通知图标</string>
<string name="auto_time">自动设置时间</string>
<string name="auto_timezone">自动设置时区</string>
<string name="master_mute">全局静音</string>
<string name="backup_service">备份服务</string>
<string name="hide">隐藏</string>
<string name="app_manage">应用管理</string>
<string name="suspend">停用</string>
<string name="block_unins">防卸载</string>
<string name="hide">隐藏</string>
<string name="isapphidden_desc">如果隐藏,有可能是没安装</string>
<string name="sometimes_not_available">有时候不能用</string>
<string name="user_ctrl_disabled">禁止用户控制</string>
<string name="user_ctrl_disabled_desc">阻止清除应用数据和缓存</string>
<string name="password">密码</string>
<string name="allow">允许</string>
<string name="disallow">禁止</string>
<string name="is_disallow">是否禁止:</string>
<string name="apps_ctrl_description">包括清空存储空间、清空缓存</string>
<string name="create_windows_description">包括Toast和浮动通知</string>
<string name="permission">权限</string>
<string name="ui_ctrl">UI控制</string>
<string name="place_holder" />
<string name="permission_desc">授权与取消授权DeviceAdmin或DeviceOwner</string>
<string name="device_ctrl_desc">控制一些软件、硬件</string>
<string name="app_manage_desc">非DeviceOwner勿入</string>
<string name="user_restrict_desc">限制一些功能</string>
<string name="block_unins">防卸载</string>
<string name="sometimes_not_available">有时候不能用</string>
<string name="user_restrict">用户限制</string>
<string name="config_mobile_network">配置移动数据</string>
<string name="config_wifi">配置Wi-Fi</string>
<string name="bluetooth">蓝牙</string>
<string name="bt_share">蓝牙分享</string>
<string name="airplane_mode">飞行模式</string>
<string name="config_location">配置位置信息</string>
<string name="config_brightness">调整亮度</string>
<string name="debug_features">调试功能</string>
<string name="create_windows">创建窗口</string>
<string name="adjust_volume">调整音量</string>
<string name="install_apps">安装应用</string>
<string name="camera_toggle">切换相机</string>
<string name="sms">短信</string>
<string name="apps_ctrl">控制应用</string>
<string name="autofill">自动填充服务</string>
<string name="inst_unknown_src">安装未知来源应用</string>
<string name="password">密码</string>
<string name="security_desc">锁屏密码相关操作</string>
<string name="reset_pwd_desc">留空可以清除密码纯数字将使用PIN码</string>
<string name="max_pwd_fail">最大密码错误次数</string>
<string name="max_pwd_fail_desc">达到该限制会恢复出厂设置</string>
<string name="max_pwd_fail_textfield">错误次数</string>
@@ -59,5 +63,4 @@
<string name="pwd_history">密码历史记录长度</string>
<string name="pwd_history_desc">用户输入的密码不能与历史记录中的任何密码相同0为无限制</string>
<string name="pwd_history_textfield">历史记录长度</string>
<string name="reset_pwd_desc">留空可以清除密码纯数字将使用PIN码</string>
</resources>

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AndroidOwner" parent="android:Theme.Material.Light.NoActionBar" />
<style name="Theme.AndroidOwner" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:navigationBarColor">#00FFFFFF</item>
<item name="android:statusBarColor">#00FFFFFF</item>
</style>
</resources>