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

Commit a804b7f9 authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Making notifications wider in split shade mode

With this change quick settings take 40% of the width and notifications 60%.

Bug: 171917882
Test: Manual + Presubmit
Change-Id: I3907dfc4437fdf4137b777c8c193bd3ad7bccdfd
parent ecb2d83d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@
            android:id="@+id/qs_edge_guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            systemui:layout_constraintGuide_percent="0.5"
            systemui:layout_constraintGuide_percent="0.4"
            android:orientation="vertical"/>

        <com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
+6 −13
Original line number Diff line number Diff line
@@ -867,25 +867,16 @@ public class NotificationPanelViewController extends PanelViewController {

    public void updateResources() {
        int qsWidth = mResources.getDimensionPixelSize(R.dimen.qs_panel_width);
        ViewGroup.LayoutParams lp = mQsFrame.getLayoutParams();
        if (lp.width != qsWidth) {
            lp.width = qsWidth;
            mQsFrame.setLayoutParams(lp);
        }

        int panelWidth = mResources.getDimensionPixelSize(R.dimen.notification_panel_width);
        lp = mNotificationStackScrollLayoutController.getLayoutParams();
        if (lp.width != panelWidth) {
            lp.width = panelWidth;
            mNotificationStackScrollLayoutController.setLayoutParams(lp);
        }

        // In order to change the constraints at runtime, all children of the Constraint Layout
        // must have ids.
        // To change the constraints at runtime, all children of the ConstraintLayout must have ids
        ensureAllViewsHaveIds(mNotificationContainerParent);
        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(mNotificationContainerParent);
        if (Utils.shouldUseSplitNotificationShade(mFeatureFlags, mResources)) {
            // width = 0 to take up all available space within constraints
            qsWidth = 0;
            panelWidth = 0;
            constraintSet.connect(R.id.qs_frame, END, R.id.qs_edge_guideline, END);
            constraintSet.connect(
                    R.id.notification_stack_scroller, START,
@@ -894,6 +885,8 @@ public class NotificationPanelViewController extends PanelViewController {
            constraintSet.connect(R.id.qs_frame, END, PARENT_ID, END);
            constraintSet.connect(R.id.notification_stack_scroller, START, PARENT_ID, START);
        }
        constraintSet.getConstraint(R.id.notification_stack_scroller).layout.mWidth = panelWidth;
        constraintSet.getConstraint(R.id.qs_frame).layout.mWidth = qsWidth;
        constraintSet.applyTo(mNotificationContainerParent);
    }

+0 −18
Original line number Diff line number Diff line
@@ -18,14 +18,12 @@ package com.android.systemui.statusbar.phone;

import android.app.Fragment;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowInsets;
import android.widget.FrameLayout;

import androidx.annotation.DimenRes;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.android.systemui.R;
@@ -82,22 +80,6 @@ public class NotificationsQuickSettingsContainer extends ConstraintLayout
        FragmentHostManager.get(this).removeTagListener(QS.TAG, this);
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        reloadWidth(mQsFrame, R.dimen.qs_panel_width);
        reloadWidth(mStackScroller, R.dimen.notification_panel_width);
    }

    /**
     * Loads the given width resource and sets it on the given View.
     */
    private void reloadWidth(View view, @DimenRes int width) {
        LayoutParams params = (LayoutParams) view.getLayoutParams();
        params.width = getResources().getDimensionPixelSize(width);
        view.setLayoutParams(params);
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        mBottomPadding = insets.getStableInsetBottom();
+53 −36
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.annotation.IdRes;
import android.app.ActivityManager;
import android.app.StatusBarManager;
import android.content.res.Configuration;
@@ -262,8 +263,9 @@ public class NotificationPanelViewTest extends SysuiTestCase {
        when(mView.findViewById(R.id.qs_frame)).thenReturn(mQsFrame);
        when(mView.findViewById(R.id.keyguard_status_view))
                .thenReturn(mock(KeyguardStatusView.class));
        when(mView.findViewById(R.id.keyguard_header)).thenReturn(mKeyguardStatusBar);
        mNotificationContainerParent = new NotificationsQuickSettingsContainer(getContext(), null);
        mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
        mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));
        when(mView.findViewById(R.id.notification_container_parent))
                .thenReturn(mNotificationContainerParent);
        FlingAnimationUtils.Builder flingAnimationUtilsBuilder = new FlingAnimationUtils.Builder(
@@ -293,10 +295,6 @@ public class NotificationPanelViewTest extends SysuiTestCase {
                .thenReturn(mKeyguardClockSwitchController);
        when(mKeyguardStatusViewComponent.getKeyguardStatusViewController())
                .thenReturn(mKeyguardStatusViewController);
        when(mQsFrame.getLayoutParams()).thenReturn(
                new ViewGroup.LayoutParams(600, 400));
        when(mNotificationStackScrollLayoutController.getLayoutParams()).thenReturn(
                new ViewGroup.LayoutParams(600, 400));

        mNotificationPanelViewController = new NotificationPanelViewController(mView,
                mResources,
@@ -442,7 +440,8 @@ public class NotificationPanelViewTest extends SysuiTestCase {

    @Test
    public void testAllChildrenOfNotificationContainer_haveIds() {
        enableDualPaneShade();
        enableSplitShade();
        mNotificationContainerParent.removeAllViews();
        mNotificationContainerParent.addView(newViewWithId(1));
        mNotificationContainerParent.addView(newViewWithId(View.NO_ID));

@@ -455,52 +454,54 @@ public class NotificationPanelViewTest extends SysuiTestCase {
    @Test
    public void testSinglePaneShadeLayout_isAlignedToParent() {
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false);
        mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
        mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));

        mNotificationPanelViewController.updateResources();

        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(mNotificationContainerParent);
        ConstraintSet.Layout qsFrameLayout = constraintSet.getConstraint(R.id.qs_frame).layout;
        ConstraintSet.Layout stackScrollerLayout = constraintSet.getConstraint(
                R.id.notification_stack_scroller).layout;
        assertThat(qsFrameLayout.endToEnd).isEqualTo(ConstraintSet.PARENT_ID);
        assertThat(stackScrollerLayout.startToStart).isEqualTo(ConstraintSet.PARENT_ID);
        assertThat(getConstraintSetLayout(R.id.qs_frame).endToEnd)
                .isEqualTo(ConstraintSet.PARENT_ID);
        assertThat(getConstraintSetLayout(R.id.notification_stack_scroller).startToStart)
                .isEqualTo(ConstraintSet.PARENT_ID);
    }

    @Test
    public void testSplitShadeLayout_isAlignedToGuideline() {
        enableDualPaneShade();
        mNotificationContainerParent.addView(newViewWithId(R.id.qs_frame));
        mNotificationContainerParent.addView(newViewWithId(R.id.notification_stack_scroller));
        enableSplitShade();

        mNotificationPanelViewController.updateResources();

        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(mNotificationContainerParent);
        ConstraintSet.Layout qsFrameLayout = constraintSet.getConstraint(R.id.qs_frame).layout;
        ConstraintSet.Layout stackScrollerLayout = constraintSet.getConstraint(
                R.id.notification_stack_scroller).layout;
        assertThat(qsFrameLayout.endToEnd).isEqualTo(R.id.qs_edge_guideline);
        assertThat(stackScrollerLayout.startToStart).isEqualTo(R.id.qs_edge_guideline);
        assertThat(getConstraintSetLayout(R.id.qs_frame).endToEnd)
                .isEqualTo(R.id.qs_edge_guideline);
        assertThat(getConstraintSetLayout(R.id.notification_stack_scroller).startToStart)
                .isEqualTo(R.id.qs_edge_guideline);
    }

    private View newViewWithId(int id) {
        View view = new View(mContext);
        view.setId(id);
        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        // required as cloning ConstraintSet fails if view doesn't have layout params
        view.setLayoutParams(layoutParams);
        return view;
    @Test
    public void testSinglePaneShadeLayout_childrenHaveConstantWidth() {
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(false);

        mNotificationPanelViewController.updateResources();

        assertThat(getConstraintSetLayout(R.id.qs_frame).mWidth)
                .isEqualTo(mResources.getDimensionPixelSize(R.dimen.qs_panel_width));
        assertThat(getConstraintSetLayout(R.id.notification_stack_scroller).mWidth)
                .isEqualTo(mResources.getDimensionPixelSize(R.dimen.notification_panel_width));
    }

    @Test
    public void testOnDragDownEvent_horizontalTranslationIsZeroForDualPaneShade() {
    public void testSplitShadeLayout_childrenHaveZeroWidth() {
        enableSplitShade();

        mNotificationPanelViewController.updateResources();

        assertThat(getConstraintSetLayout(R.id.qs_frame).mWidth).isEqualTo(0);
        assertThat(getConstraintSetLayout(R.id.notification_stack_scroller).mWidth).isEqualTo(0);
    }

    @Test
    public void testOnDragDownEvent_horizontalTranslationIsZeroForSplitShade() {
        when(mNotificationStackScrollLayoutController.getWidth()).thenReturn(350f);
        when(mView.getWidth()).thenReturn(800);
        enableDualPaneShade();
        enableSplitShade();

        onTouchEvent(MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN,
                200f /* x position */, 0f, 0));
@@ -508,7 +509,23 @@ public class NotificationPanelViewTest extends SysuiTestCase {
        verify(mQsFrame).setTranslationX(0);
    }

    private void enableDualPaneShade() {
    private View newViewWithId(int id) {
        View view = new View(mContext);
        view.setId(id);
        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        // required as cloning ConstraintSet fails if view doesn't have layout params
        view.setLayoutParams(layoutParams);
        return view;
    }

    private ConstraintSet.Layout getConstraintSetLayout(@IdRes int id) {
        ConstraintSet constraintSet = new ConstraintSet();
        constraintSet.clone(mNotificationContainerParent);
        return constraintSet.getConstraint(id).layout;
    }

    private void enableSplitShade() {
        when(mResources.getBoolean(R.bool.config_use_split_notification_shade)).thenReturn(true);
        when(mFeatureFlags.isTwoColumnNotificationShadeEnabled()).thenReturn(true);
    }