1 of 20

2 of 20

Sign in

https://tinyurl.com/hacksprintw20signin4

3 of 20

Link to ReadME + code:

https://tinyurl.com/hacksprintw2020

Slides:

https://tinyurl.com/hacksprintw5

its

4 of 20

Attendance Code

ACM Membership Portal

https://members.uclaacm.com

WotInNavigation

5 of 20

6 of 20

What we will cover today

  • Gradle
  • Fragments
  • Navigation

7 of 20

Let’s talk about Gradle

8 of 20

But before that, what is a build system?

  • Build systems, or build tools automate the “building” process of an app or program and combines everything into a usable and executable form
  • This is very useful in large scale projects

9 of 20

Back to Gradle

  • Android Studio has chosen to use gradle, an “advanced build toolkit” that helps us combine all our source code and app resources into APKs.
  • APK stands for Android Application Package, which is essentially the final form of your mobile app.

App Res

  • Layouts (.xml)
  • Strings
  • Colors
  • Styles
  • Drawables

Source Code

  • MainActivity.kt
  • ...

Other Components

  • Dependencies
  • ...

10 of 20

build.gradle

  • Using Gradle is really nice because it means that we, as developers, never need to worry about how our app is built.
  • So we generally don’t have to worry too much about it
  • However, we should still know about the build.gradle file

11 of 20

Fragments

12 of 20

What is a fragment?

  • A Fragment represents a behavior or a portion of user interface in the app.
  • In fact, Activities and Fragments are very similar, they both receive their own input events, they both have their own .xml file to describe their appearance, and .kt file to hold logic.
  • You can think of a fragment as a “sub-activity” that has its own functionality that one can remove while the activity is running.

13 of 20

Some differences...

However, they are different in that:

  • Multiple Fragments can “live” in one Activity
  • You can reuse Fragments in different Activities
  • While an Activity can contain a Fragment, a Fragment cannot contain an Activity

As such, an Activity is not dependant on Fragments, but Fragments are dependant on Activities.

14 of 20

Fragment:

Navigation Bar

15 of 20

16 of 20

Nav time!!!!!

https://www.uclapuritytest.com/

(disclaimer: all answers to the test is for demonstration purpose only)

17 of 20

Navigation Graph

  • A graph that defines the flow of your application
  • How fragments are “linked” together
  • In our application:

  • Our navigation graph will look exactly like that

StartFragment → GameFragment → ScoreFragment

18 of 20

NavHostFragment

  • A built-in Android fragment that handles navigation

MainActivity

NavHostFragment

GameFragment

StartFragment

ScoreFragment

contains

controls

I can swap different fragments in and out of the screen

19 of 20

NavHostFragment

  • A built-in Android fragment that handles navigation

MainActivity

NavHostFragment

GameFragment

StartFragment

ScoreFragment

contains

controls

provides

Our Navigation graph

20 of 20

Action