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

Commit 464e4ad2 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Use only a single TileLayout in QSPanel

The layout is the same regardless of the media configuration for both
QSPanel and QuickQSPanel, the only thing that changes is the number of
columns/rows.

Remove code maintaining two possible TileLayouts, including code that
destroyed and recreated the views.

Test: manual, change orientation with and without media
Fixes: 191948961
Change-Id: I80356b5dde787722cbae3a5eb757a5d458529a29
parent 0954cfe6
Loading
Loading
Loading
Loading
+15 −45
Original line number Original line Diff line number Diff line
@@ -98,11 +98,7 @@ public class QSPanel extends LinearLayout implements Tunable {
    private LinearLayout mHorizontalLinearLayout;
    private LinearLayout mHorizontalLinearLayout;
    protected LinearLayout mHorizontalContentContainer;
    protected LinearLayout mHorizontalContentContainer;


    // Only used with media
    private QSTileLayout mHorizontalTileLayout;
    protected QSTileLayout mRegularTileLayout;
    protected QSTileLayout mTileLayout;
    protected QSTileLayout mTileLayout;
    private int mLastOrientation = -1;
    private int mMediaTotalBottomMargin;
    private int mMediaTotalBottomMargin;


    public QSPanel(Context context, AttributeSet attrs) {
    public QSPanel(Context context, AttributeSet attrs) {
@@ -119,8 +115,7 @@ public class QSPanel extends LinearLayout implements Tunable {
    }
    }


    void initialize() {
    void initialize() {
        mRegularTileLayout = createRegularTileLayout();
        mTileLayout = getOrCreateTileLayout();
        mTileLayout = mRegularTileLayout;


        if (mUsingMediaPlayer) {
        if (mUsingMediaPlayer) {
            mHorizontalLinearLayout = new RemeasuringLinearLayout(mContext);
            mHorizontalLinearLayout = new RemeasuringLinearLayout(mContext);
@@ -133,7 +128,6 @@ public class QSPanel extends LinearLayout implements Tunable {
            mHorizontalContentContainer.setClipChildren(true);
            mHorizontalContentContainer.setClipChildren(true);
            mHorizontalContentContainer.setClipToPadding(false);
            mHorizontalContentContainer.setClipToPadding(false);


            mHorizontalTileLayout = createHorizontalTileLayout();
            LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
            LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
            int marginSize = (int) mContext.getResources().getDimension(R.dimen.qs_media_padding);
            int marginSize = (int) mContext.getResources().getDimension(R.dimen.qs_media_padding);
            lp.setMarginStart(0);
            lp.setMarginStart(0);
@@ -176,17 +170,12 @@ public class QSPanel extends LinearLayout implements Tunable {
    }
    }


    /** */
    /** */
    public QSTileLayout createRegularTileLayout() {
    public QSTileLayout getOrCreateTileLayout() {
        if (mRegularTileLayout == null) {
        if (mTileLayout == null) {
            mRegularTileLayout = (QSTileLayout) LayoutInflater.from(mContext)
            mTileLayout = (QSTileLayout) LayoutInflater.from(mContext)
                    .inflate(R.layout.qs_paged_tile_layout, this, false);
                    .inflate(R.layout.qs_paged_tile_layout, this, false);
        }
        }
        return mRegularTileLayout;
        return mTileLayout;
    }


    protected QSTileLayout createHorizontalTileLayout() {
        return createRegularTileLayout();
    }
    }


    @Override
    @Override
@@ -273,18 +262,18 @@ public class QSPanel extends LinearLayout implements Tunable {
     * @param pageIndicator indicator to use for page scrolling
     * @param pageIndicator indicator to use for page scrolling
     */
     */
    public void setFooterPageIndicator(PageIndicator pageIndicator) {
    public void setFooterPageIndicator(PageIndicator pageIndicator) {
        if (mRegularTileLayout instanceof PagedTileLayout) {
        if (mTileLayout instanceof PagedTileLayout) {
            mFooterPageIndicator = pageIndicator;
            mFooterPageIndicator = pageIndicator;
            updatePageIndicator();
            updatePageIndicator();
        }
        }
    }
    }


    private void updatePageIndicator() {
    private void updatePageIndicator() {
        if (mRegularTileLayout instanceof PagedTileLayout) {
        if (mTileLayout instanceof PagedTileLayout) {
            if (mFooterPageIndicator != null) {
            if (mFooterPageIndicator != null) {
                mFooterPageIndicator.setVisibility(View.GONE);
                mFooterPageIndicator.setVisibility(View.GONE);


                ((PagedTileLayout) mRegularTileLayout).setPageIndicator(mFooterPageIndicator);
                ((PagedTileLayout) mTileLayout).setPageIndicator(mFooterPageIndicator);
            }
            }
        }
        }
    }
    }
@@ -354,7 +343,7 @@ public class QSPanel extends LinearLayout implements Tunable {
        return true;
        return true;
    }
    }


    protected boolean needsDynamicRowsAndColumns() {
    private boolean needsDynamicRowsAndColumns() {
        return true;
        return true;
    }
    }


@@ -669,39 +658,20 @@ public class QSPanel extends LinearLayout implements Tunable {
    }
    }


    protected void setPageMargin(int pageMargin) {
    protected void setPageMargin(int pageMargin) {
        if (mRegularTileLayout instanceof PagedTileLayout) {
        if (mTileLayout instanceof PagedTileLayout) {
            ((PagedTileLayout) mRegularTileLayout).setPageMargin(pageMargin);
            ((PagedTileLayout) mTileLayout).setPageMargin(pageMargin);
        }
        if (mHorizontalTileLayout != mRegularTileLayout
                && mHorizontalTileLayout instanceof PagedTileLayout) {
            ((PagedTileLayout) mHorizontalTileLayout).setPageMargin(pageMargin);
        }
        }
    }
    }


    void setUsingHorizontalLayout(boolean horizontal, ViewGroup mediaHostView, boolean force,
    void setUsingHorizontalLayout(boolean horizontal, ViewGroup mediaHostView, boolean force) {
            UiEventLogger uiEventLogger) {
        if (horizontal != mUsingHorizontalLayout || force) {
        if (horizontal != mUsingHorizontalLayout || force) {
            mUsingHorizontalLayout = horizontal;
            mUsingHorizontalLayout = horizontal;
            View visibleView = horizontal ? mHorizontalLinearLayout : (View) mRegularTileLayout;
            View hiddenView = horizontal ? (View) mRegularTileLayout : mHorizontalLinearLayout;
            ViewGroup newParent = horizontal ? mHorizontalContentContainer : this;
            ViewGroup newParent = horizontal ? mHorizontalContentContainer : this;
            QSPanel.QSTileLayout newLayout = horizontal
            switchAllContentToParent(newParent, mTileLayout);
                    ? mHorizontalTileLayout : mRegularTileLayout;
            if (hiddenView != null
                    && (mRegularTileLayout != mHorizontalTileLayout
                    || hiddenView != mRegularTileLayout)) {
                // Only hide the view if the horizontal and the regular view are different,
                // otherwise its reattached.
                hiddenView.setVisibility(View.GONE);
            }
            visibleView.setVisibility(View.VISIBLE);
            switchAllContentToParent(newParent, newLayout);
            reAttachMediaHost(mediaHostView, horizontal);
            reAttachMediaHost(mediaHostView, horizontal);
            mTileLayout = newLayout;
            newLayout.setListening(mListening, uiEventLogger);
            if (needsDynamicRowsAndColumns()) {
            if (needsDynamicRowsAndColumns()) {
                newLayout.setMinRows(horizontal ? 2 : 1);
                mTileLayout.setMinRows(horizontal ? 2 : 1);
                newLayout.setMaxColumns(horizontal ? 2 : 4);
                mTileLayout.setMaxColumns(horizontal ? 2 : 4);
            }
            }
            updateMargins(mediaHostView);
            updateMargins(mediaHostView);
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -147,14 +147,14 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
            mBrightnessMirrorController.addCallback(mBrightnessMirrorListener);
            mBrightnessMirrorController.addCallback(mBrightnessMirrorListener);
        }
        }


        ((PagedTileLayout) mView.createRegularTileLayout())
        ((PagedTileLayout) mView.getOrCreateTileLayout())
                .setOnTouchListener(mTileLayoutTouchListener);
                .setOnTouchListener(mTileLayoutTouchListener);
    }
    }


    @Override
    @Override
    protected QSTileRevealController createTileRevealController() {
    protected QSTileRevealController createTileRevealController() {
        return mQsTileRevealControllerFactory.create(
        return mQsTileRevealControllerFactory.create(
                this, (PagedTileLayout) mView.createRegularTileLayout());
                this, (PagedTileLayout) mView.getOrCreateTileLayout());
    }
    }


    @Override
    @Override
+2 −10
Original line number Original line Diff line number Diff line
@@ -297,20 +297,12 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
    }
    }


    boolean switchTileLayout(boolean force) {
    boolean switchTileLayout(boolean force) {
        /** Whether or not the QuickQSPanel currently contains a media player. */
        /* Whether or not the panel currently contains a media player. */
        boolean horizontal = shouldUseHorizontalLayout();
        boolean horizontal = shouldUseHorizontalLayout();
        if (horizontal != mUsingHorizontalLayout || force) {
        if (horizontal != mUsingHorizontalLayout || force) {
            mUsingHorizontalLayout = horizontal;
            mUsingHorizontalLayout = horizontal;
            for (QSPanelControllerBase.TileRecord record : mRecords) {
            mView.setUsingHorizontalLayout(mUsingHorizontalLayout, mMediaHost.getHostView(), force);
                mView.removeTile(record);
                record.tile.removeCallback(record.callback);
            }
            mView.setUsingHorizontalLayout(mUsingHorizontalLayout, mMediaHost.getHostView(), force,
                    mUiEventLogger);
            updateMediaDisappearParameters();
            updateMediaDisappearParameters();

            setTiles();

            return true;
            return true;
        }
        }
        return false;
        return false;
+1 −12
Original line number Original line Diff line number Diff line
@@ -61,21 +61,10 @@ public class QuickQSPanel extends QSPanel {
    }
    }


    @Override
    @Override
    public TileLayout createRegularTileLayout() {
    public TileLayout getOrCreateTileLayout() {
        return new QQSSideLabelTileLayout(mContext);
        return new QQSSideLabelTileLayout(mContext);
    }
    }


    @Override
    protected QSTileLayout createHorizontalTileLayout() {
        TileLayout t = createRegularTileLayout();
        t.setMaxColumns(2);
        return t;
    }

    @Override
    protected boolean needsDynamicRowsAndColumns() {
        return false; // QQS always have the same layout
    }


    @Override
    @Override
    protected boolean displayMediaMarginsOnMedia() {
    protected boolean displayMediaMarginsOnMedia() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -127,7 +127,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
        when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
        when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
        when(mQSPanel.openPanelEvent()).thenReturn(QSEvent.QS_PANEL_EXPANDED);
        when(mQSPanel.openPanelEvent()).thenReturn(QSEvent.QS_PANEL_EXPANDED);
        when(mQSPanel.closePanelEvent()).thenReturn(QSEvent.QS_PANEL_COLLAPSED);
        when(mQSPanel.closePanelEvent()).thenReturn(QSEvent.QS_PANEL_COLLAPSED);
        when(mQSPanel.createRegularTileLayout()).thenReturn(mPagedTileLayout);
        when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
        when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
        when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
        when(mQSTile.getTileSpec()).thenReturn("dnd");
        when(mQSTile.getTileSpec()).thenReturn("dnd");
        when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
        when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
Loading