diff options
| author | 2022-07-12 19:08:35 +0800 | |
|---|---|---|
| committer | 2022-07-13 21:15:12 +0800 | |
| commit | 623ed192e869d5812c5731ab828639f6d39de8f2 (patch) | |
| tree | 554e08058759dfb3c2c09ccb3c7eda50d8ee88a7 | |
| parent | cf3b16d69b5f769a2bb45cc860ddbce79cdef9d0 (diff) | |
[LeAudio Broadcast] Shows the broadcast icon on output switcher
When the devcie is broadcasting, the output switcher UI shows the
broadcast icon in the top right corner.
Figma: https://www.figma.com/file/3Kf9EnVdbvQKP5Q1CUviTY/LE-Audio?node-id=0%3A1
Screenshot1: show broadcasting icon
https://hsv.googleplex.com/4875202925166592?node=10
Screenshot2: hide broadcasting icon
https://hsv.googleplex.com/6429825930625024?node=7
Bug: 215469904
Test:
[pass] atest MediaOutputDialogTest
[pass] atest MediaOutputBaseDialogTest
Change-Id: I764f2b0de0d2e008a05b95135507f51ede0b2131
5 files changed, 120 insertions, 5 deletions
diff --git a/packages/SystemUI/res/layout/media_output_dialog.xml b/packages/SystemUI/res/layout/media_output_dialog.xml index 1efb4796b5b7..52140f42eb08 100644 --- a/packages/SystemUI/res/layout/media_output_dialog.xml +++ b/packages/SystemUI/res/layout/media_output_dialog.xml @@ -42,12 +42,35 @@ android:layout_height="wrap_content" android:paddingStart="12dp" android:orientation="vertical"> - <ImageView - android:id="@+id/app_source_icon" - android:layout_width="20dp" - android:layout_height="20dp" + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" android:gravity="center_vertical" - android:importantForAccessibility="no"/> + android:orientation="horizontal"> + <ImageView + android:id="@+id/app_source_icon" + android:layout_width="20dp" + android:layout_height="20dp" + android:gravity="center_vertical" + android:importantForAccessibility="no"/> + + <Space + android:layout_weight="1" + android:layout_width="0dp" + android:layout_height="match_parent"/> + + <ImageView + android:id="@+id/broadcast_icon" + android:src="@drawable/settings_input_antenna" + android:contentDescription="@string/broadcasting_description_is_broadcasting" + android:layout_width="48dp" + android:layout_height="48dp" + android:padding="12dp" + android:gravity="center_vertical" + android:clickable="true" + android:focusable="true" + android:visibility="gone"/> + </LinearLayout> <TextView android:id="@+id/header_title" android:layout_width="wrap_content" diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java index e5913061ef3f..0d5cab688d72 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java @@ -91,6 +91,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements private TextView mHeaderSubtitle; private ImageView mHeaderIcon; private ImageView mAppResourceIcon; + private ImageView mBroadcastIcon; private RecyclerView mDevicesRecyclerView; private LinearLayout mDeviceListLayout; private LinearLayout mCastAppLayout; @@ -239,6 +240,7 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements mAppButton = mDialogView.requireViewById(R.id.launch_app_button); mAppResourceIcon = mDialogView.requireViewById(R.id.app_source_icon); mCastAppLayout = mDialogView.requireViewById(R.id.cast_app_section); + mBroadcastIcon = mDialogView.requireViewById(R.id.broadcast_icon); mDeviceListLayout.getViewTreeObserver().addOnGlobalLayoutListener( mDeviceListLayoutListener); @@ -366,6 +368,9 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements mStopButton.setEnabled(true); mStopButton.setText(getStopButtonText()); mStopButton.setOnClickListener(v -> onStopButtonClick()); + + mBroadcastIcon.setVisibility(getBroadcastIconVisibility()); + mBroadcastIcon.setOnClickListener(v -> onBroadcastIconClick()); } private void updateButtonBackgroundColorFilter() { @@ -490,6 +495,14 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog implements dismiss(); } + public int getBroadcastIconVisibility() { + return View.GONE; + } + + public void onBroadcastIconClick() { + // Do nothing. + } + public boolean isBroadcastSupported() { return false; } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java index a6cf408e0099..afa1dd351787 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java @@ -134,6 +134,17 @@ public class MediaOutputDialog extends MediaOutputBaseDialog { } } + @Override + public int getBroadcastIconVisibility() { + return (isBroadcastSupported() && mMediaOutputController.isBluetoothLeBroadcastEnabled()) + ? View.VISIBLE : View.GONE; + } + + @Override + public void onBroadcastIconClick() { + startLeBroadcastDialog(); + } + @VisibleForTesting public enum MediaOutputEvent implements UiEventLogger.UiEventEnum { @UiEvent(doc = "The MediaOutput dialog became visible on the screen.") diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java index 9eaa20c2afed..d414660018a8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBaseDialogTest.java @@ -43,6 +43,8 @@ import android.widget.TextView; import androidx.core.graphics.drawable.IconCompat; import androidx.test.filters.SmallTest; +import com.android.settingslib.bluetooth.CachedBluetoothDevice; +import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; @@ -98,10 +100,17 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { private CharSequence mHeaderSubtitle; private String mStopText; private boolean mIsBroadcasting; + private boolean mIsBroadcastIconVisibility; + @Before public void setUp() { when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager); + final CachedBluetoothDeviceManager cachedBluetoothDeviceManager = mock( + CachedBluetoothDeviceManager.class); + when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn( + cachedBluetoothDeviceManager); + when(cachedBluetoothDeviceManager.findDevice(any())).thenReturn(null); when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn(null); when(mMediaController.getPlaybackState()).thenReturn(mPlaybackState); when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_NONE); @@ -153,6 +162,27 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { } @Test + public void refresh_broadcastIconVisibilityOff_broadcastIconLayoutNotVisible() { + mIsBroadcastIconVisibility = false; + + mMediaOutputBaseDialogImpl.refresh(); + final ImageView view = mMediaOutputBaseDialogImpl.mDialogView.requireViewById( + R.id.broadcast_icon); + + assertThat(view.getVisibility()).isEqualTo(View.GONE); + } + @Test + public void refresh_broadcastIconVisibilityOn_broadcastIconLayoutVisible() { + mIsBroadcastIconVisibility = true; + + mMediaOutputBaseDialogImpl.refresh(); + final ImageView view = mMediaOutputBaseDialogImpl.mDialogView.requireViewById( + R.id.broadcast_icon); + + assertThat(view.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test public void refresh_checkTitle() { mHeaderTitle = "test_string"; @@ -308,5 +338,10 @@ public class MediaOutputBaseDialogTest extends SysuiTestCase { public CharSequence getStopButtonText() { return mStopText; } + + @Override + public int getBroadcastIconVisibility() { + return mIsBroadcastIconVisibility ? View.VISIBLE : View.GONE; + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java index c45db05bacee..6afed1a846b0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputDialogTest.java @@ -172,6 +172,39 @@ public class MediaOutputDialogTest extends SysuiTestCase { } @Test + public void getBroadcastIconVisibility_isBroadcasting_returnVisible() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(true); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(true); + + assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void getBroadcastIconVisibility_noBroadcasting_returnGone() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(true); + + assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.GONE); + } + + @Test + public void getBroadcastIconVisibility_remoteNonLeDevice_returnGone() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothLeBroadcast.isEnabled(any())).thenReturn(false); + when(mPlaybackState.getState()).thenReturn(PlaybackState.STATE_PLAYING); + when(mMediaDevice.isBLEDevice()).thenReturn(false); + + assertThat(mMediaOutputDialog.getBroadcastIconVisibility()).isEqualTo(View.GONE); + } + + @Test // Check the visibility metric logging by creating a new MediaOutput dialog, // and verify if the calling times increases. public void onCreate_ShouldLogVisibility() { |