public class TraceMe extends Activity {
private Button updateBtn;
private Button sendBtn;
private LocationManager locationManager;
private TextView utc;
private TextView dataStatus;
private TextView currentLatitude;
private TextView currentLontitude;
private TextView direction;
private TextView speed;
private LocationListener locationlisterner;
public void alert(int titleId) {
new AlertDialog.Builder(this).setIcon(R.drawable.alert_dialog_icon)
.setTitle(titleId).setSingleChoiceItems(R.array.ok, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
}).show();
}
public void alert(String title) {
new AlertDialog.Builder(this).setIcon(R.drawable.alert_dialog_icon)
.setTitle(title).setSingleChoiceItems(R.array.ok, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
dialog.dismiss();
}
}).show();
}
public void updateLocationInfo(Location location) {
if (location == null) {
alert(R.string.location_not_available);
} else {
utc.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(new Date(location.getTime())));
currentLatitude.setText(String.valueOf(location.getLatitude()));
currentLontitude.setText(String.valueOf(location.getLongitude()));
if (location.hasBearing()) {
direction.setText(String.valueOf(location.getBearing()));
} else {
direction.setText(R.string.lbl_unavailable);
}
if (location.hasSpeed()) {
speed.setText(String.valueOf(String
.valueOf(location.getSpeed() * 3.6))
+ TraceMe.this.getApplicationContext().getString(
R.string.lbl_speed_unit));
} else {
speed.setText(R.string.lbl_unavailable);
}
}
}
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(locationlisterner);
}
sassasas
最新推荐文章于 2017-09-11 17:14:22 发布