Add corpus icons to 'Searchable items' settings screen.

Change-Id: I90e051e48932ba405353c38c4a4ad6e93fd0fec9
diff --git a/res/layout/searchable_item_preference.xml b/res/layout/searchable_item_preference.xml
new file mode 100644
index 0000000..89850e8
--- /dev/null
+++ b/res/layout/searchable_item_preference.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<!-- Based on /frameworks/base/core/res/res/layout/preference.xml -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:minHeight="?android:attr/listPreferredItemHeight"
+    android:gravity="center_vertical"
+    android:paddingRight="?android:attr/scrollbarSize">
+
+    <ImageView android:id="@+id/icon"
+        android:layout_width="48dip"
+        android:layout_height="48dip"/>
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="15dip"
+        android:layout_marginRight="6dip"
+        android:layout_marginTop="6dip"
+        android:layout_marginBottom="6dip"
+        android:layout_weight="1">
+
+        <TextView android:id="@+android:id/title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:singleLine="true"
+            android:textAppearance="?android:attr/textAppearanceLarge"
+            android:ellipsize="marquee"
+            android:fadingEdge="horizontal" />
+
+        <TextView android:id="@+android:id/summary"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_below="@android:id/title"
+            android:layout_alignLeft="@android:id/title"
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:maxLines="4" />
+
+    </RelativeLayout>
+
+    <!-- Preference should place its actual preference widget here. -->
+    <LinearLayout android:id="@+android:id/widget_frame"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:gravity="center_vertical"
+        android:orientation="vertical" />
+
+</LinearLayout>
diff --git a/src/com/android/quicksearchbox/SearchSettings.java b/src/com/android/quicksearchbox/SearchSettings.java
index 73dfb2d..80fe835 100644
--- a/src/com/android/quicksearchbox/SearchSettings.java
+++ b/src/com/android/quicksearchbox/SearchSettings.java
@@ -60,7 +60,7 @@
     private static final String SEARCH_ENGINE_SETTINGS_PREF = "search_engine_settings";
     private static final String SEARCH_CORPORA_PREF = "search_corpora";
 
-    // Preifx of per-corpus enable preference
+    // Prefix of per-corpus enable preference
     private static final String CORPUS_ENABLED_PREF_PREFIX = "enable_corpus_";
     private static final String VOICE_SEARCH_HINTS_ENABLED_PREF = "voice_search_hints_enabled";
 
diff --git a/src/com/android/quicksearchbox/SearchableItemPreference.java b/src/com/android/quicksearchbox/SearchableItemPreference.java
new file mode 100644
index 0000000..36bb874
--- /dev/null
+++ b/src/com/android/quicksearchbox/SearchableItemPreference.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.quicksearchbox;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.preference.CheckBoxPreference;
+import android.view.View;
+import android.widget.ImageView;
+
+/**
+ * A CheckBoxPreference with an icon added.
+ */
+public class SearchableItemPreference extends CheckBoxPreference {
+
+    private Drawable mIcon;
+
+    SearchableItemPreference(Context context) {
+        super(context);
+        setLayoutResource(R.layout.searchable_item_preference);
+    }
+
+    public void setIcon(Drawable icon) {
+        mIcon = icon;
+    }
+
+     @Override
+    protected void onBindView(View view) {
+        super.onBindView(view);
+        ImageView icon = (ImageView) view.findViewById(R.id.icon);
+        icon.setImageDrawable(mIcon);
+    }
+
+}
diff --git a/src/com/android/quicksearchbox/SearchableItemsSettings.java b/src/com/android/quicksearchbox/SearchableItemsSettings.java
index d2f13d9..a279593 100644
--- a/src/com/android/quicksearchbox/SearchableItemsSettings.java
+++ b/src/com/android/quicksearchbox/SearchableItemsSettings.java
@@ -17,7 +17,6 @@
 package com.android.quicksearchbox;
 
 import android.os.Bundle;
-import android.preference.CheckBoxPreference;
 import android.preference.Preference;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceGroup;
@@ -79,7 +78,7 @@
      * Adds a suggestion source to the list of suggestion source checkbox preferences.
      */
     private Preference createCorpusPreference(Corpus corpus) {
-        CheckBoxPreference sourcePref = new CheckBoxPreference(this);
+        SearchableItemPreference sourcePref = new SearchableItemPreference(this);
         sourcePref.setKey(SearchSettings.getCorpusEnabledPreference(corpus));
         // Put web corpus first. The rest are alphabetical.
         if (corpus.isWebCorpus()) {
@@ -92,6 +91,7 @@
         CharSequence description = corpus.getSettingsDescription();
         sourcePref.setSummaryOn(description);
         sourcePref.setSummaryOff(description);
+        sourcePref.setIcon(corpus.getCorpusIcon());
         return sourcePref;
     }