(1) Updated copyright info (2017, yay) (2) moved the temp file loading process to a later stage (onResume) of the app start

This commit is contained in:
y20k 2017-01-19 13:36:49 +01:00
parent 0e94bdb9dd
commit 542660c0c5
19 changed files with 83 additions and 66 deletions

View file

@ -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

View file

@ -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
-----------------

View file

@ -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'
}

View file

@ -54,8 +54,8 @@
android:name=".TrackerService"
android:exported="false">
<intent-filter>
<action android:name="org.y20k.transistor.action.START" />
<action android:name="org.y20k.transistor.action.STOP" />
<action android:name="org.y20k.trackbook.action.START" />
<action android:name="org.y20k.trackbook.action.STOP" />
</intent-filter>
</service>

View file

@ -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
*/

View file

@ -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
*

View file

@ -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) {
// // 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<Void, Void, Void> {
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();
}
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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
*

View file

@ -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
*

View file

@ -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
*

View file

@ -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
*

View file

@ -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
*

View file

@ -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
*

View file

@ -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");

View file

@ -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";

View file

@ -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
*

View file

@ -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
*