During import, add photo markers to gallery

This commit is contained in:
Jimmy Shih
2013-12-02 10:59:48 -08:00
parent d0a9885a50
commit 93ddc27566
3 changed files with 16 additions and 5 deletions
@@ -30,8 +30,8 @@ import com.google.android.apps.mytracks.fragments.ExportDialogFragment;
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportCaller;
import com.google.android.apps.mytracks.fragments.ExportDialogFragment.ExportType;
import com.google.android.apps.mytracks.fragments.FrequencyDialogFragment;
import com.google.android.apps.mytracks.fragments.PlayMultipleDialogFragment;
import com.google.android.apps.mytracks.fragments.MyTracksMapFragment;
import com.google.android.apps.mytracks.fragments.PlayMultipleDialogFragment;
import com.google.android.apps.mytracks.fragments.StatsFragment;
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
import com.google.android.apps.mytracks.io.file.exporter.SaveActivity;
@@ -140,9 +140,7 @@ public class TrackDetailActivity extends AbstractSendToGoogleActivity
hasPhoto = false;
if (id != -1L) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(photoUri);
sendBroadcast(mediaScanIntent);
FileUtils.updateMediaScanner(TrackDetailActivity.this, photoUri);
}
}
}
@@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.io.file.exporter.KmzTrackExporter;
import com.google.android.apps.mytracks.util.FileUtils;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import java.io.ByteArrayInputStream;
@@ -184,12 +185,15 @@ public class KmzTrackImporter implements TrackImporter {
File dir = FileUtils.getPhotoDir(importTrackId);
FileUtils.ensureDirectoryExists(dir);
fileOutputStream = new FileOutputStream(new File(dir, fileName));
File file = new File(dir, fileName);
fileOutputStream = new FileOutputStream(file);
byte[] buffer = new byte[BUFFER_SIZE];
int count;
while ((count = zipInputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, count);
}
FileUtils.updateMediaScanner(context, Uri.fromFile(file));
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
@@ -15,6 +15,9 @@
*/
package com.google.android.apps.mytracks.util;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import java.io.File;
@@ -173,6 +176,12 @@ public class FileUtils {
}
return fileName.substring(index + 1);
}
public static void updateMediaScanner(Context context, Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
context.sendBroadcast(mediaScanIntent);
}
/**
* Builds a filename with the given base and the given extension, possibly