Last active
December 12, 2022 16:06
-
-
Save cyril-tl/48768a7573262ab3d10072dc6d52cbfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.myapp | |
| import android.os.Bundle | |
| import androidx.activity.ComponentActivity | |
| import androidx.activity.compose.setContent | |
| import androidx.compose.foundation.layout.* | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.mutableStateOf | |
| import androidx.compose.runtime.remember | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.tooling.preview.Preview | |
| import com.example.lenotificateur.ui.theme.LeNotificateurTheme | |
| import androidx.compose.foundation.selection.toggleable | |
| import androidx.compose.material.* | |
| import androidx.compose.runtime.MutableState | |
| import androidx.compose.ui.Alignment | |
| import androidx.compose.ui.semantics.Role | |
| import androidx.compose.ui.unit.dp | |
| class MainActivity : ComponentActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContent { | |
| LeNotificateurTheme { | |
| // A surface container using the 'background' color from the theme | |
| Surface( | |
| modifier = Modifier.fillMaxSize(), | |
| color = MaterialTheme.colors.background | |
| ) { | |
| Greeting("Android") | |
| } | |
| } | |
| } | |
| } | |
| } | |
| @Composable | |
| fun Greeting(name: String) { | |
| Column( | |
| Modifier.fillMaxWidth(), | |
| horizontalAlignment = Alignment.CenterHorizontally, | |
| verticalArrangement = Arrangement.Center | |
| ) { | |
| Text(text = "Hello $name!") | |
| SettingsView() | |
| } | |
| } | |
| @Composable | |
| fun SettingsView() { | |
| // CheckBoxDemo(name = "channel default") | |
| // CheckBoxDemo(name = "channel alert") | |
| // val checkedStateSwitch = remember { mutableStateOf(true) } Switch( | |
| // checked = checkedStateSwitch.value, | |
| // onCheckedChange = { checkedStateSwitch.value = it } | |
| // ) | |
| var switchTableLog = remember { mutableStateOf(true) } | |
| SwitchDemo("Alertes table log?", switchTableLog) | |
| var switchTableLogTravail = remember { mutableStateOf(true) } | |
| SwitchDemo("Alertes table log travail?", switchTableLogTravail) | |
| var switchOthers = remember { mutableStateOf(true) } | |
| SwitchDemo("Autres alertes", switchOthers) | |
| } | |
| @Composable | |
| fun SwitchDemo(text: String, mutableBool: MutableState<Boolean>) { | |
| Row( | |
| Modifier | |
| .fillMaxWidth(1f) | |
| .height(64.dp) | |
| .toggleable( | |
| role = Role.Switch, | |
| value = mutableBool.value, | |
| onValueChange = { mutableBool.value = it }, | |
| ) | |
| ) { | |
| Column( | |
| modifier = Modifier.fillMaxHeight(), | |
| verticalArrangement = Arrangement.Center | |
| ) { | |
| Text( | |
| modifier = Modifier | |
| .padding(start = 16.dp), | |
| text = text | |
| ) | |
| } | |
| Spacer(Modifier.weight(1f)) | |
| Column( | |
| modifier = Modifier.fillMaxHeight(), | |
| verticalArrangement = Arrangement.Center | |
| ) { | |
| Switch( | |
| modifier = Modifier.padding(end = 8.dp), | |
| checked = mutableBool.value, onCheckedChange = null | |
| ) | |
| } | |
| } | |
| } | |
| @Composable | |
| fun CheckBoxDemo(name: String) { | |
| val checkedState = remember { mutableStateOf(true) } | |
| Row() { | |
| Checkbox( | |
| checked = checkedState.value, | |
| onCheckedChange = { checkedState.value = it }, | |
| enabled = true | |
| ) | |
| Text(text = name) | |
| } | |
| } | |
| @Preview(showBackground = true) | |
| @Composable | |
| fun DefaultPreview() { | |
| LeNotificateurTheme { | |
| Greeting("Android") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment