Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c37cb246 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Feature to return an extra in the cursor that keeps the spinny going.

If a search provider returns an extra in the cursor with the key
SearchManager.CURSOR_EXTRA_KEY_IN_PROGRESS, and the value true, then
the spinny in the search dialog will not stop, but the cursor
contents will still be used to update the results. This way, partial
search results can be sent while the user is informed that the search
is still in progress.
parent 1e5e8f26
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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"
+8 −0
Original line number Diff line number Diff line
@@ -1299,6 +1299,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()}
+45 −7
Original line number Diff line number Diff line
@@ -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();
            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);