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

Commit 8c2f3085 authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Automerger Merge Worker
Browse files

Merge "extract text conversions from composing text and send them for search"...

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

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/15532476

Change-Id: Ic591cf62d70eb41c1614795d798c37a88e9ca594
parents e046ea22 b4585414
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.
     */