Previous slide Next slide Toggle fullscreen Open presenter view
CS 3180 Mobile Application Development
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Today’s Agenda
What is Jetpack Compose? (20 min)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Today’s Agenda (continued)
What is Jetpack Compose? (20 min)
Core Composables (25 min)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Today’s Agenda (continued)
What is Jetpack Compose? (20 min)
Core Composables (25 min)
Layouts with Column/Row/Box (30 min)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Learning Objectives
By the end of today, you will be able to:
Explain declarative UI and how Compose works
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Learning Objectives (continued)
By the end of today, you will be able to:
Explain declarative UI and how Compose works
Build UI using core composables
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Learning Objectives (continued)
By the end of today, you will be able to:
Explain declarative UI and how Compose works
Build UI using core composables
Arrange UI with Column, Row, and Box
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
What is Jetpack Compose?
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
What is Jetpack Compose? (continued)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
What is Jetpack Compose? (continued)
Declarative UI framework
100% Kotlin (no XML)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
What is Jetpack Compose? (continued)
Declarative UI framework
100% Kotlin (no XML)
Official Android UI toolkit (stable since 2021)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
What is Jetpack Compose? (continued)
Declarative UI framework
100% Kotlin (no XML)
Official Android UI toolkit (stable since 2021)
Less code, easier to maintain
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Declarative vs. Imperative
val textView = findViewById<TextView>(R.id.greeting)
textView.text = "Hello, $name "
textView.setTextColor(Color.BLUE)
Text(
text = "Hello, $name " ,
color = Color.Blue
)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Key Compose Principles
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Key Compose Principles (continued)
Composable functions (annotated with @Composable)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Key Compose Principles (continued)
Composable functions (annotated with @Composable)
Data flows down, events flow up
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Key Compose Principles (continued)
Composable functions (annotated with @Composable)
Data flows down, events flow up
Recomposition updates UI automatically
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Key Compose Principles (continued)
Composable functions (annotated with @Composable)
Data flows down, events flow up
Recomposition updates UI automatically
Everything is a function
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Compose Advantages
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Compose Advantages (continued)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Compose Advantages (continued)
Type-safe Kotlin UI
Less boilerplate
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Compose Advantages (continued)
Type-safe Kotlin UI
Less boilerplate
Live Preview in Android Studio
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Compose Advantages (continued)
Type-safe Kotlin UI
Less boilerplate
Live Preview in Android Studio
Interoperable with XML
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Your First Composable
@Composable
fun Greeting (name: String ) {
Text(text = "Hello, $name !" )
}
@Preview
@Composable
fun GreetingPreview () {
Greeting("Android" )
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Text Composable
Text(
text = "Hello, World!" ,
fontSize = 24. sp,
fontWeight = FontWeight.Bold,
color = Color.Blue,
textAlign = TextAlign.Center
)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Image and Icon Composables
Image(
painter = painterResource(R.drawable.logo),
contentDescription = "App logo" ,
modifier = Modifier.size(100. dp)
)
Icon(
imageVector = Icons.Default.Favorite,
contentDescription = "Favorite" ,
tint = Color.Red
)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Button(onClick = { }) {
Text("Click Me" )
}
OutlinedButton(onClick = { }) { Text("Outlined" ) }
TextButton(onClick = { }) { Text("Text Button" ) }
IconButton(onClick = { }) {
Icon(Icons.Default.Add, contentDescription = "Add" )
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
TextField and OutlinedTextField
var text by remember { mutableStateOf("" ) }
TextField(
value = text,
onValueChange = { text = it },
label = { Text("Enter name" ) },
placeholder = { Text("John Doe" ) }
)
OutlinedTextField(
value = text,
onValueChange = { text = it },
label = { Text("Email" ) }
)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Common Composable Patterns
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Common Composable Patterns (continued)
Provide contentDescription for accessibility
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Common Composable Patterns (continued)
Provide contentDescription for accessibility
Use Material Design components when possible
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Common Composable Patterns (continued)
Provide contentDescription for accessibility
Use Material Design components when possible
Composable names use PascalCase
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Common Composable Patterns (continued)
Provide contentDescription for accessibility
Use Material Design components when possible
Composable names use PascalCase
Content is often a trailing lambda
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layouts: Column (Vertical)
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.SpaceBetween,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Top" )
Text("Middle" )
Text("Bottom" )
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layouts: Row (Horizontal)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
Icon(Icons.Default.Home, contentDescription = "Home" )
Icon(Icons.Default.Search, contentDescription = "Search" )
Icon(Icons.Default.Person, contentDescription = "Profile" )
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layouts: Box (Overlapping)
Box(
modifier = Modifier.size(200. dp),
contentAlignment = Alignment.Center
) {
Image(
painter = painterResource(R.drawable.golf_hole),
contentDescription = null ,
modifier = Modifier.fillMaxSize()
)
Text(
text = "Hole 7" ,
color = Color.White,
fontSize = 24. sp,
fontWeight = FontWeight.Bold
)
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Nesting Layouts
Column {
Row {
}
Box {
}
Row {
}
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layout Decision Guide
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layout Decision Guide (continued)
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layout Decision Guide (continued)
Column: vertical stacks
Row: horizontal alignment
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layout Decision Guide (continued)
Column: vertical stacks
Row: horizontal alignment
Box: overlapping content
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Layout Decision Guide (continued)
Column: vertical stacks
Row: horizontal alignment
Box: overlapping content
LazyColumn/Row: scrollable lists
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Activity: Scorecard Grid Layout
Goal: Build a 3-column grid for Hole, Par, Score
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
@Composable
fun ScorecardGrid () {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16. dp),
verticalArrangement = Arrangement.spacedBy(8. dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8. dp)
) {
Text("Hole" , modifier = Modifier.weight(1f ), fontWeight = FontWeight.Bold)
Text("Par" , modifier = Modifier.weight(1f ), fontWeight = FontWeight.Bold)
Text("Score" , modifier = Modifier.weight(1f ), fontWeight = FontWeight.Bold)
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Scorecard Grid: Hole Rows
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8. dp)
) {
HoleButton("1" , Modifier.weight(1f ))
Text("4" , modifier = Modifier.weight(1f ))
ScoreButton("" , Modifier.weight(1f ))
}
}
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
@Composable
fun HoleButton (holeNumber: String , modifier: Modifier = Modifier) {
Button(
onClick = { },
modifier = modifier,
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF2E7D32 )
)
) {
Text(holeNumber, fontSize = 18. sp)
}
}
@Composable
fun ScoreButton (score: String , modifier: Modifier = Modifier) {
OutlinedButton(
onClick = { },
modifier = modifier
) {
Text(score.ifEmpty { "-" }, fontSize = 18. sp)
}
}
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Live Demo Preview
Show the scorecard grid in Preview with 1–2 holes and verify spacing
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Wrap-Up
Compose is declarative and Kotlin-first
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Wrap-Up (continued)
Compose is declarative and Kotlin-first
Core composables build most screens
Week 4 Monday: Jetpack Compose Foundations
CS 3180 Mobile Application Development
Wrap-Up (continued)
Compose is declarative and Kotlin-first
Core composables build most screens
Layouts organize components into a scorecard
Week 4 Monday: Jetpack Compose Foundations
SPEAKER NOTES:
Welcome to Week 4! Today we start Jetpack Compose, the modern UI toolkit for Android.
Hook: "Have you used a modern app that feels smooth and consistent? Compose is the toolkit behind that experience."
Connect to the Hope Foundation golf app: we will build the scorecard UI using Compose throughout this week.
SPEAKER NOTES:
We’ll begin with what Compose is and why it changes how we build UI.
SPEAKER NOTES:
Next, we’ll learn the basic building blocks: Text, Image, Button, and TextField.
SPEAKER NOTES:
Finally, we’ll lay out content like a scorecard using Column, Row, and Box.
SPEAKER NOTES:
We’ll define declarative UI and contrast it with the XML approach you may have seen.
SPEAKER NOTES:
You will build basic UI components with Material Design in Compose.
SPEAKER NOTES:
We’ll design layouts that look like a real golf scorecard.
SPEAKER NOTES:
We'll explore what Jetpack Compose is, one characteristic at a time.
SPEAKER NOTES:
Declarative means we describe the UI we want, not the steps to build it.
SPEAKER NOTES:
Everything is Kotlin: functions, parameters, and type safety. No XML layouts required.
SPEAKER NOTES:
Compose is not experimental—it’s the official toolkit for modern Android apps.
SPEAKER NOTES:
Compose significantly reduces boilerplate and keeps UI logic close to state.
SPEAKER NOTES:
In imperative UI, we mutate a widget after finding it. In Compose, we declare the UI directly from state.
Connect to web frameworks: React/SwiftUI are also declarative.
SPEAKER NOTES:
Compose has four core principles. Let's explore them one at a time.
SPEAKER NOTES:
Composable functions are the building blocks of Compose. The annotation tells the compiler this is UI.
SPEAKER NOTES:
We pass state in via parameters and bubble user actions up with lambdas.
SPEAKER NOTES:
When state changes, Compose reruns affected composables to update the UI.
SPEAKER NOTES:
UI is just functions. That makes it testable and easier to reason about.
SPEAKER NOTES:
Compose offers several advantages over the older XML approach. Let's look at them.
SPEAKER NOTES:
Compile-time errors beat runtime crashes. Kotlin helps here.
SPEAKER NOTES:
Compose replaces dozens of XML lines with a few Kotlin lines.
SPEAKER NOTES:
Preview allows you to see UI without running the whole app.
SPEAKER NOTES:
We can mix Compose with legacy XML when needed, especially in real-world apps.
SPEAKER NOTES:
Highlight `@Composable` and `@Preview`. Demonstrate Preview in Android Studio if possible.
SPEAKER NOTES:
Discuss common styling options and encourage using `MaterialTheme.typography` later.
SPEAKER NOTES:
Emphasize accessibility: always provide `contentDescription` for images and icons.
SPEAKER NOTES:
Call out how each button communicates different emphasis in UI.
SPEAKER NOTES:
Note: `remember` and state are required for text input; we will cover state on Wednesday.
SPEAKER NOTES:
Let's establish best practices for writing composables that are maintainable and professional.
SPEAKER NOTES:
Accessibility is part of professional app development. Screen readers rely on this.
SPEAKER NOTES:
Material components follow Android UI guidelines and help us stay consistent.
SPEAKER NOTES:
This is a Kotlin convention you’ll see everywhere in Compose code.
SPEAKER NOTES:
Show how Kotlin’s trailing lambda syntax keeps UI code readable.
SPEAKER NOTES:
Column stacks items vertically. We’ll use this for screens and forms.
SPEAKER NOTES:
Row is perfect for navigation bars, button groups, and alignment of controls.
SPEAKER NOTES:
Box is used for overlays: text on images, badges, and floating buttons.
SPEAKER NOTES:
Layouts can be nested to build complex UIs. Compose encourages small, reusable blocks.
SPEAKER NOTES:
Each layout serves a specific purpose. Let's learn when to use each one.
SPEAKER NOTES:
Use Column for forms, lists of fields, or stacked sections.
SPEAKER NOTES:
Use Row for navigation, toolbars, and button groups.
SPEAKER NOTES:
Use Box when you need content layered on top of other content.
SPEAKER NOTES:
Lazy lists are for long data sets. We will cover these soon.
SPEAKER NOTES:
Students will sketch a simple scorecard layout that mirrors a real golf card.
SPEAKER NOTES:
Show how `weight(1f)` creates equal column widths.
SPEAKER NOTES:
Emphasize the pattern. Students repeat the row for holes 2-9.
SPEAKER NOTES:
Use Hope Foundation green for the hole buttons. Talk about consistency and branding.
SPEAKER NOTES:
If time allows, display the Preview and adjust spacing or font sizes.
SPEAKER NOTES:
Summarize the key point: Compose uses functions to describe the UI.
SPEAKER NOTES:
Text, Image, Button, TextField are your main tools this week.
SPEAKER NOTES:
We now have the building blocks for the Hope Foundation scorecard.
Preview the plan for Wednesday: state and interactivity.