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

Commit cf124fb9 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Use single line QQS when not playing media"

parents 809e21fc aba2a542
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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);
+51 −2
Original line number Diff line number Diff line
@@ -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);
+9 −1
Original line number Diff line number Diff line
@@ -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) {