Android Projects 2013

28
MVC Pattern Shopping Cart  Android_Examp le In this example showing use of MVC Pattern to create a very asic Shopping cart! Creating very asic Controller Class and defined in application context and you can use this Control ler Class as a "loal class! If any View#Activit y$ re%uired values then view should call controller and then controller will call appropriate Model and provide value to view! Models can also communicate with each others to exchange values! http&''androidexample!com'(se_MVC_Pattern_)o_Create_Very_*asic_Shoppin g_Cart__+  _Android_Example'index!php, view-article_discription.aid-//0.aaid-/12 n this example showing use of MVC Pattern to create a very asic Shopping cart! Creating very asic Controller Class and defined in application context and you can use this Controller Class as a "loal class! If any View#Activity$ re%uired values then view should call controller and then controller will call appropriate Model and provide value to view! Models can also communicate with each others to exchange values!

Transcript of Android Projects 2013

Page 1: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 1/28

MVC Pattern Shopping Cart Android_Example

In this example showing use of MVC Pattern to create a very asic Shoppingcart! Creating very asic Controller Class and defined in application context andyou can use this Controller Class as a "loal class! If any View#Activity$ re%uiredvalues then view should call controller and then controller will call appropriateModel and provide value to view!

Models can also communicate with each others to exchange values!

http&''androidexample!com'(se_MVC_Pattern_)o_Create_Very_*asic_Shopping_Cart__+ _Android_Example'index!php,

view-article_discription.aid-//0.aaid-/12

n this example showing use of MVC Pattern to create a very asic Shopping cart!Creating very asic Controller Class and defined in application context and youcan use this Controller Class as a "loal class! If any View#Activity$ re%uiredvalues then view should call controller and then controller will call appropriateModel and provide value to view!

Models can also communicate with each others to exchange values!

Page 2: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 2/28

 

This Example WorkFlow :

Page 3: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 3/28

Project Structure :

Page 4: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 4/28

File : src/ModelProducts.java Model Class to store products details!

File : src/ModelCart.java Model Class to store products in cart!

Page 5: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 5/28

Create a ModelProducts type Arraylist to store ModelProducts instances!

File : src/Cotroller.java Controller class extends with android!app!Application and defined in the application tag in your

 AndroidManifest!xml file! Android will create an instance of Controller class and ma3e it availalefor your entire application context! 4ou can get o5ect of your class on any activity ' roadcastreceiver ' service in application context#environment$ y Context!getApplicationContext#$ method!

Controller class to intract with models and provide values to views!

Create a ModelProducts type Arraylist to store ModelProducts instances!Create a ModelCart type refference to store ModelCart instance to intract with ModelCart! 

File : !droidMai"est.xml 

 Assign Controller!5ava in application tag6 see this line in applicationtag adroid:ame#$com.adroidexample.mvc.Cotroller$!"ter assi% &ou ca %et Cotroller.java istace o a& activit& i applicatio cotext. 

File : src/FirstScree.java %et!pplicatioCotext'( method o" Cotext will %ive Cotroller.java o)ject* use this o)jectto store product details ad the store o)ject i !rra&list.

Creati% view elemets d&amicall& to show product details ad add to cart )uttos.

!"ter click add to cart )utto product o)ject will store i !rra&list de"ied i ModelCartclass. 

File : src/SecodScree.java Showi% ModelProduct o)jects details o scree that stored i ModelCart !rra&list. 

File : src/ThirdScree.java Showi% ModelProduct o)jects details o scree that stored i ModelCart !rra&list. 

Page 6: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 6/28

+commi% ,ut%oi% Call -o% With Call uratio !droid Project

n )his pro5ect creating a incomming outgoing call log with call duration! 

WorkFlow :Created three roadcast reciever!  a. *roadcast 7eciever for Incomming call #IncomingCall!5ava$!  ). *roadcast 7eciever for 8utgoing call #8utgoingCall!5ava$!  c. *roadcast 7eciever for Call duration #Call9uration7eceiver!5ava$!Created controller file Controller!5avaCreated a list to show what type of call log want to show! created three files  a. Call:ist!5ava to show call list options!  ). Call:ist9ata!5ava to create each row data in list!  c. Call:istValues!5ava Model to store each row data for list!9*Adapter!5ava to store call data in s%lite dataase!Call9etailServer!5ava to store s%lite data to server and show call data to activity!

 

Flow :

  0.  ;hen a call will come then IncommingCall!5ava and Call9uration7eceiver!5ava roadcastrecievers called and data store in s%lite dataase!  1.  ;hen a call will ma3e to other then 8utgoingCall!5ava and Call9uration7eceiver!5avaroadcast recievers called and data store in s%lite dataase!  2.  ;hen clic3 on Call log type #today'wee3ly'monthly$ one re%uest sent to server andcalllogserver!php called and return result ased on imei numer and show on activity!

owload +ma%es From We) !d -a3& -oad +-ist4iew !droid Example

n this example downloading images from we to a listview! (sing la<y loading to downloadimages in a listview! (sing custom adapter to create lisview rows and using Image:oader class tola<y load images from we and show in listview row! Clic3 on listview showing image url in alert! 

Steps :  Mai!ctivit&.java : Initiali<e static image url in string array and create listview!  -a3&+ma%e-oad!dapter.java : (sed to create each list row! Inflate taitem!xml file for eachrow and call Image:oader!5ava to download image from url and resi<e downloaded image cache

on sdcard!  +ma%e-oader.java : (sed to download image from url and resi<e downloaded image andma3e file cache on sdcard! :a<y load images for listview rows!  FileCache.java : (sed to create folder at sdcard and create map to store downloaded imageinformation!  Memor&Cache.java : (sed to set cache folder si<e limit # =ow much m'3 downloadedimage cache folder will store $ and also used to clear cache files from sdcard!  5tils.java : (sed to Create Cache image for images downloaded from we! 

Page 7: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 7/28

Example Flow :

Project Structure :

Page 8: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 8/28

File : !droidMai"est.xml + 9efine android!permission!;7I)E_E>)E7?A:_S)87A"E and android!permission!I?)E7?E)permissions

File : mai.xml + )his file used to show main activity screen!+ 9efine :istView in this file!

Page 9: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 9/28

File : Mai!ctivit&.java + 9efine numer of image urls in a string array!

+ Call adapter class to create listview rows! 

File : -a3&+ma%e-oad!dapter.java + Create custom adapter!+ Inflate taitem!xml file to create rows in listview!+ Call Image:oader!5ava to download and cache images from we! 

File : File : listview6row.xml

File : +ma%e-oader.java + (sed to download images from we and resi<e!+ :a<y load images in listview!+ @urther explanation See in comments!

File : FileCache.java 

File : Memor&Cache.java

File : 5tils.java

Page 10: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 10/28

evice To evice Messa%i% 5si% 7oo%le CloudMessa%i% 7CM !droid Exa

n this example sending device to device #Moile )o Moile$ messaging using google cloudmessaging #"CM$! it is the very asic example you can use this to create advance levelmessaging application! (sing php as server side language and mys%l dataase 6 you can useother server side language #5sp'asp!net'asp$ and dataase #s%lserver'oracle$! 

8,TE :Students can also use this pro5ect for semester pro5ect! )hey can modify and inhance examplesource code! =ere i am using =))P ased device to device messaging ut 7ight way to achieve the device todevice messaging is to implement "CM Cloud Connection Server #CCS$ ! "CM CloudConnection Server #CCS$ is a connection server ased on >MPP! CCS allows 1rd+party app

servers to communicate with Android devices y estalishing a persistent )CP connection with"oogle servers using the >MPP protocol! )his communication is asynchronous andidirectional#device to device$! Check this 59- "or MPP )ased 7CM Cloud Coectio Server 'CCS(:http&''developer!android!com'google'gcm'ccs!html this url is using Smac3 API for AVA :ater i will give example to send device to device message with CCS and >MPP! *ut now going with this =))P ased messaging#chatting$! +" &ou are ew i 7oo%le Cloud Messa%i% '7CM( implemetatio the must )e read "irstthis example.

 Android Push ?otifications using "oogle Cloud Messaging #"CM$ + PA7) / + this example usi% custom %rid la&out so also read this example.Custom "rid :ayout + Android Example + this example usi% custom spier so also read this example.Custom Spinner ;ith Image And )ext + Android Example

Example WorkFlow :

Page 11: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 11/28

Project Structure

Page 12: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 12/28

 Assuming you have read previous "CM example and familiar with "oogle cloud messagingasics!

Page 13: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 13/28

Page 14: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 14/28

STEPS :

See aove image!!!!!?ow ;e will follow these steps 

0.  Edit configuration files and create support files!

  1.  Chec3 device is registered for weserver or not!

1!.  if device is not registered then send to registration screen and after gcm registration save"CM regI9 and device IMEI to mys%l dataase on server 6 After registration redirect to show allregistered devices screen!

  1;.  if device is registered then get this device regI9 and IMEI from server and store it inSB:ite dataase on phone and redirect to show all registered devices screen!

  2.  Select user to send message and after selection show send message screen!

  <.  ;hen user sending message then send sender IMEI 6 sendto IMEI and message to weserver 6 weserver get user device data #regI9$ from mys%l dataase and call gcm to sendmessage to regI9!

  =.  ;hen "CM Client on device get new message store it in SB:ite dataase on phone andshow new notification message in notification ar!

  >.  After clic3ing notification showmessage screen will open and show all got messages and onshowmessage screen user can also send message to other devices #See output video$!

 

8,TE :

In this example i am showing 5ava'xml'php files step y step! 

 /??????????????????????????????????? STEP0 ST!9T????????????????????????????????????/

 

STEP0 : Edit co"i%uratio "iles ad createsupport "iles.

 

M- F+-E : !droidMai"est.xml )he following permission are re%uired to ma3e your pro5ect support gcm!

+8TE98ET  )o ma3e your app use internet services!!CCESS68ETW,9@6ST!TE  )o access networ3 state #used to detect internet status$7ET6!CC,58TS  7e%uired as "CM needs google accountW!@E6-,C@  ?eeded if your app need to wa3e your device when it sleeps

Page 15: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 15/28

4+;9!TE  ?eeded if your support viration when receiving notification Also add some roadcast receivers as mentioned elow! 

In this Example (sing two configuration files!

Config!5ava for client side and config!php for server side!(sing three support files for clients Controller!5ava6 9*Adapter!5ava6 (ser9ata!5ava 

A!4! F+-E : Co"i%.java )his is the main client side configuration file! 

A!4! F+-E : 5serata.java )his is the model class to show user data!

A!4! F+-E : ;!dapter.java S%lite dataase helper class that defined user and message specific funtions!)his class contains funtions to insert'update'delete user data! 

A!4! F+-E : Cotroller.java Controller!5ava is very important class 6 its contains all the client side function responsile for userdata flow!

Controller class extends with android!app!Application and defined in the application tag in your AndroidManifest!xml file! Android will create an instance of Controller class and ma3e it availalefor your entire application context! 4ou can get o5ect of your class on any activity ' roadcastreceiver ' service in application context#environment$ y calling Context!getApplicationContext#$method! 

Create MBS- ta)le :

C9E!TE T!;-E +F 8,T E+STS D%cm6usersD '

  DidD it'00( 8,T 85-- !5T,6+8C9EME8T*

  D%cm6re%idD text*

Page 16: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 16/28

  DameD varchar'=( 8,T 85--*

  DemailD varchar'1==( 8,T 85--*

  DimeiD varchar'1( 8,T 85--*

  Dcreated6atD timestamp 8,T 85-- EF!5-TC599E8T6T+MEST!MP*

  P9+M!9B @EB 'DidD(*

  @EB DimeiD 'DimeiD(

( E87+8E#+o; EF!5-T C!9SET#lati0!5T,6+8C9EME8T#0 G

PP F+-E : co"i%.php

PP F+-E : co"i%.php 

To %et 7,,7-E6!P+6@EB see this url : Android Push ?otifications using "oogle Cloud Messaging #"CM$ + PA7) / 

?php 

/**  * Database config variables  */  define("DB_HOST", "localhost"!  define("DB_S#$", "%%%%%%%%"!  define("DB_&'SSO$D", "%%%%%%%%"!  define("DB_D'T'B'S#", "%%%%%%%%"!

  /*  * )oogle lo+d essaging '&- .e  */  define(")OO)0#_'&-_.#1", "'-2aS'34S45S647%1_T8888888"! //&lace o+r )oogle '&- .e 

Page 17: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 17/28

PP F+-E : "uctio.php Contains all functions responsile for gcm registration 6 fetch'insert'delete user data to mys%ldataase! 

PP F+-E: loader.php Include configuration and function file and ma3e dataase connection! loader!php is centrali<edfile and it will include y other php file! 

 /??????????????????????????????????? STEP0 E8????????????????????????????????????/

 

 /??????????????????????????????????? STEP1 ST!9T????????????????????????????????????/

 

STEP 1 : Check device is re%istered "or We)serveror ot.

 

A!4! F+-E : Mai.java 

PP F+-E : validate6device.php )his will validate user from mys%l dataase y IMEI numer posted from Main!5avaif IMEI numer found then send user data as S8? to device with status DupdateD!if IMEI numer not found then send user data as S8? to device with status DinstallD! 

1!.  if device is not registered then send to registration screen and after gcm registration store"CM regI9 and device IMEI to mys%l dataase on server 6 After registration redirect to show all

registered devices screen! 

A!4! F+-E : 9e%ister!ctivit&.java 7egistration screen layout 6 fill name and mail id and send to MainActivity!5ava for "CMregistration! 

Page 18: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 18/28

M- F+-E : activit&6re%ister.xml 

A!4! F+-E : Mai!ctivit&.java 

7egister device for "oogle Cloud Messaging#"CM$ after successfull gcm registartion sendinggcm regI9 to server and store regI9 6name6IMEI in mys%l dataase for further use to sendmessages from gcm!

MainActivity!5ava file is using Controller!5ava methods for registration#see controller classregister#$ and post#$ method$!

Creating a roadcast receiver to get gcm message and show on screen#MainActivity!5ava$! 

Mai!ctivit&.java "ile is usi% re%ister.php "ile to post 7CM ad device data to server. 

PP F+-E : re%ister.php )his file will get post data and store it in mys%l dataase!Send a registration confirm message to device! 

M- F+-E : activit&6mai.xml (sed for MainActivity!5ava file layout! 

gistered devices screen!

 

A!4! F+-E : 7rid4iewExample.java )his file is showing all registered user in a Custom grid view!

Calling userdata!php file from server and get all user data as S8? and show data in a customgridview #see custom grid view example$!

 After grid selection redirect to ShowMessage!5ava file with selected user data! pac9age co:;androide8a:ple;:obilegc:!  i:port 6ava;io;B+ffered$eader!  i:port 6ava;io;-np+tStrea:$eader!  i:port 6ava;io;O+tp+tStrea:riter!  i:port 6ava;net;$0!  i:port 6ava;net;$0onnection!  i:port 6ava;net;$0#ncoder! 

i:port org;6son;<SO='rra!  i:port org;6son;<SO=#8ception!

Page 19: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 19/28

  i:port org;6son;<SO=Ob6ect! 

i:port co:;androide8a:ple;:obilegc:;+sto:)rid'dapter!  i:port android;app;'ctivit!  i:port android;app;&rogressDialog!  i:port android;content;onte8t!  i:port

 android;content;-ntent!  i:port android;os;'sncTas9!

  i:port android;os;B+ndle!  i:port android;>idget;'dapter5ie>!  i:port android;>idget;)rid5ie>!  i:port android;telephon;Telephonanager!  i:port android;+til;0og!  i:port android;vie>;5ie>!  i:port android;>idget;'dapter5ie>;On-te:lic90istener! 

p+blic class )rid5ie>#8a:ple e8tends 'ctivit  

)rid5ie> grid5ie>!

  ontroller aontroller @ n+ll! 

AOverride  p+blic void onreate(B+ndle saved-nstanceState  

s+per;onreate(saved-nstanceState!  setontent5ie>($;lao+t;grid_vie>_android_e8a:ple!

//)et gridvie> ob6ect fro: 8:l file  grid5ie> @ ()rid5ie> find5ie>B-d($;id;grid5ie>4!

 // )et )lobal variable instance

  aontroller @ (ontroller get'pplicationonte8t(!

 // ebServer $e+est $0 to get 'll registered devices

  String server$0 @ onfig;1O$_S#$5#$_$0C"+serdata;php"!

 // se 'sncTas9 e8ec+te ethod To &revent '=$ &roble:

  0ongOperation server$e+est @ ne> 0ongOperation(!server$e+est;e8ec+te(server$0,"rrr","",""!

 

grid5ie>;setOn-te:lic90istener(ne>  On-te:lic90istener(   p+blic void on-te:lic9('dapter5ie>?E parent, 5ie> v,  int position, long id  

String device-#- @ ""!  if(onfig;S#O=D_S-0'TO$

 //a9e it tr+e in O=F-) if o+ >ant to open second si:+t

  // for testing act+all >e are +sing -#- n+:ber to save

 device-#- @ "GGGGGGGGGGGGGG4"!

Page 20: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 20/28

  else

    // )#T -#- =B#$

Telephonanager tanager @ (Telephonanager getBaseonte8  ;getSste:Service(onte8t;T#0#&HO=1_S#$5-#!  device-#- @ tanager;getDevice-d(!

 String +-#- @ aontroller;getserData(position;get-#-(!

  String +=a:e @ aontroller;getserData(position;get=a:e(!

 

// 0a+nch ain 'ctivit  -ntent i @ ne> -ntent(get'pplicationonte8t(, Send&+sh=otifi 

// $egistering +ser on o+r server// Sending registraiton details to ain'ctivit

  i;p+t#8tra("na:e", +=a:e!  i;p+t#8tra("i:ei", +-#-! // Send to  i;p+t#8tra("sendfro:", device-#-!  start'ctivit(i!

 

  !

 

 

// lass >ith e8tends 'sncTas9 class  p+blic class 0ongOperation e8tends 'sncTas9String, 5oid, StringE  

// $e+ired initiali2ation

 //private final Httplient lient @ ne> Defa+ltHttplient(!

  // private ontroller aontroller @ n+ll!  private String #rror @ n+ll!  private &rogressDialog Dialog @ ne> &rogressDialog()rid5ie>#8a:ple  String data @""!

int si2eData @ G!protected void on&re#8ec+te(

  // =OT#I 1o+ can call - #le:ent here;

 //Start &rogress Dialog (essage

 Dialog;setessage(")etting registered +sers ;;"!

  Dialog;sho>(!

 

Page 21: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 21/28

 

 // all after on&re#8ec+te :ethod

  protected String do-nBac9gro+nd(String;;; para:s  

/************ a9e &ost all To eb Server ***********/

  B+ffered$eader reader@n+ll!  String ontent @ ""!  // Send data

tr

 // Defined $0 >here to send data

  $0 +rl @ ne> $0(para:sJGK! 

// Set $e+est para:eter  if(Lpara:sJ4K;e+als(""  data C@"M" C $0#ncoder;encode("data", "TFN3" C   if(Lpara:sJK;e+als(""  data C@"M" C $0#ncoder;encode("data", "TFN3" C   if(Lpara:sJPK;e+als(""  data C@"M" C $0#ncoder;encode("dataP", "TFN3" C   0og;i(")",data!

 // Send &OST data re+est

 $0onnection conn @ +rl;openonnection(!conn;setDoO+tp+t(tr+e!O+tp+tStrea:riter >r @ ne> O+tp+tStrea:riter(conn;getO

  >r;>rite( data !>r;fl+sh(!

// )et the server response

reader @ ne> B+ffered$eader(ne> -np+tStrea:$eader(conn;g  StringB+ilder sb @ ne> StringB+ilder(!  String line @ n+ll!

 // $ead Server $esponse

  >hile((line @ reader;read0ine( L@ n+ll    // 'ppend server response in string  sb;append(line C ""! 

 // 'ppend Server $esponse To ontent String

ontent @ sb;toString(!    catch(#8ception e8    #rror @ e8;getessage(!    finall 

Page 22: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 22/28

  tr 

 reader;close(!

 

 

catch(#8ception e8  

 /*****************************************************/

  ret+rn ontent! 

 protected void on&ost#8ec+te(String ontent

  // =OT#I 1o+ can call - #le:ent here;

 // lose progress dialog

  Dialog;dis:iss(!

 if (#rror L@ n+ll

 

else  

// Sho> $esponse <son On Screen (activit

 /****************** Start &arse $esponse <SO= Data *********

  aontroller;clearserData(!

 <SO=Ob6ect 6son$esponse!

 tr 

 // reates a ne> <SO=Ob6ect >ith na:e/val+e :appings6son$esponse @ ne> <SO=Ob6ect(ontent!

 // $et+rns the val+e :apped b na:e if it e8ists and// $et+rns n+ll other>ise;<SO='rra 6sonain=ode @ 6son$esponse;opt<SO='rra("

 /*********** &rocess each <SO= =ode ************/

 int length<son'rr @ 6sonain=ode;length(!for(int i@G! i length<son'rr! iCC

  /****** )et Ob6ect for each <SO= node;**********  <SO=Ob6ect 6sonhild=ode @ 6sonain=ode;get<SO=O

 /******* Fetch node val+es **********/

  String -#- @ 6sonhild=ode;optString("i:e  String =a:e @ 6sonhild=ode;optString("na:

Page 23: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 23/28

 0og;i(")","NNN"C=a:e!

 serData +serdata @ ne> serData(!

  +serdata;set-#-(-#-!  +serdata;set=a:e(=a:e!

 //'dd +ser data to controller class serData'rr

  aontroller;setserData(+serdata!

 

 

/****************** #nd &arse $esponse <SO= Data *******

 // Set grid adapter to +sto:)rid'daptergrid5ie>;set'dapter(ne> +sto:)rid'dapter(getBaseonte8

 

catch (<SO=#8ception e  

e;printStac9Trace(! 

 

 

 

 

 7rid4iewExample.java "ile used userdata.php to %et all re%istered user devices. 

PP F+-E : userdata.php 7eturn all registered user device data as S8?! ?php

 re+ire_once(Qloader;phpQ!

 Rres+ltsers @ get'llsers(!

  if (Rres+ltsers L@ false  R=+:Ofsers @ :sl_n+:_ro>s(Rres+ltsers!  else  R=+:Ofsers @ G! 

R6sonData  @ arra(!  if (R=+:Ofsers E G

Page 24: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 24/28

 R6sonTe:pData @ arra(!

  R6sonTe:pDataJQi:eiQK @ "'ll"!  R6sonTe:pDataJQregidQK @ "'ll"!  R6sonTe:pDataJQna:eQK @ "Send To 'll"!  R6sonTe:pDataJQerrorQK @ ""!

R6sonDataJK @ R6sonTe:pData! 

>hile (Rro>sers @ :sl_fetch_arra(Rres+ltsers  

R6sonTe:pData @ arra(!  R6sonTe:pDataJQi:eiQK @ Rro>sersJ"i:ei"K!  R6sonTe:pDataJQregidQK @ Rro>sersJ"gc:_regid"K!  R6sonTe:pDataJQna:eQK @ Rro>sersJ"na:e"K!  R6sonTe:pDataJQerrorQK @ ""!

 R6sonDataJK @ R6sonTe:pData!

 

 

  else  R6sonTe:pData @ arra(!  R6sonTe:pDataJQi:eiQK @ "Data not fo+nd;"!  R6sonTe:pDataJQregidQK @ "Data not fo+nd;"!  R6sonTe:pDataJQna:eQK @ "Data not fo+nd;"!  R6sonTe:pDataJQerrorQK @ "n"!  R6sonDataJK @ R6sonTe:pData! 

 Ro+tp+t'rr @ arra(!

  Ro+tp+t'rrJQ'ndroidQK @ R6sonData!

 // #ncode 'rra To <SO= Data

  print_r( 6son_encode(Ro+tp+t'rr!  ?E

 

M- F+-E : %rid6view6adroid6example.xml ?8:l version@"4;G" encoding@"+tfN3"?E  )rid5ie> 8:lnsIandroid@"httpI//sche:as;android;co:/ap9/res/android"  androidIid@"ACid/grid5ie>4"  androidIn+:ol+:ns@"a+to_fit"  androidIgravit@"center"

  androidIcol+:nidth@"4GGdp"  androidIstretchode@"col+:nidth"  androidIlao+t_>idth@"fill_parent"  androidIlao+t_height@"fill_parent" E 

/)rid5ie>E

 

A!4! F+-E : Custom7rid!dapter.java 

Page 25: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 25/28

pac9age co:;androide8a:ple;:obilegc:! i:port android;content;onte8t!i:port android;vie>;0ao+t-nflater!i:port android;vie>;5ie>!i:port android;vie>;5ie>)ro+p!i:port

 android;>idget;Base'dapter!i:port android;>idget;Te8t5ie>! 

p+blic class +sto:)rid'dapter e8tends Base'dapter  

private onte8t conte8t!//private final StringJK grid5al+es!

  private ontroller aontroller! 

//onstr+ctor to initiali2e val+es  p+blic +sto:)rid'dapter(onte8t conte8t, ontroller aontroller   this;conte8t @ conte8t!

  this;aontroller @ aontroller! 

 AOverride

  p+blic int geto+nt(  

// =+:ber of ti:es get5ie> :ethod call depends +pon grid5al+es;length  ret+rn aontroller;getserDataSi2e(!   

AOverride  p+blic Ob6ect get-te:(int position   ret+rn n+ll!   

AOverride  p+blic long get-te:-d(int position  

ret+rn G! 

 

// =+:ber of ti:es get5ie> :ethod call depends +pon grid5al+es;length

 p+blic 5ie> get5ie>(int position, 5ie> convert5ie>, 5ie>)ro+p parent  

//0ao+t-nflator to call e8ternal grid_ite:;8:l file

 0ao+t-nflater inflater @ (0ao+t-nflater conte8t

  ;getSste:Service(onte8t;0'1OT_-=F0'T#$_S#$5-#! 5ie> grid5ie>!

Page 26: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 26/28

 if (convert5ie> @@ n+ll  

grid5ie> @ ne> 5ie>(conte8t! // get lao+t fro: grid_ite:;8:l

  grid5ie> @ inflater;inflate($;lao+t;grid_ite:, n+ll! serData +serdataOb6 @ aontroller;getserData(position!

 // set val+e into te8tvie>

 Te8t5ie> te8t5ie> @ (Te8t5ie> grid5ie>

  ;find5ie>B-d($;id;grid_ite:_label!  te8t5ie>;setTe8t(+serdataOb6;get=a:e(! 

else   grid5ie> @ (5ie> convert5ie>!   

ret+rn grid5ie>! 

 

M- F+-E : %rid6item.xml xml file used in Custom"ridAdapter!5ava file! ?8:l version@"4;G" encoding@"+tfN3"?E  0inear0ao+t 8:lnsIandroid@"httpI//sche:as;android;co:/ap9/res/android"  androidIlao+t_>idth@">rap_content"  androidIlao+t_height@">rap_content"  androidIpadding@"dp"  androidIorientation@"vertical"  E

 -:age5ie>

  androidIid@"ACid/grid_ite:_i:age"  androidIlao+t_>idth@"Gp8"  androidIlao+t_height@"Gp8"  androidIlao+t_:argin$ight@"4Gp8"  androidIsrc@"Adra>able/+ser_th+:b" E  /-:age5ie>E

 0inear0ao+t

  androidIlao+t_>idth@">rap_content"  androidIlao+t_height@">rap_content"

  androidIpadding@"Gdp" androidIorientation@"vertical"E

Te8t5ie>  androidIid@"ACid/grid_ite:_label"  androidIlao+t_>idth@">rap_content"

Page 27: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 27/28

  androidIlao+t_height@">rap_content"  androidIte8t@""  androidIlao+t_:arginTop@"Pp8"  androidIte8tSi2e@"4p8"  androidIte8tStle@"bold"E  /Te8t5ie>E

  Te8t5ie>  androidIid@"ACid/grid_ite:_label_static"  androidIlao+t_>idth@">rap_content"  androidIlao+t_height@">rap_content"  androidIte8t@""  androidIlao+t_:arginTop@"Pp8"  androidIte8tSi2e@"4p8" /E 

/0inear0ao+tE

/0inear0ao+tE

 

 /??????????????????????????????????? STEP1 E8????????????????????????????????????/ 

 /????????????????????????????? STEP2 !8 STEP<ST!9T ???????????????????????????/ 

STEP2. Select user to sed messa%e ad a"ter

selectio show sed messa%e scree.

STEP<. Whe user sedi% messa%e the sedseder +ME+ * sedto +ME+ ad messa%e to we)server * we)server %et user device data 're%+("rom m&sHl data)ase ad call %cm to sedmessa%e to re%+. 

A!4! F+-E : SedPush8oti"icatio.java "et user values got from "ridViewExample!5ava file!

;rite your message!

Send message and values to sendpush!php file!

Page 28: Android Projects 2013

7/27/2019 Android Projects 2013

http://slidepdf.com/reader/full/android-projects-2013 28/28