Mobile Application Development

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 49

Mobile Application

Development

Android

1
Introduction to Android

 Mobile operating system based on Linux kernel


 User Interface for touch screens
 Used on over 80% of all smartphones
 Powers devices such as watches, TVs, and cars
 Over 2 Million Android apps in Google Play store
 Highly customizable for devices / by vendors
 Open source

2
Android Software Developer Kit (SDK)

 Development tools (debugger, monitors, editors)


 Libraries (maps, wearables)
 Virtual devices (emulators)
 Documentation (developers.android.com)
 Sample code

3
Create Your First Android App

 Prerequisites
 Java Programming Language
 Object-oriented programming
 XML - properties / attributes
 Using an IDE for development and debugging

4
Android Studio

● Android IDE
● Project structure
● Templates
● Layout Editor
● Testing tools
● Gradle-based
build
● Log Console
● Debugger
● Monitors
● Emulators

5
Creating Your First Android App(Start Android Studio)

6
Create a project inside Android Studio

7
Name your app

8
Pick activity template

Choose templates for


common activities,
such as maps or
navigation drawers.

Pick Empty Activity or


Basic Activity for
simple and custom
activities.

9
Name your activity

● Good practice to name


main activity
MainActivity and
activity_main layout

● Use AppCompat

● Generating layout file


is convenient

10
Android Studio Panes

Layout
Editor

Project
Files

Android Monitors:
logcat: log messages

11
Project folders

1. Manifests:
 Android Manifest file -
description of app read by the
Android runtime
2. Java:
 Java source code packages
3. Res:
 Resources (XML) - layout,
strings, images, dimensions,
colors...
4. build.gradle:
 Gradle build files

12
Gradle build system

 Modern build subsystem in Android Studio


 Three build.gradle:
 project
 module
 settings
 Typically not necessary to know low-level Gradle
details
 Learn more about grader at https://gradle.org/

13
Run your app

1. Run

2. Select virtual
or physical
device

3. OK

14
Create a virtual device

Use emulators to test app on different versions of Android and form factors.

Tools > Android > AVD Manager or:

15
Configure virtual device

1. Choose hardware 2. Select Android Version


3. Finalize

16
Run on a virtual device

17
Run on a physical device

1. Turn on Developer Options:


a. Settings > About phone
b. Tap Build number seven times
2. Turn on USB Debugging
a. Settings > Developer Options >
USB Debugging
3. Connect phone to computer with cable

Windows/Linux additional setup:


● Using Hardware Devices

Windows drivers:
● OEM USB Drivers

18
Xml in android

XML stands for Extensible Markup Language.


XML is a markup language much like HTML used to
describe data.
XML tags are not predefined in XML.
We must define our own Tags.
Xml as itself is well readable both by human and
machine.
Also, it is scalable and simple to develop.
In Android we use xml for designing our layouts
because xml is lightweight language so it doesn’t
make our layout heavy.

19
Basics Of User Interface:

The whole concept of Android User Interface is


defined using the hierarchy of View and ViewGroup
objects.
If you look at your mobile
device, every user interface
element that you see is a
View.

20
Different XML Files Used in Android:
1. Layout XML Files:
 Layout xml files are used to define the actual UI(User interface)
of our application.
 It holds all the elements(views) or the tools that we want to use
in our application.
 Like the TextView’s, Button’s and other UI elements.

21
What is a view

 Views are Android's basic user interface building


blocks.
 display text (TextView class), edit text (EditText class)
 buttons (Button class), menus, other controls
 scrollable (ScrollView, RecyclerView)
 show images (ImageView)
 subclass of View class

22
Views have properties

 Have properties (e.g., color, dimensions, positioning)


 May have focus (e.g., selected to receive user input)
 May be interactive (respond to user clicks)
 May be visible or not
 Have relationships to other views
Examples of views

23
Examples of views

24
Creating and laying out views

 Graphically within Android Studio

 XML Files

 Programmatically

25
Views defined in Layout Editor

26
View properties in XML

android:<property_name>="<property_value>"
Example: android:layout_width="match_parent"

android:<property_name>="@<resource_type>/resource_id"
Example: android:text="@string/button_label_next"

android:<property_name>="@+id/view_id"
Example: android:id="@+id/show_count"

27
ViewGroup & View Hierarchy

A ViewGroup (parent) is a type of view that can


contain other views (children)
ViewGroup is the base class for layouts and view
containers
 ScrollView—scrollable view that contains one child
view
 LinearLayout—arrange views in horizontal/vertical
row
 RecyclerView—scrollable "list" of views or view
groups

28
Hierarchy of view groups and views

29
View hierarchy and screen layout

30
Best practices for view hierarchies

 Arrangement of view hierarchy affects app performance


 Use smallest number of simplest views possible
 Keep the hierarchy flat—limit nesting of views and view
groups

31
Basic Layout XML Code:
Below we show activity_main.xml file in which we have two TextView’s.

32
2. Manifest xml File(Mainfest.xml):
 This xml is used to define all the components of our application.
 It includes the names of our application packages, our Activities,
receivers, services and the permissions that our application needs.
 For Example – Suppose we need to use internet in our app then we need to
define Internet permission in this file.
Below we show the AndroidManifest.xml file and define the Internet Permission in that file.

33
3. Strings xml File(strings.xml):
 This xml file is used to replace the Hard-coded strings with a single string.
 We define all the strings in this xml file and then access them in our app(Activity
or in Layout XML files) from this file.
 This file enhance the reusability of the code.

34
4. Styles xml File(styles.xml):
 This xml is used to define different styles and looks for
the UI(User Interface) of application.
 We define our custom themes and styles in this file.

35
5. Drawable xml Files:
 These are those xml files that are used to provide various graphics to the
elements or views of application.
 When we need to create a custom UI we use drawable xml files.
 Suppose if we need to define a gradient color in the background of Button or
any custom shape for a view then we create a Drawable xml file and set it in
the background of View.

36
6. Color xml File (colors.xml):
 This file is used to define the color codes that we used in our app.
 We simply define the color’s in this file and used them in our app from
this file.

37
7. Dimension xml File(dimens.xml):
 This xml file is used to define the dimensions of the View’s.
 Suppose we need a Button with 50dp(density pixel) height then
we define the value 50dp in dimens.xml file and then use it in
our app from this file.

38
Layouts

 are specific types of view groups


 are subclasses of ViewGroup
 contain child views
 can be in a row, column, grid, table, absolute

39
Common Layout Classes

LinearLayout RelativeLayout GridLayou TableLayout


t

40
Common Layout Classes

 ConstraintLayout - connect views with constraints


 LinearLayout - horizontal or vertical row
 RelativeLayout - child views relative to each other
 TableLayout - rows and columns
 FrameLayout - shows one child of a stack of children
 GridView - 2D scrollable grid

41
Linear Layout
Linear layout is a simple layout used in android for layout
designing.
In the Linear layout all the elements are displayed in linear
fashion means all the childs/elements of a linear layout are
displayed according to its orientation.
The value for orientation property can be either horizontal or
vertical.
Types Of Linear Layout Orientation
There are two types of linear layout orientation:
1. Vertical
2. Horizontal
Vertical:
In this all the child are arranged vertically in a line one after the other.
In below code snippets we have specified orientation “vertical” so the
childs/views of this layout are displayed vertically.

42
43
Horizontal:
 In this all the child are arranged horizontally in a line one after
the other.
 In below code snippets we have specified orientation
“horizontal” so the childs/views of this layout are displayed
horizontally.

44
Main Attributes In Linear Layout:
orientation: The orientation attribute used to set the
childs/views horizontally or vertically. In Linear layout default
orientation is vertical.
gravity: The gravity attribute is an optional attribute which is
used to control the alignment of the layout like left, right,
center, top, bottom etc.

45
layout_weight: The layout weight attribute specify each child
control’s relative importance within the parent linear layout.

46
weightSum: weightSum is the sum up of all the child
attributes weight. This attribute is required if we define
weight property of the childs.

47
Example of Linear Layout:

Now lets design 2 linear layout UI. First we have designed using
weight attribute and second without using it. So below layout output
will clear the difference between them:

48
Example 1: First we will design Android Linear Layout without using weight
property. In this example we have used one TextView and 4 Button. The
orientation is set to vertical.

49

You might also like