summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Storage.java
diff options
context:
space:
mode:
authorSanthosh Kumar H E <skhara@codeaurora.org>2013-12-05 16:36:52 +0530
committerSanthosh Kumar H E <skhara@codeaurora.org>2013-12-06 18:58:24 +0530
commitdbdb7620da136374eea95170261032f910015db0 (patch)
tree007242cdb44941ecb855751c85da69aa97cc6a43 /src/com/android/camera/Storage.java
parent1c7734057201ffd1b6d165d9e24793ef3d213043 (diff)
parentdf2b0819907c440a660e228414a18184732816d1 (diff)
downloadandroid_packages_apps_Snap-dbdb7620da136374eea95170261032f910015db0.tar.gz
android_packages_apps_Snap-dbdb7620da136374eea95170261032f910015db0.tar.bz2
android_packages_apps_Snap-dbdb7620da136374eea95170261032f910015db0.zip
Merge remote-tracking branch into merge_branch
Delay onResume tasks to speed up lockscreen onResume->onPause->onResume launch sequence. Import translations. DO NOT MERGE gcam: Clean up placeholders, and add deletion robustness. Fix issue of focus indicator staying on without being hidden Ensure view size gets updated after phone decors change. Show the 100% state of the progress at least one frame. Add parameters and deduplicate parameter changes Revert parallel opening camera in photo mode. Differentiate the InProgressData from the normal PhotoData. Close mode menus if another control is touched Start gcam module directly when handling capture intent. Import translations. DO NOT MERGE Add a null check to fix NPE Add logging to various actions Ensure mOpenCameraThread has been setup before dereferencing. Add logging to various actions Ensure mOpenCameraThread has been setup before dereferencing. Add GCam progress indicator. hide preview cover on arrival of new preview data if hidden Fix photo mode is getting stuck in a single CameraState. ... Conflicts: res/layout/photo_module.xml res/values/arrays.xml src/com/android/camera/CameraActivity.java src/com/android/camera/PhotoUI.java src/com/android/camera/Storage.java src/com/android/camera/WideAnglePanoramaModule.java src/com/android/camera/ui/FilmStripView.java Change-Id: Ic41b4e7e07b2b0ed7936b78a6c5f05270d05985f
Diffstat (limited to 'src/com/android/camera/Storage.java')
-rw-r--r--src/com/android/camera/Storage.java133
1 files changed, 92 insertions, 41 deletions
diff --git a/src/com/android/camera/Storage.java b/src/com/android/camera/Storage.java
index 49435e4c0..29dad8aa4 100644
--- a/src/com/android/camera/Storage.java
+++ b/src/com/android/camera/Storage.java
@@ -44,6 +44,7 @@ public class Storage {
public static final String DIRECTORY = DCIM + "/Camera";
public static final String RAW_DIRECTORY = DCIM + "/Camera/raw";
+ public static final String JPEG_POSTFIX = ".jpg";
// Match the code in MediaProvider.computeBucketValues().
public static final String BUCKET_ID =
@@ -63,6 +64,24 @@ public class Storage {
}
}
+ public static void writeFile(String path, byte[] jpeg, ExifInterface exif,
+ String mimeType) {
+ if (exif != null && (mimeType == null ||
+ mimeType.equalsIgnoreCase("jpeg"))) {
+ try {
+ exif.writeExif(jpeg, path);
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to write data", e);
+ }
+ } else if (jpeg != null) {
+ if (!(mimeType.equalsIgnoreCase("jpeg") || mimeType == null)) {
+ File dir = new File(RAW_DIRECTORY);
+ dir.mkdirs();
+ }
+ writeFile(path, jpeg);
+ }
+ }
+
public static void writeFile(String path, byte[] data) {
FileOutputStream out = null;
try {
@@ -74,48 +93,30 @@ 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, String pictureFormat) {
- int jpegLength = 0;
-
- if (jpeg != null) {
- jpegLength = jpeg.length;
- }
+ // 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) {
- // Save the image.
- String path = generateFilepath(title, pictureFormat);
- if (exif != null && (pictureFormat == null ||
- pictureFormat.equalsIgnoreCase("jpeg"))) {
- try {
- exif.writeExif(jpeg, path);
- } catch (Exception e) {
- Log.e(TAG, "Failed to write data", e);
- }
- } else if (jpeg != null) {
- if (!(pictureFormat.equalsIgnoreCase("jpeg") || pictureFormat == null)) {
- File dir = new File(RAW_DIRECTORY);
- dir.mkdirs();
- }
- writeFile(path, jpeg);
- }
+ String path = generateFilepath(title, mimeType);
+ writeFile(path, jpeg, exif, mimeType);
return addImage(resolver, title, date, location, orientation,
- jpegLength, path, width, height, pictureFormat);
+ 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, String pictureFormat) {
+ String path, int width, int height, String mimeType) {
// Insert into MediaStore.
ContentValues values = new ContentValues(9);
values.put(ImageColumns.TITLE, title);
- if (pictureFormat.equalsIgnoreCase("jpeg") || pictureFormat == null) {
+ if (mimeType.equalsIgnoreCase("jpeg") || mimeType == null) {
values.put(ImageColumns.DISPLAY_NAME, title + ".jpg");
} else {
values.put(ImageColumns.DISPLAY_NAME, title + ".raw");
@@ -133,19 +134,54 @@ public class Storage {
values.put(ImageColumns.LATITUDE, location.getLatitude());
values.put(ImageColumns.LONGITUDE, location.getLongitude());
}
+ return values;
+ }
- Uri uri = null;
- try {
- uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
- } catch (Throwable th) {
- // This can happen when the external volume is already mounted, but
- // MediaScanner has not notify MediaProvider to add that volume.
- // The picture is still safe and MediaScanner will find it and
- // insert it into MediaProvider. The only problem is that the user
- // cannot click the thumbnail to review the picture.
- Log.e(TAG, "Failed to write MediaStore" + th);
+ // 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);
+
+ return insertImage(resolver, values);
+ }
+
+ // Overwrites the file and updates the MediaStore, or inserts the image if
+ // one does not already exist.
+ 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, mimeType);
+ writeFile(path, jpeg, exif, mimeType);
+ updateImage(imageUri, resolver, title, date, location, orientation, jpeg.length, path,
+ width, height, mimeType);
+ }
+
+ // Updates the image values in MediaStore, or inserts the image if one does
+ // not already exist.
+ 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 == 0) {
+ // If no prior row existed, insert a new one.
+ Log.w(TAG, "updateImage called with no prior image at uri: " + imageUri);
+ insertImage(resolver, values);
+ } else if (rowsModified != 1) {
+ // This should never happen
+ throw new IllegalStateException("Bad number of rows (" + rowsModified
+ + ") updated for uri: " + imageUri);
}
- return uri;
}
public static void deleteImage(ContentResolver resolver, Uri uri) {
@@ -199,4 +235,19 @@ public class Storage {
Log.e(TAG, "Failed to create " + nnnAAAAA.getPath());
}
}
+
+ private static Uri insertImage(ContentResolver resolver, ContentValues values) {
+ Uri uri = null;
+ try {
+ uri = resolver.insert(Images.Media.EXTERNAL_CONTENT_URI, values);
+ } catch (Throwable th) {
+ // This can happen when the external volume is already mounted, but
+ // MediaScanner has not notify MediaProvider to add that volume.
+ // The picture is still safe and MediaScanner will find it and
+ // insert it into MediaProvider. The only problem is that the user
+ // cannot click the thumbnail to review the picture.
+ Log.e(TAG, "Failed to write MediaStore" + th);
+ }
+ return uri;
+ }
}