catches a crash that could happen when a location fix was acquired too slow (see #3)

This commit is contained in:
y20k 2016-09-26 13:43:26 +02:00
parent 403cb3f134
commit 60a5ba5b5a
5 changed files with 43 additions and 22 deletions

View file

@ -26,5 +26,5 @@ dependencies {
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'org.osmdroid:osmdroid-android:5.2@aar'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.code.gson:gson:2.7'
}

View file

@ -361,11 +361,19 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
// get last location from MainActivity Fragment
Location lastLocation = mMainActivityMapFragment.getCurrentBestLocation();
// start tracker service
Intent intent = new Intent(this, TrackerService.class);
intent.setAction(ACTION_START);
intent.putExtra(EXTRA_LAST_LOCATION, lastLocation);
startService(intent);
if (lastLocation != null) {
// start tracker service
Intent intent = new Intent(this, TrackerService.class);
intent.setAction(ACTION_START);
intent.putExtra(EXTRA_LAST_LOCATION, lastLocation);
startService(intent);
} else {
Toast.makeText(this, getString(R.string.toast_message_location_services_not_ready), Toast.LENGTH_LONG).show();
// change state back
mTrackerServiceRunning = false;
setFloatingActionButtonState();
}
}
// update tracking state in MainActivityMapFragment

View file

@ -299,25 +299,35 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
// app does not have any location fix
mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager);
}
position = convertToGeoPoint(mCurrentBestLocation);
// center map on current position
mController.setCenter(position);
// mark user's new location on map and remove last marker
updateMyLocationMarker();
// check if really got a position
if (mCurrentBestLocation != null) {
position = convertToGeoPoint(mCurrentBestLocation);
// inform user about location quality
String locationInfo;
long locationAge = (SystemClock.elapsedRealtimeNanos() - mCurrentBestLocation.getElapsedRealtimeNanos()) / 1000000;
String locationAgeString = LocationHelper.convertToReadableTime(locationAge, false);
if (locationAgeString == null) {
locationAgeString = mActivity.getString(R.string.toast_message_last_location_age_one_hour);
// center map on current position
mController.setCenter(position);
// mark user's new location on map and remove last marker
updateMyLocationMarker();
// inform user about location quality
String locationInfo;
long locationAge = (SystemClock.elapsedRealtimeNanos() - mCurrentBestLocation.getElapsedRealtimeNanos()) / 1000000;
String locationAgeString = LocationHelper.convertToReadableTime(locationAge, false);
if (locationAgeString == null) {
locationAgeString = mActivity.getString(R.string.toast_message_last_location_age_one_hour);
}
locationInfo = " " + locationAgeString + " | " + mCurrentBestLocation.getProvider();
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_last_location) + locationInfo, Toast.LENGTH_LONG).show();
return true;
} else {
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_location_services_not_ready), Toast.LENGTH_LONG).show();
return false;
}
locationInfo = " " + locationAgeString + " | " + mCurrentBestLocation.getProvider();
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_last_location) + locationInfo, Toast.LENGTH_LONG).show();
return true;
// CASE DEFAULT
default:
@ -374,6 +384,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
/* Removes track crumbs from map */
public void clearMap() {
// TODO clear map or clear intent
if (mTrackOverlay != null) {
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
mMapView.getOverlays().remove(mTrackOverlay);

View file

@ -16,8 +16,8 @@
<string name="tab_last_track">LETZTE AUFZEICHNUNG</string>
<!-- notification -->
<string name="notification_title_trackbook_not_running">Trackbook ist aktiv</string>
<string name="notification_title_trackbook_running">Trackbook ist inaktiv</string>
<string name="notification_title_trackbook_not_running">Trackbook ist inaktiv</string>
<string name="notification_title_trackbook_running">Trackbook ist aktiv</string>
<string name="notification_stop">Stopp</string>
<string name="notification_swipe_to_clear_map">(Ausblenden setzt Kartenansicht zurück)</string>
<string name="notification_content_duration">Dauer</string>
@ -34,6 +34,7 @@
<string name="toast_message_no_external_storage">Zugriff auf den externen Speicher verweigert.</string>
<string name="toast_message_location_offline">Standortdienste sind deaktiviert. Trackbook kann nicht aufzeichnen.</string>
<string name="toast_message_acquiring_location">Suche aktuellen Standort.</string>
<string name="toast_message_location_services_not_ready">Standortdienste noch nicht bereit. Bitte erneut versuchen.</string>
<string name="toast_message_last_location">Letzte Position:</string>
<string name="toast_message_clear_map">Kartenansicht wird zurückgesetzt</string>
<string name="toast_message_last_location_age_one_hour">über eine Stunde</string>

View file

@ -34,6 +34,7 @@
<string name="toast_message_no_external_storage">Unable to access external storage.</string>
<string name="toast_message_location_offline">Location is turned off. Trackbook will not work.</string>
<string name="toast_message_acquiring_location">Acquiring current location.</string>
<string name="toast_message_location_services_not_ready">Location services not ready. Please retry.</string>
<string name="toast_message_last_location">Last location:</string>
<string name="toast_message_clear_map">Clearing map.</string>
<string name="toast_message_last_location_age_one_hour">over one hour</string>