forked from upstream-mirrors/OpenTracks
Code cleanup: specify directories inside the cache directory at FileUtils.java
This commit is contained in:
@@ -83,6 +83,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
|||||||
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
private static final String CURRENT_TAB_TAG_KEY = "current_tab_tag_key";
|
||||||
private static final String PHOTO_URI_KEY = "photo_uri_key";
|
private static final String PHOTO_URI_KEY = "photo_uri_key";
|
||||||
private static final String HAS_PHOTO_KEY = "has_photo_key";
|
private static final String HAS_PHOTO_KEY = "has_photo_key";
|
||||||
|
private static final String JPEG_EXTENSION = "jpeg";
|
||||||
|
|
||||||
// The following are set in onCreate
|
// The following are set in onCreate
|
||||||
private boolean hasCamera;
|
private boolean hasCamera;
|
||||||
@@ -399,7 +400,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
|||||||
FileUtils.ensureDirectoryExists(dir);
|
FileUtils.ensureDirectoryExists(dir);
|
||||||
|
|
||||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||||
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, "jpeg"));
|
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, JPEG_EXTENSION));
|
||||||
|
|
||||||
photoUri = Uri.fromFile(file);
|
photoUri = Uri.fromFile(file);
|
||||||
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.google.android.apps.mytracks.content;
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
@@ -435,8 +436,8 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
throw new FileNotFoundException(uri.getPath());
|
throw new FileNotFoundException(uri.getPath());
|
||||||
} finally {
|
} finally {
|
||||||
File[] files = getContext().getCacheDir().listFiles();
|
File dir = new File(getContext().getCacheDir(), FileUtils.PLAY_TRACKS_DIR);
|
||||||
for (File file : files) {
|
for (File file : dir.listFiles()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class SaveActivity extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File directory = playTrack ? getCacheDir()
|
File directory = playTrack ? new File(getCacheDir(), FileUtils.PLAY_TRACKS_DIR)
|
||||||
: new File(FileUtils.getPath(trackFileFormat.getExtension()));
|
: new File(FileUtils.getPath(trackFileFormat.getExtension()));
|
||||||
if (!FileUtils.ensureDirectoryExists(directory)) {
|
if (!FileUtils.ensureDirectoryExists(directory)) {
|
||||||
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.external_storage_not_writable, Toast.LENGTH_LONG).show();
|
||||||
@@ -90,12 +90,12 @@ public class SaveActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (playTrack) {
|
if (playTrack) {
|
||||||
for (File file : getCacheDir().listFiles()) {
|
for (File file : directory.listFiles()) {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
directoryDisplayName = playTrack ? getCacheDir().getName()
|
directoryDisplayName = playTrack ? directory.getName()
|
||||||
: FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
: FileUtils.getPathDisplayName(trackFileFormat.getExtension());
|
||||||
|
|
||||||
Object retained = getLastNonConfigurationInstance();
|
Object retained = getLastNonConfigurationInstance();
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ public class SyncUtils {
|
|||||||
|
|
||||||
private static final String TAG = SyncUtils.class.getSimpleName();
|
private static final String TAG = SyncUtils.class.getSimpleName();
|
||||||
private static final String SYNC_AUTHORITY = "com.google.android.maps.mytracks";
|
private static final String SYNC_AUTHORITY = "com.google.android.maps.mytracks";
|
||||||
private static final String TEMP_DIR = "temp";
|
|
||||||
|
|
||||||
private SyncUtils() {}
|
private SyncUtils() {}
|
||||||
|
|
||||||
@@ -454,7 +453,7 @@ public class SyncUtils {
|
|||||||
Context context, MyTracksProviderUtils myTracksProviderUtils, Track track, boolean useKmz)
|
Context context, MyTracksProviderUtils myTracksProviderUtils, Track track, boolean useKmz)
|
||||||
throws FileNotFoundException {
|
throws FileNotFoundException {
|
||||||
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : TrackFileFormat.KML.getExtension();
|
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : TrackFileFormat.KML.getExtension();
|
||||||
java.io.File directory = new java.io.File(context.getCacheDir(), TEMP_DIR);
|
java.io.File directory = new java.io.File(context.getCacheDir(), FileUtils.TEMP_FILES_DIR);
|
||||||
|
|
||||||
if (!FileUtils.ensureDirectoryExists(directory)) {
|
if (!FileUtils.ensureDirectoryExists(directory)) {
|
||||||
Log.d(TAG, "Unable to create " + directory.getAbsolutePath());
|
Log.d(TAG, "Unable to create " + directory.getAbsolutePath());
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ public class FileUtils {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int MAX_FAT32_PATH_LENGTH = 260;
|
static final int MAX_FAT32_PATH_LENGTH = 260;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The play tracks directory under the My Tracks cache directory.
|
||||||
|
*/
|
||||||
|
public static final String PLAY_TRACKS_DIR = "temp";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The temp files directory under the My Tracks cache directory.
|
||||||
|
*/
|
||||||
|
public static final String TEMP_FILES_DIR = "temp_files";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the external storage is available.
|
* Returns true if the external storage is available.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user