Android UI - PPT
Android UI - PPT
TABLE OF CONTENTS
What is Android
• 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
• An operating system
• Middleware
• Key applications.
**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
Features of Android
Architecture of Android
Android S/W development environment
Android Architecture
• Java applications
Linux OS
SOFTWARE DEVELOPMENT SETUP
Android S/W development environment
• Java JDK
• Android SDK
• Class Library
• Developer Tools
• Emulator and System Images
• Documentation and Sample Code
Hands On
App
• The compiled Java code is bundled by the “aapt tool” into an Android
package, an archive file marked by an .apk suffix.
App
• Rather, they have essential components that the system can instantiate
and run as needed.
Android S/W development environment
▪ AndroidManifest.xml :
– A descriptor file.
– Defines the various components
– Intents
– Used to define required permissions
<activity android:name=“.SampleActivity”
android:label=“@string/activity_title_text_ref”>
<intent-filter>
/* ... */
</intent-filter>
</activity>
</application>
</manifest>
Android S/W development environment
• 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
• 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
• /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
• /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
Gradle Scripts
– Build.gradle – Project
• In dependencies match with your Android studio version
– Build.gradle - Module
Android S/W development environment
Before you can run your application on a device, you must perform some
basic setup for 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
• Click Finish
Android S/W development environment
AVD
• In SDK Tools, install Google USB Driver for Nexus and Pixel devices
Application Components
• 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.
• An application might consist of just one activity or, it may contain several.
Activity
• Typically, one of the activities is marked as the first one that should be
presented to the user when the application is launched.
• 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.
Activity Lifetime
HANDS ON
Android S/W development environment
Hands On
Hands On - Solution
View Components
Layout
Linear Layout
• The most common way to define your layout and express the view hierarchy is with an
XML layout file.
• 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
– Text Fields:
– EditText – user input text widget
– TextView – Displays text
Hands On
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
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
• The device has touch capabilities, then the user begins interacting with the interface
by touching it,
• 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
• When in touch mode, you may query whether a View allows focus with
isFocusableInTouchMode()
Intent Objects
Intent messaging is a facility for late run-time binding between components in the same
or different applications.
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
• 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