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

Commit b4585414 authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "extract text conversions from composing text and send them for search" into sc-qpr1-dev

parents 587ab5c7 4ca16e1b
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -18,8 +18,10 @@ package com.android.launcher3.allapps.search;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME;

import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.SuggestionSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
@@ -47,6 +49,7 @@ public class AllAppsSearchBarController
    protected SearchCallback<AdapterItem> mCallback;
    protected ExtendedEditText mInput;
    protected String mQuery;
    private String[] mTextConversions;

    protected SearchAlgorithm<AdapterItem> mSearchAlgorithm;

@@ -78,7 +81,20 @@ public class AllAppsSearchBarController

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // Do nothing
        mTextConversions = extractTextConversions(s);
    }

    private static String[] extractTextConversions(CharSequence text) {
        if (text instanceof SpannableStringBuilder) {
            SpannableStringBuilder spanned = (SpannableStringBuilder) text;
            SuggestionSpan[] suggestionSpans =
                spanned.getSpans(0, text.length(), SuggestionSpan.class);
            if (suggestionSpans != null && suggestionSpans.length > 0) {
                spanned.removeSpan(suggestionSpans[0]);
                return suggestionSpans[0].getSuggestions();
            }
        }
        return null;
    }

    @Override
@@ -89,7 +105,7 @@ public class AllAppsSearchBarController
            mCallback.clearSearchResult();
        } else {
            mSearchAlgorithm.cancel(false);
            mSearchAlgorithm.doSearch(mQuery, mCallback);
            mSearchAlgorithm.doSearch(mQuery, mTextConversions, mCallback);
        }
    }

+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,13 @@ public interface SearchAlgorithm<T> {
     */
    void doSearch(String query, SearchCallback<T> callback);

    /**
     * Performs search with {@code query} and the {@code suggestedQueries}/
     */
    default void doSearch(String query, String[] suggestedQueries, SearchCallback<T> callback) {
        doSearch(query, callback);
    }

    /**
     * Cancels any active request.
     */