Make it easier to have different themes for different configs

This should have no visible UI effects

Change-Id: I0d7bd0338adb4bef04f060705c27e5ba3c6dcbd8
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index e5f3744..bf6ec36 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -37,12 +37,13 @@
 
     <application android:label="@string/app_name"
                  android:icon="@drawable/search_app_icon"
-                 android:name=".QsbApplicationWrapper">
+                 android:name=".QsbApplicationWrapper"
+                 android:theme="@style/Theme.QuickSearchBox">
         <activity android:name=".SearchActivity"
                   android:label="@string/app_name"
                   android:launchMode="singleTask"
                   android:windowSoftInputMode="stateAlwaysVisible|adjustResize"
-                  android:theme="@style/Theme.QuickSearchBox">
+                  android:theme="@style/Theme.QuickSearchBox.Search">
             <!-- Show app icon in Launcher. -->
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -120,7 +121,7 @@
 
         <!-- This class name is referenced in res/xml/search_widget_info.xml -->
         <activity android:name="com.android.quicksearchbox.SearchWidgetConfigActivity"
-                android:theme="@style/Theme.SearchWidgetConfig">
+                android:theme="@style/Theme.QuickSearchBox.SearchWidgetConfig">
             <intent-filter>
                 <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
             </intent-filter>
diff --git a/res/layout/contact_suggestion.xml b/res/layout/contact_suggestion.xml
index c4abc86..f216050 100644
--- a/res/layout/contact_suggestion.xml
+++ b/res/layout/contact_suggestion.xml
@@ -17,9 +17,7 @@
 <view
     xmlns:android="http://schemas.android.com/apk/res/android"
     class="com.android.quicksearchbox.ui.ContactSuggestionView"
-    android:layout_width="match_parent"
-    android:background="@drawable/suggestion_background"
-    android:layout_height="56dip" >
+    style="@style/Suggestion">
 
     <!-- Icons come first in the layout, since their placement doesn't depend on
          the placement of the text views. -->
@@ -54,10 +52,7 @@
     <!-- The subtitle comes before the title, since the height of the title depends on whether the
          subtitle is visible or gone. -->
     <TextView android:id="@+id/text2"
-        style="?android:attr/dropDownItemStyle"
-        android:textStyle="normal"
-        android:textColor="@android:color/secondary_text_light"
-        android:textSize="13sp"
+        style="@style/SuggestionText2"
         android:singleLine="true"
         android:layout_width="match_parent"
         android:layout_height="29dip"
@@ -73,10 +68,7 @@
     <!-- The title is placed above the subtitle, if there is one. If there is no
          subtitle, it fills the parent. -->
     <TextView android:id="@+id/text1"
-        style="?android:attr/dropDownItemStyle"
-        android:textStyle="normal"
-        android:textColor="@android:color/primary_text_light"
-        android:textSize="16sp"
+        style="@style/SuggestionText1"
         android:singleLine="true"
         android:paddingRight="2dip"
         android:layout_width="match_parent"
diff --git a/res/layout/suggestion.xml b/res/layout/suggestion.xml
index a873faf..e89679f 100644
--- a/res/layout/suggestion.xml
+++ b/res/layout/suggestion.xml
@@ -17,10 +17,7 @@
 <view
     xmlns:android="http://schemas.android.com/apk/res/android"
     class="com.android.quicksearchbox.ui.DefaultSuggestionView"
-    android:layout_width="match_parent"
-    android:background="@drawable/suggestion_background"
-    android:layout_height="56dip"
-    android:focusable="true" >
+    style="@style/Suggestion">
 
     <!-- Icons come first in the layout, since their placement doesn't depend on
          the placement of the text views. -->
@@ -48,10 +45,7 @@
     <!-- The subtitle comes before the title, since the height of the title depends on whether the
          subtitle is visible or gone. -->
     <TextView android:id="@+id/text2"
-        style="?android:attr/dropDownItemStyle"
-        android:textStyle="normal"
-        android:textColor="@android:color/secondary_text_light"
-        android:textSize="13sp"
+        style="@style/SuggestionText2"
         android:singleLine="true"
         android:layout_width="match_parent"
         android:layout_height="29dip"
@@ -67,11 +61,8 @@
     <!-- The title is placed above the subtitle, if there is one. If there is no
          subtitle, it fills the parent. -->
     <TextView android:id="@+id/text1"
-        style="?android:attr/dropDownItemStyle"
+        style="@style/SuggestionText1"
         android:ellipsize="start"
-        android:textStyle="normal"
-        android:textColor="@android:color/primary_text_light"
-        android:textSize="16sp"
         android:singleLine="true"
         android:paddingRight="2dip"
         android:layout_width="match_parent"
diff --git a/res/values/config.xml b/res/values/config.xml
index 0c3eb64..535cab1 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -55,4 +55,8 @@
 
   <!-- The maximum promoted suggestions -->
   <integer name="max_promoted_suggestions">8</integer>
+
+  <!-- The number of columns in the corpus selection dialog -->
+  <integer name="corpus_selection_dialog_columns">4</integer>
+
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 2e2fa17..8b614f0 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -15,28 +15,31 @@
 -->
 
 <resources>
-    <style name="Theme.QuickSearchBox" parent="@android:style/Theme.Light.NoTitleBar">
-        <!-- Get rid of status bar shadow. -->
-        <item name="android:windowSoftInputMode">stateUnchanged|adjustResize</item>
-        <item name="android:windowContentOverlay">@null</item>
-        <item name="android:windowIsTranslucent">true</item>
-        <item name="android:windowBackground">@android:color/transparent</item>
+
+    <style name="Suggestion">
+        <item name="android:layout_width">match_parent</item>
+        <item name="android:background">@drawable/suggestion_background</item>
+        <item name="android:layout_height">56dip</item>
+        <item name="android:focusable">true</item>
     </style>
 
-    <style name="Theme.SearchWidgetConfig" parent="@android:style/Theme.Dialog">
-        <item name="android:windowBackground">@android:color/transparent</item>
+    <style name="SuggestionText1">
+        <item name="android:textStyle">normal</item>
+        <item name="android:textColor">?android:attr/textColorPrimary</item>
+        <item name="android:textSize">16sp</item>
     </style>
 
-    <style name="Theme.SelectSearchSource" parent="@android:style/Theme.Light.NoTitleBar">
-        <item name="android:windowSoftInputMode">stateUnchanged|adjustResize</item>
-        <item name="android:colorBackgroundCacheHint">@null</item>
-        <item name="android:windowFrame">@null</item>
-        <item name="android:windowContentOverlay">@null</item>
-        <item name="android:windowIsFloating">true</item>
-        <item name="android:backgroundDimEnabled">false</item>
-        <item name="android:windowIsTranslucent">true</item>
-        <item name="android:windowAnimationStyle">@style/Animation.SelectSearchSource</item>
-        <item name="android:windowBackground">@android:color/transparent</item>
+    <style name="SuggestionText2">
+        <item name="android:textStyle">normal</item>
+        <item name="android:textColor">?android:attr/textColorSecondary</item>
+        <item name="android:textSize">13sp</item>
+    </style>
+
+    <style name="SuggestionText1.Query" parent="@style/SuggestionText1">
+    </style>
+
+    <style name="SuggestionText1.Suggested" parent="@style/SuggestionText1">
+        <item name="android:textStyle">bold</item>
     </style>
 
     <style name="Animation.SelectSearchSource" parent="@android:style/Animation">
@@ -44,19 +47,4 @@
         <item name="android:windowExitAnimation">@anim/corpus_selector_close</item>
     </style>
 
-    <!-- The number of columns in the business listing launcher GridView -->
-    <integer name="corpus_selection_dialog_columns">4</integer>
-
-    <style name="SuggestionQueryTextAppearance">
-        <item name="android:textStyle">normal</item>
-        <item name="android:textColor">#ff000000</item>
-        <item name="android:textSize">16sp</item>
-    </style>
-
-    <style name="SuggestionSuggestedTextAppearance">
-        <item name="android:textStyle">bold</item>
-        <item name="android:textColor">#ff000000</item>
-        <item name="android:textSize">16sp</item>
-    </style>
-
 </resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml
new file mode 100644
index 0000000..92b574e
--- /dev/null
+++ b/res/values/themes.xml
@@ -0,0 +1,48 @@
+<?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.
+-->
+
+<resources>
+
+    <style name="Theme.QuickSearchBox" parent="@android:style/Theme.Light">
+    </style>
+
+    <style name="Theme.QuickSearchBox.Search" parent="@style/Theme.QuickSearchBox">
+        <item name="android:windowActionBar">false</item>
+        <item name="android:windowNoTitle">true</item>
+        <!-- Get rid of status bar shadow. -->
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowIsTranslucent">true</item>
+        <item name="android:windowBackground">@android:color/transparent</item>
+        <item name="android:windowSoftInputMode">stateUnchanged|adjustResize</item>
+    </style>
+
+    <style name="Theme.QuickSearchBox.SearchWidgetConfig" parent="@android:style/Theme.Dialog">
+        <item name="android:windowBackground">@android:color/transparent</item>
+    </style>
+
+    <style name="Theme.SelectSearchSource" parent="@android:style/Theme.Light.NoTitleBar">
+        <item name="android:windowSoftInputMode">stateUnchanged|adjustResize</item>
+        <item name="android:colorBackgroundCacheHint">@null</item>
+        <item name="android:windowFrame">@null</item>
+        <item name="android:windowContentOverlay">@null</item>
+        <item name="android:windowIsFloating">true</item>
+        <item name="android:backgroundDimEnabled">false</item>
+        <item name="android:windowIsTranslucent">true</item>
+        <item name="android:windowAnimationStyle">@style/Animation.SelectSearchSource</item>
+        <item name="android:windowBackground">@android:color/transparent</item>
+    </style>
+
+</resources>
diff --git a/src/com/android/quicksearchbox/QsbApplication.java b/src/com/android/quicksearchbox/QsbApplication.java
index 57969d3..4b1bac1 100644
--- a/src/com/android/quicksearchbox/QsbApplication.java
+++ b/src/com/android/quicksearchbox/QsbApplication.java
@@ -37,6 +37,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Process;
+import android.view.ContextThemeWrapper;
 
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
@@ -66,7 +67,8 @@
     private TextAppearanceFactory mTextAppearanceFactory;
 
     public QsbApplication(Context context) {
-        mContext = context;
+        // the application context does not use the theme from the <application> tag
+        mContext = new ContextThemeWrapper(context, R.style.Theme_QuickSearchBox);
     }
 
     public static boolean isFroyoOrLater() {
diff --git a/src/com/android/quicksearchbox/TextAppearanceFactory.java b/src/com/android/quicksearchbox/TextAppearanceFactory.java
index a8324ae..af950d9 100644
--- a/src/com/android/quicksearchbox/TextAppearanceFactory.java
+++ b/src/com/android/quicksearchbox/TextAppearanceFactory.java
@@ -31,13 +31,13 @@
 
     public Object[] createSuggestionQueryTextAppearance() {
         return new Object[]{
-                new TextAppearanceSpan(mContext, R.style.SuggestionQueryTextAppearance)
+                new TextAppearanceSpan(mContext, R.style.SuggestionText1_Query)
         };
     }
 
     public Object[] createSuggestionSuggestedTextAppearance() {
         return new Object[]{
-                new TextAppearanceSpan(mContext, R.style.SuggestionSuggestedTextAppearance)
+                new TextAppearanceSpan(mContext, R.style.SuggestionText1_Suggested)
         };
     }