summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Storage.java
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-10-17 15:41:44 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-10-28 11:13:40 -0700
commit7cfcafdf8f4a439c8fa87b612616fe409979e8a4 (patch)
tree57e306c62dcc4d57c14562fd4c9bc287e4da85d9 /src/com/android/camera/Storage.java
parentd053a5b2aa8cd9cb09bd40962b305ef34e7d404b (diff)
downloadandroid_packages_apps_Snap-7cfcafdf8f4a439c8fa87b612616fe409979e8a4.tar.gz
android_packages_apps_Snap-7cfcafdf8f4a439c8fa87b612616fe409979e8a4.tar.bz2
android_packages_apps_Snap-7cfcafdf8f4a439c8fa87b612616fe409979e8a4.zip
gcam: Add placeholder image.
Bug: 11050749 Change-Id: I374c5919d6da0609fccd21c09775fa91894d5a24
Diffstat (limited to 'src/com/android/camera/Storage.java')
-rw-r--r--src/com/android/camera/Storage.java98
1 files changed, 76 insertions, 22 deletions
diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java
index a8ce08b93..499d03029 100644
--- a/src/com/android/camera/Storage.java
+++ b/src/com/android/camera/Storage.java
@@ -43,6 +43,7 @@ public class Storage {
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString();
public static final String DIRECTORY = DCIM + "/Camera";
+ public static final String JPEG_POSTFIX = ".jpg";
// Match the code in MediaProvider.computeBucketValues().
public static final String BUCKET_ID =
@@ -62,6 +63,18 @@ public class Storage {
}
}
+ public static void writeFile(String path, byte[] jpeg, ExifInterface exif) {
+ if (exif != null) {
+ try {
+ exif.writeExif(jpeg, path);
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to write data", e);
+ }
+ } else {
+ writeFile(path, jpeg);
+ }
+ }
+
public static void writeFile(String path, byte[] data) {
FileOutputStream out = null;
try {
@@ -73,39 +86,41 @@ public class Storage {
try {
out.close();
} catch (Exception e) {
+ Log.e(TAG, "Failed to close file after write", e);
}
}
}
- // Save the image and add it to media store.
- public static Uri addImage(ContentResolver resolver, String title,
- long date, Location location, int orientation, ExifInterface exif,
- byte[] jpeg, int width, int height) {
- // Save the image.
+ // Save the image and add it to the MediaStore.
+ public static Uri addImage(ContentResolver resolver, String title, long date,
+ Location location, int orientation, ExifInterface exif, byte[] jpeg, int width,
+ int height) {
+
+ return addImage(resolver, title, date, location, orientation, exif, jpeg, width, height,
+ LocalData.MIME_TYPE_JPEG);
+ }
+
+ // Save the image with a given mimeType and add it the MediaStore.
+ public static Uri addImage(ContentResolver resolver, String title, long date,
+ Location location, int orientation, ExifInterface exif, byte[] jpeg, int width,
+ int height, String mimeType) {
+
String path = generateFilepath(title);
- if (exif != null) {
- try {
- exif.writeExif(jpeg, path);
- } catch (Exception e) {
- Log.e(TAG, "Failed to write data", e);
- }
- } else {
- writeFile(path, jpeg);
- }
+ writeFile(path, jpeg, exif);
return addImage(resolver, title, date, location, orientation,
- jpeg.length, path, width, height);
+ jpeg.length, path, width, height, mimeType);
}
- // Add the image to media store.
- public static Uri addImage(ContentResolver resolver, String title,
+ // Get a ContentValues object for the given photo data
+ public static ContentValues getContentValuesForData(String title,
long date, Location location, int orientation, int jpegLength,
- String path, int width, int height) {
- // Insert into MediaStore.
- ContentValues values = new ContentValues(9);
+ String path, int width, int height, String mimeType) {
+
+ ContentValues values = new ContentValues(11);
values.put(ImageColumns.TITLE, title);
- values.put(ImageColumns.DISPLAY_NAME, title + ".jpg");
+ values.put(ImageColumns.DISPLAY_NAME, title + JPEG_POSTFIX);
values.put(ImageColumns.DATE_TAKEN, date);
- values.put(ImageColumns.MIME_TYPE, LocalData.MIME_TYPE_JPEG);
+ values.put(ImageColumns.MIME_TYPE, mimeType);
// Clockwise rotation in degrees. 0, 90, 180, or 270.
values.put(ImageColumns.ORIENTATION, orientation);
values.put(ImageColumns.DATA, path);
@@ -117,6 +132,17 @@ public class Storage {
values.put(ImageColumns.LATITUDE, location.getLatitude());
values.put(ImageColumns.LONGITUDE, location.getLongitude());
}
+ return values;
+ }
+
+ // Add the image to media store.
+ public static Uri addImage(ContentResolver resolver, String title,
+ long date, Location location, int orientation, int jpegLength,
+ String path, int width, int height, String mimeType) {
+ // Insert into MediaStore.
+ ContentValues values =
+ getContentValuesForData(title, date, location, orientation, jpegLength, path,
+ width, height, mimeType);
Uri uri = null;
try {
@@ -132,6 +158,34 @@ public class Storage {
return uri;
}
+ // Overwrites the file and updates the MediaStore
+ public static void updateImage(Uri imageUri, ContentResolver resolver, String title, long date,
+ Location location, int orientation, ExifInterface exif, byte[] jpeg, int width,
+ int height, String mimeType) {
+ String path = generateFilepath(title);
+ writeFile(path, jpeg, exif);
+ updateImage(imageUri, resolver, title, date, location, orientation, jpeg.length, path,
+ width, height, mimeType);
+ }
+
+ // Updates the image values in MediaStore
+ public static void updateImage(Uri imageUri, ContentResolver resolver, String title,
+ long date, Location location, int orientation, int jpegLength,
+ String path, int width, int height, String mimeType) {
+
+ ContentValues values =
+ getContentValuesForData(title, date, location, orientation, jpegLength, path,
+ width, height, mimeType);
+
+ // Update the MediaStore
+ int rowsModified = resolver.update(imageUri, values, null, null);
+ if (rowsModified != 1) {
+ // This should never happen
+ throw new IllegalStateException("Bad number of rows (" + rowsModified
+ + ") updated for uri: " + imageUri);
+ }
+ }
+
public static void deleteImage(ContentResolver resolver, Uri uri) {
try {
resolver.delete(uri, null, null);