Merge "Use only a single TileLayout in QSPanel" into sc-dev

This commit is contained in:
Fabian Kozynski
2021-06-30 14:42:36 +00:00
committed by Android (Google) Code Review
6 changed files with 22 additions and 71 deletions

View File

@@ -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);
} }

View File

@@ -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

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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));

View File

@@ -107,7 +107,7 @@ public class QSPanelControllerTest extends SysuiTestCase {
when(mQSPanel.isAttachedToWindow()).thenReturn(true); when(mQSPanel.isAttachedToWindow()).thenReturn(true);
when(mQSPanel.getDumpableTag()).thenReturn("QSPanel"); when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
when(mQSPanel.createRegularTileLayout()).thenReturn(mPagedTileLayout); when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout); when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile)); when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView); when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView);