mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-23 01:14:26 +01:00
Modify home screen items.
This commit is contained in:
@@ -5,11 +5,7 @@ import androidx.annotation.StringRes
|
|||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -17,37 +13,64 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
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.unit.dp
|
||||||
|
import no.nordicsemi.android.theme.view.ScreenSection
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FeatureButton(@DrawableRes iconId: Int, @StringRes nameId: Int, onClick: () -> Unit) {
|
fun FeatureButton(
|
||||||
Row(
|
@DrawableRes iconId: Int,
|
||||||
|
@StringRes nameCode: Int,
|
||||||
|
@StringRes name: Int,
|
||||||
|
onClick: () -> Unit
|
||||||
|
) {
|
||||||
|
ScreenSection {
|
||||||
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
.height(150.dp)
|
||||||
.clickable { onClick() }
|
.clickable { onClick() }
|
||||||
.background(MaterialTheme.colorScheme.background)
|
.background(MaterialTheme.colorScheme.background)
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = nameCode),
|
||||||
|
style = MaterialTheme.typography.labelMedium
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(iconId),
|
painter = painterResource(iconId),
|
||||||
contentDescription = stringResource(id = nameId),
|
contentDescription = stringResource(id = name),
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
|
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSecondary),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(64.dp)
|
.size(64.dp)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(Color.White)
|
.background(MaterialTheme.colorScheme.secondary)
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = name),
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(id = nameId))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
private fun FeatureButtonPreview() {
|
||||||
|
FeatureButton(R.drawable.ic_csc, R.string.csc_module, R.string.csc_module_full) { }
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ package no.nordicsemi.android.nrftoolbox
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
import androidx.activity.compose.LocalOnBackPressedDispatcherOwner
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||||
@@ -60,7 +58,7 @@ internal fun HomeScreen() {
|
|||||||
composable(NavDestination.RSCS.id) { RSCSScreen { viewModel.navigateUp() } }
|
composable(NavDestination.RSCS.id) { RSCSScreen { viewModel.navigateUp() } }
|
||||||
composable(NavDestination.CGMS.id) { CGMScreen { viewModel.navigateUp() } }
|
composable(NavDestination.CGMS.id) { CGMScreen { viewModel.navigateUp() } }
|
||||||
composable(NavDestination.REQUEST_PERMISSION.id) { RequestPermissionScreen(continueAction) }
|
composable(NavDestination.REQUEST_PERMISSION.id) { RequestPermissionScreen(continueAction) }
|
||||||
composable(NavDestination.BLUETOOTH_NOT_AVAILABLE.id) { BluetoothNotAvailableScreen{ viewModel.finish() } }
|
composable(NavDestination.BLUETOOTH_NOT_AVAILABLE.id) { BluetoothNotAvailableScreen { viewModel.finish() } }
|
||||||
composable(NavDestination.BLUETOOTH_NOT_ENABLED.id) {
|
composable(NavDestination.BLUETOOTH_NOT_ENABLED.id) {
|
||||||
BluetoothNotEnabledScreen(continueAction)
|
BluetoothNotEnabledScreen(continueAction)
|
||||||
}
|
}
|
||||||
@@ -91,22 +89,127 @@ fun HomeView(callback: (NavDestination) -> Unit) {
|
|||||||
(context as? Activity)?.finish()
|
(context as? Activity)?.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
|
Column(
|
||||||
FeatureButton(R.drawable.ic_csc, R.string.csc_module) { callback(NavDestination.CSC) }
|
modifier = Modifier
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
.fillMaxSize()
|
||||||
FeatureButton(R.drawable.ic_hrs, R.string.hrs_module) { callback(NavDestination.HRS) }
|
.padding(horizontal = 16.dp)
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
.verticalScroll(rememberScrollState())
|
||||||
FeatureButton(R.drawable.ic_gls, R.string.gls_module) { callback(NavDestination.GLS) }
|
) {
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
FeatureButton(R.drawable.ic_hts, R.string.hts_module) { callback(NavDestination.HTS) }
|
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
FeatureButton(R.drawable.ic_bps, R.string.bps_module) { callback(NavDestination.BPS) }
|
Box(
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
modifier = Modifier
|
||||||
FeatureButton(R.drawable.ic_rscs, R.string.rscs_module) { callback(NavDestination.RSCS) }
|
.weight(1f)
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
.fillMaxSize(),
|
||||||
FeatureButton(R.drawable.ic_prx, R.string.prx_module) { callback(NavDestination.PRX) }
|
contentAlignment = Alignment.Center
|
||||||
Spacer(modifier = Modifier.height(1.dp))
|
) {
|
||||||
FeatureButton(R.drawable.ic_cgm, R.string.cgm_module) { callback(NavDestination.CGMS) }
|
FeatureButton(
|
||||||
|
R.drawable.ic_csc,
|
||||||
|
R.string.csc_module,
|
||||||
|
R.string.csc_module_full
|
||||||
|
) { callback(NavDestination.CSC) }
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_hrs, R.string.hrs_module,
|
||||||
|
R.string.hrs_module_full
|
||||||
|
) { callback(NavDestination.HRS) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_gls, R.string.gls_module,
|
||||||
|
R.string.gls_module_full
|
||||||
|
) { callback(NavDestination.GLS) }
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_hts, R.string.hts_module,
|
||||||
|
R.string.hts_module_full
|
||||||
|
) { callback(NavDestination.HTS) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_bps, R.string.bps_module,
|
||||||
|
R.string.bps_module_full
|
||||||
|
) { callback(NavDestination.BPS) }
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_rscs,
|
||||||
|
R.string.rscs_module,
|
||||||
|
R.string.rscs_module_full
|
||||||
|
) { callback(NavDestination.RSCS) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_prx, R.string.prx_module,
|
||||||
|
R.string.prx_module_full
|
||||||
|
) { callback(NavDestination.PRX) }
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
FeatureButton(
|
||||||
|
R.drawable.ic_cgm, R.string.cgm_module,
|
||||||
|
R.string.cgm_module_full
|
||||||
|
) { callback(NavDestination.CGMS) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class MainActivity : NordicActivity() {
|
|||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
NordicTheme {
|
NordicTheme {
|
||||||
Surface(color = MaterialTheme.colorScheme.background) {
|
Surface(color = MaterialTheme.colorScheme.surface) {
|
||||||
HomeScreen()
|
HomeScreen()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="csc_module">CSC</string>
|
<string name="csc_module">CSC</string>
|
||||||
|
<string name="csc_module_full">Cyclic Speed and Cadence</string>
|
||||||
<string name="hrs_module">HRS</string>
|
<string name="hrs_module">HRS</string>
|
||||||
|
<string name="hrs_module_full">Heart Rate</string>
|
||||||
<string name="gls_module">GLS</string>
|
<string name="gls_module">GLS</string>
|
||||||
|
<string name="gls_module_full">Glucose</string>
|
||||||
<string name="hts_module">HTS</string>
|
<string name="hts_module">HTS</string>
|
||||||
|
<string name="hts_module_full">Health Thermometer</string>
|
||||||
<string name="bps_module">BPS</string>
|
<string name="bps_module">BPS</string>
|
||||||
|
<string name="bps_module_full">Blood presure</string>
|
||||||
<string name="rscs_module">RSCS</string>
|
<string name="rscs_module">RSCS</string>
|
||||||
|
<string name="rscs_module_full">Running Speed and Cadence</string>
|
||||||
<string name="prx_module">PRX</string>
|
<string name="prx_module">PRX</string>
|
||||||
|
<string name="prx_module_full">Proximity</string>
|
||||||
<string name="cgm_module">CGMS</string>
|
<string name="cgm_module">CGMS</string>
|
||||||
|
<string name="cgm_module_full">Continuous Glucose</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package no.nordicsemi.android.theme.view
|
package no.nordicsemi.android.theme.view
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import no.nordicsemi.android.material.you.Card
|
import no.nordicsemi.android.material.you.Card
|
||||||
|
|
||||||
@@ -14,9 +12,9 @@ fun ScreenSection(content: @Composable () -> Unit) {
|
|||||||
Card(
|
Card(
|
||||||
backgroundColor = MaterialTheme.colorScheme.background,
|
backgroundColor = MaterialTheme.colorScheme.background,
|
||||||
shape = RoundedCornerShape(4.dp),
|
shape = RoundedCornerShape(4.dp),
|
||||||
elevation = 0.dp
|
elevation = 0.dp,
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(16.dp)) {
|
Column {
|
||||||
content()
|
content()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ include ':lib_service'
|
|||||||
include ':lib_theme'
|
include ':lib_theme'
|
||||||
include ':lib_utils'
|
include ':lib_utils'
|
||||||
|
|
||||||
|
if (file('../Android-Common-Libraries').exists()) {
|
||||||
|
includeBuild('../Android-Common-Libraries')
|
||||||
|
}
|
||||||
|
|
||||||
//if (file('../Android-BLE-Library').exists()) {
|
//if (file('../Android-BLE-Library').exists()) {
|
||||||
// includeBuild('../Android-BLE-Library')
|
// includeBuild('../Android-BLE-Library')
|
||||||
//}
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user