prevents a crash that occured when system location settings where off (see #32) & shiny new owmdroid library, YAY!

This commit is contained in:
y20k 2018-02-19 09:00:47 +01:00
parent c0acbb5ec8
commit 61acda4e1e
4 changed files with 24 additions and 13 deletions

View file

@ -50,6 +50,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import org.osmdroid.config.Configuration;
import org.y20k.trackbook.helpers.DialogHelper;
import org.y20k.trackbook.helpers.LogHelper;
import org.y20k.trackbook.helpers.TrackbookKeys;
@ -121,7 +122,7 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
}
// set user agent to prevent getting banned from the osm servers
org.osmdroid.tileprovider.constants.OpenStreetMapTileProviderConstants.setUserAgentValue(BuildConfig.APPLICATION_ID);
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);
// set up main layout
setupLayout();
@ -454,19 +455,20 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
switch (mFloatingActionButtonState) {
case FAB_STATE_DEFAULT:
// show snackbar
Snackbar.make(view, R.string.snackbar_message_tracking_started, Snackbar.LENGTH_SHORT).setAction("Action", null).show();
// change state
mTrackerServiceRunning = true;
mFloatingActionButtonState = FAB_STATE_RECORDING;
setFloatingActionButtonState();
// get last location from MainActivity Fragment // todo check -> may produce NullPointerException
MainActivityMapFragment mainActivityMapFragment = (MainActivityMapFragment) mSectionsPagerAdapter.getFragment(FRAGMENT_ID_MAP);
Location lastLocation = mainActivityMapFragment.getCurrentBestLocation();
if (lastLocation != null) {
// change state
mTrackerServiceRunning = true;
mFloatingActionButtonState = FAB_STATE_RECORDING;
setFloatingActionButtonState();
// show snackbar
Snackbar.make(view, R.string.snackbar_message_tracking_started, Snackbar.LENGTH_SHORT).setAction("Action", null).show();
// start tracker service
startTrackerService(ACTION_START, lastLocation);
@ -474,7 +476,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
Toast.makeText(this, getString(R.string.toast_message_location_services_not_ready), Toast.LENGTH_LONG).show();
// change state back
mTrackerServiceRunning = false;
setFloatingActionButtonState();
}
break;

View file

@ -171,6 +171,9 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
// add multi-touch capability
mMapView.setMultiTouchControls(true);
// disable default zoom controls
mMapView.setBuiltInZoomControls(false);
// add compass to map
CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
compassOverlay.enableCompass();
@ -359,7 +362,11 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
/* Getter for current best location */
public Location getCurrentBestLocation() {
return mCurrentBestLocation;
if (mLocationSystemSetting) {
return mCurrentBestLocation;
} else {
return null;
}
}

View file

@ -175,6 +175,9 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O
// add multi-touch capability
mMapView.setMultiTouchControls(true);
// disable default zoom controls
mMapView.setBuiltInZoomControls(false);
// add compass to map
CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
compassOverlay.enableCompass();

View file

@ -20,8 +20,8 @@ allprojects {
}
project.ext {
applicationId = 'org.y20k.trackbook'
versionCode = 20
versionName = '1.1.4'
versionCode = 21
versionName = '1.1.5'
minSdkVersion = 22
compileSdkVersion = 27
targetSdkVersion = 27
@ -29,7 +29,7 @@ allprojects {
supportLibraryVersion = '27.0.2'
constraintLayoutVersion = '1.1.0-beta4'
osmdroidVersion = '5.6.5'
osmdroidVersion = '6.0.1'
gsonVersion = '2.8.2'
}
}