merge in klp-release history after reset to klp-dev
diff --git a/src/com/android/contacts/model/RawContactModifier.java b/src/com/android/contacts/model/RawContactModifier.java
index f1f5697..5f8b410 100644
--- a/src/com/android/contacts/model/RawContactModifier.java
+++ b/src/com/android/contacts/model/RawContactModifier.java
@@ -58,6 +58,7 @@
 import com.android.contacts.common.model.account.AccountType.EventEditType;
 import com.android.contacts.common.model.account.GoogleAccountType;
 import com.android.contacts.common.model.dataitem.DataKind;
+import com.android.contacts.model.dataitem.PhoneDataItem;
 import com.android.contacts.model.dataitem.StructuredNameDataItem;
 import com.android.contacts.util.DateUtils;
 import com.android.contacts.util.NameConverter;
@@ -693,6 +694,16 @@
             // Won't override the contact name
             if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 continue;
+            } else if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) {
+                values.remove(PhoneDataItem.KEY_FORMATTED_PHONE_NUMBER);
+                final Integer type = values.getAsInteger(Phone.TYPE);
+                // If the provided phone number provides a custom phone type but not a label,
+                // replace it with mobile (by default) to avoid the "Enter custom label" from
+                // popping up immediately upon entering the ContactEditorFragment
+                if (type != null && type == Phone.TYPE_CUSTOM &&
+                        TextUtils.isEmpty(values.getAsString(Phone.LABEL))) {
+                    values.put(Phone.TYPE, Phone.TYPE_MOBILE);
+                }
             }
 
             DataKind kind = accountType.getKindForMimetype(mimeType);
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 1e91fb6..28d63ec 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -37,6 +37,9 @@
 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
 import android.provider.ContactsContract.CommonDataKinds.Website;
 import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.DisplayNameSources;
+import android.provider.ContactsContract.Intents.Insert;
+import android.provider.ContactsContract.Directory;
 import android.provider.ContactsContract.QuickContact;
 import android.provider.ContactsContract.RawContacts;
 import android.support.v13.app.FragmentPagerAdapter;
@@ -114,11 +117,12 @@
     private View mLineAfterTrack;
 
     private ImageView mPhotoView;
-    private ImageView mOpenDetailsImage;
+    private ImageView mOpenDetailsOrAddContactImage;
     private ImageView mStarImage;
     private ViewPager mListPager;
     private ViewPagerAdapter mPagerAdapter;
 
+    private Contact mContactData;
     private ContactLoader mContactLoader;
 
     private final ImageViewDrawableSetter mPhotoSetter = new ImageViewDrawableSetter();
@@ -159,6 +163,37 @@
     private StopWatch mStopWatch = ENABLE_STOPWATCH
             ? StopWatch.start("QuickContact") : StopWatch.getNullStopWatch();
 
+    final OnClickListener mOpenDetailsClickHandler = new OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            final Intent intent = new Intent(Intent.ACTION_VIEW, mLookupUri);
+            mContactLoader.cacheResult();
+            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+            startActivity(intent);
+            close(false);
+        }
+    };
+
+    final OnClickListener mAddToContactsClickHandler = new OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            if (mContactData == null) {
+                Log.e(TAG, "Empty contact data when trying to add to contact");
+                return;
+            }
+            final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
+            intent.setType(Contacts.CONTENT_ITEM_TYPE);
+
+            // Only pre-fill the name field if the provided display name is an organization
+            // name or better (e.g. structured name, nickname)
+            if (mContactData.getDisplayNameSource() >= DisplayNameSources.ORGANIZATION) {
+                intent.putExtra(Insert.NAME, mContactData.getDisplayName());
+            }
+            intent.putExtra(Insert.DATA, mContactData.getContentValues());
+            startActivity(intent);
+        }
+    };
+
     @Override
     protected void onCreate(Bundle icicle) {
         mStopWatch.lap("c"); // create start
@@ -202,7 +237,7 @@
         mFloatingLayout = (FloatingChildLayout) findViewById(R.id.floating_layout);
         mTrack = (ViewGroup) findViewById(R.id.track);
         mTrackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller);
-        mOpenDetailsImage = (ImageView) findViewById(R.id.contact_details_image);
+        mOpenDetailsOrAddContactImage = (ImageView) findViewById(R.id.contact_details_image);
         mStarImage = (ImageView) findViewById(R.id.quickcontact_star_button);
         mListPager = (ViewPager) findViewById(R.id.item_list_pager);
         mSelectedTabRectangle = findViewById(R.id.selected_tab_rectangle);
@@ -216,17 +251,7 @@
             }
         });
 
-        final OnClickListener openDetailsClickHandler = new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                final Intent intent = new Intent(Intent.ACTION_VIEW, mLookupUri);
-                mContactLoader.cacheResult();
-                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
-                startActivity(intent);
-                close(false);
-            }
-        };
-        mOpenDetailsImage.setOnClickListener(openDetailsClickHandler);
+        mOpenDetailsOrAddContactImage.setOnClickListener(mOpenDetailsClickHandler);
 
         mPagerAdapter = new ViewPagerAdapter(getFragmentManager());
         mListPager.setAdapter(mPagerAdapter);
@@ -243,7 +268,7 @@
         setHeaderNameText(R.id.name, R.string.missing_name);
 
         mPhotoView = (ImageView) mPhotoContainer.findViewById(R.id.photo);
-        mPhotoView.setOnClickListener(openDetailsClickHandler);
+        mPhotoView.setOnClickListener(mOpenDetailsClickHandler);
 
         mStopWatch.lap("v"); // view initialized
 
@@ -341,11 +366,12 @@
      * Handle the result from the ContactLoader
      */
     private void bindData(Contact data) {
+        mContactData = data;
         final ResolveCache cache = ResolveCache.getInstance(this);
         final Context context = this;
 
-        mOpenDetailsImage.setVisibility(isMimeExcluded(Contacts.CONTENT_ITEM_TYPE) ? View.GONE
-                : View.VISIBLE);
+        mOpenDetailsOrAddContactImage.setVisibility(isMimeExcluded(Contacts.CONTENT_ITEM_TYPE) ?
+                View.GONE : View.VISIBLE);
         final boolean isStarred = data.getStarred();
         if (isStarred) {
             mStarImage.setImageResource(R.drawable.ic_favorite_on_lt);
@@ -357,7 +383,19 @@
         // If this is a json encoded URI, there is no local contact to star
         if (UriUtils.isEncodedContactUri(lookupUri)) {
             mStarImage.setVisibility(View.GONE);
+
+            // If directory export support is not allowed, then don't allow the user to add
+            // to contacts
+            if (mContactData.getDirectoryExportSupport() == Directory.EXPORT_SUPPORT_NONE) {
+                mOpenDetailsOrAddContactImage.setImageResource(R.drawable.ic_contacts_holo_dark);
+                mOpenDetailsOrAddContactImage.setOnClickListener(mOpenDetailsClickHandler);
+            } else {
+                mOpenDetailsOrAddContactImage.setImageResource(R.drawable.ic_add_contact_holo_dark);
+                mOpenDetailsOrAddContactImage.setOnClickListener(mAddToContactsClickHandler);
+            }
         } else {
+            mOpenDetailsOrAddContactImage.setImageResource(R.drawable.ic_contacts_holo_dark);
+            mOpenDetailsOrAddContactImage.setOnClickListener(mOpenDetailsClickHandler);
             mStarImage.setVisibility(View.VISIBLE);
             mStarImage.setOnClickListener(new OnClickListener() {
                 @Override