Add support to SuggestionsAdapter to query the 'working' status

of its underlying cursor and update a spinner in the search dialog
accordingly.
This commit is contained in:
Mike LeBeau
2009-05-20 17:22:13 -07:00
parent b204d4f127
commit 1480eb27f5
16 changed files with 94 additions and 5 deletions

View File

@@ -31,6 +31,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
@@ -103,6 +104,7 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
private Button mGoButton;
private ImageButton mVoiceButton;
private View mSearchPlate;
private AnimationDrawable mWorkingSpinner;
// interaction with searchable application
private SearchableInfo mSearchable;
@@ -182,6 +184,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
mGoButton = (Button) findViewById(com.android.internal.R.id.search_go_btn);
mVoiceButton = (ImageButton) findViewById(com.android.internal.R.id.search_voice_btn);
mSearchPlate = findViewById(com.android.internal.R.id.search_plate);
mWorkingSpinner = (AnimationDrawable) getContext().getResources().
getDrawable(com.android.internal.R.drawable.search_spinner);
// attach listeners
mSearchAutoComplete.addTextChangedListener(mTextWatcher);
@@ -239,7 +243,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
return doShow(initialQuery, selectInitialQuery, componentName, appSearchData, globalSearch);
}
/**
* Called in response to a press of the hard search button in
* {@link #onKeyDown(int, KeyEvent)}, this method toggles between in-app
@@ -395,6 +398,24 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
mPreviousComponents = null;
}
/**
* Sets the search dialog to the 'working' state, which shows a working spinner in the
* right hand size of the text field.
*
* @param working true to show spinner, false to hide spinner
*/
public void setWorking(boolean working) {
if (working) {
mSearchAutoComplete.setCompoundDrawablesWithIntrinsicBounds(
null, null, mWorkingSpinner, null);
mWorkingSpinner.start();
} else {
mSearchAutoComplete.setCompoundDrawablesWithIntrinsicBounds(
null, null, null, null);
mWorkingSpinner.stop();
}
}
/**
* Closes and gets rid of the suggestions adapter.
*/
@@ -563,8 +584,8 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
// attach the suggestions adapter, if suggestions are available
// The existence of a suggestions authority is the proxy for "suggestions available here"
if (mSearchable.getSuggestAuthority() != null) {
mSuggestionsAdapter = new SuggestionsAdapter(getContext(), mSearchable,
mOutsideDrawablesCache);
mSuggestionsAdapter = new SuggestionsAdapter(getContext(), this, mSearchable,
mOutsideDrawablesCache, mGlobalSearchMode);
mSearchAutoComplete.setAdapter(mSuggestionsAdapter);
}
}

View File

@@ -25,6 +25,7 @@ import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.server.search.SearchableInfo;
import android.text.Html;
import android.text.TextUtils;
@@ -45,12 +46,18 @@ import java.util.WeakHashMap;
* @hide
*/
class SuggestionsAdapter extends ResourceCursorAdapter {
// The value used to query a cursor whether it is still expecting more input,
// so we can correctly display (or not display) the 'working' spinner in the search dialog.
public static final String IS_WORKING = "isWorking";
private static final boolean DBG = false;
private static final String LOG_TAG = "SuggestionsAdapter";
private SearchDialog mSearchDialog;
private SearchableInfo mSearchable;
private Context mProviderContext;
private WeakHashMap<String, Drawable> mOutsideDrawablesCache;
private boolean mGlobalSearchMode;
// Cached column indexes, updated when the cursor changes.
private int mFormatCol;
@@ -61,12 +68,13 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
private int mIconBitmap1Col;
private int mIconBitmap2Col;
public SuggestionsAdapter(Context context, SearchableInfo searchable,
WeakHashMap<String, Drawable> outsideDrawablesCache) {
public SuggestionsAdapter(Context context, SearchDialog searchDialog, SearchableInfo searchable,
WeakHashMap<String, Drawable> outsideDrawablesCache, boolean globalSearchMode) {
super(context,
com.android.internal.R.layout.search_dropdown_item_icons_2line,
null, // no initial cursor
true); // auto-requery
mSearchDialog = searchDialog;
mSearchable = searchable;
// set up provider resources (gives us icons, etc.)
@@ -74,6 +82,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mProviderContext = mSearchable.getProviderContext(mContext, activityContext);
mOutsideDrawablesCache = outsideDrawablesCache;
mGlobalSearchMode = globalSearchMode;
}
/**
@@ -118,6 +127,28 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mIconBitmap1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1_BITMAP);
mIconBitmap2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2_BITMAP);
}
updateWorking();
}
@Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
updateWorking();
}
/**
* Updates the search dialog according to the current working status of the cursor.
*/
private void updateWorking() {
if (!mGlobalSearchMode || mCursor == null) return;
Bundle request = new Bundle();
request.putString(SearchManager.EXTRA_DATA_KEY, IS_WORKING);
Bundle response = mCursor.respond(request);
if (response.containsKey(IS_WORKING)) {
boolean isWorking = response.getBoolean(IS_WORKING);
mSearchDialog.setWorking(isWorking);
}
}
/**