Merge "Use same printer-list template as in the print spooler."
diff --git a/res/layout/printer_dropdown_item.xml b/res/layout/printer_dropdown_item.xml
index 0063477..1209aa6 100644
--- a/res/layout/printer_dropdown_item.xml
+++ b/res/layout/printer_dropdown_item.xml
@@ -15,31 +15,33 @@
 -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
+    android:layout_width="fill_parent"
     android:layout_height="wrap_content"
-    android:minHeight="48dip"
-    android:gravity="center_vertical"
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:background="?android:attr/selectableItemBackground">
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:orientation="horizontal"
+    android:gravity="start|center_vertical">
 
     <ImageView
         android:id="@+id/icon"
-        android:layout_width="48dip"
-        android:layout_height="48dip"
+        android:layout_width="40dip"
+        android:layout_height="40dip"
         android:layout_gravity="center_vertical"
-        android:layout_marginEnd="8dip"
+        android:layout_marginTop="8dip"
+        android:layout_marginBottom="8dip"
         android:duplicateParentState="true"
         android:contentDescription="@null"
-        android:visibility="gone">
+        android:visibility="invisible">
     </ImageView>
 
-    <LinearLayout
-        android:layout_width="wrap_content"
+    <RelativeLayout
+        android:layout_width="0dip"
+        android:layout_weight="1"
         android:layout_height="wrap_content"
-        android:layout_marginTop="6dip"
-        android:layout_marginBottom="6dip"
-        android:orientation="vertical">
+        android:layout_gravity="center_vertical"
+        android:layout_marginStart="16dip"
+        android:duplicateParentState="true">
 
         <TextView
             android:id="@+id/title"
@@ -47,24 +49,45 @@
             android:layout_height="wrap_content"
             android:textAppearance="?android:attr/textAppearanceMedium"
             android:singleLine="true"
-            android:ellipsize="marquee"
+            android:ellipsize="end"
+            android:textIsSelectable="false"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentStart="true"
             android:fadingEdge="horizontal"
+            android:textAlignment="viewStart"
             android:textColor="?android:attr/textColorPrimary"
-            android:textIsSelectable="false">
+            android:duplicateParentState="true">
         </TextView>
 
         <TextView
             android:id="@+id/subtitle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_below="@id/title"
+            android:layout_alignParentStart="true"
             android:textAppearance="?android:attr/textAppearanceSmall"
             android:singleLine="true"
             android:ellipsize="end"
             android:textIsSelectable="false"
             android:visibility="gone"
-            android:textColor="?android:attr/textColorSecondary">
+            android:textColor="?android:attr/textColorSecondary"
+            android:textAlignment="viewStart"
+            android:duplicateParentState="true">
         </TextView>
 
-    </LinearLayout>
+    </RelativeLayout>
+
+    <ImageView
+        android:id="@+id/more_info"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:paddingLeft="16dip"
+        android:contentDescription="@string/printer_info_desc"
+        android:src="@drawable/ic_info"
+        android:tint="?android:attr/colorControlNormal"
+        android:tintMode="src_in"
+        android:visibility="gone">
+    </ImageView>
 
 </LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 438afa9..76bc8b5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4034,6 +4034,9 @@
     <!-- Utterance to announce that the search box is hidden. This is spoken to a blind user. [CHAR LIMIT=none] -->
     <string name="print_search_box_hidden_utterance">Search box hidden</string>
 
+    <!-- Description of printer info icon. [CHAR LIMIT=50] -->
+    <string name="printer_info_desc">More information about this printer</string>
+
     <!-- App Fuel Gauge strings -->
     <skip />
 
diff --git a/src/com/android/settings/print/PrintServiceSettingsFragment.java b/src/com/android/settings/print/PrintServiceSettingsFragment.java
index 2adfb17..a9dba1e 100644
--- a/src/com/android/settings/print/PrintServiceSettingsFragment.java
+++ b/src/com/android/settings/print/PrintServiceSettingsFragment.java
@@ -40,11 +40,13 @@
 import android.print.PrinterInfo;
 import android.text.TextUtils;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.View.OnClickListener;
 import android.view.accessibility.AccessibilityManager;
 import android.widget.AdapterView;
 import android.widget.BaseAdapter;
@@ -529,6 +531,17 @@
             return position;
         }
 
+        /**
+         * Checks if a printer can be used for printing
+         *
+         * @param position The position of the printer in the list
+         * @return true iff the printer can be used for printing.
+         */
+        public boolean isActionable(int position) {
+            PrinterInfo printer = (PrinterInfo) getItem(position);
+            return printer.getStatus() != PrinterInfo.STATUS_UNAVAILABLE;
+        }
+
         @Override
         public View getView(int position, View convertView, ViewGroup parent) {
             if (convertView == null) {
@@ -536,7 +549,9 @@
                         R.layout.printer_dropdown_item, parent, false);
             }
 
-            PrinterInfo printer = (PrinterInfo) getItem(position);
+            convertView.setEnabled(isActionable(position));
+
+            final PrinterInfo printer = (PrinterInfo) getItem(position);
             CharSequence title = printer.getName();
             CharSequence subtitle = printer.getDescription();
             Drawable icon = printer.loadIcon(getActivity());
@@ -553,10 +568,36 @@
                 subtitleView.setVisibility(View.GONE);
             }
 
+            ImageView moreInfoView = (ImageView) convertView.findViewById(R.id.more_info);
+            if (printer.getInfoIntent() != null) {
+                moreInfoView.setVisibility(View.VISIBLE);
+                moreInfoView.setOnClickListener(new OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                        try {
+                            getActivity().startIntentSender(
+                                    printer.getInfoIntent().getIntentSender(), null, 0, 0, 0);
+                        } catch (SendIntentException e) {
+                            Log.e(LOG_TAG, "Could not execute pending info intent: %s", e);
+                        }
+                    }
+                });
+            } else {
+                moreInfoView.setVisibility(View.GONE);
+            }
+
             ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
             if (icon != null) {
-                iconView.setImageDrawable(icon);
                 iconView.setVisibility(View.VISIBLE);
+                if (!isActionable(position)) {
+                    icon.mutate();
+
+                    TypedValue value = new TypedValue();
+                    getActivity().getTheme().resolveAttribute(android.R.attr.disabledAlpha, value,
+                            true);
+                    icon.setAlpha((int)(value.getFloat() * 255));
+                }
+                iconView.setImageDrawable(icon);
             } else {
                 iconView.setVisibility(View.GONE);
             }