diff options
author | Fabian Kozynski <kozynski@google.com> | 2019-12-10 18:13:53 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-10 18:13:53 +0000 |
commit | cf124fb9614287e82d254dea67b778c46f831e76 (patch) | |
tree | 1b2024a2cd80005f3f0bdfdb5fa9a9e6541240d6 | |
parent | 809e21fc286f7bffdb6dd835b9931adb7748ba08 (diff) | |
parent | aba2a5424dd148550095489ba5b8964d2a9ca4ea (diff) |
Merge "Use single line QQS when not playing media"
3 files changed, 68 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSMediaPlayer.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSMediaPlayer.java index 5bb882e2355f..d40e25064352 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSMediaPlayer.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSMediaPlayer.java @@ -250,6 +250,14 @@ public class QuickQSMediaPlayer { return (state.getState() == PlaybackState.STATE_PLAYING); } + /** + * Check whether this player has an attached media session. + * @return whether there is a controller with a current media session. + */ + public boolean hasMediaSession() { + return mController != null && mController.getPlaybackState() != null; + } + private void addAlbumArtBackground(MediaMetadata metadata, int bgColor) { Bitmap albumArt = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART); float radius = mContext.getResources().getDimension(R.dimen.qs_media_corner_radius); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java index d377f1c793a9..feb10a2e9a6e 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java @@ -57,6 +57,12 @@ public class QuickQSPanel extends QSPanel { private int mMaxTiles; protected QSPanel mFullPanel; private QuickQSMediaPlayer mMediaPlayer; + private boolean mUsingMediaPlayer; + private LinearLayout mHorizontalLinearLayout; + + // Only used with media + private QSTileLayout mMediaTileLayout; + private QSTileLayout mRegularTileLayout; @Inject public QuickQSPanel(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, @@ -72,8 +78,9 @@ public class QuickQSPanel extends QSPanel { removeView((View) mTileLayout); } - if (Utils.useQsMediaPlayer(context)) { - LinearLayout mHorizontalLinearLayout = new LinearLayout(mContext); + mUsingMediaPlayer = Utils.useQsMediaPlayer(context); + if (mUsingMediaPlayer) { + mHorizontalLinearLayout = new LinearLayout(mContext); mHorizontalLinearLayout.setOrientation(LinearLayout.HORIZONTAL); mHorizontalLinearLayout.setClipChildren(false); mHorizontalLinearLayout.setClipToPadding(false); @@ -81,6 +88,8 @@ public class QuickQSPanel extends QSPanel { LayoutParams lp = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1); mTileLayout = new DoubleLineTileLayout(context); + mMediaTileLayout = mTileLayout; + mRegularTileLayout = new HeaderTileLayout(context); lp.setMarginEnd(10); lp.setMarginStart(0); mHorizontalLinearLayout.addView((View) mTileLayout, lp); @@ -95,6 +104,8 @@ public class QuickQSPanel extends QSPanel { mTileLayout.setListening(mListening); addView(mHorizontalLinearLayout, 0 /* Between brightness and footer */); + ((View) mRegularTileLayout).setVisibility(View.GONE); + addView((View) mRegularTileLayout, 0); super.setPadding(0, 0, 0, 0); } else { sDefaultMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_columns); @@ -130,6 +141,8 @@ public class QuickQSPanel extends QSPanel { Dependency.get(TunerService.class).removeTunable(mNumTiles); } + + @Override protected String getDumpableTag() { return TAG; @@ -152,6 +165,42 @@ public class QuickQSPanel extends QSPanel { super.drawTile(r, state); } + boolean switchTileLayout() { + if (!mUsingMediaPlayer) return false; + if (mMediaPlayer.hasMediaSession() + && mHorizontalLinearLayout.getVisibility() == View.GONE) { + mHorizontalLinearLayout.setVisibility(View.VISIBLE); + ((View) mRegularTileLayout).setVisibility(View.GONE); + mTileLayout.setListening(false); + for (TileRecord record : mRecords) { + mTileLayout.removeTile(record); + record.tile.removeCallback(record.callback); + } + mTileLayout = mMediaTileLayout; + setTiles(mHost.getTiles()); + mTileLayout.setListening(mListening); + return true; + } else if (!mMediaPlayer.hasMediaSession() + && mHorizontalLinearLayout.getVisibility() == View.VISIBLE) { + mHorizontalLinearLayout.setVisibility(View.GONE); + ((View) mRegularTileLayout).setVisibility(View.VISIBLE); + mTileLayout.setListening(false); + for (TileRecord record : mRecords) { + mTileLayout.removeTile(record); + record.tile.removeCallback(record.callback); + } + mTileLayout = mRegularTileLayout; + setTiles(mHost.getTiles()); + mTileLayout.setListening(mListening); + return true; + } + return false; + } + + public boolean hasMediaPlayerSession() { + return mMediaPlayer.hasMediaSession(); + } + @Override public void setHost(QSTileHost host, QSCustomizer customizer) { super.setHost(host, customizer); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java index e5cec878b63d..d4af1548af41 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java @@ -339,7 +339,7 @@ public class QuickStatusBarHeader extends RelativeLayout implements if (mQsDisabled) { lp.height = resources.getDimensionPixelSize( com.android.internal.R.dimen.quick_qs_offset_height); - } else if (useQsMediaPlayer(mContext)) { + } else if (useQsMediaPlayer(mContext) && mHeaderQsPanel.hasMediaPlayerSession()) { lp.height = Math.max(getMinimumHeight(), resources.getDimensionPixelSize( com.android.internal.R.dimen.quick_qs_total_height_with_media)); @@ -405,6 +405,11 @@ public class QuickStatusBarHeader extends RelativeLayout implements mHeaderTextContainerView.setVisibility(INVISIBLE); } } + if (expansionFraction < 1 && expansionFraction > 0.99) { + if (mHeaderQsPanel.switchTileLayout()) { + updateResources(); + } + } } public void disable(int state1, int state2, boolean animate) { @@ -453,6 +458,9 @@ public class QuickStatusBarHeader extends RelativeLayout implements return; } mHeaderQsPanel.setListening(listening); + if (mHeaderQsPanel.switchTileLayout()) { + updateResources(); + } mListening = listening; if (listening) { |