From 542660c0c556b7728e41582a81c415dfda62913a Mon Sep 17 00:00:00 2001 From: y20k Date: Thu, 19 Jan 2017 13:36:49 +0100 Subject: [PATCH] (1) Updated copyright info (2017, yay) (2) moved the temp file loading process to a later stage (onResume) of the app start --- LICENSE.md | 4 +- README.md | 2 +- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 4 +- .../org/y20k/trackbook/InfosheetActivity.java | 9 ++- .../java/org/y20k/trackbook/MainActivity.java | 2 +- .../trackbook/MainActivityMapFragment.java | 70 +++++++++++-------- .../trackbook/MainActivityTrackFragment.java | 6 +- .../org/y20k/trackbook/TrackerService.java | 9 ++- .../java/org/y20k/trackbook/core/Track.java | 2 +- .../org/y20k/trackbook/core/WayPoint.java | 2 +- .../trackbook/helpers/LocationHelper.java | 2 +- .../org/y20k/trackbook/helpers/LogHelper.java | 2 +- .../org/y20k/trackbook/helpers/MapHelper.java | 2 +- .../trackbook/helpers/NotificationHelper.java | 2 +- .../y20k/trackbook/helpers/StorageHelper.java | 18 ++--- .../y20k/trackbook/helpers/TrackbookKeys.java | 6 +- .../layout/DodgeAbleLayoutBehavior.java | 2 +- .../layout/NonSwipeableViewPager.java | 2 +- 19 files changed, 83 insertions(+), 66 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 64cb8ea..1ab67e2 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,8 +1,8 @@ The MIT License (MIT) ===================== -Copyright (c) 2016 - Y20K.org ------------------------------ +Copyright (c) 2016-17 - Y20K.org +-------------------------------- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 16e53bd..be2b808 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Trackbook - Movement Recorder for Android Trackbook is a bare bones app for recording your movements. Trackbook is great for hiking, vacation or workout. Once started it traces your movements on a map. The map data is provided by [OpenStreetMap (OSM)](https://www.openstreetmap.org/). -Trackbook is free software. It is published under the [MIT open source license](https://opensource.org/licenses/MIT). Trackbook uses [osmdroid](https://github.com/osmdroid/osmdroid) to display the map, which is also free software published under the [Apache License](https://github.com/osmdroid/osmdroid/blob/master/LICENSE). Want to help? Please check out the notes in [CONTRIBUTE.md](https://github.com/y20k/transistor/blob/master/CONTRIBUTE.md) first. +Trackbook is free software. It is published under the [MIT open source license](https://opensource.org/licenses/MIT). Trackbook uses [osmdroid](https://github.com/osmdroid/osmdroid) to display the map, which is also free software published under the [Apache License](https://github.com/osmdroid/osmdroid/blob/master/LICENSE). Want to help? Please check out the notes in [CONTRIBUTE.md](https://github.com/y20k/trackbook/blob/master/CONTRIBUTE.md) first. Install Trackbook ----------------- diff --git a/app/build.gradle b/app/build.gradle index dc58494..3bd414c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,10 +22,9 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:25.1.0' compile 'com.android.support:design:25.1.0' compile 'com.android.support:cardview-v7:25.1.0' - compile 'org.osmdroid:osmdroid-android:5.6.2' + compile 'org.osmdroid:osmdroid-android:5.6.3' compile 'com.google.code.gson:gson:2.8.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e54b915..3518a30 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,8 +54,8 @@ android:name=".TrackerService" android:exported="false"> - - + + diff --git a/app/src/main/java/org/y20k/trackbook/InfosheetActivity.java b/app/src/main/java/org/y20k/trackbook/InfosheetActivity.java index 1beb1e1..6136ba8 100644 --- a/app/src/main/java/org/y20k/trackbook/InfosheetActivity.java +++ b/app/src/main/java/org/y20k/trackbook/InfosheetActivity.java @@ -1,14 +1,17 @@ /** * InfosheetActivity.java * Implements the app's infosheet activity - * The infosheet activity sets up infosheet screens for "About" and "How to" + * The infosheet activity sets up infosheet screens for "About" * * This file is part of - * TRANSISTOR - Radio App for Android + * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2015-16 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT + * + * Trackbook uses osmdroid - OpenStreetMap-Tools for Android + * https://github.com/osmdroid/osmdroid */ diff --git a/app/src/main/java/org/y20k/trackbook/MainActivity.java b/app/src/main/java/org/y20k/trackbook/MainActivity.java index 6fd7e4d..353e2c9 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivity.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivity.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java b/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java index 0882545..14ab1ac 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivityMapFragment.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * @@ -75,6 +75,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { private SettingsContentObserver mSettingsContentObserver; private MapView mMapView; private IMapController mController; + private StorageHelper mStorageHelper; private LocationManager mLocationManager; private LocationListener mGPSListener; private LocationListener mNetworkListener; @@ -113,6 +114,9 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { // mTrackerServiceRunning = savedInstanceState.getBoolean(INSTANCE_TRACKING_STATE, false); } + // create storage helper + mStorageHelper = new StorageHelper(mActivity); + // acquire reference to Location Manager mLocationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE); @@ -193,20 +197,25 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { mFirstStart = false; } - // restore track - StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP); - if (storageHelper.tempFileExists()) { - // load track from temp file if it exists - LoadTempTrackAsyncHelper loadTempTrackAsyncHelper = new LoadTempTrackAsyncHelper(); - loadTempTrackAsyncHelper.execute(); - LogHelper.v(LOG_TAG, "MapFragment: getting track from temp file."); - } else if (savedInstanceState != null) { - // load track from saved instance +// // restore track +// StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP); +// if (storageHelper.tempFileExists()) { +// // load track from temp file if it exists +// LoadTempTrackAsyncHelper loadTempTrackAsyncHelper = new LoadTempTrackAsyncHelper(); +// loadTempTrackAsyncHelper.execute(); +// LogHelper.v(LOG_TAG, "MapFragment: getting track from temp file."); +// } else if (savedInstanceState != null) { +// // load track from saved instance +// mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_MAIN_MAP); +// if (mTrack != null) { +// drawTrackOverlay(mTrack); +// LogHelper.v(LOG_TAG, "MapFragment: got track from saved instance."); +// } +// } + + // load track from saved instance + if (savedInstanceState != null) { mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_MAIN_MAP); - if (mTrack != null) { - drawTrackOverlay(mTrack); - LogHelper.v(LOG_TAG, "MapFragment: got track from saved instance."); - } } // mark user's location on map @@ -226,22 +235,30 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { // set visibility mFragmentVisible = true; - // handle incoming intent (from notification) -// handleIncomingIntent(); // todo remove - // load state of tracker service - see if anything changed loadTrackerServiceState(mActivity); - // request an updated track recording from service - if TrackerService is running + // CASE 1: recording active if (mTrackerServiceRunning) { + // request an updated track recording from service Intent i = new Intent(); i.setAction(ACTION_TRACK_REQUEST); LocalBroadcastManager.getInstance(mActivity).sendBroadcast(i); + LogHelper.v(LOG_TAG, "MapFragment: requesting updated track from service."); } - // draw track on map - if available - if (mTrack != null) { + // CASE 2: recording stopped - temp file exists + else if (mStorageHelper.tempFileExists()) { + // load track from temp file if it exists + LoadTempTrackAsyncHelper loadTempTrackAsyncHelper = new LoadTempTrackAsyncHelper(); + loadTempTrackAsyncHelper.execute(); + LogHelper.v(LOG_TAG, "MapFragment: getting track from temp file."); + + // CASE 3: not recording and no temp file + } else if (mTrack != null) { + // just draw existing track data drawTrackOverlay(mTrack); + LogHelper.v(LOG_TAG, "MapFragment: got track from saved instance."); } // show/hide the location off notification bar @@ -421,8 +438,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { } else { // clear track object and delete temp file mTrack = null; - StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP); - storageHelper.deleteTempFile(); + mStorageHelper.deleteTempFile(); } // // save track state @@ -705,8 +721,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { protected Void doInBackground(Void... voids) { LogHelper.v(LOG_TAG, "Saving track object in background."); // save track object - StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TRACK); - storageHelper.saveTrack(mTrack); + mStorageHelper.saveTrack(mTrack, FILETYPE_TRACK); return null; } @@ -731,14 +746,11 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { */ private class LoadTempTrackAsyncHelper extends AsyncTask { - StorageHelper storageHelper; - @Override protected Void doInBackground(Void... voids) { LogHelper.v(LOG_TAG, "Loading temporary track object in background."); // load track object - storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP); - mTrack = storageHelper.loadTrack(); + mTrack = mStorageHelper.loadTrack(FILETYPE_TEMP); return null; } @@ -753,7 +765,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys { } // delete temp file - storageHelper.deleteTempFile(); + mStorageHelper.deleteTempFile(); } } diff --git a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java index 4a0fa72..ffb1ee6 100644 --- a/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java +++ b/app/src/main/java/org/y20k/trackbook/MainActivityTrackFragment.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * @@ -318,8 +318,8 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys protected Void doInBackground(Void... voids) { LogHelper.v(LOG_TAG, "Loading track object in background."); // load track object - StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TRACK); - mTrack = storageHelper.loadTrack(); + StorageHelper storageHelper = new StorageHelper(mActivity); + mTrack = storageHelper.loadTrack(FILETYPE_TRACK); return null; } diff --git a/app/src/main/java/org/y20k/trackbook/TrackerService.java b/app/src/main/java/org/y20k/trackbook/TrackerService.java index 15c2655..01d332c 100644 --- a/app/src/main/java/org/y20k/trackbook/TrackerService.java +++ b/app/src/main/java/org/y20k/trackbook/TrackerService.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * @@ -250,6 +250,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven // stop timer mTimer.cancel(); + // TODO test for race condition + sendTrackUpdate(); + // save a temp file in case the activity has been killed SaveTempTrackAsyncHelper saveTempTrackAsyncHelper = new SaveTempTrackAsyncHelper(); saveTempTrackAsyncHelper.execute(); @@ -420,8 +423,8 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven protected Void doInBackground(Void... voids) { LogHelper.v(LOG_TAG, "Saving temporary track object in background."); // save track object - StorageHelper storageHelper = new StorageHelper(TrackerService.this, FILETYPE_TEMP); - storageHelper.saveTrack(mTrack); + StorageHelper storageHelper = new StorageHelper(TrackerService.this); + storageHelper.saveTrack(mTrack, FILETYPE_TEMP); return null; } diff --git a/app/src/main/java/org/y20k/trackbook/core/Track.java b/app/src/main/java/org/y20k/trackbook/core/Track.java index cb89529..927e640 100644 --- a/app/src/main/java/org/y20k/trackbook/core/Track.java +++ b/app/src/main/java/org/y20k/trackbook/core/Track.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/core/WayPoint.java b/app/src/main/java/org/y20k/trackbook/core/WayPoint.java index 2fde290..5011575 100644 --- a/app/src/main/java/org/y20k/trackbook/core/WayPoint.java +++ b/app/src/main/java/org/y20k/trackbook/core/WayPoint.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java index 92d1346..db0078d 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/LocationHelper.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java index a4bcb00..cea1d5c 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/LogHelper.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java index b1f14ac..0a3a40c 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/MapHelper.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java index 6145c39..4836d7f 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java b/app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java index e228ea6..f48477d 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/StorageHelper.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * @@ -51,7 +51,6 @@ public class StorageHelper implements TrackbookKeys { private static final String LOG_TAG = StorageHelper.class.getSimpleName(); /* Main class variables */ - private final int mFileType; private final String mDirectoryName = "tracks"; private final String mFileExtension = ".trackbook"; private final Context mActivity; @@ -60,10 +59,9 @@ public class StorageHelper implements TrackbookKeys { /* Constructor */ - public StorageHelper(Context activity, int fileType) { + public StorageHelper(Context activity) { // store activity mActivity = activity; - mFileType = fileType; // get "tracks" folder mFolder = mActivity.getExternalFilesDir(mDirectoryName); @@ -93,7 +91,7 @@ public class StorageHelper implements TrackbookKeys { /* Saves track object to file */ - public boolean saveTrack(@Nullable Track track) { + public boolean saveTrack(@Nullable Track track, int fileType) { // get "tracks" folder mFolder = mActivity.getExternalFilesDir(mDirectoryName); @@ -106,7 +104,7 @@ public class StorageHelper implements TrackbookKeys { if (mFolder != null && mFolder.exists() && mFolder.isDirectory() && mFolder.canWrite() && recordingStart != null && track != null) { // create file object String fileName; - if (mFileType == FILETYPE_TEMP) { + if (fileType == FILETYPE_TEMP) { // case: temp file fileName = FILENAME_TEMP + mFileExtension; } else { @@ -132,7 +130,7 @@ public class StorageHelper implements TrackbookKeys { } // if write was successful delete old track files - only if not a temp file - if (mFileType != FILETYPE_TEMP) { + if (fileType != FILETYPE_TEMP) { // include temp file if it exists deleteOldTracks(true); } @@ -148,11 +146,11 @@ public class StorageHelper implements TrackbookKeys { /* Loads given file into memory */ - public Track loadTrack () { + public Track loadTrack (int fileType) { // get file reference File file; - if (mFileType == FILETYPE_TEMP) { + if (fileType == FILETYPE_TEMP) { file = getTempFile(); } else { file = getMostCurrentTrack(); @@ -176,6 +174,8 @@ public class StorageHelper implements TrackbookKeys { sb.append("\n"); } + // TODO implement a format version check before handing the file to GSON + // get track from JSON GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("M/d/yy hh:mm a"); diff --git a/app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java b/app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java index b2b2f08..cb0e620 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java +++ b/app/src/main/java/org/y20k/trackbook/helpers/TrackbookKeys.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * @@ -23,8 +23,8 @@ package org.y20k.trackbook.helpers; public interface TrackbookKeys { /* ACTIONS */ - String ACTION_START = "org.y20k.transistor.action.START"; - String ACTION_STOP = "org.y20k.transistor.action.STOP"; + String ACTION_START = "org.y20k.trackbook.action.START"; + String ACTION_STOP = "org.y20k.trackbook.action.STOP"; String ACTION_DEFAULT = "DEFAULT"; String ACTION_SHOW_MAP = "SHOW_MAP"; String ACTION_TRACK_UPDATED = "TRACK_UPDATED"; diff --git a/app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java b/app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java index 984edf4..0cb8446 100644 --- a/app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java +++ b/app/src/main/java/org/y20k/trackbook/layout/DodgeAbleLayoutBehavior.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT * diff --git a/app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java b/app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java index ed6971e..d84dea5 100644 --- a/app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java +++ b/app/src/main/java/org/y20k/trackbook/layout/NonSwipeableViewPager.java @@ -6,7 +6,7 @@ * This file is part of * TRACKBOOK - Movement Recorder for Android * - * Copyright (c) 2016 - Y20K.org + * Copyright (c) 2016-17 - Y20K.org * Licensed under the MIT-License * http://opensource.org/licenses/MIT *