fixes a bug where the app could get stuck in a loop after a crash during recording (the latter should not occur in the first place ^o^).
This commit is contained in:
		
							parent
							
								
									5e8c8f215c
								
							
						
					
					
						commit
						576ea43c21
					
				
					 4 changed files with 39 additions and 13 deletions
				
			
		|  | @ -8,8 +8,8 @@ android { | |||
|         applicationId "org.y20k.trackbook" | ||||
|         minSdkVersion 22 | ||||
|         targetSdkVersion 25 | ||||
|         versionCode 9 | ||||
|         versionName "1.0.2 (Astronomy Domine)" | ||||
|         versionCode 10 | ||||
|         versionName "1.0.3 (Astronomy Domine)" | ||||
|         vectorDrawables.useSupportLibrary = true | ||||
|     } | ||||
|     buildTypes { | ||||
|  | @ -26,5 +26,5 @@ dependencies { | |||
|     compile 'com.android.support:design:25.3.1' | ||||
|     compile 'com.android.support:cardview-v7:25.3.1' | ||||
|     compile 'org.osmdroid:osmdroid-android:5.6.4' | ||||
|     compile 'com.google.code.gson:gson:2.8.0' | ||||
|     compile 'com.google.code.gson:gson:2.8.1' | ||||
| } | ||||
|  |  | |||
|  | @ -28,6 +28,7 @@ import android.content.pm.PackageManager; | |||
| import android.location.Location; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.os.Environment; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.annotation.Nullable; | ||||
|  | @ -92,6 +93,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys { | |||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
| 
 | ||||
|         // check state of External Storage | ||||
|         checkExternalStorageState(); | ||||
| 
 | ||||
|         // load saved state of app | ||||
|         loadFloatingActionButtonState(this); | ||||
| 
 | ||||
|  | @ -655,6 +659,24 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys { | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /* Checks the state of External Storage */ | ||||
|     private void checkExternalStorageState() { | ||||
| 
 | ||||
|         String state = Environment.getExternalStorageState(); | ||||
|         if (!state.equals(Environment.MEDIA_MOUNTED)) { | ||||
|             LogHelper.e(LOG_TAG, "Error: Unable to mount External Storage. Current state: " + state); | ||||
| 
 | ||||
|             // move MainActivity to back | ||||
|             moveTaskToBack(true); | ||||
| 
 | ||||
|             // shutting down app | ||||
|             android.os.Process.killProcess(android.os.Process.myPid()); | ||||
|             System.exit(1); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * Inner class: SectionsPagerAdapter that returns a fragment corresponding to one of the tabs. | ||||
|      * see also: https://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html | ||||
|  |  | |||
|  | @ -129,7 +129,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven | |||
| 
 | ||||
|         // ACTION STOP | ||||
|         else if (intent.getAction().equals(ACTION_STOP) || !mLocationSystemSetting) { | ||||
|             stopTracking(); | ||||
|             if (mTrack != null) { | ||||
|                 stopTracking(); | ||||
|             } | ||||
| 
 | ||||
|             // save changed state of Floating Action Button | ||||
|             SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext()); | ||||
|  | @ -413,7 +415,9 @@ public class TrackerService extends Service implements TrackbookKeys, SensorEven | |||
|             mLocationSystemSetting = LocationHelper.checkLocationSystemSetting(getApplicationContext()); | ||||
|             if (previousLocationSystemSetting != mLocationSystemSetting && !mLocationSystemSetting && mTrackerServiceRunning) { | ||||
|                 LogHelper.v(LOG_TAG, "Location Setting turned off while tracking service running."); | ||||
|                 stopTracking(); | ||||
|                 if (mTrack != null) { | ||||
|                     stopTracking(); | ||||
|                 } | ||||
|                 stopForeground(true); | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -51,18 +51,18 @@ public class StorageHelper implements TrackbookKeys { | |||
|     private static final String LOG_TAG = StorageHelper.class.getSimpleName(); | ||||
| 
 | ||||
|     /* Main class variables */ | ||||
|     private final Context mActivity; | ||||
|     private final Context mContext; | ||||
|     private File mFolder; | ||||
|     private final File mTempFile; | ||||
| 
 | ||||
| 
 | ||||
|     /* Constructor */ | ||||
|     public StorageHelper(Context activity) { | ||||
|     public StorageHelper(Context context) { | ||||
|         // store activity | ||||
|         mActivity = activity; | ||||
|         mContext = context; | ||||
| 
 | ||||
|         // get "tracks" folder | ||||
|         mFolder  = mActivity.getExternalFilesDir(TRACKS_DIRECTORY_NAME); | ||||
|         mFolder  = mContext.getExternalFilesDir(TRACKS_DIRECTORY_NAME); | ||||
|         // mFolder = getTracksDirectory(); | ||||
| 
 | ||||
|         // create "tracks" folder if necessary | ||||
|  | @ -129,7 +129,7 @@ public class StorageHelper implements TrackbookKeys { | |||
| 
 | ||||
|             // if write was successful delete old track files - only if not a temp file | ||||
|             if (fileType != FILE_TEMP_TRACK) { | ||||
|                 // include  temp file if it exists | ||||
|                 // include temp file if it exists | ||||
|                 deleteOldTracks(true); | ||||
|             } | ||||
| 
 | ||||
|  | @ -340,9 +340,9 @@ public class StorageHelper implements TrackbookKeys { | |||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /* Return a write-able sub-directory from external storage  */ | ||||
|     /* Return a write-able sub-directory from external storage */ | ||||
|     private File getTracksDirectory() { | ||||
|         File[] storage = mActivity.getExternalFilesDirs(TRACKS_DIRECTORY_NAME); | ||||
|         File[] storage = mContext.getExternalFilesDirs(TRACKS_DIRECTORY_NAME); | ||||
|         for (File file : storage) { | ||||
|             if (file != null) { | ||||
|                 String state = EnvironmentCompat.getStorageState(file); | ||||
|  | @ -352,7 +352,7 @@ public class StorageHelper implements TrackbookKeys { | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         Toast.makeText(mActivity, R.string.toast_message_no_external_storage, Toast.LENGTH_LONG).show(); | ||||
|         Toast.makeText(mContext, R.string.toast_message_no_external_storage, Toast.LENGTH_LONG).show(); | ||||
|         LogHelper.e(LOG_TAG, "Unable to access external storage."); | ||||
| 
 | ||||
|         return null; | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 y20k
						y20k