adapt for wearables, change app icon

This commit is contained in:
BinTianqi
2024-01-24 15:52:27 +08:00
parent e75a0946db
commit 1f79994161
34 changed files with 379 additions and 163 deletions

View File

@@ -1,6 +1,7 @@
package com.binbin.androidowner
import android.annotation.SuppressLint
import android.app.ActivityManager
import android.app.admin.DevicePolicyManager
import android.content.ComponentName
import android.content.Context
@@ -12,15 +13,19 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack
import androidx.compose.material.icons.outlined.Home
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.RadioButton
@@ -50,11 +55,11 @@ import androidx.navigation.compose.rememberNavController
import com.binbin.androidowner.ui.theme.AndroidOwnerTheme
import com.google.accompanist.systemuicontroller.rememberSystemUiController
@ExperimentalMaterial3Api
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)
setContent {
val sysUiCtrl = rememberSystemUiController()
@@ -87,8 +92,10 @@ fun MyScaffold(){
"AppSetting" to R.string.setting
)
val topBarName = topBarNameMap[backStackEntry?.destination?.route]?: R.string.app_name
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Scaffold(
topBar = {
if(!sharedPref.getBoolean("isWear",false)){
TopAppBar(
title = {
Text(
@@ -120,6 +127,26 @@ fun MyScaffold(){
}
}
)
}
},
floatingActionButton = {
if(sharedPref.getBoolean("isWear",false)&&topBarName!=R.string.app_name){
FloatingActionButton(
onClick = {
navCtrl.navigate("HomePage") {
popUpTo(
navCtrl.graph.findStartDestination().id
) { saveState = true }
}
focusMgr.clearFocus()
},
modifier = Modifier.size(35.dp),
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
contentColor = MaterialTheme.colorScheme.tertiary
) {
Icon(imageVector = Icons.Outlined.Home, contentDescription = null)
}
}
}
) {
NavHost(
@@ -136,7 +163,7 @@ fun MyScaffold(){
composable(route = "UserRestriction", content = { UserRestriction()})
composable(route = "UserManage", content = { UserManage()})
composable(route = "Password", content = { Password()})
composable(route = "AppSetting", content = { AppSetting()})
composable(route = "AppSetting", content = { AppSetting(navCtrl)})
}
}
}
@@ -150,15 +177,22 @@ fun HomePage(navCtrl:NavHostController){
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{"未激活"}
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Column(modifier = Modifier.verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally) {
if(sharedPref.getBoolean("isWear",false)){
Text(text = "Android owner", style = MaterialTheme.typography.titleLarge)
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp, horizontal = 8.dp)
.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)
.clickable(onClick = { navCtrl.navigate("Permissions") })
.padding(horizontal = 5.dp, vertical = 14.dp),
.padding(
horizontal = 5.dp,
vertical = if (!sharedPref.getBoolean("isWear", false)) { 14.dp } else { 1.dp }
),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
@@ -168,7 +202,7 @@ fun HomePage(navCtrl:NavHostController){
painterResource(R.drawable.block_fill0)
},
contentDescription = null,
modifier = Modifier.padding(horizontal = 13.dp),
modifier = Modifier.padding(horizontal = if(!sharedPref.getBoolean("isWear",false)){10.dp}else{6.dp}),
tint = MaterialTheme.colorScheme.tertiary
)
Column {
@@ -191,25 +225,28 @@ fun HomePage(navCtrl:NavHostController){
HomePageItem(R.string.user_manage,R.drawable.account_circle_fill0,R.string.user_manage_desc,"UserManage",navCtrl)
HomePageItem(R.string.password, R.drawable.password_fill0,R.string.security_desc, "Password",navCtrl)
HomePageItem(R.string.setting, R.drawable.info_fill0, R.string.setting_desc, "AppSetting",navCtrl)
Spacer(Modifier.padding(vertical = 15.dp))
}
}
@Composable
fun HomePageItem(name:Int, imgVector:Int, description:Int, navTo:String, myNav:NavHostController){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 5.dp, horizontal = 8.dp)
.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.primaryContainer)
.clickable(onClick = { myNav.navigate(navTo) })
.padding(6.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = painterResource(imgVector),
contentDescription = null,
modifier = Modifier.padding(horizontal = 10.dp),
modifier = Modifier.padding(horizontal = if(!sharedPref.getBoolean("isWear",false)){10.dp}else{6.dp}),
tint = MaterialTheme.colorScheme.primary
)
Column {
@@ -218,10 +255,12 @@ fun HomePageItem(name:Int, imgVector:Int, description:Int, navTo:String, myNav:N
style = MaterialTheme.typography.headlineSmall,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
Text(
text = stringResource(description),
color = MaterialTheme.colorScheme.onPrimaryContainer
)
if(!sharedPref.getBoolean("isWear",false)){
Text(
text = stringResource(description),
color = MaterialTheme.colorScheme.onPrimaryContainer
)
}
}
}
}
@@ -232,13 +271,14 @@ fun RadioButtonItem(
selected:()->Boolean,
operation:()->Unit
){
val sharedPref = LocalContext.current.getSharedPreferences("data", Context.MODE_PRIVATE)
Row(verticalAlignment = Alignment.CenterVertically,modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(25))
.clickable(onClick = operation)
) {
RadioButton(selected = selected(), onClick = operation)
Text(text)
RadioButton(selected = selected(), onClick = operation,modifier=if(sharedPref.getBoolean("isWear",false)){Modifier.size(28.dp)}else{Modifier})
Text(text = text, style = if(!sharedPref.getBoolean("isWear",false)){MaterialTheme.typography.bodyLarge}else{MaterialTheme.typography.bodyMedium})
}
}
@@ -253,10 +293,19 @@ fun isProfileOwner(dpm:DevicePolicyManager): Boolean {
@SuppressLint("ModifierFactoryExtensionFunction")
@Composable
fun sections(bgColor:Color=MaterialTheme.colorScheme.primaryContainer):Modifier{
return Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp)
.clip(RoundedCornerShape(14.dp))
.background(color = bgColor)
.padding(vertical = 6.dp, horizontal = 10.dp)
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)
.padding(vertical = 6.dp, horizontal = 10.dp)
}else{
Modifier
.fillMaxWidth()
.padding(horizontal = 3.dp, vertical = 3.dp)
.clip(RoundedCornerShape(10.dp))
.background(color = bgColor)
.padding(vertical = 2.dp, horizontal = 3.dp)
}
}