You are on page 1of 25

ALLAMA IQBAL OPEN

UNIVERSITY
ISLAMABAD
Name: Samina Asghar

Roll No: Bp482829

Semester: 7th Semester (Autumn 2020)

Course: Mobile Application Development

Code: 3499
Assignment NO 1
Question NO 1:
(a)Define Android operating system? Also write down the
characteristics of Android system.

Android operating system:


Android is a mobile operating system based on a modified version of the Linux kernel and
other open source software, designed primarily for touchscreen mobile devices such
as smartphones and tablets. Android is developed by a consortium of developers known as
the Open Handset Alliance and commercially sponsored by Google. It was unveiled in
November 2007, with the first commercial Android device launched in September 2008.
It is free and open source software; its source code is known as Android Open Source Project
(AOSP), which is primarily licensed under the Apache License. However most Android devices
ship with additional proprietary software pre-installed, most notably Google Mobile
Services (GMS) which includes core apps such as Google Chrome, the digital
distribution platform Google Play and associated Google Play Services development platform.
About 70 percent of Android smartphones run Google's ecosystem; competing Android
ecosystems and forks include Fire OS (developed by Amazon) or Lineages. However the
"Android" name and logo are trademarks of Google which impose standards to restrict
"uncertified" devices outside their ecosystem to use android branding.
The source code has been used to develop variants of Android on a range of other electronics,
such as game consoles, digital cameras, portable media players, PCs and others, each with a
specialized user interface. Some well-known derivatives include Android T for televisions
and Wear OS for wearable’s, both developed by Google. Software packages on Android, which
use the APK format, are generally distributed through proprietary application stores like Google
Play Store, Samsung Galaxy Store, and Huawei Appealer, or open source platforms
like Antoine or F-Droid.
Android has been the best-selling OS worldwide on smartphones since 2011 and on tablets
since 2013. As of May 2017, it has over two billion monthly active users, the largest installed
base of any operating system, and as of August 2020, the Google Play Store features over
3 million apps. The current stable version is Android 11, released on September 8, 2020.
Characteristics of Android system:
With Android operating system (OS) KitKat version 4.4 rolling out to mobile devices across the
globe, Google is on to something—Android is now more popular than iOS or the Windows
phone. The OS tends to garner rave reviews for its ease of use and open source, but many iOS
or Windows phone users argue that their preferred operating system can do just as much. In
some respects that’s true, but here are 10 features unique to Android’s OS.

1) Near Field Communication (NFC)


Most Android devices support NFC, which allows electronic devices to easily interact across
short distances. The main aim here is to create a payment option that is simpler than carrying
credit cards or cash, and while the market hasn’t exploded as many experts had predicted,
there may be an alternative in the works, in the form of Bluetooth Low Energy (BLE).
2) Alternate Keyboards
Android supports multiple keyboards and makes them easy to install; the SwiftKey, Skype, and
8pen apps all offer ways to quickly change up your keyboard style. Other mobile operating
systems either don’t permit extra keyboards at all, or the process to install and use them are
tedious and time-consuming.
3) Infrared Transmission
The Android operating system supports a built-in infrared transmitter, allowing you to use your
phone or tablet as a remote control.
4) No-Touch Control
Using Android apps such as Wave Control, users can control their phones touch-free, using only
gestures. Have messy hands but need to turn off your screen or change a song? Simple. This
could prove especially useful if you’re driving, so you can keep both eyes on the road.
5) Automation
The Tasker app lets you not only control app permissions but also automate them. Do you only
want your location services to be active during the day? Want to create a customized way to
start your music—for example, with a voice command and at a certain volume? Tasker can
help.
6) Wireless App Downloads
Accessing app stores on any mobile device can be frustrating, but iOS makes it a little more
difficult—download an app on your computer, and it won’t sync to your mobile device until you
plug in and access iTunes. Using the Android Market or third-party options like AppBrain,
meanwhile, let you download apps on your PC and then automatically sync them your Droid, no
plugging required.
7) Storage and Battery Swap
Android phones also have unique hardware capabilities. Google’s OS makes it possible to
remove and upgrade your battery or to replace one that no longer holds a charge. In addition,
Android phones come with SD card slots for expandable storage.
8) Custom Home Screens
While it’s possible to hack certain phones to customize the home screen, Android comes with
this capability from the get-go. Download a third-party launcher like Nova, Apex or Slide and
you can add gestures, new shortcuts, or even performance enhancements for older-model
devices.
9) Widgets
Apps are versatile, but sometimes you want information at a glance instead of having to open
an app and wait for it to load. Android widgets let you display just about any feature you
choose, right on the home screen—including weather apps, music widgets, or productivity tools
that helpfully remind you of upcoming meetings or approaching deadlines.

10) Custom ROMs


This is a big one. Because the Android operating system is open source, developers can tweak
the current OS and build their own versions, which users can download and install in place of
the stock OS. Some are filled with features, while others change the look and feel of a device.
Chances are if there’s a feature you want, someone has already built a custom ROM for it.

Android offers a host of options not found in comparable mobile operating systems. What’s
your favorite Android-only feature?

(b) Elaborate the different between the android: version code and
android: version Name attributes in the AndroidManifest.xml file?
Android: version Code — an integer value that represents the version of the application code,
relative to other versions. The value is an integer so that other applications can
programmatically evaluate it, for example to check an upgrade or downgrade relationship. You
can set the value to any integer you want, however you should make sure that each successive
release of your application uses a greater value. The system does not enforce this behavior, but
increasing the value with successive releases is normative. Typically, you would release the first
version of your application with version Code set to 1, then monotonically increase the value
with each release, regardless whether the release constitutes a major or minor release. This
means that the android: version Code value does not necessarily have a strong resemblance to
the application release version that is visible to the user (see android: version Name, below).
Applications and publishing services should not display this version value to users.

Android: version Name — a string value that represents the release version of the application
code, as it should be shown to users. The value is a string so that you can describe the
application version as a. String, or as any other type of absolute or relative version identifier. As
with android: version Code, the system does not use this value for any internal purpose, other
than to enable applications to display it to users. Publishing services may also extract the
android: version Name value for display to user’s
AndroidManifest.xml file in android:

The AndroidManifest.xml file contains information of your package, including components of


the application such as activities, services, broadcast receivers, content providers etc.

It performs some other tasks also:

o It is responsible to protect the application to access any protected parts by


providing the permissions.
o It also declares the android app that the application is going to use.
o It lists the instrumentation classes. The instrumentation classes provides profiling
and other information’s. These information’s are removed just before the
application is published etc.

This is the required xml file for all the android application and located inside the root directory.
A simple AndroidManifest.xml file looks like this:

1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
2.     package="com.javatpoint.hello"  
3.     android:versionCode="1"  
4.     android:versionName="1.0" >  
5.   
6.     <uses-sdk  
7.         android:minSdkVersion="8"  
8.         android:targetSdkVersion="15" />  
9.   
10.     <application  
11.         android:icon="@drawable/ic_launcher"  
12.         android:label="@string/app_name"  
13.         android:theme="@style/AppTheme" >  
14.         <activity  
15.             android:name=".MainActivity"  
16.             android:label="@string/title_activity_main" >  
17.             <intent-filter>  
18.                 <action android:name="android.intent.action.MAIN" />  
19.   
20.                 <category android:name="android.intent.category.LAUNCHER" />  
21.             </intent-filter>  
22.         </activity>  
23.     </application>  
24.   
25. </manifest>  

Question NO 2:
Differentiate the following with suitable examples:

(a) Context and views

Context:
Context means the setting of a word or event. If your friend is furious at you for calling her your
worst enemy, remind her that the context of those remarks was Opposite Day.
Context comes from the Latin for how something is made. It was first used to talk about writing,
as in "the beautiful phrase occurs in the context of the concluding paragraph." We use it now to
talk about any circumstance in which something happens. You might say that you can't
understand what happens without looking at the context. When someone takes your words but
makes it sound like you meant something else, they've taken your words out of context.

Views 
Is the fourth studio album by Canadian rapper Drake. It was released on April 29, 2016, by Cash
Money Records, Republic Records, and Young Money Entertainment. Recording sessions took
place from 2015 to 2016, with both Drake and his longtime collaborator and record
producer 40 serving as the record's executive producers. 40 also primarily handled the
production on the album alongside other record producers such as Nineteen85, Manish Bid
aye, Kanye West, and Jordan Ullman, among others. Featured guest appearances
include PartyNextDoor, Pimp C, Divan, Whiz kid, Kyla, and Rihanna.
Views takes influence from West Indian and West African music. The album marks Drake's first
full foray into Jamaican dancehall music, while also featuring other genres such
as R&B, trap, Farebeat, UK funky, and pop. Similar to his previous records, the album sees
Drake discussing his relationship woes, experiences with betrayal, and celebrations of loyalty
and friendship. The album was supported by five singles: "Hotline Bling", "One Dance", "Pop
Style", "Controller", and "Too Good".
The album debuted at number one on the US Billboard 200, with over one million album-
equivalent units earned in its first week of release, including 852,000 copies, and achieving a
then record over 245 million streams. It spent a total 13 non-consecutive weeks at number one
on the Billboard 200, and also became Drake's first number-one album on the UK Albums Chart.
All 20 songs from the album charted on the US Billboard Hot 100.
The album received lukewarm reviews from critics, many of whom found it to be an overlong
retread of Drake's previous work. Despite this, it became Drake's most commercially successful
album having sold over seven million certified units worldwide. The album has been certified six
times platinum by the Recording Industry Association of America (RIAA). It was nominated
for Album of the Year and Best Rap Album at the 2017 Grammy Awards.

(b) Orientation and Layout


Orientation:
 Is the way in which a rectangular page is oriented for normal viewing? The two most common
types of orientation are portrait and landscape. The term "portrait orientation" comes
from visual art terminology and describes the dimensions used to capture a person's face and
upper body in a picture; in such images, the height of the display area is greater than the width.
The term "landscape orientation" also reflects visual art terminology, where pictures with more
width than height are needed to fully capture the horizon within an artist's view.
Besides describing the way documents can be viewed and edited, the concepts of "portrait"
and "landscape" orientation can also be used to describe video and photography display
options (where the concept of "aspect ratio" replaces that of "page orientation"). Many types
of visual media use landscape mode, especially the 4:3 aspect ratio used for classic TV
formatting, which is 4 units or pixels wide and 3 units tall, and the 16:9 aspect ratio for
newer, widescreen media viewing.
Most paper documents use portrait orientation. By default, most computer and television
displays use landscape orientation, while most mobile phones use portrait orientation (with
some flexibility on modern smartphones to switch screen orientations according to user
preference). Portrait mode is preferred for editing page layout work, in order to view the entire
page of a screen at once without showing wasted space outside the borders of a page, and for
script-writing, legal work (in drafting contracts etc.), and other applications where it is useful to
see a maximum number of lines of text. It is also preferred for smartphone use, as a phone in
portrait orientation can be operated easily with one hand. Landscape viewing, on the other
hand, visually caters to the natural horizontal alignment of human eyes at the same time
landscape details are much wider than they are taller, and is therefore useful for portraying
wider visuals with multiple elements that need to be observed simultaneously.
Layouts

A layout defines the structure for a user interface in your app, such as in an activity. All
elements in the layout are built using a hierarchy of View and View Group objects.
A View usually draws something the user can see and interact with. Whereas a View Group is
an invisible container that defines the layout structure for View and other View Group objects,
as shown in figure 1.

The View objects are usually called "widgets" and can be one of many subclasses, such
as Button or Text View. The View Group objects are usually called "layouts" can be one of many
types that provide a different layout structure, such as Linear Layout or Constraint Layout.

You can declare a layout in two ways:

 Declare UI elements in XML. Android provides a straightforward XML vocabulary that


corresponds to the View classes and subclasses, such as those for widgets and layouts.

You can also use Android Studio's Layout Editor to build your XML layout using a drag-and-drop
interface.

 Instantiate layout elements at runtime. Your app can create View and View Group
objects (and manipulate their properties) programmatically.

Declaring your UI in XML allows you to separate the presentation of your app from the code
that controls its behavior. Using XML files also makes it easy to provide different layouts for
different screen sizes and orientations (discussed further in Supporting Different Screen Sizes).

The Android framework gives you the flexibility to use either or both of these methods to build
your app's UI. For example, you can declare your app's default layouts in XML, and then modify
the layout at runtime.

(c) Android Emulator and Android SDDK

Android – Emulator:

The Android Emulator simulates Android devices on your computer so that you can test your
application on a variety of devices and Android API levels without needing to have each physical
device.

The emulator provides almost all of the capabilities of a real Android device. You can simulate
incoming phone calls and text messages, specify the location of the device, simulate different
network speeds, simulate rotation and other hardware sensors, access the Google Play Store,
and much more.

Testing your app on the emulator is in some ways faster and easier than doing so on a physical
device. For example, you can transfer data faster to the emulator than to a device connected
over USB.

The emulator comes with predefined configurations for various Android phone, tablet, Wear
OS, and Android TV devices.

Android SDDK
The Android software development kit (SDK) includes a comprehensive set of development
tools. These include a debugger, libraries, a handset emulator based on QEMU, documentation,
sample code, and tutorials. Currently supported development platforms include computers
running Linux (any modern desktop Linux distribution), Mac OS X 10.5.8 or later, and Windows
7 or later. As of March 2015, the SDK is not available on Android itself, but software
development is possible by using specialized Android applications.
Until around the end of 2014, the officially-supported integrated development
environment (IDE) was Eclipse using the Android Development Tools (ADT) Plugin,
though IntelliJ IDEA IDE (all editions) fully supports Android development out of the
box, and Net Beans IDE also supports Android development via a plugin. As of 2015, Android
Studio, made by Google and powered by IntelliJ, is the official IDE; however, developers are free
to use others, but Google made it clear that ADT was officially deprecated since the end of 2015
to focus on Android Studio as the official Android IDE. Additionally, developers may use any text
editor to edit Java and XML files, then use command line tools (Java Development
Kit and Apache Ant are required) to create, build and debug Android applications as well as
control attached Android devices (e.g., triggering a reboot, installing software package(s)
remotely).
Enhancements to Android's SDK go hand-in-hand with the overall Android platform
development. The SDK also supports older versions of the Android platform in case developers
wish to target their applications at older devices. Development tools are downloadable
components, so after one has downloaded the latest version and platform, older platforms and
tools can also be downloaded for compatibility testing.

Android applications are packaged in .apk format and stored under  /data/app  folder on the
Android OS (the folder is accessible only to the root user for security reasons). APK package
contains .dex files (compiled byte code files called Dalvik executable), resource files, etc.
(d) Menu and Context Menu:
Menus

Menus are a common user interface component in many types of applications. To provide a
familiar and consistent user experience, you should use the Menu APIs to present user actions
and other options in your activities.

Beginning with Android 3.0 (API level 11), Android-powered devices are no longer required to
provide a dedicated Menu button. With this change, Android apps should migrate away from a
dependence on the traditional 6-item menu panel and instead provide an app bar to present
common user actions.

Although the design and user experience for some menu items have changed, the semantics to
define a set of actions and options is still based on the Menu APIs. This guide shows how to
create the three fundamental types of menus or action presentations on all versions of
Android:

Options menu and app bar

The options menu is the primary collection of menu items for an activity. It's where you should
place actions that have a global impact on the app, such as "Search," "Compose email," and
"Settings."

See the section about Creating an Options Menu.

.
Context menu:

A context menu is a pop-up menu that provides shortcuts for actions the software developer


anticipates the user might want to take.  

In a Windows environment, the context menu is accessed with a right mouse click.  For
example, if the end user right-clicks in a Word document, the pop-up menu will include
shortcuts for undo, cut, copy and paste.  If the end user right-clicks in Excel, however, the
context menu also includes shortcuts for insert cell, delete cell, paste special and other
commands that are commonly used for that program. 

User interaction with context menus depends upon the computing device, its operating system
(OS) and it input mechanisms. If the user does not have a mouse, for example, he may access
context menus by pressing a keyboard combination, pressing and holding a trackball, holding a
tap on a touch screen or placing two fingers on a touch pad. Context menus can be closed by
selecting an action or clicking outside the menu area in open space.

Windows 7 and Windows 8 allow users to modify the operating system's context menu to add
desired actions or remove unused options. However, this requires extensive knowledge of the
Windows registry or the aid of third-party tools such as Shell New Handler or New Menu Editor.

Question NO 3:
(a) Install Android Studio on your computer and write down the
complete process.

Install Android Studio:

Setting up Android Studio takes just a few clicks.

First, be sure you download the latest version of Android Studio.

Windows

To install Android Studio on Windows, proceed as follows:

1. If you downloaded an .exe file (recommended), double-click to launch it.

If you downloaded a .zip file, unpack the ZIP, copy the android-studio folder into your Program
Files folder, and then open the android-studio > bin folder and launch studio64.exe (for 64-bit
machines) or studio.exe (for 32-bit machines).

2. Follow the setup wizard in Android Studio and install any SDK packages that it
recommends.

That's it. The following video shows each step of the setup procedure when using the
recommended .exe download.

As new tools and other APIs become available, Android Studio tells you with a pop-up, or you
can check for updates by clicking Help > Check for Update.

Mac

To install Android Studio on your Mac, proceed as follows:


1. Launch the Android Studio DMG file.

2. Drag and drop Android Studio into the Applications folder, then launch Android Studio.

3. Select whether you want to import previous Android Studio settings, then click OK.

4. The Android Studio Setup Wizard guides you through the rest of the setup, which
includes downloading Android SDK components that are required for development.

That's it. The following video shows each step of the recommended setup procedure

Linux

To install Android Studio on Linux, proceed as follows:

1. Unpack the .zip file you downloaded to an appropriate location for your applications,


such as within /user/local/ for your user profile, or /opt/ for shared users.

If you're using a 64-bit version of Linux, make sure you first install the required libraries for 64-
bit machines.

2. To launch Android Studio, open a terminal, navigate to the android-


studio/bin/ directory, and execute studio.sh.

3. Select whether you want to import previous Android Studio settings or not, then
click OK.

4. The Android Studio Setup Wizard guides you through the rest of the setup, which
includes downloading Android SDK components that are required for development.

Required libraries for 64-bit machines

If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with the
following command:

Studio apt-get install libc6:i386 libncurses5:i386 listed++6:i386 lib32z1 libbz2-1.0:i386

If you are running 64-bit Fedora, the command is:

Studio yum install zlib.i686 ncurses-libs.i686 bzip2-libs.i686

That's it. The following video shows each step of the recommended setup procedure.

As new tools and other APIs become available, Android Studio tells you with a pop-up, or you
can check for updates by clicking Help > Check for Update.
Chrome OS

Follow these steps to install Android Studio on Chrome OS:

1. If you haven't already done so, install Linux for Chrome OS.

2. Open the Files app and locate the DEB package you downloaded in


the Downloads folder under My files.

3. Right-click the DEB package and select Install with Linux (Beta).

4. If you have installed Android Studio before, select whether you want to import previous
Android Studio settings, then click OK.

5. The Android Studio Setup Wizard guides you through the rest of the setup, which includes
downloading Android SDK components that are required for development.
6. After installation is complete, launch Android Studio either from the Launcher, or from the
Chrome OS Linux terminal by running studio.sh in the default installation directory:

/opt/android-studio/bin/studio.sh

That's it. As new tools and other APIs become available, Android Studio tells you with a pop-up,
or you can check for updates by clicking Help > Check for Update.

(b) Differentiate the Eclipse and Android Studio Integrated


Development with an application.
Android Studio Vs Eclipse
I have written this article about differences between Android Studio Vs Eclipse is something i
have experienced during my android application development. And i will tell you the reason
why i prefer Android Studio over Eclipse.

Eclipse:

Eclipse is simple and shorter build time when compare to android Studio. It is very lagging when
you switch between layouts and java files. Poor layout preview and not good user friendly.
Good for small android application development. Faster APK build when compared to Android
Studio. Since Eclipse has been around for so long you can find support from many online
sources.

 Easy Portable – platform independent


 Faster IDE launch
 Good for small application development
 Simple – Because of less features

Android Studio

Android Studio has been released stable version on June 2015. The Android Studio IDE is based
off IntelliJ IDEA from Jet Brains and is being offered by Google for free which is developed and
supported by Google, same developer of android OS. Which is regularly updated and adding
new features and fixing bugs reported by developers making it is best choice for android
application development. Greater build time when comparing with Eclipse. Advanced Code
completion and refactoring tools. Some of the main features of Android Studio are as follows,

 Flexible Grade-based build system


 Build variants and multiple apk file generation
 Code templates to help you build common app features
 Rich layout editor with support for drag and drop theme editing
 lint tools to catch performance, usability, version compatibility, and other problems
 Pro Guard and app-signing capabilities
 Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud
Messaging and App Engine
 And much more…

Question NO 4:
(a) Explain the procedure of creating user Interface through GUI and
programmatically.
Programming Graphical User Interface (GUI):
So far, we have covered the basic programming constructs (such as variables, data types,
decision, loop, array and method) and introduced the important concept of Object-Oriented
Programming (OOP). As discussed, OOP permits higher level of abstraction than traditional
Procedural-Oriented languages (such as C and Pascal). You can create high-level abstract data
types called classes to mimic real-life things. These classes are self-contained and are reusable.
In this article, I shall show you how you can reuse the graphics classes provided in JDK for
constructing your own Graphical User Interface (GUI) applications. Writing your own graphics
classes (and re-inventing the wheels) is mission impossible! These graphics classes, developed
by expert programmers, are highly complex and involve many advanced design patterns. 
However, re-using them are not so difficult, if you follow the API documentation, samples and
templates provided.
I shall assume that you have a good grasp of OOP, including composition, inheritance,
polymorphism, abstract class and interface; otherwise, read the earlier articles. I will describe
another important OO concept called nested class (or inner class) in this article.
There are current three sets of Java APIs for graphics programming: AWT
(Abstract Windowing Toolkit), Swing and JavaFX.
1. AWT API was introduced in JDK 1.0. Most of the AWT components have become
obsolete and should be replaced by newer Swing components.
2. Swing API, a much more comprehensive set of graphics libraries that enhances the AWT,
was introduced as part of Java Foundation Classes (JFC) after the release of JDK 1.1. JFC
consists of Swing, Java2D, Accessibility, Internationalization, and Pluggable Look-and-Feel
Support APIs. JFC has been integrated into core Java since JDK 1.2.
3. The latest JavaFX, which was integrated into JDK 8, is meant to replace Swing.

Android User Interface: Creating UI programmatically in Android

In this article we will talk about user interface in Android. We will discuss about Android
operating system which is much more suitable for user-friendly operations.

Actually, Android is a complete Operating System that fully support mobile technology. We


know about the Activity class and also know the life cycle of the activity class. We can say that
this activity is a means by which users cooperate with the application. Nevertheless, the activity
by itself does not have a presence on the screen. As an alternative, it has to draw the screen by
using Views and View Groups. In that certain stage, we will study the particulars about creating
user interfaces in Android application, and how users interact with them. After that we will
learn the procedure that can handle the changes in screen orientation on our Android devices.

Now here we are giving very small illustration about some User Interface after that we will be
discuss about some features elaborately. Now some UI is given bellow.

Procedure to Set Views and Linear Layout User Interface Programmatically


Now here we are discussing about the Linear Layout. This Linear Layout arranges views in a
single column or a single row manner. Basically the Child views can be structured either
vertically or horizontally. The file is also written here.

Sample linear layout

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


<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”filling_parent”
android:layout_height=”filling_parent”
android:orientation=”horizontal” >
<TextView
android:layout_width=”filling_parent”
android:layout_height=”wraping_contents”
android:text=”@string/welcome”/>
</LinearLayout>

Above program is now illustrated through the main.xml file. In the program segment we
perceive that the root (main segment) of the element is <Linear Layout> and it has a <Text
View> element present inside it. The <Linear Layout> element controls the order in which the
views are restricted.

In that respect we take an illustration, the width of the <Text View> element fills the entire
width of its parent. Basically the screen adjusts are using the filling parent constant. Its height is
specified by the wraping_contents constant. After that if we do not think about the <Text View>
view to occupy the entire row, for that circumstance we can set its layout width attribute to
wraping_contents, this process is like below.

Sample showing layout

<TextView
android:layout_width=”wraping_contents”
android:layout_height=”wraping_contents”
android:text=”@string/Welcome” />

This code is used to set the width of the view to be equal to the width of the text contained
within its unambiguous locality. After that we can consider the following layout as per our
requirement.

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


<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”filling_parent”
android:layout_height=”filling_parent”
android:orientation=”horizontal” >
<TextView
android:layout_width=”100dp”
android:layout_height=”wraping_contents”
android:text=”@string/Welcome” />
<Button
android:layout_width=”160dp”
android:layout_height=”wraping_contents”
android:text=”Button”
android:onClick=”onClick”/>
</LinearLayout>

(b) What is the difference between Layout and views? Also elaborate
different types of layouts.
Layout
To give you a different example of why you use each component (layout / view / partial view),
imagine that you own a website that has 100 pages in total, and let say you want to update the
design of your website, how are you going to do it?

Updating each page individually would drive me insane, because you’re replicating your code
constantly for every single page, just to update your design.

This is what the Layout view helps you solve, you use the Layout view to create a template for
all of your pages.

View
Using our existing scenario of 100 page website, each page is going to have content that is
unique, the View allows us to display this content whilst using our template from the Layout.

Partial View
Now let imagine that we allow our visitors to comment on our pages, each comment must look
consistent, and behave exactly the same as all the other comments throughout our website...
To achieve this, you would use a Partial View which would act as a template for the comments
that you receive on your website.
The benefits of doing this is that you don't have to repeat your code everywhere, you only have
to create one Partial View to render any comment.

TYPES OF LAYOUTS
There are four basic layout types: process, product, hybrid, and fixed position. In this section we
look at the basic characteristics of each of these types. Then we examine the details of
designing some of the main types.
Process layouts Layouts that group resources based on similar processes or functions. Process
layouts arrange items by type as seen in this grocery store.
Product layouts are layouts that group resources based on similar processes or functions. This
type of layout is seen in companies with intermittent processing systems. You would see a
process layout in environments in which a large variety of items are produced in a low volume.
Since many different items are produced, each with unique processing requirements, it is not
possible to dedicate an entire facility to each item. It is more efficient to group resources based
on their function. The products are then moved from one resource to another, based on their
unique needs.

The challenge in process layouts is to arrange resources to maximize efficiency and minimize
waste of movement. If the process layout has not been designed properly, many products will
have to be moved long distances, often on a daily basis.
Question NO 5:
(a) How do you access the string resource stored in the string. Xml
file? Also write the code snippet to obtain the current date.
String Resources
A string resource provides text strings for your application with optional text styling and
formatting. There are three types of resources that can provide your application with strings:
String
XML resource that provides a single string.
String Array
XML resource that provides an array of strings.
Quantity Strings (Plurals)
XML resource that carries different strings for pluralization.
All strings are capable of applying some styling markup and formatting arguments. For
information about styling and formatting strings, see the section about Formatting and Styling.
String
A single string that can be referenced from the application or from other resource files (such as
an XML layout).
Note: A string is a simple resource that is referenced using the value provided in
the name attribute (not the name of the XML file). So, you can combine string resources with
other simple resources in the one XML file, under one <resources> element.
file location:
res/values/filename.xml
The filename is arbitrary. The <string> element's name will be used as the resource ID.
compiled resource data type:
Resource pointer to a String.

resource reference:
In Java: R.string.string_name
In XML:@string/string_name

syntax:

<?xml version="1.0" encoding="utf-8"?>


<resources>
    <string
        name="string_name"
        >text_string</string>
</resources>

elements:
<resources>

Required. This must be the root node.

No attributes.
<string>

A string, which can include styling tags. Beware that you must escape apostrophes and
quotation marks. For more information about how to properly style and format your
strings see Formatting and Styling, below.

attributes:
name

String. A name for the string. This name will be used as the resource ID.

example:
XML file saved at res/values/strings.xml:

<?xml version="1.0" encoding="utf-8"?>


<resources>
    <string name="hello">Hello!</string>
</resources>

This layout XML applies a string to a View:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

This application code retrieves a string:

String string = getString(R.string.hello);

You can use either getString(int) or getText(int) to retrieve a


string. getText(int) will retain any rich text styling applied to the string.
Current time and date:
As per Oracle documentation, Simple Date Format is a concrete class for formatting and parsing
dates in a locale-sensitive manner. In this example, we have imported simple date format class
from java as shown below -

import java.text.SimpleDateFormat;
import java.util.Date;

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required
details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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:gravity="center"

   android:layout_height="match_parent">

   <TextView

      android:id="@+id/date"

      android:layout_width="wrap_content"

      android:layout_height="wrap_content"

      android:layout_centerHorizontal="true"

      android:textSize="30sp"

      android:layout_marginBottom="36dp" />

</RelativeLayout>

In the above code, we have given text view, it going to print the current date on the window
manager.
Step 3 − Add the following code to src/MainActivity.java

package com.example.andy.myapplication;

import android.annotation.TargetApi;

import android.os.Build;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.widget.TextView;

import java.text.SimpleDateFormat;

import java.util.Date;

public class MainActivity extends AppCompatActivity {

   @TargetApi(Build.VERSION_CODES.O)

   @Override

   protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

      TextView textView=findViewById(R.id.date);

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss z");

      String currentDateandTime = sdf.format(new Date());

      textView.setText(currentDateandTime);

   }

In the above code we are calling SimpleDateFormat and from the simpledateformat, we are
accessing the current date in the string. There are so many date format are available. For more
reference Click here.
Step 4 − No need to change manifest.xml.
Let's try to run your application. I assume you have connected your actual Android Mobile
device with your computer. To run the app from an android studio, open one of your project's
activity files and click Run  from the toolbar. Select your mobile device as an option and then
check your mobile device which will display your default screen −

(b) Explain Button, imageButton, edittext, checkBox, toggleButton,


radioButton, and radiogroup views.
In Android, Radio Button are mainly used together in a Radio Group. In Radio Group checking
the one radio button out of several radio button added in it will automatically unchecked all the
others. It means at one time we can checked only one radio button from a group of radio
buttons which belong to same radio group. The most common use of radio button is in Quiz
Android App code.

Radio Button is a two state button that can be checked or unchecked. If a radio button is
unchecked then a user can check it by simply clicking on it. Once a Radio Button is checked by
user it can’t be unchecked by simply pressing on the same button. It will automatically
unchecked when you press any other Radio Button within same Radio Group.

Important Note: Radio Group is a widget used in Android for the grouping of radio buttons and
provide the feature of selecting only one radio button from the set. When a user try to select
any other radio button within same radio group the previously selected radio button will be
automatically unchecked.
Radio Group And Radio Button code in XML:

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/simpleRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton
android:id="@+id/simpleRadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>

ImageButton:
public class ImageButton
extends ImageView
java.lang.Object

   ↳ android.view.View

     ↳ android.widget.ImageView

       ↳ android.widget.ImageButton

Known direct subclasses

ZoomButton

Edittext:
public class EditText
extends TextView
java.lang.Object

   ↳ android.view.View
     ↳ android.widget.TextView

       ↳ android.widget.EditText

Known direct subclasses

AutoCompleteTextView, ExtractEditText

Known indirect subclasses

MultiAutoCompleteTextView

Checkbox:
A checkbox (check box, tickbox, tick box) is a GUI widget that permits the user to make a
binary choice, i.e. a choice between one of two possible mutually exclusive options. For
example, the user may have to answer 'yes' (checked) or 'no' (not checked) on a simple yes/no
question.
Check boxes are shown as when unchecked, or ☑ or ☒ (depending on the GUI) when checked.
A caption describing the meaning of the checkbox is normally shown adjacent to the checkbox.
Inverting the state of a checkbox is done by clicking the mouse on the box, or the caption, or by
using a keyboard shortcut, such as the space bar.
Often, a series of checkboxes is presented, each with a binary choice between two options.
Then the user may select several of the choices. Contrasting is a radio button, in which only a
single option is selectable from several mutually-exclusive choices.
ToggleButton:

A toggle button allows the user to change a setting between two states.

You can add a basic toggle button to your layout with the ToggleButton object. Android 4.0 (API
level 14) introduces another kind of toggle button called a switch that provides a slider control,
which you can add with a Switch object. SwitchCompat is a version of the Switch widget which
runs on devices back to API 7.

If you need to change a button's state yourself, you can use


the CompoundButton.setChecked() or CompoundButton.toggle() method.

Toggle buttons

You might also like