0% found this document useful (0 votes)
913 views60 pages

Android UI - PPT

This document provides an overview of the Android software development environment including: 1. It describes what Android is and its key features such as its open source nature, software stack, and support for common media formats. 2. It outlines the architecture of Android including its Java-based development environment, core libraries, Dalvik virtual machine, and integration with the Linux kernel. 3. It provides details on setting up the Android software development environment including installing the Java JDK, Android SDK, and using the Android Studio IDE.

Uploaded by

mithungn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
913 views60 pages

Android UI - PPT

This document provides an overview of the Android software development environment including: 1. It describes what Android is and its key features such as its open source nature, software stack, and support for common media formats. 2. It outlines the architecture of Android including its Java-based development environment, core libraries, Dalvik virtual machine, and integration with the Linux kernel. 3. It provides details on setting up the Android software development environment including installing the Java JDK, Android SDK, and using the Android Studio IDE.

Uploaded by

mithungn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Android – User Interface

TABLE OF CONTENTS

1. Android S/W development


environment
2.Common layout objects and
views
3.Hands On exercises
WHAT IS ANDROID
Android S/W development environment

What is Android

Android is a mobile operating system

• Based upon a modified version of the Linux kernel.

• Initially developed by Android Inc., a firm purchased by Google in 2005.

• Google released most of the Android code under the Apache License, a free
software and open source license.

• The unveiling of the Android distribution on 5 November 2007 was announced with
the founding of the Open Handset Alliance, a consortium of 78 hardware, software,
and telecom companies devoted to advancing open standards for mobile devices.
Android S/W development environment

What is Android

➢It is also a software stack for mobile devices which includes:

• An operating system

• Middleware

• Key applications.

➢The Android SDK provides the tools and APIs

Rich development environment includes:


• a device emulator

• tools for debugging

• memory and performance profiling

**https://developer.android.com/about/dashboards/index.html
Android S/W development environment

Features of Android

• Media support for common audio, video, and still image formats
• MPEG4
• H.264
• MP3
• AAC
• AMR
• JPG
• PNG
• GIF

• GSM Telephony (hardware dependent)

• Bluetooth, EDGE, 3G, and WiFi (hardware dependent)

• Camera, GPS, compass, and accelerometer (hardware dependent)


Android S/W development environment

Features of Android

➢It also includes:

• Application framework enabling reuse and replacement of components

• Dalvik virtual machine optimized for mobile devices

• Integrated browser based on the open source WebKit engine

• Optimized graphics powered by a custom 2D graphics library


• 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration
optional)

• SQLite for structured data storage


ARCHITECTURE OF ANDROID
Android S/W development environment

Architecture of Android
Android S/W development environment

Android Architecture

The Android operating system software stack consists of

• Java applications

• Java based object oriented application framework

• Java core libraries

• Dalvik virtual machine featuring JIT compilation.


Android S/W development environment

Android Build Process

Write app in Java


Compile with Javac

Transform to dex bytecode with dex

Loaded into Dalvik VM

Linux OS
SOFTWARE DEVELOPMENT SETUP
Android S/W development environment

Software Development Setup

• Java JDK

• Android SDK
• Class Library
• Developer Tools
• Emulator and System Images
• Documentation and Sample Code

• Android Studio IDE


• Reduces Development and Testing Time
• Makes User Interface-Creation easier
ANATOMY OF ANDROID
APPLICATION(APP)
Android S/W development environment

Hands On

1) Create a Hello World App (with Empty Activity)

2) Explore Android Studio IDE

3) Understand App Artifacts

4) Understand Project Structure

5) Create AVD(Android Virtual Device)

6) Connect Android Physical device


Android S/W development environment

App

• Android applications are written in the Java programming language.

• The compiled Java code is bundled by the “aapt tool” into an Android
package, an archive file marked by an .apk suffix.

• All the code in a single .apk file is considered to be one application.

• Android application lives in its own world:


• Every application runs in its own Linux process.
• Each process has its own virtual machine (VM).
• Each application is assigned a unique Linux user ID.
Android S/W development environment

App

• Application Components: Android applications don't have a single entry


point for everything in the application

- no main() function, for example

• Rather, they have essential components that the system can instantiate
and run as needed.
Android S/W development environment

Artifacts of Android Application(App)

▪ AndroidManifest.xml :
– A descriptor file.
– Defines the various components
– Intents
– Used to define required permissions

▪ src :Source code of the application


▪ res: Resources of the application
Android S/W development environment

Artifacts of Android Application(App)

<?xml version=“1.0” encoding=“utf-8”?>


<manifest xmlns:android=“http://schemas.android.com/apk/res/android”
package=“uk.ac.ic.doc”
<application android:icon=“@drawable/icon”
android:label=“@string/app_name”>

<activity android:name=“.SampleActivity”
android:label=“@string/activity_title_text_ref”>
<intent-filter>
/* ... */
</intent-filter>
</activity>

</application>

</manifest>
Android S/W development environment

App Project Structure

• Every Android Project uses a specific directory tree structure

• src/main/
– This contains AndroidManifest file
• /src/main/java/
This folder will contain the Java source files that you will be creating.
The files inside this folder will be organized according to the package
structure. This is similar to the /src folder which is present in any normal
Java project.

• …/gen
This is also a source folder, but will be contain Java source files that will be
automatically generated by the android platform. The framework will
generate R class file.
Android S/W development environment

App Project Structure

• src/main/res
This directory contains all the external resources (images, data files etc)
that are used by the android application. These external resources
(content) will be referenced in the android application.
This contains the following sub-folders
/res/drawable
/res/layout
/res/menu
/res/mipmap
/res/values
Android S/W development environment

App Project Structure

• /res/drawable
This folder contains all images, pictures etc. If you want to include an
image or an icon in your android application, then you will be placing it in
this folder.

• /res/layout
This folder contains the UI layouts that will be used in the project. These
UI layouts are stored as XML files.

• /res/menu
– This folder contains xml files which defined menu used in the application

• /res/mipmap
This folder contains launcher icons
Android S/W development environment

App Project Structure

• /res/values
This folder again contains XML files, which contain key values pairs that
will be referenced in the application. These XML files declare Arrays,
colors, dimensions, strings etc. The main idea of having these values in a
separate XML file is that the values can be used based on the locale without
actually changing the source code.

• /assets
This folder also contains external resources used in the application like
the /res folder. But the main difference is that the resources are stored in
raw format and can be read only programmatically.
Android S/W development environment

App Project Structure

Gradle Scripts

– Build.gradle – Project
• In dependencies match with your Android studio version

– Build.gradle - Module
Android S/W development environment

App Project Structure

IDs are generated based on file names


if those xml files are anywhere but in /res/values
TESTING YOUR APPS
Android S/W development environment

Running Application on Device

Before you can run your application on a device, you must perform some
basic setup for your device:

• Enable USB Debugging on your device

• Ensure that your development computer can detect your device when
connected via USB
ANDROID VIRTUAL DEVICES (AVDS)
Android S/W development environment

AVD

• In Android Studio, choose AVD Manager.


• Tools->Android-> AVD Manager

• Select Create Virtual Devices

• Click New. And follow the instructions…

• Type the name of the AVD, such as "my_avd".

• Click Finish
Android S/W development environment

AVD

▪ Android Virtual Devices (AVDs) are configurations of emulator options


that let you better model an actual device.

▪ Each AVD is made up of:


• A hardware profile to define the hardware features of the virtual
device.
• A mapping to a system image to define the version of Android
platform that will run on the virtual device.
• Other options which lets you control the screen dimensions,
appearance, and so on. You can also specify the emulated SD card to
use with the AVD.
• A dedicated storage area on your development machine, in which is
stored the device's user data and emulated SD card.
CONFIGURING PHYSICAL DEVICES
Android S/W development environment

Android Physical Devices

• In SDK Tools, install Google USB Driver for Nexus and Pixel devices

• For others, download device driver


• Go To Control Panel ->Device Manager
• Search for your device( Android Device and Portable device)
• If Brand is identified then device driver is installed
• Otherwise Right Click on device->Update device driver

• Settings->About Phone-Build Number ( press 7 Times)


• Enable USB Debugging
Android S/W development environment

Application Components

There are four types of components:


• Activity

• Broadcast Receiver

• Service

• ContentProvider
Android S/W development environment

Activities

• An activity presents a visual user interface for one focused endeavor the
user can undertake.

• Each activity is independent of the others.

• Each one is implemented as a subclass of the Activity base class.

• An application might consist of just one activity or, it may contain several.

• Typically correspond to one UI screen


Android S/W development environment

Activity

• Typically, one of the activities is marked as the first one that should be
presented to the user when the application is launched.

• Moving from one activity to another is accomplished by having the


current activity start the next one.

• Each activity is given a default window to draw in. Typically, the window
fills the screen, but it might be smaller than the screen and float on top of
other windows.

• Each activity class must have a corresponding <activity> declaration in its


package's AndroidManifest.xml. Activities can be started with
Context.startActivity().
Android S/W development environment

Activity Lifetime
HANDS ON
Android S/W development environment

Hands On

1) Upgrade the App as per the requirements given


below:
i) Change the text to “Lets Start Learning Android”.
ii) Change the icon of the App.
Android S/W development environment

Hands On - Solution

1) Upgrade the App as per the requirements given


below:
i) Change the text to “Lets Start Learning
Android”.
Change in strings.xml file
ii) Change the icon of the App.
New->Image Asset->Select Launcher Icons
from Icon Type drop down-> Path-> Select your
image file
COMMON LAYOUT OBJECTS AND
VIEWS
Android S/W development environment

View Components

• An activities UI is defined using a


hierarchy of View and ViewGroup
nodes.

• ViewGroup class serves as the base


for subclasses called "layouts,"

• View class serves as the base for


subclasses called "widgets," which
offer fully implemented UI objects,
like text fields and buttons.

• The most common way to define


UI and express the view hierarchy
is with an XML layout file.
Android S/W development environment

Layout

Linear Layout

• The most common way to define your layout and express the view hierarchy is with an
XML layout file.

• Linear Layout aligns all children in a single direction – vertically or horizontally,


depending on how you define the orientation attribute.

• All children are stacked one after the other, so a vertical list will only have one child
per row.

• Horizontal list will only be one row high (the height of the tallest child, plus padding).

• A Linear Layout respects margins between children and the gravity (right, center, or
left alignment) of each child.
Android S/W development environment

Layout

Relative Layout

• Relative Layout lets child views specify their position relative to the parent view or to
each other (specified by ID).

• you can align two elements by right border, one below another, centered in the screen,
centered left, and so on.

• In this ordering, the element that you will reference (in order to position other view
objects) must be listed in the XML file before you refer to it from the other views via
its reference ID.
Android S/W development environment

Layout

• Frame Layout

• Table Layout

• Etc…
Android S/W development environment

Views

➢ Android has many readymade Views (widgets) available for developers.


For example:

– Button – a text based push-button widget


– RadioButton – a two-states button that can be either checked or
unchecked
– Checkbox – multi selection widget
– ImageButton – an image based push-button widget
– ImageView – Displays an arbitrary image

– Text Fields:
– EditText – user input text widget
– TextView – Displays text

– And Many other


Android S/W development environment

Hands On

Develop a Registration Form App.


Requirements are given below:

It should have 4 fields


– Name
– Emp ID
– Password
– Password( re-type)
MENUS
Android S/W development environment

Menus

Android provides three types of application menus

• Options Menu - appears when the user presses the device MENU key.

• Context Menu - A floating list of menu items that appears when the user
performs a long-press on a View.

• Submenu - A floating list of menu items that the user opens by pressing a
menu item in the Options Menu or a context menu.

When the user selects a menu item from the Options Menu, the system calls your
Activity's onOptionsItemSelected() method:
Android S/W development environment

Menus

Context Menu: In order for a View to provide a context menu,


you must "register" the view for a context menu.

Call registerForContextMenu() and pass it the View you want to


give a context menu. (ex:
registerForContextMenu(mAboutImgObj))

When this View receives a long-press, it displays a context menu.


Android S/W development environment

Menus

Submenus: You can add a submenu to either Options menu or context menu.

When creating your menu resource, you can create a submenu by adding a <menu> element as the child
of an <item>. For example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/file"
android:icon="@drawable/file"
android:title="@string/file" >
<!-- "file" submenu -->
<menu">
<item android:id="@+id/new"
android:title="@string/new" />
<item android:id="@+id/open"
android:title="@string/open" />
</menu>
</item>
</menu>

When the user selects an item from a submenu, the parent menu's respective on-item-selected callback
method receives the event.
HANDLING UI EVENTS
Android S/W development environment

Event Listeners

• An event listener is an interface in the View class that contains a single callback
method.

• These methods will be called by the Android framework when the View to which the
listener has been registered is triggered by user i.e. interaction with the item in the UI.

• Included in the event listener interfaces are the following callback methods:
onClick() onKey()
onLongClick() onTouch()
onFocusChange() onCreateContextMenu()

• To handle the events, implement the respective interface and pass the instance to the
respective View.set...Listener() method. (E.g., call setOnClickListener() and pass it
your implementation of the OnClickListener)
Android S/W development environment

Touch Event Listeners

• The device has touch capabilities, then the user begins interacting with the interface
by touching it,

• So there is no longer necessary to highlight items, or give focus to a particular View.


This mode for interaction named "touch mode."

• For a touch-capable device, once the user touches the screen, the device will enter
touch mode.

• From this point onward, only Views for which isFocusableInTouchMode() is true will
be focusable, such as text editing widgets.

• Other Views that are touchable, like buttons, will not take focus when touched; they
will simply fire their on-click listeners when pressed.
Android S/W development environment

Handling Focus

• The framework will handle routine focus movement in response to user input.

• This includes changing the focus as Views are removed or hidden, or as new Views
become available.

• Views indicate their willingness to take focus through the isFocusable() method

• To change whether a View can take focus, call setFocusable().

• When in touch mode, you may query whether a View allows focus with
isFocusableInTouchMode()

• You can change this with setFocusableInTouchMode().


INTENT AND INTENT FILTERS
Android S/W development environment

Intent and Intent Filters

▪ Components of an application — activities, services, and broadcast receivers —


• -are activated through messages, called intents.

• An intent is an abstract description of an operation to be performed.

▪ It can be used with


• startActivity() to launch an Activity,
• broadcastIntent() to send it to any interested BroadcastReceiver components, and
• startService() or bindService() to communicate with a background Service.

▪ An intent object is a bundle of information.


Android S/W development environment

Intent Objects

Intent messaging is a facility for late run-time binding between components in the same
or different applications.

It contains information of interest to the component that receives the intent


- such as the action to be taken and the data to act on
plus information of interest to the Android system
-such as the category of component that should handle the intent and
instructions on how to launch a target activity.

Three aspects of an Intent object are consulted when the object is tested against an
intent filter:
action
data (both URI and data type)
category
Android S/W development environment

Intent Resolution

Intents can be divided into two groups:

• Explicit intents designate the target component by its name


(the component name field, mentioned earlier, has a value set).

Explicit intents are typically used for application-internal messages — such as an


activity starting a subordinate service or launching a sister activity.

• Implicit intents do not name a target (the field for the component name is blank).
Implicit intents are often used to activate components in other applications.
Thank You!
References

• https://developer.android.com/develop/index.html

• https://developer.android.com/training/index.html

You might also like