UI changes for icons in sim settings

+ UI changes relate to displaying sim icons in sim settings
+ Correcting way to display phone number inside sim settings dialog

Bug: 18356419
Change-Id: I1fe025fac52f20b607d4492b99cfef9588ec9416
diff --git a/res/drawable-hdpi/ic_live_help.png b/res/drawable-hdpi/ic_live_help.png
new file mode 100644
index 0000000..f3548f6
--- /dev/null
+++ b/res/drawable-hdpi/ic_live_help.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_live_help.png b/res/drawable-mdpi/ic_live_help.png
new file mode 100644
index 0000000..e958662
--- /dev/null
+++ b/res/drawable-mdpi/ic_live_help.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_live_help.png b/res/drawable-xhdpi/ic_live_help.png
new file mode 100644
index 0000000..dbbbfed
--- /dev/null
+++ b/res/drawable-xhdpi/ic_live_help.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_live_help.png b/res/drawable-xxhdpi/ic_live_help.png
new file mode 100644
index 0000000..f2a01fe
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_live_help.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_live_help.png b/res/drawable-xxxhdpi/ic_live_help.png
new file mode 100644
index 0000000..00338a0
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_live_help.png
Binary files differ
diff --git a/res/layout/select_account_list_item.xml b/res/layout/select_account_list_item.xml
index d80fef5..55484b1 100644
--- a/res/layout/select_account_list_item.xml
+++ b/res/layout/select_account_list_item.xml
@@ -14,11 +14,12 @@
      limitations under the License.
 -->
 
-<!-- Layout of a single item in the InCallUI Account Chooser Dialog. -->
+<!-- Layout of a single item for displaying sim cards. -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:background="?android:attr/selectableItemBackground"
     android:padding="4dp" >
 
     <ImageView android:id="@+id/icon"
@@ -26,11 +27,32 @@
         android:layout_height="48dp"
         android:scaleType="center" />
 
-    <TextView android:id="@+id/text"
-        android:textAppearance="?android:attr/textAppearanceMedium"
-        android:gravity="start|center_vertical"
-        android:layout_marginLeft="8dp"
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:orientation="vertical"
+        android:layout_marginStart="15dip"
+        android:layout_marginEnd="6dip"
+        android:layout_marginTop="6dip"
+        android:layout_marginBottom="6dip"
+        android:layout_height="wrap_content"
         android:layout_width="0dp"
-        android:layout_weight="1"
-        android:layout_height="match_parent" />
+        android:layout_weight="1" >
+        <TextView android:id="@+id/title"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:gravity="start|center_vertical"
+            android:layout_marginLeft="8dp"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:ellipsize="marquee"
+            android:fadingEdge="horizontal" />
+        <TextView android:id="@+id/summary"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:gravity="start|center_vertical"
+            android:layout_marginLeft="8dp"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@id/title"
+            android:textColor="?android:attr/textColorSecondary"
+            android:layout_alignStart="@id/title" />
+    </LinearLayout>
 </LinearLayout>
diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java
index a371868..6de0cc1 100644
--- a/src/com/android/settings/sim/SimSettings.java
+++ b/src/com/android/settings/sim/SimSettings.java
@@ -22,6 +22,7 @@
 import android.content.DialogInterface;
 import android.content.res.Resources;
 import android.database.Cursor;
+import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
 import android.os.Bundle;
 import android.preference.Preference;
@@ -322,7 +323,7 @@
         ListAdapter adapter = new SelectAccountListAdapter(
                 builder.getContext(),
                 R.layout.select_account_list_item,
-                arr);
+                arr, id);
 
         if (id == DATA_PICK) {
             builder.setTitle(R.string.select_sim_for_data);
@@ -339,43 +340,61 @@
     private class SelectAccountListAdapter extends ArrayAdapter<String> {
         private Context mContext;
         private int mResId;
+        private int mDialogId;
+        private final float OPACITY = 0.54f;
 
         public SelectAccountListAdapter(
-                Context context, int resource, String[] arr) {
+                Context context, int resource, String[] arr, int dialogId) {
             super(context, resource, arr);
             mContext = context;
             mResId = resource;
+            mDialogId = dialogId;
         }
 
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
             LayoutInflater inflater = (LayoutInflater)
                     mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
             View rowView;
             final ViewHolder holder;
+            SubscriptionInfo sir;
 
             if (convertView == null) {
                 // Cache views for faster scrolling
                 rowView = inflater.inflate(mResId, null);
                 holder = new ViewHolder();
-                holder.textView = (TextView) rowView.findViewById(R.id.text);
-                holder.imageView = (ImageView) rowView.findViewById(R.id.icon);
+                holder.title = (TextView) rowView.findViewById(R.id.title);
+                holder.summary = (TextView) rowView.findViewById(R.id.summary);
+                holder.icon = (ImageView) rowView.findViewById(R.id.icon);
                 rowView.setTag(holder);
-            }
-            else {
+            } else {
                 rowView = convertView;
                 holder = (ViewHolder) rowView.getTag();
             }
 
-            holder.textView.setText(getItem(position));
-            holder.imageView.setImageDrawable(getResources().getDrawable(R.drawable.ic_sim_sd));
+            if (mDialogId == CALLS_PICK && position == 0) {
+                holder.title.setText(getItem(position));
+                holder.summary.setText("");
+                holder.icon.setImageDrawable(getResources()
+                        .getDrawable(R.drawable.ic_live_help));
+                holder.icon.setAlpha(OPACITY);
+            } else {
+                if (mDialogId == CALLS_PICK && position != 0) {
+                    sir = mSelectableSubInfos.get(position - 1);
+                } else {
+                    sir = mSelectableSubInfos.get(position);
+                }
+                holder.title.setText(sir.getDisplayName());
+                holder.summary.setText(sir.getNumber());
+                holder.icon.setImageBitmap(sir.createIconBitmap(mContext));
+            }
             return rowView;
         }
 
         private class ViewHolder {
-            TextView textView;
-            ImageView imageView;
+            TextView title;
+            TextView summary;
+            ImageView icon;
         }
     }
 
@@ -397,10 +416,12 @@
         private SubscriptionInfo mSubInfoRecord;
         private int mSlotId;
         private int[] tintArr;
+        Context mContext;
 
         public SimPreference(Context context, SubscriptionInfo subInfoRecord, int slotId) {
             super(context);
 
+            mContext = context;
             mSubInfoRecord = subInfoRecord;
             mSlotId = slotId;
             setKey("sim" + mSlotId);
@@ -411,12 +432,17 @@
         public void update() {
             final Resources res = getResources();
 
+            setTitle(String.format(getResources()
+                    .getString(R.string.sim_editor_title), (mSlotId + 1)));
             if (mSubInfoRecord != null) {
-                setTitle(String.format(res.getString(R.string.sim_editor_title),
-                        (mSubInfoRecord.getSimSlotIndex() + 1)));
-                setSummary(mSubInfoRecord.getDisplayName() + " - " +
-                        mSubInfoRecord.getNumber().toString());
-                setEnabled(true);
+                if (TextUtils.isEmpty(mSubInfoRecord.getNumber().toString())) {
+                   setSummary(mSubInfoRecord.getDisplayName());
+                } else {
+                    setSummary(mSubInfoRecord.getDisplayName() + " - " +
+                            mSubInfoRecord.getNumber().toString());
+                    setEnabled(true);
+                }
+                setIcon(new BitmapDrawable(res, (mSubInfoRecord.createIconBitmap(mContext))));
             } else {
                 setSummary(R.string.sim_slot_empty);
                 setFragment(null);
@@ -424,20 +450,6 @@
             }
         }
 
-        public String getFormattedPhoneNumber() {
-            try{
-                final String rawNumber = PhoneFactory.getPhone(mSlotId).getLine1Number();
-                String formattedNumber = null;
-                if (!TextUtils.isEmpty(rawNumber)) {
-                    formattedNumber = PhoneNumberUtils.formatNumber(rawNumber);
-                }
-
-                return formattedNumber;
-            } catch (java.lang.IllegalStateException ise){
-                return "Unknown";
-            }
-        }
-
         public SubscriptionInfo getSubInfoRecord() {
             return mSubInfoRecord;
         }
@@ -480,7 +492,12 @@
             });
 
             TextView numberView = (TextView)dialogLayout.findViewById(R.id.number);
-            numberView.setText(simPref.getFormattedPhoneNumber());
+            final String rawNumber = mSubInfoRecord.getNumber();
+            if (TextUtils.isEmpty(rawNumber)) {
+                numberView.setText(res.getString(com.android.internal.R.string.unknownName));
+            } else {
+                numberView.setText(PhoneNumberUtils.formatNumber(rawNumber));
+            }
 
             TextView carrierView = (TextView)dialogLayout.findViewById(R.id.carrier);
             carrierView.setText(mSubInfoRecord.getCarrierName());