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

Commit 9c4b182c authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

[Flexiglass] Fix 1px rounding error

In some cases, in split shade in flexiglass, due to rounding errors, the
leftmost 1px of tiles in the second page can be seen peeking from under
the notifications scrim. This is due to the fact that rounding errors
accumulate when calculating the page margins for the PagedTileLayout.

With this change, when in flexiglass and if the page margin is expected
to be half of the total margin, but the total margin is odd, instead of
having 0.5px missing on each side, we round down in one side and up in
the other.

Test: manual
Fixes: 339863138
Flag: com.android.systemui.scene_container

Change-Id: I1bcf9b730c9e70056bc3022558bf1045b30d3a60
parent 34053329
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -103,8 +103,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
    }
    private int mLastMaxHeight = -1;

    @Override
    public void setPageMargin(int marginPixels) {
    public void setPageMargin(int marginPixelsStart, int marginPixelsEnd) {
        // Using page margins creates some rounding issues that interfere with the correct position
        // in the onPageChangedListener and therefore present bad positions to the PageIndicator.
        // Instead, we use negative margins in the container and positive padding in the pages,
@@ -113,14 +112,19 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
        // QSContainerImpl resources are set onAttachedView, so this view will always have the right
        // values when attached.
        MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
        lp.setMarginStart(-marginPixels);
        lp.setMarginEnd(-marginPixels);
        lp.setMarginStart(-marginPixelsStart);
        lp.setMarginEnd(-marginPixelsEnd);
        setLayoutParams(lp);

        int nPages = mPages.size();
        for (int i = 0; i < nPages; i++) {
            View v = mPages.get(i);
            v.setPadding(marginPixels, v.getPaddingTop(), marginPixels, v.getPaddingBottom());
            v.setPadding(
                    marginPixelsStart,
                    v.getPaddingTop(),
                    marginPixelsEnd,
                    v.getPaddingBottom()
            );
        }
    }

+14 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import androidx.annotation.Nullable;
import com.android.systemui.Dumpable;
import com.android.systemui.qs.customize.QSCustomizer;
import com.android.systemui.res.R;
import com.android.systemui.scene.shared.flag.SceneContainerFlag;
import com.android.systemui.shade.LargeScreenHeaderHelper;
import com.android.systemui.shade.TouchLogger;
import com.android.systemui.util.LargeScreenUtils;
@@ -300,7 +301,7 @@ public class QSContainerImpl extends FrameLayout implements Dumpable {
                // QS panel lays out some of its content full width
                qsPanelController.setContentMargins(mContentHorizontalPadding,
                        mContentHorizontalPadding);
                qsPanelController.setPageMargin(mTilesPageMargin);
                setPageMargins(qsPanelController);
            } else if (view == mHeader) {
                quickStatusBarHeaderController.setContentMargins(mContentHorizontalPadding,
                        mContentHorizontalPadding);
@@ -318,6 +319,18 @@ public class QSContainerImpl extends FrameLayout implements Dumpable {
        }
    }

    private void setPageMargins(QSPanelController qsPanelController) {
        if (SceneContainerFlag.isEnabled()) {
            if (mHorizontalMargins == mTilesPageMargin * 2 + 1) {
                qsPanelController.setPageMargin(mTilesPageMargin, mTilesPageMargin + 1);
            } else {
                qsPanelController.setPageMargin(mTilesPageMargin, mTilesPageMargin);
            }
        } else {
            qsPanelController.setPageMargin(mTilesPageMargin, mTilesPageMargin);
        }
    }

    /**
     * Clip QS bottom using a concave shape.
     */
+2 −2
Original line number Diff line number Diff line
@@ -638,9 +638,9 @@ public class QSPanel extends LinearLayout implements Tunable {
        return mListening;
    }

    protected void setPageMargin(int pageMargin) {
    protected void setPageMargin(int pageMarginStart, int pageMarginEnd) {
        if (mTileLayout instanceof PagedTileLayout) {
            ((PagedTileLayout) mTileLayout).setPageMargin(pageMargin);
            ((PagedTileLayout) mTileLayout).setPageMargin(pageMarginStart, pageMarginEnd);
        }
    }

+2 −2
Original line number Diff line number Diff line
@@ -284,8 +284,8 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
        return mView.isExpanded();
    }

    void setPageMargin(int pageMargin) {
        mView.setPageMargin(pageMargin);
    void setPageMargin(int pageMarginStart, int pageMarginEnd) {
        mView.setPageMargin(pageMarginStart, pageMarginEnd);
    }

    /**