Hide the icon if didn't have media session or album art
- This CL before, output switcher panel will show default icon if there are no media session or album art. This CL will hide the icon if there are no media session or album art. - Add test case Bug: 161495909 Test: make -j42 RunSettingsRoboTests Change-Id: I5f80158b12f89c8499fb97d0b203ebeffefbc18b
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/title_group"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
@@ -25,11 +25,7 @@ import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.media.MediaMetadata;
|
import android.media.MediaMetadata;
|
||||||
import android.media.session.MediaController;
|
import android.media.session.MediaController;
|
||||||
import android.media.session.MediaSessionManager;
|
import android.media.session.MediaSessionManager;
|
||||||
@@ -109,8 +105,7 @@ public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceC
|
|||||||
@Override
|
@Override
|
||||||
public IconCompat getIcon() {
|
public IconCompat getIcon() {
|
||||||
if (mMediaController == null) {
|
if (mMediaController == null) {
|
||||||
return IconCompat.createWithResource(mContext, R.drawable.ic_media_stream).setTint(
|
return null;
|
||||||
Utils.getColorAccentDefaultColor(mContext));
|
|
||||||
}
|
}
|
||||||
final MediaMetadata metadata = mMediaController.getMetadata();
|
final MediaMetadata metadata = mMediaController.getMetadata();
|
||||||
if (metadata != null) {
|
if (metadata != null) {
|
||||||
@@ -124,25 +119,6 @@ public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, "Media meta data does not contain icon information");
|
Log.d(TAG, "Media meta data does not contain icon information");
|
||||||
return getPackageIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
private IconCompat getPackageIcon() {
|
|
||||||
try {
|
|
||||||
final Drawable drawable = mContext.getPackageManager().getApplicationIcon(mPackageName);
|
|
||||||
if (drawable instanceof BitmapDrawable) {
|
|
||||||
return IconCompat.createWithBitmap(((BitmapDrawable) drawable).getBitmap());
|
|
||||||
}
|
|
||||||
final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
|
|
||||||
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
final Canvas canvas = new Canvas(bitmap);
|
|
||||||
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
|
||||||
drawable.draw(canvas);
|
|
||||||
|
|
||||||
return IconCompat.createWithBitmap(bitmap);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
Log.e(TAG, "Package is not found. Unable to get package icon.");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,6 +93,7 @@ public class PanelFragment extends Fragment {
|
|||||||
private String mPanelClosedKey;
|
private String mPanelClosedKey;
|
||||||
private LinearLayout mPanelHeader;
|
private LinearLayout mPanelHeader;
|
||||||
private ImageView mTitleIcon;
|
private ImageView mTitleIcon;
|
||||||
|
private LinearLayout mTitleGroup;
|
||||||
private TextView mHeaderTitle;
|
private TextView mHeaderTitle;
|
||||||
private TextView mHeaderSubtitle;
|
private TextView mHeaderSubtitle;
|
||||||
private int mMaxHeight;
|
private int mMaxHeight;
|
||||||
@@ -191,6 +192,7 @@ public class PanelFragment extends Fragment {
|
|||||||
mTitleView = mLayoutView.findViewById(R.id.panel_title);
|
mTitleView = mLayoutView.findViewById(R.id.panel_title);
|
||||||
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
|
mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
|
||||||
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
|
mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
|
||||||
|
mTitleGroup = mLayoutView.findViewById(R.id.title_group);
|
||||||
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
|
||||||
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
|
||||||
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
|
mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
|
||||||
@@ -228,26 +230,13 @@ public class PanelFragment extends Fragment {
|
|||||||
|
|
||||||
final IconCompat icon = mPanel.getIcon();
|
final IconCompat icon = mPanel.getIcon();
|
||||||
final CharSequence title = mPanel.getTitle();
|
final CharSequence title = mPanel.getTitle();
|
||||||
if (icon == null) {
|
|
||||||
|
if (icon != null || mPanel.getViewType() == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
||||||
|
enablePanelHeader(icon, title);
|
||||||
|
} else {
|
||||||
mTitleView.setVisibility(View.VISIBLE);
|
mTitleView.setVisibility(View.VISIBLE);
|
||||||
mPanelHeader.setVisibility(View.GONE);
|
mPanelHeader.setVisibility(View.GONE);
|
||||||
mTitleView.setText(title);
|
mTitleView.setText(title);
|
||||||
} else {
|
|
||||||
mTitleView.setVisibility(View.GONE);
|
|
||||||
mPanelHeader.setVisibility(View.VISIBLE);
|
|
||||||
mPanelHeader.setAccessibilityPaneTitle(title);
|
|
||||||
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
|
||||||
mHeaderTitle.setText(title);
|
|
||||||
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
|
||||||
if (mPanel.getHeaderIconIntent() != null) {
|
|
||||||
mTitleIcon.setOnClickListener(getHeaderIconListener());
|
|
||||||
mTitleIcon.setLayoutParams(new LinearLayout.LayoutParams(
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
||||||
} else {
|
|
||||||
final int size = getResources().getDimensionPixelSize(
|
|
||||||
R.dimen.output_switcher_panel_icon_size);
|
|
||||||
mTitleIcon.setLayoutParams(new LinearLayout.LayoutParams(size, size));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPanel.getViewType() == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
if (mPanel.getViewType() == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
||||||
@@ -281,6 +270,29 @@ public class PanelFragment extends Fragment {
|
|||||||
0 /* value */);
|
0 /* value */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enablePanelHeader(IconCompat icon, CharSequence title) {
|
||||||
|
mTitleView.setVisibility(View.GONE);
|
||||||
|
mPanelHeader.setVisibility(View.VISIBLE);
|
||||||
|
mPanelHeader.setAccessibilityPaneTitle(title);
|
||||||
|
mHeaderTitle.setText(title);
|
||||||
|
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
||||||
|
if (icon != null) {
|
||||||
|
mTitleGroup.setVisibility(View.VISIBLE);
|
||||||
|
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
||||||
|
if (mPanel.getHeaderIconIntent() != null) {
|
||||||
|
mTitleIcon.setOnClickListener(getHeaderIconListener());
|
||||||
|
mTitleIcon.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
|
} else {
|
||||||
|
final int size = getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.output_switcher_panel_icon_size);
|
||||||
|
mTitleIcon.setLayoutParams(new LinearLayout.LayoutParams(size, size));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mTitleGroup.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadAllSlices() {
|
private void loadAllSlices() {
|
||||||
mSliceLiveData.clear();
|
mSliceLiveData.clear();
|
||||||
final List<Uri> sliceUris = mPanel.getSlices();
|
final List<Uri> sliceUris = mPanel.getSlices();
|
||||||
@@ -477,7 +489,13 @@ public class PanelFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onHeaderChanged() {
|
public void onHeaderChanged() {
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
mTitleIcon.setImageIcon(mPanel.getIcon().toIcon(getContext()));
|
final IconCompat icon = mPanel.getIcon();
|
||||||
|
if (icon != null) {
|
||||||
|
mTitleIcon.setImageIcon(icon.toIcon(getContext()));
|
||||||
|
mTitleGroup.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mTitleGroup.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
mHeaderTitle.setText(mPanel.getTitle());
|
mHeaderTitle.setText(mPanel.getTitle());
|
||||||
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
mHeaderSubtitle.setText(mPanel.getSubTitle());
|
||||||
});
|
});
|
||||||
|
@@ -318,4 +318,20 @@ public class MediaOutputPanelTest {
|
|||||||
public void getViewType_checkType() {
|
public void getViewType_checkType() {
|
||||||
assertThat(mPanel.getViewType()).isEqualTo(PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
assertThat(mPanel.getViewType()).isEqualTo(PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getIcon_mediaControllerIsNull_returnNull() {
|
||||||
|
mMediaControllers.clear();
|
||||||
|
mPanel.onStart();
|
||||||
|
|
||||||
|
assertThat(mPanel.getIcon()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getIcon_mediaMetadataIsNull_returnNull() {
|
||||||
|
mPanel.onStart();
|
||||||
|
when(mMediaController.getMetadata()).thenReturn(null);
|
||||||
|
|
||||||
|
assertThat(mPanel.getIcon()).isNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user