Merge "Do not show title in car mode."
diff --git a/src/com/android/contacts/model/Sources.java b/src/com/android/contacts/model/Sources.java
index b6422fb..c786752 100644
--- a/src/com/android/contacts/model/Sources.java
+++ b/src/com/android/contacts/model/Sources.java
@@ -51,6 +51,7 @@
 public class Sources extends BroadcastReceiver implements OnAccountsUpdateListener {
     private static final String TAG = "Sources";
 
+    private Context mContext;
     private Context mApplicationContext;
     private AccountManager mAccountManager;
 
@@ -79,6 +80,7 @@
      * Internal constructor that only performs initial parsing.
      */
     private Sources(Context context) {
+        mContext = context;
         mApplicationContext = context.getApplicationContext();
         mAccountManager = AccountManager.get(mApplicationContext);
 
@@ -288,7 +290,7 @@
             return source;
         } else {
             // Not inflated, but requested that we force-inflate
-            source.ensureInflated(mApplicationContext, inflateLevel);
+            source.ensureInflated(mContext, inflateLevel);
             return source;
         }
     }
diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java
index 4f13028..01a9e12 100644
--- a/src/com/android/contacts/ui/EditContactActivity.java
+++ b/src/com/android/contacts/ui/EditContactActivity.java
@@ -55,6 +55,7 @@
 import android.content.ContentProviderOperation.Builder;
 import android.database.Cursor;
 import android.graphics.Bitmap;
+import android.media.MediaScannerConnection;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Environment;
@@ -84,9 +85,11 @@
 
 import java.io.File;
 import java.lang.ref.WeakReference;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 
 /**
  * Activity for editing or inserting a contact.
@@ -125,7 +128,10 @@
 
     private static final int ICON_SIZE = 96;
 
-    private static final String TEMP_FILENAME = "com.android.contacts.icon-temp.jpg";
+    private static final File PHOTO_DIR = new File(Environment.getExternalStorageDirectory(),
+            "com.android.contacts.icon");
+
+    private File mCurrentPhotoFile;
 
     String mQuerySelection;
 
@@ -552,7 +558,7 @@
             }
 
             case CAMERA_WITH_DATA: {
-                doCropPhoto();
+                doCropPhoto(mCurrentPhotoFile);
                 break;
             }
 
@@ -1017,12 +1023,23 @@
     }
 
     /**
-     * Launches Camera to take a picture and store it in a temporary file.
+     * Create a file name for the icon photo using current time.
+     */
+    private String getPhotoFileName() {
+        Date date = new Date(System.currentTimeMillis());
+        SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss");
+        return dateFormat.format(date) + ".jpg";
+    }
+
+    /**
+     * Launches Camera to take a picture and store it in a file.
      */
     protected void doTakePhoto() {
         try {
             // Launch camera to take photo for selected contact
-            final Intent intent = getTakePickIntent();
+            PHOTO_DIR.mkdirs();
+            mCurrentPhotoFile = new File(PHOTO_DIR, getPhotoFileName());
+            final Intent intent = getTakePickIntent(mCurrentPhotoFile);
             startActivityForResult(intent, CAMERA_WITH_DATA);
         } catch (ActivityNotFoundException e) {
             Toast.makeText(this, R.string.photoPickerNotFoundText, Toast.LENGTH_LONG).show();
@@ -1032,9 +1049,8 @@
     /**
      * Constructs an intent for capturing a photo and storing it in a temporary file.
      */
-    public static Intent getTakePickIntent() {
+    public static Intent getTakePickIntent(File f) {
         Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
-        final File f = new File(Environment.getExternalStorageDirectory(), TEMP_FILENAME);
         intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
         return intent;
     }
@@ -1042,19 +1058,18 @@
     /**
      * Sends a newly acquired photo to Gallery for cropping
      */
-    protected void doCropPhoto() {
+    protected void doCropPhoto(File f) {
         try {
 
             // Add the image to the media store
-            final File f = new File(Environment.getExternalStorageDirectory(), TEMP_FILENAME);
-            final String photoUri = MediaStore.Images.Media.insertImage(getContentResolver(),
-                    f.getAbsolutePath(), null, null);
-
-            // Delete the temporary file
-            f.delete();
+            MediaScannerConnection.scanFile(
+                    this,
+                    new String[] { f.getAbsolutePath() },
+                    new String[] { null },
+                    null);
 
             // Launch gallery to crop the photo
-            final Intent intent = getCropImageIntent(Uri.parse(photoUri));
+            final Intent intent = getCropImageIntent(Uri.fromFile(f));
             startActivityForResult(intent, PHOTO_PICKED_WITH_DATA);
         } catch (Exception e) {
             Log.e(TAG, "Cannot crop image", e);