Mad Manual
Mad Manual
MOBILE APPLICATION
DEVELOPMENTLABORATORY
MANUAL MASTER COPY
VI Semester
CourseCode:18CSMP6
8
Sl. Particulars
No.
1 Vision and Mission of Department
2 PEOs, PSOs, POs
3 • Course Outcomes
• Syllabus
• Conduction of Practical Examination
• CO-PO-PSO Mapping
4 Lab Evaluation Process
5 Lab Rubrics
6 Lab Evaluation Sheet
7 CHAPTER1 INTRODUCTION
ANDROID STUDIO TUTORIALS
CHAPTER 2
PART-A
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
Experiment 1 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.
Develop an Android application using controls like Button, TextView,
EditText for designing a Calculator having basic functionality like
Experiment 2
Addition, Subtraction, Multiplication, and Division.
Create a SIGN Up activity with Username and Password. Validation of
password should happen based on the following rules:
8 • Password should contain uppercase and lowercase letters.
Experiment 3 • Password should contain letters and numbers.
• Password should contain special characters.
• Minimum length of the password (the default value is 8).
Develop an application to set an image as wallpaper. On click of a
button, the wallpaper image should start to change randomly every 30
Experiment 4 seconds.
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
Experiment 5 until the STOP button is pressed. Display the counter value
in a TextView control.
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
Experiment 6
which when clicked should display the data in their
respective layouts side by side.
MD 2 To provide exposure to the latest tools in the area of computer hardware and
software
MD 4 To establish Industry Institute Interaction and make students ready for the
Industrial environment
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex
engineering activities with anunderstanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal,health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professionalengineeringpractice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
12. Life-longlearning: Recognize the need for, and have the preparation and
ability to engage in independent and life-long learning in the broadest
context of technological change.
Course Objectives
Course Outcomes
SubjectCode:18CSMP68 IA Marks:40
No. of Practical Hrs. /Week:0:0:2 Exam Marks: 60 Total No. of
Practical Hrs:3Hours/Week Exam Hours: 03No. of Credits:02
PART A
Program 1
Create an application to design a Visiting Card. The Visiting card should have a
company logo atthe 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.
Program 2
Develop an Android application using controls like Button, TextView, EditText for
designing aCalculator having basic functionality
On successful SIGN UP proceed to the next Login activity. Here the user should SIGN
IN usingthe 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 attemptsand after that display a toast message saying “Failed
Login Attempts” and disable the SIGNIN button. Use Bundle to transfer information
from one activity to another.
Program 4
Develop an application to set an image as wallpaper. On click of a button, the
wallpaper imageshould start to change randomly every 30seconds.
Program 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.
Program 7
Develop a simple application with one Edit Text so that the user can write some text
in it. Createa button called “Convert Text to Speech” that converts the user input text
into voice.
PART B
Program 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.
Program 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 Date Pickercontrol, which on the selection of a date
should display the Meeting Agenda information for thatparticular date, else it should
display a toast message saying “No Meeting on this Date”.
Program 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 “FirstCreate a File”.
Program 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.
Program 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 StartTask 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”.
Program 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 EditText to read the Principal Amount,
DownPayment, InterestRate, LoanTerm (in months) and a button named as “Calculate
Monthly EMI”.On click of this button, the result should be shown in a TextView. Also,
calculate the EMI by varying the Loan Term and InterestRate values.
18CSMP68.1 3 2 2 - 2 1 - - 1 1 - 1
18CSMP68.2 3 2 2 - 2 1 - - 1 1 - 1
18CSMP68.3 3 2 2 - 2 1 - - 1 1 - 1
18CSMP68.4 3 2 2 - - - - 2 1 1 - 1
18CSMP68 3 2 2 - 2 1 - 2 1 1 - 1
ACTIVITY MARKS
Manual 19
Viva 05
TOTAL 24
Lab Rubrics
Rubrics for Evaluation of Observation Book
18 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
Attribute NOT
EXCELLENT GOOD SATISFACTORY SATISFACTORY
Max 3 2 1 0
Marks
Write-Up 3 1. Written 1. Written 1. Written Program 1. Written
complete Program with few with logical and Incomplete Program
logical errors. syntax errors. 2. Input and expected
program
2. Written input 2. Written input and output is not written
without any and expected expected output for
errors output for few test one test case.
2. Written input cases. 3. Written program
and expected 3. Written with moderate
output for all program with indentation
the test cases. moderate
indentation
3. Written
program with
proper
indentation
Max 9-10 5-8 3-4 0-2
Marks
Execution 10 1. Execution of 1. Execution of 1. Execution of No Execution
code with
code with code with
excellent
debugging skill. good average
debugging debugging skill.
2. Got desired skill.
output for all 2. Got desired
required test 2. Got desired output for only
case output for few one test case
test cases
Max 3 2 1 0
Marks
Viva Voce 3 1. Exhibits 1. Exhibits good 1. Able to exhibits 1. Unable to explain
strong hold on hold on basic of average concepts.
basic of Data Data Structure knowledge on 2. Unable to explain
Structure concepts basic of Data the program.
concepts 2. Able to Structure concepts 3. Unable to
2. Able to demonstrate 2. Able to communicate ideas.
demonstrate given program demonstrate given
given program 3. Presents only program partially
3. Presents all a few concepts 3. Lack of
concepts clearly clearly confidence to
answer the
questions
Max 2 1 0
Marks
Results 2 Written desired output Written desired Not able to write
for all required test output for few output
cases test cases
Max 2 1 0
Marks
Time 2 Written Complete Written Not submitted
Management program with desired Complete
output and submitted on program with
time desired output
and submitted by
taking extra time
Attribute NOT
EXCELLENT GOOD SATISFACTORY SATISFACTORY
Max 13-15 8-12 5-7 0-4
Marks
Write-Up 15 1. Written 1. Written 1. Written Program 1.Written
complete program Program with with logical and Incomplete
few logical syntax errors. Program
without any errors
errors. 2. Written input and 2.Input and
2.Written input 2. Written input expected output for expected output is
and expected and expected one test case not written
output for all the output for few 3.Written program
test cases. test cases. with reasonable
3.Written program 3. Written indentation
program with
with proper
moderate
indentation indentation
10
11
12
13
14
15
16
• Experiment distribution
• For laboratories having only one part: Students are allowed to pick one
experiment fromthe lot with equal opportunity.
• ForlaboratorieshavingPARTAandPARTB:Studentsareallowedtopickone
experiment from PART A and one experiment from PART B, with
equalopportunity.
Every day the new devices are incoming to the market with innovative options
thanks to growing technology. The evolution of Mobile Application Development
technology with new devices made our lives much easier.
In the smartphone world, simply having a running web site is not enough.
Regarding arecent study, it has shown that about 45% and more of Google search
happens using smartphones.The number is spectacular and there is a growth within
the mobile business. Being obtainable on an internet-enabled device is needed for
every and each business which has given
the kicking start to mobile application development.
1. Native Applications:
These are applications developed to be used on a particular platform or operating system
such as Android, iOS etc. Native apps are usually written in languages that the platform
accepts. They are also built using the specific Integrated Development Environment
(IDE) for the given operating systems, such as Android Studio for Android Apps and
XCode for iOS Apps.
The principal advantage of native apps is that they optimize the user experience. By being
designedand developed specifically for that platform, they look and perform better.
Examples of some popular Native Applications are Instagram for Android, VLC media
player for Android, WordPress for iOS, and 2048 game for iOS,
2. Hybrid Applications:
These are applications developed to be used across multiple platforms i.e can be
deployed on bothiOS and Android platforms. Hybrid mobile applications are built in a
similar manner as websites. Both use a combination of technologies like HTML, CSS,
and JavaScript. However, instead of targeting a mobile browser, hybrid applications
target a WebView hosted inside a native container.This enables them to do things like
access hardware capabilities of the mobile device.
Today, most hybrid mobile applications leverage Apache Cordova, a platform that
provides a consistent set of JavaScript APIs to access device capabilities through plug-
ins, which are built withnative code.
Examples of some popular Hybrid Applications are MarketWatch, Untappd, FanReact,
and TripCase.
Linux kernel
At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches. This
provides a level of abstraction between the device hardware and it contains all the
essential hardware drivers like camera, keypad, display etc. Also, the kernel handles all
the things that Linux is really good atsuch as networking and a vast array of device
drivers, which take the pain out of interfacing to peripheral hardware.
Libraries
On top of Linux kernel there is a set of libraries including open-source Web browser
engine WebKit, well known library libc, SQLite database which is a useful repository
for storage and sharing of application data, libraries to play and record audio and video,
SSL libraries responsiblefor Internet security etc.
Android Libraries
This category encompasses those Java-based libraries that are specific to Android
development. Examples of libraries in this category include the application framework
libraries in addition to those that facilitate user interface building, graphics drawing and
database access. A summary of some key core Android libraries available to the
Android developer is as follows −
• android.app − Provides access to the application model and is the cornerstone of all
Android applications.
• android.content − Facilitates content access, publishing and messaging between
applications and application components.
1. Android StudioTutorials
Install Android Studio andPackages:
GotoTools SelectAVDManager
While creating a New Project for First Time, make sure Android Studio is connected
to internet,It downloads the required packages from internet.
Go to File New NewProject
Choose Java
Right Click on app folder New Folder Assets Folder Press Finish
Button
RightClickonassetsfolderNewFile
Program 1
CreateanapplicationtodesignaVisitingCard.TheVisitingcardshouldhaveacompanylogo
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 thewebsite address is to be displayed. Insert a
horizontal line between the job title and the phonenumber.
Design
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns: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"
android:layout_marginStart="11dp"
android:layout_marginLeft="11dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="0dp"
<RelativeLayout
android:layout_width="382dp"
android:layout_height="60dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp">
<ImageView
android:id="@+id/imageView2"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignWithParentIfMissing="false"
android:layout_marginStart="39dp"
android:layout_marginLeft="39dp"
android:layout_toEndOf="@+id/textView"
android:layout_toRightOf="@+id/textView"
app:srcCompat="@android:drawable/btn_star_big_on" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="31dp"
android:layout_marginLeft="-29dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="TIMZ INFOTECH PVT LTD"
android:textAllCaps="true"
android:textColor="#090808"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#0C0C0C" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:paddingLeft="10dp"
android:text="Software Developer"
android:textColor="#931212"
android:textSize="16sp" />
<View
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#0C0C0C" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Email id:[email protected]"
android:textColor="#971414"
android:textSize="20sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Phone:1234566789"
android:textColor="#971414"
android:textSize="20sp" />
</LinearLayout>
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">
<Button
android:id="@+id/button_clear"
android:layout_width="87dp"
android:layout_height="53dp"
android:layout_marginTop="30dp"
android:text="C"
app:layout_constraintStart_toStartOf="@+id/button_add"
app:layout_constraintTop_toBottomOf="@+id/button_add"/>
<Button android:id="@+id/button_sub"
android:layout_width="87dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
<Button
android:id="@+id/button_add"
android:layout_width="87dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="+"
app:layout_constraintStart_toEndOf="@+id/button_equal"
app:layout_constraintTop_toBottomOf="@+id/button_sub"
android:layout_marginLeft="20dp"/>
<Button
android:id="@+id/button_mul"
android:layout_width="87dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="*"
app:layout_constraintStart_toEndOf="@+id/button_six"
app:layout_constraintTop_toBottomOf="@+id/button_div"
android:layout_marginLeft="20dp"/>
<Button
android:id="@+id/button_equal"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="="
app:layout_constraintStart_toEndOf="@+id/button_zero"
app:layout_constraintTop_toBottomOf="@+id/button_three"/>
<Button
android:id="@+id/button_zero"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="0"
app:layout_constraintStart_toEndOf="@+id/button_dot"
app:layout_constraintTop_toBottomOf="@+id/button_two"/>
<Button
android:id="@+id/button_dot"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
<Button
android:id="@+id/button_three"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="3"
app:layout_constraintStart_toEndOf="@+id/button_two"
app:layout_constraintTop_toBottomOf="@+id/button_six"/>
<Button
android:id="@+id/button_two"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="2"
app:layout_constraintStart_toEndOf="@+id/button_one"
app:layout_constraintTop_toBottomOf="@+id/button_five"/>
<Button
android:id="@+id/button_one"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_four"/>
<Button
android:id="@+id/button_six"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="6"
app:layout_constraintStart_toEndOf="@+id/button_five"
app:layout_constraintTop_toBottomOf="@+id/button_nine"/>
<Button
android:id="@+id/button_seven"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="7"
app:layout_constraintStart_toStartOf="parent"
<Button
android:id="@+id/button_eight"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" android:text="8"
app:layout_constraintStart_toEndOf="@+id/button_seven"
app:layout_constraintTop_toBottomOf="@+id/txt_result"/>
<Button
android:id="@+id/button_nine"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="9"
app:layout_constraintStart_toEndOf="@+id/button_eight"
app:layout_constraintTop_toBottomOf="@+id/txt_result"/>
<Button
android:id="@+id/button_four"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_seven"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="SIMPLECALCULATOR"
android:textSize="26dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Result"
android:textSize="18dp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/textView"
<EditText
android:id="@+id/txt_result"
android:layout_width="310dp"
android:layout_height="46dp"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<Button
android:id="@+id/button_div"
android:layout_width="87dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="/"
app:layout_constraintStart_toEndOf="@+id/button_nine"
app:layout_constraintTop_toBottomOf="@+id/txt_result"/>
<Button
android:id="@+id/button_five"
android:layout_width="62dp"
android:layout_height="53dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="5"
app:layout_constraintStart_toEndOf="@+id/button_four"
app:layout_constraintTop_toBottomOf="@+id/button_eight"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example. partAprogram2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
Button btnOne,btnTwo,btnThree,btnFour,btnFive,btnSix;
Button btnSeven, btnEight, btnNine, btnZero;
Button btnAdd,btnSub,btnMul,btnDiv;
Button btnClear,btnEqual,btnDot;
51 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
EditText txtResult;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOne=(Button)findViewById(R.id.button_one); btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.button_two); btnTwo.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.button_three); btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.button_four); btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.button_five); btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.button_six); btnSix.setOnClickListener(this);
btnSeven=(Button)findViewById(R.id.button_seven); btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.button_eight); btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.button_nine); btnNine.setOnClickListener(this);
btnZero=(Button)findViewById(R.id.button_zero); btnZero.setOnClickListener(this);
btnAdd=(Button)findViewById(R.id.button_add); btnAdd.setOnClickListener(this);
btnSub=(Button)findViewById(R.id.button_sub); btnSub.setOnClickListener(this);
btnMul=(Button)findViewById(R.id.button_mul); btnMul.setOnClickListener(this);
btnDiv=(Button)findViewById(R.id.button_div); btnDiv.setOnClickListener(this);
btnClear=(Button)findViewById(R.id.button_clear); btnClear.setOnClickListener(this);
btnEqual=(Button)findViewById(R.id.button_equal); btnEqual.setOnClickListener(this);
btnDot=(Button)findViewById(R.id.button_dot); btnDot.setOnClickListener(this);
txtResult=(EditText)findViewById(R.id.txt_result); txtResult.setText("");
}
public void onClick(View v)
{
if(v.equals(btnOne)) txtResult.append("1");
if(v.equals(btnTwo)) txtResult.append("2");
if(v.equals(btnThree)) txtResult.append("3");
if(v.equals(btnFour)) txtResult.append("4");
if(v.equals(btnFive)) txtResult.append("5");
if(v.equals(btnSix)) txtResult.append("6");
if(v.equals(btnSeven)) txtResult.append("7");
if(v.equals(btnEight)) txtResult.append("8");
} else if (data.contains("*")) {
String[] operands = data.split(Pattern.quote("*"));
if (operands.length == 2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
} else if (data.contains("+")) {
String[] operands = data.split(Pattern.quote("+"));
if (operands.length == 2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 + operand2;
txtResult.setText(String.valueOf(result));
} else {
Toast.makeText(getBaseContext(), "InvalidInput", Toast.LENGTH_LONG).show();
}
} else if (data.contains("-")) {
String[] operands = data.split("-");
if (operands.length == 2) {
double operand1 = Double.parseDouble(operands[0]);
double operand2 = Double.parseDouble(operands[1]);
double result = operand1 - operand2;
txtResult.setText(String.valueOf(result));
} else {
Toast.makeText(getBaseContext(), "InvalidInput", Toast.LENGTH_LONG).show();
}
}
Sample Output
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/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="SIGNUP"
android:textColor="@android:color/background_dark"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
android:text="USERNAME"
56 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
android:layout_marginLeft="30dp" />
<TextView
android:id="@+id/textView4"
android:layout_width="82dp"
android:layout_height="34dp"
android:layout_marginTop="50dp"
android:text="PASSWORD"
app:layout_constraintStart_toStartOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView3"/>
<EditText
android:id="@+id/txt_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="10dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="@+id/textView3"/>
<Button
android:id="@+id/btn_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="SignUp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_password" />
<EditText
android:id="@+id/txt_password"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginTop="26dp"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/txt_username"
app:layout_constraintStart_toStartOf="@+id/txt_username"
app:layout_constraintTop_toBottomOf="@+id/txt_username"/>
</androidx.constraintlayout.widget.ConstraintLayout>
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;
import androidx.appcompat.app.AppCompatActivity;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
EditText txtUsername;
EditText txtPassword;
Button btnSignup;
String regularExpression="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtUsername=(EditText)findViewById(R.id.txt_username);
txtPassword=(EditText)findViewById(R.id.txt_password);
btnSignup=(Button)findViewById(R.id.btn_signup);
btnSignup.setOnClickListener(this);
}
}
................................................................................
activity_login.xml:
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:textSize="22sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:text="Username"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView7"/>
<EditText
android:id="@+id/txt_login_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="@+id/textView9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView9"
app:layout_constraintTop_toTopOf="@+id/textView9"/>
<EditText
android:id="@+id/txt_login_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="@+id/txt_login_username"
app:layout_constraintStart_toStartOf="@+id/txt_login_username"
app:layout_constraintTop_toTopOf="@+id/textView10"/>
<Button
android:id="@+id/btn_login_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_login_password"/>
</androidx.constraintlayout.widget.ConstraintLayout>
..........................................................................................
LoginActivity.java
package com.example.partAprogram3;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener
{
EditText txtLoginUsername;
EditText txtLoginPassword;
Button btnLogin;
String user,pass;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState)
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mydial">
<uses-permission android:name="android.permission. SET_WALLPAPPER "/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyDial">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
<?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"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ClickheretoChangeWallpaper"
android:id="@+id/btn_start_change_wallpaper"/>
</LinearLayout>
MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
Button changewallpaper;
Timer mytimer;
Drawable drawable;
boolean running;
WallpaperManager wpm;
int prev=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Activity_main.xml
<?xmlversion="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:id="@+id/lbl_counter"
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="100dp"
android:text="CounterApplication"
android:textSize="36sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/lbl_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="CounterValue"
android:textColor="#6E3030"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
67 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
android:id="@+id/btn_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lbl_text" />
<Button
android:id="@+id/btn_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Stop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_start" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.partAprogram5;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
TextView lblCounter;
Button btnStart,btnStop;
int counter=0;
boolean running=false;
};
try
{
Thread.sleep(1000);
}
catch(Exception e){ }
}
}
}
}
8. Read the XML and Json Data in the files and display onscreen
Rea
Activity_main.xml:
<?xmlversion="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">
<Button
android:id="@+id/btn_parsexml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="ParseXMLData"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4"/>
<Button
android:id="@+id/btn_parsejson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
72 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
android:text="ParseJsonData"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_parsexml"/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="PARSINGXMLANDJSONDATA"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
.............................................................
activity_view.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=".ViewActivity">
<TextView
android:id="@+id/lbl_xml_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="XmlData"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="PARSINGXMLANDJSONDATA"
android:textSize="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp"
android:text="XMLDATA"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
Button btnParseXml,btnParseJson;
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnParseXml=(Button)findViewById(R.id.btn_parsexml);
btnParseJson=(Button)findViewById(R.id.btn_parsejson);
btnParseJson.setOnClickListener(this);
btnParseXml.setOnClickListener(this);
}
@Override
ViewActivity.java
package com.example.programsix;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
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 java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
public class ViewActivity extends AppCompatActivity
{
TextView lblXmlData,lblJsonData;
int mode=0;
@Override protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
lblXmlData=(TextView)findViewById(R.id.lbl_xml_data);
lblJsonData=(TextView)findViewById(R.id.lbl_json_data);
mode=getIntent().getIntExtra("mode",0);
if(mode==1)
parseJson();
else
parseXmlDocument();
}
public String parseXmlDocument()
{
try
{
InputStream is=getAssets().open("input.xml");
DocumentBuilderFactory dbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
dBuilder = dbFactory.newDocumentBuilder();
Document doc=dBuilder.parse(is);
Element element=doc.getDocumentElement();
element.normalize();
NodeList nList=doc.getElementsByTagName("employee");
for(int i=0;i<nList.getLength();i++)
{
Design
Activity_main.xml:
<?xmlversion="1.0"encoding="utf-8"?>
package com.example.partAprogram7;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
EditText txtSpeak;
<Button android:id="@+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="Delete"
app:layout_constraintStart_toEndOf="@+id/txt_phonenumber"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_marginLeft="20dp" />
<Button android:id="@+id/btn_one"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber"
android:layout_marginLeft="20dp" />
<Button android:id="@+id/btn_two"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="2"
app:layout_constraintEnd_toStartOf="@+id/btn_three"
app:layout_constraintStart_toEndOf="@+id/btn_one"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber"/>
<Button android:id="@+id/btn_three"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_phonenumber"
android:layout_marginRight="20dp" />
<Button android:id="@+id/btn_five"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="5"
app:layout_constraintEnd_toStartOf="@+id/btn_six" app:layout_constraintStart_toEndOf="@+id/btn_four"
app:layout_constraintTop_toBottomOf="@+id/btn_two"/>
<Button android:id="@+id/btn_six"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_three"
android:layout_marginRight="20dp" />
<Button android:id="@+id/btn_seven"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="7"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_four"
android:layout_marginLeft="20dp" />
<Button android:id="@+id/btn_eight"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="8" app:layout_constraintEnd_toStartOf="@+id/btn_nine"
app:layout_constraintStart_toEndOf="@+id/btn_seven"
app:layout_constraintTop_toBottomOf="@+id/btn_five"/>
<Button android:id="@+id/btn_nine"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_six"
android:layout_marginRight="20dp" />
<Button android:id="@+id/btn_zero"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:text="0" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_eight"/>
<Button android:id="@+id/btn_call"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="Call"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_zero"
<Button android:id="@+id/btn_save"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginEnd="20dp" android:text="Save"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_zero"
android:layout_marginRight="20dp" />
<Button android:id="@+id/btn_start"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginTop="30dp" android:text="*"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_seven"
android:layout_marginLeft="20dp" />
<Button android:id="@+id/btn_hash"
android:layout_width="wrap_content" android:layout_height="wrap_content"
MainActivity.java
package com.example.mydial;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
btnOne=(Button)findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
btnThree=(Button)findViewById(R.id.btn_three); btnThree.setOnClickListener(this);
btnFour=(Button)findViewById(R.id.btn_four); btnFour.setOnClickListener(this);
btnFive=(Button)findViewById(R.id.btn_five); btnFive.setOnClickListener(this);
btnSix=(Button)findViewById(R.id.btn_six); btnSix.setOnClickListener(this);
btnSeven=(Button)findViewById(R.id.btn_seven); btnSeven.setOnClickListener(this);
btnEight=(Button)findViewById(R.id.btn_eight); btnEight.setOnClickListener(this);
btnNine=(Button)findViewById(R.id.btn_nine); btnNine.setOnClickListener(this);
btnZero=(Button)findViewById(R.id.btn_zero); btnZero.setOnClickListener(this);
btnStar=(Button)findViewById(R.id.btn_start); btnStar.setOnClickListener(this);
btnHash=(Button)findViewById(R.id.btn_hash); btnHash.setOnClickListener(this);
btnCall=(Button)findViewById(R.id.btn_call); btnCall.setOnClickListener(this);
btnSave=(Button)findViewById(R.id.btn_save); btnSave.setOnClickListener(this);
btnDel=(Button)findViewById(R.id.btn_delete); btnDel.setOnClickListener(this);
txtPhonenumber=(EditText)findViewById(R.id.txt_phonenumber); txtPhonenumber.setText("");
}
else if(v.equals(btnSave))
{
Intent contactIntent=new Intent
(ContactsContract.Intents.Insert.ACTION); contactIntent.setType
(ContactsContract.RawContacts.CONTENT_TYPE);
contactIntent
.putExtra(ContactsContract.Intents.Insert.NAME,"Unknown");
contactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, txtPhonenumber.getText().toString());
startActivity(contactIntent);
else if(v.equals(btnDel))
{
String data=txtPhonenumber.getText().toString(); if(data.length()>0)
{
txtPhonenumber.setText
(data.substring(0,data.length()-1));
}
else
{
txtPhonenumber.setText("");
}
}
btnCall.setOnClickListener(new View.OnClickListener()
{
@Override public void onClick(View v){
String data=txtPhonenumber.getText().toString();
Intent intent=new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+data)); startActivity(intent);
}
}
);
AndriodManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mydial">
<uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>
Sample Output
Program 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.
Design
activity_main.xml
<?xmlversion="1.0"encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.androi
xmlns:tools="http://schemas.android.com/tool
s" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="MedicineDatabase"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/
>
<TextView android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="MedicineName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/txt_medici
ne_name"/>
<TextView
android:id="@+id/textView
4"
android:layout_width="wrap
_content"
android:layout_height="wra
p_content"
android:layout_marginStart=
"20dp" android:text="Date"
app:layout_constraintBottom_toBottomOf="@+id/txt_date"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_medicine_name"/>
<TextView android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Time"
app:layout_constraintStart_toStartOf="parent
"
app:layout_constraintTop_toTopOf="@+id/tx
t_time"/>
<EditText
<EditText
android:id="@+id/txt_date
"
android:layout_width="wra
p_content"
android:layout_height="wra
p_content"
android:layout_marginTop=
"15dp" android:ems="10"
android:inputType="textPers
onName"
app:layout_constraintStart_toStartOf="@+id/txt_medicine_name"
app:layout_constraintTop_toBottomOf="@+id/txt_medicine_name"/>
<EditText
android:id="@+id/txt_time
"
android:layout_width="wra
p_content"
android:layout_height="wra
p_content"
android:layout_marginTop=
"20dp" android:ems="10"
android:inputType="textPers
onName"
app:layout_constraintStart_toStartOf="@+id/txt_date"
app:layout_constraintTop_toBottomOf="@+id/txt_date"/>
<Button
android:id="@+i
d/btn_save"
android:layout_width="wrap
_content"
android:layout_height="wra
p_content"
android:layout_marginTop=
"50dp" android:text="Save"
<Button
ndroid:id="@+i
d/btn_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Show"
app:layout_constraintEnd_toEndOf="@+id
/txt_time"
app:layout_constraintTop_toBottomOf="@+id/txt_time"/>
<TextView
android:id="@+id/lbl_data
"
android:layout_width="wra
p_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Data"
app:layout_constraintEnd_toEndOf="par
ent"
app:layout_constraintStart_toStartOf="p
arent"
app:layout_constraintTop_toBottomOf="@+id/btn_save"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MyDatabase.java
packagecom.example.partb_program1;
importandroid.content.Context;
importandroid.database.sqlite.SQLiteDatabase
;
importandroid.database.sqlite.SQLiteOpenHel
per;
importandroidx.annotation.Nullable;
publicclassMyDatabaseextendsSQLiteOpenHe
lper{
publicstaticStringDATABASE_NAME="medi
cine.db";
publicMyDatabase(@NullableContextcontext,@NullableStringname,@Nullable
@Override
publicvoidonCreate(SQLiteD
atabasedb){
db.execSQL("CREATETABLEMEDICINE_NAMES(NAMETEXT,MDATETEXT,MTIME
TEXT)");
@Override
publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVers
ion){
}
}
MainActivity.java
packagecom.example.partb_program1;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.content.ContentValues;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDat
abase; importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
importandroid.widget.Toast;
importorg.w3c.dom.Text;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtMedicineName,txtDate,txtTime;
ButtonbtnSave,btnShow;
TextViewlblData;
MyDatabas
emyDataba
se;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
btnSave=(Button)findViewById(R.id.btn_save
); btnSave.setOnClickListener(this);
btnShow=(Button)findViewById(R.id.btn_sho
w); btnShow.setOnClickListener(this);
lblData=(TextView)findViewById(R.id.lbl_da
ta);
myDatabase=newMyDatabase(getBaseContex
t(), MyDatabase.DATABASE_NAME,null,1);
publicvoidonClick(Viewv)
{
if(v.equals(btnSave))
{
StringmedicineName=txtMedicineName.getText().toString();
Stringdate=txtDate.getText().toString();
Stringtime=txtTime.getText().toString();
SQLiteDatabasedatabase=myDatabase.getWritable
Database(); ContentValuescv=newContentValues();
cv.put("NAME",medicineName);
cv.put("MDATE",date);
cv.put("MTIME",time);
database.insert("MEDICINE_NAMES",null,cv);
Toast.makeText(getBaseContext(),"DataSaved",Toast.LENGTH_LONG).show();
}
elseif(v.equals(btnShow))
{
SQLiteDatabasedatabase=myDatabase.getReadableDatabas
e(); Cursorcursor=database.query("MEDICINE_NAMES",
newString[]{"NAME","MDATE","MTIME"},null,null,null
,null,null); lblData.setText("NAME\tDATE\tTIME\n");
while(cursor.moveToNext())
{
lblData.append(cursor.getString(0
)+"\t");
lblData.append(cursor.getString(1
)+"\t");
lblData.append(cursor.getString(2
)+"\n");
}
94 Dept of CSE, AMCEC- Mobile App Development 18CSMP68
}
}
}
Sample Output
Design
<?xmlversion="1.0"encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayoutxmlns: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:id="@+id/layout"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<Button android:id="@+id/btn_open"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="40dp" android:layout_marginEnd="10dp" android:text="Open"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<Button android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="50dp"
android:text="Save" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
packagecom.example.partbprogram7;
importandroidx.appcompat.app.AppCompatActivity; importandroid.content.ClipData;
importandroid.content.ClipboardManager; importandroid.os.Bundle;
importandroid.view.View; importandroid.widget.Button; importandroid.widget.EditText;
importandroid.widget.Toast;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtCopy,txtPaste;
ButtonbtnCopy,btnPaste;
ClipboardManagermyClipboard; @Override
protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); txtCopy=(EditText)findViewById(R.id.txt_copy);
txtPaste=(EditText)findViewById(R.id.txt_paste);
btnCopy=(Button)findViewById(R.id.btn_copy); btnCopy.setOnClickListener(this);
btnPaste=(Button)findViewById(R.id.btn_paste); btnPaste.setOnClickListener(this);
myClipboard=(ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
}
elseif(v.equals(btnPaste))
{
ClipDataabc=myClipboard.getPrimaryClip(); ClipData.Itemitem=abc.getItemAt(0);
txtPaste.setText(item.getText().toString());
}
}
}
AndroidManifest.xml
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.partbprogram7">
Sample Output
Design
activity_main.xml
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EMICALCULATOR"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="76dp"/>
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="PrincipalAmount"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t
extView"/>
<EditText
android:id="@+id/txt_princi
pal"
android:layout_width="wrap
_content"
android:layout_height="wra
p_content"
android:layout_marginStart=
"10dp"
android:layout_marginTop=
"30dp" android:ems="10"
android:inputType="textPers
onName"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<TextView
android:id="@+id/downpay
ment"
android:layout_width="wrap
_content"
android:layout_height="wra
p_content"
<EditText
android:id="@+id/txt_down
npayment"
android:layout_width="wrap
_content"
android:layout_height="wra
p_content"
android:layout_marginTop=
"40dp" android:ems="10"
android:inputType="textPers
onName"
app:layout_constraintStart_toStartOf="@+id/txt_principal"
<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="InterestRate"
app:layout_constraintStart_toStartOf="@+id/downpayme
nt"
app:layout_constraintTop_toTopOf="@+id/txt_interestrat
e"/>
<EditText
android:id="@+id/txt_interestra
te"
android:layout_width="wrap_c
ontent"
android:layout_height="wrap_c
ontent"
android:layout_marginTop="40
dp" android:ems="10"
android:inputType="textPerson
Name"
app:layout_constraintStart_toStartOf="@+id/txt_downnpayment"
app:layout_constraintTop_toBottomOf="@+id/txt_downnpayment"/>
<TextView
android:id="@+id/textVie
w5"
android:layout_width="13
0dp"
android:layout_height="3
3dp"
android:layout_marginTo
p="8dp"
android:text="LoanTerm(
Months)"
app:layout_constraintStart_toStartOf="@+id/textView4"
app:layout_constraintTop_toTopOf="@+id/txt_termmonths"/>
<EditText
android:id="@+id/txt_termmon
ths"
android:layout_width="wrap_c
ontent"
android:layout_height="wrap_c
ontent"
android:layout_marginStart="2
0dp"
android:layout_marginTop="32
dp" android:ems="10"
android:inputType="textPerson
Name"
app:layout_constraintStart_toStartOf="@+id/txt_interestrate"
app:layout_constraintTop_toBottomOf="@+id/txt_interestrate"/>
<Button
android:id="@+id/btn_calculate
"
android:layout_width="wrap_c
ontent"
android:layout_height="wrap_c
ontent"
android:layout_marginTop="30
dp"
android:text="CalculateEMI"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_termmonths"/>
<TextView
android:id="@+id/lbl_emiamou
nt"
android:layout_width="wrap_c
ontent"
android:layout_height="wrap_c
ontent"
android:layout_marginTop="30
dp" android:text="EmiAmount"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_calculate"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
packagecom.example.partb_program8;
importandroidx.appcompat.app.AppCompat
Activity; importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
importandroid.widget.Toast;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListe
ner{ EditTexttxtPrinicple,txtDownPayment,txtInterestRate,txtLoanTerm;
ButtonbtnCalculate;
TextViewlblResult;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPrinicple=(EditText)findViewById(R.id.txt_princip
al);
txtDownPayment=(EditText)findViewById(R.id.txt_downnpayment);
txtInterestRate=(EditText)findViewById(R.id.txt_interestrate);
txtLoanTerm=(EditText)findViewById(R.id.txt_termmonths);
btnCalculate=(Button)findViewById(R.id.btn_calculate);
btnCalculate.setOnClickListener(this);
lblResult=(TextView)findViewById(R.id.lbl_emiamount);
publicvoidonClick(Viewv)
{
try
{
DecimalFormatform
atter=new
DecimalFormat("#0.
00");
doubleprinicipleAmount=
Double.parseDouble(txtPri
nicple.
getText().toString());
doubledownPayment=Double.parseDouble(txtDownPayment.getText().toString());
prinicipleAmount=prinicipleAmount-downPayment;
doubleinterestRate=Double.parseDouble(txtInterestRate.getText().toString());
interestRate=interestRate/(12*100);
doubleloanTerm=Double.parseDouble(txtLoanTerm.getText().toString());
catch(Exceptione)
{
Toast.makeText(getBaseContext(),"InvalidInput",Toast.LENGTH_LONG).show();
}
}
}
Sample Output
1. What is Android?
It is an open-sourced operating system that is used primarily on mobile devices, such as cell
phones and tablets. It is a Linux kernel-based system that’s been equipped with rich
components that allows developers to create and run apps that can perform both basic and
advanced functions.</p>
5. What is AAPT?
AAPT is short for Android Asset Packaging Tool. This tool provides developers with the
ability to deal with zip-compatible archives, which includes creating, extracting as well as
viewing its contents.
8 . Describe Activities.
Activities are what you refer to as the window to a user interface. Just as you create windows
in orderto display output or to ask for an input in the form of dialog boxes, activities play the
same role, though it may not always be in the form of a user interface.
Android Manifest.xml
build.xml
bin/
src/
res/
assets/
12. What is the importance of XML-based layouts?
The use of XML-based layouts provides a consistent and somewhat standard means of setting
GUI definition format. In common practice, layout details are placed in XML files while other
items are placed in source files.
25. Is there a case wherein other qualifiers in multiple resources take precedence over
locale? Yes, there are actually instances wherein some qualifiers can take precedence over
locale. There aretwo known exceptions, which are the MCC (mobile country code. and
MNC (mobile network code.qualifiers.