Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 414ef5f3 authored by Alexandr Shabalin's avatar Alexandr Shabalin Committed by Android (Google) Code Review
Browse files

Merge changes from topics "ashabalin-extract-theme", "ashablain-fix-legacy-dialog-ui" into main

* changes:
  Make the Output Switcher layout up to the spec.
  Detach color scheme from MediaSwitchingController.
parents da95f43d 169b1bda
Loading
Loading
Loading
Loading
+23 −8
Original line number Diff line number Diff line
@@ -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);
+15 −12
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
  ~ limitations under the License.
  -->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/media_output_dialog"
    android:layout_width="@dimen/large_dialog_width"
    android:layout_height="wrap_content"
@@ -35,24 +35,25 @@
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/header_icon"
            android:layout_width="72dp"
            android:layout_height="72dp"
            android:layout_width="@dimen/media_output_dialog_header_album_icon_size"
            android:layout_height="@dimen/media_output_dialog_header_album_icon_size"
            android:layout_marginEnd="@dimen/media_output_dialog_header_icon_padding"
            android:importantForAccessibility="no"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingStart="12dp"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:gravity="top"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/app_source_icon"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginBottom="7dp"
                    android:gravity="center_vertical"
                    android:importantForAccessibility="no"/>

@@ -103,12 +104,11 @@
        android:layout_height="wrap_content" >
    </ViewStub>

    <LinearLayout
    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/device_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical">
        android:layout_height="0dp"
        android:layout_weight="1">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list_result"
@@ -116,8 +116,11 @@
            android:paddingTop="8dp"
            android:clipToPadding="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHeight_max="@dimen/media_output_dialog_list_max_height"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

    <LinearLayout
        android:layout_width="match_parent"
+3 −2
Original line number Diff line number Diff line
@@ -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();
        }

+44 −31
Original line number Diff line number Diff line
@@ -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);
        }
    }
+12 −40

File changed.

Preview size limit exceeded, changes collapsed.

Loading