diff options
| author | Chih-Chung Chang <chihchung@google.com> | 2011-10-11 16:42:42 +0800 |
|---|---|---|
| committer | Chih-Chung Chang <chihchung@google.com> | 2011-10-11 16:43:34 +0800 |
| commit | ee740f1254232cbe5b8dd34c0c957866c03e7787 (patch) | |
| tree | ed152f6bb45005b214e5073cd3b00945d381fe30 | |
| parent | 5e99c7f1f5c07d9b728c301a5746cb15b65124fb (diff) | |
| download | LegacyCamera-ee740f1254232cbe5b8dd34c0c957866c03e7787.zip LegacyCamera-ee740f1254232cbe5b8dd34c0c957866c03e7787.tar.gz LegacyCamera-ee740f1254232cbe5b8dd34c0c957866c03e7787.tar.bz2 | |
Fix 5429468: Append _1, _2, etc to the file name in the same second.
Change-Id: I68ca915eee4e343fa1b90fef068fecb9c919aa53
| -rw-r--r-- | src/com/android/camera/Util.java | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 61a55dd..768bf27 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -79,7 +79,7 @@ public class Util { private static boolean sIsTabletUI; private static float sPixelDensity = 1; - private static String sImageFileNameFormat; + private static ImageFileNamer sImageFileNamer; private Util() { } @@ -92,8 +92,8 @@ public class Util { context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); sPixelDensity = metrics.density; - - sImageFileNameFormat = context.getString(R.string.image_file_name_format); + sImageFileNamer = new ImageFileNamer( + context.getString(R.string.image_file_name_format)); } public static boolean isTabletUI() { @@ -517,9 +517,9 @@ public class Util { } public static String createJpegName(long dateTaken) { - Date date = new Date(dateTaken); - SimpleDateFormat dateFormat = new SimpleDateFormat(sImageFileNameFormat); - return dateFormat.format(date); + synchronized (sImageFileNamer) { + return sImageFileNamer.generateName(dateTaken); + } } public static void broadcastNewPicture(Context context, Uri uri) { @@ -615,4 +615,35 @@ public class Util { win.setAttributes(winParams); } } + + private static class ImageFileNamer { + private SimpleDateFormat mFormat; + + // The date (in milliseconds) used to generate the last name. + private long mLastDate; + + // Number of names generated for the same second. + private int mSameSecondCount; + + public ImageFileNamer(String format) { + mFormat = new SimpleDateFormat(format); + } + + public String generateName(long dateTaken) { + Date date = new Date(dateTaken); + String result = mFormat.format(date); + + // If the last name was generated for the same second, + // we append _1, _2, etc to the name. + if (dateTaken / 1000 == mLastDate / 1000) { + mSameSecondCount++; + result += "_" + mSameSecondCount; + } else { + mLastDate = dateTaken; + mSameSecondCount = 0; + } + + return result; + } + } } |
