Merge change 2147 into donut

* changes:
  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:
Android (Google) Code Review
2009-05-20 20:34:49 -07:00
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);
}
}
/**

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2008, 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.
*/
-->
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/search_spinner_anim1" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim2" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim3" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim4" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim5" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim6" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim7" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim8" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim9" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim10" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim11" android:duration="150" />
<item android:drawable="@drawable/search_spinner_anim12" android:duration="150" />
</animation-list>

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 527 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 B

View File

@ -71,6 +71,7 @@
android:layout_weight="1.0"
android:paddingLeft="8dip"
android:paddingRight="6dip"
android:drawablePadding="2dip"
android:singleLine="true"
android:inputType="text|textAutoComplete"
android:dropDownWidth="fill_parent"