(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:
parent
0e94bdb9dd
commit
542660c0c5
19 changed files with 83 additions and 66 deletions
|
@ -1,8 +1,8 @@
|
||||||
The MIT License (MIT)
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
@ -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 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
|
Install Trackbook
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
@ -22,10 +22,9 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
testCompile 'junit:junit:4.12'
|
|
||||||
compile 'com.android.support:appcompat-v7:25.1.0'
|
compile 'com.android.support:appcompat-v7:25.1.0'
|
||||||
compile 'com.android.support:design:25.1.0'
|
compile 'com.android.support:design:25.1.0'
|
||||||
compile 'com.android.support:cardview-v7: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'
|
compile 'com.google.code.gson:gson:2.8.0'
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@
|
||||||
android:name=".TrackerService"
|
android:name=".TrackerService"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.y20k.transistor.action.START" />
|
<action android:name="org.y20k.trackbook.action.START" />
|
||||||
<action android:name="org.y20k.transistor.action.STOP" />
|
<action android:name="org.y20k.trackbook.action.STOP" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
/**
|
/**
|
||||||
* InfosheetActivity.java
|
* InfosheetActivity.java
|
||||||
* Implements the app's infosheet activity
|
* 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
|
* 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
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
|
*
|
||||||
|
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
||||||
|
* https://github.com/osmdroid/osmdroid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
@ -75,6 +75,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
private SettingsContentObserver mSettingsContentObserver;
|
private SettingsContentObserver mSettingsContentObserver;
|
||||||
private MapView mMapView;
|
private MapView mMapView;
|
||||||
private IMapController mController;
|
private IMapController mController;
|
||||||
|
private StorageHelper mStorageHelper;
|
||||||
private LocationManager mLocationManager;
|
private LocationManager mLocationManager;
|
||||||
private LocationListener mGPSListener;
|
private LocationListener mGPSListener;
|
||||||
private LocationListener mNetworkListener;
|
private LocationListener mNetworkListener;
|
||||||
|
@ -113,6 +114,9 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
// mTrackerServiceRunning = savedInstanceState.getBoolean(INSTANCE_TRACKING_STATE, false);
|
// mTrackerServiceRunning = savedInstanceState.getBoolean(INSTANCE_TRACKING_STATE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create storage helper
|
||||||
|
mStorageHelper = new StorageHelper(mActivity);
|
||||||
|
|
||||||
// acquire reference to Location Manager
|
// acquire reference to Location Manager
|
||||||
mLocationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
|
mLocationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
@ -193,20 +197,25 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
mFirstStart = false;
|
mFirstStart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore track
|
// // restore track
|
||||||
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
|
// StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
|
||||||
if (storageHelper.tempFileExists()) {
|
// if (storageHelper.tempFileExists()) {
|
||||||
// load track from temp file if it exists
|
// // load track from temp file if it exists
|
||||||
LoadTempTrackAsyncHelper loadTempTrackAsyncHelper = new LoadTempTrackAsyncHelper();
|
// LoadTempTrackAsyncHelper loadTempTrackAsyncHelper = new LoadTempTrackAsyncHelper();
|
||||||
loadTempTrackAsyncHelper.execute();
|
// loadTempTrackAsyncHelper.execute();
|
||||||
LogHelper.v(LOG_TAG, "MapFragment: getting track from temp file.");
|
// LogHelper.v(LOG_TAG, "MapFragment: getting track from temp file.");
|
||||||
} else if (savedInstanceState != null) {
|
// } 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
|
// load track from saved instance
|
||||||
|
if (savedInstanceState != null) {
|
||||||
mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK_MAIN_MAP);
|
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
|
// mark user's location on map
|
||||||
|
@ -226,22 +235,30 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
// set visibility
|
// set visibility
|
||||||
mFragmentVisible = true;
|
mFragmentVisible = true;
|
||||||
|
|
||||||
// handle incoming intent (from notification)
|
|
||||||
// handleIncomingIntent(); // todo remove
|
|
||||||
|
|
||||||
// load state of tracker service - see if anything changed
|
// load state of tracker service - see if anything changed
|
||||||
loadTrackerServiceState(mActivity);
|
loadTrackerServiceState(mActivity);
|
||||||
|
|
||||||
// request an updated track recording from service - if TrackerService is running
|
// CASE 1: recording active
|
||||||
if (mTrackerServiceRunning) {
|
if (mTrackerServiceRunning) {
|
||||||
|
// request an updated track recording from service
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
i.setAction(ACTION_TRACK_REQUEST);
|
i.setAction(ACTION_TRACK_REQUEST);
|
||||||
LocalBroadcastManager.getInstance(mActivity).sendBroadcast(i);
|
LocalBroadcastManager.getInstance(mActivity).sendBroadcast(i);
|
||||||
|
LogHelper.v(LOG_TAG, "MapFragment: requesting updated track from service.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw track on map - if available
|
// CASE 2: recording stopped - temp file exists
|
||||||
if (mTrack != null) {
|
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);
|
drawTrackOverlay(mTrack);
|
||||||
|
LogHelper.v(LOG_TAG, "MapFragment: got track from saved instance.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// show/hide the location off notification bar
|
// show/hide the location off notification bar
|
||||||
|
@ -421,8 +438,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
} else {
|
} else {
|
||||||
// clear track object and delete temp file
|
// clear track object and delete temp file
|
||||||
mTrack = null;
|
mTrack = null;
|
||||||
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
|
mStorageHelper.deleteTempFile();
|
||||||
storageHelper.deleteTempFile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// // save track state
|
// // save track state
|
||||||
|
@ -705,8 +721,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
LogHelper.v(LOG_TAG, "Saving track object in background.");
|
LogHelper.v(LOG_TAG, "Saving track object in background.");
|
||||||
// save track object
|
// save track object
|
||||||
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TRACK);
|
mStorageHelper.saveTrack(mTrack, FILETYPE_TRACK);
|
||||||
storageHelper.saveTrack(mTrack);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,14 +746,11 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
*/
|
*/
|
||||||
private class LoadTempTrackAsyncHelper extends AsyncTask<Void, Void, Void> {
|
private class LoadTempTrackAsyncHelper extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
StorageHelper storageHelper;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
LogHelper.v(LOG_TAG, "Loading temporary track object in background.");
|
LogHelper.v(LOG_TAG, "Loading temporary track object in background.");
|
||||||
// load track object
|
// load track object
|
||||||
storageHelper = new StorageHelper(mActivity, FILETYPE_TEMP);
|
mTrack = mStorageHelper.loadTrack(FILETYPE_TEMP);
|
||||||
mTrack = storageHelper.loadTrack();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,7 +765,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete temp file
|
// delete temp file
|
||||||
storageHelper.deleteTempFile();
|
mStorageHelper.deleteTempFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
@ -318,8 +318,8 @@ public class MainActivityTrackFragment extends Fragment implements TrackbookKeys
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
LogHelper.v(LOG_TAG, "Loading track object in background.");
|
LogHelper.v(LOG_TAG, "Loading track object in background.");
|
||||||
// load track object
|
// load track object
|
||||||
StorageHelper storageHelper = new StorageHelper(mActivity, FILETYPE_TRACK);
|
StorageHelper storageHelper = new StorageHelper(mActivity);
|
||||||
mTrack = storageHelper.loadTrack();
|
mTrack = storageHelper.loadTrack(FILETYPE_TRACK);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
@ -250,6 +250,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
// stop timer
|
// stop timer
|
||||||
mTimer.cancel();
|
mTimer.cancel();
|
||||||
|
|
||||||
|
// TODO test for race condition
|
||||||
|
sendTrackUpdate();
|
||||||
|
|
||||||
// save a temp file in case the activity has been killed
|
// save a temp file in case the activity has been killed
|
||||||
SaveTempTrackAsyncHelper saveTempTrackAsyncHelper = new SaveTempTrackAsyncHelper();
|
SaveTempTrackAsyncHelper saveTempTrackAsyncHelper = new SaveTempTrackAsyncHelper();
|
||||||
saveTempTrackAsyncHelper.execute();
|
saveTempTrackAsyncHelper.execute();
|
||||||
|
@ -420,8 +423,8 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
LogHelper.v(LOG_TAG, "Saving temporary track object in background.");
|
LogHelper.v(LOG_TAG, "Saving temporary track object in background.");
|
||||||
// save track object
|
// save track object
|
||||||
StorageHelper storageHelper = new StorageHelper(TrackerService.this, FILETYPE_TEMP);
|
StorageHelper storageHelper = new StorageHelper(TrackerService.this);
|
||||||
storageHelper.saveTrack(mTrack);
|
storageHelper.saveTrack(mTrack, FILETYPE_TEMP);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
@ -51,7 +51,6 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
private static final String LOG_TAG = StorageHelper.class.getSimpleName();
|
private static final String LOG_TAG = StorageHelper.class.getSimpleName();
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
private final int mFileType;
|
|
||||||
private final String mDirectoryName = "tracks";
|
private final String mDirectoryName = "tracks";
|
||||||
private final String mFileExtension = ".trackbook";
|
private final String mFileExtension = ".trackbook";
|
||||||
private final Context mActivity;
|
private final Context mActivity;
|
||||||
|
@ -60,10 +59,9 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
public StorageHelper(Context activity, int fileType) {
|
public StorageHelper(Context activity) {
|
||||||
// store activity
|
// store activity
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mFileType = fileType;
|
|
||||||
|
|
||||||
// get "tracks" folder
|
// get "tracks" folder
|
||||||
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
||||||
|
@ -93,7 +91,7 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Saves track object to file */
|
/* Saves track object to file */
|
||||||
public boolean saveTrack(@Nullable Track track) {
|
public boolean saveTrack(@Nullable Track track, int fileType) {
|
||||||
|
|
||||||
// get "tracks" folder
|
// get "tracks" folder
|
||||||
mFolder = mActivity.getExternalFilesDir(mDirectoryName);
|
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) {
|
if (mFolder != null && mFolder.exists() && mFolder.isDirectory() && mFolder.canWrite() && recordingStart != null && track != null) {
|
||||||
// create file object
|
// create file object
|
||||||
String fileName;
|
String fileName;
|
||||||
if (mFileType == FILETYPE_TEMP) {
|
if (fileType == FILETYPE_TEMP) {
|
||||||
// case: temp file
|
// case: temp file
|
||||||
fileName = FILENAME_TEMP + mFileExtension;
|
fileName = FILENAME_TEMP + mFileExtension;
|
||||||
} else {
|
} 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 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
|
// include temp file if it exists
|
||||||
deleteOldTracks(true);
|
deleteOldTracks(true);
|
||||||
}
|
}
|
||||||
|
@ -148,11 +146,11 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
|
|
||||||
|
|
||||||
/* Loads given file into memory */
|
/* Loads given file into memory */
|
||||||
public Track loadTrack () {
|
public Track loadTrack (int fileType) {
|
||||||
|
|
||||||
// get file reference
|
// get file reference
|
||||||
File file;
|
File file;
|
||||||
if (mFileType == FILETYPE_TEMP) {
|
if (fileType == FILETYPE_TEMP) {
|
||||||
file = getTempFile();
|
file = getTempFile();
|
||||||
} else {
|
} else {
|
||||||
file = getMostCurrentTrack();
|
file = getMostCurrentTrack();
|
||||||
|
@ -176,6 +174,8 @@ public class StorageHelper implements TrackbookKeys {
|
||||||
sb.append("\n");
|
sb.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO implement a format version check before handing the file to GSON
|
||||||
|
|
||||||
// get track from JSON
|
// get track from JSON
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
@ -23,8 +23,8 @@ package org.y20k.trackbook.helpers;
|
||||||
public interface TrackbookKeys {
|
public interface TrackbookKeys {
|
||||||
|
|
||||||
/* ACTIONS */
|
/* ACTIONS */
|
||||||
String ACTION_START = "org.y20k.transistor.action.START";
|
String ACTION_START = "org.y20k.trackbook.action.START";
|
||||||
String ACTION_STOP = "org.y20k.transistor.action.STOP";
|
String ACTION_STOP = "org.y20k.trackbook.action.STOP";
|
||||||
String ACTION_DEFAULT = "DEFAULT";
|
String ACTION_DEFAULT = "DEFAULT";
|
||||||
String ACTION_SHOW_MAP = "SHOW_MAP";
|
String ACTION_SHOW_MAP = "SHOW_MAP";
|
||||||
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
String ACTION_TRACK_UPDATED = "TRACK_UPDATED";
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* This file is part of
|
* This file is part of
|
||||||
* TRACKBOOK - Movement Recorder for Android
|
* TRACKBOOK - Movement Recorder for Android
|
||||||
*
|
*
|
||||||
* Copyright (c) 2016 - Y20K.org
|
* Copyright (c) 2016-17 - Y20K.org
|
||||||
* Licensed under the MIT-License
|
* Licensed under the MIT-License
|
||||||
* http://opensource.org/licenses/MIT
|
* http://opensource.org/licenses/MIT
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue