From df8e5ef0fd527ba65637b3518f1467785b7aed44 Mon Sep 17 00:00:00 2001 From: y20k Date: Wed, 28 Nov 2018 09:21:10 +0100 Subject: [PATCH] null check on vibration invocation & track size check --- app/src/main/java/org/y20k/trackbook/MainActivity.java | 4 +++- .../java/org/y20k/trackbook/MainActivityTrackFragment.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/y20k/trackbook/MainActivity.java b/app/src/main/java/org/y20k/trackbook/MainActivity.java index e75c892..1075e75 100755 --- a/app/src/main/java/org/y20k/trackbook/MainActivity.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivity.java @@ -721,8 +721,10 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys { Toast.makeText(this, stringResource, Toast.LENGTH_LONG).show(); // vibrate 50 milliseconds Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); - v.vibrate(50); + if (v != null) { + v.vibrate(50); // v.vibrate(VibrationEffect.createOneShot(50, DEFAULT_AMPLITUDE)); // todo check if there is a support library vibrator + } } diff --git a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java index 6d13f83..da4269a 100755 --- a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java @@ -362,7 +362,7 @@ public class MainActivityTrackFragment extends Fragment implements AdapterView.O private void displayTrack() { GeoPoint position; - if (mTrack != null) { + if (mTrack != null && mTrack.getSize() > 0) { // set end of track as position Location lastLocation = mTrack.getWayPointLocation(mTrack.getSize() -1); position = new GeoPoint(lastLocation.getLatitude(), lastLocation.getLongitude());