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:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1' compile 'com.android.support:design:24.2.1'
compile 'org.osmdroid:osmdroid-android:5.2@aar' 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 // get last location from MainActivity Fragment
Location lastLocation = mMainActivityMapFragment.getCurrentBestLocation(); Location lastLocation = mMainActivityMapFragment.getCurrentBestLocation();
// start tracker service if (lastLocation != null) {
Intent intent = new Intent(this, TrackerService.class); // start tracker service
intent.setAction(ACTION_START); Intent intent = new Intent(this, TrackerService.class);
intent.putExtra(EXTRA_LAST_LOCATION, lastLocation); intent.setAction(ACTION_START);
startService(intent); 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 // 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 // app does not have any location fix
mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager); 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 // check if really got a position
updateMyLocationMarker(); if (mCurrentBestLocation != null) {
position = convertToGeoPoint(mCurrentBestLocation);
// inform user about location quality // center map on current position
String locationInfo; mController.setCenter(position);
long locationAge = (SystemClock.elapsedRealtimeNanos() - mCurrentBestLocation.getElapsedRealtimeNanos()) / 1000000;
String locationAgeString = LocationHelper.convertToReadableTime(locationAge, false); // mark user's new location on map and remove last marker
if (locationAgeString == null) { updateMyLocationMarker();
locationAgeString = mActivity.getString(R.string.toast_message_last_location_age_one_hour);
// 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 // CASE DEFAULT
default: default:
@ -374,6 +384,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
/* Removes track crumbs from map */ /* Removes track crumbs from map */
public void clearMap() { public void clearMap() {
// TODO clear map or clear intent
if (mTrackOverlay != null) { if (mTrackOverlay != null) {
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show(); Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
mMapView.getOverlays().remove(mTrackOverlay); mMapView.getOverlays().remove(mTrackOverlay);

View file

@ -16,8 +16,8 @@
<string name="tab_last_track">LETZTE AUFZEICHNUNG</string> <string name="tab_last_track">LETZTE AUFZEICHNUNG</string>
<!-- notification --> <!-- notification -->
<string name="notification_title_trackbook_not_running">Trackbook ist aktiv</string> <string name="notification_title_trackbook_not_running">Trackbook ist inaktiv</string>
<string name="notification_title_trackbook_running">Trackbook ist inaktiv</string> <string name="notification_title_trackbook_running">Trackbook ist aktiv</string>
<string name="notification_stop">Stopp</string> <string name="notification_stop">Stopp</string>
<string name="notification_swipe_to_clear_map">(Ausblenden setzt Kartenansicht zurück)</string> <string name="notification_swipe_to_clear_map">(Ausblenden setzt Kartenansicht zurück)</string>
<string name="notification_content_duration">Dauer</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_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_location_offline">Standortdienste sind deaktiviert. Trackbook kann nicht aufzeichnen.</string>
<string name="toast_message_acquiring_location">Suche aktuellen Standort.</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_last_location">Letzte Position:</string>
<string name="toast_message_clear_map">Kartenansicht wird zurückgesetzt</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> <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_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_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_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_last_location">Last location:</string>
<string name="toast_message_clear_map">Clearing map.</string> <string name="toast_message_clear_map">Clearing map.</string>
<string name="toast_message_last_location_age_one_hour">over one hour</string> <string name="toast_message_last_location_age_one_hour">over one hour</string>