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

Commit 1632752a authored by Alina Zaidi's avatar Alina Zaidi
Browse files

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

Test: Tested prototype locally.
Bug: b/157286785
Change-Id: I263063a451862755efe3d6e4a5a2eb69f2ea29b8
parent 2b30076a
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
<?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>
 No newline at end of file
</com.android.launcher3.widget.picker.search.LauncherWidgetsSearchBar>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -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");

+2 −1
Original line number Diff line number Diff line
@@ -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. */
+3 −1
Original line number Diff line number Diff line
@@ -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;
+77 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}
Loading