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

Commit 5ca62190 authored by Kevin Lim's avatar Kevin Lim Committed by Android (Google) Code Review
Browse files

Merge "[UniversalSearchInput] Support search box dynamic height adjustment in...

Merge "[UniversalSearchInput] Support search box dynamic height adjustment in ActivityAllAppsContainerView" into main
parents bd3bb005 0c7079ec
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.Flags;
import com.android.launcher3.Insettable;
import com.android.launcher3.InsettableFrameLayout;
import com.android.launcher3.R;
@@ -764,6 +765,16 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
        }
    }

    /**
     * Force header height update with an offset. Used by {@link UniversalSearchInputView} to
     * request {@link FloatingHeaderView} to update its maxTranslation for multiline search bar.
     */
    public void forceUpdateHeaderHeight(int offset) {
        if (Flags.multilineSearchBar()) {
            mHeader.updateSearchBarOffset(offset);
        }
    }

    protected void updateHeaderScroll(int scrolledOffset) {
        float prog1 = Utilities.boundToRange((float) scrolledOffset / mHeaderThreshold, 0f, 1f);
        int headerColor = getHeaderColor(prog1);
+20 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.android.launcher3.Flags;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
import com.android.launcher3.allapps.ActivityAllAppsContainerView.AdapterHolder;
@@ -104,6 +105,8 @@ public class FloatingHeaderView extends LinearLayout implements
    private boolean mFloatingRowsCollapsed;
    // Total height of all current floating rows. Collapsed rows == 0 height.
    private int mFloatingRowsHeight;
    // Offset of search bar. Adds to the floating view height when multi-line is supported.
    private int mSearchBarOffset = 0;

    // This is initialized once during inflation and stays constant after that. Fixed views
    // cannot be added or removed dynamically.
@@ -198,6 +201,14 @@ public class FloatingHeaderView extends LinearLayout implements
        }
    }

    /**
     * Offset floating rows height by search bar
     */
    void updateSearchBarOffset(int offset) {
        mSearchBarOffset = offset;
        onHeightUpdated();
    }

    @Override
    public void onPluginDisconnected(AllAppsRow plugin) {
        PluginHeaderRow row = mPluginRows.get(plugin);
@@ -258,9 +269,18 @@ public class FloatingHeaderView extends LinearLayout implements
        mTabLayout.setVisibility(mTabsHidden ? GONE : visibility);
    }

    /** Returns whether search bar has multi-line support, and is currently in multi-line state. */
    private boolean isSearchBarMultiline() {
        return Flags.multilineSearchBar() && mSearchBarOffset > 0;
    }

    private void updateExpectedHeight() {
        updateFloatingRowsHeight();
        mMaxTranslation = 0;
        boolean shouldAddSearchBarHeight = isSearchBarMultiline() && !Flags.floatingSearchBar();
        if (shouldAddSearchBarHeight) {
            mMaxTranslation += mSearchBarOffset;
        }
        if (mFloatingRowsCollapsed) {
            return;
        }
+92 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.allapps

import android.content.Context
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.launcher3.Flags
import com.android.launcher3.util.ActivityContextWrapper
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class FloatingHeaderViewTests {

    @get:Rule val mSetFlagsRule = SetFlagsRule()

    private lateinit var context: Context
    private lateinit var vut: FloatingHeaderView

    @Before
    fun setUp() {
        context = ActivityContextWrapper(getApplicationContext())
        // TODO(b/352161553): Inflate FloatingHeaderView or R.layout.all_apps_content with proper
        // FloatingHeaderView#setup
        vut = FloatingHeaderView(context)
        vut.onFinishInflate()
    }

    @Test
    @DisableFlags(Flags.FLAG_FLOATING_SEARCH_BAR, Flags.FLAG_MULTILINE_SEARCH_BAR)
    fun onHeightUpdated_whenNotMultiline_thenZeroHeight() {
        vut.setFloatingRowsCollapsed(true)
        val beforeHeight = vut.maxTranslation
        vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)

        vut.onHeightUpdated()

        assertThat(vut.maxTranslation).isEqualTo(beforeHeight)
    }

    @Test
    @EnableFlags(Flags.FLAG_MULTILINE_SEARCH_BAR)
    @DisableFlags(Flags.FLAG_FLOATING_SEARCH_BAR)
    fun onHeightUpdated_whenMultiline_thenHeightIsOffset() {
        vut.setFloatingRowsCollapsed(true)
        vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)

        vut.onHeightUpdated()

        assertThat(vut.maxTranslation).isEqualTo(HEADER_HEIGHT_OFFSET)
    }

    @Test
    @DisableFlags(Flags.FLAG_MULTILINE_SEARCH_BAR)
    @EnableFlags(Flags.FLAG_FLOATING_SEARCH_BAR)
    fun onHeightUpdated_whenFloatingRowsShownAndNotMultiline_thenAddsOnlyFloatingRow() {
        // Collapse floating rows and expand to trigger header height calculation
        vut.setFloatingRowsCollapsed(true)
        vut.setFloatingRowsCollapsed(false)
        val defaultHeight = vut.maxTranslation
        vut.updateSearchBarOffset(HEADER_HEIGHT_OFFSET)

        vut.onHeightUpdated()

        assertThat(vut.maxTranslation).isEqualTo(defaultHeight)
    }

    companion object {
        private const val HEADER_HEIGHT_OFFSET = 50
    }
}