From 61acda4e1e3810878d88529888cf2ebbfba49405 Mon Sep 17 00:00:00 2001 From: y20k Date: Mon, 19 Feb 2018 09:00:47 +0100 Subject: [PATCH] prevents a crash that occured when system location settings where off (see #32) & shiny new owmdroid library, YAY! --- .../java/org/y20k/trackbook/MainActivity.java | 19 ++++++++++--------- .../trackbook/MainActivityMapFragment.java | 9 ++++++++- .../trackbook/MainActivityTrackFragment.java | 3 +++ build.gradle | 6 +++--- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/y20k/trackbook/MainActivity.java b/app/src/main/java/org/y20k/trackbook/MainActivity.java index e43775a..3eecb80 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivity.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivity.java @@ -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; diff --git a/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java b/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java index d22031f..fc04157 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java @@ -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; + } } diff --git a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java index 8b22ff9..64d56ca 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java @@ -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(); diff --git a/build.gradle b/build.gradle index f39f109..20087fe 100644 --- a/build.gradle +++ b/build.gradle @@ -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' } }