From 1632752a72e7e61ca219b6a97c5f142c07828e33 Mon Sep 17 00:00:00 2001 From: Alina Zaidi Date: Mon, 15 Mar 2021 07:00:49 +0000 Subject: [PATCH] Have an interface for WidgetsSearchBar so Nexus Launcher can override the search bar. Test: Tested prototype locally. Bug: b/157286785 Change-Id: I263063a451862755efe3d6e4a5a2eb69f2ea29b8 --- res/layout/widgets_search_bar.xml | 7 +- .../launcher3/config/FeatureFlags.java | 3 + .../widget/picker/WidgetsFullSheet.java | 3 +- .../widget/picker/WidgetsRecyclerView.java | 4 +- .../search/LauncherWidgetsSearchBar.java | 77 +++++++++++++++++++ .../picker/search/WidgetsSearchBar.java | 57 ++------------ 6 files changed, 95 insertions(+), 56 deletions(-) create mode 100644 src/com/android/launcher3/widget/picker/search/LauncherWidgetsSearchBar.java diff --git a/res/layout/widgets_search_bar.xml b/res/layout/widgets_search_bar.xml index 252637d9cf..450e5f1ece 100644 --- a/res/layout/widgets_search_bar.xml +++ b/res/layout/widgets_search_bar.xml @@ -1,5 +1,5 @@ - + android:padding="12dp"> - \ No newline at end of file + \ No newline at end of file diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index 48e41d5fda..c1dd809855 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -140,6 +140,9 @@ public final class FeatureFlags { public static final BooleanFlag ENABLE_OVERVIEW_SELECTIONS = new DeviceFlag( "ENABLE_OVERVIEW_SELECTIONS", true, "Show Select Mode button in Overview Actions"); + public static final BooleanFlag ENABLE_WIDGETS_PICKER_AIAI_SEARCH = new DeviceFlag( + "ENABLE_WIDGETS_PICKER_AIAI_SEARCH", false, "Enable AiAi search in the widgets picker"); + public static final BooleanFlag ENABLE_OVERVIEW_SHARE = getDebugFlag( "ENABLE_OVERVIEW_SHARE", false, "Show Share button in Overview Actions"); diff --git a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java index 6b3c71ab36..92994be568 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsFullSheet.java @@ -439,7 +439,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet public int getHeaderViewHeight() { return measureHeightWithVerticalMargins(mSearchAndRecommendationViewHolder.mCollapseHandle) + measureHeightWithVerticalMargins(mSearchAndRecommendationViewHolder.mHeaderTitle) - + measureHeightWithVerticalMargins(mSearchAndRecommendationViewHolder.mSearchBar); + + measureHeightWithVerticalMargins( + (View) mSearchAndRecommendationViewHolder.mSearchBar); } /** private the height, in pixel, + the vertical margins of a given view. */ diff --git a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java index 9ab64247a7..12d3f11919 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java +++ b/src/com/android/launcher3/widget/picker/WidgetsRecyclerView.java @@ -34,6 +34,7 @@ import com.android.launcher3.views.ActivityContext; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import com.android.launcher3.widget.model.WidgetsListContentEntry; import com.android.launcher3.widget.model.WidgetsListHeaderEntry; +import com.android.launcher3.widget.model.WidgetsListSearchHeaderEntry; /** * The widgets recycler view. @@ -219,7 +220,8 @@ public class WidgetsRecyclerView extends BaseRecyclerView implements OnItemTouch int totalItemsHeight = 0; for (int i = 0; i < untilIndex; i++) { WidgetsListBaseEntry entry = mAdapter.getItems().get(i); - if (entry instanceof WidgetsListHeaderEntry) { + if (entry instanceof WidgetsListHeaderEntry || + entry instanceof WidgetsListSearchHeaderEntry) { totalItemsHeight += mEstimatedWidgetListHeaderHeight; } else if (entry instanceof WidgetsListContentEntry) { totalItemsHeight += mLastVisibleWidgetContentTableHeight; diff --git a/src/com/android/launcher3/widget/picker/search/LauncherWidgetsSearchBar.java b/src/com/android/launcher3/widget/picker/search/LauncherWidgetsSearchBar.java new file mode 100644 index 0000000000..d68e87e3d6 --- /dev/null +++ b/src/com/android/launcher3/widget/picker/search/LauncherWidgetsSearchBar.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2021 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.widget.picker.search; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.LinearLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.android.launcher3.R; +import com.android.launcher3.search.SearchAlgorithm; +import com.android.launcher3.widget.model.WidgetsListBaseEntry; + +import java.util.List; + +/** + * View for a search bar with an edit text with a cancel button. + */ +public class LauncherWidgetsSearchBar extends LinearLayout implements WidgetsSearchBar { + private WidgetsSearchBarController mController; + private EditText mEditText; + private ImageButton mCancelButton; + + public LauncherWidgetsSearchBar(Context context) { + this(context, null, 0); + } + + public LauncherWidgetsSearchBar(@NonNull Context context, + @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public LauncherWidgetsSearchBar(@NonNull Context context, @Nullable AttributeSet attrs, + int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + public void initialize(List allWidgets, + SearchModeListener searchModeListener) { + SearchAlgorithm algo = + new SimpleWidgetsSearchAlgorithm(new SimpleWidgetsSearchPipeline(allWidgets)); + mController = new WidgetsSearchBarController( + algo, mEditText, mCancelButton, searchModeListener); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mEditText = findViewById(R.id.widgets_search_bar_edit_text); + mCancelButton = findViewById(R.id.widgets_search_cancel_button); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + mController.onDestroy(); + } +} diff --git a/src/com/android/launcher3/widget/picker/search/WidgetsSearchBar.java b/src/com/android/launcher3/widget/picker/search/WidgetsSearchBar.java index d8e9733ce5..af6dc48aae 100644 --- a/src/com/android/launcher3/widget/picker/search/WidgetsSearchBar.java +++ b/src/com/android/launcher3/widget/picker/search/WidgetsSearchBar.java @@ -16,64 +16,21 @@ package com.android.launcher3.widget.picker.search; -import android.content.Context; -import android.util.AttributeSet; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.LinearLayout; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.android.launcher3.R; -import com.android.launcher3.search.SearchAlgorithm; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import java.util.List; /** - * View for a search bar with an edit text with a cancel button. + * Interface for a widgets picker search bar. */ -public class WidgetsSearchBar extends LinearLayout { - private WidgetsSearchBarController mController; - private EditText mEditText; - private ImageButton mCancelButton; - - public WidgetsSearchBar(Context context) { - this(context, null, 0); - } - - public WidgetsSearchBar(@NonNull Context context, - @Nullable AttributeSet attrs) { - this(context, attrs, 0); - } - - public WidgetsSearchBar(@NonNull Context context, @Nullable AttributeSet attrs, - int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - +public interface WidgetsSearchBar { /** * Attaches a controller to the search bar which interacts with {@code searchModeListener}. */ - public void initialize(List allWidgets, - SearchModeListener searchModeListener) { - SearchAlgorithm algo = - new SimpleWidgetsSearchAlgorithm(new SimpleWidgetsSearchPipeline(allWidgets)); - mController = new WidgetsSearchBarController( - algo, mEditText, mCancelButton, searchModeListener); - } + void initialize(List allWidgets, SearchModeListener searchModeListener); - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - mEditText = findViewById(R.id.widgets_search_bar_edit_text); - mCancelButton = findViewById(R.id.widgets_search_cancel_button); - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - mController.onDestroy(); - } + /** + * Sets the vertical location, in pixels, of this search bar relative to its top position. + */ + void setTranslationY(float translationY); }