Move label fetch logic into common utility class.

- Move logic from PhoneActionInflater and PhoneActionAltInflater into common
  utility method so it can be shared by PhoneNumberInteraction without going
  through account manager.
- Refactored InteractionType to be constant int instead of enum class.

Bug: 6993891
Change-Id: I91793fccc2ff193426d276dbc776c241cb930694
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3d0d953..0958dd8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1029,92 +1029,6 @@
          and will not be synced. -->
     <string name="account_phone" product="default">Phone-only, unsynced</string>
 
-    <!-- Action string for calling a custom phone number -->
-    <string name="call_custom">Call <xliff:g id="custom">%s</xliff:g></string>
-    <!-- Action string for calling a home phone number -->
-    <string name="call_home">Call home</string>
-    <!-- Action string for calling a mobile phone number -->
-    <string name="call_mobile">Call mobile</string>
-    <!-- Action string for calling a work phone number -->
-    <string name="call_work">Call work</string>
-    <!-- Action string for calling a work fax phone number -->
-    <string name="call_fax_work">Call work fax</string>
-    <!-- Action string for calling a home fax phone number -->
-    <string name="call_fax_home">Call home fax</string>
-    <!-- Action string for calling a pager phone number -->
-    <string name="call_pager">Call pager</string>
-    <!-- Action string for calling an other phone number -->
-    <string name="call_other">Call</string>
-    <!-- Action string for calling a callback number -->
-    <string name="call_callback">Call callback</string>
-    <!-- Action string for calling a car phone number -->
-    <string name="call_car">Call car</string>
-    <!-- Action string for calling a company main phone number -->
-    <string name="call_company_main">Call company main</string>
-    <!-- Action string for calling a ISDN phone number -->
-    <string name="call_isdn">Call ISDN</string>
-    <!-- Action string for calling a main phone number -->
-    <string name="call_main">Call main</string>
-    <!-- Action string for calling an other fax phone number -->
-    <string name="call_other_fax">Call fax</string>
-    <!-- Action string for calling a radio phone number -->
-    <string name="call_radio">Call radio</string>
-    <!-- Action string for calling a Telex phone number -->
-    <string name="call_telex">Call telex</string>
-    <!-- Action string for calling a TTY/TDD phone number -->
-    <string name="call_tty_tdd">Call TTY/TDD</string>
-    <!-- Action string for calling a work mobile phone number -->
-    <string name="call_work_mobile">Call work mobile</string>
-    <!-- Action string for calling a work pager phone number -->
-    <string name="call_work_pager">Call work pager</string>
-    <!-- Action string for calling an assistant phone number -->
-    <string name="call_assistant">Call <xliff:g id="assistant">%s</xliff:g></string>
-    <!-- Action string for calling a MMS phone number -->
-    <string name="call_mms">Call MMS</string>
-
-    <!-- Action string for sending an SMS to a custom phone number -->
-    <string name="sms_custom">Text <xliff:g id="custom">%s</xliff:g></string>
-    <!-- Action string for sending an SMS to a home phone number -->
-    <string name="sms_home">Text home</string>
-    <!-- Action string for sending an SMS to a mobile phone number -->
-    <string name="sms_mobile">Text mobile</string>
-    <!-- Action string for sending an SMS to a work phone number -->
-    <string name="sms_work">Text work</string>
-    <!-- Action string for sending an SMS to a work fax phone number -->
-    <string name="sms_fax_work">Text work fax</string>
-    <!-- Action string for sending an SMS to a home fax phone number -->
-    <string name="sms_fax_home">Text home fax</string>
-    <!-- Action string for sending an SMS to a pager phone number -->
-    <string name="sms_pager">Text pager</string>
-    <!-- Action string for sending an SMS to an other phone number -->
-    <string name="sms_other">Text</string>
-    <!-- Action string for sending an SMS to a callback number -->
-    <string name="sms_callback">Text callback</string>
-    <!-- Action string for sending an SMS to a car phone number -->
-    <string name="sms_car">Text car</string>
-    <!-- Action string for sending an SMS to a company main phone number -->
-    <string name="sms_company_main">Text company main</string>
-    <!-- Action string for sending an SMS to a ISDN phone number -->
-    <string name="sms_isdn">Text ISDN</string>
-    <!-- Action string for sending an SMS to a main phone number -->
-    <string name="sms_main">Text main</string>
-    <!-- Action string for sending an SMS to an other fax phone number -->
-    <string name="sms_other_fax">Text fax</string>
-    <!-- Action string for sending an SMS to a radio phone number -->
-    <string name="sms_radio">Text radio</string>
-    <!-- Action string for sending an SMS to a Telex phone number -->
-    <string name="sms_telex">Text telex</string>
-    <!-- Action string for sending an SMS to a TTY/TDD phone number -->
-    <string name="sms_tty_tdd">Text TTY/TDD</string>
-    <!-- Action string for sending an SMS to a work mobile phone number -->
-    <string name="sms_work_mobile">Text work mobile</string>
-    <!-- Action string for sending an SMS to a work pager phone number -->
-    <string name="sms_work_pager">Text work pager</string>
-    <!-- Action string for sending an SMS to an assistant phone number -->
-    <string name="sms_assistant">Text <xliff:g id="assistant">%s</xliff:g></string>
-    <!-- Action string for sending an SMS to a MMS phone number -->
-    <string name="sms_mms">Text MMS</string>
-
     <!-- Generic action string for text messaging a contact. Used by AccessibilityService to announce the purpose of the view. [CHAR LIMIT=NONE] -->
     <string name="sms">Text message</string>
 
diff --git a/src/com/android/contacts/interactions/PhoneNumberInteraction.java b/src/com/android/contacts/interactions/PhoneNumberInteraction.java
index 7ecd5d8..2cf0601 100644
--- a/src/com/android/contacts/interactions/PhoneNumberInteraction.java
+++ b/src/com/android/contacts/interactions/PhoneNumberInteraction.java
@@ -20,7 +20,6 @@
 import android.app.Dialog;
 import android.app.DialogFragment;
 import android.app.FragmentManager;
-import android.content.ContentValues;
 import android.content.Context;
 import android.content.CursorLoader;
 import android.content.DialogInterface;
@@ -53,10 +52,7 @@
 import com.android.contacts.common.Collapser.Collapsible;
 import com.android.contacts.common.MoreContactUtils;
 import com.android.contacts.common.activity.TransactionSafeActivity;
-import com.android.contacts.model.AccountTypeManager;
-import com.android.contacts.model.account.AccountType;
-import com.android.contacts.model.account.AccountType.StringInflater;
-import com.android.contacts.model.dataitem.DataKind;
+import com.android.contacts.common.util.ContactDisplayUtils;
 import com.google.common.annotations.VisibleForTesting;
 
 import java.util.ArrayList;
@@ -75,12 +71,6 @@
 public class PhoneNumberInteraction implements OnLoadCompleteListener<Cursor> {
     private static final String TAG = PhoneNumberInteraction.class.getSimpleName();
 
-    @VisibleForTesting
-    /* package */ enum InteractionType {
-        PHONE_CALL,
-        SMS
-    }
-
     /**
      * A model object for capturing a phone number for a given contact.
      */
@@ -162,14 +152,12 @@
      * A list adapter that populates the list of contact's phone numbers.
      */
     private static class PhoneItemAdapter extends ArrayAdapter<PhoneItem> {
-        private final InteractionType mInteractionType;
-        private final AccountTypeManager mAccountTypeManager;
+        private final int mInteractionType;
 
         public PhoneItemAdapter(Context context, List<PhoneItem> list,
-                InteractionType interactionType) {
+                int interactionType) {
             super(context, R.layout.phone_disambig_item, android.R.id.text2, list);
             mInteractionType = interactionType;
-            mAccountTypeManager = AccountTypeManager.getInstance(context);
         }
 
         @Override
@@ -177,20 +165,11 @@
             final View view = super.getView(position, convertView, parent);
 
             final PhoneItem item = getItem(position);
-            final AccountType accountType = mAccountTypeManager.getAccountType(
-                    item.accountType, item.dataSet);
             final TextView typeView = (TextView) view.findViewById(android.R.id.text1);
-            final DataKind kind = accountType.getKindForMimetype(Phone.CONTENT_ITEM_TYPE);
-            if (kind != null) {
-                ContentValues values = new ContentValues();
-                values.put(Phone.TYPE, item.type);
-                values.put(Phone.LABEL, item.label);
-                StringInflater header = (mInteractionType == InteractionType.SMS)
-                        ? kind.actionAltHeader : kind.actionHeader;
-                typeView.setText(header.inflateUsing(getContext(), values));
-            } else {
-                typeView.setText(R.string.call_other);
-            }
+            CharSequence value = ContactDisplayUtils.getLabelForCallOrSms((int) item.type,
+                    item.label, mInteractionType, getContext());
+
+            typeView.setText(value);
             return view;
         }
     }
@@ -213,13 +192,13 @@
         private static final String ARG_INTERACTION_TYPE = "interactionType";
         private static final String ARG_CALL_ORIGIN = "callOrigin";
 
-        private InteractionType mInteractionType;
+        private int mInteractionType;
         private ListAdapter mPhonesAdapter;
         private List<PhoneItem> mPhoneList;
         private String mCallOrigin;
 
         public static void show(FragmentManager fragmentManager,
-                ArrayList<PhoneItem> phoneList, InteractionType interactionType,
+                ArrayList<PhoneItem> phoneList, int interactionType,
                 String callOrigin) {
             PhoneDisambiguationDialogFragment fragment = new PhoneDisambiguationDialogFragment();
             Bundle bundle = new Bundle();
@@ -234,8 +213,7 @@
         public Dialog onCreateDialog(Bundle savedInstanceState) {
             final Activity activity = getActivity();
             mPhoneList = getArguments().getParcelableArrayList(ARG_PHONE_LIST);
-            mInteractionType =
-                    (InteractionType) getArguments().getSerializable(ARG_INTERACTION_TYPE);
+            mInteractionType = getArguments().getInt(ARG_INTERACTION_TYPE);
             mCallOrigin = getArguments().getString(ARG_CALL_ORIGIN);
 
             mPhonesAdapter = new PhoneItemAdapter(activity, mPhoneList, mInteractionType);
@@ -243,7 +221,7 @@
             final View setPrimaryView = inflater.inflate(R.layout.set_primary_checkbox, null);
             return new AlertDialog.Builder(activity)
                     .setAdapter(mPhonesAdapter, this)
-                    .setTitle(mInteractionType == InteractionType.SMS
+                    .setTitle(mInteractionType == ContactDisplayUtils.INTERACTION_SMS
                             ? R.string.sms_disambig_title : R.string.call_disambig_title)
                     .setView(setPrimaryView)
                     .create();
@@ -291,7 +269,7 @@
 
     private final Context mContext;
     private final OnDismissListener mDismissListener;
-    private final InteractionType mInteractionType;
+    private final int mInteractionType;
 
     private final String mCallOrigin;
 
@@ -304,12 +282,12 @@
      * require a {@link TransactionSafeActivity} (i.e. see {@link #startInteractionForPhoneCall}).
      */
     @VisibleForTesting
-    /* package */ PhoneNumberInteraction(Context context, InteractionType interactionType,
+    /* package */ PhoneNumberInteraction(Context context, int interactionType,
             DialogInterface.OnDismissListener dismissListener) {
         this(context, interactionType, dismissListener, null);
     }
 
-    private PhoneNumberInteraction(Context context, InteractionType interactionType,
+    private PhoneNumberInteraction(Context context, int interactionType,
             DialogInterface.OnDismissListener dismissListener, String callOrigin) {
         mContext = context;
         mInteractionType = interactionType;
@@ -322,11 +300,11 @@
     }
 
     private static void performAction(
-            Context context, String phoneNumber, InteractionType interactionType,
+            Context context, String phoneNumber, int interactionType,
             String callOrigin) {
         Intent intent;
         switch (interactionType) {
-            case SMS:
+            case ContactDisplayUtils.INTERACTION_SMS:
                 intent = new Intent(
                         Intent.ACTION_SENDTO, Uri.fromParts("sms", phoneNumber, null));
                 break;
@@ -448,7 +426,7 @@
      * data Uri won't.
      */
     public static void startInteractionForPhoneCall(TransactionSafeActivity activity, Uri uri) {
-        (new PhoneNumberInteraction(activity, InteractionType.PHONE_CALL, null))
+        (new PhoneNumberInteraction(activity, ContactDisplayUtils.INTERACTION_CALL, null))
                 .startInteraction(uri);
     }
 
@@ -462,7 +440,7 @@
      */
     public static void startInteractionForPhoneCall(TransactionSafeActivity activity, Uri uri,
             String callOrigin) {
-        (new PhoneNumberInteraction(activity, InteractionType.PHONE_CALL, null, callOrigin))
+        (new PhoneNumberInteraction(activity, ContactDisplayUtils.INTERACTION_CALL, null, callOrigin))
                 .startInteraction(uri);
     }
 
@@ -479,7 +457,8 @@
      * data Uri won't.
      */
     public static void startInteractionForTextMessage(TransactionSafeActivity activity, Uri uri) {
-        (new PhoneNumberInteraction(activity, InteractionType.SMS, null)).startInteraction(uri);
+        (new PhoneNumberInteraction(activity, ContactDisplayUtils.INTERACTION_SMS, null))
+                .startInteraction(uri);
     }
 
     @VisibleForTesting
diff --git a/src/com/android/contacts/model/account/BaseAccountType.java b/src/com/android/contacts/model/account/BaseAccountType.java
index 7f9e1ef..6b4d623 100644
--- a/src/com/android/contacts/model/account/BaseAccountType.java
+++ b/src/com/android/contacts/model/account/BaseAccountType.java
@@ -39,6 +39,7 @@
 import android.view.inputmethod.EditorInfo;
 
 import com.android.contacts.R;
+import com.android.contacts.common.util.ContactDisplayUtils;
 import com.android.contacts.model.dataitem.DataKind;
 import com.android.contacts.test.NeededForTesting;
 import com.android.contacts.util.DateUtils;
@@ -540,70 +541,24 @@
     public static class PhoneActionInflater extends CommonInflater {
         @Override
         protected boolean isCustom(Integer type) {
-            return type == Phone.TYPE_CUSTOM || type == Phone.TYPE_ASSISTANT;
+            return ContactDisplayUtils.isCustomPhoneType(type);
         }
 
         @Override
         protected int getTypeLabelResource(Integer type) {
-            if (type == null) return R.string.call_other;
-            switch (type) {
-                case Phone.TYPE_HOME: return R.string.call_home;
-                case Phone.TYPE_MOBILE: return R.string.call_mobile;
-                case Phone.TYPE_WORK: return R.string.call_work;
-                case Phone.TYPE_FAX_WORK: return R.string.call_fax_work;
-                case Phone.TYPE_FAX_HOME: return R.string.call_fax_home;
-                case Phone.TYPE_PAGER: return R.string.call_pager;
-                case Phone.TYPE_OTHER: return R.string.call_other;
-                case Phone.TYPE_CALLBACK: return R.string.call_callback;
-                case Phone.TYPE_CAR: return R.string.call_car;
-                case Phone.TYPE_COMPANY_MAIN: return R.string.call_company_main;
-                case Phone.TYPE_ISDN: return R.string.call_isdn;
-                case Phone.TYPE_MAIN: return R.string.call_main;
-                case Phone.TYPE_OTHER_FAX: return R.string.call_other_fax;
-                case Phone.TYPE_RADIO: return R.string.call_radio;
-                case Phone.TYPE_TELEX: return R.string.call_telex;
-                case Phone.TYPE_TTY_TDD: return R.string.call_tty_tdd;
-                case Phone.TYPE_WORK_MOBILE: return R.string.call_work_mobile;
-                case Phone.TYPE_WORK_PAGER: return R.string.call_work_pager;
-                case Phone.TYPE_ASSISTANT: return R.string.call_assistant;
-                case Phone.TYPE_MMS: return R.string.call_mms;
-                default: return R.string.call_custom;
-            }
+            return ContactDisplayUtils.getPhoneLabelResourceId(type);
         }
     }
 
     public static class PhoneActionAltInflater extends CommonInflater {
         @Override
         protected boolean isCustom(Integer type) {
-            return (type == Phone.TYPE_CUSTOM || type == Phone.TYPE_ASSISTANT);
+            return ContactDisplayUtils.isCustomPhoneType(type);
         }
 
         @Override
         protected int getTypeLabelResource(Integer type) {
-            if (type == null) return R.string.sms_other;
-            switch (type) {
-                case Phone.TYPE_HOME: return R.string.sms_home;
-                case Phone.TYPE_MOBILE: return R.string.sms_mobile;
-                case Phone.TYPE_WORK: return R.string.sms_work;
-                case Phone.TYPE_FAX_WORK: return R.string.sms_fax_work;
-                case Phone.TYPE_FAX_HOME: return R.string.sms_fax_home;
-                case Phone.TYPE_PAGER: return R.string.sms_pager;
-                case Phone.TYPE_OTHER: return R.string.sms_other;
-                case Phone.TYPE_CALLBACK: return R.string.sms_callback;
-                case Phone.TYPE_CAR: return R.string.sms_car;
-                case Phone.TYPE_COMPANY_MAIN: return R.string.sms_company_main;
-                case Phone.TYPE_ISDN: return R.string.sms_isdn;
-                case Phone.TYPE_MAIN: return R.string.sms_main;
-                case Phone.TYPE_OTHER_FAX: return R.string.sms_other_fax;
-                case Phone.TYPE_RADIO: return R.string.sms_radio;
-                case Phone.TYPE_TELEX: return R.string.sms_telex;
-                case Phone.TYPE_TTY_TDD: return R.string.sms_tty_tdd;
-                case Phone.TYPE_WORK_MOBILE: return R.string.sms_work_mobile;
-                case Phone.TYPE_WORK_PAGER: return R.string.sms_work_pager;
-                case Phone.TYPE_ASSISTANT: return R.string.sms_assistant;
-                case Phone.TYPE_MMS: return R.string.sms_mms;
-                default: return R.string.sms_custom;
-            }
+            return ContactDisplayUtils.getSmsLabelResourceId(type);
         }
     }
 
diff --git a/tests/src/com/android/contacts/interactions/PhoneNumberInteractionTest.java b/tests/src/com/android/contacts/interactions/PhoneNumberInteractionTest.java
index a82e0f6..4e347b7 100644
--- a/tests/src/com/android/contacts/interactions/PhoneNumberInteractionTest.java
+++ b/tests/src/com/android/contacts/interactions/PhoneNumberInteractionTest.java
@@ -30,7 +30,7 @@
 import android.test.InstrumentationTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 
-import com.android.contacts.interactions.PhoneNumberInteraction.InteractionType;
+import com.android.contacts.common.util.ContactDisplayUtils;
 import com.android.contacts.interactions.PhoneNumberInteraction.PhoneItem;
 import com.android.contacts.tests.mocks.ContactsMockContext;
 import com.android.contacts.tests.mocks.MockContentProvider;
@@ -60,7 +60,7 @@
     private final static class TestPhoneNumberInteraction extends PhoneNumberInteraction {
         private ArrayList<PhoneItem> mPhoneList;
 
-        public TestPhoneNumberInteraction(Context context, InteractionType interactionType,
+        public TestPhoneNumberInteraction(Context context, int interactionType,
                 OnDismissListener dismissListener) {
             super(context, interactionType, dismissListener);
         }
@@ -94,7 +94,7 @@
                         Phone.CONTENT_ITEM_TYPE);
 
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.SMS, null);
+                mContext, ContactDisplayUtils.INTERACTION_SMS, null);
 
         interaction.startInteraction(contactUri);
         interaction.getLoader().waitForLoader();
@@ -113,7 +113,7 @@
                         Phone.CONTENT_ITEM_TYPE);
 
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.SMS, null);
+                mContext, ContactDisplayUtils.INTERACTION_SMS, null);
 
         interaction.startInteraction(dataUri);
         interaction.getLoader().waitForLoader();
@@ -134,7 +134,7 @@
                         2, "456", 1, null, null, Phone.TYPE_HOME, null, Phone.CONTENT_ITEM_TYPE);
 
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.SMS, null);
+                mContext, ContactDisplayUtils.INTERACTION_SMS, null);
 
         interaction.startInteraction(contactUri);
         interaction.getLoader().waitForLoader();
@@ -175,7 +175,7 @@
                         Phone.CONTENT_ITEM_TYPE);
 
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.PHONE_CALL, null);
+                mContext, ContactDisplayUtils.INTERACTION_CALL, null);
 
         interaction.startInteraction(contactUri);
         interaction.getLoader().waitForLoader();
@@ -193,7 +193,7 @@
                 .returnRow(1, "example@example.com", 0, null, null, Phone.TYPE_HOME, null,
                         SipAddress.CONTENT_ITEM_TYPE);
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.PHONE_CALL, null);
+                mContext, ContactDisplayUtils.INTERACTION_CALL, null);
 
         interaction.startInteraction(contactUri);
         interaction.getLoader().waitForLoader();
@@ -214,7 +214,7 @@
                         Phone.CONTENT_ITEM_TYPE);
 
         TestPhoneNumberInteraction interaction = new TestPhoneNumberInteraction(
-                mContext, InteractionType.PHONE_CALL, null);
+                mContext, ContactDisplayUtils.INTERACTION_CALL, null);
 
         interaction.startInteraction(contactUri);
         interaction.getLoader().waitForLoader();