18CSMP68 Lab Manual
18CSMP68 Lab Manual
18CSMP68 Lab Manual
Installation procedure of the Android Studio/Java software must be demonstrated, carried out in
groups.
Students should use the latest version of Android Studio/Java to execute these programs.
All of these diagrams are for representational purpose only.Students are expected to improvise on it.
Programs List:
PART – A
1 Create an application to design aVisiting Card. The Visiting card should havea companylogoatthe
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 isto be displayed. Insert a horizontal line between the job title and the phone
number.
2 Develop an Android application usingcontrols like Button, TextView, EditText for designing a
calculatorhaving basic functionality like Addition, Subtraction, Multiplication,andDivision.
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.
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
pressingoftheSTART 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 TextViewcontrol.
6 Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature,andHumidity. 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 withoneEditTextso 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 withCALLand 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 Eveningor 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 playerthat 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.
7 Develop an application that makes use of the clipboard framework for copying and pasting of the
text. The activity consists of two EditText 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 EditText to read the PrincipalAmount, 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 TextView. Also, calculate the EMI by varying the Loan Term and
Interest Rate values.
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.
Infer the role of permissions and security for Android applications.
Procedure to Conduct Practical Examination
Experiment distribution
o For laboratories having only one part: Students are allowed to pick oneexperiment from the lot
with equal opportunity.
o For laboratories having PART A and PART B: Students are allowed to pick oneexperiment
from PART A and one experiment from PART B, with equalopportunity.
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
GLOBAL ACADEMY OF TECHNOLOGY
Department of Computer Science & Engineering
Affiliated to VTU, Accredited by NAAC with 'A' grade
RR Nagar, Bengaluru – 560 098
(Accredited by NBA 2019-2022)
VI Semester
CourseCode:18CSMP68
Version1.1
w.e.f 19th April, 2021
Editorial Committee
Approved by
Dr. BHAGYASHREE R HANJI , H.O.D, In Charge
Document Log
Prof. Priyanka G
Prof. Tanushree K N
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 81-90
Experiment 8
contacts.
9 CHAPTER4 ADDITIONAL EXPERIMENTS 91-105
10 CHAPTER5 VIVA QUESTIONS 102-104
Vision of the Institute
Becomeapremierinstitutionimpartingqualityeducationinengineeringandmanagementtomeet
the changing needs ofsociety
Create environment conducive for continuous learning through quality teaching and
learning processes supported by moderninfrastructure
Promote Research and Innovation through collaboration withindustries
Inculcate ethical values and environmental consciousness through holistic education
programs
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineeringsciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmentalconsiderations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information
to provide validconclusions.
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 an
understanding of thelimitations.
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 professional
engineeringpractice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
9. Individualandteamwork:Functioneffectivelyasanindividual,andasamemberorleaderindiverse teams,
and in multidisciplinarysettings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
communityandwithsocietyatlarge,suchas,beingabletocomprehendandwriteeffectivereportsand design
documentation, make effective presentations, and give and receive clearinstructions.
11. Projectmanagementandfinance:Demonstrateknowledgeandunderstandingoftheengineeringand
management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinaryenvironments.
12. Life-longlearning:Recognizetheneedfor,andhavethepreparationandabilitytoengagein
independent and life-long learning in the broadest context of technologicalchange.
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: 03
No. of Credits:02
1. TheinstallationprocedureoftheAndroidStudio/Javasoftwaremustbedemonstratedand
carried out ingroups.
2. Students should use the latest version of Android Studio/Java/ Kotlin to execute these
programs.Diagramsgivenareforrepresentationalpurposesonly,studentsareexpectedto
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 PartB).
PART A
Program 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.
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 which displays a message saying “Successful Login”
or else display a toast message saying “Login Failed”. The user is given only two attempts and
afterthatdisplayatoastmessagesaying“FailedLoginAttempts”anddisabletheSIGNINbutton. Use
Bundle to transfer information from one activity toanother.
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 6
Create two files of XML and JSON type with values for City_Name, Latitude, Longitude,
Temperature,andHumidity.Developanapplicationtocreateanactivitywithtwobuttonstoparse the
XML and JSON files which when clicked should display the data in their respective layouts side
by side.
Program 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.
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,TimeandMeetingAgendaasinputfromtheuserandstorethisinformationintotheSQLite
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 thisDate”.
Program 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.
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
asynchronoustaskshouldimplementthefunctionalityofasimplemovingbanner.Onpressingthe
StartTaskbutton,thebannermessageshouldscrollfromrighttoleft.OnpressingtheStopTask button,
the banner message should stop. Let the banner message be “Demonstration of
AsynchronousTask”.
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
Thedownpaymentamounthastobedeductedfromtheprincipalamountpaidtowardsbuyingthe Car.
Develop an application that makes use of this AIDL service to calculate the EMI. This
applicationshouldhavefourEditTexttoreadthePrincipalAmount,DownPayment,InterestRate, Loan
Term (in months) and a button named as “Calculate Monthly EMI”.On click of this button,
theresultshouldbeshowninaTextView.Also,calculatetheEMIbyvaryingtheLoanTermand Interest
Ratevalues.
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
Attribute NOT
EXCELLENT GOOD SATISFACTORY
SATISFACTORY
Max 3 2 1 0
Marks
Write-Up 3 1.Written 1.Written 1.Written Program 1.Written Incomplete
complete Program with few with logical and 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 indentation
3.Written program 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 from
the lot with equal opportunity.
ForlaboratorieshavingPARTAandPARTB:Studentsareallowedtopickoneexperiment
from PART A and one experiment from PART B, with equalopportunity.
Change of experiment is allowed only once and marks allotted for procedure to be
made zero of the changed part only.
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 a
recent 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
designed and 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 both
iOS 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
with native 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
at such 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 responsible
for 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.
Dept. of CSE, GAT 21MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
android.content − Facilitates content access, publishing and messaging between applications
and application components.
android.database − Used to access data published by content providers and includes SQLite
database management classes.
android.opengl − A Java interface to the OpenGL ES 3D graphics rendering API.
android.os − Provides applications with access to standard operating system services including
messages, system services and inter-process communication.
android.text − Used to render and manipulate text on a device display.
android.view − The fundamental building blocks of application user interfaces.
android.widget − A rich collection of pre-built user interface components such as buttons,
labels, list views, layout managers, radio buttons etc.
android.webkit − A set of classes intended to allow web-browsing capabilities to be built into
applications.
Having covered the Java-based core libraries in the Android runtime, it is now time to turn our
attention to the C/C++ based libraries contained in this layer of the Android software stack.
Android Runtime
This is the third section of the architecture and available on the second layer from the bottom.
This section provides a key component called Dalvik Virtual Machine which is a kind of Java
Virtual Machine specially designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-threading,
which is intrinsic in the Java language. The Dalvik VM enables every Android application to run
in its own process, with its own instance of the Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable Android application
developers to write Android applications using standard Java programming language.
Application Framework
The Application Framework layer provides many higher-level services to applications in the
form of Java classes. Application developers are allowed to make use of these services in their
applications.
The Android framework includes the following key services −
Activity Manager − Controls all aspects of the application lifecycle and activity stack.
Content Providers − Allows applications to publish and share data with other applications.
Resource Manager − Provides access to non-code embedded resources such as strings, color
settings and user interface layouts.
Notifications Manager − Allows applications to display alerts and notifications to the user.
View System − An extensible set of views used to create application user interfaces.
Dept. of CSE, GAT 22MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
Applications
You will find all the Android application at the top layer. You will write your application to be
installed on this layer only. Examples of such applications are Contacts Books, Browser, Games
etc.
GotoToolsSelectAVDManager
Select Android Q, if not already downloaded press download, After download completes Select
Q and Press Next Button.
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 FileNewNewProject
PackageNameEnterpackagenameatleasttwoidentifier(Eg:com.example).BestPractice
is3ormoreidentifier(Eg:com.example.firstapp).
Right Click on app folder New Folder Assets Folder Press Finish
Button
RightClickonassetsfolderNewFile
Program 1
CreateanapplicationtodesignaVisitingCard.TheVisitingcardshouldhaveacompanylogoat 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
phonenumber.
Design
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="25dp"
android:paddingRight="20dp"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="59dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="31dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="GLOBALTECHNOLOGYLTD"
android:textColor="#E61717"
android:textSize="20sp"/>
<ImageView
android:id="@+id/imageView4"
android:layout_width="48dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginLeft="11dp"
android:layout_marginBottom="0dp"
android:layout_toRightOf="@id/textView"
app:srcCompat="@drawable/gat_logo"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Amith"
android:textSize="16dp"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="softwaredeveloper"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#000000"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="+91-91082-75635"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bangalore"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Email:info@gat.ac.in,Website:https://gat.ac.in/, Fax:+91-80-
28603158"
android:textSize="16dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:textColor="#000000"
android:gravity="center"
/>
</LinearLayout>
<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"
android:layout_marginTop="30dp"
android:text="-"
app:layout_constraintStart_toEndOf="@+id/button_three"
app:layout_constraintTop_toBottomOf="@+id/button_mul"/>
<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"/>
<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"/>
<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"
android:layout_marginTop="30dp"
android:text="."
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_one"/>
<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_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"
app:layout_constraintTop_toBottomOf="@+id/txt_result"/>
<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"/>
<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"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+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="/"
<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
packagecom.example.partaprogram2;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
importjava.util.regex.Pattern;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
ButtonbtnOne,btnTwo,btnThree,btnFour,btnFive,btnSix;
Button btnSeven, btnEight, btnNine,
btnZero;ButtonbtnAdd,btnSub,btnMul,btnDi
v;
ButtonbtnClear,btnEqual,btnDot;
EditTexttxtResult;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
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);
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("");
}
if(v.equals(btnEqual))
{
try {
Stringdata=txtResult.getText().toString();
if(data.contains("/")){
String[]operands=data.split("/");
if(operands.length==2){
doubleoperand1=Double.parseDouble(operands[0]);
doubleoperand2=Double.parseDouble(operands[1]);
doubleresult=operand1/operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"InvalidInput",
Toast.LENGTH_LONG).show();
}
}
elseif(data.contains("*")){
String[]operands=data.split(Pattern.quote("*"));
if(operands.length==2){
doubleoperand1=Double.parseDouble(operands[0]);
doubleoperand2=Double.parseDouble(operands[1]);
Dept. of CSE, GAT 49MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
doubleresult=operand1*operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"InvalidInput",
Toast.LENGTH_LONG).show();
}
}
elseif(data.contains("+")){
String[]operands=data.split(Pattern.quote("+"));
if(operands.length==2){
doubleoperand1=Double.parseDouble(operands[0]);
doubleoperand2=Double.parseDouble(operands[1]);
doubleresult=operand1+operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"InvalidInput",
Toast.LENGTH_LONG).show();
}
}
elseif(data.contains("-")){
String[]operands=data.split("-");
if(operands.length==2){
doubleoperand1=Double.parseDouble(operands[0]);
doubleoperand2=Double.parseDouble(operands[1]);
doubleresult=operand1-operand2;
txtResult.setText(String.valueOf(result));
}
else
{
Toast.makeText(getBaseContext(),"InvalidInput",
Toast.LENGTH_LONG).show();
}
}
}
catch(Exceptione){
Toast.makeText(getBaseContext(),"InvalidInput",
Toast.LENGTH_LONG).show();
}
}
Sample Output
Activity_main.xml
<?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: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="22dp"
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"
<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_marginStart="40dp"
android:layout_marginEnd="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"/>
<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"/>
<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"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login"
android:textSize="22dp"
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_marginStart="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"/>
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="50dp"
<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>
MainActivity.java
packagecom.example.parta.program3;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtUsername;
EditTexttxtPassword;
ButtonbtnSignup;
StringregularExpression="^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-
z\\d@$!]{8,}$";
btnSignup=(Button)findViewById(R.id.btn_signup);
btnSignup.setOnClickListener(this);
publicvoidonClick(Viewv)
{
Stringusername=txtUsername.getText().toString();
Stringpassword=txtPassword.getText().toString();
if(validatePassword(password)){
Bundlebundle=newBundle();
bundle.putString("user",username);
bundle.putString("Lab@2018",password);
Intentit=newIntent(this,LoginActivity.class);
it.putExtra("data",bundle);
startActivity(it);
}
else
{
Toast.makeText(getBaseContext(),"InvalidPassword",
Toast.LENGTH_LONG).show();
}
}
publicbooleanvalidatePassword(Stringpassword)
{
Patternpattern=Pattern.compile(regularExpression);
Matchermatcher=pattern.matcher(password);
returnmatcher.matches();
}
}
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
publicclassLoginActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtLoginUsername;
EditTexttxtLoginPassword;
ButtonbtnLogin;
Stringuser,pass;
intcount=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
txtLoginUsername=(EditText)
findViewById(R.id.txt_login_username);
txtLoginPassword=(EditText)
findViewById(R.id.txt_login_password);
btnLogin=(Button)findViewById(R.id.btn_login_signin);
btnLogin.setOnClickListener(this);
Bundlebundle=getIntent().getBundleExtra("data");
user=bundle.getString("user");
pass=bundle.getString("Lab@2018");
publicvoidonClick(Viewv)
{
Stringuser1=txtLoginUsername.getText().toString();
Stringpass1=txtLoginPassword.getText().toString();
if(user.equals(user1)&&pass.equals(pass1))
{
Toast.makeText(this,"LoginSuccessful"
,Toast.LENGTH_LONG).show();
}
else
}
}
Sample Output
activity_main.xml
<?xmlversion="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: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>
importandroidx.appcompat.app.AppCompatActivity;
importandroid.app.WallpaperManager;
importandroid.graphics.BitmapFactory;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importjava.util.Timer;
importjava.util.TimerTask;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
ButtonbtnChangeWallpaper;
booleanrunning;
int[]imagesArray=newint[]{
R.drawable.img1,
R.drawable.img2,
R.drawable.img3,
R.drawable.img4,
R.drawable.img5,
R.drawable.img6,
R.drawable.img7,
R.drawable.img8,
R.drawable.img9,
R.drawable.img10,
R.drawable.img11,
R.drawable.img12
};
inti=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnChangeWallpaper=(Button)
findViewById(R.id.btn_start_change_wallpaper);
btnChangeWallpaper.setOnClickListener(this);
classMyTimerextendsTimerTask
{
publicvoidrun()
{
try
{
WallpaperManagerwallpaperManager=
WallpaperManager.getInstance(getBaseContext());
if(i==12)
i=1;
if(i==11)
i=2;
if(i==10)
i=3;
if(i==9)
i=4;
if(i==8)
i=5;
if(i==7)
i=6;
if(i==6)
i=7;
if(i==5)
i=8;
if(i==4)
i=9;
if(i==3)
i=10;
}
}
AndriodManifest.xml
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.program4">
<uses-permissionandroid:name="android.permission.SET_WALLPAPER"/>
<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/AppTheme">
<activityandroid:name=".MainActivity">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?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/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="@color/colorAccent"
android:textSize="30sp"
Dept. of CSE, GAT 66MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
app:layout_constraintEnd_toEndOf="parent"
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
packagecom.example.program5;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.TextView;
importorg.w3c.dom.Text;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
TextViewlblCounter;
ButtonbtnStart,btnStop;
intcounter=0;
booleanrunning=false;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lblCounter=(TextView)findViewById(R.id.lbl_text);
btnStart=(Button)findViewById(R.id.btn_start);
btnStop=(Button)findViewById(R.id.btn_stop);
btnStop.setOnClickListener(this);
Dept. of CSE, GAT 67MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
btnStart.setOnClickListener(this);
}
publicvoidonClick(Viewv)
{
if(v.equals(btnStart))
{
counter=0;
running=true;
newMyCounter().start();
}
elseif(v.equals(btnStop))
{
running=false;
}
}
Handlerhandler=newHandler()
{
publicvoidhandleMessage(Messagem)
{
lblCounter.setText(String.valueOf(m.what));
}
};
classMyCounterextendsThread
{
publicvoidrun()
{
while(running)
{
counter++;
handler.sendEmptyMessage(counter);
try {
Thread.sleep(1000);
}
catch(Exceptione){ }
}
}
}
}
<city_name>Mysore</city_name>
<Latitude>12.295</Latitude>
<Longitude>76.639</Longitude>
<Temperature>22</Temperature>
<Humidity>90%</Humidity>
</employee>
</records>
7. Create input.json file inside assets folder and paste the below JsonData
{
"employee": {
"city_name": "Mysore",
"Latitude": "12.295",
"Longitude": "76.639",
"Temperature": 22,
"Humidity": "90%"
}
}
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.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: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"/>
<TextView android:id="@+id/textView4"
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"/>
</androidx.constraintlayout.widget.ConstraintLayout>
activity_view.xml
<?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: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"
Dept. of CSE, GAT 72MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
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"/>
<TextView android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:text="JSONDATA"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<TextView
android:id="@+id/lbl_json_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="JsonData"
app:layout_constraintEnd_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView3"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
packagecom.example.parta_program6;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
ButtonbtnParseXml,btnParseJson;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
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
Dept. of CSE, GAT 73MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
publicvoidonClick(Viewv){
if(v.equals(btnParseJson))
{
Intentit=newIntent(this,ViewActivity.class);
it.putExtra("mode",1);
startActivity(it);
}
elseif(v.equals(btnParseXml))
{
Intentit=newIntent(this,ViewActivity.class);
it.putExtra("mode",2);
startActivity(it);
}
}
}
ViewActivity.java
packagecom.example.parta_program6;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.widget.TextView;
importorg.json.JSONObject;
importorg.w3c.dom.Document;
importorg.w3c.dom.Element;
importorg.w3c.dom.Node;
importorg.w3c.dom.NodeList;
importjava.io.InputStream;
importjavax.xml.parsers.DocumentBuilder;
importjavax.xml.parsers.DocumentBuilderFactory;
publicclassViewActivityextendsAppCompatActivity{ TextViewlblXmlData,lblJsonData;
intmode=0;@O
verride
protectedvoidonCreate(BundlesavedInstanceState){
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);
else
parseXmlDocument();
publicStringparseXmlDocument()
{
try {
InputStreamis=getAssets().open("input.xml");
DocumentBuilderFactorydbFactory=DocumentBuilderFactory.newInstance();
DocumentBuilderdBuilder=dbFactory.newDocumentBuilder();
Documentdoc=dBuilder.parse(is);
Elementelement=doc.getDocumentElement();
element.normalize();
NodeListnList=doc.getElementsByTagName("employee");
for(inti=0;i<nList.getLength();i++){
Nodenode=nList.item(i);
if(node.getNodeType()==Node.ELEMENT_NODE){
Elementelement2=(Element)node;
lblXmlData.setText("CityName:"+getValue("city_name",element2)+"\n");
lblXmlData.append("Latitude:"+getValue("Latitude",element2)+"\n");
lblXmlData.append("Longitude:"+getValue("Longitude",element2)+"\n");
lblXmlData.append("Temperature:"+getValue("Temperature",element2)+"\n");
lblXmlData.append("Humidity:"+getValue("Humidity",element2)+"\n");
}
}
}
catch(Exceptione){e.printStackTrace();}
return null;
}
privatestaticStringgetValue(Stringtag,Elementelement){
NodeListnodeList=element.getElementsByTagName(tag).item(0).getChildNodes();
Nodenode=nodeList.item(0);
returnnode.getNodeValue();
}
publicvoidparseJson()
{
try {
InputStreaminputStream=getAssets().open("input.json");
byte[]data=newbyte[inputStream.available()];
inputStream.read(data);
}
catch(Exceptione){e.printStackTrace();}
}
}
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/txt_texttospeak"
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_marginStart="50dp"
android:layout_marginTop="80dp"
android:text="EnterTexttoSpeak"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<Button
android:id="@+id/btn_speak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:text="Speak"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText"/>
</androidx.constraintlayout.widget.ConstraintLayout>
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.speech.tts.TextToSpeech;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
importjava.util.Locale;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtSpeak;
ButtonbtnSpeak;
TextToSpeechtextToSpeech;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtSpeak=(EditText)findViewById(R.id.editText);
btnSpeak=(Button)findViewById(R.id.btn_speak);
btnSpeak.setOnClickListener(this);
textToSpeech=newTextToSpeech(getBaseContext(),
newTextToSpeech.OnInitListener(){
@Override
publicvoidonInit(intstatus){
if(status!=TextToSpeech.ERROR)
{
Toast.makeText(getBaseContext(),"Success",Toast.LENGTH_LONG).show();
}
}
});
textToSpeech.setLanguage(Locale.UK);
}
publicvoidonClick(Viewv)
{
Stringtext=txtSpeak.getText().toString();
textToSpeech.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
}
<?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: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="50dp"
android:text="PHONEDAILER"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/txt_phonenumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<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"/>
<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"/>
<Button
android:id="@+id/btn_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="2"
<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"/>
<Button
android:id="@+id/btn_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:text="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_one"/>
<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"/>
<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"/>
<Button
android:id="@+id/btn_eight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
<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"/>
<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"/>
<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"/>
<Button
android:id="@+id/btn_hash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
MainActivity.java
packagecom.example.part_a_program_8;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.content.Intent;
importandroid.net.Uri;
importandroid.os.Bundle;
importandroid.provider.ContactsContract;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
ButtonbtnOne,btnTwo,btnThree,btnFour,btnFive;
ButtonbtnSix,btnSeven,btnEight,btnNine,btnZero;
ButtonbtnDel,btnStar,btnHash,btnCall,btnSave;
EditTexttxtPhonenumber;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnOne=(Button)findViewById(R.id.btn_one);
btnOne.setOnClickListener(this);
btnTwo=(Button)findViewById(R.id.btn_two);
btnTwo.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);
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("");
}
publicvoidonClick(Viewv)
{
if(v.equals(btnOne))
txtPhonenumber.append("1");
else if(v.equals(btnTwo))
txtPhonenumber.append("2");
else if(v.equals(btnThree))
txtPhonenumber.append("3");
else if(v.equals(btnFour))
txtPhonenumber.append("4");
else if(v.equals(btnFive))
txtPhonenumber.append("5");
else if(v.equals(btnSix))
txtPhonenumber.append("6");
else if(v.equals(btnSeven))
txtPhonenumber.append("7");
else if(v.equals(btnEight))
txtPhonenumber.append("8");
else if(v.equals(btnNine))
txtPhonenumber.append("9");
else if(v.equals(btnZero))
txtPhonenumber.append("0");
else if(v.equals(btnHash))
txtPhonenumber.append("#");
else if(v.equals(btnSave))
{
IntentcontactIntent=newIntent
(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))
{
Stringdata=txtPhonenumber.getText().toString();
if(data.length()>0)
{
txtPhonenumber.setText
(data.substring(0,data.length()-1));
}
else
{
txtPhonenumber.setText("");
}
}
btnCall.setOnClickListener(newView.OnClickListener()
{
@Override
publicvoidonClick(Viewv){
Stringdata=txtPhonenumber.getText().toString();
Intentintent=newIntent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+data));
startActivity(intent);
}
}
);
<uses-permission android:name="android.permission.CALL_PHONE"/>
<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/AppTheme">
<activityandroid:name=".MainActivity">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</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
d.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<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_medicine_name"/>
<TextView android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_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/txt_time"/>
<EditText
android:id="@+id/txt_medicine_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<EditText
android:id="@+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/txt_medicine_name"
app:layout_constraintTop_toBottomOf="@+id/txt_medicine_name"/>
<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_constraintStart_toStartOf="@+id/txt_time"
app:layout_constraintTop_toBottomOf="@+id/txt_time"/>
<Button
ndroid:id="@+id/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="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
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.SQLiteOpenHelper;
importandroidx.annotation.Nullable;
publicclassMyDatabaseextendsSQLiteOpenHelper{
publicstaticStringDATABASE_NAME="medicine.db";
publicMyDatabase(@NullableContextcontext,@NullableStringname,@Nullable
SQLiteDatabase.CursorFactoryfactory,intversion){
super(context,name,factory,version);
}
db.execSQL("CREATETABLEMEDICINE_NAMES(NAMETEXT,MDATETEXT,MTIMETEXT)");
@Override
publicvoidonUpgrade(SQLiteDatabasedb,intoldVersion,intnewVersion){
}
}
MainActivity.java
packagecom.example.partb_program1;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.content.ContentValues;
importandroid.database.Cursor;
importandroid.database.sqlite.SQLiteDatabase;
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;
MyDatabasemyDatabase;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMedicineName=(EditText)findViewById(R.id.txt_medicine_name);
txtDate=(EditText)findViewById(R.id.txt_date);
txtTime=(EditText)findViewById(R.id.txt_time);
btnSave=(Button)findViewById(R.id.btn_save);
btnSave.setOnClickListener(this);
btnShow=(Button)findViewById(R.id.btn_show);
btnShow.setOnClickListener(this);
lblData=(TextView)findViewById(R.id.lbl_data);
myDatabase=newMyDatabase(getBaseContext(),
MyDatabase.DATABASE_NAME,null,1);
publicvoidonClick(Viewv)
Dept. of CSE, GAT 94MOBILE APPLICATION DEVELOPMENT LAB18CSMP68
{
if(v.equals(btnSave))
{
StringmedicineName=txtMedicineName.getText().toString();
Stringdate=txtDate.getText().toString();
Stringtime=txtTime.getText().toString();
SQLiteDatabasedatabase=myDatabase.getWritableDatabase();
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.getReadableDatabase();
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");
}
}
}
}
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_create"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="40dp"
android:text="Create"
app:layout_constraintEnd_toStartOf="@+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"/>
<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"/>
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="FileApplication"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/txt_content"
android:layout_width="272dp"
android:layout_height="138dp"
android:layout_marginTop="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintTop_toBottomOf="@+id/btn_create"
tools:layout_editor_absoluteX="65dp"/>
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
MainActivity.java
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);
}
@Override
publicvoidonClick(Viewv){
if(v.equals(btnCopy))
{
ClipDatamyClip;
Stringdata=txtCopy.getText().toString();
myClip=ClipData.newPlainText("text",data);
myClipboard.setPrimaryClip(myClip);
Toast.makeText(getBaseContext(),"Copied..",Toast.LENGTH_LONG).show();
}
AndroidManifest.xml
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.partbprogram7">
<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/AppTheme">
<activityandroid:name=".MainActivity">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
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/lblpayment"
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: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/textView"/>
<EditText
android:id="@+id/txt_principal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/textView"/>
<TextView
android:id="@+id/downpayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DownPayment"
app:layout_constraintStart_toStartOf="@+id/textView2"
app:layout_constraintTop_toTopOf="@+id/txt_downnpayment"/>
<EditText
android:id="@+id/txt_downnpayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
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/downpayment"
app:layout_constraintTop_toTopOf="@+id/txt_interestrate"/>
<EditText
android:id="@+id/txt_interestrate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/txt_downnpayment"
app:layout_constraintTop_toBottomOf="@+id/txt_downnpayment"/>
<TextView
android:id="@+id/textView5"
android:layout_width="130dp"
android:layout_height="33dp"
android:layout_marginTop="8dp"
android:text="LoanTerm(Months)"
app:layout_constraintStart_toStartOf="@+id/textView4"
app:layout_constraintTop_toTopOf="@+id/txt_termmonths"/>
<EditText
android:id="@+id/txt_termmonths"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="32dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/txt_interestrate"
app:layout_constraintTop_toBottomOf="@+id/txt_interestrate"/>
<Button
android:id="@+id/btn_calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
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_emiamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="EmiAmount"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
packagecom.example.partb_program8;
importandroidx.appcompat.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
importandroid.widget.Toast;
importjava.text.DecimalFormat;
importjava.util.logging.SimpleFormatter;
publicclassMainActivityextendsAppCompatActivityimplementsView.OnClickListener{
EditTexttxtPrinicple,txtDownPayment,txtInterestRate,txtLoanTerm;
ButtonbtnCalculate;
TextViewlblResult;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtPrinicple=(EditText)findViewById(R.id.txt_principal);
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
{
DecimalFormatformatter=new
DecimalFormat("#0.00");
doubleprinicipleAmount=
Double.parseDouble(txtPrinicple.
getText().toString());
doubledownPayment=Double.parseDouble(txtDownPayment.getText().toString());
doubleemi=prinicipleAmount*
(interestRate*Math.pow((1+interestRate),loanTerm))
/(Math.pow((1+interestRate),loanTerm)-1);
lblResult.setText(String.valueOf(formatter.format(emi)));
}
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
order to 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.
26. 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 are
two known exceptions, which are the MCC (mobile country code. and MNC (mobile network code.
qualifiers.