Have an interface for WidgetsSearchBar so Nexus Launcher can override the search bar.

Test: Tested prototype locally.
Bug: b/157286785
Change-Id: I263063a451862755efe3d6e4a5a2eb69f2ea29b8
This commit is contained in:
Alina Zaidi 2021-03-15 07:00:49 +00:00
parent 2b30076aba
commit 1632752a72
6 changed files with 95 additions and 56 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.android.launcher3.widget.picker.search.WidgetsSearchBar
<com.android.launcher3.widget.picker.search.LauncherWidgetsSearchBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widgets_search_bar"
android:layout_width="match_parent"
@ -7,8 +7,7 @@
android:orientation="horizontal"
android:layout_marginTop="16dp"
android:background="@drawable/bg_widgets_searchbox"
android:padding="12dp"
android:visibility="gone">
android:padding="12dp">
<EditText
android:id="@+id/widgets_search_bar_edit_text"
@ -30,4 +29,4 @@
android:background="?android:selectableItemBackground"
android:layout_gravity="center"
android:visibility="gone"/>
</com.android.launcher3.widget.picker.search.WidgetsSearchBar>
</com.android.launcher3.widget.picker.search.LauncherWidgetsSearchBar>

View File

@ -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");

View File

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

View File

@ -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;

View File

@ -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<WidgetsListBaseEntry> allWidgets,
SearchModeListener searchModeListener) {
SearchAlgorithm<WidgetsListBaseEntry> 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();
}
}

View File

@ -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<WidgetsListBaseEntry> allWidgets,
SearchModeListener searchModeListener) {
SearchAlgorithm<WidgetsListBaseEntry> algo =
new SimpleWidgetsSearchAlgorithm(new SimpleWidgetsSearchPipeline(allWidgets));
mController = new WidgetsSearchBarController(
algo, mEditText, mCancelButton, searchModeListener);
}
void initialize(List<WidgetsListBaseEntry> 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);
}