Util.java revision aaf129e4b755e4eef9eaa0fd736a9bbd20904fc8
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.camera; 18 19import android.app.Activity; 20import android.app.AlertDialog; 21import android.app.admin.DevicePolicyManager; 22import android.content.ActivityNotFoundException; 23import android.content.ContentResolver; 24import android.content.Context; 25import android.content.DialogInterface; 26import android.content.Intent; 27import android.graphics.Bitmap; 28import android.graphics.BitmapFactory; 29import android.graphics.Matrix; 30import android.graphics.Point; 31import android.graphics.Rect; 32import android.graphics.RectF; 33import android.hardware.Camera; 34import android.hardware.Camera.CameraInfo; 35import android.hardware.Camera.Parameters; 36import android.hardware.Camera.Size; 37import android.location.Location; 38import android.net.Uri; 39import android.os.Build; 40import android.os.ParcelFileDescriptor; 41import android.telephony.TelephonyManager; 42import android.util.DisplayMetrics; 43import android.util.FloatMath; 44import android.util.Log; 45import android.view.Display; 46import android.view.OrientationEventListener; 47import android.view.Surface; 48import android.view.View; 49import android.view.Window; 50import android.view.WindowManager; 51import android.view.animation.AlphaAnimation; 52import android.view.animation.Animation; 53 54import java.io.Closeable; 55import java.io.IOException; 56import java.lang.reflect.Method; 57import java.text.SimpleDateFormat; 58import java.util.Date; 59import java.util.List; 60import java.util.StringTokenizer; 61 62/** 63 * Collection of utility functions used in this package. 64 */ 65public class Util { 66 private static final String TAG = "Util"; 67 68 // Orientation hysteresis amount used in rounding, in degrees 69 public static final int ORIENTATION_HYSTERESIS = 5; 70 71 public static final String REVIEW_ACTION = "com.android.camera.action.REVIEW"; 72 73 // Private intent extras. Test only. 74 private static final String EXTRAS_CAMERA_FACING = 75 "android.intent.extras.CAMERA_FACING"; 76 77 private static boolean sIsTabletUI; 78 private static float sPixelDensity = 1; 79 private static ImageFileNamer sImageFileNamer; 80 81 private Util() { 82 } 83 84 public static void initialize(Context context) { 85 sIsTabletUI = (context.getResources().getConfiguration().smallestScreenWidthDp >= 600); 86 87 DisplayMetrics metrics = new DisplayMetrics(); 88 WindowManager wm = (WindowManager) 89 context.getSystemService(Context.WINDOW_SERVICE); 90 wm.getDefaultDisplay().getMetrics(metrics); 91 sPixelDensity = metrics.density; 92 sImageFileNamer = new ImageFileNamer( 93 context.getString(R.string.image_file_name_format)); 94 } 95 96 public static boolean isTabletUI() { 97 return sIsTabletUI; 98 } 99 100 public static int dpToPixel(int dp) { 101 return Math.round(sPixelDensity * dp); 102 } 103 104 // Rotates the bitmap by the specified degree. 105 // If a new bitmap is created, the original bitmap is recycled. 106 public static Bitmap rotate(Bitmap b, int degrees) { 107 return rotateAndMirror(b, degrees, false); 108 } 109 110 // Rotates and/or mirrors the bitmap. If a new bitmap is created, the 111 // original bitmap is recycled. 112 public static Bitmap rotateAndMirror(Bitmap b, int degrees, boolean mirror) { 113 if ((degrees != 0 || mirror) && b != null) { 114 Matrix m = new Matrix(); 115 // Mirror first. 116 // horizontal flip + rotation = -rotation + horizontal flip 117 if (mirror) { 118 m.postScale(-1, 1); 119 degrees = (degrees + 360) % 360; 120 if (degrees == 0 || degrees == 180) { 121 m.postTranslate(b.getWidth(), 0); 122 } else if (degrees == 90 || degrees == 270) { 123 m.postTranslate(b.getHeight(), 0); 124 } else { 125 throw new IllegalArgumentException("Invalid degrees=" + degrees); 126 } 127 } 128 if (degrees != 0) { 129 // clockwise 130 m.postRotate(degrees, 131 (float) b.getWidth() / 2, (float) b.getHeight() / 2); 132 } 133 134 try { 135 Bitmap b2 = Bitmap.createBitmap( 136 b, 0, 0, b.getWidth(), b.getHeight(), m, true); 137 if (b != b2) { 138 b.recycle(); 139 b = b2; 140 } 141 } catch (OutOfMemoryError ex) { 142 // We have no memory to rotate. Return the original bitmap. 143 } 144 } 145 return b; 146 } 147 148 /* 149 * Compute the sample size as a function of minSideLength 150 * and maxNumOfPixels. 151 * minSideLength is used to specify that minimal width or height of a 152 * bitmap. 153 * maxNumOfPixels is used to specify the maximal size in pixels that is 154 * tolerable in terms of memory usage. 155 * 156 * The function returns a sample size based on the constraints. 157 * Both size and minSideLength can be passed in as -1 158 * which indicates no care of the corresponding constraint. 159 * The functions prefers returning a sample size that 160 * generates a smaller bitmap, unless minSideLength = -1. 161 * 162 * Also, the function rounds up the sample size to a power of 2 or multiple 163 * of 8 because BitmapFactory only honors sample size this way. 164 * For example, BitmapFactory downsamples an image by 2 even though the 165 * request is 3. So we round up the sample size to avoid OOM. 166 */ 167 public static int computeSampleSize(BitmapFactory.Options options, 168 int minSideLength, int maxNumOfPixels) { 169 int initialSize = computeInitialSampleSize(options, minSideLength, 170 maxNumOfPixels); 171 172 int roundedSize; 173 if (initialSize <= 8) { 174 roundedSize = 1; 175 while (roundedSize < initialSize) { 176 roundedSize <<= 1; 177 } 178 } else { 179 roundedSize = (initialSize + 7) / 8 * 8; 180 } 181 182 return roundedSize; 183 } 184 185 private static int computeInitialSampleSize(BitmapFactory.Options options, 186 int minSideLength, int maxNumOfPixels) { 187 double w = options.outWidth; 188 double h = options.outHeight; 189 190 int lowerBound = (maxNumOfPixels < 0) ? 1 : 191 (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); 192 int upperBound = (minSideLength < 0) ? 128 : 193 (int) Math.min(Math.floor(w / minSideLength), 194 Math.floor(h / minSideLength)); 195 196 if (upperBound < lowerBound) { 197 // return the larger one when there is no overlapping zone. 198 return lowerBound; 199 } 200 201 if (maxNumOfPixels < 0 && minSideLength < 0) { 202 return 1; 203 } else if (minSideLength < 0) { 204 return lowerBound; 205 } else { 206 return upperBound; 207 } 208 } 209 210 public static Bitmap makeBitmap(byte[] jpegData, int maxNumOfPixels) { 211 try { 212 BitmapFactory.Options options = new BitmapFactory.Options(); 213 options.inJustDecodeBounds = true; 214 BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, 215 options); 216 if (options.mCancel || options.outWidth == -1 217 || options.outHeight == -1) { 218 return null; 219 } 220 options.inSampleSize = computeSampleSize( 221 options, -1, maxNumOfPixels); 222 options.inJustDecodeBounds = false; 223 224 options.inDither = false; 225 options.inPreferredConfig = Bitmap.Config.ARGB_8888; 226 return BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, 227 options); 228 } catch (OutOfMemoryError ex) { 229 Log.e(TAG, "Got oom exception ", ex); 230 return null; 231 } 232 } 233 234 public static void closeSilently(Closeable c) { 235 if (c == null) return; 236 try { 237 c.close(); 238 } catch (Throwable t) { 239 // do nothing 240 } 241 } 242 243 public static void Assert(boolean cond) { 244 if (!cond) { 245 throw new AssertionError(); 246 } 247 } 248 249 public static CameraManager.CameraProxy openCamera(Activity activity, int cameraId) 250 throws CameraHardwareException, CameraDisabledException { 251 // Check if device policy has disabled the camera. 252 DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService( 253 Context.DEVICE_POLICY_SERVICE); 254 if (dpm.getCameraDisabled(null)) { 255 throw new CameraDisabledException(); 256 } 257 258 try { 259 return CameraHolder.instance().open(cameraId); 260 } catch (CameraHardwareException e) { 261 // In eng build, we throw the exception so that test tool 262 // can detect it and report it 263 if ("eng".equals(Build.TYPE)) { 264 throw new RuntimeException("openCamera failed", e); 265 } else { 266 throw e; 267 } 268 } 269 } 270 271 public static void showErrorAndFinish(final Activity activity, int msgId) { 272 DialogInterface.OnClickListener buttonListener = 273 new DialogInterface.OnClickListener() { 274 @Override 275 public void onClick(DialogInterface dialog, int which) { 276 activity.finish(); 277 } 278 }; 279 new AlertDialog.Builder(activity) 280 .setCancelable(false) 281 .setIconAttribute(android.R.attr.alertDialogIcon) 282 .setTitle(R.string.camera_error_title) 283 .setMessage(msgId) 284 .setNeutralButton(R.string.dialog_ok, buttonListener) 285 .show(); 286 } 287 288 public static <T> T checkNotNull(T object) { 289 if (object == null) throw new NullPointerException(); 290 return object; 291 } 292 293 public static boolean equals(Object a, Object b) { 294 return (a == b) || (a == null ? false : a.equals(b)); 295 } 296 297 public static int nextPowerOf2(int n) { 298 n -= 1; 299 n |= n >>> 16; 300 n |= n >>> 8; 301 n |= n >>> 4; 302 n |= n >>> 2; 303 n |= n >>> 1; 304 return n + 1; 305 } 306 307 public static float distance(float x, float y, float sx, float sy) { 308 float dx = x - sx; 309 float dy = y - sy; 310 return FloatMath.sqrt(dx * dx + dy * dy); 311 } 312 313 public static int clamp(int x, int min, int max) { 314 if (x > max) return max; 315 if (x < min) return min; 316 return x; 317 } 318 319 public static int getDisplayRotation(Activity activity) { 320 int rotation = activity.getWindowManager().getDefaultDisplay() 321 .getRotation(); 322 switch (rotation) { 323 case Surface.ROTATION_0: return 0; 324 case Surface.ROTATION_90: return 90; 325 case Surface.ROTATION_180: return 180; 326 case Surface.ROTATION_270: return 270; 327 } 328 return 0; 329 } 330 331 public static int getDisplayOrientation(int degrees, int cameraId) { 332 // See android.hardware.Camera.setDisplayOrientation for 333 // documentation. 334 Camera.CameraInfo info = new Camera.CameraInfo(); 335 Camera.getCameraInfo(cameraId, info); 336 int result; 337 if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 338 result = (info.orientation + degrees) % 360; 339 result = (360 - result) % 360; // compensate the mirror 340 } else { // back-facing 341 result = (info.orientation - degrees + 360) % 360; 342 } 343 return result; 344 } 345 346 public static int getCameraOrientation(int cameraId) { 347 Camera.CameraInfo info = new Camera.CameraInfo(); 348 Camera.getCameraInfo(cameraId, info); 349 return info.orientation; 350 } 351 352 public static int roundOrientation(int orientation, int orientationHistory) { 353 boolean changeOrientation = false; 354 if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) { 355 changeOrientation = true; 356 } else { 357 int dist = Math.abs(orientation - orientationHistory); 358 dist = Math.min( dist, 360 - dist ); 359 changeOrientation = ( dist >= 45 + ORIENTATION_HYSTERESIS ); 360 } 361 if (changeOrientation) { 362 return ((orientation + 45) / 90 * 90) % 360; 363 } 364 return orientationHistory; 365 } 366 367 public static Size getOptimalPreviewSize(Activity currentActivity, 368 List<Size> sizes, double targetRatio) { 369 // Use a very small tolerance because we want an exact match. 370 final double ASPECT_TOLERANCE = 0.001; 371 if (sizes == null) return null; 372 373 Size optimalSize = null; 374 double minDiff = Double.MAX_VALUE; 375 376 // Because of bugs of overlay and layout, we sometimes will try to 377 // layout the viewfinder in the portrait orientation and thus get the 378 // wrong size of preview surface. When we change the preview size, the 379 // new overlay will be created before the old one closed, which causes 380 // an exception. For now, just get the screen size. 381 Display display = currentActivity.getWindowManager().getDefaultDisplay(); 382 Point point = new Point(); 383 display.getSize(point); 384 int targetHeight = Math.min(point.x, point.y); 385 386 // Try to find an size match aspect ratio and size 387 for (Size size : sizes) { 388 double ratio = (double) size.width / size.height; 389 if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; 390 if (Math.abs(size.height - targetHeight) < minDiff) { 391 optimalSize = size; 392 minDiff = Math.abs(size.height - targetHeight); 393 } 394 } 395 396 // Cannot find the one match the aspect ratio. This should not happen. 397 // Ignore the requirement. 398 if (optimalSize == null) { 399 Log.w(TAG, "No preview size match the aspect ratio"); 400 minDiff = Double.MAX_VALUE; 401 for (Size size : sizes) { 402 if (Math.abs(size.height - targetHeight) < minDiff) { 403 optimalSize = size; 404 minDiff = Math.abs(size.height - targetHeight); 405 } 406 } 407 } 408 return optimalSize; 409 } 410 411 // Returns the largest picture size which matches the given aspect ratio. 412 public static Size getOptimalVideoSnapshotPictureSize( 413 List<Size> sizes, double targetRatio) { 414 // Use a very small tolerance because we want an exact match. 415 final double ASPECT_TOLERANCE = 0.001; 416 if (sizes == null) return null; 417 418 Size optimalSize = null; 419 420 // Try to find a size matches aspect ratio and has the largest width 421 for (Size size : sizes) { 422 double ratio = (double) size.width / size.height; 423 if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; 424 if (optimalSize == null || size.width > optimalSize.width) { 425 optimalSize = size; 426 } 427 } 428 429 // Cannot find one that matches the aspect ratio. This should not happen. 430 // Ignore the requirement. 431 if (optimalSize == null) { 432 Log.w(TAG, "No picture size match the aspect ratio"); 433 for (Size size : sizes) { 434 if (optimalSize == null || size.width > optimalSize.width) { 435 optimalSize = size; 436 } 437 } 438 } 439 return optimalSize; 440 } 441 442 public static void dumpParameters(Parameters parameters) { 443 String flattened = parameters.flatten(); 444 StringTokenizer tokenizer = new StringTokenizer(flattened, ";"); 445 Log.d(TAG, "Dump all camera parameters:"); 446 while (tokenizer.hasMoreElements()) { 447 Log.d(TAG, tokenizer.nextToken()); 448 } 449 } 450 451 /** 452 * Returns whether the device is voice-capable (meaning, it can do MMS). 453 */ 454 public static boolean isMmsCapable(Context context) { 455 TelephonyManager telephonyManager = (TelephonyManager) 456 context.getSystemService(Context.TELEPHONY_SERVICE); 457 if (telephonyManager == null) { 458 return false; 459 } 460 461 try { 462 Class<?> partypes[] = new Class[0]; 463 Method sIsVoiceCapable = TelephonyManager.class.getMethod( 464 "isVoiceCapable", partypes); 465 466 Object arglist[] = new Object[0]; 467 Object retobj = sIsVoiceCapable.invoke(telephonyManager, arglist); 468 return (Boolean) retobj; 469 } catch (java.lang.reflect.InvocationTargetException ite) { 470 // Failure, must be another device. 471 // Assume that it is voice capable. 472 } catch (IllegalAccessException iae) { 473 // Failure, must be an other device. 474 // Assume that it is voice capable. 475 } catch (NoSuchMethodException nsme) { 476 } 477 return true; 478 } 479 480 // This is for test only. Allow the camera to launch the specific camera. 481 public static int getCameraFacingIntentExtras(Activity currentActivity) { 482 int cameraId = -1; 483 484 int intentCameraId = 485 currentActivity.getIntent().getIntExtra(Util.EXTRAS_CAMERA_FACING, -1); 486 487 if (isFrontCameraIntent(intentCameraId)) { 488 // Check if the front camera exist 489 int frontCameraId = CameraHolder.instance().getFrontCameraId(); 490 if (frontCameraId != -1) { 491 cameraId = frontCameraId; 492 } 493 } else if (isBackCameraIntent(intentCameraId)) { 494 // Check if the back camera exist 495 int backCameraId = CameraHolder.instance().getBackCameraId(); 496 if (backCameraId != -1) { 497 cameraId = backCameraId; 498 } 499 } 500 return cameraId; 501 } 502 503 private static boolean isFrontCameraIntent(int intentCameraId) { 504 return (intentCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); 505 } 506 507 private static boolean isBackCameraIntent(int intentCameraId) { 508 return (intentCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); 509 } 510 511 private static int mLocation[] = new int[2]; 512 513 // This method is not thread-safe. 514 public static boolean pointInView(float x, float y, View v) { 515 v.getLocationInWindow(mLocation); 516 return x >= mLocation[0] && x < (mLocation[0] + v.getWidth()) 517 && y >= mLocation[1] && y < (mLocation[1] + v.getHeight()); 518 } 519 520 public static boolean isUriValid(Uri uri, ContentResolver resolver) { 521 if (uri == null) return false; 522 523 try { 524 ParcelFileDescriptor pfd = resolver.openFileDescriptor(uri, "r"); 525 if (pfd == null) { 526 Log.e(TAG, "Fail to open URI. URI=" + uri); 527 return false; 528 } 529 pfd.close(); 530 } catch (IOException ex) { 531 return false; 532 } 533 return true; 534 } 535 536 public static void viewUri(Uri uri, Context context) { 537 if (!isUriValid(uri, context.getContentResolver())) { 538 Log.e(TAG, "Uri invalid. uri=" + uri); 539 return; 540 } 541 542 try { 543 context.startActivity(new Intent(Util.REVIEW_ACTION, uri)); 544 } catch (ActivityNotFoundException ex) { 545 try { 546 context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); 547 } catch (ActivityNotFoundException e) { 548 Log.e(TAG, "review image fail. uri=" + uri, e); 549 } 550 } 551 } 552 553 public static void dumpRect(RectF rect, String msg) { 554 Log.v(TAG, msg + "=(" + rect.left + "," + rect.top 555 + "," + rect.right + "," + rect.bottom + ")"); 556 } 557 558 public static void rectFToRect(RectF rectF, Rect rect) { 559 rect.left = Math.round(rectF.left); 560 rect.top = Math.round(rectF.top); 561 rect.right = Math.round(rectF.right); 562 rect.bottom = Math.round(rectF.bottom); 563 } 564 565 public static void prepareMatrix(Matrix matrix, boolean mirror, int displayOrientation, 566 int viewWidth, int viewHeight) { 567 // Need mirror for front camera. 568 matrix.setScale(mirror ? -1 : 1, 1); 569 // This is the value for android.hardware.Camera.setDisplayOrientation. 570 matrix.postRotate(displayOrientation); 571 // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). 572 // UI coordinates range from (0, 0) to (width, height). 573 matrix.postScale(viewWidth / 2000f, viewHeight / 2000f); 574 matrix.postTranslate(viewWidth / 2f, viewHeight / 2f); 575 } 576 577 public static String createJpegName(long dateTaken) { 578 synchronized (sImageFileNamer) { 579 return sImageFileNamer.generateName(dateTaken); 580 } 581 } 582 583 public static void broadcastNewPicture(Context context, Uri uri) { 584 context.sendBroadcast(new Intent(android.hardware.Camera.ACTION_NEW_PICTURE, uri)); 585 // Keep compatibility 586 context.sendBroadcast(new Intent("com.android.camera.NEW_PICTURE", uri)); 587 } 588 589 public static void fadeIn(View view, float startAlpha, float endAlpha, long duration) { 590 if (view.getVisibility() == View.VISIBLE) return; 591 592 view.setVisibility(View.VISIBLE); 593 Animation animation = new AlphaAnimation(startAlpha, endAlpha); 594 animation.setDuration(duration); 595 view.startAnimation(animation); 596 } 597 598 public static void fadeIn(View view) { 599 fadeIn(view, 0F, 1F, 400); 600 601 // We disabled the button in fadeOut(), so enable it here. 602 view.setEnabled(true); 603 } 604 605 public static void fadeOut(View view) { 606 if (view.getVisibility() != View.VISIBLE) return; 607 608 // Since the button is still clickable before fade-out animation 609 // ends, we disable the button first to block click. 610 view.setEnabled(false); 611 Animation animation = new AlphaAnimation(1F, 0F); 612 animation.setDuration(400); 613 view.startAnimation(animation); 614 view.setVisibility(View.GONE); 615 } 616 617 public static void setRotationParameter(Parameters parameters, int cameraId, int orientation) { 618 // See android.hardware.Camera.Parameters.setRotation for 619 // documentation. 620 int rotation = 0; 621 if (orientation != OrientationEventListener.ORIENTATION_UNKNOWN) { 622 CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId]; 623 if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { 624 rotation = (info.orientation - orientation + 360) % 360; 625 } else { // back-facing camera 626 rotation = (info.orientation + orientation) % 360; 627 } 628 } 629 parameters.setRotation(rotation); 630 } 631 632 public static void setGpsParameters(Parameters parameters, Location loc) { 633 // Clear previous GPS location from the parameters. 634 parameters.removeGpsData(); 635 636 // We always encode GpsTimeStamp 637 parameters.setGpsTimestamp(System.currentTimeMillis() / 1000); 638 639 // Set GPS location. 640 if (loc != null) { 641 double lat = loc.getLatitude(); 642 double lon = loc.getLongitude(); 643 boolean hasLatLon = (lat != 0.0d) || (lon != 0.0d); 644 645 if (hasLatLon) { 646 Log.d(TAG, "Set gps location"); 647 parameters.setGpsLatitude(lat); 648 parameters.setGpsLongitude(lon); 649 parameters.setGpsProcessingMethod(loc.getProvider().toUpperCase()); 650 if (loc.hasAltitude()) { 651 parameters.setGpsAltitude(loc.getAltitude()); 652 } else { 653 // for NETWORK_PROVIDER location provider, we may have 654 // no altitude information, but the driver needs it, so 655 // we fake one. 656 parameters.setGpsAltitude(0); 657 } 658 if (loc.getTime() != 0) { 659 // Location.getTime() is UTC in milliseconds. 660 // gps-timestamp is UTC in seconds. 661 long utcTimeSeconds = loc.getTime() / 1000; 662 parameters.setGpsTimestamp(utcTimeSeconds); 663 } 664 } else { 665 loc = null; 666 } 667 } 668 } 669 670 public static void enterLightsOutMode(Window window) { 671 WindowManager.LayoutParams params = window.getAttributes(); 672 params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE; 673 window.setAttributes(params); 674 } 675 676 private static class ImageFileNamer { 677 private SimpleDateFormat mFormat; 678 679 // The date (in milliseconds) used to generate the last name. 680 private long mLastDate; 681 682 // Number of names generated for the same second. 683 private int mSameSecondCount; 684 685 public ImageFileNamer(String format) { 686 mFormat = new SimpleDateFormat(format); 687 } 688 689 public String generateName(long dateTaken) { 690 Date date = new Date(dateTaken); 691 String result = mFormat.format(date); 692 693 // If the last name was generated for the same second, 694 // we append _1, _2, etc to the name. 695 if (dateTaken / 1000 == mLastDate / 1000) { 696 mSameSecondCount++; 697 result += "_" + mSameSecondCount; 698 } else { 699 mLastDate = dateTaken; 700 mSameSecondCount = 0; 701 } 702 703 return result; 704 } 705 } 706} 707