Modify Select Account Dialog to align with UI mocks.

+ Additional line for the phone number
+ Support optional title (for phone calls it will be titled "Call With")
+ Tweaks to make it more visually appealing.

Bug: 18204058
Change-Id: Ie2c0fce0b20cf5e889cb17254bc6462ed4fb6438
diff --git a/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
index ca62ce5..33eebca 100644
--- a/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
+++ b/src/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
@@ -26,6 +26,7 @@
 import android.content.DialogInterface;
 import android.os.Bundle;
 import android.telecom.TelecomManager;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -46,6 +47,7 @@
  * the choice to set the phone account as default.
  */
 public class SelectPhoneAccountDialogFragment extends DialogFragment {
+    private int mTitleResId;
     private boolean mCanSetDefault;
     private List<PhoneAccountHandle> mAccountHandles;
     private boolean mIsSelected;
@@ -59,17 +61,39 @@
      *
      * @param fragmentManager The fragment manager.
      * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
+     * @param listener The listener for the results of the account selection.
      */
-    public static void showAccountDialog(FragmentManager fragmentManager, boolean canSetDefault,
+    public static void showAccountDialog(FragmentManager fragmentManager,
             List<PhoneAccountHandle> accountHandles, SelectPhoneAccountListener listener) {
+        showAccountDialog(fragmentManager, R.string.select_account_dialog_title, false,
+                accountHandles, listener);
+    }
+
+    /**
+     * Shows the account selection dialog.
+     * This is the preferred way to show this dialog.
+     * This method also allows specifying a custom title and "set default" checkbox.
+     *
+     * @param fragmentManager The fragment manager.
+     * @param titleResId The resource ID for the string to use in the title of the dialog.
+     * @param canSetDefault {@code true} if the dialog should include an option to set the selection
+     * as the default. False otherwise.
+     * @param accountHandles The {@code PhoneAccountHandle}s available to select from.
+     * @param listener The listener for the results of the account selection.
+     */
+    public static void showAccountDialog(FragmentManager fragmentManager, int titleResId,
+            boolean canSetDefault, List<PhoneAccountHandle> accountHandles,
+            SelectPhoneAccountListener listener) {
         SelectPhoneAccountDialogFragment fragment =
-                new SelectPhoneAccountDialogFragment(canSetDefault, accountHandles, listener);
+                new SelectPhoneAccountDialogFragment(
+                        titleResId, canSetDefault, accountHandles, listener);
         fragment.show(fragmentManager, "selectAccount");
     }
 
-    public SelectPhoneAccountDialogFragment(boolean canSetDefault,
+    public SelectPhoneAccountDialogFragment(int titleResId, boolean canSetDefault,
             List<PhoneAccountHandle> accountHandles, SelectPhoneAccountListener listener) {
         super();
+        mTitleResId = titleResId;
         mCanSetDefault = canSetDefault;
         mAccountHandles = accountHandles;
         mListener = listener;
@@ -111,7 +135,7 @@
                 R.layout.select_account_list_item,
                 mAccountHandles);
 
-        AlertDialog dialog = builder.setTitle(R.string.select_account_dialog_title)
+        AlertDialog dialog = builder.setTitle(mTitleResId)
                 .setAdapter(selectAccountListAdapter, selectionListener)
                 .create();
 
@@ -152,7 +176,8 @@
                 // Cache views for faster scrolling
                 rowView = inflater.inflate(mResId, null);
                 holder = new ViewHolder();
-                holder.textView = (TextView) rowView.findViewById(R.id.text);
+                holder.labelTextView = (TextView) rowView.findViewById(R.id.label);
+                holder.numberTextView = (TextView) rowView.findViewById(R.id.number);
                 holder.imageView = (ImageView) rowView.findViewById(R.id.icon);
                 rowView.setTag(holder);
             }
@@ -163,13 +188,21 @@
 
             PhoneAccountHandle accountHandle = getItem(position);
             PhoneAccount account = mTelecomManager.getPhoneAccount(accountHandle);
-            holder.textView.setText(account.getLabel());
+            holder.labelTextView.setText(account.getLabel());
+            if (account.getAddress() == null ||
+                    TextUtils.isEmpty(account.getAddress().getSchemeSpecificPart())) {
+                holder.numberTextView.setVisibility(View.GONE);
+            } else {
+                holder.numberTextView.setVisibility(View.VISIBLE);
+                holder.numberTextView.setText(account.getAddress().getSchemeSpecificPart());
+            }
             holder.imageView.setImageDrawable(account.getIcon(getContext()));
             return rowView;
         }
 
         private class ViewHolder {
-            TextView textView;
+            TextView labelTextView;
+            TextView numberTextView;
             ImageView imageView;
         }
     }