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

Commit 0e4af6d8 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Apply insets (nav bar)" into main

parents bfad288a bc353f8c
Loading
Loading
Loading
Loading
+25 −2
Original line number Diff line number Diff line
@@ -29,10 +29,13 @@ import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
@@ -125,6 +128,9 @@ private fun SceneScope.QuickSettingsScene(
            remember(lifecycleOwner, viewModel) {
                viewModel.getFooterActionsViewModel(lifecycleOwner)
            }

        // ############## SCROLLING ################

        val scrollState = rememberScrollState()
        // When animating into the scene, we don't want it to be able to scroll, as it could mess
        // up with the expansion animation.
@@ -142,6 +148,18 @@ private fun SceneScope.QuickSettingsScene(
            }
        }

        // ############# NAV BAR paddings ###############

        val navBarBottomHeight =
            WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
        val density = LocalDensity.current

        LaunchedEffect(navBarBottomHeight, density) {
            with(density) {
                viewModel.qsSceneAdapter.applyBottomNavBarPadding(navBarBottomHeight.roundToPx())
            }
        }

        // This is the background for the whole scene, as the elements don't necessarily provide
        // a background that extends to the edges.
        Spacer(
@@ -154,8 +172,13 @@ private fun SceneScope.QuickSettingsScene(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier =
                Modifier.fillMaxSize()
                    // bottom should be tied to insets
                    .padding(bottom = 16.dp)
                    .then(
                        if (isCustomizing) {
                            Modifier.padding(top = 48.dp)
                        } else {
                            Modifier.padding(bottom = navBarBottomHeight)
                        }
                    )
        ) {
            Box(modifier = Modifier.fillMaxSize().weight(1f)) {
                val shadeHeaderAndQuickSettingsModifier =
+52 −0
Original line number Diff line number Diff line
@@ -414,4 +414,56 @@ class QSSceneAdapterImplTest : SysuiTestCase() {
            verify(qsImpl!!).onConfigurationChanged(configuration)
            verify(qsImpl!!.view).dispatchConfigurationChanged(configuration)
        }

    @Test
    fun dispatchNavBarSize_beforeInflation() =
        testScope.runTest {
            runCurrent()
            val navBarHeight = 171

            val qsImpl by collectLastValue(underTest.qsImpl)

            underTest.applyBottomNavBarPadding(navBarHeight)
            underTest.inflate(context)
            runCurrent()

            verify(qsImpl!!).applyBottomNavBarToCustomizerPadding(navBarHeight)
        }

    @Test
    fun dispatchNavBarSize_afterInflation() =
        testScope.runTest {
            runCurrent()
            val navBarHeight = 171

            val qsImpl by collectLastValue(underTest.qsImpl)

            underTest.inflate(context)
            runCurrent()

            underTest.applyBottomNavBarPadding(navBarHeight)
            runCurrent()

            verify(qsImpl!!).applyBottomNavBarToCustomizerPadding(navBarHeight)
        }

    @Test
    fun dispatchNavBarSize_reinflation() =
        testScope.runTest {
            runCurrent()
            val navBarHeight = 171

            val qsImpl by collectLastValue(underTest.qsImpl)

            underTest.inflate(context)
            runCurrent()

            underTest.applyBottomNavBarPadding(navBarHeight)
            runCurrent()

            underTest.inflate(context)
            runCurrent()

            verify(qsImpl!!).applyBottomNavBarToCustomizerPadding(navBarHeight)
        }
}
+9 −0
Original line number Diff line number Diff line
@@ -992,6 +992,15 @@ public class QSImpl implements QS, CommandQueue.Callbacks, StatusBarStateControl
        return mContainer.getQsHeight();
    }

    /**
     * Pass the size of the navbar when it's at the bottom of the device so it can be used as
     * padding
     * @param padding size of the bottom nav bar in px
     */
    public void applyBottomNavBarToCustomizerPadding(int padding) {
        mQSCustomizerController.applyBottomNavBarSizeToRecyclerViewPadding(padding);
    }

    @NeverCompile
    @Override
    public void dump(PrintWriter pw, String[] args) {
+27 −2
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ public class QSCustomizer extends LinearLayout {
    private boolean mOpening;
    private boolean mIsShowingNavBackdrop;

    private boolean mSceneContainerEnabled;

    public QSCustomizer(Context context, AttributeSet attrs) {
        super(context, attrs);

@@ -88,6 +90,28 @@ public class QSCustomizer extends LinearLayout {
        updateTransparentViewHeight();
    }

    void applyBottomNavBarToPadding(int padding) {
        mRecyclerView.setPadding(
                /* left= */ mRecyclerView.getPaddingLeft(),
                /* top= */ mRecyclerView.getPaddingTop(),
                /* right= */ mRecyclerView.getPaddingRight(),
                /* bottom= */ padding
        );
    }

    void setSceneContainerEnabled(boolean enabled) {
        if (enabled != mSceneContainerEnabled) {
            mSceneContainerEnabled = enabled;
            updateTransparentViewHeight();
            if (mSceneContainerEnabled) {
                findViewById(R.id.nav_bar_background).setVisibility(View.GONE);
            } else {
                findViewById(R.id.nav_bar_background)
                        .setVisibility(mIsShowingNavBackdrop ? View.VISIBLE : View.GONE);
            }
        }
    }

    void updateResources() {
        updateTransparentViewHeight();
        mRecyclerView.getAdapter().notifyItemChanged(0);
@@ -98,7 +122,8 @@ public class QSCustomizer extends LinearLayout {
        mIsShowingNavBackdrop = newConfig.smallestScreenWidthDp >= 600
                || newConfig.orientation != Configuration.ORIENTATION_LANDSCAPE;
        if (navBackdrop != null) {
            navBackdrop.setVisibility(mIsShowingNavBackdrop ? View.VISIBLE : View.GONE);
            navBackdrop.setVisibility(
                    mIsShowingNavBackdrop && !mSceneContainerEnabled ? View.VISIBLE : View.GONE);
        }
        updateNavColors(lightBarController);
    }
@@ -275,7 +300,7 @@ public class QSCustomizer extends LinearLayout {

    private void updateTransparentViewHeight() {
        LayoutParams lp = (LayoutParams) mTransparentView.getLayoutParams();
        lp.height = QSUtils.getQsHeaderSystemIconsAreaHeight(mContext);
        lp.height = mSceneContainerEnabled ? 0 : QSUtils.getQsHeaderSystemIconsAreaHeight(mContext);
        mTransparentView.setLayoutParams(lp);
    }

+7 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.systemui.qs.QSEditEvent;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.dagger.QSScope;
import com.android.systemui.res.R;
import com.android.systemui.scene.shared.flag.SceneContainerFlags;
import com.android.systemui.statusbar.phone.LightBarController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
@@ -106,7 +107,8 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
    protected QSCustomizerController(QSCustomizer view, TileQueryHelper tileQueryHelper,
            QSHost qsHost, TileAdapter tileAdapter, ScreenLifecycle screenLifecycle,
            KeyguardStateController keyguardStateController, LightBarController lightBarController,
            ConfigurationController configurationController, UiEventLogger uiEventLogger) {
            ConfigurationController configurationController, UiEventLogger uiEventLogger,
            SceneContainerFlags sceneContainerFlags) {
        super(view);
        mTileQueryHelper = tileQueryHelper;
        mQsHost = qsHost;
@@ -116,10 +118,14 @@ public class QSCustomizerController extends ViewController<QSCustomizer> {
        mLightBarController = lightBarController;
        mConfigurationController = configurationController;
        mUiEventLogger = uiEventLogger;
        view.setSceneContainerEnabled(sceneContainerFlags.isEnabled());

        mToolbar = mView.findViewById(com.android.internal.R.id.action_bar);
    }

    public void applyBottomNavBarSizeToRecyclerViewPadding(int padding) {
        mView.applyBottomNavBarToPadding(padding);
    }

    @Override
    protected void onViewAttached() {
Loading