Adds UI support for custom search widget item backgrounds.

- A new column was added to SearchManager cursors to specify background color (optional)
- Two new colour references added to the theme for normal and search widget corpus items (we need both to be opaque for the items to render properly)
- SuggestionAdapter was updated to choose the right theme colour for each item
This commit is contained in:
Satish Sampath
2009-06-08 23:10:40 +01:00
parent 27a2b50ded
commit 1c5fa0f310
5 changed files with 74 additions and 35 deletions

View File

@@ -1359,6 +1359,15 @@ public class SearchManager
*/ */
public final static String SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id"; public final static String SUGGEST_COLUMN_SHORTCUT_ID = "suggest_shortcut_id";
/**
* Column name for suggestions cursor. <i>Optional.</i> This column is used to specify the
* cursor item's background color if it needs a non-default background color. A non-zero value
* indicates a valid background color to override the default.
*
* @hide For internal use, not part of the public API.
*/
public final static String SUGGEST_COLUMN_BACKGROUND_COLOR = "suggest_background_color";
/** /**
* Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion * Column value for suggestion column {@link #SUGGEST_COLUMN_SHORTCUT_ID} when a suggestion
* should not be stored as a shortcut in global search. * should not be stored as a shortcut in global search.

View File

@@ -27,6 +27,7 @@ import android.server.search.SearchableInfo;
import android.text.Html; import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@@ -62,6 +63,10 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
private int mText2Col; private int mText2Col;
private int mIconName1Col; private int mIconName1Col;
private int mIconName2Col; private int mIconName2Col;
private int mBackgroundColorCol;
// Cached item background color.
private int mDefaultBackgroundColor;
// This value is stored in SuggestionsAdapter by the SearchDialog to indicate whether // This value is stored in SuggestionsAdapter by the SearchDialog to indicate whether
// a particular list item should be selected upon the next call to notifyDataSetChanged. // a particular list item should be selected upon the next call to notifyDataSetChanged.
@@ -91,6 +96,11 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
Context activityContext = mSearchable.getActivityContext(mContext); Context activityContext = mSearchable.getActivityContext(mContext);
mProviderContext = mSearchable.getProviderContext(mContext, activityContext); mProviderContext = mSearchable.getProviderContext(mContext, activityContext);
TypedValue colorValue = new TypedValue();
mProviderContext.getTheme().resolveAttribute(
com.android.internal.R.attr.searchWidgetItemBackground, colorValue, true);
mDefaultBackgroundColor = mProviderContext.getResources().getColor(colorValue.resourceId);
mOutsideDrawablesCache = outsideDrawablesCache; mOutsideDrawablesCache = outsideDrawablesCache;
mGlobalSearchMode = globalSearchMode; mGlobalSearchMode = globalSearchMode;
} }
@@ -139,6 +149,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mText2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2); mText2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2);
mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1); mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1);
mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2); mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2);
mBackgroundColorCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_BACKGROUND_COLOR);
} }
} }
@@ -254,6 +265,15 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mDisplayNotifyPos = NONE; // only notify the first time mDisplayNotifyPos = NONE; // only notify the first time
} }
int backgroundColor = 0;
if (mBackgroundColorCol != -1) {
backgroundColor = cursor.getInt(mBackgroundColorCol);
}
if (backgroundColor == 0) {
backgroundColor = mDefaultBackgroundColor;
}
view.setBackgroundColor(backgroundColor);
final boolean isHtml = mFormatCol > 0 && "html".equals(cursor.getString(mFormatCol)); final boolean isHtml = mFormatCol > 0 && "html".equals(cursor.getString(mFormatCol));
setViewText(cursor, views.mText1, mText1Col, isHtml); setViewText(cursor, views.mText1, mText1Col, isHtml);
setViewText(cursor, views.mText2, mText2Col, isHtml); setViewText(cursor, views.mText2, mText2Col, isHtml);

View File

@@ -82,6 +82,10 @@
<!-- Text color for urls in search suggestions, used by things like global search and the browser. @hide --> <!-- Text color for urls in search suggestions, used by things like global search and the browser. @hide -->
<attr name="textColorSearchUrl" format="reference|color" /> <attr name="textColorSearchUrl" format="reference|color" />
<!-- Search widget result item background. -->
<attr name="searchWidgetItemBackground" format="reference|color" />
<!-- Search widget expandable result item background. -->
<attr name="searchWidgetCorpusItemBackground" format="reference|color" />
<!-- Text color, typeface, size, and style for "large" text. Defaults to primary text color. --> <!-- Text color, typeface, size, and style for "large" text. Defaults to primary text color. -->
<attr name="textAppearanceLarge" format="reference" /> <attr name="textAppearanceLarge" format="reference" />

View File

@@ -75,6 +75,8 @@
<!-- For search-related UIs --> <!-- For search-related UIs -->
<color name="search_url_text">#7fa87f</color> <color name="search_url_text">#7fa87f</color>
<color name="search_widget_item_background">@android:color/white</color>
<color name="search_widget_corpus_item_background">@android:color/lighter_gray</color>
</resources> </resources>

View File

@@ -183,6 +183,10 @@
<item name="editTextPreferenceStyle">@android:style/Preference.DialogPreference.EditTextPreference</item> <item name="editTextPreferenceStyle">@android:style/Preference.DialogPreference.EditTextPreference</item>
<item name="ringtonePreferenceStyle">@android:style/Preference.RingtonePreference</item> <item name="ringtonePreferenceStyle">@android:style/Preference.RingtonePreference</item>
<item name="preferenceLayoutChild">@android:layout/preference_child</item> <item name="preferenceLayoutChild">@android:layout/preference_child</item>
<!-- Search widget styles -->
<item name="searchWidgetItemBackground">@android:color/search_widget_item_background</item>
<item name="searchWidgetCorpusItemBackground">@android:color/search_widget_corpus_item_background</item>
</style> </style>
<!-- Variant of the default (dark) theme with no title bar --> <!-- Variant of the default (dark) theme with no title bar -->