0% found this document useful (0 votes)
10 views78 pages

6CS4-24 - Mad Lab Manual - 2022-23

The MAD Lab Manual for Poornima College of Engineering outlines the lab structure, including the vision and mission of the institute and department, the syllabus, and evaluation schemes for the Android programming lab. It details the experiments to be conducted, safety rules, and general instructions for lab conduct. The manual aims to equip students with practical skills in Android application development while adhering to academic and safety standards.

Uploaded by

tanishamahavar32
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)
10 views78 pages

6CS4-24 - Mad Lab Manual - 2022-23

The MAD Lab Manual for Poornima College of Engineering outlines the lab structure, including the vision and mission of the institute and department, the syllabus, and evaluation schemes for the Android programming lab. It details the experiments to be conducted, safety rules, and general instructions for lab conduct. The manual aims to equip students with practical skills in Android application development while adhering to academic and safety standards.

Uploaded by

tanishamahavar32
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/ 78

Poornima College of Engineering, Jaipur MAD Lab Manual

ISI-6, RIICO Institutional Area, Sitapura, Jaipur-302022, Rajasthan


Phone/Fax: 0141-2770790-92, www.pce.poornima.org

MAD Lab Manual


(Lab Code: 6CS4-24)
6thSemester, 3thYear

Department of Computer Engineering


Session: 2022-23
Poornima College of Engineering, Jaipur MAD Lab Manual

TABLE OF CONTENT
S.No. Topic/Name of Experiment Page
Number
GENERAL DETAILS

1 Vision & Mission of Institute and Department iii

2 RTU Syllabus and Marking Scheme iv

3 Lab Outcomes and its Mapping with POs and PSOs v

4 Lab Conduction Plan vii

5 General Lab Instructions viii

6 Lab Specific Safety Rules ix

LIST OF EXEPERIMENTS WITH VIVA QUESTIONS (AS PER RTU SYLLABUS)

A Zero Lecture 1
To study Android Studio and android studio installation. Create “Hello
1 World” application 10
To understand Activity, Intent, Create sample application with login 12
2 module. (Check username and password).
3 Design simple GUI application with activity and intents e.g. calculator. 20
Develop an application that makes use of RSS Feed. 24
4
Write an application that draws basic graphical primitives on the screen 33
5
Create an android app for database creation using SQLite 36
6 Database.
7 Develop a native application that uses GPS location information 45

Implement an application that writes data to the SD card. 49


8
Design a gaming application 54
9

10 Create an application to handle images and videos according to size. 60

Beyond the Syllabus Experiment-1 62


11
Beyond the Syllabus Experiment-2 65
12
Poornima College of Engineering, Jaipur DIP Lab Manual

INSTITUTE VISION & MISSION

VISION
To create knowledge based society with scientific temper, team spirit and dignity of
labor to face the global competitive challenges

MISSION
To evolve and develop skill based systems for effective delivery of knowledge so as
to equip young professionals with dedication & commitment to excellence in all
spheres of life.

DEPARTMENT VISION & MISSION

VISION
Evolve as a center of excellence with wider recognition and to adapt the rapid
innovationin Computer Engineering.

MISSION

 To provide a learning-centered environment that will enable students and


faculty members to achieve their goals empowering them to compete
globally for the most desirable careers in academia and industry.

 To contribute significantly to the research and the discovery of new arenas of


knowledge and methods in the rapid developing field of Computer
Engineering.

 To support society through participation and transfer of advanced technology


from one sector to another.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur DIP Lab Manual

RTU SYLLABUS AND MARKING SCHEME


6CS4-21: Digital Image Processing LAB

Credit: 1 Max. Marks: 50(IA:30,ETE:20)

0L+0T+2P End Term Exam:2Hours


S. No. NAME OF EXPERIMENTS
To study Android Studio and android studio installation. Create “Hello World”
1 application.

To understand Activity, Intent, Create sample application with login module. (Check
2 username and password).

3 Design simple GUI application with activity and intents e.g. calculator.
Develop an application that makes use of RSS Feed.
4
Write an application that draws basic graphical primitives on the screen
5
Create an android app for database creation using SQLite Database.
6
Develop a native application that uses GPS location information
7

8 Implement an application that writes data to the SD card.


Design a gaming application
9

10 Create an application to handle images and videos according to size.

EVALUATION SCHEME

I+II Mid Term Examination Attendance and performance End Term Examination
Total Marks
Experiment Viva Total Attendance Performance Total Experiment Viva Total

15 5 20 15 5 20 15 5 20 60

DISTRIBUTION OF MARKS FOR EACH EXPERIMENT

Attendance Record Performance Total


2 3 5 10

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur

LAB OUTCOME AND ITS MAPPING WITH PO & PSO

LAB OUTCOMES

Lab Outcomes:
Discuss the components and different Layout for mobile application
6CS4-24.1
development framework for android
6CS4-24.2 Apply essential Android Programming concepts.
Analyze various Android applications related to layouts & rich uses
6CS4-24.3
interactive interfaces.
Develop Android applications related to mobile related server-less
6CS4-24.4 database like SQLITE.

LO-PO-PSO MAPPING MATRIX OF COURSE


LO/PO/P PO PO PO PO PO PO PO PO PO PO1 PO PO1 PS PS PS
SO 1 2 3 4 5 6 7 8 9 0 11 2 O1 O2 O3
2 - - - - - - - - - - - 3 - -
6CS4-
24.1
- 2 - - 2 - - - - - - - 3 - 2
6CS4-
24.2
- - 2 - - - - - - - - - 2 - -
6CS4-
24.3
- - - 2 - - - - - - - - 2 2 -
6CS4-
24.4

PROGRAM OUTCOMES (POs)

Engineering knowledge: Apply the knowledge of mathematics, science, engineering


PO1
fundamentals, and an engineering specialization to the solution of complex engineering
problems
Problem analysis: Identify, formulate, review research literature, and analyze complex
PO2 engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur

Design/development of solutions: Design solutions for complex engineering


PO3 problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and
PO4 research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and
PO5 modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge to
PO6 assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
Environment and sustainability: Understand the impact of the professional
PO7 engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities
PO8
and norms of the engineering practice.
Individual and teamwork: Function effectively as an individual, and as a member or
PO9
leader in diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the
PO10 engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations,
and give and receive clear instructions.
Project management and finance: Demonstrate knowledge and understanding of the
PO11 engineering and management principles and apply the setoone’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
Life-long learning: Recognize the need for, and have the preparation and ability to
PO12
engage in independent and life-long learning in the broadest context of technological
change.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur

PROGRAM SPECIFIC OUTCOMES (PSOs)

The ability to understand and apply knowledge of mathematics, system analysis &
PSO1
design, Data Modelling, Cloud Technology, and latest tools to develop computer
based solutions in the areas of system software, Multimedia, Web Applications, Big
data analytics, IOT, Business Intelligence and Networking systems
PSO2 The ability to understand the evolutionary changes in computing, apply
standards and ethical practices in project development using latest tools &
Technologies to solve societal problems and meet the challenges of the future.
PSO3 The ability to employ modern computing tools and platforms to be an entrepreneur,
lifelong learning and higher studies

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

LAB CONDUCTION PLAN

Total number of experiment: 12


Total number of turns required: 12
Number of turns required for:

Experiment Number Turns Scheduled Day


Exp. 1 1 Day 1
Exp. 2 1 Day 2
Exp. 3 1 Day 3
Exp. 4 1 Day 4
Exp. 5 1 Day 5
Exp. 6 1 Day 6
Exp. 7 1 Day 7
Exp. 8 1 Day 8
Exp. 9 1 Day 9
Exp. 10 1 Day 10
Exp. 11 1 Day 11
Exp. 12 1 Day 12

DISTRIBUTIONOF LAB HOURS

Distribution of Lab Hours


S. No. Activity
Time(180minute)
1 Attendance 5
2 Explanation of features of language 20
3 Explaining the Experiment 60
4 Performance of experiment 80
5 Viva/Quiz/Queries 15

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

GENERAL LAB INSTRUCTIONS

DO’S
 Enter the lab on time and leave at proper time.
 Wait for the previous class to leave before the next class enters.
 Keep the bag outside in the respective racks.
 Utilize lab hours in the corresponding.
 Turn off the machine before leaving the lab unless a member of lab staff has specifically
told you not to do so.
 Leave the labs at least as nice as you found them.
 If you notice a problem with a piece of equipment (e.g. a computer doesn't respond) or the
room in general (e.g. cooling, heating, lighting) please report it to lab staff immediately.
Do not attempt to fix the problem yourself.

DON’TS
 Don't abuse the equipment.
 Do not adjust the heat or air conditioners. If you feel the temperature is not properly set,
inform lab staff; we will attempt to maintain a balance that is healthy for people and
machines.
 Do not attempt to reboot a computer. Report problems to lab staff.
 Do not remove or modify any software or file without permission.
 Do not remove printers and machines from the network without being explicitly told to do
so by lab staff.
 Don't monopolize equipment. If you're going to be away from your machine for more than
10 or 15 minutes, log out before leaving. This is both for the security of your account, and
to ensure that others are able to use the lab resources while you are not.
 Don’t use internet, internet chat of any kind in your regular lab schedule.
 Do not download or upload of MP3, JPG or MPEG files.
 No games are allowed in the lab sessions.
 No hardware including USB drives can be connected or disconnected in the labs without
prior permission of the lab in-charge.
 No food or drink is allowed in the lab or near any of the equipment. Aside from the fact
that it leaves a mess and attracts pests, spilling anything on a keyboard or other piece of
computer equipment could cause permanent, irreparable, and costly damage. (and in fact
has) If you need to eat or drink, take a break and do so in the canteen.
 Don’t bring any external material in the lab, except your lab record, copy and books.
 Don’t bring the mobile phones in the lab. If necessary then keep them in silence mode.
 Please be considerate of those around you, especially in terms of noise level. While labs
are a natural place for conversations of all types, kindly keep the volume turned down.

If you are having problems or questions, please go to either the faculty, lab in-charge or the lab
supporting staff. They will help you. We need your full support and cooperation for smooth
functioning of the lab.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

LAB SPECIFIC SAFETY RULES

Before entering in the lab

 All the students are supposed to prepare the theory regarding the next experiment/
Program.
 Students are supposed to bring their lab records as per their lab schedule.
 Previous experiment/program should be written in the lab record.
 If applicable trace paper/graph paper must be pasted in lab record with proper labeling.
 All the students must follow the instructions, failing which he/she may not be allowed in
the lab.

While working in the lab

 Adhere to experimental schedule as instructed by the lab in-charge/faculty.


 Get the previously performed experiment/ program signed by the faculty/ lab in charge.
 Get the output of current experiment/program checked by the faculty/ lab in charge in the
lab copy.
 Each student should work on his/her assigned computer at each turn of the lab.
 Take responsibility of valuable accessories.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Zero Lecture

Procedure

▪ One experiment with its variants will be performed by the Batch in Each Lab.
▪ Students will perform experiments in the group of four (Self Help Group) for a time slot and
so on.
▪ For first 30 Minutes program for the Experiments will be explained.
▪ Students will Develop Coding in the remaining Session and perform the experiments.
▪ In last 30 minutes viva and lab records will be evaluated.
▪ Students will be directed to write all the experiments in their Lab Records.

Getting Started

Software required: Android Studio.

STEPS FOR EXECUTION OF PROGRAM

Android - Environment Setup

Step 1 - System Requirements

You will be delighted, to know that you can start your Android application development on
either of the following operating systems −

● Microsoft® Windows® 10/8/7/Vista/2003 (32 or64-bit)


● Mac® OS X® 10.8.5 or higher, up to 10.9(Mavericks)
● GNOME or KDE desktop
Second point is that all the required tools to develop Android applications are
open source and can be downloaded from the Web. Following is the list of
software's you will need before you start your Android application
programming.

● Java JDK5 or later version


● Java Runtime Environment (JRE) 6
● Android Studio

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Step 2 - Setup Android Studio

Overview

Android Studio is the official IDE for android application development. It works based on
IntelliJIDEA, You can download the latest version of android studio from Android
Studio 2.2 Download, If you are new to installing Android Studio on windows, you will
find a file, which is named as android-studio-bundle- 143.3101438-windows.exe. So just
download and run on windows machine according to android studio wizard guideline.
If you are installing Android Studio on Mac or Linux, You can download the latest
version from Download, or Android Studio Linux Download, check the instructions
provided along with the downloaded file for MacOS and Linux. This tutorial will consider
that you are going to setup your environment on Windows machine having Windows 8.1
operating system.

Installation

So let's launch Android Studio.exe, Make sure before launch Android Studio, Our
Machine should required installed Java JDK. To install Java JDK, take a reference of
Android environment setup

Once you launched Android Studio, its time to mention JDK7 path or later version in
android studio installer.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Below the image initiating JDK to android SDK

Need to check the components, which are required to create applications, below the image
have selected Android Studio, Android SDK, Android Virtual Machine and
performance (Intel chip).

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Need to specify the location of local machine path for Android studio and Android
SDK, below the image has taken default location of windows 8.1 x64 bit architecture.

Need to specify the ram space for Android emulator by default it would take 512MB
of local machine RAM.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

At final stage, it would extract SDK packages into our local machine, it would take a
while time to finish the task and would take 2626MB of Hard disk space.
After done all above steps perfectly, you must get finish button and it going to be open android
studio project with Welcome to android studio message as shown below

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

You can start your application development by calling start a new android studio project. In a new
installation frame should ask Application name, package information and location of the project.

After entered application name, it going to be called select the form factors your application
runs on, here need to specify Minimum SDK, in our tutorial, I have declared as API23:
Android 6.0(Marshmallow)

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

The next level of installation should contain selecting the activity to mobile, it specifies the
default layout for Applications

At the final stage it going to be open development tool to write the application code.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Step 3 - Create Android Virtual Device

To test your Android applications, you will need a virtual Android device. So before we
start writing our code, let us create an Android virtual device. Launch Android AVD
Manager Clicking AVD_Manager icon as shown below

After Click on a virtual device icon, it going to be shown by default virtual devices which
are present on your SDK, or else need to create a virtual device by clicking Create new

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Virtual device button.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

If your AVD is created successfully it means your environment is ready for Android
application development. If you like, you can close this window using top-right cross
button. Better you re-start your machine and once you are done with this last step, you are
ready to proceed for your first Android example but before that we will see few more
important concepts related to Android Application Development.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment–1

AIM: To study Android Studio and android studio installation. Create “Hello World”
application.

Working:- Before Writing a Hello world code, you must know about XML tags. To write hello
word code, you should redirect to App>res>layout>Activity_main.xml

To show hello word, we need to call text view with layout (about text view and layout, you must
take references at Relative Layout and Text View).

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView android:text="@string/hello_world"
android:layout_width="550dp"
android:layout_height="wrap_content" />
</RelativeLayout>

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

OUTPUT:

Need to run the program by clicking Run> Run App or else need to call shift+f10 key. Finally,
result should be placed at Virtual devices as shown below.

Assignment:

1. Install android studio and Create “MYINFO” application and Display your Name, City
and Collage.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment–2

Object: To understand Activity, Intent, Create sample application with login module.

CONCEPT:
A login application is the screen asking your credentials to login to some particular application. You
might have seen it when logging into facebook, twitter etc. This chapter explains, how to create a
login screen and how to manage security when false attempts are made. First you have to define two
TextView asking username and password of the user. The password TextView must have inputType
set to password. Its syntax is given below −

<EditText
android:id = "@+id/editText2"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:inputType = "textPassword" />

<EditText
android:id = "@+id/editText1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
/>

Define a button with login text and set its onClick Property. After that define the function mentioned
in the onClick property in the java file.

<Button
android:id = "@+id/button1"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:onClick = "login"
android:text ="@string/Login"
/>

In the java file, inside the method of onClick get the username and passwords text using getText()
and toString() method and match it with the text using equals()function.
EditText username = (EditText)findViewById(R.id.editText1);
EditText password = (EditText)findViewById(R.id.editText2);

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

public void login(View view){


if(username.getText().toString().equals("admin")
&&
password.getText().toString().equals("admin")){

//correcct password
}else{
//wrong password
The last thing you need to do is to provide a security mechanism, so that unwanted attempts should
be avoided. For this initialize a variable and on each false attempt, decrement it. And when it reaches
to 0, disable the login button.
int counter =
3; counter--;

if(counter==0){
//disble the button, close the application e.t.c
}

Example
Here is an example demonstrating a login application. It creates a basic application that gives you
only three attempts to login to an application.
To experiment with this example, you can run this on an actual device or in an emulator.

Steps Description

1 You will use Android studio to create an Android application under a package
com.example.sairamkrishna.myapplication.

3 Modify src/MainActivity.java file to add necessary code.

4 Modify the res/layout/activity main to add respective XML components

5 Run the application and choose a running android device and install the application on it and
verify the results

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Following is the content of the modified main activity file src/MainActivity.java.

package com.example.sairamkrishna.myapplication;

import android.app.Activity; import


android.graphics.Color; import
android.os.Bundle; import
android.view.View;

import android.widget.Button; import


android.widget.EditText; import
android.widget.TextView; import
android.widget.Toast;

public class MainActivityextendsActivity {


Buttonb1,b2;
EditText ed1,ed2;

TextView tx1; int


counter =3;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1 =(Button)findViewById(R.id.button);
ed1 = (EditText)findViewById(R.id.editText); ed2 =
(EditText)findViewById(R.id.editText2);

b2 = (Button)findViewById(R.id.button2);
tx1 = (TextView)findViewById(R.id.textView3); tx1.setVisibility(View.GONE);

b1.setOnClickListener(new View.OnClickListener() { @Override


public void onClick(View v) {
if(ed1.getText().toString().equals("admin") &&
ed2.getText().toString().equals("admin")) {
Toast.makeText(getApplicationContext(),
"Redirecting...",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "Wrong
Credentials",Toast.LENGTH_SHORT).show();

tx1.setVisibility(View.VISIBLE);
tx1.setBackgroundColor(Color.RED); counter--;
tx1.setText(Integer.toString(counter));
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

if (counter== 0) {

b1.setEnabled(false);
}
}
}
});

b2.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View v)
{ finish();
}
});

}
}
Following is the modified content of the xml res/layout/activity_main.xml.
\
In the following code abc indicates about logo oftutorialspoint.com

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


<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:tools ="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height = "match_parent" android:paddingLeft=
"@dimen/activity_horizontal_margin"
android:paddingRight = "@dimen/activity_horizontal_margin" android:paddingTop =
"@dimen/activity_vertical_margin" android:paddingBottom =
"@dimen/activity_vertical_margin"
tools:context = ".MainActivity">

<TextView android:text = "Login"


android:layout_width="wrap_content"
android:layout_height = "wrap_content" android:id =
"@+id/textview" android:textSize = "35dp"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true" />

<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content" android:text =
"Tutorials point" android:id = "@+id/textView"
android:layout_below = "@+id/textview"
android:layout_centerHorizontal = "true" android:textColor
= "#ff7aff24" android:textSize = "35dp" />

<EditText

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:layout_width = "wrap_content"
android:layout_height = "wrap_content" android:id =
"@+id/editText" android:hint = "Enter Name"
android:focusable = "true" android:textColorHighlight =
"#ff7eff15" android:textColorHint = "#ffff25e6"
android:layout_marginTop = "46dp" android:layout_below =
"@+id/imageView" android:layout_alignParentLeft = "true"
android:layout_alignParentStart = "true"
android:layout_alignParentRight = "true"
android:layout_alignParentEnd = "true"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/abc"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword" android:ems="10"
android:id="@+id/editText2"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:textColorHint="#ffff299f" android:hint="Password"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Attempts Left:"
android:id="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="25dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:id="@+id/textView3"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/textView2"
android:layout_toEndOf="@+id/textview"
android:textSize="25dp"
android:layout_toRightOf="@+id/textview" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="login"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/textview"
android:layout_toStartOf="@+id/textview" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/textview"
android:layout_toEndOf="@+id/textview" />

</RelativeLayout>
Following is the content of theres/values/string.xml.

<resources>
<string name="app_name">My Application</string>
</resources>

Following is the content of AndroidManifest.xmlfile.

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


<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

<activity
android:name=".MainActivity"
android:label="@string/app_name" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

</application>
</manifest>

OUTPUT

Click Run icon from the toolbar. Android studio installs the app on your AVD and Starts it and if
everything is fine with your setup and application, it will display following Emulator window−

Type anything in the username and password field, and then press the login button. I put abc in the
username field and abc in the password field. I got failed attempt. This is shown below

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Do this two more time, and you will see that you have 0 login attempts left and your login button is
disabled.

Now open the application again, and this time enter correct username as admin and password as
admin and click on login. You will be successfully login.

If user press on cancel button, it will close an application of login screen.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment–3

Object: Design simple GUI application with activity and intents e.g. calculator.

PROGRAMS:
activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.andr
oid.com/tools"android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_3.MainActivity" >
<EditText android:id="@+id/editText1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:ems="10"
android:hint="Enter the first number"
tools:ignore="TextFields,HardcodedText">
<requestFocus />

</EditText>

<EditText

android:id="@+id/editText2" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true"
android:layout_below="@+id/editText1" android:ems="10"
android:hint="Enter the second number"
tools:ignore="TextFields,HardcodedText" />

<Button
android:id="@+id/button4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button3"
android:text="DIV" tools:ignore="HardcodedText" />

<Button
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/editText2"
android:text="ADD" tools:ignore="HardcodedText" />

<Button
android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button1"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:text="SUB" tools:ignore="HardcodedText" />

<Button
android:id="@+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_below="@+id/button2"
android:text="MUL" tools:ignore="HardcodedText" />

<TextView
android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="@+id/button4"

android:layout_centerHorizontal="true" android:layout_marginTop="22dp" android:text=""

android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

MainActivity.java:
packagecom.example.ex_no_3;
import android.support.v7.app.ActionBarActivity;
importandroid.os.Bundle;
importandroid.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.EditText; import
android.widget.TextView;
public class MainActivity extends ActionBarActivity {
intn1,n2; floatnum1,num2;@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditTexte1=(EditText)findViewById(R.id.editText1); final
EditTexte2=(EditText)findViewById(R.id.editText2);
Buttonb1=(Button)findViewById(R.id.button1);
Button b2=(Button)findViewById(R.id.button2); Button
b3=(Button)findViewById(R.id.button3); Buttonb4=(Button)findViewById(R.id.button4);
final TextView t=(TextView)findViewById(R.id.textView1); b1.setOnClickListener(
new OnClickListener()
{
@Override
public void onClick(View arg0){
// TODO Auto-generated method stub n1=Integer.parseInt(e1.getText().toString());

n2=Integer.parseInt(e2.getText().toString()); t.setText(e1.getText().toString()+" +
"+e2.getText().toString()+" = "+(n1+n2));
}
});
b2.setOnClickListener(
new OnClickListener()
{ @Override

{
public void onClick(View arg0)
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

// TODO Auto-generated method stub n1=Integer.parseInt(e1.getText().toString());


n2=Integer.parseInt(e2.getText().toString()); t.setText(e1.getText().toString()+" -
"+e2.getText().toString()+" = "+(n1-n2));
}
});
b3.setOnClickListener(
new OnClickListener()
{
@Override
public void onClick(View arg0) {

//TODOAuto-generatedmethodstub

n1=Integer.parseInt(e1.getText().toStr ing());
n2=Integer.parseInt(e2.getText().toStr ing());

t.setText(e1.getText().toString()+"* "+e2.getText().toString()+"="+(n1*n2));

});

b4.setOnClickListener(

newOnClickListener()

@Override

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

num1=Float.parseFloat(e1.getText().toS tring());

num2=Float.parseFloat(e2.getText().toS tring());

t.setText(e1.getText().toString()+"/ "+e2.getText().toString()+"="+(num1/num2));
}

});

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment–4

Object: Develop an application that makes use of RSS Feed.

PROGRAMS:

activity_main.xml:

<?xmlversion="1.0"encoding="utf-8"?>

<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/fragment_container"
android:layout_height="fill_parent"/>

fragement_layout.xml:

<?xmlversion="1.0"encoding="utf-8"?>

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"

android:layout_height="match_parent" android:orientation="vertical">

<ListView

android:id="@+id/listView" android:layout_width="fill_parent"

android:layout_height="fill_parent">

</ListView>

<ProgressBar

android:id="@+id/progressBar"

style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_centerInParent="true"/>

</RelativeLayout>

rss_item.xml:

<?xmlversion="1.0"encoding="utf-8"?>

<TextViewxmlns:android="http://schemas.android.com/apk/res/android"
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

xmlns:tools="http://schemas.android.com/tools" android:id="@+id/itemTitle"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18dp" tools:ignore="SpUsage"/>

MainActivity.java:

packagecom.example.ex_no_8; importandroid.os.Bundle;
import
android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import
android.support.v4.app.FragmentTransaction; public class MainActivity extends FragmentActivity {

@Override

publicvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceSt ate);


setContentView(R.layout.activi ty_main); if (savedInstanceState==null){

addRssFragment();

privatevoidaddRssFragment(){

FragmentManagermanager= getSupportFragmentManager(); FragmentTransactiontransaction=


manager.beginTransaction();RssFragment fragment=newRssFragment();
transaction.add(R.id.fragment_container, fragment);transaction.commit();

@Override

protectedvoid
onSaveInstanceState(Bundle outState){ super.onSaveInstanceState(outState
);
outState.putBoolean("fragment_adde d", true);

Constants.java
packagecom.example.ex_no_8; publicclassConstants{

publicstaticfinalStringTAG="RssApp";
}
PcWorldRssParser.java

packagecom.example.ex_no_8;

importjava.io.IOException; importjava.io.InputStream; importjava.util.ArrayList;


MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

importjava.util.List;

importorg.xmlpull.v1.XmlPullParser;

importorg.xmlpull.v1.XmlPullParserException; importandroid.util.Xml;
publicclassPcWorldRssParser{

// We don't use namespacesprivate final String ns =null;


publicList<RssItem>parse(InputStreaminputStream)throws XmlPullParserException,

IOException{

try {

XmlPullParserparser=Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAME
SPACES,false);parser.setInput(inputStream,null); parser.nextTag();

return readFeed(parser);

}finally{

inputStream.close();
}

privateList<RssItem>readFeed(XmlPullParserparser)throws XmlPullParserException,IOException{

parser.require(XmlPullParser.START_TAG,null,"rss"); Stringtitle=null;
Stringlink=null;

List<RssItem> items = new ArrayList<RssItem>(); while (parser.next() !=


XmlPullParser.END_DOCUMENT){

if(parser.getEventType()!= XmlPullParser.START_TAG){ continue;

Stringname=parser.getName(); if(name.equals("title")){
title=readTitle(parser);

}elseif(name.equals("link")){

link=readLink(parser);

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

if(title!=null&&link!=null){

RssItemitem=newRssItem(title,link); items.add(item);

title=null; link = null;


}

returnitems;

privateStringreadLink(XmlPullParserparser)throwsXmlPullParserException, IOException

parser.require(XmlPullParser.START_ TAG,ns,"link");Stringlink= readText(parser);


parser.require(XmlPullParser.END_TA G,ns,"link");returnlink;

privateStringreadTitle(XmlPullParserparser)throws XmlPullParserException,IOException{

parser.require(XmlPullParser.START_T AG,ns,"title");Stringtitle= readText(parser);


parser.require(XmlPullParser.END_TAG
,ns,"title");returntitle;

//Forthetagstitleandlink,extracttheirtextvalues.

privateStringreadText(XmlPullParserparser)throwsIOException, XmlPullParserException

Stringresult="";

if(parser.next()==XmlPullParser.TEXT){ result=parser.getText(); parser.nextTag();


}

returnresult;

RssAdapter.java
packagecom.example.ex_no_8; importjava.util.List;

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

importandroid.content.Context; importandroid.view.View; importandroid.view.ViewGroup;


importandroid.widget.BaseAdapter;

importandroid.widget.TextView;

publicclassRssAdapterextendsBaseAdapter{ privatefinalList<RssItem>items;
privatefinalContextcontext;
publicRssAdapter(Contextcontext, List<RssItem>items){this.items
=items;

this.context=context;

@Override

publicintgetCount(){ returnitems.size();
}

@Override

publicObjectgetItem(intposition){

returnitems.get(position);

@Override

publiclonggetItemId(intid){

return id;

@Override

publicViewgetView(intposition,ViewconvertView, ViewGroupparent){ViewHolderholder;

if(convertView==null){

convertView=View.inflate(context, R.layout.rss_item,null);holder=new ViewHolder();

holder.itemTitle=(TextView) convertView.findViewById(R.id.itemTitle);
convertView.setTag(holder);
} else {

holder=(ViewHolder)convertView.getTag();

holder.itemTitle.setText(items.get(position).getTi tle()); return convertView;


MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

staticclass ViewHolder{

TextViewitemTitle;

RssFragement.java
packagecom.example.ex_no_8; importjava.util.List;

importandroid.content.Intent; importandroid.net.Uri;
importandroid.os.Bundle; importandroid.os.Handler;

importandroid.os.ResultReceiver; importandroid.support.v4.app.Fragment;
importandroid.view.LayoutInflater; importandroid.view.View;
importandroid.view.ViewGroup; importandroid.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import
android.widget.ProgressBar;

importandroid.widget.Toast;

publicclassRssFragmentextendsFragmentimplements OnItemClickListener{privateProgressBar
progressBar;

privateListViewlistView; privateViewview; @Override

publicvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceSt


ate);setRetainInstance(true);

@Override

publicViewonCreateView(LayoutInflaterinflater,ViewGroup container,BundlesavedInstanceState){
if(view==null){

view=inflater.inflate(R.layout.fragment_layout, container,false);progressBar=(ProgressBar)
view.findViewById(R.id.progressBar);listView= (ListView)view.findViewById(R.id.listView);
listView.setOnItemClickListener(this); startService();

} else {

ViewGroupparent=(ViewGroup)view.getParent(); parent.removeView(view);

returnview;
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

privatevoidstartService(){

Intentintent=newIntent(getActivity(), RssService.class); intent.putExtra(RssService.RECEIVER,


resultReceiver); getActivity().startService(intent);

privatefinalResultReceiverresultReceiver=new ResultReceiver(newHandler()){
@SuppressWarnings("unchecked")

@Override

protectedvoidonReceiveResult(intresultCode, BundleresultData){
progressBar.setVisibility(View.GONE);

List<RssItem>items=(List<RssItem>) resultData.getSerializable(RssService.ITEMS);
if(items!=null){

RssAdapteradapter=new RssAdapter(getActivity(),items); listView.setAdapter(adapter);

} else {

Toast.makeText(getActivity(),"Anerroroccuredwhiledownloading therssfeed.",
Toast.LENGTH_LONG).show();

};

};

@Override

publicvoidonItemClick(AdapterView<?>parent,Viewview,int
position,longid){RssAdapteradapter=(RssAdapter) parent.getAdapter();
RssItem item = (RssItem) adapter.getItem(position); Uri uri = Uri.parse(item.getLink());

Intentintent=new Intent(Intent.ACTION_VIEW,uri); startActivity(intent);


}

RssItem.java

packagecom.example.ex_no_8;

publicclassRssItem{
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

privatefinalStringtitle; privatefinalStringlink;
publicRssItem(Stringtitle,Stringlink){ this.title=title;

this.link=link;

publicStringgetTitle(){ return title;


}

publicStringgetLink(){ return link;


}

RssService.java

packagecom.example.ex_no_8; importjava.io.IOException;

importjava.io.InputStream; importjava.io.Serializable; importjava.net.URL;


importjava.util.List;

importorg.xmlpull.v1.XmlPullParserException;

importandroid.app.IntentService;

importandroid.content.Intent; importandroid.os.Bundle;
importandroid.os.ResultReceiver; importandroid.util.Log;
publicclassRssServiceextendsIntentService{

private static final String RSS_LINK =


"http://www.pcworld.com/index.rss";publicstaticfinalStringITEMS
= "items";

publicstaticfinalStringRECEIVER
="receiver";publicRssService(){ super("RssService");
}

@Override

protectedvoidonHandleIntent(Intent intent){Log.d(Constants.TAG,
"Servicestarted");List<RssItem>rssItems=null;

try {

PcWorldRssParser parser = new PcWorldRssParser(); rssItems =


parser.parse(getInputStream(RSS_LINK));

} catch
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

(XmlPullParserExce ptione){ Log.w(e.getMessage (), e);


}catch(IOExceptione){ Log.w(e.getMessage(),e);
}

Bundlebundle=newBundle();

bundle.putSerializable(ITEMS,(Serializable)rssItems); ResultReceiver receiver =


intent.getParcelableExtra(RECEIVER);receiver.send(0, bundle);

publicInputStream
getInputStream(Stringlink){ try {

URLurl=newURL(link);

return url.openConnection().getInputStream(); } catch(IOExceptione){

Log.w(Constants.TAG,"Exceptionwhileretrievingthe inputstream",e);returnnull;
}

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment–5

Object: Write an application that draws basic graphical primitives on the screen

PROGRAM:

activity_main.xml:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_7.MainActivity">

<ImageView

android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"

android:layout_alignParentRight="true" android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" tools:ignore="ContentDescription"/>

</RelativeLayout>

MainActivity.java:

packagecom.example.ex_no_7;

import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;

importandroid.graphics.Bitmap;

importandroid.graphics.Canvas; importandroid.graphics.Color; importandroid.graphics.Paint;


importandroid.os.Bundle; importandroid.view.Display;
importandroid.view.MotionEvent;

importandroid.view.View;

importandroid.view.View.OnTouchListener; importandroid.widget.ImageView;
@SuppressLint("ClickableViewAccessibility")
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

publicclassMainActivityextendsActionBarActivityimplements OnTouchListener{ImageViewiv;
Bitmapb;

Canvas c; Paintp;
float dx=0,dy=0,ux=0,uy=0;

@SuppressWarnings("deprecation") @Override
protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); iv=(ImageView)this.findViewById(R.id.imageView1);
Displayd=getWindowManager().getDefaultDisplay(); floatdw=d.getWidth();
floatdh=d.getHeight();

b=Bitmap.createBitmap((int)dw,(int) dh,Bitmap.Config.ARGB_8888);
c=newCanvas(b);p=newPaint();
p.setColor(Color.BLUE);

iv.setImageBitmap(b); iv.setOnTouchListener(this);
}

@Override

publicbooleanonTouch(Viewv,MotionEventevent){

//TODOAuto-generated methodstubintaction
=event.getAction(); switch(action)
{
caseMotionEvent.ACTION_DOWN:

dx=event.getX(); dy=event.getY(); break;


caseMotionEvent.ACTION_MOVE: break;

caseMotionEvent.ACTION_UP:

ux=event.getX(); uy=event.getY();
c.drawLine(dx,dy,ux,uy,p); iv.invalidate();
break;

caseMotionEvent.ACTION_CANCEL:

break; default:
break;

return true;

}
}

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment-6

Object: Create an android app for database creation using SQLite Database

PROGRAMS:

activity_main.xml:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_4.MainActivity">

<TextView

android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:text="Reg.No."
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<EditText
android:id="@+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_toRightOf="@+id/textView1"

android:ems="10" android:inputType="number">
<requestFocus/>

</EditText>

<TextView

android:id="@+id/textView2" android:layout_width="wrap_content"
android:layout_height="wrap_content"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:layout_alignLeft="@+id/textView1"

android:layout_below="@+id/editText1"
android:layout_marginTop="20dp" android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>
<TextView

android:id="@+id/textView3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/editText2"
android:layout_marginTop="26dp" android:text="Marks"
android:textAppearance="?android:attr/textAppearanceMedium"

tools:ignore="HardcodedText"/>

<EditText

android:id="@+id/editText3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_alignLeft="@+id/editText2"

android:ems="10" android:inputType="number"/>
<EditText

android:id="@+id/editText2"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"

android:ems="10" tools:ignore="TextFields"/>
<Button

android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:layout_below="@+id/textView3"
android:layout_marginTop="32dp" android:text="ADD"
tools:ignore="HardcodedText"/>

<Button

android:id="@+id/button3" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"

android:layout_alignParentRight="true" android:text="VIEWALL"
tools:ignore="HardcodedText"/>

<Button

android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"

android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="24dp" android:text="VIEW"
tools:ignore="HardcodedText"/>

<Button

android:id="@+id/button4" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"

android:layout_marginLeft="27dp"
android:layout_marginTop="18dp" android:text="UPDATE"
tools:ignore="HardcodedText"/>
<Button

android:id="@+id/button5"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginLeft="20dp"

android:layout_toRightOf="@+id/button4"
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

android:text="DELETE" tools:ignore="HardcodedText"/>
</RelativeLayout>

MainActivity.java:

packagecom.example.ex_no_4;

import android.support.v7.app.ActionBarActivity;
importandroid.app.AlertDialog.Builder;
importandroid.content.Context;

importandroid.database.Cursor;

import android.database.sqlite.SQLiteDatabase; import


android.os.Bundle; import android.view.View;

importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.EditText; publicclassMainActivityextends
ActionBarActivity{EditText
name,regno,mark;

Button btnAdd,btnDelete,btnUpdate,btnView,btnView All;


SQLiteDatabase db;

@Override

protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
regno=(EditText)findViewById(R.id.editText1);
name=(EditText)findViewById(R.id.editText2);

mark=(EditText)findViewById(R.id.editText3);
btnAdd=(Button)findViewById(R.id.button1);
btnView=(Button)findViewById(R.id.button2);
btnViewAll=(Button)findViewById(R.id.button3);
btnUpdate=(Button)findViewById(R.id.button4);

btnDelete=(Button)findViewById(R.id.button5);

db=openOrCreateDatabase("Students",Context.MODE_PRIVATE,n
ull);

db.execSQL("CREATETABLEIFNOTEXISTSstudent(regnoVAR
CHAR,name VARCHR,mark
VARCHAR);");

btnAdd.setOnClickListener(newOnClickListener()

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

@Override

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

if(regno.getText().toString().trim().length()==0||name.getText().toSt
ring().trim().len
gth()==0||mark.getText().toString().trim().length()==0)

showMessage("Error","Please enterallvalues");return;

db.execSQL("INSERTINTOstudent

VALUES('"+regno.getText()+"','"+name.getText()+"','"+mark.getT
ext ()+"');");

showMessage("Success","Recordadded"); clearText();
}

});

btnDelete.setOnClickListener(newOnClickListener()

@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0)

showMessage("Error","PleaseenterReg.No."); return; }

Cursorc=db.rawQuery("SELECT*
FROMstudentWHEREregno='"+regno.getText()+"'", null);
if(c.moveToFirst())

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

db.execSQL("DELETE FROM student WHERE


regno='"+regno.getText()+"'");showMessage("Success",
"RecordDeleted");

else

showMessage("Error","InvalidReg.No.");

clearText();

});

btnUpdate.setOnClickListener(newOnClickListener()

{
@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub
if(regno.getText().toString().trim().length()==0)
{

showMessage("Error","PleaseenterReg.No.");

return;

Cursorc=db.rawQuery("SELECT*FROM
studentWHEREregno='"+regno.getText()+"'",null);

if(c.moveToFirst())

db.execSQL("UPDATEstudentSET

name='"+name.getText()+"',mark='"+mark.getText()+"'WHERE
regno='"+regno.getText()+"'");

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

showMessage("Success","Record
Modified");
} else
{
showMessage("Error","InvalidReg. No.");

} clearText();

});

btnView.setOnClickListener(newOnClickListener()

@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub

if(regno.getText().toString().trim().length()==0)

showMessage("Error","Please enterReg.No.");return;

Cursorc=db.rawQuery("SELECT*FROM
studentWHEREregno='"+regno.getText()+"'",null);

if(c.moveToFirst())

name.setText(c.getString(1)); mark.setText(c.getString(2));
} else
{

showMessage("Error","InvalidReg.No."); clearText();
}

});

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

btnViewAll.setOnClickListener(newOnClickListener()

@Override

publicvoidonClick(Viewv){

//TODOAuto-generatedmethodstub

Cursorc=db.rawQuery("SELECT*FROMstudent",null);
if(c.getCount()==0)
{

showMessage("Error","Norecordsfound"); return;
}

StringBufferbuffer=newStringBuffer(); while(c.moveToNext())

buffer.append("Reg.No:"+c.getString(0)+"\n");
buffer.append("Name:"+c.getString(1)+"\n");
buffer.append("Mark:"+c.getString(2)+"\n\n");
}
showMessage("StudentDetails",buffer.toString());

});

publicvoidshowMessage(Stringtitle,Stringmessage)

Builderbuilder=newBuilder(this); builder.setCancelable(true);
builder.setTitle(title); builder.setMessage(message); builder.show();
}

publicvoidclearText()
{

regno.setText("");

name.setText("");

mark.setText(""); regno.requestFocus();
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

Output

Thus the application that makes use of database has been developed and the output was
verified.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment-7

Object: Develop a native application that uses GPS location information

PROGRAM:

activity_main.xml:

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"

android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_5.MainActivity">

<TextView

android:id="@+id/textView1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" android:layout_alignParentTop="true"

android:layout_marginTop="114dp" android:text=""
android:textAppearance="?android:attr/textAppearanceMedium
tools:ignore="HardcodedText"/>

<TextView

android:id="@+id/textView2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1"

android:layout_alignParentRight="true"

android:layout_below="@+id/textView1" android:layout_marginTop="51dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
tools:ignore="HardcodedText"/>

<TextView
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

android:id="@+id/textView3" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_marginTop="47dp"
android:text="CurrentLocation"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText"/>

</RelativeLayout>

MainActivity.java:

packagecom.example.ex_no_5;

import android.support.v7.app.ActionBarActivity;
importandroid.content.Context;import android.location.Criteria;

importandroid.location.Location;

importandroid.location.LocationListener; importandroid.location.LocationManager;
importandroid.os.Bundle;
importandroid.widget.TextView; importandroid.widget.Toast;

publicclassMainActivityextendsActionBarActivityimplements
LocationListener{@Override

protectedvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceStat


e); setContentView(R.layout.activity
_main);

LocationManager
lm=(LocationManager)getSystemService(Context.LOCATION_SERVICE);Criteria
c=new Criteria();

Strings=lm.getBestProvider(c,false); if(s!=null&&!s.equals(""))

Locationl=lm.getLastKnownLocation(s); lm.requestLocationUpdates(s,20000,1,this);
if(l!=null)
onLocationChanged(l);

else
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

Toast.makeText(getApplicationContext(),
"Locationcan'tberetrieved!!!",Toast.LENGTH_LONG).show();
}

else

Toast.makeText(getApplicationContext(),"Provider
notfound!!!",Toast.LENGTH_LONG).show();

@Override

publicvoid
onLocationChanged(Location arg0){//TODOAuto- generatedmethodstub

TextView t1=(TextView)findViewById(R.id.textView1); t1.setText("Latitude :


\n"+arg0.getLatitude()); TextView t2=(TextView)findViewById(R.id.textView2);
t2.setText("Longitude :
\n"+arg0.getLongitude());

@Override

publicvoidonProviderDisabled(Stringarg0){

//TODOAuto-generatedmethodstub

@Override

publicvoidonProviderEnabled(Stringarg0){

//TODOAuto-generatedmethodstub

}
@Override

publicvoidonStatusChanged(Stringarg0,intarg1, Bundlearg2){//TODOAuto-
generatedmethod stub

}
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment-8

Object: Implement an application that writes data to the SDcard.

PROGRAM:

activity_main.xml:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ex_no_6.MainActivity">

<EditText

android:id="@+id/editText1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:ems="10"
android:hint="Path" tools:ignore="TextFields,HardcodedText">

<requestFocus/>

</EditText>

<Button

android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignTop="@+id/editText1"
android:layout_toRightOf="@+id/editText1" android:text="READ"

tools:ignore="HardcodedText"/>

<EditText

android:id="@+id/editText2" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1"
android:layout_centerVertical="true" android:ems="10"
android:hint="ContentsofFile"

android:inputType="textMultiLine" tools:ignore="HardcodedText"/>

<Button
MAD Lab (6CS4-23) Manual 2022-23
Poornima College of Engineering, Jaipur Department of Computer Engineering

android:id="@+id/button2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:text="SAVE" tools:ignore="HardcodedText"/>

</RelativeLayout>

MainActivity.java:

packagecom.example.ex_no_6;

importjava.io.BufferedReader; importjava.io.File;
importjava.io.FileNotFoundException; importjava.io.FileReader;
importjava.io.FileWriter; importjava.io.IOException;
import android.support.v7.app.ActionBarActivity; import android.annotation.SuppressLint;
importandroid.content.SharedPreferences;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener; importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast; publicclassMainActivityextends
ActionBarActivity{ @SuppressLint("SdCardPath")
@Override

protectedvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState


);
setContentView(R.layout.activity_ main);
final EditText e1=(EditText)findViewById(R.id.editText1)
;finalEditText e2=(EditText)findViewById(R.id.editText2)
;

Buttonb1=(Button)findViewById(R.id.button1);

Buttonb2=(Button)findViewById(R.id.button2);

Stringpath=getPreferences(MODE_PRIVATE).getString("fpath", "/sdcard/file1");e1.setText(path);

b1.setOnClickListener(

newOnClickListener()

@Override

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

File f=new File(e1.getText().toString());

Strings="";

StringBuildersb=newStringBuilder(); FileReaderfr=null;
try {

fr=newFileReader(f);

}catch(FileNotFoundExceptione){

//TODOAuto-generatedcatch block

e.printStackTrace();

BufferedReaderbr=new BufferedReader(fr);

try {

while((s=br.readLine())!=null)

sb.append(s+"\n");

}catch(IOExceptione){

// TODO Auto-generated catch block

e.printStackTrace();

Toast.makeText(getApplicationContext(

),"FileReadSuccessfully!!!",Toast.LENGTH_LONG).show();

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

e2.setText(sb);

});

b2.setOnClickListener(

newOnClickListener()

@Override

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

File f=new File(e1.getText().toString());


FileWriterfw=null; try {
fw=newFileWriter(f);

}catch(IOExceptione3){

//TODOAuto-generatedcatch block

e3.printStackTrace();

try {

fw.write(e2.getText().toString()
);

}catch(IOExceptione2){

// TODO Auto-generated catch block

e2.printStackTrace();

try {

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

fw.close();

}catch(IOExceptione2){

//TODOAuto-generatedcatch block

e2.printStackTrace();

SharedPreferences.Editor

e=getPreferences(MODE_PRIVATE).edit();

e.putString("fpath",f.getPath());
e.commit(); Toast.makeText(getApplicationContext()
, "Saved Successfully!!!",Toast.LENGTH_LONG).show();

}});
}}

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment-9

Object: Design a gaming application (Tic Tac ToeGame).

PROGRAM:

activity_main.xml:

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

<androidx.constraintlayout.widget.ConstraintLayout
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:layout_height="match_parent" tools:context=".MainActivity">

<TextView android:id="@+id/textView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="23dp" android:text="@string/heading" android:textSize="36sp"
android:textStyle="bold" app:fontFamily="cursive" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />

<ImageView android:id="@+id/imageView" android:layout_width="0dp"


android:layout_height="wrap_content"
android:contentDescription="@string/grid"

app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" app:srcCompat="@drawable/grid" />

<LinearLayout android:id="@+id/linearLayout" android:layout_width="0dp"


android:layout_height="420dp" android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@+id/imageView">

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"


android:layout_weight="1" android:orientation="horizontal">

<ImageView android:id="@+id/imageView0" android:layout_width="match_parent"


android:layout_height="match_parent"
android:layout_weight="1"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:onClick="playerTap" android:padding="20sp" android:tag="0"/>

<ImageView android:id="@+id/imageView1" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="1"/>

<ImageView android:id="@+id/imageView2" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="2"/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"

android:layout_weight="1" android:orientation="horizontal">

<ImageView android:id="@+id/imageView3" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="3"/>

<ImageView android:id="@+id/imageView4" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="4"/>

<ImageView android:id="@+id/imageView5" android:layout_width="match_parent"


android:layout_height="match_parent"
android:layout_weight="1"

android:onClick="playerTap" android:padding="20sp" android:tag="5" />


</LinearLayout>

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_weight="1"
android:orientation="horizontal">

<ImageView android:id="@+id/imageView6" android:layout_width="match_parent"

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="6" />

<ImageView android:id="@+id/imageView7" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap"

android:padding="20sp" android:tag="7"/>

<ImageView android:id="@+id/imageView8" android:layout_width="match_parent"


android:layout_height="match_parent" android:layout_weight="1"
android:onClick="playerTap" android:padding="20sp" android:tag="8"/>
</LinearLayout>

</LinearLayout>

<TextView android:id="@+id/status"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15sp" android:text="@string/status"
android:textSize="18sp" android:textStyle="italic"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/linearLayout"/>

</androidx.constraintlayout.widget.ConstraintLayout>

File:- MainActivity.java

package com.poornima.tictactoe;

import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;


importandroid.view.View;
import android.widget.ImageView; import android.widget.TextView;

publicclassMainActivityextendsAppCompatActivity{ boolean gameActive =true;

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

// Player representation

// 0 -X

// 1 -O

int activePlayer = 0;

int[] gameState = {2, 2 , 2, 2, 2, 2, 2, 2,2};

// Statemeanings:

// 0 -X

// 1 -O

// 2 -Null

int[][] winPositions = {{0,1,2}, {3,4,5}, {6,7,8},

{0,3,6}, {1,4,7}, {2,5,8},

{0,4,8}, {2,4,6}};

public void playerTap(View view){ ImageView img = (ImageView) view;


inttappedImage=Integer.parseInt(img.getTag().toString()); if(!gameActive){
gameReset(view);

if(gameState[tappedImage] == 2) { gameState[tappedImage] = activePlayer;


img.setTranslationY(-1000f);
if (activePlayer == 0) { img.setImageResource(R.drawable.x); activePlayer = 1;
TextView status = findViewById(R.id.status); status.setText("O's Turn - Tap toplay");
} else {

img.setImageResource(R.drawable.o); activePlayer = 0;
TextView status = findViewById(R.id.status); status.setText("X's Turn - Tap to play");
}

img.animate().translationYBy(1000f).setDuration(300);

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

// Check if any player has won for(int[] winPosition: winPositions){


if(gameState[winPosition[0]] == gameState[winPosition[1]] &&

gameState[winPosition[1]] == gameState[winPosition[2]] &&


gameState[winPosition[0]]!=2){
//Somebodyhaswon!-Findoutwho! StringwinnerStr;
gameActive = false; if(gameState[winPosition[0]] == 0){
winnerStr = "X has won";

else{

winnerStr = "O has won";

//Updatethestatusbarforwinnerannouncement TextView status =


findViewById(R.id.status); status.setText(winnerStr);
}
}
}
public void gameReset(View view) { gameActive = true;
activePlayer = 0;

for(int i=0; i<gameState.length; i++){ gameState[i] = 2;


}

((ImageView)findViewById(R.id.imageView0)).setImageResource(0);
((ImageView)findViewById(R.id.imageView1)).setImageResource(0);
((ImageView)findViewById(R.id.imageView2)).setImageResource(0);
((ImageView)findViewById(R.id.imageView3)).setImageResource(0);
((ImageView)findViewById(R.id.imageView4)).setImageResource(0);
((ImageView)findViewById(R.id.imageView5)).setImageResource(0);
((ImageView)findViewById(R.id.imageView6)).setImageResource(0);
((ImageView)findViewById(R.id.imageView7)).setImageResource(0);
((ImageView)findViewById(R.id.imageView8)).setImageResource(0);

TextView status = findViewById(R.id.status); status.setText("X's Turn - Tap to play");


}
@Override

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);
}

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Experiment-10

Object: Create an application to handle images and videos according to size.

activity_main.xml

Drag the VideoView from the pallete, now the activity_main.xml file will like this:

File: activity_main.xml

<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android "


xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".MainActivity" >

<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>

</RelativeLayout>

Activity class

Let's write the code of to play the video file. Here, we are going to play 1.mp4 file located inside
the sdcard/media directory.

File: MainActivity.java

package com.example.video1;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.view.Menu;
importandroid.widget.MediaController;
import android.widget.VideoView; 9.
public class MainActivity extends Activity {
@Override

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

protected void onCreate(Bundle savedInstanceState){


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView=(VideoView)findViewById(R.id.videoView1);

//CreatingMediaController
MediaController mediaController= newMediaController(this);
mediaController.setAnchorView(videoView); 22.
//specify the location of mediafile
Uri uri=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/m
edia/1.mp4");

//Setting MediaController and URI, then starting thevideoView


videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start(); 31.
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it ispresent.
getMenuInflater().inflate(R.menu.activity_main,menu);
return true;
}}

RESULT:

Thus the application that uses GUI Components, Fonts, handle images and videos
and Colors has been developed and the output was verified.

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Beyond the Syllabus Experiment-1

AIM: Create an app for Gallery.

Program:

Code for gallery adaptor:

package example.abhiandroid.galleryexample;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class CustomGalleryAdapter extends BaseAdapter {
private Context context;
private int[] images;

public CustomGalleryAdapter(Context c, int[] images) {


context = c;
this.images = images;
}

// returns the number of images


public int getCount() {
return images.length;
}

// returns the ID of an item


public Object getItem(int position) {
return position;
}

// returns the ID of an item


public long getItemId(int position) {
return position;
}
// returns an ImageView view
public View getView(int position, View convertView, ViewGroup parent) {

// create a ImageView programmatically


ImageView imageView = new ImageView(context);
imageView.setImageResource(images[position]); // set image in ImageView
imageView.setLayoutParams(new Gallery.LayoutParams(200, 200)); // set ImageView

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

param
return imageView;
}
}
Code for main:
package example.abhiandroid.galleryexample;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {

Gallery simpleGallery;
CustomGalleryAdapter customGalleryAdapter;
ImageView selectedImageView;
// array of images
int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3,
R.drawable.image4, R.drawable.image5,
R.drawable.image6, R.drawable.image7, R.drawable.image8, R.drawable.image9,
R.drawable.image10, R.drawable.image11,
R.drawable.image12, R.drawable.image13};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleGallery = (Gallery) findViewById(R.id.simpleGallery); // get the reference of
Gallery
selectedImageView = (ImageView) findViewById(R.id.selectedImageView); // get the
reference of ImageView
customGalleryAdapter = new CustomGalleryAdapter(getApplicationContext(), images); //
initialize the adapter
simpleGallery.setAdapter(customGalleryAdapter); // set the adapter
// perform setOnItemClickListener event on the Gallery
simpleGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// set the selected image in the ImageView
selectedImageView.setImageResource(images[position]);
}

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

Output:

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Beyond the Syllabus Experiment-2

AIM: WAP for Spinner


Program:
Code for activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.androi
d.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:layout_height="match_parent"
tools:context="example.javatpoint.com.spinner.MainActivity">

<Spinner
android:id="@+id/spinner"
android:layout_width="149dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498" />

</android.support.constraint.ConstraintLayout>

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Code for MainActivity.java

package example.javatpoint.com.spinner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements


AdapterView.OnItemSelectedListener {
String[] country = { "India", "USA", "China", "Japan", "Other"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Getting the instance of Spinner and applying OnItemSelectedListener on it
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);

//Creating the ArrayAdapter instance having the country list


ArrayAdapter aa = new
ArrayAdapter(this,android.R.layout.simple_spinner_item,country);

aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Setting the ArrayAdapter data on the Spinner
spin.setAdapter(aa);

//Performing action onItemSelected and onNothing selected


@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long
id) {

MAD Lab (6CS4-23) Manual 2022-23


Poornima College of Engineering, Jaipur Department of Computer Engineering

Toast.makeText(getApplicationContext(),country[position] ,
Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}

Output:

MAD Lab (6CS4-23) Manual 2022-23

You might also like