From db0aa6541ad47011d71dfd6aef4aa1825dda678c Mon Sep 17 00:00:00 2001 From: Hugh Chen Date: Mon, 7 Sep 2020 17:24:54 +0800 Subject: [PATCH] Hide the icon if there is no media session or album art. - Before this CL, the output switch panel will show a default icon if there is no media session or album art. This CL will hide the icon if there is no media session or album art. - Add test case Bug: 161495909 Test: make -j42 RunSettingsRoboTests Change-Id: I5f80158b12f89c8499fb97d0b203ebeffefbc18b Merged-In: I5f80158b12f89c8499fb97d0b203ebeffefbc18b (cherry picked from commit 30805af9defa1041ba90add3f00584b92dd9ef0e) --- res/layout/panel_layout.xml | 1 + .../settings/panel/MediaOutputPanel.java | 26 +-------- .../android/settings/panel/PanelFragment.java | 54 ++++++++++++------- .../settings/panel/MediaOutputPanelTest.java | 16 ++++++ 4 files changed, 54 insertions(+), 43 deletions(-) diff --git a/res/layout/panel_layout.xml b/res/layout/panel_layout.xml index 895d09b89ad..5f33c32eb08 100644 --- a/res/layout/panel_layout.xml +++ b/res/layout/panel_layout.xml @@ -36,6 +36,7 @@ android:visibility="gone"> sliceUris = mPanel.getSlices(); @@ -471,7 +483,13 @@ public class PanelFragment extends Fragment { @Override public void onHeaderChanged() { 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()); mHeaderSubtitle.setText(mPanel.getSubTitle()); }); diff --git a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java index 2ab428d9b75..207a64428c1 100644 --- a/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java +++ b/tests/robotests/src/com/android/settings/panel/MediaOutputPanelTest.java @@ -317,4 +317,20 @@ public class MediaOutputPanelTest { public void getViewType_checkType() { 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(); + } }