Revert "Adds secondary icons and intents to entries if they exist"

This reverts commit 85a4b71bb40d0d9bb0fb6f15333c21ce10b9770e.

Change-Id: I41846103ecefe54c16d865039e460e51d7275ed7
diff --git a/res/layout/expanding_entry_card_item.xml b/res/layout/expanding_entry_card_item.xml
index 0e5e75d..02a593a 100644
--- a/res/layout/expanding_entry_card_item.xml
+++ b/res/layout/expanding_entry_card_item.xml
@@ -31,8 +31,7 @@
         android:layout_alignParentStart="true"
         android:layout_alignParentTop="true"
         android:layout_marginEnd="@dimen/expanding_entry_card_item_image_spacing"
-        android:scaleType="fitCenter"
-        android:layout_marginTop="@dimen/expanding_entry_card_item_icon_margin_top" />
+        android:scaleType="fitCenter" />
 
     <TextView
         android:id="@+id/header"
@@ -77,15 +76,4 @@
         android:layout_marginTop="@dimen/expanding_entry_card_item_text_icon_margin_top"
         android:layout_marginEnd="@dimen/expanding_entry_card_item_text_icon_margin_right" />
 
-    <ImageView
-        android:id="@+id/icon_alternate"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentEnd="true"
-        android:layout_alignParentTop="true"
-        android:visibility="gone"
-        android:layout_marginEnd="@dimen/expanding_entry_card_item_alternate_icon_margin_end"
-        android:layout_marginTop="@dimen/expanding_entry_card_item_icon_margin_top"
-        android:layout_marginBottom="@dimen/expanding_entry_card_item_alternate_icon_margin_bottom" />
-
-</RelativeLayout>
+</RelativeLayout>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 82f4792..eb9b40c 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -184,10 +184,6 @@
     <dimen name="expanding_entry_card_item_sub_header_icon_margin_right">4dp</dimen>
     <dimen name="expanding_entry_card_item_sub_header_icon_margin_bottom">14dp</dimen>
 
-    <dimen name="expanding_entry_card_item_icon_margin_top">8dp</dimen>
-    <dimen name="expanding_entry_card_item_alternate_icon_margin_end">0dp</dimen>
-    <dimen name="expanding_entry_card_item_alternate_icon_margin_bottom">10dp</dimen>
-
     <dimen name="people_activity_card_elevation">2dp</dimen>
 
     <dimen name="expanding_entry_card_item_icon_height">24dp</dimen>
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 6fa85b1..f7a1367 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -24,13 +24,11 @@
 import android.content.Intent;
 import android.content.res.Resources;
 import android.graphics.ColorFilter;
-import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
-import android.view.TouchDelegate;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
@@ -62,21 +60,15 @@
         private final String mText;
         private final Drawable mTextIcon;
         private final Intent mIntent;
-        private final Drawable mAlternateIcon;
-        private final Intent mAlternateIntent;
-        private final String mAlternateContentDescription;
         private final boolean mIsEditable;
 
         public Entry(int viewId, Drawable icon, String header, String subHeader, String text,
-                Intent intent, Drawable alternateIcon, Intent alternateIntent,
-                String alternateContentDescription, boolean isEditable) {
-            this(viewId, icon, header, subHeader, null, text, null, intent, alternateIcon,
-                    alternateIntent, alternateContentDescription, isEditable);
+                Intent intent, boolean isEditable) {
+            this(viewId, icon, header, subHeader, null, text, null, intent, isEditable);
         }
 
         public Entry(int viewId, Drawable mainIcon, String header, String subHeader,
                 Drawable subHeaderIcon, String text, Drawable textIcon, Intent intent,
-                Drawable alternateIcon, Intent alternateIntent, String alternateContentDescription,
                 boolean isEditable) {
             mViewId = viewId;
             mIcon = mainIcon;
@@ -86,9 +78,6 @@
             mText = text;
             mTextIcon = textIcon;
             mIntent = intent;
-            mAlternateIcon = alternateIcon;
-            mAlternateIntent = alternateIntent;
-            mAlternateContentDescription = alternateContentDescription;
             mIsEditable = isEditable;
         }
 
@@ -120,18 +109,6 @@
             return mIntent;
         }
 
-        Drawable getAlternateIcon() {
-            return mAlternateIcon;
-        }
-
-        Intent getAlternateIntent() {
-            return mAlternateIntent;
-        }
-
-        String getAlternateContentDescription() {
-            return mAlternateContentDescription;
-        }
-
         boolean isEditable() {
             return mIsEditable;
         }
@@ -404,10 +381,6 @@
                         if (icon != null) {
                             icon.setColorFilter(mThemeColorFilter);
                         }
-                        Drawable alternateIcon = entry.getAlternateIcon();
-                        if (alternateIcon != null) {
-                            alternateIcon.setColorFilter(mThemeColorFilter);
-                        }
                     }
                 }
             }
@@ -421,47 +394,47 @@
 
     // TODO add accessibility content descriptions
     private View createEntryView(LayoutInflater layoutInflater, Entry entry) {
-        final View view = layoutInflater.inflate(
+        View view = layoutInflater.inflate(
                 R.layout.expanding_entry_card_item, this, false);
 
         view.setId(entry.getViewId());
 
-        final ImageView icon = (ImageView) view.findViewById(R.id.icon);
+        ImageView icon = (ImageView) view.findViewById(R.id.icon);
         if (entry.getIcon() != null) {
             icon.setImageDrawable(entry.getIcon());
         } else {
             icon.setVisibility(View.GONE);
         }
 
-        final TextView header = (TextView) view.findViewById(R.id.header);
+        TextView header = (TextView) view.findViewById(R.id.header);
         if (entry.getHeader() != null) {
             header.setText(entry.getHeader());
         } else {
             header.setVisibility(View.GONE);
         }
 
-        final TextView subHeader = (TextView) view.findViewById(R.id.sub_header);
+        TextView subHeader = (TextView) view.findViewById(R.id.sub_header);
         if (entry.getSubHeader() != null) {
             subHeader.setText(entry.getSubHeader());
         } else {
             subHeader.setVisibility(View.GONE);
         }
 
-        final ImageView subHeaderIcon = (ImageView) view.findViewById(R.id.icon_sub_header);
+        ImageView subHeaderIcon = (ImageView) view.findViewById(R.id.icon_sub_header);
         if (entry.getSubHeaderIcon() != null) {
             subHeaderIcon.setImageDrawable(entry.getSubHeaderIcon());
         } else {
             subHeaderIcon.setVisibility(View.GONE);
         }
 
-        final TextView text = (TextView) view.findViewById(R.id.text);
+        TextView text = (TextView) view.findViewById(R.id.text);
         if (entry.getText() != null) {
             text.setText(entry.getText());
         } else {
             text.setVisibility(View.GONE);
         }
 
-        final ImageView textIcon = (ImageView) view.findViewById(R.id.icon_text);
+        ImageView textIcon = (ImageView) view.findViewById(R.id.icon_text);
         if (entry.getTextIcon() != null) {
             textIcon.setImageDrawable(entry.getTextIcon());
         } else {
@@ -473,35 +446,6 @@
             view.setTag(entry.getIntent());
         }
 
-        final ImageView alternateIcon = (ImageView) view.findViewById(R.id.icon_alternate);
-        if (entry.getAlternateIcon() != null && entry.getAlternateIntent() != null) {
-            alternateIcon.setImageDrawable(entry.getAlternateIcon());
-            alternateIcon.setOnClickListener(mOnClickListener);
-            alternateIcon.setTag(entry.getAlternateIntent());
-            alternateIcon.setId(entry.getViewId());
-            alternateIcon.setVisibility(View.VISIBLE);
-            alternateIcon.setContentDescription(entry.getAlternateContentDescription());
-
-            // Expand the clickable area for alternate icon to be top to bottom and to right edge
-            // of the entry view
-            view.post(new Runnable() {
-                @Override
-                public void run() {
-                    final Rect entryRect = new Rect();
-                    view.getHitRect(entryRect);
-
-                    final Rect alternateIconRect = new Rect();
-                    alternateIcon.getHitRect(alternateIconRect);
-                    alternateIconRect.right = entryRect.right;
-                    alternateIconRect.bottom = entryRect.bottom;
-                    alternateIconRect.top = entryRect.top;
-                    final TouchDelegate touchDelegate =
-                            new TouchDelegate(alternateIconRect, alternateIcon);
-                    view.setTouchDelegate(touchDelegate);
-                }
-            });
-        }
-
         return view;
     }
 
diff --git a/src/com/android/contacts/quickcontact/QuickContactActivity.java b/src/com/android/contacts/quickcontact/QuickContactActivity.java
index 5ee7e7e..8ee82b5 100644
--- a/src/com/android/contacts/quickcontact/QuickContactActivity.java
+++ b/src/com/android/contacts/quickcontact/QuickContactActivity.java
@@ -31,8 +31,6 @@
 import android.content.ContentValues;
 import android.content.Intent;
 import android.content.Loader;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.PorterDuff;
@@ -129,6 +127,7 @@
 import com.android.contacts.util.StructuredPostalUtils;
 import com.android.contacts.widget.MultiShrinkScroller;
 import com.android.contacts.widget.MultiShrinkScroller.MultiShrinkScrollerListener;
+
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 
@@ -163,6 +162,7 @@
     private static final int ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION = 150;
     private static final int REQUEST_CODE_CONTACT_EDITOR_ACTIVITY = 1;
     private static final int SCRIM_COLOR = Color.argb(0xB2, 0, 0, 0);
+    private static final String SCHEME_SMSTO = "smsto";
     private static final String MIMETYPE_SMS = "vnd.android-dir/mms-sms";
 
     /** This is the Intent action to install a shortcut in the launcher. */
@@ -210,6 +210,7 @@
     private boolean mIsWaitingForOtherPieceOfExitAnimation;
     private boolean mIsExitAnimationInProgress;
     private boolean mHasComputedThemeColor;
+    private ComponentName mSmsComponent;
 
     private Contact mContactData;
     private ContactLoader mContactLoader;
@@ -298,7 +299,7 @@
             String usageType = DataUsageFeedback.USAGE_TYPE_CALL;
 
             final String scheme = intent.getData().getScheme();
-            if ((scheme != null && scheme.equals(CallUtil.SCHEME_SMSTO)) ||
+            if ((scheme != null && scheme.equals(SCHEME_SMSTO)) ||
                     (intent.getType() != null && intent.getType().equals(MIMETYPE_SMS))) {
                 usageType = DataUsageFeedback.USAGE_TYPE_SHORT_TEXT;
             }
@@ -501,6 +502,8 @@
 
         setContentView(R.layout.quickcontact_activity);
 
+        mSmsComponent = PhoneCapabilityTester.getSmsComponent(this);
+
         mContactCard = (ExpandingEntryCardView) findViewById(R.id.communication_card);
         mNoContactDetailsCard = (ExpandingEntryCardView) findViewById(R.id.no_contact_data_card);
         mRecentCard = (ExpandingEntryCardView) findViewById(R.id.recent_card);
@@ -954,9 +957,6 @@
         String text = null;
         Drawable textIcon = null;
         Intent intent = null;
-        Drawable alternateIcon = null;
-        Intent alternateIntent = null;
-        String alternateContentDescription = null;
         final boolean isEditable = false;
 
         DataKind kind = dataItem.getDataKind();
@@ -1046,10 +1046,6 @@
                 if (PhoneCapabilityTester.isPhone(this)) {
                     intent = CallUtil.getCallIntent(phone.getNumber());
                 }
-                alternateIntent = new Intent(Intent.ACTION_SENDTO,
-                        Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null));
-                alternateIcon = getResources().getDrawable(R.drawable.ic_message_24dp);
-                alternateContentDescription = getResources().getString(R.string.sms_other);
             }
         } else if (dataItem instanceof EmailDataItem) {
             final EmailDataItem email = (EmailDataItem) dataItem;
@@ -1151,18 +1147,6 @@
             }
         }
 
-        if (alternateIntent != null) {
-            // Do not set the alternate intent is there are no resolves
-            if (!PhoneCapabilityTester.isIntentRegistered(this, alternateIntent)) {
-                alternateIntent = null;
-            }
-
-            // Attempt to use package manager to find a suitable content description if needed
-            if (TextUtils.isEmpty(alternateContentDescription)) {
-                alternateContentDescription = getIntentResolveLabel(alternateIntent);
-            }
-        }
-
         // If the Entry has no visual elements, return null
         if (icon == null && TextUtils.isEmpty(header) && TextUtils.isEmpty(subHeader) &&
                 subHeaderIcon == null && TextUtils.isEmpty(text) && textIcon == null) {
@@ -1173,7 +1157,7 @@
                 -1 : (int) dataItem.getId();
 
         return new Entry(dataId, icon, header, subHeader, subHeaderIcon, text, textIcon,
-                intent, alternateIcon, alternateIntent, alternateContentDescription, isEditable);
+                intent, isEditable);
     }
 
     private List<Entry> dataItemsToEntries(List<DataItem> dataItems) {
@@ -1183,30 +1167,30 @@
             if (entry != null) {
                 entries.add(entry);
             }
+            // TODO merge secondary intents
+            if (dataItem instanceof PhoneDataItem) {
+                final PhoneDataItem phone = (PhoneDataItem) dataItem;
+                Intent smsIntent = null;
+                if (mSmsComponent != null) {
+                    smsIntent = new Intent(Intent.ACTION_SENDTO,
+                            Uri.fromParts(CallUtil.SCHEME_SMSTO, phone.getNumber(), null));
+                    smsIntent.setComponent(mSmsComponent);
+                }
+                final int dataId = dataItem.getId() > Integer.MAX_VALUE ?
+                        -1 : (int) dataItem.getId();
+                entries.add(new Entry(dataId,
+                        getResources().getDrawable(R.drawable.ic_message_24dp),
+                        getResources().getString(R.string.send_message),
+                        /* subHeader = */ null,
+                        /* text = */ phone.buildDataString(this,
+                                dataItem.getDataKind()),
+                        smsIntent,
+                        /* isEditable = */ false));
+            }
         }
         return entries;
     }
 
-    private String getIntentResolveLabel(Intent intent) {
-        final List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent,
-                PackageManager.MATCH_DEFAULT_ONLY);
-
-        // Pick first match, otherwise best found
-        ResolveInfo bestResolve = null;
-        final int size = matches.size();
-        if (size == 1) {
-            bestResolve = matches.get(0);
-        } else if (size > 1) {
-            bestResolve = ResolveCache.getInstance(this).getBestResolve(intent, matches);
-        }
-
-        if (bestResolve == null) {
-            return null;
-        }
-
-        return String.valueOf(bestResolve.loadLabel(getPackageManager()));
-    }
-
     /**
      * Asynchronously extract the most vibrant color from the PhotoView. Once extracted,
      * apply this tint to {@link MultiShrinkScroller}. This operation takes about 20-30ms
@@ -1338,9 +1322,6 @@
                     interaction.getViewFooter(this),
                     interaction.getFooterIcon(this),
                     interaction.getIntent(),
-                    /* alternateIcon = */ null,
-                    /* alternateIntent = */ null,
-                    /* alternateContentDescription = */ null,
                     /* isEditable = */ false));
         }
         return entries;