Code cleanup: FileUtils.java

This commit is contained in:
Jimmy Shih
2013-10-04 15:37:10 -07:00
parent 4161f8ff56
commit 3827faa0e5
3 changed files with 29 additions and 22 deletions
@@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter;
import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.SystemUtils;
import com.google.android.maps.mytracks.R;
@@ -219,7 +220,7 @@ public class ImportAsyncTask extends AsyncTask<Void, Integer, Boolean> {
File[] candidates = file.listFiles();
if (candidates != null) {
for (File candidate : candidates) {
if (!candidate.isDirectory()) {
if (!FileUtils.isDirectory(candidate)) {
String name = candidate.getName();
if (trackFileFormat == TrackFileFormat.KML && (
name.endsWith("." + TrackFileFormat.KML.getExtension())
@@ -117,7 +117,7 @@ public class KmzTrackImporter implements TrackImporter {
if (importTrackId != -1L) {
File dir = new File(
FileUtils.getPath(FileUtils.PICTURES_DIR, Long.toString(importTrackId)));
if (dir.exists() && dir.isDirectory()) {
if (FileUtils.isDirectory(dir)) {
for (File file : dir.listFiles()) {
file.delete();
}
@@ -31,15 +31,21 @@ public class FileUtils {
private FileUtils() {}
/**
* Name of the top-level directory inside the SD card where our files will be
* read from/written to.
* The backups directory under the My Tracks external storage directory.
*/
protected static final String SDCARD_TOP_DIR = "MyTracks";
public static final String BACKUPS_DIR = "backups";
/**
* The pictures directory under the My Tracks external storage directory.
*/
public static final String PICTURES_DIR = "pictures";
/**
* The My Tracks external storage directory.
*/
@VisibleForTesting
static final String SDCARD_TOP_DIR = "MyTracks";
/**
* The maximum FAT32 path length. See the FAT32 spec at
* http://msdn.microsoft.com/en-us/windows/hardware/gg463080
@@ -74,8 +80,7 @@ public class FileUtils {
}
/**
* Ensures the directory exists by creating it and its parents if
* necessary.
* Ensures the directory exists by creating it and its parents if necessary.
*
* @return whether the directory exists (either already existed or was
* successfully created)
@@ -102,6 +107,7 @@ public class FileUtils {
}
return dirNameBuilder.toString();
}
/**
* Gets a path on the external storage.
*