Compose Learning Projects

Compose Learning Projects

 
 

Unit 1

Business Card App

  • Create Business Card in App
  • App to Practice Layout In Android using Jetpack Compose
@Composable fun BuisnessCard() { Column( modifier = Modifier .fillMaxSize() .background(colorResource(id = R.color.LightGreen)), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, ) { Surface(color = colorResource(id = R.color.NavyBlue)) { Image( painter = painterResource(id = R.drawable.android_logo), contentDescription = null, modifier = Modifier .height(150.dp) .width(150.dp) ) } Text( text = stringResource(R.string.name_surname), color = Color.Black, fontSize = 32.sp, modifier = Modifier.padding(8.dp) ) Text( text = "Junior Android Developer", fontWeight = FontWeight.Bold, fontSize = 20.sp, color = colorResource(id = R.color.DarkGreen) ) Spacer(modifier = Modifier.padding(bottom = 200.dp)) ContactRow(text = stringResource(R.string.contact_number), Icons.Rounded.Phone) ContactRow(text = stringResource(R.string.share_link), Icons.Rounded.Share) ContactRow(text = stringResource(R.string.email), Icons.Rounded.Email) } } @Composable fun ContactRow(text: String, icon: ImageVector) { Row( horizontalArrangement = Arrangement.Center, modifier = Modifier.padding(16.dp) ) { Icon( imageVector = icon, contentDescription = null, tint = colorResource(id = R.color.DarkGreen), modifier = Modifier.weight(1.5f) ) Text( text = text, color = Color.Black, modifier = Modifier.weight(3f) ) } }
  • Color.xml
<color name="black">#FF000000</color> <color name="white">#FFFFFFFF</color> <color name="LightGreen">#d2e8d4</color> <color name="DarkGreen">#006d3b</color> <color name="NavyBlue">#073042</color>
  • Strings.xml
<string name="name_surname">Devansh Amdavadwala</string> <string name="contact_number">+91 9429509806</string> <string name="email">devanshamdavadwala@gmail.com</string> <string name="share_link">\@Android Dev</string>

Compose Quadrant App

  • Create Layout that divides Screen into four Sections to Display Data.
  • App to Practice Layout In Android using Jetpack Compose
@Composable fun ComposeQuadrantApp() { val context = LocalContext.current Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Row(Modifier.weight(1f)) { ComposableInfoCard( title = context.getString(R.string.first_title), desc = context.getString(R.string.first_description), backgroundColor = Color(0xFFEADDFF), modifier = Modifier.weight(1f) ) ComposableInfoCard( title = context.getString(R.string.second_title), desc = context.getString(R.string.second_description), backgroundColor = Color(0xFFD0BCFF), modifier = Modifier.weight(1f) ) } Row(Modifier.weight(1f)) { ComposableInfoCard( title = context.getString(R.string.third_title), desc = context.getString(R.string.third_description), backgroundColor = Color(0xFFB69DF8), modifier = Modifier.weight(1f) ) ComposableInfoCard( title = context.getString(R.string.fourth_title), desc = context.getString(R.string.fourth_description), backgroundColor = Color(0xFFF6EDFF), modifier = Modifier.weight(1f) ) } } } @Composable fun ComposableInfoCard(title: String, desc: String, backgroundColor: Color, modifier: Modifier) { Column( modifier = modifier .fillMaxSize() .background(backgroundColor) .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Text( text = title, modifier = Modifier.padding(bottom = 16.dp), fontWeight = FontWeight.Bold ) Text( text = desc, textAlign = TextAlign.Justify ) } }
  • strings.xml
<!-- Compose Quadrant screen --> <string name="first_title">Text composable</string> <string name="first_description">Displays text and follows the recommended Material Design guidelines.</string> <string name="second_title">Image composable</string> <string name="second_description">Creates a composable that lays out and draws a given Painter class object.</string> <string name="third_title">Row composable</string> <string name="third_description">A layout composable that places its children in a horizontal sequence.</string> <string name="fourth_title">Column composable</string> <string name="fourth_description">A layout composable that places its children in a vertical sequence.</string>
 
 

Article Page App

  • App to Learn Design And Use of Widgets In Android using Jetpack Compose.
  • Page to display article using jetpack compose
@Composable fun ComposeArticle(title: String, first: String, last: String) { Column( modifier = Modifier.fillMaxSize() ) { Image( painter = painterResource(id = R.drawable.bg_compose_background), contentDescription = null, ) Text(text = title, fontSize = 24.sp, modifier = Modifier.padding(16.dp)) Text( text = first, textAlign = TextAlign.Justify, modifier = Modifier.padding(start = 16.dp, end = 16.dp) ) Text( text = last, textAlign = TextAlign.Justify, modifier = Modifier.padding(16.dp) ) } }
 
 
  • Files needed in this app.
 
 
 

Birth Day Card App

  • App that will create Birthday card for Your Friends And Family.
  • Learn How to Use Image , Text Widget in Compose
  • Learn How to set Widgets in Layout using Column and Box
@Composable fun MakeCard(message: String, from: String, modifier: Modifier) { val image = painterResource(id = R.drawable.androidparty) Box(modifier) { Image( painter = image, contentDescription = null, contentScale = ContentScale.Crop, alpha = 0.5f, ) } Column( modifier = Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { Text( text = message, style = TextStyle( fontSize = 100.sp, lineHeight = 116.sp, textAlign = TextAlign.Center, fontWeight = FontWeight.Bold ), modifier = Modifier.fillMaxWidth() ) Text( text = from, fontSize = 32.sp, modifier = Modifier .padding(end = 16.dp) .align(alignment = Alignment.End) ) } }
 
 

Unit 2

Dice Roll App

  • Basic math logic , and how app works on Button click
  • Use of remember variable that will hold data in mutable state for app.
  • remember → it will recompose all items where it is used , whenever its value will be change.
// DiceWithButtonAndImage( // modifier = Modifier // .fillMaxSize() // .wrapContentSize(Alignment.Center) // ) @Composable fun DiceWithButtonAndImage(modifier: Modifier = Modifier) { var result by remember { mutableStateOf(1) } val imageResource = when (result) { 1 -> R.drawable.dice_1 2 -> R.drawable.dice_2 3 -> R.drawable.dice_3 4 -> R.drawable.dice_4 5 -> R.drawable.dice_5 else -> R.drawable.dice_6 } Column( modifier = modifier, horizontalAlignment = Alignment.CenterHorizontally, ) { Image(painter = painterResource(id = imageResource), contentDescription = result.toString()) Spacer(modifier = Modifier.height(16.dp)) Button(onClick = { result = (1..6).random() }) { Text(text = stringResource(id = R.string.roll)) } } }
 
 
  • File needed in this app

Create Lemonade App

  • -