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

Commit 0d977866 authored by Alex Shabalin's avatar Alex Shabalin
Browse files

Consolidate the loading indicator and item background rendering.

Flag: EXEMPT refactor
Bug: 387570618
Test: atest SystemUIGoogleRoboRNGTests:MediaOutputAdapterScreenshotTest,
    atest SystemUiRoboTests:MediaOutputAdapterTest
Change-Id: I14a0753ccbd5e8b7f360a01a6fc87728790eb367
parent c9eab1d5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,6 +17,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <corners
        android:radius="16dp"/>
        android:radius="@dimen/media_output_dialog_background_radius"/>
    <solid android:color="@color/media_dialog_item_background" />
</shape>
 No newline at end of file
+16 −26
Original line number Diff line number Diff line
@@ -202,9 +202,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        && !mController.hasAdjustVolumeUserRestriction()) {
                    connectionState = ConnectionState.CONNECTING;
                    setUpDeviceIcon(device);
                    updateProgressBarColor();
                    setSingleLineLayout(device.getName(), false /* showSeekBar*/,
                            true /* showProgressBar */);
                    setSingleLineLayout(device.getName(), false /* showSeekBar*/);
                } else {
                    setUpDeviceIcon(device);
                    setSingleLineLayout(device.getName());
@@ -213,6 +211,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                // Set different layout for each device
                if (device.isMutingExpectedDevice()
                        && !mController.isCurrentConnectedDeviceRemote()) {
                    connectionState = ConnectionState.CONNECTED;
                    updateUnmutedVolumeIcon(device);
                    mCurrentActivePosition = position;
                    updateFullItemClickListener(v -> onItemClick(v, device));
@@ -231,8 +230,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        disableFocusPropertyForView(mContainerLayout);
                        setUpContentDescriptionForView(mSeekBar, mContext.getString(
                                R.string.accessibility_cast_name, sessionName));
                        setSingleLineLayout(sessionName, true /* showSeekBar */,
                                false /* showProgressBar */);
                        setSingleLineLayout(sessionName, true /* showSeekBar */);
                        initGroupSeekbar(isCurrentSeekbarInvisible);
                    }
                } else if (device.hasSubtext()) {
@@ -246,7 +244,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        ongoingSessionStatus = new OngoingSessionStatus(
                                device.isHostForOngoingSession());
                        setTwoLineLayout(device.getName() /* title */,
                                true /* showSeekBar */, false /* showProgressBar */,
                                true /* showSeekBar */,
                                true /* showSubtitle */, false /* showStatus */);
                        connectionState = ConnectionState.CONNECTED;
                        initSeekbar(device, isCurrentSeekbarInvisible);
@@ -273,7 +271,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                                        ? DEVICE_CONNECTED_ALPHA : DEVICE_DISCONNECTED_ALPHA);
                        setTwoLineLayout(device.getName(),
                                currentlyConnected  /* showSeekBar */,
                                false /* showProgressBar */, true /* showSubtitle */,
                                true /* showSubtitle */,
                                deviceStatusIcon != null /* showStatus */);
                    }
                } else if (device.getState() == MediaDeviceState.STATE_CONNECTING_FAILED) {
@@ -282,14 +280,12 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    mSubTitleText.setText(R.string.media_output_dialog_connect_failed);
                    updateFullItemClickListener(v -> onItemClick(v, device));
                    setTwoLineLayout(device.getName(), false /* showSeekBar */,
                            false /* showProgressBar */, true /* showSubtitle */,
                            true /* showSubtitle */,
                            true /* showStatus */);
                } else if (device.getState() == MediaDeviceState.STATE_GROUPING) {
                    connectionState = ConnectionState.CONNECTING;
                    setUpDeviceIcon(device);
                    updateProgressBarColor();
                    setSingleLineLayout(device.getName(), false /* showSeekBar*/,
                            true /* showProgressBar */);
                    setSingleLineLayout(device.getName(), false /* showSeekBar*/);
                } else if (mController.getSelectedMediaDevice().size() > 1 && isSelected) {
                    // selected device in group
                    updateUnmutedVolumeIcon(device);
@@ -298,8 +294,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                            isDeselectable /* deselectable */);
                    disableFocusPropertyForView(mContainerLayout);
                    setUpContentDescriptionForView(mSeekBar, device);
                    setSingleLineLayout(device.getName(), true /* showSeekBar */,
                            false /* showProgressBar */);
                    setSingleLineLayout(device.getName(), true /* showSeekBar */);
                    connectionState = ConnectionState.CONNECTED;
                    initSeekbar(device, isCurrentSeekbarInvisible);
                } else if (!mController.hasAdjustVolumeUserRestriction()
@@ -316,8 +311,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        updateUnmutedVolumeIcon(device);
                        ongoingSessionStatus = new OngoingSessionStatus(
                                device.isHostForOngoingSession());
                        setSingleLineLayout(device.getName(), true /* showSeekBar */,
                                false /* showProgressBar */);
                        setSingleLineLayout(device.getName(), true /* showSeekBar */);
                        connectionState = ConnectionState.CONNECTED;
                        initSeekbar(device, isCurrentSeekbarInvisible);
                    } else if (mController.isCurrentConnectedDeviceRemote()
@@ -330,8 +324,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                                isDeselectable /* isDeselectable */);
                        disableFocusPropertyForView(mContainerLayout);
                        setUpContentDescriptionForView(mSeekBar, device);
                        setSingleLineLayout(device.getName(), true /* showSeekBar */,
                                false /* showProgressBar */);
                        setSingleLineLayout(device.getName(), true /* showSeekBar */);
                        connectionState = ConnectionState.CONNECTED;
                        initSeekbar(device, isCurrentSeekbarInvisible);
                    } else {
@@ -339,8 +332,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                        disableFocusPropertyForView(mContainerLayout);
                        setUpContentDescriptionForView(mSeekBar, device);
                        mCurrentActivePosition = position;
                        setSingleLineLayout(device.getName(), true /* showSeekBar */,
                                false /* showProgressBar */);
                        setSingleLineLayout(device.getName(), true /* showSeekBar */);
                        connectionState = ConnectionState.CONNECTED;
                        initSeekbar(device, isCurrentSeekbarInvisible);
                    }
@@ -353,8 +345,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                            || hasRouteListingPreferenceItem) {
                        updateFullItemClickListener(v -> onItemClick(v, device));
                    }
                    setSingleLineLayout(device.getName(), false /* showSeekBar */,
                            false /* showProgressBar */);
                    setSingleLineLayout(device.getName(), false /* showSeekBar */);
                } else {
                    setUpDeviceIcon(device);
                    setSingleLineLayout(device.getName());
@@ -376,8 +367,11 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {

            if (isDeviceGroup) {
                updateEndAreaForDeviceGroup();
                updateItemBackground(ConnectionState.CONNECTED);
            } else {
                updateEndArea(device, connectionState, groupStatus, ongoingSessionStatus);
                updateLoadingIndicator(connectionState);
                updateItemBackground(connectionState);
            }
        }

@@ -493,11 +487,6 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            }
        }

        private void updateProgressBarColor() {
            mProgressBar.getIndeterminateDrawable().setTintList(
                    ColorStateList.valueOf(mController.getColorItemContent()));
        }

        public void updateEndAreaForGroupCheckBox(@NonNull MediaDevice device,
                @NonNull GroupStatus groupStatus) {
            boolean isEnabled = isGroupCheckboxEnabled(groupStatus);
@@ -525,6 +514,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            mTitleText.setTextColor(mController.getColorItemContent());
            mCheckBox.setVisibility(View.GONE);
            setSingleLineLayout(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(
+32 −34
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.WallpaperColors;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.Icon;
import android.graphics.drawable.LayerDrawable;
@@ -198,28 +197,15 @@ public abstract class MediaOutputBaseAdapter extends
        }

        void setSingleLineLayout(CharSequence title) {
            setSingleLineLayout(title, false, false);
            setSingleLineLayout(title, false);
        }

        void setSingleLineLayout(CharSequence title, boolean showSeekBar, boolean showProgressBar) {
            boolean isActive = showSeekBar || showProgressBar;
        void setSingleLineLayout(CharSequence title, boolean showSeekBar) {
            if (!mCornerAnimator.isRunning()) {
                final Drawable backgroundDrawable =
                        showSeekBar
                                ? mContext.getDrawable(
                                        R.drawable.media_output_item_background_active)
                                .mutate() : mContext.getDrawable(
                                        R.drawable.media_output_item_background)
                                .mutate();
                mItemLayout.setBackground(backgroundDrawable);
                if (showSeekBar) {
                    updateSeekbarProgressBackground();
                }
            }
            mItemLayout.setBackgroundTintList(
                    ColorStateList.valueOf(isActive ? mController.getColorConnectedItemBackground()
                            : mController.getColorItemBackground()));
            mProgressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
            mSeekBar.setAlpha(1);
            mSeekBar.setVisibility(showSeekBar ? View.VISIBLE : View.GONE);
            if (!showSeekBar) {
@@ -229,28 +215,46 @@ public abstract class MediaOutputBaseAdapter extends
        }

        void setTwoLineLayout(CharSequence title,
                boolean showSeekBar, boolean showProgressBar, boolean showSubtitle,
                boolean showStatus) {
                boolean showSeekBar, boolean showSubtitle, boolean showStatus) {
            mStatusIcon.setVisibility(showStatus ? View.VISIBLE : View.GONE);
            mSeekBar.setAlpha(1);
            mSeekBar.setVisibility(showSeekBar ? View.VISIBLE : View.GONE);
            final Drawable backgroundDrawable;
            backgroundDrawable = mContext.getDrawable(
                    showSeekBar ? R.drawable.media_output_item_background_active
                            : R.drawable.media_output_item_background).mutate();
            mItemLayout.setBackgroundTintList(ColorStateList.valueOf(
                    showSeekBar ? mController.getColorConnectedItemBackground()
                            : mController.getColorItemBackground()
            ));
            if (showSeekBar) {
                updateSeekbarProgressBackground();
            }
            mItemLayout.setBackground(backgroundDrawable);
            mProgressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
            mSubTitleText.setVisibility(showSubtitle ? View.VISIBLE : View.GONE);
            mTitleText.setText(title);
        }

        protected void updateLoadingIndicator(ConnectionState connectionState) {
            if (connectionState == ConnectionState.CONNECTING) {
                mProgressBar.setVisibility(View.VISIBLE);
                mProgressBar.getIndeterminateDrawable().setTintList(
                        ColorStateList.valueOf(mController.getColorItemContent()));
            } else {
                mProgressBar.setVisibility(View.GONE);
            }
        }

        protected void updateItemBackground(ConnectionState connectionState) {
            boolean isConnected = connectionState == ConnectionState.CONNECTED;
            boolean isConnecting = connectionState == ConnectionState.CONNECTING;

            // Increase corner radius for a connected state.
            if (!mCornerAnimator.isRunning()) {  // FIXME(b/387576145): This is always True.
                int backgroundDrawableId =
                        isConnected ? R.drawable.media_output_item_background_active
                                : R.drawable.media_output_item_background;
                mItemLayout.setBackground(mContext.getDrawable(backgroundDrawableId).mutate());
            }

            // Connected or connecting state has a darker background.
            int backgroundColor = isConnected || isConnecting
                    ? mController.getColorConnectedItemBackground()
                    : mController.getColorItemBackground();
            mItemLayout.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
        }

        protected void updateEndAreaVisibility(boolean showEndTouchArea, boolean isCheckbox) {
            mEndTouchArea.setVisibility(showEndTouchArea ? View.VISIBLE : View.GONE);
            if (showEndTouchArea) {
@@ -423,12 +427,6 @@ public abstract class MediaOutputBaseAdapter extends
        void initFakeActiveDevice(MediaDevice device) {
            disableSeekBar();
            updateTitleIcon(device, false /* isMutedIcon */);
            final Drawable backgroundDrawable = mContext.getDrawable(
                                    R.drawable.media_output_item_background_active)
                            .mutate();
            mItemLayout.setBackground(backgroundDrawable);
            mItemLayout.setBackgroundTintList(
                    ColorStateList.valueOf(mController.getColorConnectedItemBackground()));
            mIconAreaLayout.setBackground(null);
        }