Uploaded by Quennie Quidet

Android Studio Course 1 Week 3

advertisement
Android Studio Course 1 Week 3&4
Requirements Gathering
Developing an app can take a lot of time, and this is tricky to know where to start. The decisions you
make before beginning your project will determine to a great extent, the amount of time you will spend
on coding or manipulating libraries or packages. Successful app development depends on good project
planning. In this video, you will learn how to perform requirements gathering, an essential step in
project planning. Project planning starts with getting a clear picture of what the project, or in this case,
the app is going to do. Once you have the idea clearly defined, it allows you to break the app down into
principal components of functionality. No matter if the app is for yourself or for a client, requirements
gathering is an important step that should not be skipped. Let's go through a simple requirements
specification for a video player app. As mentioned earlier, an app normally starts with an idea. The idea
in this case is to create a video player. There are a lot of different ways to play videos. Think about
streaming. Will the app have video adds? Will it play one or multiple video formats? What controls will it
need? You need to think about what exactly you want this app to do. These questions will guide you to
determine what components the app needs to have to fulfill its envisioned functions. Some more
questions you should consider are, are you going to build the video app yourself, or will it be a video
selection app that sends videos to another app that plays them? Will the App Store videos on the device
or stream them to the device or gather links for selection? Let's say the answers to these questions are
that you want a self-contained app with a player that stores mp4 videos locally and controls each video.
With this information, you can further decide what platforms you want to use to develop the app, as
well as which libraries or packages you will need. In this case, the app will run on Android. Finally, you
have a complete requirements specification for your app. By now, you should understand that you will
speed up the development time considerably if you carefully consider your options, instead of diving
straight in and guessing as you go. In this video, you've learned that no matter what app you're trying to
build, you should always start with requirements gathering. The aim is to answer as many questions as
possible to determine the needed components. The more complex the project, the more questions you
will need to ask and answer. But even a simple plan, like the example covered in this video, will save a lot
of time and effort.
Basic project planning
Project planning is an important part of commencing any new project. It serves as a roadmap that
shows the phases of the project, as well as their start and end dates and dependencies.
Project planning is one of the most critical stages of software development. Let's explore why it's is
so important.
1.
Project performance and success rates
Project planning involves comprehensive mapping and organization of project goals, tasks,
schedules and resources before anyone assigns project roles and the team starts implementing the
plan. With proper planning in place, you can boost the project performance and success rates of a
team.
2.
Clear objectives
Having a clear direction of what needs to be achieved greatly increases the likelihood that you will
do it. But without a concise objective from the start, the project will be complicated. If the team isn't
clear on what they are working on, it’s almost impossible to know when the project is completed.
Proper planning helps the team focus on the most important thing, the objectives and the end goal.
3.
Resource allocation
Having a project planned out shows how much of the workforce is required to execute the project.
The plan also allows project managers to monitor which resources have been allocated and thus
avoid excessive allocation.
4.
Communication
Planning aids communication, which will help every team member know what exactly is required of
them ahead of time. A well-written plan will help you communicate key details, making it seamless
for you and your entire team to complete specific tasks. Listening to their input and ideas is also a
great way to achieve buy-in and foster the commitment of every team member.
5.
Project-specific Training
Project planning ensures team members have the required technical know-how to execute the
assigned tasks and identifies talent pipelines to provide an adequate supply of trained talents
throughout the lifecycle of the project.
Project proposal
Now that you know what the requirements of the proposed app projects are, you can think about it from
a more technical perspective. Building an application from scratch can be quite difficult and timeconsuming. However, developers have a wide range of templates available that can make this process
easier in Android Studio. With these templates, you can quickly set up your video at project while you
focus on implementing the main features. The main features are that users can select, play, and pause a
video. One popular use of templates is to add new activities to an existing app project. In this case, the
basic activity template will be useful when you create your main activity screen where users can interact
with the video player. The basic activity template allows you to create a base code for your video app
that includes commonly used user interface or UI components you may need for the project. This will
form a base project to which you can add more code to perform specific actions based on the project
requirements. Let's review what else you know about the project. So far you know that the app will be
lightweight because you don't have to worry about images, music, or streaming video to the app. You
know that you require play and stop buttons for the video, and you can create these using a clickable
button. You know that you'll need to select a video from the phone library. You need an additional
button in your app. Because you don't require streaming, you can use Android's video view component
as it allows you to just display a video file. With only a few changes to the default build pattern, you can
incorporate all the elements needed for your app. Now you can start to think about the next step, which
is starting the project.
Start the project
You are ready to start creating your video player. Now that you know what the requirements are and you
have your project plan in place, you can go ahead and launch Android Studio and start coding. When you
launch Android Studio, on the first screen, click on the New Project button located in the top right corner
of the screen. A window will pop up where you can select a template from a wide range of product
templates. Because you are creating a mobile app, you should select the phone and tablet templates tab.
Select the basic activity template. This will allow you to create a base code for your app. This includes
commonly used user interface components. Now, create a new basic activity by providing a project
name, let's call it Video_player. Every Android app has an application ID. This ID uniquely identifies your
app on the device and in the Google Play Store. Once you publish your app, you should never change the
application ID. If you want to upload a new version of your app, the application ID needs to be the same
as what it was when originally published. If you attempt to make changes to the application ID, the
Google Play Store sees the deployment as a completely different app. Let's create a unique package
name and call it com.example.video_ player. Select Kotlin from the language drop-down menu. For this
project, you're using Kotlin throughout. Next is minimum software development kit or SDK. This is the
minimum version of the Android operating system required to run your video player application. Let's
select API Level 23, which is equivalent to Android 6.0. Finally, click on the Finish button. Now you have a
new video player project made using the basic activity template. You now have a basic main activity
class, which will be used to display the user interface of your video player to the user. Apart from the
main activity class, there are other files and folders that are generated alongside it. You have already
learned about them in previous videos. So you're ready to move on to the next step where you will learn
more about Android's video view, a component that allows you to simply display a video file.
VideoView class
One of the primary uses for mobile devices is to enable the user to be entertained by offering them
access to quality content. One key form of content widely used, especially for tablet devices, is
video. As part of developing your own video app player in Android Studio, you can use the
VideoView class.
What is VideoView class?
VideoView class allows you to play video files in Android.
The Android SDK includes two classes that make video playback implementation on Android
devices easy to implement when developing apps. VideoView can be used to display and play a
video in an Android app.
Whenever you add this component to the layout of an activity, it provides a surface onto which a
video may be played. The following video formats are currently supported on Android:




H.263
H.264 AVC
MPEG-4 SP
VP8
Aside from the surface to display a video, the VideoView class has a wide range of methods that
may be called in order to control the playback of video. Some of the more commonly used methods
are as follows:
setVideoPath(String path)
This specifies the path (as a string) of the video media to be played. This can be either a remote
video file URL or a local video file on the device.
setVideoUri(Uri uri)
This function operates the same way as the setVideoPath() method but takes a URI object as an
argument instead of a string.
start()
When this function is used, it starts video playback.
stopPlayback()
This function stops the video playback.
pause()
This function pauses video playback.
isPlaying ()
This function returns a Boolean value that indicates whether a video is currently playing.
What is MediaController?
The MediaController is the user interface to control the video.
Specifically, it is a view that contains media controls such as "Play/Pause", "Rewind", "Fast Forward"
and a progress slider. It synchronizes the controls with the state of the MediaPlayer.
The MediaController comes with a default set of controls. If you want to make changes to it, you
have to implement the MediaController class programmatically within your Kotlin code.
You can also use ExoPlayer for audio and video streaming in Android apps, but it is not distributed
with the Android SDK. To find out more about this, you can check out the additional readings for this
lesson.
Setting up the screen
There are many video player apps available. Some are nicer to use than others. But what makes one app
better than another? Well, for one thing, users like easy navigation. Elements like buttons and menus
need to be in expected and logical places on the screen. To create an enjoyable user experience, you
should try to design simple and intuitive mobile apps that are easy to navigate. Fortunately, Android
Studio has many layouts that you can use to achieve this. In this video, you will learn about the different
types of layouts you can use in android Studio to build the first screen that appears when a user
launches an app. The main activity. By now, you know that one of the basic components of an app is
activities. Generally, an Android app contains one or more activities. Each activity is one screen of the
app. These screens will contain one or more UI components. The structure of these UI components is
defined by layouts. A good example of this is the installed apps tray on your mobile. Layouts are
comprised of a collection of views and ViewGroup objects. But what does view and ViewGroup mean? A
view is Android's built-in view class. When this is used to create a view, it can be referred to as an object.
It represents a rectangular area of the screen and is used for displaying information or content and event
handling. Text, images and buttons are all views on Android. They can be grouped inside another view
which can act as a container. ViewGroup is a special use of the view class because it can contain one or
more other views. In other words, ViewGroup is used to define the layout in which views will be
arranged on the Android screen. There are various layouts available in Android that you can use to
implement a user interface with a distinctive design that is in line with the requirements gathering of the
app. Earlier in this course, you covered Extensible Markup Language or XML. Android layouts are written
in XML. You declare a layout through a simple XML layout file located in the resource Layout folder of any
projects you work on. When you create a project using a basic activity template, Android Studio
generates a file called activity main dot XML. Let's explore a few Android Layouts that developers use
regularly. First, you get Android linear layout. Linear layout is an extension of a ViewGroup, which is used
to render different child view instances, such as text, button and so on. This layout is used by setting the
orientation to either a horizontal or a vertical direction, one after the other. Next is the Android
constraint layout. Constraint layout is a ViewGroup subclass that enables developers to position and size
child views or widgets flexibly using constraints. These constraints make it possible to position a child
view relative to other views on the screen. For example, you need to use constraints to constrain child B
to the right of child A, child C to the top of child A and B. Another layout is Android RecyclerView. This is
a ViewGroup that can be used to display sets of data that can be scrolled. The item views inside the
RecyclerView are positioned using layout managers. For example, linear layout manager displays items in
a vertical or horizontal list and grid layout manager displays items in a grid. Then you get Android
WebView. WebView is an extension of a ViewGroup which is used to render webpages as part of an
activity layout. Next, you will explore a practical demonstration of how to create a layout XML file for the
main activity within the video player project that was created earlier. I have the video player project
open that I created earlier in Android Studio. Remember, when I used a basic activity template to create
the project, a set of folders including the Layout folder, was automatically created. I will now create a
simple activity file with no UI elements within the Layout folder. I right-click on the Layout folder, go to
New and then click on "Layout Resource File". I call it activity main. Android Studio will add the XML
extension by default, because it recognizes that it is a layout file. I now have to specify the root element.
The root element defines a particular view group that I will use to create all the UI components. For the
screen UI, I have chosen the constraint layout. As I discussed earlier, there are different types of layouts,
such as linear, relative, and so on. The constraint layout is an extension of the ViewGroup. I will use the
constraint layout as the parent component, which will hold all the other UI elements together. I click on
"Okay" to create the activity main file. Notice that the file is currently empty because it does not have
any UI components yet. In later videos, you will learn how to add UI components within the constraint
layout. By now, you should know what layouts are and how they are used in Android app development.
You also learned how to create a layout file in the Layout folder of a project.
Layouts
Part of setting up the screen of your app in Android Studio involves layouts. Read on to learn more
about the function and types of layouts in Android Studio.
What is a layout?
In Android, layout defines the user interface (UI) for an app or activity and holds the UI elements that
will appear to the user.
Related to layouts are View and ViewGroup.
View
A View is defined as the UI which is used to create interactive UI components such as TextView,
ImageView, Label, RadioButton and so on. It is in charge of event handling and drawing. They
are generally referred to as "widgets".
ViewGroup
A ViewGroup serves as a parent class for layouts and layout parameters that hold other Views or
ViewGroups and define the layout properties. They are generally referred to as "layouts".
Types of Android Layouts
LinearLayout
LinearLayout is a ViewGroup subclass used to render child View elements one after the other
either horizontally or vertically based on the orientation property specified.
ConstraintLayout
ConstraintLayout is a ViewGroup subclass used to specify the position of layout constraints for
every child View relative to other views on the screen.
Frame Layout
FrameLayout is a ViewGroup subclass used to specify the position of View elements it contains on
the top of each other to display only a single View inside the FrameLayout.
Table Layout
TableLayout is a ViewGroup subclass used to display the child View elements in rows and
columns.
WebView
WebView is a browser that is used to display the web pages in your activity layout.
RecyclerView
You can use RecyclerView with LinearLayoutManager to display scrollable lists of items in a single
column. You can also use RecyclerView with GridLayoutManager to display a scrollable list of
items in a grid view of rows and columns.
Finding the assets
So far, you have a basic app with a layout for the main activity. You also have an overview of video view
class. Now, it's time to concentrate on how and where your app will find the videos it must play. Android
has a built-in class specifically for locating files. It's called URI, which stands for Uniform Resource
Identifier. This is essentially the file path and the description of the resource you want to locate. A URI
identifies a resource either by location, name, or both. Take note that a resource can be any type of file.
It can be an image, video, or music file. Since I'm building a video player, I will demonstrate how to find
an MP4 video file. Let's open Android Studio to explore how to locate a video file with URI. Before I
demonstrate how to find assets from within your Kotlin code, I need to add the video files to my project
folder. Remember, I want to play videos within the app that I'm developing, instead of selecting them
from a user's device. To do that, I need to create a specific folder in which the video files can be saved. I
right-click on the res folder, go to New, and select New Android resource directory. Notice that there is
also an option that says directory. What's the difference? When I use a new Android Resource Directory?
Android recognizes all files saved there as resources and assigns unique IDs to each item. These IDs help
Android identify a resource whenever a developer needs to reference it. On the other hand, a directory
folder is just a regular folder and Android will not assign IDs to the files saved in it. Next, I need to specify
the resource type, which in this case is raw. Notice that the directory name automatically changes to raw
when you select row as the resource type. Click on "Okay". The raw folder is now in the res folder and I
can add a video file to it. I simply drag a sample video file into the raw folder. When you add assets,
Android Studio will ask you if you want to change the name of the file. To keep the file name the same,
click on refactor. Test.mp4 is now in the raw folder. The question is now, how do you make a reference to
test.mp4 from within your Kotlin code. I have the MainActivity Kotlin file open. I will now paste a code
snippet into it and then explain what it does. This code will make a reference to the file because it
specifies where to find it. First, it specifies that it is an Android resource. Then it specifies the package
name, which in this case is com.example. Lastly, it specifies to retrieve the file test from this directory,
make sure that you do not add the file extension. Android automatically recognizes the file as a video file
because it's added to the raw folder inside the Android Resource folder. You should now be familiar with
how to create an Android Resource folder and add files to it. You should also now know how to reference
files saved in this folder from within your Kotlin code. Later, you will learn how to create a video
application and then play the video right within the application.
Required imports
In Kotlin, a single input statement can make visible a class or all classes for a built-in package within
Android SDK. It is useful to a developer like you, because you won't have to write an entire video player
app from scratch. To speed up development, you will use a video view class, which has already been
added to Android SDK. To access this and other helpful classes, you can reference it by using an import
statement. You can write an import statement like this. The statement says that I want to use the video
view class included in the Android SDK. Now, let's take a more in-depth look at the inputs you'll use for
your video player app project. By now, you know that the video player video view class is used to play
the video player in an application. You need to be able to make a reference to this in the Kotlin code.
Here, you'll notice that I already have a few imports. These make reference to built-in packages already
developed and built by Android that come with the Android SDK. Because they are built-in, you can
import and make reference to those packages. First, let's examine the URI. This built-in package allows
you to reference the location of a particular file that you want to play. With the URI, you can either make
a reference to a file that's already in your application folder, like for example, within the raw folder here,
or you can make reference to a file that is on the user's device, perhaps the external storage. Next is the
media controller. This enables you to have access to the playback controls of the video player. This
means the play pause backward and forward controls. The media controller package allows you to
program the controls you need for your video player application. This is the control itself that renders
the video file. This is the video view widget. This package allows you to be able to render and play video
files. An important one to have. Apart from these packages, you also need a few other ones. These are
packages you need within the code base, like the activity class. You have to make reference to it before
you can use it. If I delete it, for example, it throws an error because it doesn't exist anymore. When I
import it again, it's there and it can be used. That's how you import packages. You might have noticed
this gray colored text. It shows up like that because I haven't used those packages in my code base yet.
On the other hand, when the package name is in white, it means it's been referenced and the package
has been accessed. Those are the major inputs you need for your video player application. These include
URI, media controller and activity class, all built-in packages that come with the Android SDK. In later
videos, you will be able to start building the application itself, write the code, and ensure that your video
file will play on your app. The next video is about the different built-in classes you'll need for your video
player app.
Kotlin: Simple terms
In a previous video, you pondered the question of why some apps are better than others. Here is a
reason. Interactivity, users want apps that respond to their input. That's why you need a way to manage
user inputs effectively and you do that with variables. Variables can be used, among other things to
enable developers to capture user inputs to create a more interactive user experience. In this video, you
will learn how to declare variables and how to display their values on screen. You can temporarily store
data using variables. The data stored as variables can be changed and reused depending on the
condition or on information passed across the application. To declare a variable in Kotlin, you use the
keyword var or val. Let's unpack the syntax. Var or val implies that you are creating a variable. Next is an
identifier or the name that you give the variable. The identifier is followed by an equal sign and finally
the value which is stored in the variable. You will learn the difference between var and val later in this
video. Let's first explore a few examples of variable types. Kotlin provides a set of built in variable types
that represent numbers. One of them is integer or Int, for instance, you can have a variable total count
which is an integer variable and has a value of 25. Another variable type is string which is a collection of
characters. You can have a variable called country as a variable of the string type and its value can be
United States. But say you do not know the value of the variable yet. Fortunately, you can also declare a
variable without assigning a value right away. However, this is only possible if you specify the type. Let's
declare a variable with an identifier called color and set the data type as string. Because you already
specified what the variable type is. You are allowed to assign the value of color only in the next line.
Next, let's focus on the difference between var and val. A variable declared using the val keyword cannot
be changed once the value is assigned. For example, if the variable country was created using val and the
value of United States of America was assigned to it, it will generate an error if you try to assign United
States in the next line. On the contrary, when you declare a variable using the var keyword, the value can
be changed later in the code. So if the variable country is created with the var keyword, no error will
occur if the value is reassigned later. Lastly, let's focus on how to display variables on screen. To perform
special tasks such as displaying a variable programming languages use something called functions. A
function is a unit of code that performs a special task. To display a variable on screening in Kotlin you use
a printline function like many other programming languages. To write a printline function, you type
println followed by a set of parentheses. You then add the variable identifier in between the
parentheses. This line of code will let the value of the variable display on screen. Let's explore a few
examples of the printline functions.
Say you have a variable first name that has the value of Michael. And in the next line, the print line
function that includes the word, hello. A space between quotation marks, a plus sign, and the variable
first name. Hello Michael will be displayed on screen. You can also have two additional variables, last
name and full name, which combined two variables, namely first name, and last name. Notice that a plus
sign can be used to combine the values of two string values as a single string. The printline function will
let the first name and the last name display on screen. In this video, you were introduced to different
keywords that you can use to declare variables. You also learned about different types of variables and
how you can display variables with the printline function.
Android Views
The main building block for the user interface (UI) of an app like the video player you are preparing
to develop is creating a View.
What are Views?
The View object is created from the View class and occupies a rectangular screen area. It is
responsible for the processing of drawings and events.
The View is the base class for widgets that are used to create interactive components of the user UI
such as buttons or text fields.
In summary, a View can be considered a rectangle on the screen that displays a certain type of
content, like an image, a piece of text or even a button!
Most used Android Views
Some of the most used Android Views include:










TextView
EditText
Button
ImageView
ImageButton
CheckBox
RadioButton
RecyclerView
DatePicker and
Spinner
View sizes
A View occupies a rectangle shape, although the rectangle is invisible.
The size of this rectangle can be manually set by specifying the exact size (with appropriate units) or
using some predetermined values. These predefined values are match_parent and
wrap_content.
match_parent means it will occupy all of the available space available within its parent ViewGroup,
whereas wrap_content means it will occupy only as much space as required for its content to
display.
XML syntax for creating a View
Now, as you learned previously, to draw anything in your Android application you need to specify it
in the design XML files. You will create Kotlin files to add functionality.
Every View in XML has the following format:


It always starts with an angle bracket, followed by the View name.
You then write attributes that will determine what this view will look like on the app
screen along with a value for the attribute. Each view has its own unique attributes.
 In the end, it is closed by a forward slash and an angle bracket.
So, every View subclass needs to follow this standard so that it can display on the screen of the
app. This format is the default standard of XML.
Take note that there are two attributes that are required for every View. These are
android:layout_height and android:layout_width.
These attributes determine the size of the invisible rectangle created by the view. Using these
attributes, you control the size of every view in your Android app.
Create the player
You're almost ready to start creating your player. But first, there are a couple of important things you
need to be aware of. You will use Android's VideoView class, it will be used to display a video file in your
application. You will need another component named MediaController as well. It will provide you with
the playback controls of the video player, such as play, pause, backward, and forward to control the
video player. With the combination of VideoView and MediaController class, you will be able to create
your video player. Now, let's move on to what you need to do to actually create your player. As you
follow along, keep in mind that this is an overview, so it's okay if you don't understand everything that's
happening in the code. I'm now going to create my video player. In the IDE, I already have the video I
want to play in the raw folder. Because I generated this project from a basic activity template, I have an
activity_main that has been automatically generated. I have the main activity class as well. All that's left
to do is to start writing code. I'm going to have to access the VideoView player in the activity_main file
because it's used to play the video in mp4 format. I need to make a reference to the controller here in
the UI interface. When I go to the Design tab, you'll notice that right now the interface is blank. But let
me get back to the code. From the code base, which is the XML equivalent code for the UI, I need to
start writing something. Here is the code for the VideoView controller that I'm going to use. Here is a
unique ID testView. I can choose to name it anything I want. But for now, I'm calling this testView and it's
there to manage the rendering on the UI. These are properties you have to define to ensure that the UI
is properly rendered on the interface. Here, you can notice how the VideoView I just added to the XML
displays in the Design tab. At this point, I can't do anything with it yet, I have to program it and make
sure that I can play and pause. But before I can do this, I need to go back to the main activity class. This
isn't doing anything right now either. I have to make sure that the VideoView player in the
activity_main.xml can respond to user inputs so I have some code for that. But before I start writing
anything, I want to discuss a function named onCreate. onCreate is used for the main activity. It is the
entry point of the application. When the app runs this is where it goes first, the onCreate code snippet.
I'm going to put my code after set content view, because this is going to set the content, the
activity_main I just created. I'm going to put my code here after this line when the content has been
rendered by the compiler. Let me explain the code step-by-step. This is a reference to the video player I
just created and the activity_main.xml. This is a testView. I make a reference to the testView and that's
why I have declared a variable here named videoView. What I want to do is find the property. It should
examine all the view groups that have this testView property and then retrieve it and store it in the
temporary variable. Once this is in place, the next thing to do is to create an instance of MediaController.
MediaController enables me to have control over the videoView player. If I want to play, pause, or
forward, the MediaController handles those activities. Now that I have this one in place handling the
activities, I need to make a reference to the location of the file. The MP4 video that has to be accessed is
inside raw. With the URI, I have access to the directory or the location of the file I want to play. This code
snippet is performing the operation, which is why it's needed in the codebase. The next step is to play
the video. I need to be able to set the controller you just created to VideoView. That is because I want
VideoView to have control over the media controller. I'm setting the controller to it, meaning that this
controller is specifically for this videoView. If you have two other video views within the same UI, you'll
have different controllers for them. After this, the next step is to set the location of the video I want to
play. That's the URI here. I've already set the variable here, and I've set the value as well. Now we're
saying that sets the video URI, which is here. The next step is to ensure that there's a focus. That's why
I'm using requestFocus here. This reference is a function that allows you to be able to start the video
immediately and then focus on the controller of which we have the last phase, which is on and start. All
these things are basic configurations you need to have in place before you start the video itself. I'm going
to start the emulator now. Let's examine what it looks like there. I'm just waiting for it to come up since
it's busy installing the application. Here's the video playing right now. This is the controller. If you tap on
this to focus on the video, then the controller will pop up. You can pause, play and you can forward.
There you have a video player. I hope you enjoyed this walk through of the process of creating the video
player. First, I added the VideoView to the XML and I made sure that the VideoView player can respond
to user inputs. Then I used onCreate to make sure that the application starts at the right point. After
which I referenced testsView, created an instance of MediaController and made reference to the location
of the file. After that, I set the controller to videoView, used the URI to set the location of the video I
want to play and used requestFocus to start the video immediately and focus on the controller.
Remember not to worry about knowing everything that's happening in the code at this point, you will
have the opportunity to deepen your understanding in later courses on Kotlin where the code is
explained in more detail. Now, it's time for you to give creating a video player a try.
Module summary: Building the app
You've reached the end of this module on android mobile app development. Let's recap the key points
and skills related to building a mobile app in android. You began this module with a lesson on the
requirements gathering process and its role in project planning and creation. Project planning is crucial
to the efficient development of effective apps. You then moved on to explore the project templates
available to you in android studio focusing on the basic activity templates that can be used to create the
base code for your video app. You also learned about components, you can add to this base code such as
clickable buttons and a video viewer. Next you explore the process of starting the video player project in
android studio. You began with template selection and ended with selecting the software development
kit or SDK, which is the minimum android version needed to run your app. You should now be able to
recall and perform these steps and other steps to create a base project using a template in android
studio, you were then introduced to the video view class, an android studio component used to display
video files then came setting up the app screen, concentrating on the main activity. Remember, an
android app contains one or more activities and each activity is one app screen. The main activity is the
first screen that is displayed when a user launches the app. These screens contain user interface or UI
components, the structure of which is defined by layouts. You learned that UI is made up of views and
view groups. A view represents a rectangular area of the screen and a building block of Ui such as text,
images or buttons. And view groups are like a container for views that define the layout in which these
views will be arranged on screen. You discovered the different layouts written using extensible markup
language, or xml. In android studio, including the linear layout, relative layout, list, view and web view.
You also learned how to declare a layout through a simple xml layout file located in the resource layout
folder of the app project. The next step involved familiarizing yourself with android's built in class for
locating files, the uniform resource identifier or you are I and how to use u r I to locate a video file. You
also discovered how to use import statements to access helpful android sdK classes such as the video
view class as well as you are I, media controller and activity class. You were introduced to variables that
can hold values such as integers or strings, as a way for developers to capture user inputs to create a
more interactive user experience, You declared these variables in Katelyn, using the key words far or Val,
a variable declared with a var can change, whereas a variable declared with val is immutable and the
value cannot be changed or reassigned variables can be displayed with the print line function in Katelyn,
for example, displaying a variable called first name with the value of Michael along with Hello. So the
app displays. Hello, Michael. Finally, you will walk through the process of creating a video player, from
adding video view to the xml to using YU Ri to set the location of the video files you want to play. You
should now be familiar with the essential skills and concepts of android mobile app development,
including how to create your own video player app in android studio. Congratulations. That's great
progress towards becoming a skilled android mobile app developer.
Additional resources
Learn more
Here is a list of additional reading material that may consolidate some of the knowledge you've
gained so far and be helpful as you continue your learning journey.
Android layouts and XML

Layouts
ExoPlayer in Android


Introduction to ExoPlayer
ExoPlayer
Kotlin

Basic syntax
VideoView class

VideoView
Course recap: Introduction to Android
mobile application development
Now that you've completed your Introduction to Android Mobile App Development, let's recap what
you've learned. You began with an introduction to the program and course. You gained insight into the
roles and responsibilities of mobile developers from designing, building and maintaining mobile apps to
project planning and research, and discovered essential development skills like programming languages.
Whether joining a company or freelancing, you explored different careers for mobile developers, and in
Android development, specifically. You then downloaded and installed the Integrated Development
Environment or IDE, used for developing Android apps, Android Studio. When exploring mobile
platforms, you learned that mobile apps are installable software that runs on mobile devices. You
identified some advantages and disadvantages of mobile apps, such as being faster than mobile
websites, but more expensive to build. You also learned about mobile operating systems, which allow
mobile devices to run apps, and Android platforms like Chromebook and Android TV. In your introduction
to Android development, you learned about Android programming languages, focusing on Kotlin, the
preferred language for building Android apps. Benefits of Kotlin include: conciseness, readability, and
easier maintenance, as well as interoperability with Java. You toured Android Studio, learning about
some of its key features, such as a build system that allows you to compile and build your Android apps.
You also examined the toolbar, navigation bar and project window, editor window, tool window bar and
status bar. You discovered different project templates in Android like, the basic activity and bottom
navigation templates. Some of their uses such as providing a code-based to work from when developing
apps to adding activities to existing projects, and the advantages of using them, such as building
functional apps quickly. You learned that with the Android Software Development Kit or SDK tools, it's
easy to start a new project with a set of default project directories and files. After that, you were
introduced to the major components that make up Android apps: activities, services, broadcast
receivers, and content providers. You learned that the AndroidManifest.xml configuration file defines
these major components and their interactions, and contains information about what an app needs in
order to run on an Android device. You were also introduced to how to define the components within
this XML file. There was an introduction to emulator software, the computer programs that allow you to
test your apps on simulations of the devices they'd been designed for. Next, you learned about and
examined the interface of the Android Virtual Device or AVD Manager, an Android Studio feature used to
ensure your Android apps are optimized for different devices. After that, you were introduced to the
Android operating system or OS images, which are versions of the Android operating systems used by an
emulator. You learned how to access the OS images by creating and configuring a device with Android
Studio's Virtual Device Manager, and explored some AVD properties commonly used when configuring
an emulator. As you moved on to exploring the Android Studio IDE and project structure, you've
examined the structure of an Android project. You learned about the folders and files that contain
everything required for an app to run, such as the root directory, which is the root for all other folders
and files, and the .gradle folder, which is essential for project building. You also learned about the
MainActivity class, which is generated alongside these folders and files when creating an app in Android
Studio and contains Kotlin code integral to app behavior. The on create function in MainActivity was
identified as the entry point for your app to run successfully. After that, you delved into Gradle, which
manages the Android projects through a set of build configuration files. For every Android project, you
learned, two build.gradle files are generated. The first whose settings apply to every module in the entire
project, and the second, whose project level or module level settings apply only to the app module. You
discovered the structure of a default build.gradle file and explored popular Gradle commands that give
you more control over the Gradle system, such as the Gradle build command. You gained more insight
into the AndroidManifest file, an XML file that contains essential information about your app. You
learned about the resources contained in Android Studio's resource folder, such as files and static
content. Your code uses light colors and animations, you can reference these resources anywhere in your
app code. You also examined the res and layout folders within the project files. These help your app
render high-quality images across different devices and manage user interface or UI of your app. Finally,
was the setting up your project and preparing for building a video player app. You started by exploring
the importance of project planning for successful app development, and using requirements gathering,
to decide which built-in controls like project templates to use. You were introduced to layouts in Android
Studio and how they are used to structure app UI, including setting up the screen that appears when an
app is launched. To use these layouts, you need to declare them using a simple XML layout file in the
resource layout folder of any project. You also discussed some commonly used templates, such as the
basic activity template. You learned more about the Uniform Resource Identifier or URI, a built-in class,
specifically for locating resources, and how to use import statements to access helpful classes like this
one within the Android SDK. You were introduced two variables as a way to capture user inputs and
create a more interactive user experience. You learned to declare variables in Kotlin using the keywords
var or val, and to display them with the print line function. Finally, you had the opportunity to follow
along and create your own video player app in Android Studio using Android's video view class and the
media controller component. Well done, you've covered many concepts and skills, and gained significant
Android mobile app development knowledge during these courses. Best of luck as you try out what
you've learned.
About the graded assessment
The purpose of the graded assessment
The main purpose of the graded assessment is to check your knowledge and understanding of the
key learning objectives of the course you have just completed.
Most importantly, graded assessments help you to establish which topics you have mastered and
which topics may require further focus before you can complete the course.
Ultimately, the graded assessment is designed to help you make sure that you are ready for the next
course in this program.
Prepare for the graded assessment
You have encountered exercises, knowledge checks, in-video questions and other assessments as
you have progressed through the course. Nothing in the graded assessment will be outside what you
have covered already, so you should be well placed to succeed.
Review the graded assessment
Please review the graded assessment feedback and where necessary go back and work through the
topics that you feel require your further attention.
Good luck!
Exercise: Create the player
Following this reading exercise, you should be able to create a simple player app.
Lab objectives
Goal
Create a video player that plays a video file
Objectives
 Create an Android project
 Add an mp4 video file to your new project
 Create a user interface
 Add import statements VideoView and MediaController to your Activity class
 Add a VideoView to activity_main.xml
 Add the code that plays video in the onCreate() function of MainActivity.kt
Step 1: Create a new project using Basic Activity Template and call it video_player.
New Project Window with Basic Activity selected
Basic Activity settings window
Step 2: Create a raw directory and add an mp4 video file to the folder.
Right click menu with New Android Resource Directory selected
New Resource Directory settings window with a Resource type of Raw selected
Step 3: In the activity_main.xml file, create a VideoView inside a ConstraintLayout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.
android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.video_player.MainActivity">
<VideoView
android:id="@+id/testView"
android:layout_width="wrap_content"
android:layout_height="308dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 4: In MainActivity.kt class add the following import statements at the top of the file if they
don’t exist:
import android.widget.MediaController
import android.widget.VideoView
Step 5: In the onCreate function add this code snippet to play the video file.
setContentView(R.layout.activity_main)
//Find the VideoView class by its id
val videoView = findViewById(R.id.testView)
//Creating MediaController
val mediaController = MediaController(this)
mediaController.setAnchorView(videoView)
//specify the location of media file
val uri:Uri = parse(
"android.resource://" + packageName
+ "/raw/test"
)
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController)
videoView.setVideoURI(uri)
videoView.requestFocus()
videoView.start()
Solution code
The following is a sample solution for the 'Create the Player' exercise.
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.
android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.video_player.MainActivity">
<VideoView
android:id="@+id/testView"
android:layout_width="wrap_content"
android:layout_height="308dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.example.video_player
import
import
import
import
import
import
import
android.R
android.net.Uri
android.net.Uri.*
android.os.Bundle
android.widget.MediaController
android.widget.VideoView
androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Find the VideoView class by its id
val videoView = findViewById(R.id.testView)
//Creating MediaController
val mediaController = MediaController(this)
mediaController.setAnchorView(videoView)
//specify the location of media file
val uri:Uri = parse(
"android.resource://" + packageName
+ "/raw/test"
)
//Setting MediaController and URI, then starting the videoView
videoView.setMediaController(mediaController)
videoView.setVideoURI(uri)
videoView.requestFocus()
videoView.start()
}
}
Congratulations!
Congratulations on reaching the end of this Android Mobile Application
Development course. You've worked hard to get here and developed a lot of new
skills during the course. You are able to demonstrate some of this learning and
your practical database skill set by creating a video player app. Following your
completion of this first course in Android development, you should now be able
to; understand the general principles of mobile apps and the Android platform
ecosystem, setup and explore the Android Studio environment and create and modify
your own video player app. What are the next steps? Well, this is the first
course in the Android program, and it has given you an initial introduction to
several key areas. You probably realize that there's still more for you to learn.
If you found this course helpful and want to discover more, then why not register
for the second course. You'll continue to develop your skill set during each of
the Android courses that are part of this program. In the final course of this
program, you will bring together all the skills you've learned to create a simple
Android mobile app. Even though you're just starting out in your journey to
become a mobile developer, you have gained a valuable understanding of the
concepts and practical skills you'll continue to learn as you progress. The tasks
you have completed in this course has helped to consolidate your knowledge thus
far. Well done on taking the first steps towards a future career. Once you've
completed all the courses in this program, you'll receive certification in Meta
Android development. The certification can also be used as a progression to other
Meta role-based certifications. Depending on your goals, you may choose to go
deep with advanced role-based certifications or take other fundamental courses
once you earn this certification. Meta certifications provide globally recognized
and industry endorsed evidence of your technical skills. Thank you. It's been a
pleasure to embark on this journey of discovery with you. Best of luck in the
future.
Next steps
Congratulations! You've completed this course and taken another step toward improving your
knowledge, skills and qualifications.
In the next course, you will be introduced to Kotlin, a popular programming language used in Android
mobile app development.
You will learn about the basic concepts of mobile app development using Kotlin. You will discover
what data types, variables, conditions and loops are and explore how they are used. You will also
discover how to work with functions, classes, and objects and learn about their advanced attributes.
Finally, you will have the opportunity to practice what you have learned by completing a practical
assignment followed by a self-review exercise.
Download