forked from upstream-mirrors/OpenTracks
Code cleanup: cleanup callers of FileUtils.buildUniqueFileName
This commit is contained in:
@@ -1008,10 +1008,6 @@ limitations under the License.
|
|||||||
translation_description="When deleting multiple markers, the confirmation message.">
|
translation_description="When deleting multiple markers, the confirmation message.">
|
||||||
All markers for this track will be permanently deleted from the device.
|
All markers for this track will be permanently deleted from the device.
|
||||||
</string>
|
</string>
|
||||||
<string name="marker_insert_photo_error"
|
|
||||||
translation_description="The error message when unable to insert a photo marker.">
|
|
||||||
Unable to insert a photo marker. Try again.
|
|
||||||
</string>
|
|
||||||
<string name="marker_label_end"
|
<string name="marker_label_end"
|
||||||
translation_description="When inserting a marker to indicate the end of a track, the marker's
|
translation_description="When inserting a marker to indicate the end of a track, the marker's
|
||||||
name. E.g., 'track_name (End)'.
|
name. E.g., 'track_name (End)'.
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import android.os.Parcelable;
|
|||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -66,7 +65,6 @@ import android.widget.TabHost.TabSpec;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -391,32 +389,22 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity implements
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_insert_photo:
|
case R.id.track_detail_insert_photo:
|
||||||
try {
|
if (!FileUtils.isExternalStorageWriteable()) {
|
||||||
if (!FileUtils.isExternalStorageWriteable()) {
|
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();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
File dir = new File(
|
|
||||||
FileUtils.getDirectoryPath(FileUtils.PICTURES_DIR, Long.toString(trackId)));
|
|
||||||
FileUtils.ensureDirectoryExists(dir);
|
|
||||||
|
|
||||||
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
|
||||||
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, "jpeg"));
|
|
||||||
|
|
||||||
if (file.exists()) {
|
|
||||||
Toast.makeText(this, R.string.marker_insert_photo_error, Toast.LENGTH_LONG).show();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
file.createNewFile();
|
|
||||||
photoUri = Uri.fromFile(file);
|
|
||||||
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
|
||||||
MediaStore.EXTRA_OUTPUT, photoUri);
|
|
||||||
startActivityForResult(intent, CAMERA_REQUEST_CODE);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "Unable to insert photo marker", e);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File dir = new File(
|
||||||
|
FileUtils.getDirectoryPath(FileUtils.PICTURES_DIR, Long.toString(trackId)));
|
||||||
|
FileUtils.ensureDirectoryExists(dir);
|
||||||
|
|
||||||
|
String fileName = SimpleDateFormat.getDateTimeInstance().format(new Date());
|
||||||
|
File file = new File(dir, FileUtils.buildUniqueFileName(dir, fileName, "jpeg"));
|
||||||
|
|
||||||
|
photoUri = Uri.fromFile(file);
|
||||||
|
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
|
||||||
|
MediaStore.EXTRA_OUTPUT, photoUri);
|
||||||
|
startActivityForResult(intent, CAMERA_REQUEST_CODE);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_play:
|
case R.id.track_detail_play:
|
||||||
playTrack(new long[] {trackId});
|
playTrack(new long[] {trackId});
|
||||||
|
|||||||
@@ -183,17 +183,10 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
if (tracks.length == 0) {
|
if (tracks.length == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Track track = tracks[0];
|
Track track = tracks[0];
|
||||||
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
|
boolean useKmz = trackFileFormat == TrackFileFormat.KML && !playTrack;
|
||||||
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
|
String extension = useKmz ? KmzTrackExporter.KMZ_EXTENSION : trackFileFormat.getExtension();
|
||||||
|
|
||||||
// Make sure the file doesn't exist yet (possibly by changing the filename)
|
|
||||||
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
|
|
||||||
if (fileName == null) {
|
|
||||||
Log.d(TAG, "Unable to get a unique filename for " + track.getName());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
FileTrackExporter fileTrackExporter = new FileTrackExporter(myTracksProviderUtils, tracks,
|
||||||
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
|
trackFileFormat.newTrackWriter(context, playTrack), new TrackExporterListener() {
|
||||||
|
|
||||||
@@ -212,6 +205,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
trackExporter = useKmz ? new KmzTrackExporter(myTracksProviderUtils, fileTrackExporter, tracks)
|
trackExporter = useKmz ? new KmzTrackExporter(myTracksProviderUtils, fileTrackExporter, tracks)
|
||||||
: fileTrackExporter;
|
: fileTrackExporter;
|
||||||
|
|
||||||
|
String fileName = FileUtils.buildUniqueFileName(directory, track.getName(), extension);
|
||||||
File file = new File(directory, fileName);
|
File file = new File(directory, fileName);
|
||||||
FileOutputStream fileOutputStream = null;
|
FileOutputStream fileOutputStream = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user