*/
public TravelTimeDemoScreen() {
setTitle("Travel Time Demo");
// Initialize status field
_statusField = new LabelField("");
setStatus(_statusField);
// Free form address entry field
_addressField =
new BasicEditField("Destination: ", "", 500,
TextField.NO_NEWLINE);
add(_addressField);
// Start/end time selection
final VerticalFieldManager vfm = new VerticalFieldManager();
_choiceField =
new ObjectChoiceField("When:", new Object[] { "Depart Now",
"Depart At", "Arrive At" }, 0);
_choiceField.setChangeListener(new FieldChangeListener() {
/**
* @see net.rim.device.api.ui.FieldChangeListener#fieldChanged(Field,
* int)
*/
public void fieldChanged(final Field field, final int context) {
if (context == ChoiceField.CONTEXT_CHANGE_OPTION) {
final int idx = _choiceField.getSelectedIndex();
if (idx == DEPART_NOW) {
_dateField.setEnabled(false);
} else {
_dateField.setEnabled(true);
_dateField.setFocus();
}
}
}
});
vfm.add(_choiceField);
final DateFormat dateFormat =
DateFormat.getInstance(DateFormat.DATETIME_DEFAULT);
_dateField = new DateField("", System.currentTimeMillis(), dateFormat);
_dateField.setEnabled(false);
vfm.add(_dateField);
add(vfm);
// Initialize a button for intitiating a travel time query
final HorizontalFieldManager hfm =
new HorizontalFieldManager(Field.FIELD_HCENTER);
final ButtonField travelButton =
new ButtonField("Get Travel Time", ButtonField.CONSUME_CLICK
| ButtonField.NEVER_DIRTY);
hfm.add(travelButton);
add(hfm);
travelButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(final Field field, final int context) {
findTravelTime();
}
});
// Add labels to display travel time results
_startLabel = new LabelField();
add(_startLabel);
_endLabel = new LabelField();
add(_endLabel);
_elapsedLabel = new LabelField();
add(_elapsedLabel);
_distanceLabel = new LabelField();
add(_distanceLabel);
}