CS 3180 Mobile Application Development

Week 5 Wednesday: Material Design 3 Theming

CS 3180 Mobile Application Development

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Today's Agenda

  1. Material Design 3 fundamentals (15 min)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Today's Agenda (continued)

  1. Material Design 3 fundamentals (15 min)
  2. Creating the Hope Foundation theme (20 min)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Today's Agenda (continued)

  1. Material Design 3 fundamentals (15 min)
  2. Creating the Hope Foundation theme (20 min)
  3. Building adaptive layouts (15 min)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Part 1: Material Design 3

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

What is Material Design?

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

What is Material Design? (continued)

  • Google's design system for consistency
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

What is Material Design? (continued)

  • Google's design system for consistency
  • Material 3 is the current version (2021+)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

What is Material Design? (continued)

  • Google's design system for consistency
  • Material 3 is the current version (2021+)
  • Material You: personalization from device theme
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

What is Material Design? (continued)

  • Google's design system for consistency
  • Material 3 is the current version (2021+)
  • Material You: personalization from device theme
  • Includes components, colors, typography, shapes
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Components in Jetpack Compose

import androidx.compose.material3.*  // ✅ Use this

// NOT this:
import androidx.compose.material.*   // ❌ Old (Material 2)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material Theme Structure

MaterialTheme(
    colorScheme = ...,    // Colors (primary, error, etc.)
    typography = ...,     // Text styles
    shapes = ...          // Corner radii
) {
    // Your UI here
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Accessing Theme Values in Compose

@Composable
fun ThemedScorecard() {
    Text(
        text = "Charity Golf Tracker",
        color = MaterialTheme.colorScheme.primary,
        style = MaterialTheme.typography.headlineMedium
    )
    
    Surface(
        color = MaterialTheme.colorScheme.primaryContainer,
        shape = MaterialTheme.shapes.medium
    ) {
        Text("Team Score: 72")
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Part 2: Hope Foundation Brand Theme

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Color Roles

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Color Roles (continued)

Primary Colors (Hope Foundation Green)

  • primary: Main brand color (buttons, accents)
  • onPrimary: Text/icons on primary background
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Color Roles (continued)

Primary Colors (Hope Foundation Green)

  • primary: Main brand color (buttons, accents)
  • onPrimary: Text/icons on primary background
  • primaryContainer: Lighter primary (chips, badges)
  • onPrimaryContainer: Text on primaryContainer
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Color Roles (continued)

Secondary Colors (Hope Foundation Gold)

  • secondary: Complementary accent
  • secondaryContainer: Lighter secondary
  • onSecondary, onSecondaryContainer: Text colors
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Material 3 Color Roles (continued)

Surface & Error Colors

  • surface: Background for components
  • onSurface: Text on surface
  • error: Error states (over-par scores!)
  • onError: Text on error background
  • background, onBackground: Screen background
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 1: Define Hope Foundation Colors

// theme/Color.kt

val HopeGreen = Color(0xFF2E7D32)
val HopeGold = Color(0xFFFFC107)

// Light theme
val md_theme_light_primary = Color(0xFF2E7D32)
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val md_theme_light_primaryContainer = Color(0xFFB8F5B0)

val md_theme_light_secondary = Color(0xFF7D5800)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFFFDEA6)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 2: Define Dark Theme Colors

// Dark theme variants
val md_theme_dark_primary = Color(0xFF9DD996)
val md_theme_dark_onPrimary = Color(0xFF00390C)
val md_theme_dark_primaryContainer = Color(0xFF0B5319)

val md_theme_dark_secondary = Color(0xFFF5BE48)
val md_theme_dark_onSecondary = Color(0xFF422D00)
val md_theme_dark_secondaryContainer = Color(0xFF5F4100)

val md_theme_dark_error = Color(0xFFFFB4AB)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 3: Create Color Schemes

// theme/Theme.kt

val HopeFoundationLightColorScheme = lightColorScheme(
    primary = Color(0xFF2E7D32),
    onPrimary = Color.White,
    primaryContainer = Color(0xFFB8F5B0),
    secondary = Color(0xFF7D5800),
    onSecondary = Color.White,
    secondaryContainer = Color(0xFFFFDEA6),
    error = Color(0xFFBA1A1A),
    background = Color(0xFFFCFDF6),
    surface = Color(0xFFFCFDF6)
)

val HopeFoundationDarkColorScheme = darkColorScheme(
    primary = Color(0xFF9DD996),
    onPrimary = Color(0xFF00390C),
    primaryContainer = Color(0xFF0B5319),
    secondary = Color(0xFFF5BE48),
    error = Color(0xFFFFB4AB),
    background = Color(0xFF1A1C19),
    surface = Color(0xFF1A1C19)
)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 4: Create Theme Composable

@Composable
fun CharityGolfTrackerTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colorScheme = if (darkTheme) {
        HopeFoundationDarkColorScheme
    } else {
        HopeFoundationLightColorScheme
    }
    
    MaterialTheme(
        colorScheme = colorScheme,
        typography = GolfTypography,
        shapes = GolfShapes,
        content = content
    )
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 5: Define Typography for Golf App

// theme/Type.kt

val GolfTypography = Typography(
    headlineMedium = TextStyle(
        fontWeight = FontWeight.SemiBold,
        fontSize = 28.sp,
        lineHeight = 36.sp
    ),
    titleLarge = TextStyle(
        fontWeight = FontWeight.Bold,
        fontSize = 22.sp
    ),
    bodyLarge = TextStyle(
        fontWeight = FontWeight.Normal,
        fontSize = 16.sp
    ),
    // Large font for scores (outdoor visibility!)
    labelLarge = TextStyle(
        fontWeight = FontWeight.Bold,
        fontSize = 24.sp
    )
)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 6: Define Shapes

// theme/Shape.kt

val GolfShapes = Shapes(
    small = RoundedCornerShape(8.dp),    // Score badges
    medium = RoundedCornerShape(12.dp),  // Cards
    large = RoundedCornerShape(16.dp)    // Dialogs
)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Step 7: Wrap Your App in Theme

@Composable
fun ScorecardScreen() {
    CharityGolfTrackerTheme {
        Scaffold(
            topBar = {
                TopAppBar(
                    title = { Text("Scorecard") },
                    colors = TopAppBarDefaults.topAppBarColors(
                        containerColor = 
                            MaterialTheme.colorScheme.primaryContainer,
                        titleContentColor = 
                            MaterialTheme.colorScheme.onPrimaryContainer
                    )
                )
            }
        ) { padding ->
            Column(modifier = Modifier.padding(padding)) {
                // Your scorecard content
            }
        }
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Testing Light and Dark Themes

@Preview(name = "Light Mode")
@Preview(
    name = "Dark Mode",
    uiMode = Configuration.UI_MODE_NIGHT_YES
)
@Composable
fun ScorecardPreview() {
    CharityGolfTrackerTheme {
        ScorecardScreen()
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Using Material Theme Builder

Steps:

  1. Go to Material Theme Builder
  2. Enter Hope Green (#2E7D32) as primary color
  3. Enter Hope Gold (#FFC107) as secondary color
  4. View generated colors for light and dark modes
  5. Export as Jetpack Compose code
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Part 3: Adaptive Layouts

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Why Adaptive Layouts Matter

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Why Adaptive Layouts Matter (continued)

  • Users rotate their devices
  • Some users have tablets
  • Foldables have multiple configurations
  • Different screen sizes need different layouts
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Window Size Classes

val widthSizeClass: WindowWidthSizeClass
val heightSizeClass: WindowHeightSizeClass

Width classes:

  • Compact: < 600dp (phones)
  • Medium: 600-839dp (tablets, landscape phones)
  • Expanded: >= 840dp (large tablets, desktops)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Height classes:

Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Height classes: (continued)

  • Compact: < 480dp (small height)
  • Medium: 480-899dp (typical phones)
  • Expanded: >= 900dp (tablets in landscape)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Detecting Window Size

@Composable
fun ResponsiveScorecardScreen(
    windowWidthClass: WindowWidthSizeClass
) {
    when (windowWidthClass) {
        WindowWidthSizeClass.Compact -> {
            // Phone layout: single column
            ScorecardPhoneLayout()
        }
        WindowWidthSizeClass.Medium -> {
            // Landscape phone or small tablet
            ScorecardMediumLayout()
        }
        WindowWidthSizeClass.Expanded -> {
            // Tablet layout
            ScorecardTabletLayout()
        }
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Example: Phone Layout (Compact Width)

@Composable
fun ScorecardPhoneLayout() {
    Column(modifier = Modifier.fillMaxSize()) {
        // Single column of holes
        LazyColumn(modifier = Modifier.weight(1f)) {
            items(9) { index ->
                HoleScoreRow(
                    holeNumber = index + 1,
                    par = pars[index],
                    strokes = scores[index]
                )
            }
        }
        
        // Summary at bottom
        ScoreSummary(totalScore, scoreVsPar)
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Example: Tablet Layout (Expanded Width)

@Composable
fun ScorecardTabletLayout() {
    Row(modifier = Modifier.fillMaxSize()) {
        // Holes on left, summary on right
        LazyColumn(modifier = Modifier.weight(1f)) {
            items(9) { index ->
                HoleScoreRow(
                    holeNumber = index + 1,
                    par = pars[index],
                    strokes = scores[index]
                )
            }
        }
        
        Divider(modifier = Modifier
            .fillMaxHeight()
            .width(1.dp)
        )
        
        // Fixed summary panel on right
        ScoreSummaryPanel(
            modifier = Modifier
                .width(250.dp)
                .padding(16.dp)
        )
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Key Principles for Adaptive UI

  1. Test on multiple device sizes
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Key Principles for Adaptive UI (continued)

  1. Test on multiple device sizes
  2. Use fillMaxSize(), fillMaxWidth(), weight()
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Key Principles for Adaptive UI (continued)

  1. Test on multiple device sizes
  2. Use fillMaxSize(), fillMaxWidth(), weight()
  3. Nest Column/Row appropriately
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Key Principles for Adaptive UI (continued)

  1. Test on multiple device sizes
  2. Use fillMaxSize(), fillMaxWidth(), weight()
  3. Nest Column/Row appropriately
  4. Use LazyColumn/LazyRow for long lists
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Key Principles for Adaptive UI (continued)

  1. Test on multiple device sizes
  2. Use fillMaxSize(), fillMaxWidth(), weight()
  3. Nest Column/Row appropriately
  4. Use LazyColumn/LazyRow for long lists
  5. Test landscape and portrait orientations
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Putting It Together: Complete Themed Scorecard

@Composable
fun App() {
    CharityGolfTrackerTheme {
        val windowWidthClass = 
            calculateWindowSizeClass(
                LocalContext.current
            ).widthSizeClass
        
        Scaffold(
            topBar = {
                TopAppBar(
                    title = { Text("Golf Tracker") },
                    colors = TopAppBarDefaults
                        .topAppBarColors(
                            containerColor = 
                                MaterialTheme.colorScheme
                                    .primaryContainer
                        )
                )
            }
        ) { padding ->
            when (windowWidthClass) {
                WindowWidthSizeClass.Compact ->
                    ScorecardPhoneLayout()
                WindowWidthSizeClass.Medium ->
                    ScorecardMediumLayout()
                WindowWidthSizeClass.Expanded ->
                    ScorecardTabletLayout()
            }
        }
    }
}
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Summary: Building Professional Apps

Three pillars:

  1. State management (ViewModels)
  2. Visual design (Material Theme)
  3. Responsive layouts (Window Size Classes)
Week 5 Wednesday: Material Design 3 Theming
CS 3180 Mobile Application Development

Friday: Implementation Time

  • Apply what you've learned to your scorecard
  • Add ViewModel for state persistence
  • Apply Hope Foundation theme
  • Test on multiple screen sizes
  • No new lecture—hands-on work session
Week 5 Wednesday: Material Design 3 Theming

SPEAKER NOTES: Welcome to Wednesday's demo! Yesterday we solved the critical data persistence problem with ViewModels. Today we make the scorecard look professional using Material Design 3 and the Hope Foundation brand identity. Hook: "Your app works, but does it feel like Hope Foundation? Let's add their brand." Context: Maria wants the scorecard to feel like part of the Hope Foundation family. We'll apply their official colors (green #2E7D32, gold #FFC107) and create a cohesive, professional design.

SPEAKER NOTES: We'll start with the principles and components of Material Design 3.

SPEAKER NOTES: Then we'll use the Material Theme Builder to generate colors for the Hope Foundation brand.

SPEAKER NOTES: Finally, we'll make the scorecard responsive to different screen sizes and orientations.

SPEAKER NOTES: Material Design is Google's design system. Material 3 (M3) is the latest version, and it powers modern Android apps.

SPEAKER NOTES: Material Design is a comprehensive design system created by Google.

SPEAKER NOTES: When every Android app follows the same design patterns, users have a familiar experience. They know how buttons work, how to navigate, what interactions mean what.

SPEAKER NOTES: Material 2 was used for years, but Material 3 introduced Material You with dynamic colors and better personalization.

SPEAKER NOTES: Material You can automatically extract colors from a device's wallpaper (on Android 12+). But we can override this with brand colors.

SPEAKER NOTES: Material Design provides templates for every UI element: buttons, cards, navigation, dialogs, etc.

SPEAKER NOTES: Make sure you import from `material3`, not `material`. We're using Material 3. Available components: - Button, FilledButton, OutlinedButton, TextButton - Card, ElevatedCard, OutlinedCard - TextField, OutlinedTextField - TopAppBar, BottomAppBar - NavigationBar, NavigationRail - FloatingActionButton - Scaffold (for layout structure) - And many more...

SPEAKER NOTES: MaterialTheme is a composable that provides theme values to all components inside it. Any component can access these values using MaterialTheme.colorScheme, MaterialTheme.typography, etc.

SPEAKER NOTES: Notice we never hardcode colors or text styles. We always use MaterialTheme values. This way, when the theme changes (dark mode, brand update), the entire app updates automatically.

SPEAKER NOTES: Now let's create a theme that represents the Hope Foundation brand identity.

SPEAKER NOTES: Material 3 has specific color roles. Each has a purpose.

SPEAKER NOTES: Primary is the dominant brand color. For Hope Foundation, that's their green #2E7D32. OnPrimary is the color of text/icons that appear on top of the primary color.

SPEAKER NOTES: PrimaryContainer is a lighter shade used for less prominent elements. OnPrimaryContainer is the text color for that container.

SPEAKER NOTES: Secondary is typically a complementary color. For Hope Foundation, that's their gold #FFC107.

SPEAKER NOTES: Error is important for golf scoring. We can use error color to show scores above par.

SPEAKER NOTES: We define: 1. The brand colors (Hope Green, Hope Gold) 2. All the theme color variants for light mode These aren't random—they're generated using color theory to ensure readability and accessibility.

SPEAKER NOTES: Dark mode colors are different from light mode. We use lighter shades because the background is dark. The gold becomes more peachy to be readable on black. This is generated using Material Theme Builder, which ensures proper contrast.

SPEAKER NOTES: We create complete color schemes using the lightColorScheme and darkColorScheme builder functions. These handle all the color roles at once.

SPEAKER NOTES: This composable wraps the app theme. It checks if the system is in dark mode and uses the appropriate color scheme. We pass typography and shapes (we'll define those next) to complete the theme.

SPEAKER NOTES: Typography in Material Design has specific roles: displayLarge, headlineMedium, titleLarge, bodyLarge, etc. Note labelLarge is extra large (24sp) because golf scores need to be visible in bright sunlight. This is a real-world consideration for this app.

SPEAKER NOTES: Material Design shapes define corner radii. Small corners look modern, while larger corners feel more relaxed. We use these shapes consistently across the app.

SPEAKER NOTES: Wrap your screen content in CharityGolfTrackerTheme. Now all components automatically use the Hope Foundation colors. Notice: we use MaterialTheme.colorScheme.primaryContainer for the top bar background. We never hardcode colors.

SPEAKER NOTES: Use @Preview annotations with different uiMode values to see both light and dark themes. This ensures your design works in both modes. In Android Studio, you'll see both preview windows side by side.

SPEAKER NOTES: Material Theme Builder does all the color science for you. It generates harmonious color palettes and ensures proper contrast for accessibility. You don't have to manually define all the colors—the builder generates them!

SPEAKER NOTES: Material Design 3 isn't just about colors. It also includes responsive design patterns. Our scorecard needs to work on phones, tablets, and foldable devices.

SPEAKER NOTES: The Hope Foundation app might be used on: - Small phones (4.5 inches) - Large phones (6+ inches) - Tablets (10 inches) - Foldables (depends on fold state) We need to adapt the layout for each.

SPEAKER NOTES: A layout that looks great on a portrait phone might be cramped on a landscape tablet. We need to respond to these changes.

SPEAKER NOTES: Android provides WindowSizeClass to detect screen size at runtime. We can use this to adapt our layout. These aren't arbitrary numbers—they're breakpoints where UI patterns typically change.

SPEAKER NOTES: Height matters too, though it's less commonly used.

SPEAKER NOTES: A compact height means limited vertical space. A scrollable layout might be needed.

SPEAKER NOTES: At the root of your app, detect the window size and choose the appropriate layout.

SPEAKER NOTES: On a phone, we use a single column. The holes are scrollable, and the summary is fixed at the bottom.

SPEAKER NOTES: On a tablet, we have enough width for a two-column layout. Holes on the left, always-visible summary on the right.

SPEAKER NOTES: Use Android Studio's preview to test on phone, tablet, foldable sizes.

SPEAKER NOTES: These modifiers make layouts flexible. Never hardcode pixel widths—use layout weights instead.

SPEAKER NOTES: Column for vertical stacking, Row for horizontal. Nest them as needed.

SPEAKER NOTES: These are lazy composables—they only compose the visible items, saving memory.

SPEAKER NOTES: Rotation is a configuration change, but now your ViewModel preserves state while the layout adapts.

SPEAKER NOTES: This is the complete picture: 1. The app is wrapped in CharityGolfTrackerTheme 2. We detect the window size 3. We choose the appropriate layout 4. All colors come from the theme 5. ViewModel preserves state across all these changes Maria's scorecard now: - Survives rotation and configuration changes ✓ - Uses Hope Foundation colors ✓ - Works on any device size ✓ - Looks professional ✓

SPEAKER NOTES: These three things together create a professional, production-quality app that works everywhere: - Data isn't lost when the screen rotates - The app looks cohesive and branded - The interface adapts to different devices Next week we'll add lists and navigation to this foundation!

SPEAKER NOTES: Friday you'll do the real work. Start from the template, add ViewModel, add theming, make it adaptive. Come with questions. I'll circulate and help debug issues.