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

This commit is contained in:
Hyunyoung Song
2021-09-24 03:54:12 +00:00
committed by Android (Google) Code Review
2 changed files with 26 additions and 3 deletions

View File

@@ -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);
}
}
@@ -154,4 +170,4 @@ public class AllAppsSearchBarController
public boolean isSearchFieldFocused() {
return mInput.isFocused();
}
}
}

View File

@@ -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.
*/