teaching machines

Exportable Machine List

October 19, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

This app is for the on-the-go business man looking to log all the printing devices at location and be able to export his results so that they can manipulate the data in excel.  My main activity gets the database if there is one and then populates the screen with a list of items that are currently in the database.  There is an option to add a new machine where you specify the name of the machine.  The machine is then added to the list.   Along with the name of the machine, there is also a picture of the machine type.  This image changes depending on why type the machine is.  Printers, copiers and fax machines each have their own image.

From the list of machines that are pulled from the database or added, you can click on a machine and then edit it.  The intent then switches to a screen where you can specify the type, pages per minute and year of the machine.  There is then a save button below the fields to save your changes.  If changes have been made but not saved and the user attempts to go back, the user is prompted with a dialog box for them to save before continuing.

From the main screen, you can choose to export the database to a .csv file.  This .csv file is stored on the SD card.  To do this I used a simple file stream to make and open the file.  Then I cycled through the items in the database a wrote them to the file(code below).  This file can then be pulled off the SD and sent as an attachment in an email or transferred directly to a computer where it can be opened by Excel.

FileOutputStream out = new FileOutputStream(file.getAbsolutePath());
out.write("Model, Type, PPM, Year \n".getBytes()); //*** Print header for the file
			
	//*** Cycle through the machines and write them to the export file ***//
	Machine[] machines = db.getMachines();
	for (Machine machine : machines) {
	     String exportString = machine.getName() + ", " + machine.getType() + ", " + 
			           machine.getPpm()  + ", " + machine.getYear() + "\n";

	     out.write(exportString.getBytes());
	}
	out.close(); //*** Close stream