summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2011-10-11 02:00:57 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-11 02:00:57 -0700
commitb0e8c4a25504bc9ffdc8c48b724230d4d41d83a6 (patch)
tree7808ed666b04a5bdd001876dc325f7f1b874561a /src
parent75e164e060723ea5803dbbb828e5ec4f6e8142e3 (diff)
parentee740f1254232cbe5b8dd34c0c957866c03e7787 (diff)
downloadLegacyCamera-b0e8c4a25504bc9ffdc8c48b724230d4d41d83a6.zip
LegacyCamera-b0e8c4a25504bc9ffdc8c48b724230d4d41d83a6.tar.gz
LegacyCamera-b0e8c4a25504bc9ffdc8c48b724230d4d41d83a6.tar.bz2
Merge "Fix 5429468: Append _1, _2, etc to the file name in the same second."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/camera/Util.java43
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;
+ }
+ }
}