0% found this document useful (0 votes)
209 views38 pages

Mobile Application Development: Dr. Babasaheb Ambedkar Open University Ahmedabad

Uploaded by

maulik shah
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)
209 views38 pages

Mobile Application Development: Dr. Babasaheb Ambedkar Open University Ahmedabad

Uploaded by

maulik shah
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/ 38

MOBILE APPLICATION

DEVELOPMENT
PGDCA 203

BLOCK 2:
ANDROID APPLICATION AND
USER INTERFACE DESIGN

Dr. Babasaheb Ambedkar Open University


Ahmedabad
MOBILE APPLICATION
DEVELOPMENT

Knowledge Management and


Research Organization
Pune
Editorial Panel

Author
Er. Nishit Mathur

Language Editor
Prof. Jaipal Gaikwad

Graphic and Creative Panel


Ms. K. Jamdal
Ms. Lata Dawange
Ms. Pinaz Driver
Ms. Ashwini Wankhede
Mr. Kiran Shinde
Mr. Prashant Tikone
Mr. Akshay Mirajkar

Copyright © 2015 Knowledge Management and Research Organization.


All rights reserved. No part of this book may be reproduced, transmitted or utilized
in any form or by a means, electronic or mechanical, including photocopying,
recording or by any information storage or retrieval system without written
permission from us.

Acknowledgment
Every attempt has been made to trace the copyright holders of material reproduced
in this book. Should an infringement have occurred, we apologize for the same and
will be pleased to make necessary correction/amendment in future edition of this
book.
The content is developed by taking reference of online and print publications that
are mentioned in Bibliography. The content developed represents the breadth of
research excellence in this multidisciplinary academic field. Some of the
information, illustrations and examples are taken "as is" and as available in the
references mentioned in Bibliography for academic purpose and better
understanding by learner.'
ROLE OF SELF INSTRUCTIONAL MATERIAL IN DISTANCE LEARNING

The need to plan effective instruction is imperative for a successful


distance teaching repertoire. This is due to the fact that the instructional
designer, the tutor, the author (s) and the student are often separated by
distance and may never meet in person. This is an increasingly common
scenario in distance education instruction. As much as possible, teaching by
distance should stimulate the student's intellectual involvement and
contain all the necessary learning instructional activities that are capable of
guiding the student through the course objectives. Therefore, the course /
self-instructional material are completely equipped with everything that
the syllabus prescribes.
To ensure effective instruction, a number of instructional design
ideas are used and these help students to acquire knowledge, intellectual
skills, motor skills and necessary attitudinal changes. In this respect,
students' assessment and course evaluation are incorporated in the text.
The nature of instructional activities used in distance education self-
instructional materials depends on the domain of learning that they
reinforce in the text, that is, the cognitive, psychomotor and affective. These
are further interpreted in the acquisition of knowledge, intellectual skills
and motor skills. Students may be encouraged to gain, apply and
communicate (orally or in writing) the knowledge acquired. Intellectual-
skills objectives may be met by designing instructions that make use of
students' prior knowledge and experiences in the discourse as the
foundation on which newly acquired knowledge is built.
The provision of exercises in the form of assignments, projects and
tutorial feedback is necessary. Instructional activities that teach motor skills
need to be graphically demonstrated and the correct practices provided
during tutorials. Instructional activities for inculcating change in attitude
and behavior should create interest and demonstrate need and benefits
gained by adopting the required change. Information on the adoption and
procedures for practice of new attitudes may then be introduced.
Teaching and learning at a distance eliminates interactive
communication cues, such as pauses, intonation and gestures, associated
with the face-to-face method of teaching. This is particularly so with the
exclusive use of print media. Instructional activities built into the
instructional repertoire provide this missing interaction between the
student and the teacher. Therefore, the use of instructional activities to
affect better distance teaching is not optional, but mandatory.
Our team of successful writers and authors has tried to reduce this.
Divide and to bring this Self Instructional Material as the best teaching
and communication tool. Instructional activities are varied in order to assess
the different facets of the domains of learning.
Distance education teaching repertoire involves extensive use of self-
instructional materials, be they print or otherwise. These materials are
designed to achieve certain pre-determined learning outcomes, namely goals
and objectives that are contained in an instructional plan. Since the teaching
process is affected over a distance, there is need to ensure that students actively
participate in their learning by performing specific tasks that help them to
understand the relevant concepts. Therefore, a set of exercises is built into the
teaching repertoire in order to link what students and tutors do in the
framework of the course outline. These could be in the form of students'
assignments, a research project or a science practical exercise. Examples of
instructional activities in distance education are too numerous to list.
Instructional activities, when used in this context, help to motivate students,
guide and measure students' performance (continuous assessment)
PREFACE
We have put in lots of hard work to make this book as user-friendly
as possible, but we have not sacrificed quality. Experts were involved in
preparing the materials. However, concepts are explained in easy language
for you. We have included may tables and examples for easy understanding.
We sincerely hope this book will help you in every way you expect.
All the best for your studies from our team!
Mobile Application Development
Contents

BLOCK 1: BASICS OF ANDROID APPLICATION

UNIT 1 INTRODUCTION TO ANDROID, TOOLS AND BASICS


The Android Platform, Installing Android Studio, Java for Android,
Android Studio for Android Software Development, Building a
sample Android application
UNIT 2 ANDROID APPLICATION DESIGN ESSENTIALS - I
A Framework for a Well-Behaved Application, Application Context,
Activities, Services, Intents, Intent Filter, Permissions, Receiving and
Broadcasting Intents,

BLOCK 2: ANDROID APPLICATION AND USER INTERFACE


DESIGN

UNIT 1 ANDROID APPLICATION DESIGN ESSENTIALS - II


Using Intent Filter, Permissions, Android Manifest File and its
common settings, managing different types application resources in
a hierarchy
UNIT 2 Android User Interface Design and Common APIs
User Interface Screen elements, Designing User Interfaces with
Layouts, Drawing and Working with Animation ,Drawing 2D and
3D Graphics and Multimedia,
BLOCK 3: ANDROID NETWORKING AND DEVELOPMENT

UNIT 1 ADVANCED TOPICS - I


Android Networking, Web and Telephony API, Search, Location and
Mapping, Sensors, NFC, Speech, Gestures, and Accessibility,
UNIT 2 ADVANCED TOPICS - II
Communication, Identity, Sync, and Social Media, The Android
Native Development Kit (NDK)

BLOCK 4: ANDROID APPLICATION PUBLISHING AND CONTENT


PROVIDERS

UNIT 1 MORE ON ANDROID

Handling and Persisting Data, A Content Provider as a Facade


for a RESTful Web Service, Using Content Providers

UNIT 2 PUBLISHING ANDROID APPLICATION


Deploying Android Application to the World, Selling your
Android application
Dr. Babasaheb PGDCA-203
Ambedkar
Open University

MOBILE APPLICATION DEVELOPMENT


BLOCK 1: ANDROID APPLICATION AND USER INTERFACE
DESIGN

UNIT 1
ANDROID APPLICATION DESIGN ESSENTIALS - II 03

UNIT 2
ANDROID USER INTERFACE DESIGN AND COMMON APIS 15
BLOCK 2: ANDROID APPLICATION AND
USER INTERFACE DESIGN
Block Introduction
Intents are asynchronous messages which permit application components to
request functionality from other android components. Intents allow you to interact
with components from the same applications additionally like components
contributed by other applications. The new Fragment API for android, introduced
in android 3.0, permits for easier dynamic user interfaces. API that is application
program interface may be a set of routines, protocols, and tools for building
software applications.

In this block, we will detail about the basic of Intent messages and usability
of application components. The block will focus on the study and concept of
running android 6.0 with API level 23 with permission requiring for access of
additional features. You will get an idea on application in Android with necessity
of Manifest.xml file.
In this block, you will make to learn and understand about new Fragment
API for android for easy dynamic user interfaces. The concept related to interface
elements in android app using view and ViewGroup objects will also be explained
to the students. The student will be demonstrated practically about animations.

Block Objective
After learning this block, you will be able to understand:

 The basic of applying Intent Filter

 Study features of Permissions

 Concept of Android Manifest File

 Idea about managing different types application resources

 Features of Android User Interface Design

 Idea about User Interface Screen elements

 Concept of Layouts

 Working characteristics of Graphics and Multimedia

1
Android Block Structure
Application and
User Interface Unit 1: Android Application Design Essentials - II
Design
Unit 2: Android Application Design Essentials - I

2
UNIT 1: ANDROID APPLICATION DESIGN
ESSENTIALS - II
Unit Structure
1.0 Learning Objectives
1.1 Introduction

1.2 Using Intent Filter


1.3 Permissions

1.4 Android Manifest File and its common settings


1.5 Managing different types application resources in a hierarchy

1.6 Let Us Sum Up


1.7 Answers for Check Your Progress

1.8 Glossary
1.9 Assignment
1.10 Activities

1.11 Case Study


1.12 Further Readings

1.0 Learning Objectives


After learning this unit, you will be able to understand:

 About Intent Filter

 About Android Manifest File

 About application resources

1.1 Introduction
Your app's user interface is collectively that the user can see and collaborate
with. Android provides a variety of pre-built UI components such as structured
layout objects and UI controls that allow you to build the graphical user interface

3
Android for your app. Android also provides other UI modules for different interfaces such
Application and as dialogs, notifications, and menus.
User Interface
Design

1.2 Using Intent Filter


Intents are asynchronous messages which permit application components to
request functionality from other android components. Intents allow you to interact
with components from the same applications additionally like components
contributed by other applications. Intents are used to signal to the android system
that a precise event has occurred. Intents typically describe the action that should
be performed and provide data upon that such an action should be done. for
example, your application will begin a browser component for a certain url via an
intent. This is demonstrated by the following example.

A component will register itself via an intent filter for a selected action and
specific data. an intent filter specifies the kinds of intents to that an activity,
service, or broadcast receiver will respond to by declaring the capabilities of a
component.

Android components register intent filters either statically within the


androidManifest.xml or just in case of a broadcast receiver also dynamically via
code. An intent filter is defined by its category, action and data filters. It also can
contain additional meta-data.

If intent is sent to the android system, the android platform runs a receiver
determination. It uses the data included within the intent. If many components
have registered for the same intent filter, the user will decide that component
should be started.

Intent filter
You can register your android components via intent filters for certain
events. If a component doesn't define one, it will solely be referred to as by
explicit intents. This chapter offers an example for registering a component for
intent. The key for this registration is that your component registers for the correct
action, mime-type and specifies the correct meta-data.
4
To inform the system those implicit intents they will handle, activities, Android
services, and broadcast receivers will have one or more intent filters. each filter Application
Design
describes a capability of the component, a set of intents that the component is
Essentials - II
willing to receive. It, in effect, filters in intents of a desired kind, whereas filtering
out unwanted intents — however solely unwanted implicit intents (those that do
not name a target class). a certain intent is usually delivered to its target, no matter
what it contains; the filter isn't consulted. However an implicit intent is delivered
to a component as long as it will undergo one of the component's filters.

An intent filter is an instance of the IntentFilter class. However, since the


android system should realize the capabilities of a part before it will launch that
part, intent filters are typically not set up in Java code, however within the
application's manifest file (AndroidManifest.xml) as <intent-filter>
elements. (The one exception would be filters for broadcast receivers that square
measure registered dynamically by calling Context.registerReceiver(); they're
directly created as IntentFilter objects.)
A filter has fields that parallel the action, data, and category fields of an
Intent object. An implicit intent is tested against the filter in all 3 areas. To be
delivered to the component that owns the filter, it must pass all 3 tests. If it fails
even one in all them, the android system will not deliver it to the part — at least
not on the basis of that filter. However, since a component can have multiple
intent filters, an intent that doesn't pass through one of a component's filters may
make it through on another.

Check your progress 1


1. What is android intent?

a. It is an abstract description of an operation to be performed


b. activity
c. process
d. None of these

2. The Primary elements of intent are____________________.


a. Action

b. Data
c. Both of these
d. None of these

5
Android 1.3 Permissions
Application and
User Interface It's easy for an app to overwhelm a user with permission requests. If a user
Design
finds the app frustrating to use, or the user is worried regarding what the app could
be doing with the user's information, they will avoid using the app or uninstall it
entirely. Whenever you ask for permission, you force the user to form a decision.
You must minimize the amount of times you make these requests. If the user is
running android 6.0 (API level 23) or later, whenever the user tries some new app
feature that needs a permission, the app needs to interrupt the user's work with a
permission request. If the user is running an earlier version of golem, the user
needs to grant all of the app's permissions when installing the app; if the list is just
too long or appears inappropriate, the user could decide not to install your app at
all. For these reasons, you must minimize the amount of permissions your app
wants.
If the user is running android 6.0 (API level 23) or later, the user needs to
grant your app its permissions whereas they're running the app. If you confront the
user with a lot of requests for permissions promptly, you'll overwhelm the user
and cause them to quit your app. Instead, you should invite permissions as you
need them.

In some cases, one or additional permissions could be absolutely essential to


your app. it would add up to ask for all of these permissions as soon because the
app launches. For example, if you make a photography app, the app would wish
access to the device camera. Once the user launches the app for the first time, they
will not be surprised to be asked for permission to use the camera. However if the
same app also had a feature to share photos with the user's contacts, you probably
mustn't invite the READ_CONTACTS permission at first launch. Instead, wait till
the user tries to use the "sharing" feature and ask for the permission.

The permissions dialog shown by the system when you call


requestPermissions() says that what permission your app wants, but doesn't tell
why. In some cases, the user may find it confusing. It's has been a good idea to
explain to the user why your app wants the permissions before calling
requestPermissions().
For example, a photography app might want to use location services so it
can geotag the photos. A typical user might not understand that a photo can
contain location information, and would be puzzled why their photography app
wants to know the location. So in this case, it's a good idea for the app to tell the
user about this feature before calling requestPermissions().
6
Android
Check your progress 2 Application
1. Which method is called when the app seeks permission from the user? Design
Essentials - II
a. startActivitity()

b. requestPermission()
c. broadcastReceiver()

d. None of these

1.4 Android Manifest File and its common settings


Every application should have an AndroidManifest.xml file (with precisely
that name) in its root directory. The manifest file presents essential info regarding
your app to the android system, info the system must have before it will run any of
the app's code. Among other things, the manifests will the following:

 It names the Java package for the application. The package name is a unique
identifier for the application.
 It describes the components of the application — the activities, services,
broadcast receivers, and content providers that the application consists of. It
names the classes that implement every of the elements and publishes their
capabilities (for example, that Intent messages they will handle). These
declarations let the android system know what the components are and
under what conditions they will be launched.
 It determines that processes can host application components.
 It declares that permissions the application should have so as to access
protected parts of the API and interact with other applications.
 It additionally declares the permissions that others are needed to have so as
to move with the application's components.
 It lists the Instrumentation classes that provide profiling and other info
because the application is running. These declarations are present within the
manifest solely whereas the application is being developed and tested; they
are removed before the application is published.
 It declares the minimum level of the android API that the application needs.
 It lists the libraries that the application should be linked against.
AndroidManifest.xml could be a powerful go in the android platform that
enables you to describe the functionality and needs of your application to android.

7
Android However, working with it's not easy. Xamarin.Android helps to reduce this
Application and problem by permitting you to feature custom attributes to your classes, which can
User Interface
then be wont to automatically generate the manifest for you. Our goal is that 99 of
Design
our users should never need to manually modify AndroidManifest.xml.
AndroidManifest.xml is generated as a part of the build method, and also the
XML found inside Properties/AndroidManifest.xml is merged with XML that's
generated from custom attributes. The resulting merged AndroidManifest.xml
resides within the obj subdirectory; for example, it resides at
obj/Debug/android/AndroidManifest.xml for debug builds. The merging process
is trivial: it uses custom attributes within the code to generate XML elements, and
inserts those elements into AndroidManifest.xml.

Structure of Manifest File


The code below shows the structure of manifest file and every element that
it can contain. Each element, along with all of its attributes, is documented in full
in a separate file.

8
Android
Application
Design
Essentials - II

All the elements that appear in manifest file are highlighted below. These
are the standard elements that are used in manifest files.

9
Android
Application and
User Interface
Design

Check your progress 3


1. What is android manifest file?

a. java file
b. drivers

c. It is a file that application code, resources, permissions, icons and themes


d. None of these

2. What is the use of manifest file?


a. It names the Java package for the application

b. It determines which processes will host application components


c. It lists the libraries of the application

d. All of these

1.5 Managing different types application resources in a


hierarchy
The well-written application accesses its resources programmatically rather
than hard coding them into the source code. this is often done for a variety of
reasons. Storing application resources in a very single place is a additional
organized approach to development and makes the code more legible and
maintainable. Externalizing resources like strings makes it easier to localize
applications for various languages and geographic regions. All android
applications are composed of 2 things:

 Functionality or code instructions


10
 Data or resources Android
Application
The functionality is that the code that determines however your application Design
behaves. This includes any algorithms that make the application run. Resources Essentials - II
include text strings, images and icons, audio files, videos, and other data
employed by the application.

Android resource files are stored separately from the java class files within
the android project. Most common resource types are stored in XML. You’ll
additionally store raw data files and graphics as resources. Resources are
organized in a very strict directory hierarchy within the android project. All
resources should be stored under the /res project directory in specially named
subdirectories that has to be lowercase.

Application resources are created and stored within the android project files
under the /res directory. Employing a well-defined however flexible directory
structure, resources are organized, defined, and compiled with the appliance
package. Application resources are not shared with the rest of the android system.

Storing Application Resources


Defining application data as resources (as opposed to at runtime in code) is
good programming practice. Grouping application resources together and
compiling them into the application package has the following benefits:

 Code is cleaner and easier to read, resulting in fewer bugs.

 Resources are organized by type and guaranteed to be unique.

 Resources are conveniently set for handset customization.

 Localization and internationalization are simple.


The android platform supports a range of resource sorts, which might be
combined to create differing kinds of applications. Android applications will
include many different varieties of resources. The following are a number of the
most common resource types:

 Strings, colors, and dimensions

 Drawable graphics files

 Layout files

 Raw files of all types

Resource sorts are defined with special XML tags and organized into
specially named project directories. Some /res subdirectories, like the /drawable,
11
Android /layout, and /values directories, are created by default once a new android project
Application and is formed, however others should be added by the developer once required.
User Interface
Design Resource files stored within /res subdirectories must abide by the following rules:

 Resource filenames must be in lowercase.

 Resource filenames may contain letters, numbers, underscores, and periods


only.

 Resource filenames must be unique.

When resources are compiled, their name dictates their variable name. For
example,a graphics file saved within the /drawable directory as mypic.jpg is
referenced as @drawable/mypic. It’s necessary to name resource names
intelligently and be aware of character limitations that are stricter than file system
names. Consult the android documentation for specific project directory naming
conventions.

Simple resources like string, color, and dimension values ought to be


defined in XML files under the /res/values project directory in XML files. These
resource files use special XML tags that represent name/value pairs. These types
of resources are compiled into the application package at build time.

All application resources are keep within the /res project directory structure
and are compiled into the project at build time. Application resources may be used
programmatically. They’ll even be referenced in different application resources.
Application resources may be accessed programmatically using the generated
class file called R.java. To reference a resource from within your Activity class,
you must retrieve the application’s Resources object using the getResources()
method then build the appropriate method call, supported the kind of resource you
want to retrieve.

Check your progress 4


1. In android resources are stored inside________________.
a. Java file

b. Layout folder
c. Res Folder of XML file

d. None of these

12
Android
1.6 Let Us Sum Up Application
Design
In this unit we have learnt that Intents are asynchronous messages which
Essentials - II
permit application components to request functionality from other android
components that allow interacting with components from similar applications with
components that are contributed by other applications.
If user is running android 6.0 or later, whenever the user tries some new app
feature that needs permission, the app needs to interrupt the user's work with a
permission request.

It is noted that all application should have AndroidManifest.xml file in its


root directory that shows required info regarding an app for android system.

It is found that a well-written application accesses its resources


programmatically rather than hard coding them into the source code which often is
carried out for variety of reasons.

1.7 Answers for Check Your Progress

Check your progress 1

Answers: (1 –a), (2-c)

Check your progress 2

Answers: (1 -b)

Check your progress 3

Answers: (1 –c), (2 –d)

Check your progress 4

Answers: (1 -c)

1.8 Glossary
1. Activity - An application screen that supports Java code from Activity class.

13
Android 2. Application - In Android application, there are activities, services, listeners
Application and and intent receivers.
User Interface
Design 3. Intent - Message object which uses to communicate with certain
applications/activities asynchronously.

1.9 Assignment
Explain intent and intent filters with the help of an example.

1.10 Activities
Study android manifest file of your project.

1.11 Case Study


Study android application resources.

1.12 Further Readings


1. Learn Java for Android Development (2nd edition), Jeff Friesen, 2013

2. Android Application Development for Java Programmers, James C. Sheusi,


2012

14
UNIT 2: ANDROID USER INTERFACE
DESIGN AND COMMON APIS
Unit Structure
2.0 Learning Objectives
2.1 Introduction

2.2 User Interface Screen elements


2.3 Designing User Interfaces with Layouts

2.4 Drawing and Working with Animation


2.5 Drawing 2D and 3D Graphics and Multimedia

2.6 Let Us Sum Up


2.7 Answers for Check Your Progress

2.8 Glossary
2.9 Assignment
2.10 Activities

2.11 Case Study


2.12 Further Readings

2.0 Learning Objectives


After learning this unit, you will be able to understand:

 About User Interface Screen

 About Working with Animation

 About Drawing 2D and 3D Graphics

2.1 Introduction
The new Fragment API for android, introduced in android 3.0, permits for
easier dynamic user interfaces. API that is application program interface may be a
set of routines, protocols, and tools for building software applications. The API
specifies however software components should interact and apis are used once
15
Android programming graphical program (GUI) components. A good API makes it easier
Application and to develop a program by providing all the building blocks. A programmer then
User Interface
puts the blocks together.
Design

2.2 User Interface Screen elements


All user interface elements in an android app are built using view and
ViewGroup objects. A view is an object that draws one thing on the screen that
the user will move with. A viewGroup is an object that holds alternative View
(and ViewGroup) objects so as to define the layout of the interface.
The user interface for every component of your app is defined using a hierarchy of
view and ViewGroup objects, as shown in figure 2.1. every view group is an
invisible container that organizes child views, whereas the child views is also
input controls or other widgets that draw some part of the UI. This hierarchy tree
is often as easy or complicated as you wish it to be.

Fig 2.1 User Interface components

To declare your layout, you can instantiate View objects in code and start
building a tree, but the easiest and the most effective way to define your layout is
by using an XML file. XML offers a human-readable structure for the layout,
similar to HTML. The name of an XML element for a view is respective to the
Android class it represents. So a <TextView> element creates a TextView widget
in your UI, and a <LinearLayout> element creates a LinearLayout view group.

16
Check your progress 1 Android User
Interface
1. What is view group? Design and
Common APIS
a. class

b. It is a collection of views
c. object

d. None of these
2. What are the attributes of <TextView>?

a. android:id
b. android:editable

c. android:fontFamily
d. All of these

2.3 Designing User Interfaces with Layouts


A layout defines the visual structure for a program, like the UI for an
activity or app convenience. You’ll be able to declare a layout in 2 ways:

 Declare UI elements in XML. android provides a simple XML vocabulary


that corresponds to the read classes and subclasses, like those for widgets
and layouts.

 Instantiate layout elements at runtime. Your application will create read and
ViewGroup objects (and manipulate their properties) programmatically.
The android framework provides you the flexibility to use either or each of
those methods for declaring and managing your application's UI. For example,
you'll declare your application's default layouts in XML, including the screen
elements which will seem in them and their properties. You’ll then add code in
your application that would modify the state of the screen objects, including those
declared in XML, at run time.
The advantage to declaring your UI in XML is that it allows you to better
separate the presentation of your application from the code that controls its
behavior. Your UI descriptions are external to your application code, which
implies that you simply will modify or adapt it while not having to modify your
source code and recompile. For example, you'll produce XML layouts for
17
Android different screen orientations, totally different device screen sizes, and totally
Application and different languages. Additionally, declaring the layout in XML makes it easier to
User Interface
visualize the structure of your UI, therefore it's easier to debug problems. As such,
Design
this document focuses on teaching you how to declare your layout in XML. If you
are interested in instantiating view objects at runtime, refer to the ViewGroup and
view class references.
XML layout attributes named layout_something define layout parameters
for the view that are acceptable for the ViewGroup in which it resides.

Every ViewGroup class implements a nested class that extends


ViewGroup.LayoutParams. This subclass contains property varieties that define
the size and position for every child view, as appropriate for the view group. As
you'll see in figure 2.2, the parent view group defines layout parameters for every
child view.

Fig 2.2 Designing Layout

The geometry of a view is that of a rectangle. A view includes a location,


expressed as a pair of left and top coordinates, and 2 dimensions, expressed as a
width and a height. The unit for location and dimensions is the pixel.
It is possible to retrieve the location of a view by invoking the methods
getLeft() and getTop(). The previous returns the left, or X, coordinate of the
rectangle representing the view. The latter returns the top, or Y, coordinate of the
rectangle representing the view. These methods both return the location of the
view relative to its parent. For instance, when getLeft() returns 20, which means
the view is located 20 pixels to the right of the left edge of its direct parent.

18
In addition, many convenience strategies are offered to avoid unnecessary Android User
computations, specifically getRight() and getBottom(). These strategies come the Interface
coordinates of the correct and bottom edges of the rectangle representing the view. Design and
Common APIS
for instance, calling getRight() is similar to the following computation: getLeft() +
getWidth().

Each subclass of the ViewGroup class provides a unique way to show the
views you nest within it. Below are a number of the a lot of common layout types
that are built into the android platform.

Fig 2.3 Different Layouts

Check your progress 2


1. Where does a layout placed in android?
a. In XML file

b. In Resource folder
c. Not defined clearly

d. None of these
2. What is linear layout?

a. Placing views in rows and columns


b. Placing views either horizontally or vertically

c. Placing views in relative position


d. None of these

19
Android 2.4 Drawing and Working with Animation
Application and
User Interface It is found that in Android, the framework provides dual animation systems:
Design
 property animation

 view animation
The above two animation systems are practical options, whereas the
property animation system is preferred method to apply as it is flexible and offers
more features. Additionally, these two systems will allow drawable animation that
can be easily available to load drawable resources and will show in single frame
one after another.

Notwithstanding working on what, normally such devices carried restricted


power, which serves as highest rated mobile applications that carries sophisticated
User Experience (UX) that carries full high quality graphics as well as animations
which shows an perceptive, thus far approachable and energetic outlook. With
increase in mobile applications and leading to more and more sophisticatedness,
consumers will expect even high from applications.

Animation
Animation is the base of Android application as users like things which tend
to move here and there on the screen. Animations appear as advance way which
helps in improving user expertise for particular application that will help in
standing out. The best animations are the ones that users don’t happen to see as it
looks natural. Android provides the following three API’s for:

View Animation:
It serves as genuine API which Android gives. Such type of animations is
fixed to particular View and will able to do simple transformations of contents
regarding particular View. Being simple and ease, such API tends to be of use for
things which can be an alpha animation, rotations and further.

Property Animation:
This type of animation is introduced in Android which allows an application
to animate with all its features. It is of used when an change in property of an
object appears, as if particular object is not visible on screen.

Drawable Animation:
It is a special Drawable resource which on application results in simple
animation effect along with its layouts.

20
Android User
Check your progress 3 Interface
Design and
1. To change the property of an object we use_________.
Common APIS
a. View Animaton

b. Drawable Animation
c. Property Animation

d. All of these

2.5 Drawing 2D and 3D Graphics and Multimedia


Android is rich and carries varied framework which supports 2D and 3D
graphics along with animations. In this, the graphics splits into several approaches
which are utilized for 2D and 3D graphic animations. In Android, 3D graphics are
present through various built in frameworks which can be OpenGL ES for
OpenGL and for 3rd party frameworks as MonoGame.
It is seen that Android will have two different API’s that frames 2D graphics
which can be high level declarative approach while other is of programmatic low-
level API:

 Drawable Resources – Such resources applies to develop custom graphics


which can be programmatical or typical that embeds drawing instructions in
XML files. It is noted that Drawable resources normally are explained as
XML files having instructions or actions for Android which can be utilized
for 2D graphic.

 Canvas – It is a sort of low level API which involves drawing directly on a


bitmap and shows very fine-grained control on display.
Along with 2D graphics techniques, Android carries numerous ways to
develop animations which can be:

 Drawable Animations: It is found that Android supports frame-by-frame


animations which are called as Drawable Animation. It is easy and simple
animation API where Android sequentially loads and show Drawable
resources one after another in series just like cartoon.

 View Animations: It seems that View Animations appears as original


animation API’s which is present in Android along with its versions. Suich
type of API are restricted which allows work with View objects and will do
21
Android simple transformations on particular Views. There are normally explained in
Application and XML files which are available in /Resources/anim folder.
User Interface
Design  Property Animations: It is noted that in Android, such animations exists as
new set of animation API’s. which introduces extensible and flexible system
which can be utilized to animate properties of particular object and not
simply the View objects. It is flexible which allows animations to put in a
nutshell in different classes which allows sharing of code in easy way.

2D Graphics
Drawable Resources are customary as well as elevated mechanism in
Android applications. As with external expedients, Drawable Resources are
affirmative – they’re described in XML files. This access authorizes for a filter
estrangement of code from reserves. This can advance execution as well as
extension since it is not essential to alter code to update or convert the graphics in
an Android application.
Furthermore, while Drawable Resources are advantageous for ample
elementary as well as common graphic conditions, however the default the power
as well as control of the Canvas API.

The extraneous approach, applying the Canvas material, is very analogous


to estranged accustomed API arrangements comparable as System. Drawing or
iOS’s Core Drawing. Applying the Canvas material assigns the best control of
how 2D graphics are developed. It is applicable for circumstances where a
Drawable Resource will not perform or will be hard to work with. For exemplary,
it may be necessary to draw a custom slider control whose appearance will change
based on calculations related to the value of the slider.

Canvas Drawing API


Drawables are authoritative furthermore acquire their boundaries. Assured
substances are both not feasible and very complicated. For exemplary, conducting
a filter to a blueprint that was acquired by a camera on the appliance. It would be
very burdensome to conduct red-eye compaction by utilizing a Drawable
Resource. Instead, the Canvas API authorizes an application very establish
grained control to selectively adjust colors in a definite fraction of the picture.
One class that is averagely utilized with the Canvas endures the Paint class. This
class accepts colour as well as style information about how to illustrate on the
class. It is utilized to assign things comparable a color as well as transparency.

22
The Canvas API utilizes the painter’s archetypal to illustrate 2D graphics. Android User
Actions are conducted in successive levels on foremost of each other. Each Interface
behavior will overlay numerous domain of the basic bitmap. When the domain Design and
Common APIS
interlaces a subsequently painted domain the fresh paint will fractionally or
entirely darken the old. This is the equivalent approach abundant other drawing
APIs comparable as System.Drawing along with iOS’s Core Graphics function.

Check your progress 4


1. To create 2 – D graphics in android we can use ________.

a. Canvas
b. Drawable resources

c. Both of these
d. None of these
2. Why canvas is better than drawable resource for creating graphics?

a. It is appropriate for situations where a Drawable Resource will not work


b. the Canvas API allows an application very find grained control

c. The Canvas API uses the painter’s model to draw 2D graphics


d. All of these

2.6 Let Us Sum Up


While studying this unit, we have learnt that new Fragment API for android
introduces in android 3.0, which permits easier dynamic user interfaces. API is
application program which interface sets the routines, protocols, and tools for
building software applications.
It is studied that every user interface elements in android app that are built
using view and ViewGroup objects where view serves as object that draws one
thing on screen which user will move while viewGroup serves as object that holds
alternative View objects as define in layout of interface.
It is seen that a layout defines visual structure for a program, like UI for an
activity or app convenience that you'll be able to declare in a layout by two ways

23
Android It is noted that animations are great way to improve user experience of an
Application and application which help it stand out. The best animations are the ones that users
User Interface
don’t notice because they feel natural.
Design

2.7 Answers for Check Your Progress

Check your progress 1

Answers: (1 –b), (2-d)

Check your progress 2

Answers: (1 -a), (2-b)

Check your progress 3

Answers: (1 –c)

Check your progress 4

Answers: (1 -c), (2-d)

2.8 Glossary
1. Intent - Message object which uses to communicate with certain
applications/activities asynchronously.
2. Intent Filter - It is an object filter application which is present in manifest
file which shows system with its types of components.
3. Animation - Motion of objects created with software that allows moving an
image in motion graphics.

2.9 Assignment
Write differences among canvas and drawable resources for creating
graphics.

24
2.10 Activities Android User
Interface
Design UI of a registration system. Design and
Common APIS

2.11 Case Study


Study UI and Layout in android.

2.12 Further Readings


1. Learn Java for Android Development (2nd edition), Jeff Friesen, 2013.
2. Android Application Development for Java Programmers, James C. Sheusi,
2012.

25
Android Block Summary
Application and
User Interface In this block, you have learnt and understand about the basic of
Design
asynchronous messages and use of permissions for developing Android features.
The block gives an idea on use of Intent in interacting with components along
with extra components. You have been well explained on the various criteria’s
and rules to be followed for permission of rights.

The block detailed about the basic of visual structure for a program along
with usability of AndroidManifest.xml file. The concept related to User Interface
with respect to activity or applications are also explained to you. You will be
demonstrated practically about 2D and 3D animations in Android.

26
Block Assignment
Short Answer Questions
1. How animation can be applied in android?
2. What is the difference between intent and intent filters

3. What is view group?


4. What is meant by permission and how it can be provided?

Long Answer Questions


1. What is android manifest file? Explain in detail by providing its structure.

2. What is the difference between relative layout and linear layout?


3. Create a login form and study its manifest file.

4. How can we manage different type’s application resources in android?

27
Android Enrolment No.
Application and
User Interface 1. How many hours did you need for studying the units?
Design
Unit No 1 2 3 4

Nos of Hrs

2. Please give your reactions to the following items based on your reading of
the block:

3. Any Other Comments


………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

………………………………………………………………………………………………

28
Education is something
which ought to be
brought within
the reach of every one.

- Dr. B. R. Ambedkar

Dr. Babasaheb Ambedkar Open University


Jyotirmay’ Parisar, Opp. Shri Balaji Temple, Sarkhej-Gandhinagar Highway, Chharodi,
Ahmedabad-382 481.

You might also like