Professional Documents
Culture Documents
UNIVERSITY
ISLAMABAD
Name: Samina Asghar
Code: 3499
Assignment NO 1
Question NO 1:
(a)Define Android operating system? Also write down the
characteristics of Android system.
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:
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:
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.
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 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.
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:
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."
.
Context menu:
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.
Windows
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
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
If you're using a 64-bit version of Linux, make sure you first install the required libraries for 64-
bit machines.
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.
If you are running a 64-bit version of Ubuntu, you need to install some 32-bit libraries with the
following command:
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
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.
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.
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,
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.
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.
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.
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.
<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.
(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:
elements:
<resources>
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:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
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.
<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;
@TargetApi(Build.VERSION_CODES.O)
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView=findViewById(R.id.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 −
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
ZoomButton
Edittext:
public class EditText
extends TextView
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.EditText
AutoCompleteTextView, ExtractEditText
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.
Toggle buttons