Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
locationlab;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
android.app.ListActivity;
android.content.Context;
android.location.Location;
android.location.LocationListener;
android.location.LocationManager;
android.os.Bundle;
android.util.Log;
android.view.Menu;
android.view.MenuInflater;
android.view.MenuItem;
android.view.View;
android.view.View.OnClickListener;
android.widget.ListView;
android.widget.Toast;
Location mLastLocationReading;
PlaceViewAdapter mAdapter;
LocationManager mLocationManager;
boolean mMockLocationOn = false;
}
@Override
protected void onPause() {
// TODO - unregister for location updates
mLocationManager.removeUpdates(this);
shutdownMockLocationManager();
super.onPause();
}
// Callback method used by PlaceDownloaderTask
public void addNewPlace(PlaceRecord place) {
Log.i(TAG, "Entered addNewPlace()");
// TODO - Attempt to add place to the adapter, considering the following
cases
// A PlaceBadge for this location already exists. In this case issue a T
oast message
// with the text - "You already have this location badge." Use the Place
Record
// class' intersects() method to determine whether a PlaceBadge already
exists
// for a given location. Do not add the PlaceBadge to the adapter
if (mAdapter.getList().contains(place)) {
Toast.makeText(this, "You already have this location badge.", Toast.
LENGTH_SHORT).show();
return;
}
//
//
//
if
The place is null. In this case issue a Toast message with the text
"PlaceBadge could not be acquired"
Do not add the PlaceBadge to the adapter
(place == null) {
Toast.makeText(this, "PlaceBadge could not be acquired", Toast.LENGT
H_SHORT).show();
return;
}
//
//
//
if
The place has no country name. In this case issue a Toast message
with the text - "There is no country at this location".
Do not add the PlaceBadge to the adapter
(place.getCountryName().isEmpty()) {
Toast.makeText(this, "There is no country at this location", Toast.L
ENGTH_SHORT).show();
return;
}
// Otherwise - add the PlaceBadge to the adapter
mAdapter.add(place);
}
// LocationListener methods
@Override
public void onLocationChanged(Location currentLocation) {
// TODO - Update last location considering the following cases.
// 1) If there is no last location, set the last location to the current
//
//
//
//
//
location.
2) If the current location is older than the last location, ignore
the current location
3) If the current location is newer than the last locations, keep the
current location.