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;
protected LinearLayout mHorizontalContentContainer;
// Only used with media
private QSTileLayout mHorizontalTileLayout;
protected QSTileLayout mRegularTileLayout;
protected QSTileLayout mTileLayout;
private int mLastOrientation = -1;
private int mMediaTotalBottomMargin;
public QSPanel(Context context, AttributeSet attrs) {
@@ -119,8 +115,7 @@ public class QSPanel extends LinearLayout implements Tunable {
}
void initialize() {
mRegularTileLayout = createRegularTileLayout();
mTileLayout = mRegularTileLayout;
mTileLayout = getOrCreateTileLayout();
if (mUsingMediaPlayer) {
mHorizontalLinearLayout = new RemeasuringLinearLayout(mContext);
@@ -133,7 +128,6 @@ public class QSPanel extends LinearLayout implements Tunable {
mHorizontalContentContainer.setClipChildren(true);
mHorizontalContentContainer.setClipToPadding(false);
mHorizontalTileLayout = createHorizontalTileLayout();
LayoutParams lp = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
int marginSize = (int) mContext.getResources().getDimension(R.dimen.qs_media_padding);
lp.setMarginStart(0);
@@ -176,17 +170,12 @@ public class QSPanel extends LinearLayout implements Tunable {
}
/** */
public QSTileLayout createRegularTileLayout() {
if (mRegularTileLayout == null) {
mRegularTileLayout = (QSTileLayout) LayoutInflater.from(mContext)
public QSTileLayout getOrCreateTileLayout() {
if (mTileLayout == null) {
mTileLayout = (QSTileLayout) LayoutInflater.from(mContext)
.inflate(R.layout.qs_paged_tile_layout, this, false);
}
return mRegularTileLayout;
}
protected QSTileLayout createHorizontalTileLayout() {
return createRegularTileLayout();
return mTileLayout;
}
@Override
@@ -273,18 +262,18 @@ public class QSPanel extends LinearLayout implements Tunable {
* @param pageIndicator indicator to use for page scrolling
*/
public void setFooterPageIndicator(PageIndicator pageIndicator) {
if (mRegularTileLayout instanceof PagedTileLayout) {
if (mTileLayout instanceof PagedTileLayout) {
mFooterPageIndicator = pageIndicator;
updatePageIndicator();
}
}
private void updatePageIndicator() {
if (mRegularTileLayout instanceof PagedTileLayout) {
if (mTileLayout instanceof PagedTileLayout) {
if (mFooterPageIndicator != null) {
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;
}
protected boolean needsDynamicRowsAndColumns() {
private boolean needsDynamicRowsAndColumns() {
return true;
}
@@ -669,39 +658,20 @@ public class QSPanel extends LinearLayout implements Tunable {
}
protected void setPageMargin(int pageMargin) {
if (mRegularTileLayout instanceof PagedTileLayout) {
((PagedTileLayout) mRegularTileLayout).setPageMargin(pageMargin);
}
if (mHorizontalTileLayout != mRegularTileLayout
&& mHorizontalTileLayout instanceof PagedTileLayout) {
((PagedTileLayout) mHorizontalTileLayout).setPageMargin(pageMargin);
if (mTileLayout instanceof PagedTileLayout) {
((PagedTileLayout) mTileLayout).setPageMargin(pageMargin);
}
}
void setUsingHorizontalLayout(boolean horizontal, ViewGroup mediaHostView, boolean force,
UiEventLogger uiEventLogger) {
void setUsingHorizontalLayout(boolean horizontal, ViewGroup mediaHostView, boolean force) {
if (horizontal != mUsingHorizontalLayout || force) {
mUsingHorizontalLayout = horizontal;
View visibleView = horizontal ? mHorizontalLinearLayout : (View) mRegularTileLayout;
View hiddenView = horizontal ? (View) mRegularTileLayout : mHorizontalLinearLayout;
ViewGroup newParent = horizontal ? mHorizontalContentContainer : this;
QSPanel.QSTileLayout newLayout = horizontal
? 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);
switchAllContentToParent(newParent, mTileLayout);
reAttachMediaHost(mediaHostView, horizontal);
mTileLayout = newLayout;
newLayout.setListening(mListening, uiEventLogger);
if (needsDynamicRowsAndColumns()) {
newLayout.setMinRows(horizontal ? 2 : 1);
newLayout.setMaxColumns(horizontal ? 2 : 4);
mTileLayout.setMinRows(horizontal ? 2 : 1);
mTileLayout.setMaxColumns(horizontal ? 2 : 4);
}
updateMargins(mediaHostView);
}

View File

@@ -147,14 +147,14 @@ public class QSPanelController extends QSPanelControllerBase<QSPanel> {
mBrightnessMirrorController.addCallback(mBrightnessMirrorListener);
}
((PagedTileLayout) mView.createRegularTileLayout())
((PagedTileLayout) mView.getOrCreateTileLayout())
.setOnTouchListener(mTileLayoutTouchListener);
}
@Override
protected QSTileRevealController createTileRevealController() {
return mQsTileRevealControllerFactory.create(
this, (PagedTileLayout) mView.createRegularTileLayout());
this, (PagedTileLayout) mView.getOrCreateTileLayout());
}
@Override

View File

@@ -297,20 +297,12 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
}
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();
if (horizontal != mUsingHorizontalLayout || force) {
mUsingHorizontalLayout = horizontal;
for (QSPanelControllerBase.TileRecord record : mRecords) {
mView.removeTile(record);
record.tile.removeCallback(record.callback);
}
mView.setUsingHorizontalLayout(mUsingHorizontalLayout, mMediaHost.getHostView(), force,
mUiEventLogger);
mView.setUsingHorizontalLayout(mUsingHorizontalLayout, mMediaHost.getHostView(), force);
updateMediaDisappearParameters();
setTiles();
return true;
}
return false;

View File

@@ -61,21 +61,10 @@ public class QuickQSPanel extends QSPanel {
}
@Override
public TileLayout createRegularTileLayout() {
public TileLayout getOrCreateTileLayout() {
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
protected boolean displayMediaMarginsOnMedia() {

View File

@@ -127,7 +127,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
when(mQSPanel.getDumpableTag()).thenReturn("QSPanel");
when(mQSPanel.openPanelEvent()).thenReturn(QSEvent.QS_PANEL_EXPANDED);
when(mQSPanel.closePanelEvent()).thenReturn(QSEvent.QS_PANEL_COLLAPSED);
when(mQSPanel.createRegularTileLayout()).thenReturn(mPagedTileLayout);
when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
when(mQSTile.getTileSpec()).thenReturn("dnd");
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.getDumpableTag()).thenReturn("QSPanel");
when(mQSPanel.createRegularTileLayout()).thenReturn(mPagedTileLayout);
when(mQSPanel.getOrCreateTileLayout()).thenReturn(mPagedTileLayout);
when(mQSPanel.getTileLayout()).thenReturn(mPagedTileLayout);
when(mQSTileHost.getTiles()).thenReturn(Collections.singleton(mQSTile));
when(mQSTileHost.createTileView(any(), eq(mQSTile), anyBoolean())).thenReturn(mQSTileView);