Show GPSForm.java syntax highlighted
/*
* Copyright (c) 2004
* Helsinki Institute of Physics
* see LICENSE file for details
*
* GPSForm.java
* Created on Dec 15, 2004
*/
package fi.hip.gb.client;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;
import fi.hip.gb.bluetooth.NmeaService;
import fi.hip.gb.bluetooth.util.Properties;
import fi.hip.gb.midlet.core.LiteResult;
/**
* Shows coordinates from the GPS on the screen.
*
* @author Juho Karppinen
*/
class GPSForm extends GenericResultForm {
/**
* Constructs a new textual result observer.
*
* @param resultFile result to be shown
*/
public GPSForm(LiteResult result) {
super(result.getName(), result);
// we use MIDP2 related methods if the device supports it
boolean midp2 = System.getProperty("microedition.profiles").startsWith("MIDP-2");
StringItem item = new StringItem("Fix: ", "");
if(midp2) item.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.append(item);
item = new StringItem("Latitude ", "");
if(midp2) item.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.append(item);
item = new StringItem("Longitude: ", "");
if(midp2) item.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.append(item);
item = new StringItem("Speed: ", "");
if(midp2) item.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.append(item);
item = new StringItem("Heading: ", "");
if(midp2) item.setLayout(Item.LAYOUT_NEWLINE_AFTER);
this.append(item);
this.append(item);
//append(new StringItem("Data: ", result.readContent()));
}
public void update(LiteResult res) {
this.result = res;
Properties prop = (Properties)res.readObject();
if(prop.getProperty("fix").equals("1"))
((StringItem)get(0)).setText(prop.getProperty(NmeaService.FIX));
else
((StringItem)get(0)).setText("no");
((StringItem)get(1)).setText(prop.getProperty(NmeaService.LATITUDE_DEG) + "d "
+ prop.getProperty(NmeaService.LATITUDE_MIN) + "m "
+ prop.getProperty(NmeaService.LATITUDE_SEC) + "s "
+ prop.getProperty(NmeaService.LATITUDE_NS));
((StringItem)get(2)).setText(prop.getProperty(NmeaService.LONGITUDE_DEG) + "d "
+ prop.getProperty(NmeaService.LONGITUDE_MIN) + "m "
+ prop.getProperty(NmeaService.LONGITUDE_SEC) + "s "
+ prop.getProperty(NmeaService.LONGITUDE_EW));
((StringItem)get(3)).setText(prop.getProperty(NmeaService.SPEED));
((StringItem)get(4)).setText(prop.getProperty(NmeaService.HEADING));
((StringItem)get(5)).setText(prop.getProperty(NmeaService.DATETIME));
}
public void commandAction(Command c, Displayable disp) {
if ((c.getCommandType() == Command.BACK)) {
MIDui.back(true);
}
}
}
See more files for this project here