summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/current.xml11
-rw-r--r--core/java/android/app/SearchManager.java8
-rw-r--r--core/java/android/app/SuggestionsAdapter.java52
3 files changed, 64 insertions, 7 deletions
diff --git a/api/current.xml b/api/current.xml
index 1f7be9e..eae20e7 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -24220,6 +24220,17 @@
visibility="public"
>
</field>
+<field name="CURSOR_EXTRA_KEY_IN_PROGRESS"
+ type="java.lang.String"
+ transient="false"
+ volatile="false"
+ value="&quot;in_progress&quot;"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
<field name="EXTRA_DATA_KEY"
type="java.lang.String"
transient="false"
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index 67f9629..0ed572a 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -1300,6 +1300,14 @@ public class SearchManager
public final static String EXTRA_SELECT_QUERY = "select_query";
/**
+ * Boolean extra data key for a suggestion provider to return in {@link Cursor#getExtras} to
+ * indicate that the search is not complete yet. This can be used by the search UI
+ * to indicate that a search is in progress. The suggestion provider can return partial results
+ * this way and send a change notification on the cursor when more results are available.
+ */
+ public final static String CURSOR_EXTRA_KEY_IN_PROGRESS = "in_progress";
+
+ /**
* Intent extra data key: Use this key with Intent.ACTION_SEARCH and
* {@link android.content.Intent#getStringExtra content.Intent.getStringExtra()}
* to obtain the action message that was defined for a particular search action key and/or
diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java
index 07e9793..3e11a3f 100644
--- a/core/java/android/app/SuggestionsAdapter.java
+++ b/core/java/android/app/SuggestionsAdapter.java
@@ -159,19 +159,23 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
* for in app search we show the progress spinner until the cursor is returned with
* the results.
*/
+ Cursor cursor = null;
mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable);
try {
- final Cursor cursor = mSearchManager.getSuggestions(mSearchable, query, QUERY_LIMIT);
+ cursor = mSearchManager.getSuggestions(mSearchable, query, QUERY_LIMIT);
// trigger fill window so the spinner stays up until the results are copied over and
// closer to being ready
- if (cursor != null) cursor.getCount();
- return cursor;
+ if (cursor != null) {
+ cursor.getCount();
+ return cursor;
+ }
} catch (RuntimeException e) {
Log.w(LOG_TAG, "Search suggestions query threw an exception.", e);
- return null;
- } finally {
- mSearchDialog.getWindow().getDecorView().post(mStopSpinnerRunnable);
}
+ // If cursor is null or an exception was thrown, stop the spinner and return null.
+ // changeCursor doesn't get called if cursor is null
+ mSearchDialog.getWindow().getDecorView().post(mStopSpinnerRunnable);
+ return null;
}
public void close() {
@@ -180,6 +184,39 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mClosed = true;
}
+ @Override
+ public void notifyDataSetChanged() {
+ if (DBG) Log.d(LOG_TAG, "notifyDataSetChanged");
+ super.notifyDataSetChanged();
+
+ updateSpinnerState(getCursor());
+ }
+
+ @Override
+ public void notifyDataSetInvalidated() {
+ if (DBG) Log.d(LOG_TAG, "notifyDataSetInvalidated");
+ super.notifyDataSetInvalidated();
+
+ updateSpinnerState(getCursor());
+ }
+
+ private void updateSpinnerState(Cursor cursor) {
+ if (DBG) {
+ Log.d(LOG_TAG, "updateSpinnerState - extra = "
+ + (cursor != null
+ ? cursor.getExtras().getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)
+ : null));
+ }
+ // Check if the Cursor indicates that the query is not complete and show the spinner
+ if (cursor != null
+ && cursor.getExtras().getBoolean(SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS)) {
+ mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable);
+ return;
+ }
+ // If cursor is null or is done, stop the spinner
+ mSearchDialog.getWindow().getDecorView().post(mStopSpinnerRunnable);
+ }
+
/**
* Cache columns.
*/
@@ -202,7 +239,8 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
mText2UrlCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL);
mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1);
mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2);
- mBackgroundColorCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_BACKGROUND_COLOR);
+ mBackgroundColorCol =
+ c.getColumnIndex(SearchManager.SUGGEST_COLUMN_BACKGROUND_COLOR);
}
} catch (Exception e) {
Log.e(LOG_TAG, "error changing cursor and caching columns", e);