Intro to Android Development
  • Welcome
  • Syllabus
  • Hack Challenge
  • Resources
    • Lecture Videos
    • Ed Discussion
    • Git & GitHub Help/How-To
    • Setting up Android Studio
    • Starting an Android Studio Project & Making an Emulator
    • Importing, Exporting, & Submitting Your Projects to CMS
  • SP25 Course Material
    • Week 1 | Course Logistics, Kotlin, & Basic UI
      • Relevant Links
      • Demo/Lecture: Eatery Card
      • A0: Eatery Card (Follow-Along)
    • Week 2 | States, Components, LazyColumn
      • Relevant Links
      • Demo: Todo List
      • A2: Shopping List
    • Week 3 | Navigation & Animations
      • Relevant Links
      • Demo: Onboarding
      • A3: Stock Trading (RobbingGood)
    • Week 4 | MVVM and Flows
      • Relevant Links
      • Demo: Eatery Card 2
      • A4: Chat of a Lifetime
    • Week 5 | Dumb Components & UIEvents
      • Relevant Links
      • Demo: Music Player
      • A5: Rate My Vibe
    • Week 6 | Coroutines, Networking, JSON
      • Relevant Links
      • Demo: Retrofit
      • A6: You Should Even Lift, Bro.
  • Bonus Week | Android Job Search
    • Relevant Links
    • Android Technical Interview Question!
  • Textbook
    • 1. Introduction to the Editor and Views
      • 1.1 Introduction to the Editor
      • 1.2 SDK Management
      • 1.3 Kotlin Overview
      • 1.4 Views
      • 1.5 Android Studio Project Demo + Understanding The Editor
    • 2. Jetpack Compose
      • 2.1 Introduction
      • 2.2 Layouts
      • 2.3 Modifiers
      • 2.4 Animations
      • 2.5 Lazy Lists
      • 2.6 Reactive UI
    • 3. Intents and Manifest
      • 3.1 Activities
      • 3.2 Implicit Intents
      • 3.3 Explicit Intents
      • 3.4 Manifest
      • 3.5 Permissions
      • 3.6 Summary
    • 4. Navigation
      • 4.1 Types of Navigation
      • 4.2 Implementation of the Bottom Navigation Bar
    • 5. Data and Persistent Storage
      • 5.1 Singleton Classes
      • 5.2 Shared Preferences
      • 5.3 Rooms
      • 5.4 Entities
      • 5.5 Data Access Objects
      • 5.6 Databases
    • 5.5 Concurrency
      • 5.5.1 Coroutines
      • 5.5.2 Implementation of Coroutines
      • 5.5.3 Coroutines with Networking Calls
    • 6. Networking and 3rd Party libraries
      • 6.1 HTTP Overview
      • 6.2 3rd Party Libraries
      • 6.3 JSON and Moshi
      • 6.4 Retrofit
      • 6.5 Summary
    • 7. MVVM Design Pattern
      • 7.1 Key Idea
      • 7.2 Implementation Ideas
    • 8. Flows
    • 9. The Art and Ontology of Software
    • 10. 🔥 Firebase
      • 10.1 Setting up Firebase
      • 10.2 Authentication
      • 10.3 Analytics
      • 10.4 Messaging
      • 10.5 Firestore
  • Additional Topics
    • Git and GitHub
    • Exporting to APK
  • Archive
    • Archived Native Android Textbook Pages
      • 1. Layouts and More Views
        • 1.1 File Structure and File Types
        • 1.2 Resource Files
        • 1.3 Button and Input Control
        • 1.4 ViewGroups
        • 1.5 Summary + A Note On Chapter 2 Topics
      • 2. RecyclerViews
        • 2.1 RecyclerViews
        • 2.2 RecyclerView Performance
        • 2.3 Implementation of a Recycler View
        • 2.4 Implementation with Input Controls
        • 2.5 Filtering RecyclerViews
        • 2.6 Recyclerview Demo
      • 3. ListViews and Searching
        • 3.1 ListView vs. RecyclerView
        • 3.2 ListView Performance
        • 3.3 Implementation of a ListView
        • 3.4 Searching in a List View
      • 4. Fragments
        • 4.1 What are Fragments?
        • 4.2 Lifecycle of a Fragment
        • 4.3 Integrating a Fragment into an Activity
        • 4.4 Sharing Data Between Fragments
        • 4.5 Fragment Slide Shows
      • 5. OkHttp
      • 6. Activity Lifecycle
      • 7. Implementation of Tab Layout
    • Fall 2024 Course Material
      • Lecture 1 & Exercise 1: Introduction to Android
      • Lecture 1.5: Beauty of Kotlin
      • Lecture 2 & HW 2: Modifiers, Lazylists and Reactive UI
      • Lecture 3 & HW 3: Animations, Intents and Manifest
      • Lecture 4 & HW 4: Coroutines & Navigation
      • Lecture 5 & HW 5: Persistent Storage, Networking, and JSON Parsing
      • Lecture 6 & HW 6: MVVM, Flows
      • Bonus Lectures & Bonus HW
      • Bonus Lecture: Industry Practice
    • Spring 2024 Course Material
      • Lecture 1 & Exercise 1: Introduction to Android
      • Lecture 4 & HW 4: LazyLists
      • Lecture 6 & HW 6: Networking, Data, and Persistent Storage
    • Spring 2020 Course Material
      • Week 1: Intro to the Editor
      • Week 2: Views and Layouts
      • Week 3: Intent and Manifest
      • Week 4: ListView and RecyclerView
      • Week 5: Fragments
      • Week 6: Networking
    • Spring 2021 Lecture & HW 8: Networking & 3rd Party APIs
    • HackOurCampus Workshop
Powered by GitBook
On this page
  • Step 1: Set up your Android Studio Project (follow-along)
  • Step 2: Create New Files (follow-along)
  • Step 3: Set up EateryCard (follow-along)
  • Task 1: Build the outer Card
  • Task 2: Divide the Card Vertically
  • Task 3: Add Texts
  • Task 4: Run a screen & deploy the app!

Was this helpful?

  1. SP25 Course Material
  2. Week 1 | Course Logistics, Kotlin, & Basic UI

Demo/Lecture: Eatery Card

Using Modifier and a component's arguments to visually build a complex component!

PreviousRelevant LinksNextA0: Eatery Card (Follow-Along)

Last updated 3 months ago

Was this helpful?

In this demo, we'll be showing off how to make the following Eatery Card component, which is very similar to (albeit a bit simpler than) one you've seen if you regularly use Eatery:

If time permits, we'll then show how to use this component we've built on a screen to show things on an actual app!

Step 1: Set up your Android Studio Project (follow-along)

First, we'll show you how to set up an Android Studio project!

  1. Open Android Studio (you should have it already installed!)

  2. Click New Project or go to File -> New... -> New Project...

  3. Make an Empty Activity Project.

  4. Name your project something comprehensible like D1. Click Finish.

You should now have a new app created for you! In the future you can follow this procedure whenever you are asked to make a new project.


Step 2: Create New Files (follow-along)

Next, we'll set up some files so that we can start building components and screens!

If you expand your filesystem, this is what you should see. The folder com.[...].d1 is where you'll be adding Kotlin Android files.

  1. Right Click com.[...].d1and do New... -> Kotlin Class/File.

  2. Make a file named EateryCard ; this will become our card component.

  3. Do the same and make a file named MainScreen.

Now, let's set up EateryCard so we can be ready to dev!


Step 3: Set up EateryCard (follow-along)

Add the following functions to EateryCard:

These two functions represent the following:

  1. EateryCard is the actual component we are building.

  2. EateryCardPreview allows us to preview the component as we are building it so we can verify that what we are building looks right.

Next, click on this button on the top right:

This launches the preview so you can see what your component looks like as you're building it!

You may need to periodically Build & Refreshto see the component.

Because you haven't actually written anything in the component, nothing will show up:

But now we're ready to dev! These next parts are on your own. We'll provide hints as we go. Feel free to ask us questions!


Task 1: Build the outer Card

Time to do things yourself now! Please feel free to ask questions as you go :-)

Use a Surface component built into Android to make the card background. When asked to import Surfaceand any other Android components, always select the @Composable one.

Hint 1: Surface always needs an inner body Composable, so for now just add a {} after the Surface to get it to compile. You'll add the rest of your stuff here.

Hint 2: Roll over Surface to see the arguments it can take in. You'll want to make this a RoundedCornerShape with a corner radius of 12.dp with a shadow elevation of 4.dp.

Hint 3: We want the card to fill the max width and have a fixed height of 220.dp. Use a Modifier for this!

You should end up with the following:


Task 2: Divide the Card Vertically

We want the card to have a distinct upper and lower section. Utilize a Column and Modifier.weight(1f) on the inner components in that column to make two Boxes that take up the same vertical space!

Make the upper box a nice shade of blue.

Hint 1: Boxes are 0 width and 0 height by default if they don't have any content. Make sure your box is filling the max width if it has a background to show its color!

Hint 2: Use Modifier.background(...) with the following color to achieve an Eatery Blue color:

Color(0xff5ecfdb)

Task 3: Add Texts

Next, let's make our eatery card display text!

We want our texts to display generally in the photo below. Don't worry that the Color is Red; up to you if you want to change that.

You'll need to use a combination of Rows, Columns, Texts, Modifiers, and a careful look at the arguments each of these take in to get this look!

Hint 1: Modifier.padding() adds some padding around a container.

Hint 2: Row's horizontalArrangement parameter w/ SpaceBetween may be useful to push the Open text off to the right.

Hint 3: Remember to keep using fillMaxWidth() if you want your container to take up as much width as possible!

Hint 4: Take a look at the parameters of Text to see if you can roughly match our Text's intricacies.


Task 4: Run a screen & deploy the app!

Now that we've made our component, let's run it to make it show up on our emulator / app!

  1. First, hop over to MainScreen . This file will represent our screen that the user will see.

  2. Just like before, make a MainScreen @Composable function. Add just the Eatery Card to this screen.

  3. Move over to MainActivity and replace the default Scaffold with our MainScreen.

  4. Run the app!

(You should have an emulator set up for you automatically in android studio.)

You should see your component. However, it hugs the sides kind of ugly...ly. Can you change MainScreen to make it fit more snugly?

If you see this, congrats. You just completed D1!

How to run your app!
End result...!