use of net.rim.device.api.ui.component.EditField in project Samples-for-Java by blackberry.
the class TestScreen method fieldChanged.
public void fieldChanged(Field field, int context) {
if (simpleProvider == null) {
try {
simpleProvider = new SimpleLocationProvider(getMode(modeField.getSelectedIndex()));
} catch (final Exception le) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(le.getMessage());
}
});
}
if (simpleProvider != null) {
simpleProvider.setGeolocationTimeout(geoTimeoutField.getSelectedValue());
simpleProvider.setGPSTimeout(gpsTimeoutField.getSelectedValue());
simpleProvider.setRetryFactor(retryFactorField.getSelectedValue());
simpleProvider.setTrackignInterval(trackingIntervalField.getSelectedValue());
simpleProvider.setMaxRetryDelay(maxRetryDelayField.getSelectedValue());
}
}
if (field == startTrackingField) {
if (simpleProvider != null) {
simpleProvider.addSimpleLocationListener(this, trackingIntervalField.getSelectedValue());
}
} else if (field == stopTrackingField) {
if (simpleProvider != null) {
simpleProvider.removeSimpleLocationListener();
}
} else if (field == restartField) {
if (simpleProvider != null) {
try {
simpleProvider.restart();
} catch (IllegalStateException ise) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("Tracking session must be in progress. Please select Start Tracking.");
}
});
}
}
} else if (field == modeField) {
if (simpleProvider != null) {
try {
simpleProvider.setMode(getMode(modeField.getSelectedIndex()));
} catch (final LocationException le) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(le.toString());
}
});
}
}
} else if (field == trackingIntervalField) {
if (simpleProvider != null) {
simpleProvider.setTrackignInterval(trackingIntervalField.getSelectedValue());
}
} else if (field == gpsTimeoutField) {
if (simpleProvider != null) {
simpleProvider.setGPSTimeout(gpsTimeoutField.getSelectedValue());
}
} else if (field == geoTimeoutField) {
if (simpleProvider != null) {
simpleProvider.setGPSTimeout(geoTimeoutField.getSelectedValue());
}
} else if (field == retryFactorField) {
if (simpleProvider != null) {
simpleProvider.setRetryFactor(retryFactorField.getSelectedValue());
}
} else if (field == maxRetryDelayField) {
if (simpleProvider != null) {
simpleProvider.setMaxRetryDelay(maxRetryDelayField.getSelectedValue());
}
} else if (field == getSingleLocationField) {
new Thread() {
public void run() {
location = simpleProvider.getLocation(30);
if (location != null && location.isValid()) {
locationField.setText(location.getQualifiedCoordinates().getLatitude() + ", " + location.getQualifiedCoordinates().getLongitude());
statusField.setText("Obtained single location.");
} else {
statusField.setText("Failed to obtain location!");
}
}
}.start();
} else if (field == getLastLocationField) {
if (simpleProvider != null) {
location = simpleProvider.getLastKnownLocation();
if (location != null && location.isValid()) {
locationField.setText(location.getQualifiedCoordinates().getLatitude() + ", " + location.getQualifiedCoordinates().getLongitude());
statusField.setText("Obtained last known location.");
} else {
statusField.setText("Last known location not available! Please acquire a single location or start a tracking session first.");
}
} else {
statusField.setText("Last known location not available! Please acquire a single location or a tracking session first.");
}
} else if (field == satellitesField) {
if (location != null) {
final PopupScreen satPopup = new PopupScreen(new VerticalFieldManager()) {
protected boolean keyDown(int keycode, int time) {
int key = Keypad.key(keycode);
if (key == Keypad.KEY_ESCAPE) {
Screen screen = getScreen();
UiApplication.getUiApplication().popScreen(screen);
}
return true;
}
};
EditField satField = new EditField("", "");
satPopup.add(satField);
StringBuffer buffer = new StringBuffer();
Enumeration satEnum = location.getSatelliteInfo();
if (satEnum != null && satEnum.hasMoreElements()) {
buffer.append("ID\tAzimuth\tElevation\tSignal\n");
while (satEnum.hasMoreElements()) {
SatelliteInfo satInfo = (SatelliteInfo) satEnum.nextElement();
if (satInfo != null && satInfo.isValid()) {
buffer.append(satInfo.getId() + "\t" + satInfo.getAzimuth() + "\t" + satInfo.getElevation() + "\t" + satInfo.getSignalQuality() + "\n");
}
}
satField.setText(buffer.toString());
} else {
buffer.append("No satellite information available for current location fix");
satField.setText(buffer.toString());
}
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(satPopup);
}
});
} else {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("No location fix available..");
}
});
}
}
}
Aggregations