Mobile Computing - Practicalfile - SJ
Mobile Computing - Practicalfile - SJ
Practical File
sj
Index
1. Hello World Program in WML
2. External Links in WML
3. Multiple Cards Navigation in WML
4. Image Display in WML
5. Tables in WML
6. Forms in WML
7. Events in WML
8. Variables in WML
9. Square Calculator in WML
10. Addition Program in WML
11. WML Calculator
12. Android Hello World
13. Android Login Form
Experiment 1: Hello World Program in WML
Aim
Theory
WML (Wireless Markup Language) is a markup language used to create pages for mobile
devices. It uses cards as basic units of information. Wireless Markup Language (WML) is
designed for developing applications for mobile devices. A WML document is structured into
decks and cards, where a deck is analogous to an HTML page and a card is similar to a
section of content within that page. To create a card, you define content within the <card>
tag. By using a <p> tag inside the card, you can display text like "Hello! WML", which
ensures the text is presented in a paragraph format on mobile devices.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" He l l o WML" >
<p>He l l o! WML</ p>
</ c a r d>
</ wml >
Output
Theory
WML supports hyperlinks through the <a> tag, similar to HTML. WML allows the creation
of hyperlinks to external resources using the <a> tag, much like HTML. These links can point
to other WML cards or external websites, facilitating navigation and interactivity. By
defining the target URL in the <a> tag, users can click on these links to access additional
information or move to different pages.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" Ext e r na l Li nks " >
<p>
<a hr e f =" ht t p: / / www. e xa mpl e . c om" >Vi s i t Exa mpl e . c om</ a ><br / >
<a hr e f =" t e l : 1234567890" >Ca l l Us </ a >
</ p>
</ c a r d>
</ wml >
Output
Theory
WML allows multiple cards within a single document and provides navigation using <do>
tags. WML supports the creation of multiple cards within a single deck, enabling developers
to design multi-page applications. Navigation between these cards is managed through <do>
tags, which define actions such as moving to another card. This feature allows for creating a
structured and interactive user interface within a single WML document.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" Fi r s t Ca r d" >
<p>Thi s i s t he f i r s t c a r d</ p>
<do t ype =" a c c e pt " l a be l =" Ne xt " >
<go hr e f =" #c a r d2" / >
</ do>
</ c a r d>
Output
Theory
WML supports WBMP (Wireless Bitmap) format images using the <img> tag. Images in
WML are typically in the WBMP (Wireless Bitmap) format, suitable for mobile devices. The
<img> tag is used to embed these images within a card, allowing visual content to be
displayed alongside text. This enhances the user experience by providing graphical elements
that are easily interpreted on small screens.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" I ma ge Di s pl a y" >
<p>
<i mg s r c =" i ma ge . wbmp" a l t =" Sa mpl e I ma ge " / >
</ p>
</ c a r d>
</ wml >
Output
Theory
WML supports basic table structure using <table>, <tr>, and <td> tags. WML supports
tables through the <table>, <tr>, and <td> tags, similar to HTML. This allows developers to
organize content in a tabular format, making it easier to present data clearly and efficiently on
mobile devices. Tables in WML provide a structured way to display information such as
schedules, lists, or comparison charts.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" WML Ta bl e " >
<p>
<t a bl e c ol umns =" 2" >
<t r >
<t d>Na me </ t d>
<t d>Age </ t d>
</ t r >
<t r >
<t d>J ohn</ t d>
<t d>25</ t d>
</ t r >
</ t a bl e >
</ p>
</ c a r d>
</ wml >
Output
Theory
WML supports form elements like input fields and select boxes. Data can be passed between
cards using variables. WML forms allow user input through various tags such as <input>,
<select>, and <option>. These elements collect data from users, which can then be processed
and displayed in another card using <do> tags. This functionality enables interactive forms
and user feedback mechanisms within mobile applications.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" f or m" t i t l e =" I nput For m" >
<p>
Na me : <i nput na me =" us e r " t ype =" t e xt " / ><br / >
Age : <s e l e c t na me =" a ge " >
<opt i on va l ue =" 20" >20</ opt i on>
<opt i on va l ue =" 21" >21</ opt i on>
<opt i on va l ue =" 22" >22</ opt i on>
</ s e l e c t >
<do t ype =" a c c e pt " l a be l =" Submi t " >
<go hr e f =" #r e s ul t " / >
</ do>
</ p>
</ c a r d>
Output
Two cards: one with a form and another showing submitted data
Experiment 7: Events in WML
Aim
Theory
WML supports events like onpick (triggered when selecting an option) and ontimer (triggered
after a time delay). WML supports event handling through attributes like onpick and ontimer.
The onpick event triggers actions when an item is selected, while ontimer activates after a
specified duration. These events enable dynamic and time-based interactions, making WML
pages more responsive and engaging for users.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" Eve nt s De mo" ont i me r =" #c a r d2" >
<t i me r va l ue =" 30" / >
<p>
Thi s c a r d wi l l r e di r e c t i n 30 s e c onds
<s e l e c t >
<opt i on onpi c k=" #c a r d2" >Go t o Ca r d 2</ opt i on>
</ s e l e c t >
</ p>
</ c a r d>
Output
Theory
WML supports variables that can store and display values. WMLScript, which is used in
conjunction with WML, allows for the manipulation of variables. By using tags like
<setvar>, developers can define and set variable values that can be dynamically displayed on
a WML page. This feature is useful for creating interactive and personalized content.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a r d1" t i t l e =" Va r i a bl e s " >
<p>
<s e t va r na me =" me s s a ge " va l ue =" He l l o Wor l d" / >
The me s s a ge i s : $( me s s a ge )
</ p>
</ c a r d>
</ wml >
Output
Theory
WML can perform basic arithmetic operations using variables. WMLScript can perform
arithmetic operations, such as calculating the square of a number. By taking user input, the
script processes the number and displays the result, demonstrating simple computational
capabilities within a mobile-friendly environment.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" i nput " t i t l e =" Squa r e Ca l c ul a t or " >
<p>
Ent e r numbe r : <i nput na me =" num" t ype =" t e xt " f or ma t =" *N" / >
<do t ype =" a c c e pt " l a be l =" Ca l c ul a t e " >
<go hr e f =" #r e s ul t " >
<s e t va r na me =" s qua r e " va l ue =" $( num) *$( num) " / >
</ go>
</ do>
</ p>
</ c a r d>
Output
Theory
WML can perform addition using variables and setvar tag. WMLScript also supports basic
arithmetic operations like addition. By accepting two numbers as input, the script calculates
their sum and displays the result on the WML page. This showcases the ability to handle
basic mathematical functions within a WML application.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" i nput " t i t l e =" Addi t i on" >
<p>
Fi r s t numbe r : <i nput na me =" num1" t ype =" t e xt " f or ma t =" *N" / ><br / >
Se c ond numbe r : <i nput na me =" num2" t ype =" t e xt " f or ma t =" *N" / >
<do t ype =" a c c e pt " l a be l =" Add" >
<go hr e f =" #r e s ul t " >
<s e t va r na me =" s um" va l ue =" $( num1) +$( num2) " / >
</ go>
</ do>
</ p>
</ c a r d>
Output
Theory
WML can perform basic arithmetic operations using variables and multiple cards. A
calculator application in WML uses WMLScript to perform basic arithmetic operations.
Users input numbers and select operations, and the script processes these inputs to display the
result. This demonstrates how WML and WMLScript can be combined to create functional
and interactive mobile applications.
Code
<? xml ve r s i on=" 1. 0" ? >
<! DOCTYPE wml PUBLI C " - / / WAPFORUM/ / DTD WML 1. 1/ / EN"
" ht t p: / / www. wa pf or um. or g/ DTD/ wml _1. 1. xml " >
<wml >
<c a r d i d=" c a l c ul a t or " t i t l e =" Ca l c ul a t or " >
<p>
Fi r s t numbe r : <i nput na me =" num1" t ype =" t e xt " f or ma t =" *N" / ><br / >
Se c ond numbe r : <i nput na me =" num2" t ype =" t e xt "
f or ma t =" *N" / ><br / >
Ope r a t i on:
<s e l e c t na me =" op" >
<opt i on va l ue =" a dd" >Add</ opt i on>
<opt i on va l ue =" s ub" >Subt r a c t </ opt i on>
<opt i on va l ue =" mul " >Mul t i pl y</ opt i on>
<opt i on va l ue =" di v" >Di vi de </ opt i on>
</ s e l e c t >
<do t ype =" a c c e pt " l a be l =" Ca l c ul a t e " >
<go hr e f =" #r e s ul t " >
<s e t va r na me =" r e s ul t " va l ue =" $( num1) " / >
</ go>
</ do>
</ p>
</ c a r d>
Output
Theory
Android applications use XML layouts and Java/Kotlin code to create user interfaces.
Developing a simple Android application involves creating an activity that displays a greeting
message, such as "Hello, welcome to Android Lab". This introductory project helps new
developers understand the basics of Android app development, including activity lifecycle,
user interface design, and basic event handling.
Code
activity_main.xml
<Te xt Vi e w
a ndr oi d: l a yout _wi dt h=" wr a p_c ont e nt "
a ndr oi d: l a yout _he i ght =" wr a p_c ont e nt "
a ndr oi d: t e xt =" He l l o, we l c ome t o Andr oi d La b"
a ndr oi d: t e xt Si z e =" 20s p" / >
MainActivity.java
Output
Theory
Android provides EditText widgets for input and Button widgets for actions. An Android
login activity prompts the user to enter a username and password, validating these credentials
against predefined values. If the entered credentials are correct, a welcome message is
displayed. This exercise introduces developers to user authentication processes, UI design,
and handling user inputs in Android applications.
Code
activity_main.xml
<Edi t Te xt
a ndr oi d: i d=" @+i d/ us e r na me "
a ndr oi d: l a yout _wi dt h=" ma t c h_pa r e nt "
a ndr oi d: l a yout _he i ght =" wr a p_c ont e nt "
a ndr oi d: hi nt =" Us e r na me " / >
<Edi t Te xt
a ndr oi d: i d=" @+i d/ pa s s wor d"
a ndr oi d: l a yout _wi dt h=" ma t c h_pa r e nt "
a ndr oi d: l a yout _he i ght =" wr a p_c ont e nt "
a ndr oi d: hi nt =" Pa s s wor d"
a ndr oi d: i nput Type =" t e xt Pa s s wor d" / >
<But t on
a ndr oi d: i d=" @+i d/ l ogi nBut t on"
a ndr oi d: l a yout _wi dt h=" ma t c h_pa r e nt "
a ndr oi d: l a yout _he i ght =" wr a p_c ont e nt "
a ndr oi d: t e xt =" Logi n" / >
</ Li ne a r La yout >
MainActivity.java
@Ove r r i de
pr ot e c t e d voi d onCr e a t e ( Bundl e s a ve dI ns t a nc e St a t e ) {
s upe r . onCr e a t e ( s a ve dI ns t a nc e St a t e ) ;
s e t Cont e nt Vi e w( R. l a yout . a c t i vi t y_ma i n) ;
us e r na me = f i ndVi e wByI d( R. i d. us e r na me ) ;
pa s s wor d = f i ndVi e wByI d( R. i d. pa s s wor d) ;
l ogi nBut t on = f i ndVi e wByI d( R. i d. l ogi nBut t on) ;
Output
An Android app with username and password fields and a login button. Shows welcome
message for correct credentials (admin/password) or error for invalid ones.