Add searchSuggestThreshold to searchable meta-data.
This lets the searchable activity specify the number of characters needed to trigger suggestions. Before, this was hard-coded at 0. This caused unnecessary querying of the suggestion provider in cases where the provider does not return suggestions for empty or short queries. The attribute is not yet public, pending API council approval.
This commit is contained in:
@@ -472,7 +472,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
closeSuggestionsAdapter();
|
||||
|
||||
mSearchAutoComplete.setDropDownAnimationStyle(0); // no animation
|
||||
mSearchAutoComplete.setThreshold(0); // always allow zero-query suggestions
|
||||
mSearchAutoComplete.setThreshold(mSearchable.getSuggestThreshold());
|
||||
|
||||
if (mGlobalSearchMode) {
|
||||
mSearchAutoComplete.setDropDownAlwaysVisible(true); // fill space until results come in
|
||||
|
||||
@@ -71,6 +71,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
private String mSuggestSelection = null;
|
||||
private String mSuggestIntentAction = null;
|
||||
private String mSuggestIntentData = null;
|
||||
private int mSuggestThreshold = 0;
|
||||
private ActionKeyInfo mActionKeyList = null;
|
||||
private String mSuggestProviderPackage = null;
|
||||
|
||||
@@ -139,6 +140,16 @@ public final class SearchableInfo implements Parcelable {
|
||||
return mSuggestIntentData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the suggestion threshold for use with these suggestions.
|
||||
*
|
||||
* @return The value of the <code>searchSuggestThreshold</code> attribute,
|
||||
* or 0 if the attribute is not set.
|
||||
*/
|
||||
public int getSuggestThreshold() {
|
||||
return mSuggestThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context for the searchable activity.
|
||||
*
|
||||
@@ -238,6 +249,8 @@ public final class SearchableInfo implements Parcelable {
|
||||
com.android.internal.R.styleable.Searchable_searchSuggestIntentAction);
|
||||
mSuggestIntentData = a.getString(
|
||||
com.android.internal.R.styleable.Searchable_searchSuggestIntentData);
|
||||
mSuggestThreshold = a.getInt(
|
||||
com.android.internal.R.styleable.Searchable_searchSuggestThreshold, 0);
|
||||
}
|
||||
mVoiceSearchMode =
|
||||
a.getInt(com.android.internal.R.styleable.Searchable_voiceSearchMode, 0);
|
||||
@@ -600,6 +613,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
mSuggestSelection = in.readString();
|
||||
mSuggestIntentAction = in.readString();
|
||||
mSuggestIntentData = in.readString();
|
||||
mSuggestThreshold = in.readInt();
|
||||
|
||||
mActionKeyList = null;
|
||||
int count = in.readInt();
|
||||
@@ -636,6 +650,7 @@ public final class SearchableInfo implements Parcelable {
|
||||
dest.writeString(mSuggestSelection);
|
||||
dest.writeString(mSuggestIntentAction);
|
||||
dest.writeString(mSuggestIntentData);
|
||||
dest.writeInt(mSuggestThreshold);
|
||||
|
||||
// This is usually a very short linked list so we'll just pre-count it
|
||||
ActionKeyInfo nextKeyInfo = mActionKeyList;
|
||||
|
||||
@@ -2781,6 +2781,10 @@
|
||||
when the user clicks a suggestion. <i>Optional attribute.</i> -->
|
||||
<attr name="searchSuggestIntentData" format="string" />
|
||||
|
||||
<!-- If provided, this is the minimun number of characters needed to trigger
|
||||
search suggestions. The default value is 0. <i>Optional attribute.</i> -->
|
||||
<attr name="searchSuggestThreshold" format="integer" />
|
||||
|
||||
</declare-styleable>
|
||||
|
||||
<!-- In order to process special action keys during search, you must define them using
|
||||
|
||||
Reference in New Issue
Block a user