18csmp68-Mad-Lab Manual
18csmp68-Mad-Lab Manual
18csmp68-Mad-Lab Manual
18CSMP68
VI- Semester
Prepared By
Dr. B.T. Harish Kumar
Assistant Professor
MOBILE APPLICATION DEVELOPMENT
(Effective from the academic year 2018 -2019)
SEMESTER – VI
Course Code 18CSMP68 IA Marks 40
Number of Contact Hours/Week 0:0:2 Exam Marks 60
Total Number of Contact Hours 3 Hours/Week Exam Hours 03
CREDITS – 02
Laboratory Objectives: This laboratory (18CSMP68) will enable students to
Learn and acquire the art of Android Programming.
Configure Android studio to run the applications.
Understand and implement Android's User interface functions.
Create, modify and query on SQlite database.
Inspect different methods of sharing data using services.
Descriptions (if any):
1. The installation procedure of the Android Studio/Java software must be demonstrated and carri ed
out in groups.
2. Students should use the latest version of Android Studio/Java/ Kotlin to execute these programs.
Diagrams given are for representational purposes only, students are expected to improvise on them.
3. Part B programs should be developed as an application and are to be demonstrated as a mini project
in a group by adding extra features or the students can also develop their application and
demonstrate it as a mini-project. (Projects/programs are not limited to the list given in
Part B).
Programs List:
PART – A
1 Create an application to design a Visiting Card. The Visiting card should have a company logo at
the top right corner. The company name should be displayed in Capital letters, aligned to the
center. Information like the name of the employee, job title, phone number, address, email, fax
and the website address is to be displayed. Insert a horizontal line between the job title and the
phone number.
2 Develop an Android application using controls like Button, Text View, Edit Text for designing a
calculator having basic functionality like Addition, Subtraction, Multiplication, and Division.
3 Create a SIGN Up activity with Username and Password. Validation of password should happen
based on the following rules:
On successful SIGN UP proceed to the next Login activity. Here the user should SIGN IN using
the Username and Password created during signup activity. If the Username and Password are
matched then navigate to the next activity which displays a message saying “Successful Login” or
else display a toast message saying “Login Failed”. The user is given only two attempts and after
that display a toast message saying “Failed Login Attempts” and disable the SIGN IN button. Use
Bundle to transfer information from one activity to another.
4 Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.
5 Write a program to create an activity with two buttons START and STOP. On pressing of the
START button, the activity must start the counter by displaying the numbers from One and the
counter must keep on counting until the STOP button is pressed. Display the counter value in a
Text View control.
6 Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature, and Humidity. Develop an application to create an activity with two buttons to
parse the XML and JSON files which when clicked should display the data in their respective
layouts side by side.
7 Develop a simple application with one Edit Text so that the user can write some text in it. Create a
button called “Convert Text to Speech” that converts the user input text into voice.
8 Create an activity like a phone dialer with CALL and SAVE buttons. On pressing the CALL
button, it must call the phone number and on pressing the SAVE button it must save the number to
the phone contacts.
PART-B
1 Write a program to enter Medicine Name, Date and Time of the Day as input from the user and
store it in the SQLite database. Input for Time of the Day should be either Morning or Afternoon
or Evening or Night. Trigger an alarm based on the Date and Time of the Day and display the
Medicine Name.
2 Develop a content provider application with an activity called “Meeting Schedule” which takes
Date, Time and Meeting Agenda as input from the user and store this information into the SQLite
database. Create another application with an activity called “Meeting Info” having DatePicker
control, which on the selection of a date should display the Meeting Agenda information for that
particular date, else it should display a toast message saying “No Meeting on this Date”.
3 Create an application to receive an incoming SMS which is notified to the user. On clicking this
SMS notification, the message content and the number should be displayed on the screen. Use
appropriate emulator control to send the SMS message to your application.
4 Write a program to create an activity having a Text box, and also Save, Open and Create buttons.
The user has to write some text in the Text box. On pressing the Create button the text should be
saved as a text file in MkSDcard. On subsequent changes to the text, the Save button should be
pressed to store the latest content to the same file. On pressing the Open button, it should display
the contents from the previously stored files in the Text box. If the user tries to save the contents
in the Textbox to a file without creating it, then a toast message has to be displayed saying “First
Create a File”.
5 Create an application to demonstrate a basic media player that allows the user to Forward,
Backward, Play and Pause an audio. Also, make use of the indicator in the seek bar to move the
audio forward or backward as required.
6 Develop an application to demonstrate the use of Asynchronous tasks in android. The
asynchronous task should implement the functionality of a simple moving banner. On pressing the
Start Task button, the banner message should scroll from right to left. On pressing the Stop Task
button, the banner message should stop. Let the banner message be “Demonstration of
Asynchronous Task”.
7 Develop an application that makes use of the clipboard framework for copying and pasting of the
text. The activity consists of two Edit Text controls and two Buttons to trigger the copy and paste
functionality.
8 Create an AIDL service that calculates Car Loan EMI. The formula to calculate EMI is
E = P * (r(1+r)n)/((1+r)n-1)
where
E = The EMI payable on the car loan amount
P = The Car loan Principal Amount
r = The interest rate value computed on a monthly basis
n = The loan tenure in the form of months
The down payment amount has to be deducted from the principal amount paid towards buying the
Car. Develop an application that makes use of this AIDL service to calculate the EMI. This
application should have four Edit Text to read the Principal Amount, Down Payment, Interest
Rate, Loan Term (in months) and a button named as “Calculate Monthly EMI”. On click of this
button, the result should be shown in a Text View. Also, calculate the EMI by varying the Loan
Term and Interest Rate values.
Laboratory Outcomes: After studying these laboratory programs, students will be able to
Create, test and debug Android application by setting up Android development environment.
Implement adaptive, responsive user interfaces that work across a wide range of devices.
Infer long running tasks and background work in Android applications.
Demonstrate methods in storing, sharing and retrieving data in Android applications.
Experiment distribution
o For laboratories having only one part: Students are allowed to pick one experiment from the
lot with equal opportunity.
o For laboratories having PART A and PART B: Students are allowed to pick one experiment
from PART A and one experiment from PART B, with equal opportunity.
Change of experiment is allowed only once and marks allotted for procedure to be
made zero of the changed part only.
Text Books:
1. Google Developer Training, "Android Developer Fundamentals Course – Concept
Reference”, Google Developer Training Team, 2017.
https://www.gitbook.com/book/google-developer-training/android-developer-
fundamentals- course-concepts/details
(Download pdf file from the above link)
Reference Books:
1. Erik Hellman, “Android Programming – Pushing the Limits”, 1st Edition, Wiley India Pvt
Ltd, 2014. ISBN-13: 978-8126547197
2. Dawn Griffiths and David Griffiths, “Head First Android Development”, 1st Edition,
O‟Reilly SPD Publishers, 2015. ISBN-13: 978-9352131341
3. Bill Phillips, Chris Stewart and Kristin Marsicano, “Android Programming: The Big Nerd
Ranch Guide”, 3rd Edition, Big Nerd Ranch Guides, 2017. ISBN-13: 978-0134706054
18CSMP68 Mobile Application Development Lab Manual 2020-2021
Program No.1:
Create an application to design a Visiting Card. The Visiting card should havea company logo
at the top right corner. The company name should be displayed in Capital letters, aligned to
the center. Information like the name of the employee, job title, phone number, address,
email, fax and the website address is to be displayed. Insert a horizontal line between the job
title and the phone number.
<TextView
android:id="@+id/textView"
android:layout_width="354dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="731dp"
android:layout_marginEnd="126dp"
android:layout_marginRight="126dp"
android:text="BANGALORE INSTITUTE OF TECHNOLOGY"
android:textAlignment="center"
android:textColor="#ff00"
android:textSize="25sp" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="721dp"
android:layout_marginEnd="17dp"
android:layout_marginRight="17dp"
app:srcCompat="@drawable/bitlogo"
/>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="698dp"
android:background="#4444"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="652dp"
android:layout_marginEnd="144dp"
android:layout_marginRight="144dp"
android:text="Dr. Harish Kumar B T"
android:textAlignment="center"
android:textColor="#3700b3"
android:textSize="20sp"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="603dp"
android:layout_marginEnd="157dp"
android:layout_marginRight="157dp"
android:text="Assistant Professor"
android:textAlignment="center"
android:textSize="18sp"
/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="556dp"
android:layout_marginEnd="163dp"
android:layout_marginRight="163dp"
android:text="Mob: 9980119894"
android:textAlignment="center"
android:textColor="#b00020"
android:textSize="18sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="510dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp"
android:text="Email ID: [email protected]"
android:textAlignment="center"
android:textColor="#3700b3"
android:textSize="18sp"
/>
</RelativeLayout>
Design Output:
package com.example.labpgm1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
Program No.2:
Develop an Android application using controls like Button, TextView, EditText for
designing a calculator having basic functionality like Addition, Subtraction,
Multiplication and Division.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIMPLE CALCULATOR"
android:textSize="30sp"
android:textColor="@color/design_default_color_primary_dark"
android:textAlignment="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter First Number"
android:id="@+id/num1"
android:textSize="20sp"
android:textAlignment="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Second Number"
android:id="@+id/num2"
android:textSize="20sp"
android:textAlignment="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Result"
android:id="@+id/result"
android:textSize="20sp"
android:textAlignment="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seven"
android:text="7"
android:textAlignment="center"
android:onClick="seven"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/eight"
android:text="8"
android:textAlignment="center"
android:onClick="eight"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nine"
android:text="9"
android:textAlignment="center"
android:onClick="nine"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/divide"
android:text="/"
android:textAlignment="center"
android:onClick="divide"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/four"
android:text="4"
android:textAlignment="center"
android:onClick="four"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/five"
android:text="5"
android:textAlignment="center"
android:onClick="five"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/six"
android:text="6"
android:textAlignment="center"
android:onClick="six"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/multiply"
android:text="*"
android:textAlignment="center"
android:onClick="multiply"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/one"
android:text="1"
android:textAlignment="center"
android:onClick="one"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/two"
android:text="2"
android:textAlignment="center"
android:onClick="two"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/three"
android:text="3"
android:textAlignment="center"
android:onClick="three"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/add"
android:text="+"
android:textAlignment="center"
android:onClick="add"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dot"
android:text="."
android:textAlignment="center"
android:onClick="dot"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zero"
android:text="0"
android:textAlignment="center"
android:onClick="zero"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/equals"
android:text="="
android:textAlignment="center"
android:onClick="compute"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/minus"
android:text="- "
android:textAlignment="center"
android:onClick="sub"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clear_one_digit_at_a_time"
android:text="C"
android:textAlignment="center"
android:onClick="clear_one_digit_at_a_time"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clear_one_field_completely"
android:text="CE"
android:textAlignment="center"
android:onClick="clear_one_field_completely"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/All_Clear"
android:text="AC"
android:textAlignment="center"
android:onClick="All_Clear"
/>
</LinearLayout>
</LinearLayout>
Design Output:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
else {
Toast.makeText(this, "Please get the focus of First/Second Number field",
Toast.LENGTH_LONG).show();
}
else if(number2.hasFocus())
{
number2.append("2");
}
else {
Toast.makeText(this, "Please get the focus of First/Second Number field",
Toast.LENGTH_LONG).show();
}
}
{
number2.append("5");
}
else {
Toast.makeText(this, "Please get the focus of First/Second Number field",
Toast.LENGTH_LONG).show();
}
}
}
else {
Toast.makeText(this, "Please get the focus of First/Second Number field",
Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(this, "Please get the focus of First/Second Number field",
Toast.LENGTH_LONG).show();
}
}
break;
}
}
else
{
Toast.makeText(this, "Please click on Number1/Number2 Field",
Toast.LENGTH_LONG).show();
}
}
else if(number2.hasFocus())
{
String n;
n=number2.getText().toString();
// n=n.substring(0,n.length()-1); /// deletes digits from right to left
n=n.substring(1,n.length()); // deletes digits from left to right
number2.setText(n);
}
else
{
Toast.makeText(this, "Please click on Number1/Number2 Field",
Toast.LENGTH_LONG).show();
}
}
Output:
Program 3:
Create a SIGN Up activity with Username and Password. Validation of password should happen
based on the following rules:
On successful SIGN UP proceed to the next Login activity. Here the user should SIGN IN using
the Username and Password created during signup activity. If the Username and Password are
matched then navigate to the next activity whichdisplays a message saying “Successful Login” or
else display a toast message saying “Login Failed”.The user is given only two attempts and after
thatdisplay a toast message saying “Failed Login Attempts” and disable the SIGN IN button. Use
Bundle to transfer information from one activity to another.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign UP Activity"
android:textSize="30sp"
android:textAlignment="center"
android:textColor="@color/design_default_color_error"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uid"
android:hint="Enter User Name"
android:textSize="20sp"
android:textAlignment="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pwd"
android:hint="Enter Password"
android:textSize="20sp"
android:inputType="textPassword"
android:textAlignment="center"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/signup"
android:text="SIGNUP"
android:onClick="signup"
/>
</LinearLayout>
Design Output:
Activity_signin.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIGN IN ACTIVITY"
android:textAlignment="center"
android:textSize="30sp"
android:textColor="@color/design_default_color_error"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/uid"
android:hint="Enter UID"
android:textAlignment="center"
android:textSize="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pwd"
android:hint="Enter Password"
android:textAlignment="center"
android:inputType="textPassword"
android:textSize="20sp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/signin"
android:text="SIGN IN"
android:textAlignment="center"
android:onClick="signin"
/>
</LinearLayout>
Design Output:
Activity_success.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Success">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN SUCCESSFUL"
android:textSize="30sp"
android:textAlignment="center"
android:layout_gravity="center"
android:textColor="@color/design_default_color_primary_dark"
/>
</LinearLayout>
Design Output:
package com.example.labpgm3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = findViewById(R.id.uid);
passwd = findViewById(R.id.pwd);
}
Pattern ptrn;
Matcher mat;
String passwordptrn="^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-
9])(?=.*[<>/@%$#+=])(?=\\S+$).{8,}$";
ptrn=Pattern.compile(passwordptrn);
mat=ptrn.matcher(password);
return mat.matches();
}
package com.example.labpgm3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
attempts=0;
Intent i =new Intent(this,Success.class);
startActivity(i);
}
else
{
attempts++;
Toast.makeText(this, "SIGN IN UNSUCCESSFUL. Number of
Attempts="+attempts, Toast.LENGTH_LONG).show();
if(attempts==3)
signin.setEnabled(false);
}
}
}
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_success);
}
}
Output:
Program 4:
Develop an application to set an image as wallpaper. On click of a button, the wallpaper image
should start to change randomly every 30 seconds.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wall Paper Changing Application"
android:textAlignment="center"
android:textSize="30sp"
android:textColor="@color/design_default_color_primary"
/>
<Button
android:layout_marginTop="100dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/wp"
android:text="changewallpaper"
android:textSize="20sp"
android:onClick="ChangeWallpaper"
/>
</LinearLayout>
Design Output:
package com.example.labpgm4;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
else if(next==3)
{
drawable=getResources().getDrawable(R.drawable.three);
next=4;
}
else if(next==4)
{
drawable=getResources().getDrawable(R.drawable.four);
next=5;
}
else if(next==5)
{
drawable=getResources().getDrawable(R.drawable.five);
next=6;
}
else if(next==6)
{
drawable=getResources().getDrawable(R.drawable.six);
next=7;
}
else if(next==7)
{
drawable=getResources().getDrawable(R.drawable.seven);
next=8;
}
else if(next==8)
{
drawable=getResources().getDrawable(R.drawable.eight);
next=9;
}
else if(next==9)
{
drawable=getResources().getDrawable(R.drawable.nine);
next=10;
}
else if(next==10)
{
drawable=getResources().getDrawable(R.drawable.ten);
next=1;
}
Bitmap img=((BitmapDrawable)drawable).getBitmap();
try {
wpm.setBitmap(img);
} catch (IOException e) {
e.printStackTrace();
}
}
},30000,5000);
}
}
Output:
Program No. 5:
Write a program to create an activity with two buttons START and STOP. On pressing of the
START button, the activity must start the counter by displaying the numbers from One and the
counter must keep on counting until the STOP button is pressed. Display the counter value in a
TextView control.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="COUNTER APPLICATION"
android:textSize="30sp"
android:textColor="@color/design_default_color_primary"
android:textAlignment="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/count"
android:textAlignment="center"
android:textSize="20sp"
android:textColor="@color/design_default_color_primary"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/start"
android:text="START"
android:onClick="start"
android:textSize="20sp"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/stop"
android:text="STOP"
android:onClick="stop"
android:textSize="20sp"
/>
</LinearLayout>
Design Output:
package com.example.program5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start=findViewById(R.id.start);
stop=findViewById(R.id.stop);
counter=findViewById(R.id.count);
}
@Override
public void run() {
counter.setText(""+i);
i++;
myhandler.postDelayed(Threadcount,0);
}
};
}
Output:
6 Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature, and Humidity. Develop an application to create an activity with two buttons to
parse the XML and JSON files which when clicked should display the data in their respective
layouts side by side.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XML and JSON Parser"
android:textSize="30sp"
android:textAlignment="center"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="XMLParser"
android:text="XML PARSER"
android:textAlignment="center"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="JSONParser"
android:text="JSON PARSER"
android:textAlignment="center"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resxml"
android:textSize="15sp"
android:textAlignment="center"
android:paddingLeft="10dp"
android:paddingRight="40dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resjson"
android:textSize="15sp"
android:textAlignment="center"
android:paddingLeft="40dp"
/>
</LinearLayout>
</LinearLayout>
Design Output:
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
for(int i=0;i<nList.getLength();i++)
{
Node node=nList.item(i);
if(node.getNodeType()==Node.ELEMENT_NODE)
{
Element element2=(Element)node;
resxml.setText(resxml.getText()+"\n City
Name:"+getValue("cityname",element2)+"\n");
resxml.setText(resxml.getText()+"\n Lat:"+getValue("lat",element2)+"\n");
resxml.setText(resxml.getText()+"\n Long:"+getValue("long",element2)+"\n");
resxml.setText(resxml.getText()+"\n
Temperature:"+getValue("temp",element2)+"\n");
resxml.setText(resxml.getText()+"\n
Humidity:"+getValue("humidity",element2)+"\n");
resxml.setText(resxml.getText()+"\n -------------------------");
}
}
resjson.setText(resjson.getText()+"\n Temperature:"+obj.getString("temp")+"\n");
resjson.setText(resjson.getText()+"\n Humidity:"+obj.getString("humidity")+"\n");
resjson.setText(resjson.getText()+"\n --------------------");
}
}
Output:
7 Develop a simple application with one Edit Text so that the user can write some text in it. Create a
button called “Convert Text to Speech” that converts the user input text into voice.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEXT TO SPEECH APP"
android:textColor="@color/design_default_color_primary_dark"
android:textAlignment="center"
android:textSize="30sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pitch"
android:hint="Enter Pitch (1.0 is normal)"
android:textSize="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/speechrate"
android:hint="Enter Speech Rate (1.0 is normal)"
android:textSize="20sp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/texttospeak"
android:hint="Enter Text to Speak"
android:inputType="textMultiLine"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnspeak"
android:text="SPEAK"
android:onClick="speak"
android:textSize="30sp"
/>
</LinearLayout>
Design Output:
package com.example.textspeech;
import androidx.appcompat.app.AppCompatActivity;
import android.app.UiAutomation;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pitchrate=findViewById(R.id.pitch);
setspeechrate=findViewById(R.id.speechrate);
text=findViewById(R.id.texttospeak);
float pr,sr;
String txt;
if(pitchrate.getText().toString().equals(""))
{
pr=1.0f;
}
else
{
pr=Float.parseFloat(pitchrate.getText().toString());
}
if(setspeechrate.getText().toString().equals(""))
{
sr=1.0f;
}
else
{
sr=Float.parseFloat(setspeechrate.getText().toString());
}
t.setPitch(pr);
t.setSpeechRate(sr);
t.speak(text.getText().toString(),QUEUE_FLUSH,null);
}
}
Output:
8 Create an activity like a phone dialer with CALL and SAVE buttons. On pressing the CALL
button, it must call the phone number and on pressing the SAVE button it must save the number to
the phone contacts.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CALL and SAVE APPLICATION"
android:textSize="30sp"
android:textAlignment="center"
android:textColor="@color/design_default_color_primary_dark"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/num"
android:hint="Enter Number To Dial/SAVE"
android:textAlignment="center"
android:textSize="20sp"
android:textColor="@color/design_default_color_error"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="@+id/del"
android:text="DEL"
android:textAlignment="center"
android:onClick="delete"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<Button
android:id="@+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="three"
android:text="3" />
<Button
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="one"
android:text="1" />
<Button
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="two"
android:text="2" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/four"
android:text="4"
android:onClick="four"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/five"
android:text="5"
android:onClick="five"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/six"
android:text="6"
android:onClick="six"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seven"
android:text="7"
android:onClick="seven"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/eight"
android:text="8"
android:onClick="eight"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nine"
android:text="9"
android:onClick="nine"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/star"
android:text="*"
android:onClick="star"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zero"
android:text="0"
android:onClick="zero"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hash"
android:text="#"
android:onClick="hash"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/call"
android:text="CALL"
android:onClick="call"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/save"
android:text="SAVE"
android:onClick="save"/>
</LinearLayout>
</LinearLayout>
Design Output:
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.VibrationEffect;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.EditText;
{
number.append("6");
}
Output: