Wait to reorder players, visual updates
- Wait until QS is not visible to reorder media players - Move media players to top/left - Update layouts for current designs - reduce number of tiles in QS when media flag is enabled Test: manual, screenshots at https://drive.google.com/drive/folders/1aLsTJaOuYTdZOo3XFtWsLyvN7UALHyz3?usp=sharing Change-Id: Ibd5289d3a5fe18bbdde63141d9ef4f247b261836
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke android:width="1dp" android:color="#1f000000"/>
|
||||
<corners android:radius="20dp"/>
|
||||
<corners android:radius="24dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
|
||||
26
packages/SystemUI/res/drawable/qs_media_background.xml
Normal file
26
packages/SystemUI/res/drawable/qs_media_background.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="?android:attr/colorBackgroundFloating" />
|
||||
<corners
|
||||
android:bottomLeftRadius="@dimen/qs_media_corner_radius"
|
||||
android:topLeftRadius="@dimen/qs_media_corner_radius"
|
||||
android:bottomRightRadius="@dimen/qs_media_corner_radius"
|
||||
android:topRightRadius="@dimen/qs_media_corner_radius"
|
||||
/>
|
||||
</shape>
|
||||
@@ -19,7 +19,7 @@
|
||||
<HorizontalScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/qs_media_height"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/qs_media_padding"
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone"
|
||||
|
||||
@@ -23,20 +23,25 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="10dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:background="@drawable/qs_media_background"
|
||||
>
|
||||
<!-- Top line: icon + artist name -->
|
||||
<!-- Top line: icon + song name -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipChildren="false"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="12dp"
|
||||
>
|
||||
<com.android.internal.widget.CachingIconView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="15dp"
|
||||
android:layout_height="15dp"
|
||||
android:layout_width="14dp"
|
||||
android:layout_height="14dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
/>
|
||||
<TextView
|
||||
@@ -48,15 +53,6 @@
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Second line: song name -->
|
||||
<TextView
|
||||
android:id="@+id/header_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:fontFamily="@*android:string/config_bodyFontFamily"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Bottom section: controls -->
|
||||
<LinearLayout
|
||||
android:id="@+id/media_actions"
|
||||
@@ -70,8 +66,6 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action0"
|
||||
@@ -80,8 +74,6 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action1"
|
||||
@@ -90,8 +82,6 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action2"
|
||||
|
||||
@@ -130,9 +130,10 @@
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:id="@+id/qs_drag_handle_view"
|
||||
android:layout_width="24dp"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="4dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_gravity="center_horizontal|bottom"
|
||||
android:background="@drawable/qs_footer_drag_handle" />
|
||||
|
||||
|
||||
@@ -23,50 +23,116 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal|fill_vertical"
|
||||
android:padding="10dp"
|
||||
android:padding="16dp"
|
||||
android:background="@drawable/qs_media_background"
|
||||
>
|
||||
|
||||
<!-- placeholder for notification header -->
|
||||
<!-- Header section -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/header"
|
||||
android:padding="3dp"
|
||||
android:layout_marginEnd="-12dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/album_art"
|
||||
android:layout_width="@dimen/qs_media_album_size"
|
||||
android:layout_height="@dimen/qs_media_album_size"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_weight="0"
|
||||
/>
|
||||
|
||||
<!-- Top line: artist name -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/qs_media_album_size"
|
||||
android:layout_weight="1"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/header_title"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
>
|
||||
<com.android.internal.widget.CachingIconView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/app_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:singleLine="true"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Song name -->
|
||||
<TextView
|
||||
android:id="@+id/header_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
|
||||
android:textSize="18sp"
|
||||
android:paddingBottom="6dp"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Artist name -->
|
||||
<TextView
|
||||
android:id="@+id/header_artist"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@*android:string/config_bodyFontFamily"
|
||||
android:textSize="14sp"
|
||||
android:singleLine="true"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Output chip -->
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
|
||||
android:singleLine="true"
|
||||
/>
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:paddingLeft="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:gravity="center"
|
||||
android:id="@+id/media_seamless"
|
||||
android:background="@*android:drawable/media_seamless_background"
|
||||
android:layout_weight="1"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="@dimen/qs_seamless_icon_size"
|
||||
android:layout_height="@dimen/qs_seamless_icon_size"
|
||||
android:src="@*android:drawable/ic_media_seamless"
|
||||
android:layout_marginRight="8dp"
|
||||
android:id="@+id/media_seamless_image"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@*android:string/config_bodyFontFamily"
|
||||
android:text="@*android:string/ext_media_seamless_action"
|
||||
android:textSize="14sp"
|
||||
android:id="@+id/media_seamless_text"
|
||||
android:singleLine="true"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Second line: song name -->
|
||||
<TextView
|
||||
android:id="@+id/header_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:fontFamily="@*android:string/config_bodyFontFamily"
|
||||
android:gravity="center"/>
|
||||
|
||||
<!-- Bottom section: controls -->
|
||||
<!-- Controls -->
|
||||
<LinearLayout
|
||||
android:id="@+id/media_actions"
|
||||
android:orientation="horizontal"
|
||||
android:layoutDirection="ltr"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
>
|
||||
@@ -74,8 +140,8 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action0"
|
||||
@@ -84,18 +150,18 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action1"
|
||||
/>
|
||||
<ImageButton
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action2"
|
||||
@@ -104,8 +170,8 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action3"
|
||||
@@ -114,8 +180,8 @@
|
||||
style="@android:style/Widget.Material.Button.Borderless.Small"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:padding="8dp"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/action4"
|
||||
|
||||
@@ -1165,10 +1165,12 @@
|
||||
<dimen name="new_qs_vertical_margin">8dp</dimen>
|
||||
|
||||
<!-- Size of media cards in the QSPanel carousel -->
|
||||
<dimen name="qs_media_height">150dp</dimen>
|
||||
<dimen name="qs_media_width">350dp</dimen>
|
||||
<dimen name="qs_media_padding">8dp</dimen>
|
||||
<dimen name="qs_media_corner_radius">10dp</dimen>
|
||||
<dimen name="qs_media_album_size">72dp</dimen>
|
||||
<dimen name="qs_seamless_icon_size">20dp</dimen>
|
||||
<dimen name="qqs_media_spacing">8dp</dimen>
|
||||
|
||||
<dimen name="magnification_border_size">5dp</dimen>
|
||||
<dimen name="magnification_frame_move_short">5dp</dimen>
|
||||
|
||||
@@ -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) / 2
|
||||
cellMarginHorizontal = getDimensionPixelSize(R.dimen.qs_tile_margin_horizontal)
|
||||
cellMarginVertical = getDimensionPixelSize(R.dimen.new_qs_vertical_margin)
|
||||
}
|
||||
requestLayout()
|
||||
|
||||
@@ -36,7 +36,6 @@ import android.media.MediaMetadata;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.session.MediaSession;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -45,7 +44,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
@@ -72,8 +70,6 @@ public class QSMediaPlayer {
|
||||
private View mSeamless;
|
||||
private MediaSession.Token mToken;
|
||||
private MediaController mController;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private int mForegroundColor;
|
||||
private int mBackgroundColor;
|
||||
private ComponentName mRecvComponent;
|
||||
@@ -158,16 +154,11 @@ public class QSMediaPlayer {
|
||||
*
|
||||
* @param context
|
||||
* @param parent
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public QSMediaPlayer(Context context, ViewGroup parent, int width, int height) {
|
||||
public QSMediaPlayer(Context context, ViewGroup parent) {
|
||||
mContext = context;
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mMediaNotifView = (LinearLayout) inflater.inflate(R.layout.qs_media_panel, parent, false);
|
||||
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
@@ -217,27 +208,18 @@ public class QSMediaPlayer {
|
||||
Notification.Builder builder = Notification.Builder.recoverBuilder(mContext, notif);
|
||||
|
||||
// Album art
|
||||
addAlbumArtBackground(mMediaMetadata, bgColor, mWidth, mHeight);
|
||||
addAlbumArt(mMediaMetadata, bgColor);
|
||||
|
||||
// Reuse notification header instead of reimplementing everything
|
||||
RemoteViews headerRemoteView = builder.makeNotificationHeader();
|
||||
LinearLayout headerView = mMediaNotifView.findViewById(R.id.header);
|
||||
View result = headerRemoteView.apply(mContext, headerView);
|
||||
result.setPadding(0, 0, 0, 0);
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT, 75);
|
||||
result.setLayoutParams(lp);
|
||||
headerView.removeAllViews();
|
||||
headerView.addView(result);
|
||||
|
||||
// App icon
|
||||
ImageView appIcon = headerView.findViewById(com.android.internal.R.id.icon);
|
||||
ImageView appIcon = headerView.findViewById(R.id.icon);
|
||||
Drawable iconDrawable = icon.loadDrawable(mContext);
|
||||
iconDrawable.setTint(iconColor);
|
||||
appIcon.setImageDrawable(iconDrawable);
|
||||
|
||||
// App title
|
||||
TextView appName = headerView.findViewById(com.android.internal.R.id.app_name_text);
|
||||
TextView appName = headerView.findViewById(R.id.app_name);
|
||||
String appNameString = builder.loadHeaderAppName();
|
||||
appName.setText(appNameString);
|
||||
appName.setTextColor(iconColor);
|
||||
@@ -254,25 +236,8 @@ public class QSMediaPlayer {
|
||||
}
|
||||
});
|
||||
|
||||
// Separator
|
||||
TextView separator = headerView.findViewById(com.android.internal.R.id.header_text_divider);
|
||||
separator.setTextColor(iconColor);
|
||||
|
||||
// Album name
|
||||
TextView albumName = headerView.findViewById(com.android.internal.R.id.header_text);
|
||||
String albumString = mMediaMetadata.getString(MediaMetadata.METADATA_KEY_ALBUM);
|
||||
if (TextUtils.isEmpty(albumString)) {
|
||||
albumName.setVisibility(View.GONE);
|
||||
separator.setVisibility(View.GONE);
|
||||
} else {
|
||||
albumName.setText(albumString);
|
||||
albumName.setTextColor(iconColor);
|
||||
albumName.setVisibility(View.VISIBLE);
|
||||
separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
// Transfer chip
|
||||
mSeamless = headerView.findViewById(com.android.internal.R.id.media_seamless);
|
||||
mSeamless = headerView.findViewById(R.id.media_seamless);
|
||||
mSeamless.setVisibility(View.VISIBLE);
|
||||
updateChip(device);
|
||||
ActivityStarter mActivityStarter = Dependency.get(ActivityStarter.class);
|
||||
@@ -284,13 +249,13 @@ public class QSMediaPlayer {
|
||||
});
|
||||
|
||||
// Artist name
|
||||
TextView artistText = mMediaNotifView.findViewById(R.id.header_title);
|
||||
TextView artistText = headerView.findViewById(R.id.header_artist);
|
||||
String artistName = mMediaMetadata.getString(MediaMetadata.METADATA_KEY_ARTIST);
|
||||
artistText.setText(artistName);
|
||||
artistText.setTextColor(iconColor);
|
||||
|
||||
// Song name
|
||||
TextView titleText = mMediaNotifView.findViewById(R.id.header_text);
|
||||
TextView titleText = headerView.findViewById(R.id.header_text);
|
||||
String songName = mMediaMetadata.getString(MediaMetadata.METADATA_KEY_TITLE);
|
||||
titleText.setText(songName);
|
||||
titleText.setTextColor(iconColor);
|
||||
@@ -363,34 +328,25 @@ public class QSMediaPlayer {
|
||||
return (state.getState() == PlaybackState.STATE_PLAYING);
|
||||
}
|
||||
|
||||
private void addAlbumArtBackground(MediaMetadata metadata, int bgColor, int width, int height) {
|
||||
private void addAlbumArt(MediaMetadata metadata, int bgColor) {
|
||||
Bitmap albumArt = metadata.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
|
||||
float radius = mContext.getResources().getDimension(R.dimen.qs_media_corner_radius);
|
||||
ImageView albumView = mMediaNotifView.findViewById(R.id.album_art);
|
||||
if (albumArt != null) {
|
||||
Log.d(TAG, "updating album art");
|
||||
Bitmap original = albumArt.copy(Bitmap.Config.ARGB_8888, true);
|
||||
Bitmap scaled = scaleBitmap(original, width, height);
|
||||
Canvas canvas = new Canvas(scaled);
|
||||
|
||||
// Add translucent layer over album art to improve contrast
|
||||
Paint p = new Paint();
|
||||
p.setStyle(Paint.Style.FILL);
|
||||
p.setColor(bgColor);
|
||||
p.setAlpha(200);
|
||||
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), p);
|
||||
|
||||
int albumSize = (int) mContext.getResources().getDimension(R.dimen.qs_media_album_size);
|
||||
Bitmap scaled = scaleBitmap(original, albumSize, albumSize);
|
||||
RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(
|
||||
mContext.getResources(), scaled);
|
||||
roundedDrawable.setCornerRadius(radius);
|
||||
|
||||
mMediaNotifView.setBackground(roundedDrawable);
|
||||
albumView.setImageDrawable(roundedDrawable);
|
||||
} else {
|
||||
Log.e(TAG, "No album art available");
|
||||
GradientDrawable rect = new GradientDrawable();
|
||||
rect.setCornerRadius(radius);
|
||||
rect.setColor(bgColor);
|
||||
mMediaNotifView.setBackground(rect);
|
||||
albumView.setImageDrawable(null);
|
||||
}
|
||||
|
||||
mMediaNotifView.setBackgroundTintList(ColorStateList.valueOf(bgColor));
|
||||
}
|
||||
|
||||
private Bitmap scaleBitmap(Bitmap original, int width, int height) {
|
||||
@@ -423,8 +379,8 @@ public class QSMediaPlayer {
|
||||
rect.setStroke(2, mForegroundColor);
|
||||
rect.setColor(mBackgroundColor);
|
||||
|
||||
ImageView iconView = mSeamless.findViewById(com.android.internal.R.id.media_seamless_image);
|
||||
TextView deviceName = mSeamless.findViewById(com.android.internal.R.id.media_seamless_text);
|
||||
ImageView iconView = mSeamless.findViewById(R.id.media_seamless_image);
|
||||
TextView deviceName = mSeamless.findViewById(R.id.media_seamless_text);
|
||||
deviceName.setTextColor(fgTintList);
|
||||
|
||||
if (device != null) {
|
||||
|
||||
@@ -97,6 +97,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>();
|
||||
private LocalMediaManager mLocalMediaManager;
|
||||
private MediaDevice mDevice;
|
||||
private boolean mUpdateCarousel = false;
|
||||
|
||||
protected boolean mExpanded;
|
||||
protected boolean mListening;
|
||||
@@ -187,7 +188,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
HorizontalScrollView mediaScrollView = (HorizontalScrollView) LayoutInflater.from(
|
||||
mContext).inflate(R.layout.media_carousel, this, false);
|
||||
mMediaCarousel = mediaScrollView.findViewById(R.id.media_carousel);
|
||||
addView(mediaScrollView);
|
||||
addView(mediaScrollView, 0);
|
||||
} else {
|
||||
mMediaCarousel = null;
|
||||
}
|
||||
@@ -211,6 +212,23 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVisibilityAggregated(boolean isVisible) {
|
||||
super.onVisibilityAggregated(isVisible);
|
||||
if (!isVisible && mUpdateCarousel) {
|
||||
for (QSMediaPlayer player : mMediaPlayers) {
|
||||
if (player.isPlaying()) {
|
||||
LayoutParams lp = (LayoutParams) player.getView().getLayoutParams();
|
||||
mMediaCarousel.removeView(player.getView());
|
||||
mMediaCarousel.addView(player.getView(), 0, lp);
|
||||
((HorizontalScrollView) mMediaCarousel.getParent()).fullScroll(View.FOCUS_LEFT);
|
||||
mUpdateCarousel = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a player for the associated media session
|
||||
* @param token
|
||||
@@ -248,7 +266,6 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
}
|
||||
}
|
||||
|
||||
int playerHeight = (int) getResources().getDimension(R.dimen.qs_media_height);
|
||||
int playerWidth = (int) getResources().getDimension(R.dimen.qs_media_width);
|
||||
int padding = (int) getResources().getDimension(R.dimen.qs_media_padding);
|
||||
LayoutParams lp = new LayoutParams(playerWidth, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
@@ -257,8 +274,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
|
||||
if (player == null) {
|
||||
Log.d(TAG, "creating new player");
|
||||
|
||||
player = new QSMediaPlayer(mContext, this, playerWidth, playerHeight);
|
||||
player = new QSMediaPlayer(mContext, this);
|
||||
|
||||
if (player.isPlaying()) {
|
||||
mMediaCarousel.addView(player.getView(), 0, lp); // add in front
|
||||
@@ -267,9 +283,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne
|
||||
}
|
||||
mMediaPlayers.add(player);
|
||||
} else if (player.isPlaying()) {
|
||||
// move it to the front
|
||||
mMediaCarousel.removeView(player.getView());
|
||||
mMediaCarousel.addView(player.getView(), 0, lp);
|
||||
mUpdateCarousel = true;
|
||||
}
|
||||
|
||||
Log.d(TAG, "setting player session");
|
||||
|
||||
@@ -23,13 +23,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.media.MediaMetadata;
|
||||
import android.media.session.MediaController;
|
||||
@@ -45,9 +39,6 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
|
||||
import com.android.systemui.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -63,7 +54,6 @@ public class QuickQSMediaPlayer {
|
||||
private LinearLayout mMediaNotifView;
|
||||
private MediaSession.Token mToken;
|
||||
private MediaController mController;
|
||||
private int mBackgroundColor;
|
||||
private int mForegroundColor;
|
||||
private ComponentName mRecvComponent;
|
||||
|
||||
@@ -142,7 +132,6 @@ public class QuickQSMediaPlayer {
|
||||
View actionsContainer, int[] actionsToShow, PendingIntent contentIntent) {
|
||||
mToken = token;
|
||||
mForegroundColor = iconColor;
|
||||
mBackgroundColor = bgColor;
|
||||
|
||||
String oldPackage = "";
|
||||
if (mController != null) {
|
||||
@@ -185,8 +174,7 @@ public class QuickQSMediaPlayer {
|
||||
}
|
||||
});
|
||||
|
||||
// Album art
|
||||
addAlbumArtBackground(mMediaMetadata, mBackgroundColor);
|
||||
mMediaNotifView.setBackgroundTintList(ColorStateList.valueOf(bgColor));
|
||||
|
||||
// App icon
|
||||
ImageView appIcon = mMediaNotifView.findViewById(R.id.icon);
|
||||
@@ -194,14 +182,8 @@ public class QuickQSMediaPlayer {
|
||||
iconDrawable.setTint(mForegroundColor);
|
||||
appIcon.setImageDrawable(iconDrawable);
|
||||
|
||||
// Artist name
|
||||
TextView appText = mMediaNotifView.findViewById(R.id.header_title);
|
||||
String artistName = mMediaMetadata.getString(MediaMetadata.METADATA_KEY_ARTIST);
|
||||
appText.setText(artistName);
|
||||
appText.setTextColor(mForegroundColor);
|
||||
|
||||
// Song name
|
||||
TextView titleText = mMediaNotifView.findViewById(R.id.header_text);
|
||||
TextView titleText = mMediaNotifView.findViewById(R.id.header_title);
|
||||
String songName = mMediaMetadata.getString(MediaMetadata.METADATA_KEY_TITLE);
|
||||
titleText.setText(songName);
|
||||
titleText.setTextColor(mForegroundColor);
|
||||
@@ -277,54 +259,4 @@ public class QuickQSMediaPlayer {
|
||||
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);
|
||||
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);
|
||||
|
||||
// Add translucent layer over album art to improve contrast
|
||||
Paint p = new Paint();
|
||||
p.setStyle(Paint.Style.FILL);
|
||||
p.setColor(bgColor);
|
||||
p.setAlpha(200);
|
||||
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), p);
|
||||
|
||||
RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(
|
||||
mContext.getResources(), scaled);
|
||||
roundedDrawable.setCornerRadius(radius);
|
||||
|
||||
mMediaNotifView.setBackground(roundedDrawable);
|
||||
} else {
|
||||
Log.e(TAG, "No album art available");
|
||||
GradientDrawable rect = new GradientDrawable();
|
||||
rect.setCornerRadius(radius);
|
||||
rect.setColor(bgColor);
|
||||
mMediaNotifView.setBackground(rect);
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap scaleBitmap(Bitmap original, int width, int height) {
|
||||
Bitmap cropped = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(cropped);
|
||||
|
||||
float scale = (float) cropped.getWidth() / (float) original.getWidth();
|
||||
float dy = (cropped.getHeight() - original.getHeight() * scale) / 2.0f;
|
||||
Matrix transformation = new Matrix();
|
||||
transformation.postTranslate(0, dy);
|
||||
transformation.preScale(scale, scale);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setFilterBitmap(true);
|
||||
canvas.drawBitmap(original, transformation, paint);
|
||||
|
||||
return cropped;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,20 +85,21 @@ public class QuickQSPanel extends QSPanel {
|
||||
mHorizontalLinearLayout.setClipChildren(false);
|
||||
mHorizontalLinearLayout.setClipToPadding(false);
|
||||
|
||||
int marginSize = (int) mContext.getResources().getDimension(R.dimen.qqs_media_spacing);
|
||||
mMediaPlayer = new QuickQSMediaPlayer(mContext, mHorizontalLinearLayout);
|
||||
LayoutParams lp2 = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
|
||||
lp2.setMarginEnd(marginSize);
|
||||
lp2.setMarginStart(0);
|
||||
mHorizontalLinearLayout.addView(mMediaPlayer.getView(), lp2);
|
||||
|
||||
mTileLayout = new DoubleLineTileLayout(context);
|
||||
mMediaTileLayout = mTileLayout;
|
||||
mRegularTileLayout = new HeaderTileLayout(context);
|
||||
LayoutParams lp = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
|
||||
lp.setMarginEnd(10);
|
||||
lp.setMarginStart(0);
|
||||
lp.setMarginEnd(0);
|
||||
lp.setMarginStart(marginSize);
|
||||
mHorizontalLinearLayout.addView((View) mTileLayout, lp);
|
||||
|
||||
mMediaPlayer = new QuickQSMediaPlayer(mContext, mHorizontalLinearLayout);
|
||||
LayoutParams lp2 = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
|
||||
lp2.setMarginEnd(0);
|
||||
lp2.setMarginStart(25);
|
||||
mHorizontalLinearLayout.addView(mMediaPlayer.getView(), lp2);
|
||||
|
||||
sDefaultMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_columns);
|
||||
|
||||
mTileLayout.setListening(mListening);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.android.systemui.qs;
|
||||
|
||||
import static com.android.systemui.util.Utils.useQsMediaPlayer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
@@ -42,7 +44,8 @@ public class TileLayout extends ViewGroup implements QSTileLayout {
|
||||
public TileLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setFocusableInTouchMode(true);
|
||||
mLessRows = Settings.System.getInt(context.getContentResolver(), "qs_less_rows", 0) != 0;
|
||||
mLessRows = (Settings.System.getInt(context.getContentResolver(), "qs_less_rows", 0) != 0)
|
||||
|| useQsMediaPlayer(context);
|
||||
updateResources();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user