diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-08-17 15:54:18 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-08-17 19:43:24 +0800 |
commit | 099397cbd07c8c991f3126d0d0ac64bb6b3c0b47 (patch) | |
tree | e882349f9b36c9a0ba4ae187af41f8cd5fc123c8 /media | |
parent | 8af2d22552c61d8d4e09e52287f056428172ab05 (diff) | |
download | frameworks_base-099397cbd07c8c991f3126d0d0ac64bb6b3c0b47.zip frameworks_base-099397cbd07c8c991f3126d0d0ac64bb6b3c0b47.tar.gz frameworks_base-099397cbd07c8c991f3126d0d0ac64bb6b3c0b47.tar.bz2 |
Fix 1860351: Put datetime in jpeg exif to datetaken field.
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/ExifInterface.java | 27 | ||||
-rw-r--r-- | media/java/android/media/MediaScanner.java | 5 |
2 files changed, 31 insertions, 1 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index 6d7c0ae..d578c81 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -18,6 +18,9 @@ package android.media; import android.util.Log; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -59,7 +62,7 @@ public class ExifInterface { // The Exif tag names public static final String TAG_ORIENTATION = "Orientation"; - public static final String TAG_DATE_TIME_ORIGINAL = "DateTimeOriginal"; + public static final String TAG_DATETIME = "DateTime"; public static final String TAG_MAKE = "Make"; public static final String TAG_MODEL = "Model"; public static final String TAG_FLASH = "Flash"; @@ -321,6 +324,28 @@ public class ExifInterface { return latlng; } + private static SimpleDateFormat sFormatter = + new SimpleDateFormat("yyyy:MM:dd HH:mm:ss"); + + // Returns number of milliseconds since Jan. 1, 1970, midnight GMT. + // Returns -1 if the date time information if not available. + public static long getDateTime(HashMap<String, String> exifData) { + if (exifData == null) { + return -1; + } + + String dateTimeString = exifData.get(ExifInterface.TAG_DATETIME); + if (dateTimeString == null) return -1; + + ParsePosition pos = new ParsePosition(0); + try { + Date date = sFormatter.parse(dateTimeString, pos); + return date.getTime(); + } catch (IllegalArgumentException ex) { + return -1; + } + } + public static float convertRationalLatLonToFloat( String rationalString, String ref) { try { diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java index 376057e..3d5aae3 100644 --- a/media/java/android/media/MediaScanner.java +++ b/media/java/android/media/MediaScanner.java @@ -720,6 +720,11 @@ public class MediaScanner values.put(Images.Media.LATITUDE, latlng[0]); values.put(Images.Media.LONGITUDE, latlng[1]); } + + long time = ExifInterface.getDateTime(exifData); + if (time != -1) { + values.put(Images.Media.DATE_TAKEN, time); + } } } |