Loading src/com/android/settings/media/MediaOutputSlice.java +18 −7 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ package com.android.settings.media; import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI; import android.annotation.ColorInt; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -82,10 +82,9 @@ public class MediaOutputSlice implements CustomSliceable { } final List<MediaDevice> devices = getMediaDevices(); @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext); final MediaDevice connectedDevice = getWorker().getCurrentConnectedMediaDevice(); final ListBuilder listBuilder = buildActiveDeviceHeader(color, connectedDevice); final ListBuilder listBuilder = buildActiveDeviceHeader(connectedDevice); for (MediaDevice device : devices) { if (!TextUtils.equals(connectedDevice.getId(), device.getId())) { Loading @@ -96,9 +95,9 @@ public class MediaOutputSlice implements CustomSliceable { return listBuilder.build(); } private ListBuilder buildActiveDeviceHeader(@ColorInt int color, MediaDevice device) { private ListBuilder buildActiveDeviceHeader(MediaDevice device) { final String title = device.getName(); final IconCompat icon = IconCompat.createWithResource(mContext, device.getIcon()); final IconCompat icon = getDeviceIconCompat(device); final PendingIntent broadcastAction = getBroadcastIntent(mContext, device.getId(), device.hashCode()); Loading @@ -107,7 +106,7 @@ public class MediaOutputSlice implements CustomSliceable { final ListBuilder listBuilder = new ListBuilder(mContext, MEDIA_OUTPUT_SLICE_URI, ListBuilder.INFINITY) .setAccentColor(color) .setAccentColor(COLOR_NOT_TINTED) .addRow(new ListBuilder.RowBuilder() .setTitleItem(icon, ListBuilder.ICON_IMAGE) .setTitle(title) Loading @@ -117,6 +116,17 @@ public class MediaOutputSlice implements CustomSliceable { return listBuilder; } private IconCompat getDeviceIconCompat(MediaDevice device) { Drawable drawable = device.getIcon(); if (drawable == null) { Log.d(TAG, "getDeviceIconCompat() device : " + device.getName() + ", drawable is null"); // Use default Bluetooth device icon to handle getIcon() is null case. drawable = mContext.getDrawable(com.android.internal.R.drawable.ic_bt_headphones_a2dp); } return Utils.createIconWithDrawable(drawable); } private MediaDeviceUpdateWorker getWorker() { if (mWorker == null) { mWorker = (MediaDeviceUpdateWorker) SliceBackgroundWorker.getInstance(getUri()); Loading @@ -136,7 +146,8 @@ public class MediaOutputSlice implements CustomSliceable { final String title = device.getName(); final PendingIntent broadcastAction = getBroadcastIntent(mContext, device.getId(), device.hashCode()); final IconCompat deviceIcon = IconCompat.createWithResource(mContext, device.getIcon()); final IconCompat deviceIcon = getDeviceIconCompat(device); final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder() .setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE) .setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon, Loading tests/robotests/src/com/android/settings/media/MediaOutputSliceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import androidx.slice.Slice; import androidx.slice.SliceMetadata; Loading Loading @@ -66,6 +67,8 @@ public class MediaOutputSliceTest { @Mock private LocalMediaManager mLocalMediaManager; @Mock private Drawable mTestDrawable; private final List<MediaDevice> mDevices = new ArrayList<>(); Loading Loading @@ -105,7 +108,7 @@ public class MediaOutputSliceTest { mDevices.clear(); final MediaDevice device = mock(MediaDevice.class); when(device.getName()).thenReturn(TEST_DEVICE_1_NAME); when(device.getIcon()).thenReturn(TEST_DEVICE_1_ICON); when(device.getIcon()).thenReturn(mTestDrawable); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device); final Slice mediaSlice = mMediaOutputSlice.getSlice(); Loading Loading
src/com/android/settings/media/MediaOutputSlice.java +18 −7 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ package com.android.settings.media; import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI; import android.annotation.ColorInt; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -82,10 +82,9 @@ public class MediaOutputSlice implements CustomSliceable { } final List<MediaDevice> devices = getMediaDevices(); @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext); final MediaDevice connectedDevice = getWorker().getCurrentConnectedMediaDevice(); final ListBuilder listBuilder = buildActiveDeviceHeader(color, connectedDevice); final ListBuilder listBuilder = buildActiveDeviceHeader(connectedDevice); for (MediaDevice device : devices) { if (!TextUtils.equals(connectedDevice.getId(), device.getId())) { Loading @@ -96,9 +95,9 @@ public class MediaOutputSlice implements CustomSliceable { return listBuilder.build(); } private ListBuilder buildActiveDeviceHeader(@ColorInt int color, MediaDevice device) { private ListBuilder buildActiveDeviceHeader(MediaDevice device) { final String title = device.getName(); final IconCompat icon = IconCompat.createWithResource(mContext, device.getIcon()); final IconCompat icon = getDeviceIconCompat(device); final PendingIntent broadcastAction = getBroadcastIntent(mContext, device.getId(), device.hashCode()); Loading @@ -107,7 +106,7 @@ public class MediaOutputSlice implements CustomSliceable { final ListBuilder listBuilder = new ListBuilder(mContext, MEDIA_OUTPUT_SLICE_URI, ListBuilder.INFINITY) .setAccentColor(color) .setAccentColor(COLOR_NOT_TINTED) .addRow(new ListBuilder.RowBuilder() .setTitleItem(icon, ListBuilder.ICON_IMAGE) .setTitle(title) Loading @@ -117,6 +116,17 @@ public class MediaOutputSlice implements CustomSliceable { return listBuilder; } private IconCompat getDeviceIconCompat(MediaDevice device) { Drawable drawable = device.getIcon(); if (drawable == null) { Log.d(TAG, "getDeviceIconCompat() device : " + device.getName() + ", drawable is null"); // Use default Bluetooth device icon to handle getIcon() is null case. drawable = mContext.getDrawable(com.android.internal.R.drawable.ic_bt_headphones_a2dp); } return Utils.createIconWithDrawable(drawable); } private MediaDeviceUpdateWorker getWorker() { if (mWorker == null) { mWorker = (MediaDeviceUpdateWorker) SliceBackgroundWorker.getInstance(getUri()); Loading @@ -136,7 +146,8 @@ public class MediaOutputSlice implements CustomSliceable { final String title = device.getName(); final PendingIntent broadcastAction = getBroadcastIntent(mContext, device.getId(), device.hashCode()); final IconCompat deviceIcon = IconCompat.createWithResource(mContext, device.getIcon()); final IconCompat deviceIcon = getDeviceIconCompat(device); final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder() .setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE) .setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon, Loading
tests/robotests/src/com/android/settings/media/MediaOutputSliceTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import androidx.slice.Slice; import androidx.slice.SliceMetadata; Loading Loading @@ -66,6 +67,8 @@ public class MediaOutputSliceTest { @Mock private LocalMediaManager mLocalMediaManager; @Mock private Drawable mTestDrawable; private final List<MediaDevice> mDevices = new ArrayList<>(); Loading Loading @@ -105,7 +108,7 @@ public class MediaOutputSliceTest { mDevices.clear(); final MediaDevice device = mock(MediaDevice.class); when(device.getName()).thenReturn(TEST_DEVICE_1_NAME); when(device.getIcon()).thenReturn(TEST_DEVICE_1_ICON); when(device.getIcon()).thenReturn(mTestDrawable); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device); final Slice mediaSlice = mMediaOutputSlice.getSlice(); Loading