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

Commit c20fe0cc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix crash and QQS session issues, visual updates"

parents e8bab797 899b5950
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2020 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<!-- Carousel for media controls -->
<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/qs_media_height"
    android:padding="@dimen/qs_media_padding"
    android:scrollbars="none"
    android:visibility="gone"
    >
    <LinearLayout
        android:id="@+id/media_carousel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <!-- QSMediaPlayers will be added here dynamically -->
    </LinearLayout>
</HorizontalScrollView>
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ class DoubleLineTileLayout(context: Context) : ViewGroup(context), QSPanel.QSTil
    override fun updateResources(): Boolean {
        with(mContext.resources) {
            smallTileSize = getDimensionPixelSize(R.dimen.qs_quick_tile_size)
            cellMarginHorizontal = getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal)
            cellMarginHorizontal = getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal) / 2
            cellMarginVertical = getDimensionPixelSize(R.dimen.new_qs_vertical_margin)
        }
        requestLayout()
+2 −3
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class QSMediaPlayer {
                    }
                }
            });
            btn.setImageDrawable(mContext.getResources().getDrawable(R.drawable.lb_ic_replay));
            btn.setImageDrawable(mContext.getResources().getDrawable(R.drawable.lb_ic_play));
            btn.setImageTintList(ColorStateList.valueOf(mForegroundColor));
            btn.setVisibility(View.VISIBLE);

@@ -199,8 +199,7 @@ public class QSMediaPlayer {
        List<ResolveInfo> info = pm.queryBroadcastReceiversAsUser(it, 0, mContext.getUser());
        if (info != null) {
            for (ResolveInfo inf : info) {
                if (inf.activityInfo.packageName.equals(notif.contentIntent.getCreatorPackage())) {
                    Log.d(TAG, "Found receiver for package: " + inf);
                if (inf.activityInfo.packageName.equals(mController.getPackageName())) {
                    mRecvComponent = inf.getComponentInfo().getComponentName();
                }
            }
+4 −15
Original line number Diff line number Diff line
@@ -184,21 +184,10 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne

        // Add media carousel
        if (useQsMediaPlayer(context)) {
            HorizontalScrollView mediaScrollView = new HorizontalScrollView(mContext);
            mediaScrollView.setHorizontalScrollBarEnabled(false);
            int playerHeight = (int) getResources().getDimension(R.dimen.qs_media_height);
            int padding = (int) getResources().getDimension(R.dimen.qs_media_padding);
            LayoutParams lpView = new LayoutParams(LayoutParams.MATCH_PARENT, playerHeight);
            lpView.setMarginStart(padding);
            lpView.setMarginEnd(padding);
            addView(mediaScrollView, lpView);

            LayoutParams lpCarousel = new LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            mMediaCarousel = new LinearLayout(mContext);
            mMediaCarousel.setOrientation(LinearLayout.HORIZONTAL);
            mediaScrollView.addView(mMediaCarousel, lpCarousel);
            mediaScrollView.setVisibility(View.GONE);
            HorizontalScrollView mediaScrollView = (HorizontalScrollView) LayoutInflater.from(
                    mContext).inflate(R.layout.media_carousel, this, false);
            mMediaCarousel = mediaScrollView.findViewById(R.id.media_carousel);
            addView(mediaScrollView);
        } else {
            mMediaCarousel = null;
        }
+33 −14
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public class QuickQSMediaPlayer {
                    }
                }
            });
            btn.setImageDrawable(mContext.getResources().getDrawable(R.drawable.lb_ic_replay));
            btn.setImageDrawable(mContext.getResources().getDrawable(R.drawable.lb_ic_play));
            btn.setImageTintList(ColorStateList.valueOf(mForegroundColor));
            btn.setVisibility(View.VISIBLE);
        }
@@ -136,14 +136,25 @@ public class QuickQSMediaPlayer {
     * @param actionsContainer a LinearLayout containing the media action buttons
     * @param actionsToShow indices of which actions to display in the mini player
     *                      (max 3: Notification.MediaStyle.MAX_MEDIA_BUTTONS_IN_COMPACT)
     * @param contentIntent Intent to send when user taps on the view
     */
    public void setMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
            View actionsContainer, int[] actionsToShow) {
        Log.d(TAG, "Setting media session: " + token);
            View actionsContainer, int[] actionsToShow, PendingIntent contentIntent) {
        mToken = token;
        mForegroundColor = iconColor;
        mBackgroundColor = bgColor;
        mController = new MediaController(mContext, token);

        String oldPackage = "";
        if (mController != null) {
            oldPackage = mController.getPackageName();
        }
        MediaController controller = new MediaController(mContext, token);
        boolean samePlayer = mToken.equals(token) && oldPackage.equals(controller.getPackageName());
        if (mController != null && !samePlayer && !isPlaying(controller)) {
            // Only update if this is a different session and currently playing
            return;
        }
        mController = controller;
        MediaMetadata mMediaMetadata = mController.getMetadata();

        // Try to find a receiver for the media button that matches this app
@@ -153,7 +164,6 @@ public class QuickQSMediaPlayer {
        if (info != null) {
            for (ResolveInfo inf : info) {
                if (inf.activityInfo.packageName.equals(mController.getPackageName())) {
                    Log.d(TAG, "Found receiver for package: " + inf);
                    mRecvComponent = inf.getComponentInfo().getComponentName();
                }
            }
@@ -165,6 +175,16 @@ public class QuickQSMediaPlayer {
            return;
        }

        // Action
        mMediaNotifView.setOnClickListener(v -> {
            try {
                contentIntent.send();
                mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
            } catch (PendingIntent.CanceledException e) {
                Log.e(TAG, "Pending intent was canceled: " + e.getMessage());
            }
        });

        // Album art
        addAlbumArtBackground(mMediaMetadata, mBackgroundColor);

@@ -237,12 +257,12 @@ public class QuickQSMediaPlayer {
     * Check whether the media controlled by this player is currently playing
     * @return whether it is playing, or false if no controller information
     */
    public boolean isPlaying() {
        if (mController == null) {
    public boolean isPlaying(MediaController controller) {
        if (controller == null) {
            return false;
        }

        PlaybackState state = mController.getPlaybackState();
        PlaybackState state = controller.getPlaybackState();
        if (state == null) {
            return false;
        }
@@ -261,12 +281,11 @@ public class QuickQSMediaPlayer {
    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);
        if (albumArt != null) {
        Rect bounds = new Rect();
        mMediaNotifView.getBoundsOnScreen(bounds);
        int width = bounds.width();
        int height = bounds.height();

        if (albumArt != null && width > 0 && height > 0) {
            Bitmap original = albumArt.copy(Bitmap.Config.ARGB_8888, true);
            Bitmap scaled = scaleBitmap(original, width, height);
            Canvas canvas = new Canvas(scaled);
Loading