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

Commit 1620670c authored by Michael Mikhail's avatar Michael Mikhail Committed by Android (Google) Code Review
Browse files

Merge "Adjust the number of recommendations according to display size" into udc-dev

parents c0138451 65c79664
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -64,6 +64,10 @@
    <!-- The number of rows in the QuickSettings -->
    <integer name="quick_settings_max_rows">4</integer>

    <!-- If the dp width of the available space is <= this value, potentially adjust the number
         of media recommendation items-->
    <integer name="default_qs_media_rec_width_dp">380</integer>

    <!-- The number of columns that the top level tiles span in the QuickSettings -->

    <!-- The default tiles to display in QuickSettings -->
+1 −0
Original line number Diff line number Diff line
@@ -1094,6 +1094,7 @@
    <dimen name="qs_media_session_collapsed_guideline">144dp</dimen>

    <!-- Size of Smartspace media recommendations cards in the QSPanel carousel -->
    <dimen name="qs_media_rec_default_width">380dp</dimen>
    <dimen name="qs_media_rec_icon_top_margin">16dp</dimen>
    <dimen name="qs_media_rec_album_icon_size">16dp</dimen>
    <dimen name="qs_media_rec_album_size">88dp</dimen>
+3 −2
Original line number Diff line number Diff line
@@ -109,10 +109,11 @@ constructor(
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
) : Dumpable {
    /** The current width of the carousel */
    private var currentCarouselWidth: Int = 0
    var currentCarouselWidth: Int = 0
        private set

    /** The current height of the carousel */
    @VisibleForTesting var currentCarouselHeight: Int = 0
    private var currentCarouselHeight: Int = 0

    /** Are we currently showing only active players */
    private var currentlyShowingOnlyActive: Boolean = false
+62 −4
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BlendMode;
import android.graphics.Color;
@@ -54,6 +56,7 @@ import android.os.Process;
import android.os.Trace;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -468,6 +471,7 @@ public class MediaControlPanel {
        TransitionLayout recommendations = vh.getRecommendations();

        mMediaViewController.attach(recommendations, MediaViewController.TYPE.RECOMMENDATION);
        mMediaViewController.configurationChangeListener = this::updateRecommendationsVisibility;

        mRecommendationViewHolder.getRecommendations().setOnLongClickListener(v -> {
            if (mFalsingManager.isFalseLongTap(FalsingManager.LOW_PENALTY)) return true;
@@ -1364,6 +1368,7 @@ public class MediaControlPanel {

        boolean hasTitle = false;
        boolean hasSubtitle = false;
        int fittedRecsNum = getNumberOfFittedRecommendations();
        for (int itemIndex = 0; itemIndex < NUM_REQUIRED_RECOMMENDATIONS; itemIndex++) {
            SmartspaceAction recommendation = recommendations.get(itemIndex);

@@ -1444,12 +1449,20 @@ public class MediaControlPanel {

        // If there's no subtitles and/or titles for any of the albums, hide those views.
        ConstraintSet expandedSet = mMediaViewController.getExpandedLayout();
        ConstraintSet collapsedSet = mMediaViewController.getCollapsedLayout();
        final boolean titlesVisible = hasTitle;
        final boolean subtitlesVisible = hasSubtitle;
        mRecommendationViewHolder.getMediaTitles().forEach((titleView) ->
                setVisibleAndAlpha(expandedSet, titleView.getId(), titlesVisible));
        mRecommendationViewHolder.getMediaSubtitles().forEach((subtitleView) ->
                setVisibleAndAlpha(expandedSet, subtitleView.getId(), subtitlesVisible));
        mRecommendationViewHolder.getMediaTitles().forEach((titleView) -> {
            setVisibleAndAlpha(expandedSet, titleView.getId(), titlesVisible);
            setVisibleAndAlpha(collapsedSet, titleView.getId(), titlesVisible);
        });
        mRecommendationViewHolder.getMediaSubtitles().forEach((subtitleView) -> {
            setVisibleAndAlpha(expandedSet, subtitleView.getId(), subtitlesVisible);
            setVisibleAndAlpha(collapsedSet, subtitleView.getId(), subtitlesVisible);
        });

        // Media covers visibility.
        setMediaCoversVisibility(fittedRecsNum);

        // Guts
        Runnable onDismissClickedRunnable = () -> {
@@ -1486,6 +1499,51 @@ public class MediaControlPanel {
        Trace.endSection();
    }

    private Unit updateRecommendationsVisibility() {
        int fittedRecsNum = getNumberOfFittedRecommendations();
        setMediaCoversVisibility(fittedRecsNum);
        return Unit.INSTANCE;
    }

    private void setMediaCoversVisibility(int fittedRecsNum) {
        ConstraintSet expandedSet = mMediaViewController.getExpandedLayout();
        ConstraintSet collapsedSet = mMediaViewController.getCollapsedLayout();
        List<ViewGroup> mediaCoverContainers = mRecommendationViewHolder.getMediaCoverContainers();
        // Hide media cover that cannot fit in the recommendation card.
        for (int itemIndex = 0; itemIndex < NUM_REQUIRED_RECOMMENDATIONS; itemIndex++) {
            setVisibleAndAlpha(expandedSet, mediaCoverContainers.get(itemIndex).getId(),
                    itemIndex < fittedRecsNum);
            setVisibleAndAlpha(collapsedSet, mediaCoverContainers.get(itemIndex).getId(),
                    itemIndex < fittedRecsNum);
        }
    }

    @VisibleForTesting
    protected int getNumberOfFittedRecommendations() {
        Resources res = mContext.getResources();
        Configuration config = res.getConfiguration();
        int defaultDpWidth = res.getInteger(R.integer.default_qs_media_rec_width_dp);
        int recCoverWidth = res.getDimensionPixelSize(R.dimen.qs_media_rec_album_width)
                + res.getDimensionPixelSize(R.dimen.qs_media_info_spacing) * 2;

        // On landscape, media controls should take half of the screen width.
        int displayAvailableDpWidth = config.screenWidthDp;
        if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            displayAvailableDpWidth = displayAvailableDpWidth / 2;
        }
        int fittedNum;
        if (displayAvailableDpWidth > defaultDpWidth) {
            int recCoverDefaultWidth = res.getDimensionPixelSize(
                    R.dimen.qs_media_rec_default_width);
            fittedNum = recCoverDefaultWidth / recCoverWidth;
        } else {
            int displayAvailableWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    displayAvailableDpWidth, res.getDisplayMetrics());
            fittedNum = displayAvailableWidth / recCoverWidth;
        }
        return Math.min(fittedNum, NUM_REQUIRED_RECOMMENDATIONS);
    }

    private void fetchAndUpdateRecommendationColors(Drawable appIcon) {
        mBackgroundExecutor.execute(() -> {
            ColorScheme colorScheme = new ColorScheme(
+5 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ constructor(

    /** A listener when the current dimensions of the player change */
    lateinit var sizeChangedListener: () -> Unit
    lateinit var configurationChangeListener: () -> Unit
    private var firstRefresh: Boolean = true
    @VisibleForTesting private var transitionLayout: TransitionLayout? = null
    private val layoutController = TransitionLayoutController()
@@ -195,6 +196,10 @@ constructor(
                                )
                        }
                    }
                    if (this@MediaViewController::configurationChangeListener.isInitialized) {
                        configurationChangeListener.invoke()
                        refreshState()
                    }
                }
            }
        }
Loading