diff --git a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java index 198c4b2bfb..dfa8fa49bb 100644 --- a/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java +++ b/src/com/android/launcher3/allapps/search/AllAppsSearchBarController.java @@ -31,10 +31,10 @@ import com.android.launcher3.Launcher; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.search.SearchAlgorithm; +import com.android.launcher3.search.SearchCallback; import com.android.launcher3.util.PackageManagerHelper; -import java.util.ArrayList; - /** * An interface to a search box that AllApps can command. */ @@ -43,11 +43,11 @@ public class AllAppsSearchBarController OnFocusChangeListener { protected BaseDraggingActivity mLauncher; - protected Callbacks mCb; + protected SearchCallback mCallback; protected ExtendedEditText mInput; protected String mQuery; - protected SearchAlgorithm mSearchAlgorithm; + protected SearchAlgorithm mSearchAlgorithm; public void setVisibility(int visibility) { mInput.setVisibility(visibility); @@ -57,9 +57,9 @@ public class AllAppsSearchBarController * Sets the references to the apps model and the search result callback. */ public final void initialize( - SearchAlgorithm searchAlgorithm, ExtendedEditText input, - BaseDraggingActivity launcher, Callbacks cb) { - mCb = cb; + SearchAlgorithm searchAlgorithm, ExtendedEditText input, + BaseDraggingActivity launcher, SearchCallback callback) { + mCallback = callback; mLauncher = launcher; mInput = input; @@ -85,10 +85,10 @@ public class AllAppsSearchBarController mQuery = s.toString(); if (mQuery.isEmpty()) { mSearchAlgorithm.cancel(true); - mCb.clearSearchResult(); + mCallback.clearSearchResult(); } else { mSearchAlgorithm.cancel(false); - mSearchAlgorithm.doSearch(mQuery, mCb); + mSearchAlgorithm.doSearch(mQuery, mCallback); } } @@ -98,7 +98,7 @@ public class AllAppsSearchBarController } // If play store continues auto updating an app, we want to show partial result. mSearchAlgorithm.cancel(false); - mSearchAlgorithm.doSearch(mQuery, mCb); + mSearchAlgorithm.doSearch(mQuery, mCallback); } @Override @@ -149,7 +149,7 @@ public class AllAppsSearchBarController * Resets the search bar state. */ public void reset() { - mCb.clearSearchResult(); + mCallback.clearSearchResult(); mInput.reset(); mQuery = null; } @@ -167,31 +167,4 @@ public class AllAppsSearchBarController public boolean isSearchFieldFocused() { return mInput.isFocused(); } - - /** - * Callback for getting search results. - */ - public interface Callbacks { - - /** - * Called when the search from primary source is complete. - * - * @param items sorted list of search result adapter items - */ - void onSearchResult(String query, ArrayList items); - - /** - * Called when the search from secondary source is complete. - * - * @param items sorted list of search result adapter items - */ - void onAppendSearchResult(String query, ArrayList items); - - /** - * Called when the search results should be cleared. - */ - void clearSearchResult(); - } - - } \ No newline at end of file diff --git a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java index aef32d7a28..426fd0cd83 100644 --- a/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java +++ b/src/com/android/launcher3/allapps/search/AppsSearchContainerLayout.java @@ -47,6 +47,7 @@ import com.android.launcher3.allapps.AlphabeticalAppsList; import com.android.launcher3.allapps.SearchUiManager; import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.config.FeatureFlags; +import com.android.launcher3.search.SearchCallback; import java.util.ArrayList; @@ -54,7 +55,7 @@ import java.util.ArrayList; * Layout to contain the All-apps search UI. */ public class AppsSearchContainerLayout extends ExtendedEditText - implements SearchUiManager, AllAppsSearchBarController.Callbacks, + implements SearchUiManager, SearchCallback, AllAppsStore.OnUpdateListener, Insettable { private final BaseDraggingActivity mLauncher; diff --git a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java index 66bbd2e75d..4e213b0a1b 100644 --- a/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java +++ b/src/com/android/launcher3/allapps/search/DefaultAppSearchAlgorithm.java @@ -19,14 +19,17 @@ import android.content.Context; import android.os.Handler; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.allapps.AllAppsGridAdapter.AdapterItem; import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.search.SearchAlgorithm; +import com.android.launcher3.search.SearchCallback; import java.text.Collator; /** * The default search implementation. */ -public class DefaultAppSearchAlgorithm implements SearchAlgorithm { +public class DefaultAppSearchAlgorithm implements SearchAlgorithm { protected final Handler mResultHandler; private final AppsSearchPipeline mAppsSearchPipeline; @@ -45,7 +48,7 @@ public class DefaultAppSearchAlgorithm implements SearchAlgorithm { @Override public void doSearch(final String query, - final AllAppsSearchBarController.Callbacks callback) { + final SearchCallback callback) { mAppsSearchPipeline.query(query, results -> mResultHandler.post( () -> callback.onSearchResult(query, results)), diff --git a/src/com/android/launcher3/allapps/search/SearchAlgorithm.java b/src/com/android/launcher3/search/SearchAlgorithm.java similarity index 76% rename from src/com/android/launcher3/allapps/search/SearchAlgorithm.java rename to src/com/android/launcher3/search/SearchAlgorithm.java index c409b1ce85..1665354af2 100644 --- a/src/com/android/launcher3/allapps/search/SearchAlgorithm.java +++ b/src/com/android/launcher3/search/SearchAlgorithm.java @@ -13,17 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.allapps.search; +package com.android.launcher3.search; /** * An interface for handling search. + * + * @param Search Result type */ -public interface SearchAlgorithm { +public interface SearchAlgorithm { /** - * Performs search and sends the result to the callback. + * Performs search and sends the result to {@link SearchCallback}. */ - void doSearch(String query, AllAppsSearchBarController.Callbacks callback); + void doSearch(String query, SearchCallback callback); /** * Cancels any active request. diff --git a/src/com/android/launcher3/search/SearchCallback.java b/src/com/android/launcher3/search/SearchCallback.java new file mode 100644 index 0000000000..5796116963 --- /dev/null +++ b/src/com/android/launcher3/search/SearchCallback.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.launcher3.search; + +import java.util.ArrayList; + +/** + * An interface for receiving search results. + * + * @param Search Result type + */ +public interface SearchCallback { + + /** + * Called when the search from primary source is complete. + * + * @param items list of search results + */ + void onSearchResult(String query, ArrayList items); + + /** + * Called when the search from secondary source is complete. + * + * @param items list of search results + */ + void onAppendSearchResult(String query, ArrayList items); + + /** + * Called when the search results should be cleared. + */ + void clearSearchResult(); +} +