Listing 1222 closejobphp

require('utils.php');

$data = file_get_contents('php://input'); $j obid = $_GET['jobid'] ;

$f = fopen("~/pathtofiles/sigs/".$j obid.".jpg","w");

print (closeJob ($_GET ['jobid'])) ; <-Q Close the job

Write out the image data

Write out the image data

The POST-ed image data is read via the file_get_contents() function O. The secret is the special identifier of php://input. This is the equivalent of a binary read. This data is read into a variable named $data. The jobid is extracted from the query String Q. The image file is written out to a directory that contains signatures as JPEG files, keyed by the jobid as part of the filename Q. When a job has been closed and the signature is requested by the Android application, it is this file that is requested in the Android browser. The closeJob function Q (implemented in utils.php) updates the database to mark the selected job as CLOSED.

That wraps up the review of the source code for this chapter's sample application.

This chapter certainly was not short, but hopefully it was worth the read. The intent of the sample application was to tie together many things learned in previous chapters into a composite application that has real-world applicability to the kind of uses an Android device is capable of bringing to fruition. Is this sample application production ready? Of course not, but almost! That is, as they say, an exercise for the reader.

Starting with a simple splash screen, this application demonstrated the use of Handlers and displaying images stored in the resources section of an Android project. Moving along to the main screen, a simple UI led to different activities useful for launching various aspects of the realistic application.

Communications with the server downloaded XML data, while showing the user a ProgressDialog along the way. Once the data stream commenced, the data was parsed by the SAX XML parser, using a custom Handler to navigate the XML document.

Managing jobs in a ListView was demonstrated to be as easy as tapping on the desired job in the list. The next screen, the ShowJobs Activity, allowed even more functionality with the ability to jump to a Map showing the location of the job and even a specific product information page customized to this job. Both of those functions were as simple as preparing an Intent and a call to startActivity().

Once the mobile technician completed the job in the field, the CloseJob Activity brought the touch-screen elements into play by allowing the user to capture a signature from his customer. That digital signature was then stamped with additional, contextual information and transmitted over the internet to prove the job was done! Jumping back to what you learned earlier, it would be straightforward to add location-based data to further authenticate the captured signature.

The chapter wrapped up with a quick survey of the server-side components to demonstrate some of the steps necessary to tie the mobile and the server sides together.

0 0

Post a comment