mad lab manual - list of experiments

Upload: miraclesuresh

Post on 07-Jul-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/19/2019 MAD Lab Manual - List of Experiments

    1/24

    Ex:No:1a Develop an application that uses GUI component to create Login Page

    Date:

    Aim:

    To develop the android mobile application which consist of GUI components for Login Page creation

    Procedure:

    Step 1: Design

    1. Open the actual Project folderapp! in "ndroid #tudio I$% & %clipse I$%

    '. (lic) res director* +, la*out +, activit*-main.ml +, $esign

    /. Insert the Username and Password fields with #ubmit and 0eset buttons in $esign view of

    activit!main"xml

    Tet2iew android3tet45Login Page5 android3tet"lignment45center5 &,

    Tet2iew android3tet456ame5 &, %ditTet android3id4578id&t15 &,Tet2iew android3tet49Password9 &, %ditTet android3id4578id&t'5

    android3inputT*pe45tetPassword5 &,

    :utton android3tet45O)5 android3id4578id&b15 &,

    :utton android3tet450eset5 android3id4578id&b'5 &,

    ;. %nter the corresponding ids for each component.

    Step #:  Open java +,

    A A!>

    reset.setOn(lic)Listenernew 2iew.On(lic)Listener! =

    7Override

     public void on(lic)2iew v! =

    e1.setTetB9!>

    e'.setTetB9!>

    A A!>

    Step &: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    2/24

    Ex:No:1 ' Develop an application that uses images and various colours

    Date:

    Aim:

    To design an application that displa*s an image and various colours while clic)ing the button.

    Procedure:

    Step 1: Design

    1. Open the actual Project folderapp! in "ndroid #tudio I$%& %clipse I$%

    '. (lic) res director* +, la*out +, activit*-main.ml +, $esign

    /. Insert the following in $esign view of activit*-main.ml.

    ;. %nter the id for each component

    Step #: Open *our "ndroid studio project folder e.g. Project name3 GUI (omponents ! C,

    (lic) app +, src +, main +, res +, drawable +, add D.png file.

    Step (: Open java +, $ainActivit"%ava  and add following code

     bu1.setOn(lic)Listenernew 2iew.On(lic)Listener! =

    7Override

     public void on(lic)2iew v! =

     bu1.set:ac)ground(olor(olor.G0%%6!>

    tet.setTet(olor(olor.G0%%6!>

     bu'.set:ac)ground(olor(olor.LTG0"E!>

     bu/.set:ac)ground(olor(olor. LTG0"E!>

    AA!>

    $o this for remaining other colour buttons

    Step &: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    3/24

    Ex:No:# Develop an application that uses various )onts

    Aim:

    To design an application that displa*s the given tet in various Font t*pe such as "rial? "ngilla Tattoo

    etc.

    Procedure:

    Step 1: Design

    1. Open the actual Project folderapp! in "ndroid #tudio I$%& %clipse I$%

    '. (lic) res director* +, la*out +, activit*-main.ml +, $esign

    /. Insert the GUI components to $esign view in activit*-main.ml

    ;. %nter the id for each component

    Step #:  (reate assets sub director* in res

    0ight clic) res +, 6ew +, Folder +, 6ew "ssets Folder 

    0ight clic) assets +, 6ew +, $irector* +, %nter the director* name fonts!

     paste the font t*pes in fonts director*

    Step (: (reate an activit* file

     public class

    "rra*"dapter#tring, adapter 4 new "rra*"dapter#tring,this?

    android.0.la*out.simple-dropdown-item-1line?values!>listview.set"dapteradapter!>

  • 8/19/2019 MAD Lab Manual - List of Experiments

    4/24

    listview.setOnItem(lic)Listenernew "dapter2iew.OnItem(lic)Listener! =

    7Override

     public void onItem(lic)"dapter2iewK, parent? 2iew view? int position? long

    id!

    =

    #tring item2alue 4 #tring! listview.getItem"tPositionposition!>

    ifitem2alue.euals5"ngilla Tattoo5!!

    =

    tt.setTete1.getTet!.to#tring!!>#tring fontPath45fonts&"ngillaTattoo-P%0#O6"L-U#%-O6LE.ttf5>

    T*peface tf 4 T*peface.createFrom"ssetget"ssets!? fontPath!>

    tt.setT*pefacetf!>

    A

    add this content for other font t*pes in the List

    A!>AA

    Step &: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    5/24

    Ex:No:( Develop a *orm using Intent and Event Listeners

    Aim:

    To design a Form with appropriate user controls and

    Procedure:

    Step 1: Design

    1. (reate an android project using android studio& %clipse I$%

    '. (lic) res director* +, la*out +, activit*-main.ml +, $esign

    /. (reate another activit* b* clic)ing right in app folder +,6ew +,"ctivit* +,%mpt* "ctivit*+

    ,activit*-main'.ml

    ;. Insert the GUI components to $esign view in activit*-main.ml

    Tet2iew android3tet450%GI#T0"TIO6 FO0

  • 8/19/2019 MAD Lab Manual - List of Experiments

    6/24

    #tring name4e1.getTet!.to#tring!>

    0eturn name>

    A A

    Step (: Open java +,

  • 8/19/2019 MAD Lab Manual - List of Experiments

    7/24

    Ex:No: & Develop an application that uses Laout $anagers and event listeners

    Aim:

      To design an application that uses the %vent Listeners and

  • 8/19/2019 MAD Lab Manual - List of Experiments

    8/24

    android3title45Two5&,

    &menu,

    Step -: Open

     pm.get

    case 0.id.two3

    Intent in 4 new Intentget"pplication(ontet!?third.class!>

    start"ctivit*in!>

    #*stem.eit!>

     brea)>

    A

    return false>

    AA!>

     pm.show!>

    A

    A!>

    A A

    second"%ava

     public class second etends "pp(ompat"ctivit* =

    :utton b'>

    7Override

     protected void on(reate:undle savedInstance#tate! =...

     b'4:utton!find2iew:*Id0.id.b'!>

    Image2iew iv 4 Image2iew!find2iew:*Id0.id.iw!>

     b'.setOn(lic)Listenernew 2iew.On(lic)Listener! =

    7Override

     public void on(lic)2iew v! =

    Intent i 4 new Intentget"pplication(ontet!?

    #*stem.eit!> A

    A!>

    A A

    .hird"%ava

  • 8/19/2019 MAD Lab Manual - List of Experiments

    9/24

     public class third etends "pp(ompat"ctivit* =

    :utton bac)>

    Image2iew img>

    7Override

     protected void on(reate:undle savedInstance#tate! =

    ....

     bac)4:utton!find2iew:*Id0.id.bac)!>

    img4Image2iew!find2iew:*Id0.id.image2iew!>

     bac).setOn(lic)Listenernew 2iew.On(lic)Listener! =7Override

     public void on(lic)2iew v! =

    Intent i 4 new Intentget"pplication(ontet!?

    #*stem.eit!> A

    A!>

    A A

    Step /: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    10/24

    Ex:No:+ Develop a native calculator application

    Date:

    Aim:

    To develop the (alculator application in "ndroid device for performing basic arithmetic operations such

    as addition? subtraction etc.

    Procedure:

    Step 1: $esign for UI in la*out file activit*-main.ml!

    Step #: "lign the number :uttons in Linear La*out li)e this.

    LinearLa*out android3orientation45horiQontal5 android3la*out-width45fill-parent5

    android3la*out-height45wrap-content5 android3gravit*45center5 android3id4578id&lM5,

    :utton.... android3id 4 578id&one5 android3tet4515 &,

    :utton.... android3id 4 578id&two5 android3tet45'5 &,

    :utton.... android3id 4 578id&three5 android3tet45/5 &,

    :utton.... android3id 4 578id&div5android3tet45&5 &, &LinearLa*out,

    Step (: Open

  • 8/19/2019 MAD Lab Manual - List of Experiments

    11/24

    if optr.euals585!! =

    op' 4 Integer.parseIntdisp.getTet!.to#tring!!>

    disp.setTet55!>

    op1 4 op1 8 op'>

    disp.setTetInteger.to#tringop1!!>

    A else if optr.euals5+5!! =

    .... similar to other operators ...A A

    7Override

     public void on(lic)2iew arg! =%ditable str 4 disp.getTet!>

    switch arg.getId!! =

    case 0.id.one3

    if op' R4 ! =

    op' 4 > disp.setTet55!> A

    str 4 str.appendone.getTet!!>

    disp.setTetstr!>

     brea)>

    case 0.id.two3

    if op' R4 ! =

    op' 4 > disp.setTet55!> A

    str 4 str.appendtwo.getTet!!>

    disp.setTetstr!>

     brea)>

    case 0.id.three3

    ..... similar for other number buttons upto S

    case 0.id.cancel3

    op1 4 > op' 4 >

    disp.setTet55!>

    disp.set@int5Perform Operation5!>

     brea)>

    case 0.id.add3

    optr 4 585>if op1 44 ! =

    op1 4 Integer.parseIntdisp.getTet!.to#tring!!>

    disp.setTet55!>

    A

    else if op' R4 ! =

    op' 4 >

    disp.setTet55!>

    A

    else

    =

    op' 4 Integer.parseIntdisp.getTet!.to#tring!!>

    disp.setTet55!>op1 4 op1 8 op'>

    disp.setTetInteger.to#tringop1!!>

    A

     brea)>

    case 0.id.sub3...

    same as add N continue for other operators

    case 0.id.eual3

    if Roptr.eualsnull!! =

    if op' R4 ! =

    if optr.euals585!! =

    disp.setTet55!>

    op1 4 op1 8 op'>disp.setTetInteger.to#tringop1!!>

  • 8/19/2019 MAD Lab Manual - List of Experiments

    12/24

    A

    else if optr.euals5+5!! =

    disp.setTet55!>

    op1 4 op1 + op'>

    disp.setTetInteger.to#tringop1!!>

    A

    else if optr.euals5D5!!

    =

    disp.setTet55!>op1 4 op1 D op'>

    disp.setTetInteger.to#tringop1!!>

    A

    else if optr.euals5&5!!

    =

    disp.setTet55!>

    op1 4 op1 & op'>

    disp.setTetInteger.to#tringop1!!>

    A

    A

    else

    =

    operation!>

    A

    A

     brea)> AAA

    Step &: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    13/24

    Ex:No:, 0rite an application that dras 'asic graphical primitives on the screen

    Date:

    Aim:

    To develop an application that draws basic graphical primitives such as rectangle? circle and other

     pol*gons on the screen.

    Procedure:

    Step 1: (reate an android project using android studio

    Step #: "fter creating the project? open the java file named

    canvas.draw(ircle1? 1? ? ob!>

    ob.set(olor(olor.(E"6!>

    canvas.draw(ircle'? M? /? ob!>

    ob.set(olor(olor.

    canvas.draw0ect'? '? ;? ;? ob!>

    ob.set(olor(olor.0%$!>canvas.drawLine'M?M?/M?;?ob!>

    canvas.rotate+;M!> AAA

    Step (: 0un this app in "ndroid %mulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    14/24

    Ex:No:- Develop an application that ma2es use o* data'ase

    Date:

    Aim:

    To design a login form and insert the values into #VLite database and view the data from the database

    in android studio.

    Procedure:

    Step 1: (reate an android project using android studio

    Step #: (reate two resource files D.ml! and two activit* files D.java! named

    activit*-main.ml N activit*-main'.ml and

      %ditTet e1?e'>

      #tring nam?coll>

      S3LiteData'ase d'4 protected void on(reate:undle savedInstance#tate! {…….

  • 8/19/2019 MAD Lab Manual - List of Experiments

    15/24

     d' 5 open6r7reateData'ase89$d'9$6DE!P;I

    d'"execS3L89INSE;. IN.6 student

    final (ursor c 4 db.rawVuer*5select D from student5?null!>

    c.moveToFirst!>

    fn.setTetc.get#tringc.get(olumnInde5name5!!!>ln.setTetc.get#tringc.get(olumnInde5college5!!!>

     bac).setOn(lic)Listenernew 2iew.On(lic)Listener! =

    ... && Insert code for redirecting to @ome page...

    A

    net.setOn(lic)Listenernew 2iew.On(lic)Listener! =

    ..... public void on(lic)2iew v! =

    Tr* =

    c.moveTo6et!>

    fn.setTetc.get#tringc.get(olumnInde5name5!!!>

    ln.setTetc.get#tringc.get(olumnInde5college5!!!>

    Acatch %ception e!=Toast.ma)eTetget"pplication(ontet!?5Last 0ecord5?Toast.L%6GT@-LO6G!.show!>

    e.print#tac)Trace!>

    A A A!>

     prev.setOn(lic)Listenernew 2iew.On(lic)Listener! =

     public void on(lic)2iew v! = tr* =

    c.moveToPrevious!>

    fn.setTetc.get#tringc.get(olumnInde5name5!!!>

    ln.setTetc.get#tringc.get(olumnInde5college5!!!>

    Acatch %ception e! =

    Toast.ma)eTetget"pplication(ontet!?5First 0ecord5?Toast.L%6GT@-LO6G!.show!>

    e.print#tac)Trace!>

    AA A!> AAStep -: 0un the project

  • 8/19/2019 MAD Lab Manual - List of Experiments

    16/24

    Ex:No: / Implement an application that implements $ulti threading

    Date:

    Aim:

    To design an application that implements

    CCsam is a name o* Audio *ile8sam"mp(=

    CC'1 'utton is *or plaing audio *ile

      b1.setOn(lic)Listenernew 2iew.On(lic)Listener! =

      7Override

      public void on(lic)2iew v! =

      Intent in4new Intent

  • 8/19/2019 MAD Lab Manual - List of Experiments

    17/24

      start"ctivit*For0esultin?("

    CCthis line is used *or setting image as allpaper

      A catch %ception e! = e.print#tac)Trace!> A

    CC'( 'utton is *or starting audio *ile

     b/.setOn(lic)Listenernew 2iew.On(lic)Listener! =

      7Override

      public void on(lic)2iew v! =

      m.start!> A A!>

    CC'& is *or stooping an audio *ile

     b;.setOn(lic)Listenernew 2iew.On(lic)Listener! =

      7Override

      public void on(lic)2iew v! =

      m.stop!> A A!>

    A

      protected void on"ctivit*0esultint reuestcode?int resultcode?Intent data!=

      ifreuestcode44("

  • 8/19/2019 MAD Lab Manual - List of Experiments

    18/24

    Ex:No: Develop a native application that uses GPS location in*ormation

    Date:

    Aim: 

    To $evelop a native application that uses GP# location information

    Procedure:

    Step 1 :To use GP# in *our application first of all *ou must specif* the uses+permission in "ndroid manifest

    file3 

    manifest,

    uses+permission

    android3name45android.permission."((%##-FI6%-LO("TIO65,&usespermission,

    Step #: (reate a "ctivit* La*out

    Kml version451.5 encoding45utf+5K,LinearLa*outmlns3android45http3&&schemas.android.com&ap)&res&andro id5

    android3la*out-width45fill-parent5

    android3la*out-height45fill-parent5

    android3orientation45vertical5 ,

    Tet2iew android3id4578id&gps-tet5

    android3la*out-width45fill-parent5

    android3la*out-height45wrap-content5

    android3tet457string&hello5 &,

    &LinearLa*out,

    Step (: (reate a Wava (lass file

    7urrentLocationActivit"%ava

    ..

     public class (urrentLocation"ctivit* etends "ctivit* =

    &DD (alled when the activit* is first created. D& Private Tet2iew

    super.on(reatesavedInstance#tate!> set(ontent2iew0.la*out.main!>

    gpsLocation2iew4Tet2iew! find2iew:*Id0.id.gps-tet!>

    &D Use the Location

    Tr*=

    addresses 4 gcd.getFromLocationloc.getLatitude!?loc.getLongitude!? 1!>

    Acatch IO%ception e!=

    && TO$O "uto+generated catch bloc) 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    19/24

    e.print#tac)Trace!>

    A

    #tring tet4addressesR4null!K5(it* 3 58addresses.get!.get#ubLocalit*!85Xn (ountr*

    3 58addresses.get!.get(ountr*6ame!35Un)nown Location5>

    #tring location2alue 4 5

    gpsLocation2iew.setTetlocation2alue!>

    A7Override

     public void onProvider$isabled#tring provider!

    =Toast.ma)eTetget"pplication(ontet!?5Gps $isabled5?Toast.L%6GT@-#@O0T !.show!>

    A

    7Override

     public void onProvider%nabled#tring provider!=

    Toast.ma)eTetget"pplication(ontet!?5Gps %nabled5?Toast.L%6GT@-#@O0T!.show!>

    A

    7Override

     public void on#tatus(hanged#tring provider? int status? :undle etras!

    = A A }

    Step +: 0un the Project in emulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    20/24

    Ex:No: 1H Implement an application that rites data to the SD card

    Date:

    Aim: 

    To implement an application that read&writes data from&to the %ternal

  • 8/19/2019 MAD Lab Manual - List of Experiments

    21/24

      fout.close!>

      Toast.ma)eTetget"pplication(ontet!?filename85#aved5?Toast.L%6GT@-LO6G!.show!>

      A

      catch File6otFound%ception e!

      =

      e.print#tac)Trace!>

      A

      catch IO%ception e!

      =  e.print#tac)Trace!>

      A

     b'.setOn(lic)Listenernew 2iew.On(lic)Listener! =

    ...

    tr*

      =

      File m*File4new File5&sdcard&58filename!>

      FileInput#tream fin4new FileInput#treamm*File!>

      :uffered0eader m*0eadear4new :uffered0eadernew Input#tream0eaderfin!!>

      while a$ata0ow4m*0eadear.readLine!!R4null!

      =

      a:uffer84a$ata0ow85Xn5>

      A

      m*0eadear.close!>

      A

      catch IO%ception e!

      = A

    Toast.ma)eTetget"pplication(ontet!?a:uffer?Toast.L%6GT@-LO6G!.show!>

    A

    Step +: 0un the Project in emulator 

  • 8/19/2019 MAD Lab Manual - List of Experiments

    22/24

    Ex:No: 11 Implement an application that creates an alert upon receiving a message

    Date:

    Aim: 

    To design an application that creates an alert upon receiving a message.

    Procedure:

    Step 1: #elect File +, 6ew +, Project +, "ndroid "pplication Project or! "ndroid

    Project. Fill the forms and clic) BFinish9 button.

    Step #: (reate an activit* file

    $ainActivit"%ava

    """

     protected void on(reate:undle savedInstance#tate! =

    ..."lert$ialog.:uilder builder 4 new "lert$ialog.:uilderthis!>

    &&Uncomment the below code to #et the message and title from the strings.ml

    file

    (ontet contet 4 get"pplication(ontet!> #tring tet 4 5@ello toastR5>

    int duration 4 Toast.L%6GT@-#@O0T>

    Toast toast 4 Toast.ma)eTetcontet? tet? duration!> toast.show!>

    Toast.ma)eTetthis? 5@eelo Toast 5? Toast.L%6GT@-#@O0T!.show!>

    &&builder.set

    &etting message manuall* and performing action on button clic) 

     builder.set

    A

    A!

    .set6egative:utton56o5? new $ialogInterface.On(lic)Listener! =

     public void on(lic)$ialogInterface dialog? int id! =

    && "ction for Y6OY :utton

    dialog.cancel!>

    A

    A!>

    &&(reating dialog bo

    "lert$ialog alert 4 builder.create!>

    &etting the title manuall*

    alert.setTitle5"lertdemo5!>

    alert.show!>

    set(ontent2iew0.la*out.activit*-main!>

    AA

    Step (: 0un the Project.

  • 8/19/2019 MAD Lab Manual - List of Experiments

    23/24

    Ex:No: 1# Alarm 7loc2  

    Date:

    Aim: 

    To design mobile application that creates an alarm cloc) 

    Procedure:

    Step 1: (reate an android project using android studio

    Step #: (reate a la*out file for UI.activit*-main.ml "fter design? the code will be generated automaticall* in

    activit*-main.ml file!

    #tep /3 0ight (lic) res +, 6ew +, "ndroid 0esource director* +, select Braw9 0esource

    t*pe +, O) 

    #tep ;3 Open res +, raw and add D.mp/ file

    #tep M3 "fter creating the la*out? open the manifest file named "ndroid

  • 8/19/2019 MAD Lab Manual - List of Experiments

    24/24

     public void on0eceive(ontet contet?Intent intent!

    =

    m 4

    m.start!>

    Toast.ma)eTetcontet? 5"larm....Get up5? Toast.L%6GT@-LO6G!.show!>

    AA

    Step -: (reate an activit* file.

    $ainActivit"%ava

     public class

    "larm