diff options
author | Steve Kondik <steve@cyngn.com> | 2015-10-17 23:40:33 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-17 23:40:33 -0700 |
commit | bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398 (patch) | |
tree | 85d07b2095695fe79235ab16e627f8b22c7bfd8d /gallerycommon/src/com/android | |
parent | a3fcd50080c0546ebd5f0caf932eef02fabdd7ad (diff) | |
parent | 8de528917bf03cca93ac2a3dd19b7a5719d1a26e (diff) | |
download | android_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.tar.gz android_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.tar.bz2 android_packages_apps_Gallery2-bcbf7c98a521b9ee4a7d03e00dcfc469c9b3a398.zip |
Merge branch 'cm-12.1' of git://github.com/CyanogenMod/android_packages_apps_Gallery2 into cm-13.0
Change-Id: Ib8caa024d2e6feca332e3645038f226fd5a910a2
Diffstat (limited to 'gallerycommon/src/com/android')
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java | 20 | ||||
-rw-r--r-- | gallerycommon/src/com/android/gallery3d/exif/ExifTag.java | 43 |
2 files changed, 37 insertions, 26 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java index a1cf0fc85..21422095e 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifInterface.java @@ -318,6 +318,13 @@ public class ExifInterface { public static final int TAG_INTEROPERABILITY_INDEX = defineTag(IfdId.TYPE_IFD_INTEROPERABILITY, (short) 1); + private static final String GPS_DATE_FORMAT_STR = "yyyy:MM:dd"; + private static final String DATETIME_FORMAT_STR = "yyyy:MM:dd kk:mm:ss"; + public static final DateFormat DATETIME_FORMAT = new SimpleDateFormat(DATETIME_FORMAT_STR); + private final DateFormat mGPSDateStampFormat = new SimpleDateFormat(GPS_DATE_FORMAT_STR); + private final Calendar mGPSTimeStampCalendar = Calendar + .getInstance(TimeZone.getTimeZone("UTC")); + /** * Tags that contain offset markers. These are included in the banned * defines. @@ -732,7 +739,7 @@ public class ExifInterface { * @param inStream an InputStream containing a jpeg compressed image. * @throws IOException */ - public void readExif(InputStream inStream) throws IOException { + public void readExif(InputStream inStream) throws IOException, NullPointerException { if (inStream == null) { throw new IllegalArgumentException(NULL_ARGUMENT_STRING); } @@ -1944,13 +1951,6 @@ public class ExifInterface { return latLon; } - private static final String GPS_DATE_FORMAT_STR = "yyyy:MM:dd"; - private static final String DATETIME_FORMAT_STR = "yyyy:MM:dd kk:mm:ss"; - private final DateFormat mDateTimeStampFormat = new SimpleDateFormat(DATETIME_FORMAT_STR); - private final DateFormat mGPSDateStampFormat = new SimpleDateFormat(GPS_DATE_FORMAT_STR); - private final Calendar mGPSTimeStampCalendar = Calendar - .getInstance(TimeZone.getTimeZone("UTC")); - /** * Creates, formats, and sets the DateTimeStamp tag for one of: * {@link #TAG_DATE_TIME}, {@link #TAG_DATE_TIME_DIGITIZED}, @@ -1964,8 +1964,8 @@ public class ExifInterface { public boolean addDateTimeStampTag(int tagId, long timestamp, TimeZone timezone) { if (tagId == TAG_DATE_TIME || tagId == TAG_DATE_TIME_DIGITIZED || tagId == TAG_DATE_TIME_ORIGINAL) { - mDateTimeStampFormat.setTimeZone(timezone); - ExifTag t = buildTag(tagId, mDateTimeStampFormat.format(timestamp)); + DATETIME_FORMAT.setTimeZone(timezone); + ExifTag t = buildTag(tagId, DATETIME_FORMAT.format(timestamp)); if (t == null) { return false; } diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java index b8b387201..186cb81cf 100644 --- a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java +++ b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java @@ -17,7 +17,6 @@ package com.android.gallery3d.exif; import java.nio.charset.Charset; -import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; @@ -102,8 +101,6 @@ public class ExifTag { // Value offset in exif header. private int mOffset; - private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy:MM:dd kk:mm:ss"); - /** * Returns true if the given IFD is a valid IFD. */ @@ -314,13 +311,17 @@ public class ExifTag { * Sets a string value into this tag. This method should be used for tags of * type {@link #TYPE_ASCII}. The string is converted to an ASCII string. * Characters that cannot be converted are replaced with '?'. The length of - * the string must be equal to either (component count -1) or (component - * count). The final byte will be set to the string null terminator '\0', - * overwriting the last character in the string if the value.length is equal - * to the component count. This method will fail if: + * the string must be equal to either + * <ul> + * <li>component count - 1 when the terminating '\0' is not present</li> + * <li>component count when the terminating '\0' is present</li> + * <li>to comply with some non-conformant implementations, the terminating + * '\0' will be appended if it's not present and component count equals + * the string length; the component count will be updated in that case</li> + * This method will fail if: * <ul> * <li>The data type is not {@link #TYPE_ASCII} or {@link #TYPE_UNDEFINED}.</li> - * <li>The length of the string is not equal to (component count -1) or + * <li>The length of the string is not equal to (component count - 1) or * (component count) in the definition for this tag.</li> * </ul> */ @@ -331,11 +332,20 @@ public class ExifTag { byte[] buf = value.getBytes(US_ASCII); byte[] finalBuf = buf; - if (buf.length > 0) { - finalBuf = (buf[buf.length - 1] == 0 || mDataType == TYPE_UNDEFINED) ? buf : Arrays - .copyOf(buf, buf.length + 1); - } else if (mDataType == TYPE_ASCII && mComponentCountActual == 1) { - finalBuf = new byte[] { 0 }; + if (mDataType == TYPE_ASCII) { + if (buf.length > 0) { + if (buf[buf.length - 1] != 0) { + finalBuf = Arrays.copyOf(buf, buf.length + 1); + // Apply the workaround for non conformant implementations + // (e.g. Samsung Wave 2): Accept a string with missing + // termination character + if (mComponentCountActual == buf.length) { + mComponentCountActual++; + } + } + } else if (mComponentCountActual == 1) { + finalBuf = new byte[] { 0 }; + } } int count = finalBuf.length; if (checkBadComponentCount(count)) { @@ -524,9 +534,10 @@ public class ExifTag { * @return true on success */ public boolean setTimeValue(long time) { - // synchronized on TIME_FORMAT as SimpleDateFormat is not thread safe - synchronized (TIME_FORMAT) { - return setValue(TIME_FORMAT.format(new Date(time))); + // synchronized on DATETIME_FORMAT as SimpleDateFormat is not thread + // safe + synchronized (ExifInterface.DATETIME_FORMAT) { + return setValue(ExifInterface.DATETIME_FORMAT.format(new Date(time))); } } |