diff options
12 files changed, 271 insertions, 136 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacyTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacyTest.java index 8dff20eeb80a..9c4d93c17d00 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacyTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacyTest.java @@ -48,10 +48,12 @@ import androidx.test.filters.SmallTest; import com.android.media.flags.Flags; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; +import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.SysuiTestCase; import com.android.systemui.res.R; import com.google.common.collect.ImmutableList; +import com.google.common.util.concurrent.ListeningExecutorService; import org.junit.Before; import org.junit.Test; @@ -61,6 +63,7 @@ import org.mockito.Captor; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; import java.util.stream.Collectors; @SmallTest @@ -95,6 +98,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { private List<MediaDevice> mMediaDevices = new ArrayList<>(); private List<MediaItem> mMediaItems = new ArrayList<>(); MediaOutputSeekbar mSpyMediaOutputSeekbar; + Executor mMainExecutor = mContext.getMainExecutor(); + ListeningExecutorService mBackgroundExecutor = ThreadUtils.getBackgroundExecutor(); @Before public void setUp() { @@ -108,6 +113,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { when(mMediaSwitchingController.getSessionVolumeMax()).thenReturn(TEST_MAX_VOLUME); when(mMediaSwitchingController.getSessionVolume()).thenReturn(TEST_CURRENT_VOLUME); when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME); + when(mMediaSwitchingController.getColorSchemeLegacy()).thenReturn( + mock(MediaOutputColorSchemeLegacy.class)); when(mIconCompat.toIcon(mContext)).thenReturn(mIcon); when(mMediaDevice1.getName()).thenReturn(TEST_DEVICE_NAME_1); when(mMediaDevice1.getId()).thenReturn(TEST_DEVICE_ID_1); @@ -122,7 +129,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { mMediaItems.add(MediaItem.createDeviceMediaItem(mMediaDevice1, true)); mMediaItems.add(MediaItem.createDeviceMediaItem(mMediaDevice2, false)); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -148,7 +156,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { @Test public void onBindViewHolder_bindPairNew_verifyView() { - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -173,7 +182,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { .map((item) -> item.getMediaDevice().get()) .collect(Collectors.toList())); when(mMediaSwitchingController.getSessionName()).thenReturn(TEST_SESSION_NAME); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -195,7 +205,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { .map((item) -> item.getMediaDevice().get()) .collect(Collectors.toList())); when(mMediaSwitchingController.getSessionName()).thenReturn(null); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -665,7 +676,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { @Test public void onItemClick_clickPairNew_verifyLaunchBluetoothPairing() { - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -683,7 +695,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { assertThat(mMediaDevice2.getState()).isEqualTo( LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED); when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_TRANSFER); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -701,7 +714,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { assertThat(mMediaDevice2.getState()).isEqualTo( LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED); when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_TRANSFER); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, + mContext.getMainExecutor(), ThreadUtils.getBackgroundExecutor()); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); @@ -723,7 +737,8 @@ public class MediaOutputAdapterLegacyTest extends SysuiTestCase { when(mMediaDevice2.getState()).thenReturn( LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED); when(mMediaDevice2.getSelectionBehavior()).thenReturn(SELECTION_BEHAVIOR_GO_TO_APP); - mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mMediaOutputAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mMainExecutor, + mBackgroundExecutor); mMediaOutputAdapter.updateItems(); mViewHolder = (MediaOutputAdapterLegacy.MediaDeviceViewHolderLegacy) mMediaOutputAdapter .onCreateViewHolder(new LinearLayout(mContext), 0); diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterBase.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterBase.java index c58ba377fb68..ac1672db9375 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterBase.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterBase.java @@ -351,8 +351,9 @@ public abstract class MediaOutputAdapterBase extends RecyclerView.Adapter<Recycl @VisibleForTesting void showCustomEndSessionDialog(MediaDevice device) { MediaSessionReleaseDialog mediaSessionReleaseDialog = new MediaSessionReleaseDialog( - mContext, () -> transferOutput(device), mController.getColorButtonBackground(), - mController.getColorItemContent()); + mContext, () -> transferOutput(device), + mController.getColorSchemeLegacy().getColorButtonBackground(), + mController.getColorSchemeLegacy().getColorItemContent()); mediaSessionReleaseDialog.show(); } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacy.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacy.java index 290f62f595b1..795e811db2bc 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacy.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputAdapterLegacy.java @@ -50,9 +50,11 @@ import androidx.recyclerview.widget.RecyclerView; import com.android.media.flags.Flags; import com.android.settingslib.media.InputMediaDevice; import com.android.settingslib.media.MediaDevice; -import com.android.settingslib.utils.ThreadUtils; +import com.android.systemui.dagger.qualifiers.Background; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.res.R; +import java.util.concurrent.Executor; /** * A RecyclerView adapter for the legacy UI media output dialog device list. */ @@ -63,11 +65,19 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { private static final int UNMUTE_DEFAULT_VOLUME = 2; @VisibleForTesting static final float DEVICE_DISABLED_ALPHA = 0.5f; @VisibleForTesting static final float DEVICE_ACTIVE_ALPHA = 1f; + private final Executor mMainExecutor; + private final Executor mBackgroundExecutor; View mHolderView; private boolean mIsInitVolumeFirstTime; - public MediaOutputAdapterLegacy(MediaSwitchingController controller) { + public MediaOutputAdapterLegacy( + MediaSwitchingController controller, + @Main Executor mainExecutor, + @Background Executor backgroundExecutor + ) { super(controller); + mMainExecutor = mainExecutor; + mBackgroundExecutor = backgroundExecutor; mIsInitVolumeFirstTime = true; } @@ -181,9 +191,9 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { mEndTouchArea.setVisibility(View.GONE); mEndClickIcon.setVisibility(View.GONE); mContainerLayout.setOnClickListener(null); - mTitleText.setTextColor(mController.getColorItemContent()); - mSubTitleText.setTextColor(mController.getColorItemContent()); - mVolumeValueText.setTextColor(mController.getColorItemContent()); + mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent()); + mSubTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent()); + mVolumeValueText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent()); mIconAreaLayout.setBackground(null); updateIconAreaClickListener(null); updateSeekBarProgressColor(); @@ -193,14 +203,14 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { /** Binds a ViewHolder for a "Connect a device" item. */ void onBindPairNewDevice() { - mTitleText.setTextColor(mController.getColorItemContent()); + mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent()); mCheckBox.setVisibility(View.GONE); updateTitle(mContext.getText(R.string.media_output_dialog_pairing_new)); updateItemBackground(ConnectionState.DISCONNECTED); final Drawable addDrawable = mContext.getDrawable(R.drawable.ic_add); mTitleIcon.setImageDrawable(addDrawable); - mTitleIcon.setImageTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + mTitleIcon.setImageTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); mContainerLayout.setOnClickListener(mController::launchBluetoothPairing); } @@ -297,8 +307,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { protected void updateLoadingIndicator(ConnectionState connectionState) { if (connectionState == ConnectionState.CONNECTING) { mProgressBar.setVisibility(View.VISIBLE); - mProgressBar.getIndeterminateDrawable().setTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + mProgressBar.getIndeterminateDrawable().setTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); } else { mProgressBar.setVisibility(View.GONE); } @@ -318,8 +328,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { // Connected or connecting state has a darker background. int backgroundColor = isConnected || isConnecting - ? mController.getColorConnectedItemBackground() - : mController.getColorItemBackground(); + ? mController.getColorSchemeLegacy().getColorConnectedItemBackground() + : mController.getColorSchemeLegacy().getColorItemBackground(); mItemLayout.setBackgroundTintList(ColorStateList.valueOf(backgroundColor)); } @@ -332,13 +342,13 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { } private void updateSeekBarProgressColor() { - mSeekBar.setProgressTintList( - ColorStateList.valueOf(mController.getColorSeekbarProgress())); + mSeekBar.setProgressTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorSeekbarProgress())); final Drawable contrastDotDrawable = ((LayerDrawable) mSeekBar.getProgressDrawable()).findDrawableByLayerId( R.id.contrast_dot); - contrastDotDrawable.setTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + contrastDotDrawable.setTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); } void updateSeekbarProgressBackground() { @@ -503,9 +513,10 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { boolean isInputMediaDevice = device instanceof InputMediaDevice; int id = getDrawableId(isInputMediaDevice, isMutedVolumeIcon); mTitleIcon.setImageDrawable(mContext.getDrawable(id)); - mTitleIcon.setImageTintList(ColorStateList.valueOf(mController.getColorItemContent())); - mIconAreaLayout.setBackgroundTintList( - ColorStateList.valueOf(mController.getColorSeekbarProgress())); + mTitleIcon.setImageTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); + mIconAreaLayout.setBackgroundTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorSeekbarProgress())); } @VisibleForTesting @@ -534,8 +545,8 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { mStatusIcon.setVisibility(View.GONE); } else { mStatusIcon.setImageDrawable(deviceStatusIcon); - mStatusIcon.setImageTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + mStatusIcon.setImageTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); if (deviceStatusIcon instanceof AnimatedVectorDrawable) { ((AnimatedVectorDrawable) deviceStatusIcon).start(); } @@ -585,9 +596,10 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { private void updateEndAreaWithIcon(View.OnClickListener clickListener, @DrawableRes int iconDrawableId, @StringRes int accessibilityStringId) { - updateEndAreaColor(mController.getColorSeekbarProgress()); + updateEndAreaColor(mController.getColorSchemeLegacy().getColorSeekbarProgress()); mEndClickIcon.setImageTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); mEndClickIcon.setOnClickListener(clickListener); Drawable drawable = mContext.getDrawable(iconDrawableId); mEndClickIcon.setImageDrawable(drawable); @@ -600,8 +612,9 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { private void updateEndAreaForGroupCheckBox(@NonNull MediaDevice device, @NonNull GroupStatus groupStatus) { boolean isEnabled = isGroupCheckboxEnabled(groupStatus); - updateEndAreaColor(groupStatus.selected() ? mController.getColorSeekbarProgress() - : mController.getColorItemBackground()); + updateEndAreaColor(groupStatus.selected() + ? mController.getColorSchemeLegacy().getColorSeekbarProgress() + : mController.getColorSchemeLegacy().getColorItemBackground()); mCheckBox.setContentDescription(mContext.getString( groupStatus.selected() ? R.string.accessibility_remove_device_from_group : R.string.accessibility_add_device_to_group)); @@ -611,7 +624,7 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { isEnabled ? (buttonView, isChecked) -> onGroupActionTriggered( !groupStatus.selected(), device) : null); mCheckBox.setEnabled(isEnabled); - setCheckBoxColor(mCheckBox, mController.getColorItemContent()); + setCheckBoxColor(mCheckBox, mController.getColorSchemeLegacy().getColorItemContent()); } private void setCheckBoxColor(CheckBox checkBox, int color) { @@ -714,15 +727,15 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { } protected void setUpDeviceIcon(@NonNull MediaDevice device) { - ThreadUtils.postOnBackgroundThread(() -> { + mBackgroundExecutor.execute(() -> { Icon icon = mController.getDeviceIconCompat(device).toIcon(mContext); - ThreadUtils.postOnMainThread(() -> { + mMainExecutor.execute(() -> { if (!TextUtils.equals(mDeviceId, device.getId())) { return; } mTitleIcon.setImageIcon(icon); - mTitleIcon.setImageTintList( - ColorStateList.valueOf(mController.getColorItemContent())); + mTitleIcon.setImageTintList(ColorStateList.valueOf( + mController.getColorSchemeLegacy().getColorItemContent())); }); }); } @@ -807,7 +820,7 @@ public class MediaOutputAdapterLegacy extends MediaOutputAdapterBase { } void onBind(String groupDividerTitle) { - mTitleText.setTextColor(mController.getColorItemContent()); + mTitleText.setTextColor(mController.getColorSchemeLegacy().getColorItemContent()); mTitleText.setText(groupDividerTitle); } } 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 d791361d555f..e04a22b22f1a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBaseDialog.java @@ -342,7 +342,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog WallpaperColors wallpaperColors = WallpaperColors.fromBitmap(icon.getBitmap()); colorSetUpdated = !wallpaperColors.equals(mWallpaperColors); if (colorSetUpdated) { - mMediaSwitchingController.setCurrentColorScheme(wallpaperColors, isDarkThemeOn); + mMediaSwitchingController.updateCurrentColorScheme(wallpaperColors, + isDarkThemeOn); updateButtonBackgroundColorFilter(); updateDialogBackgroundColor(); } @@ -359,7 +360,8 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog mAppResourceIcon.setVisibility(View.GONE); } else if (appSourceIcon != null) { Icon appIcon = appSourceIcon.toIcon(mContext); - mAppResourceIcon.setColorFilter(mMediaSwitchingController.getColorItemContent()); + mAppResourceIcon.setColorFilter( + mMediaSwitchingController.getColorSchemeLegacy().getColorItemContent()); mAppResourceIcon.setImageIcon(appIcon); } else { Drawable appIconDrawable = mMediaSwitchingController.getAppSourceIconFromPackage(); @@ -419,18 +421,19 @@ public abstract class MediaOutputBaseDialog extends SystemUIDialog private void updateButtonBackgroundColorFilter() { ColorFilter buttonColorFilter = new PorterDuffColorFilter( - mMediaSwitchingController.getColorButtonBackground(), + mMediaSwitchingController.getColorSchemeLegacy().getColorButtonBackground(), PorterDuff.Mode.SRC_IN); mDoneButton.getBackground().setColorFilter(buttonColorFilter); mStopButton.getBackground().setColorFilter(buttonColorFilter); - mDoneButton.setTextColor(mMediaSwitchingController.getColorPositiveButtonText()); + mDoneButton.setTextColor( + mMediaSwitchingController.getColorSchemeLegacy().getColorPositiveButtonText()); } private void updateDialogBackgroundColor() { - getDialogView() - .getBackground() - .setTint(mMediaSwitchingController.getColorDialogBackground()); - mDeviceListLayout.setBackgroundColor(mMediaSwitchingController.getColorDialogBackground()); + getDialogView().getBackground().setTint( + mMediaSwitchingController.getColorSchemeLegacy().getColorDialogBackground()); + mDeviceListLayout.setBackgroundColor( + mMediaSwitchingController.getColorSchemeLegacy().getColorDialogBackground()); } public void handleLeBroadcastStarted() { diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java index 9ade9e275ca1..1646d6df8c5c 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java @@ -52,6 +52,8 @@ import com.android.systemui.statusbar.phone.SystemUIDialog; import com.google.zxing.WriterException; +import java.util.concurrent.Executor; + /** * Dialog for media output broadcast. */ @@ -239,13 +241,16 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { Context context, boolean aboveStatusbar, BroadcastSender broadcastSender, - MediaSwitchingController mediaSwitchingController) { + MediaSwitchingController mediaSwitchingController, + Executor mainExecutor, + Executor backgroundExecutor) { super( context, broadcastSender, mediaSwitchingController, /* includePlaybackAndAppMetadata */ true); - mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mainExecutor, + backgroundExecutor); // TODO(b/226710953): Move the part to MediaOutputBaseDialog for every class // that extends MediaOutputBaseDialog if (!aboveStatusbar) { diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogManager.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogManager.kt index 2e7e66f5b384..81c85a6ad22d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogManager.kt @@ -20,6 +20,9 @@ import android.content.Context import android.view.View import com.android.systemui.animation.DialogTransitionAnimator import com.android.systemui.broadcast.BroadcastSender +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.Main +import java.util.concurrent.Executor import javax.inject.Inject /** Manager to create and show a [MediaOutputBroadcastDialog]. */ @@ -29,7 +32,9 @@ constructor( private val context: Context, private val broadcastSender: BroadcastSender, private val dialogTransitionAnimator: DialogTransitionAnimator, - private val mediaSwitchingControllerFactory: MediaSwitchingController.Factory + private val mediaSwitchingControllerFactory: MediaSwitchingController.Factory, + @Main private val mainExecutor: Executor, + @Background private val backgroundExecutor: Executor, ) { var mediaOutputBroadcastDialog: MediaOutputBroadcastDialog? = null @@ -47,7 +52,14 @@ constructor( /* token */ null, ) val dialog = - MediaOutputBroadcastDialog(context, aboveStatusBar, broadcastSender, controller) + MediaOutputBroadcastDialog( + context, + aboveStatusBar, + broadcastSender, + controller, + mainExecutor, + backgroundExecutor, + ) mediaOutputBroadcastDialog = dialog // Show the dialog. diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputColorSchemeLegacy.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputColorSchemeLegacy.kt new file mode 100644 index 000000000000..7f0fa463811b --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputColorSchemeLegacy.kt @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2025 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. + */ + +package com.android.systemui.media.dialog + +import android.content.Context +import com.android.settingslib.Utils +import com.android.systemui.monet.ColorScheme +import com.android.systemui.res.R + +abstract class MediaOutputColorSchemeLegacy { + companion object Factory { + @JvmStatic + fun fromSystemColors(context: Context): MediaOutputColorSchemeLegacy { + return MediaOutputColorSchemeLegacySystem(context) + } + + @JvmStatic + fun fromDynamicColors( + colorScheme: ColorScheme, + isDarkTheme: Boolean, + ): MediaOutputColorSchemeLegacy { + return MediaOutputColorSchemeLegacyDynamic(colorScheme, isDarkTheme) + } + } + + abstract fun getColorConnectedItemBackground(): Int + + abstract fun getColorPositiveButtonText(): Int + + abstract fun getColorDialogBackground(): Int + + abstract fun getColorItemContent(): Int + + abstract fun getColorSeekbarProgress(): Int + + abstract fun getColorButtonBackground(): Int + + abstract fun getColorItemBackground(): Int +} + +class MediaOutputColorSchemeLegacySystem(private val mContext: Context) : + MediaOutputColorSchemeLegacy() { + + override fun getColorConnectedItemBackground() = + Utils.getColorStateListDefaultColor( + mContext, + R.color.media_dialog_connected_item_background, + ) + + override fun getColorPositiveButtonText() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_solid_button_text) + + override fun getColorDialogBackground() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_background) + + override fun getColorItemContent() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_item_main_content) + + override fun getColorSeekbarProgress() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_seekbar_progress) + + override fun getColorButtonBackground() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_button_background) + + override fun getColorItemBackground() = + Utils.getColorStateListDefaultColor(mContext, R.color.media_dialog_item_background) +} + +class MediaOutputColorSchemeLegacyDynamic(colorScheme: ColorScheme, isDarkTheme: Boolean) : + MediaOutputColorSchemeLegacy() { + private var mColorItemContent: Int + private var mColorSeekbarProgress: Int + private var mColorButtonBackground: Int + private var mColorItemBackground: Int + private var mColorConnectedItemBackground: Int + private var mColorPositiveButtonText: Int + private var mColorDialogBackground: Int + + init { + if (isDarkTheme) { + mColorItemContent = colorScheme.accent1.s100 // A1-100 + mColorSeekbarProgress = colorScheme.accent2.s600 // A2-600 + mColorButtonBackground = colorScheme.accent1.s300 // A1-300 + mColorItemBackground = colorScheme.neutral2.s800 // N2-800 + mColorConnectedItemBackground = colorScheme.accent2.s800 // A2-800 + mColorPositiveButtonText = colorScheme.accent2.s800 // A2-800 + mColorDialogBackground = colorScheme.neutral1.s900 // N1-900 + } else { + mColorItemContent = colorScheme.accent1.s800 // A1-800 + mColorSeekbarProgress = colorScheme.accent1.s300 // A1-300 + mColorButtonBackground = colorScheme.accent1.s600 // A1-600 + mColorItemBackground = colorScheme.accent2.s50 // A2-50 + mColorConnectedItemBackground = colorScheme.accent1.s100 // A1-100 + mColorPositiveButtonText = colorScheme.neutral1.s50 // N1-50 + mColorDialogBackground = colorScheme.backgroundColor + } + } + + override fun getColorConnectedItemBackground() = mColorConnectedItemBackground + + override fun getColorPositiveButtonText() = mColorPositiveButtonText + + override fun getColorDialogBackground() = mColorDialogBackground + + override fun getColorItemContent() = mColorItemContent + + override fun getColorSeekbarProgress() = mColorSeekbarProgress + + override fun getColorButtonBackground() = mColorButtonBackground + + override fun getColorItemBackground() = mColorItemBackground +} 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 2e602be4556e..8351ea9d8bca 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialog.java @@ -34,6 +34,8 @@ import com.android.systemui.broadcast.BroadcastSender; import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.res.R; +import java.util.concurrent.Executor; + /** * Dialog for media output transferring. */ @@ -49,11 +51,14 @@ public class MediaOutputDialog extends MediaOutputBaseDialog { MediaSwitchingController mediaSwitchingController, DialogTransitionAnimator dialogTransitionAnimator, UiEventLogger uiEventLogger, + Executor mainExecutor, + Executor backgroundExecutor, boolean includePlaybackAndAppMetadata) { super(context, broadcastSender, mediaSwitchingController, includePlaybackAndAppMetadata); mDialogTransitionAnimator = dialogTransitionAnimator; mUiEventLogger = uiEventLogger; - mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController); + mAdapter = new MediaOutputAdapterLegacy(mMediaSwitchingController, mainExecutor, + backgroundExecutor); if (!aboveStatusbar) { getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogManager.kt b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogManager.kt index 4e9451a838ad..d3a81a53b6d3 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputDialogManager.kt @@ -25,6 +25,9 @@ import com.android.internal.logging.UiEventLogger import com.android.systemui.animation.DialogCuj import com.android.systemui.animation.DialogTransitionAnimator import com.android.systemui.broadcast.BroadcastSender +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.Main +import java.util.concurrent.Executor import javax.inject.Inject /** Manager to create and show a [MediaOutputDialog]. */ @@ -37,6 +40,9 @@ constructor( private val dialogTransitionAnimator: DialogTransitionAnimator, private val mediaSwitchingControllerFactory: MediaSwitchingController.Factory, ) { + @Inject @Main lateinit var mainExecutor: Executor + @Inject @Background lateinit var backgroundExecutor: Executor + companion object { const val INTERACTION_JANK_TAG = "media_output" var mediaOutputDialog: MediaOutputDialog? = null @@ -51,7 +57,7 @@ constructor( aboveStatusBar: Boolean, view: View? = null, userHandle: UserHandle? = null, - token: MediaSession.Token? = null + token: MediaSession.Token? = null, ) { createAndShowWithController( packageName, @@ -62,8 +68,8 @@ constructor( it, DialogCuj( InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, - INTERACTION_JANK_TAG - ) + INTERACTION_JANK_TAG, + ), ) }, userHandle = userHandle, @@ -128,15 +134,14 @@ constructor( controller, dialogTransitionAnimator, uiEventLogger, - includePlaybackAndAppMetadata + mainExecutor, + backgroundExecutor, + includePlaybackAndAppMetadata, ) // Show the dialog. if (dialogTransitionAnimatorController != null) { - dialogTransitionAnimator.show( - mediaOutputDialog, - dialogTransitionAnimatorController, - ) + dialogTransitionAnimator.show(mediaOutputDialog, dialogTransitionAnimatorController) } else { mediaOutputDialog.show() } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java index 02dce406bbee..9e6fa48d6f98 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaSwitchingController.java @@ -83,6 +83,8 @@ import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.animation.ActivityTransitionAnimator; import com.android.systemui.animation.DialogTransitionAnimator; import com.android.systemui.broadcast.BroadcastSender; +import com.android.systemui.dagger.qualifiers.Background; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.flags.FeatureFlags; import com.android.systemui.media.dialog.MediaItem.MediaItemType; import com.android.systemui.media.nearby.NearbyMediaDevicesManager; @@ -114,6 +116,8 @@ import java.util.concurrent.Executor; import java.util.function.Function; import java.util.stream.Collectors; +import javax.inject.Inject; + /** * Controller for a dialog that allows users to switch media output and input devices, control * volume, connect to new devices, etc. @@ -149,7 +153,8 @@ public class MediaSwitchingController private final NearbyMediaDevicesManager mNearbyMediaDevicesManager; private final Map<String, Integer> mNearbyDeviceInfoMap = new ConcurrentHashMap<>(); private final MediaSession.Token mToken; - + @Inject @Main Executor mMainExecutor; + @Inject @Background Executor mBackgroundExecutor; @VisibleForTesting boolean mIsRefreshing = false; @VisibleForTesting @@ -163,17 +168,10 @@ public class MediaSwitchingController @VisibleForTesting MediaOutputMetricLogger mMetricLogger; private int mCurrentState; - - private int mColorItemContent; - private int mColorSeekbarProgress; - private int mColorButtonBackground; - private int mColorItemBackground; - private int mColorConnectedItemBackground; - private int mColorPositiveButtonText; - private int mColorDialogBackground; private FeatureFlags mFeatureFlags; private UserTracker mUserTracker; private VolumePanelGlobalStateInteractor mVolumePanelGlobalStateInteractor; + @NonNull private MediaOutputColorSchemeLegacy mMediaOutputColorSchemeLegacy; public enum BroadcastNotifyDialog { ACTION_FIRST_LAUNCH, @@ -230,20 +228,7 @@ public class MediaSwitchingController mMetricLogger = new MediaOutputMetricLogger(mContext, mPackageName); mDialogTransitionAnimator = dialogTransitionAnimator; mNearbyMediaDevicesManager = nearbyMediaDevicesManager; - mColorItemContent = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_item_main_content); - mColorSeekbarProgress = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_seekbar_progress); - mColorButtonBackground = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_button_background); - mColorItemBackground = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_item_background); - mColorConnectedItemBackground = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_connected_item_background); - mColorPositiveButtonText = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_solid_button_text); - mColorDialogBackground = Utils.getColorStateListDefaultColor(mContext, - R.color.media_dialog_background); + mMediaOutputColorSchemeLegacy = MediaOutputColorSchemeLegacy.fromSystemColors(mContext); if (enableInputRouting()) { mInputRouteManager = new InputRouteManager(mContext, audioManager); @@ -568,26 +553,15 @@ public class MediaSwitchingController return null; } - void setCurrentColorScheme(WallpaperColors wallpaperColors, boolean isDarkTheme) { - ColorScheme mCurrentColorScheme = new ColorScheme(wallpaperColors, + void updateCurrentColorScheme(WallpaperColors wallpaperColors, boolean isDarkTheme) { + ColorScheme currentColorScheme = new ColorScheme(wallpaperColors, isDarkTheme); - if (isDarkTheme) { - mColorItemContent = mCurrentColorScheme.getAccent1().getS100(); // A1-100 - mColorSeekbarProgress = mCurrentColorScheme.getAccent2().getS600(); // A2-600 - mColorButtonBackground = mCurrentColorScheme.getAccent1().getS300(); // A1-300 - mColorItemBackground = mCurrentColorScheme.getNeutral2().getS800(); // N2-800 - mColorConnectedItemBackground = mCurrentColorScheme.getAccent2().getS800(); // A2-800 - mColorPositiveButtonText = mCurrentColorScheme.getAccent2().getS800(); // A2-800 - mColorDialogBackground = mCurrentColorScheme.getNeutral1().getS900(); // N1-900 - } else { - mColorItemContent = mCurrentColorScheme.getAccent1().getS800(); // A1-800 - mColorSeekbarProgress = mCurrentColorScheme.getAccent1().getS300(); // A1-300 - mColorButtonBackground = mCurrentColorScheme.getAccent1().getS600(); // A1-600 - mColorItemBackground = mCurrentColorScheme.getAccent2().getS50(); // A2-50 - mColorConnectedItemBackground = mCurrentColorScheme.getAccent1().getS100(); // A1-100 - mColorPositiveButtonText = mCurrentColorScheme.getNeutral1().getS50(); // N1-50 - mColorDialogBackground = mCurrentColorScheme.getBackgroundColor(); - } + mMediaOutputColorSchemeLegacy = MediaOutputColorSchemeLegacy.fromDynamicColors( + currentColorScheme, isDarkTheme); + } + + MediaOutputColorSchemeLegacy getColorSchemeLegacy() { + return mMediaOutputColorSchemeLegacy; } public void refreshDataSetIfNeeded() { @@ -598,34 +572,6 @@ public class MediaSwitchingController } } - public int getColorConnectedItemBackground() { - return mColorConnectedItemBackground; - } - - public int getColorPositiveButtonText() { - return mColorPositiveButtonText; - } - - public int getColorDialogBackground() { - return mColorDialogBackground; - } - - public int getColorItemContent() { - return mColorItemContent; - } - - public int getColorSeekbarProgress() { - return mColorSeekbarProgress; - } - - public int getColorButtonBackground() { - return mColorButtonBackground; - } - - public int getColorItemBackground() { - return mColorItemBackground; - } - private void buildMediaItems(List<MediaDevice> devices) { synchronized (mMediaDevicesLock) { List<MediaItem> updatedMediaItems = buildMediaItems(mOutputMediaItemList, devices); @@ -1097,7 +1043,7 @@ public class MediaSwitchingController mVolumePanelGlobalStateInteractor, mUserTracker); MediaOutputBroadcastDialog dialog = new MediaOutputBroadcastDialog(mContext, true, - broadcastSender, controller); + broadcastSender, controller, mMainExecutor, mBackgroundExecutor); dialog.show(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java index f0902e35b837..f1bf7c0bcf13 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java @@ -50,6 +50,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.media.BluetoothMediaDevice; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; +import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCaseExtKt; import com.android.systemui.animation.DialogTransitionAnimator; @@ -152,9 +153,9 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { volumePanelGlobalStateInteractor, mUserTracker); mMediaSwitchingController.mLocalMediaManager = mLocalMediaManager; - mMediaOutputBroadcastDialog = - new MediaOutputBroadcastDialog( - mContext, false, mBroadcastSender, mMediaSwitchingController); + mMediaOutputBroadcastDialog = new MediaOutputBroadcastDialog(mContext, false, + mBroadcastSender, mMediaSwitchingController, mContext.getMainExecutor(), + ThreadUtils.getBackgroundExecutor()); mMediaOutputBroadcastDialog.show(); } 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 d3ecb3d8c944..420fd6e33abc 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 @@ -53,6 +53,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.flags.Flags; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; +import com.android.settingslib.utils.ThreadUtils; import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCaseExtKt; import com.android.systemui.animation.DialogTransitionAnimator; @@ -455,6 +456,8 @@ public class MediaOutputDialogTest extends SysuiTestCase { controller, mDialogTransitionAnimator, mUiEventLogger, + mContext.getMainExecutor(), + ThreadUtils.getBackgroundExecutor(), true); } |