Skip to content

Commit 8790764

Browse files
author
Amith Yamasani
committed
Close suggestions cursor when SearchView is detached.
Make sure that delayed filter requests don't go through after the view was detached. Bug: 5484819 Change-Id: I4d5ff5ea9b52109ecce7f84fa4d91dfcb6225037
1 parent 00ef15b commit 8790764

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

core/java/android/widget/SearchView.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ public void run() {
151151
}
152152
};
153153

154+
private Runnable mReleaseCursorRunnable = new Runnable() {
155+
public void run() {
156+
if (mSuggestionsAdapter != null && mSuggestionsAdapter instanceof SuggestionsAdapter) {
157+
mSuggestionsAdapter.changeCursor(null);
158+
}
159+
}
160+
};
161+
154162
// For voice searching
155163
private final Intent mVoiceWebSearchIntent;
156164
private final Intent mVoiceAppSearchIntent;
@@ -759,6 +767,7 @@ private void updateFocusedState() {
759767
@Override
760768
protected void onDetachedFromWindow() {
761769
removeCallbacks(mUpdateDrawableStateRunnable);
770+
post(mReleaseCursorRunnable);
762771
super.onDetachedFromWindow();
763772
}
764773

@@ -1028,7 +1037,9 @@ private void updateSearchAutoComplete() {
10281037
}
10291038
}
10301039
mQueryTextView.setInputType(inputType);
1031-
1040+
if (mSuggestionsAdapter != null) {
1041+
mSuggestionsAdapter.changeCursor(null);
1042+
}
10321043
// attach the suggestions adapter, if suggestions are available
10331044
// The existence of a suggestions authority is the proxy for "suggestions available here"
10341045
if (mSearchable.getSuggestAuthority() != null) {
@@ -1177,7 +1188,6 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
11771188
public void onActionViewCollapsed() {
11781189
clearFocus();
11791190
updateViewsVisibility(true);
1180-
mQueryTextView.setText("");
11811191
mQueryTextView.setImeOptions(mCollapsedImeOptions);
11821192
mExpandedInActionView = false;
11831193
}
@@ -1190,6 +1200,7 @@ public void onActionViewExpanded() {
11901200
mExpandedInActionView = true;
11911201
mCollapsedImeOptions = mQueryTextView.getImeOptions();
11921202
mQueryTextView.setImeOptions(mCollapsedImeOptions | EditorInfo.IME_FLAG_NO_FULLSCREEN);
1203+
mQueryTextView.setText("");
11931204
setIconified(false);
11941205
}
11951206

core/java/android/widget/SuggestionsAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@
2929
import android.content.res.ColorStateList;
3030
import android.content.res.Resources;
3131
import android.database.Cursor;
32-
import android.graphics.drawable.ColorDrawable;
3332
import android.graphics.drawable.Drawable;
34-
import android.graphics.drawable.StateListDrawable;
3533
import android.net.Uri;
3634
import android.os.Bundle;
3735
import android.text.Spannable;
3836
import android.text.SpannableString;
3937
import android.text.TextUtils;
4038
import android.text.style.TextAppearanceSpan;
4139
import android.util.Log;
42-
import android.util.SparseArray;
4340
import android.util.TypedValue;
4441
import android.view.View;
4542
import android.view.ViewGroup;
@@ -113,7 +110,6 @@ public SuggestionsAdapter(Context context, SearchView searchView,
113110

114111
mOutsideDrawablesCache = outsideDrawablesCache;
115112

116-
117113
// mStartSpinnerRunnable = new Runnable() {
118114
// public void run() {
119115
// // mSearchView.setWorking(true); // TODO:
@@ -185,6 +181,10 @@ public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
185181
* the results.
186182
*/
187183
Cursor cursor = null;
184+
if (mSearchView.getVisibility() != View.VISIBLE
185+
|| mSearchView.getWindowVisibility() != View.VISIBLE) {
186+
return null;
187+
}
188188
//mSearchView.getWindow().getDecorView().post(mStartSpinnerRunnable); // TODO:
189189
try {
190190
cursor = mSearchManager.getSuggestions(mSearchable, query, QUERY_LIMIT);

core/res/res/layout/search_view.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
android:singleLine="true"
9494
android:ellipsize="end"
9595
android:background="@null"
96-
android:inputType="text|textAutoComplete"
96+
android:inputType="text|textAutoComplete|textNoSuggestions"
9797
android:imeOptions="actionSearch"
9898
android:dropDownHeight="wrap_content"
9999
android:dropDownAnchor="@id/search_edit_frame"

0 commit comments

Comments
 (0)