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

Commit 7df087c3 authored by shaoweishen's avatar shaoweishen Committed by Automerger Merge Worker
Browse files

DO NOT MERGE: Downbranch merge conflict [Output Switcher] Add animation when...

DO NOT MERGE: Downbranch merge conflict [Output Switcher] Add animation when init connected am: de900861

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17859795



Change-Id: If87425db357057f142882206b85eaaf6ac25146e
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 526e0680 de900861
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
        <clip>
            <shape>
                <corners
                    android:radius="28dp"/>
                    android:radius="16dp"/>
                <size
                    android:height="64dp"/>
                <solid android:color="@color/material_dynamic_primary80" />
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
            android:layout_height="match_parent"
            android:background="@drawable/media_output_item_background"
            android:layout_gravity="center_vertical|start">
            <SeekBar
            <com.android.systemui.media.dialog.MediaOutputSeekbar
                android:id="@+id/volume_seekbar"
                android:splitTrack="false"
                android:visibility="gone"
+2 −0
Original line number Diff line number Diff line
@@ -1125,6 +1125,8 @@
    <dimen name="media_output_dialog_icon_corner_radius">16dp</dimen>
    <dimen name="media_output_dialog_title_anim_y_delta">12.5dp</dimen>
    <dimen name="media_output_dialog_app_tier_icon_size">20dp</dimen>
    <dimen name="media_output_dialog_background_radius">16dp</dimen>
    <dimen name="media_output_dialog_active_background_radius">28dp</dimen>

    <!-- Distance that the full shade transition takes in order to complete by tapping on a button
         like "expand". -->
+4 −5
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            super.onBind(device, topMargin, bottomMargin, position);
            final boolean currentlyConnected = !mIncludeDynamicGroup
                    && isCurrentlyConnected(device);
            boolean isCurrentSeekbarInvisible = mSeekBar.getVisibility() == View.GONE;
            if (currentlyConnected) {
                mConnectedItem = mContainerLayout;
            }
@@ -178,7 +179,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    mCheckBox.setOnCheckedChangeListener(
                            (buttonView, isChecked) -> onGroupActionTriggered(false, device));
                    setCheckBoxColor(mCheckBox, mController.getColorItemContent());
                    initSeekbar(device);
                    initSeekbar(device, isCurrentSeekbarInvisible);
                    mEndTouchArea.setVisibility(View.VISIBLE);
                    mEndTouchArea.setOnClickListener(null);
                    mEndTouchArea.setOnClickListener((v) -> mCheckBox.performClick());
@@ -193,7 +194,7 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
                    setSingleLineLayout(getItemTitle(device), true /* bFocused */,
                            true /* showSeekBar */,
                            false /* showProgressBar */, true /* showStatus */);
                    initSeekbar(device);
                    initSeekbar(device, isCurrentSeekbarInvisible);
                    setUpContentDescriptionForView(mContainerLayout, false, device);
                    mCurrentActivePosition = position;
                } else if (isDeviceIncluded(mController.getSelectableMediaDevice(), device)) {
@@ -257,10 +258,8 @@ public class MediaOutputAdapter extends MediaOutputBaseAdapter {
            mCurrentActivePosition = -1;
            mController.connectDevice(device);
            device.setState(MediaDeviceState.STATE_CONNECTING);
            if (!isAnimating()) {
            notifyDataSetChanged();
        }
        }

        private void setUpContentDescriptionForView(View view, boolean clickable,
                MediaDevice device) {
+107 −85
Original line number Diff line number Diff line
@@ -17,18 +17,22 @@
package com.android.systemui.media.dialog;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.WallpaperColors;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Typeface;
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;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -44,7 +48,6 @@ import com.android.settingslib.Utils;
import com.android.settingslib.media.MediaDevice;
import com.android.settingslib.utils.ThreadUtils;
import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;

import java.util.List;

@@ -61,7 +64,6 @@ public abstract class MediaOutputBaseAdapter extends
    protected final MediaOutputController mController;

    private int mMargin;
    private boolean mIsAnimating;

    Context mContext;
    View mHolderView;
@@ -114,10 +116,6 @@ public abstract class MediaOutputBaseAdapter extends
        return mIsDragging;
    }

    boolean isAnimating() {
        return mIsAnimating;
    }

    int getCurrentActivePosition() {
        return mCurrentActivePosition;
    }
@@ -131,7 +129,7 @@ public abstract class MediaOutputBaseAdapter extends
     */
    abstract class MediaDeviceBaseViewHolder extends RecyclerView.ViewHolder {

        private static final int ANIM_DURATION = 200;
        private static final int ANIM_DURATION = 500;

        final LinearLayout mContainerLayout;
        final FrameLayout mItemLayout;
@@ -140,12 +138,14 @@ public abstract class MediaOutputBaseAdapter extends
        final TextView mSubTitleText;
        final ImageView mTitleIcon;
        final ProgressBar mProgressBar;
        final SeekBar mSeekBar;
        final MediaOutputSeekbar mSeekBar;
        final LinearLayout mTwoLineLayout;
        final ImageView mStatusIcon;
        final CheckBox mCheckBox;
        final LinearLayout mEndTouchArea;
        private String mDeviceId;
        private ValueAnimator mCornerAnimator;
        private ValueAnimator mVolumeAnimator;

        MediaDeviceBaseViewHolder(View view) {
            super(view);
@@ -161,6 +161,7 @@ public abstract class MediaOutputBaseAdapter extends
            mStatusIcon = view.requireViewById(R.id.media_output_item_status);
            mCheckBox = view.requireViewById(R.id.check_box);
            mEndTouchArea = view.requireViewById(R.id.end_action_area);
            initAnimator();
        }

        void onBind(MediaDevice device, boolean topMargin, boolean bottomMargin, int position) {
@@ -186,9 +187,11 @@ public abstract class MediaOutputBaseAdapter extends
                boolean showProgressBar, boolean showStatus) {
            mTwoLineLayout.setVisibility(View.GONE);
            boolean isActive = showSeekBar || showProgressBar;
            if (!mCornerAnimator.isRunning()) {
                final Drawable backgroundDrawable =
                    isActive
                            ? mContext.getDrawable(R.drawable.media_output_item_background_active)
                        showSeekBar
                                ? mContext.getDrawable(
                                        R.drawable.media_output_item_background_active)
                                .mutate() : mContext.getDrawable(
                                        R.drawable.media_output_item_background)
                                .mutate();
@@ -197,9 +200,26 @@ public abstract class MediaOutputBaseAdapter extends
                                : mController.getColorItemBackground(),
                        PorterDuff.Mode.SRC_IN));
                mItemLayout.setBackground(backgroundDrawable);
                if (showSeekBar) {
                    final ClipDrawable clipDrawable =
                            (ClipDrawable) ((LayerDrawable) mSeekBar.getProgressDrawable())
                                    .findDrawableByLayerId(android.R.id.progress);
                    final GradientDrawable progressDrawable =
                            (GradientDrawable) clipDrawable.getDrawable();
                    progressDrawable.setCornerRadius(mController.getActiveRadius());
                }
            } else {
                mItemLayout.getBackground().setColorFilter(new PorterDuffColorFilter(
                        isActive ? mController.getColorConnectedItemBackground()
                                : mController.getColorItemBackground(),
                        PorterDuff.Mode.SRC_IN));
            }
            mProgressBar.setVisibility(showProgressBar ? View.VISIBLE : View.GONE);
            mSeekBar.setAlpha(1);
            mSeekBar.setVisibility(showSeekBar ? View.VISIBLE : View.GONE);
            if (!showSeekBar) {
                mSeekBar.resetVolume();
            }
            mStatusIcon.setVisibility(showStatus ? View.VISIBLE : View.GONE);
            mTitleText.setText(title);
            mTitleText.setVisibility(View.VISIBLE);
@@ -257,15 +277,21 @@ public abstract class MediaOutputBaseAdapter extends
            }
        }

        void initSeekbar(MediaDevice device) {
        void initSeekbar(MediaDevice device, boolean isCurrentSeekbarInvisible) {
            if (!mController.isVolumeControlEnabled(device)) {
                disableSeekBar();
            }
            mSeekBar.setMax(device.getMaxVolume());
            mSeekBar.setMin(0);
            mSeekBar.setMaxVolume(device.getMaxVolume());
            final int currentVolume = device.getCurrentVolume();
            if (mSeekBar.getProgress() != currentVolume) {
                mSeekBar.setProgress(currentVolume, true);
            if (mSeekBar.getVolume() != currentVolume) {
                if (isCurrentSeekbarInvisible) {
                    animateCornerAndVolume(mSeekBar.getProgress(),
                            MediaOutputSeekbar.scaleVolumeToProgress(currentVolume));
                } else {
                    if (!mVolumeAnimator.isStarted()) {
                        mSeekBar.setVolume(currentVolume);
                    }
                }
            }
            mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                @Override
@@ -273,7 +299,11 @@ public abstract class MediaOutputBaseAdapter extends
                    if (device == null || !fromUser) {
                        return;
                    }
                    mController.adjustVolume(device, progress);
                    int currentVolume = MediaOutputSeekbar.scaleProgressToVolume(progress);
                    int deviceVolume = device.getCurrentVolume();
                    if (currentVolume != deviceVolume) {
                        mController.adjustVolume(device, currentVolume);
                    }
                }

                @Override
@@ -317,63 +347,55 @@ public abstract class MediaOutputBaseAdapter extends
            });
        }

        void playSwitchingAnim(@NonNull View from, @NonNull View to) {
            final float delta = (float) (mContext.getResources().getDimensionPixelSize(
                    R.dimen.media_output_dialog_title_anim_y_delta));
            final SeekBar fromSeekBar = from.requireViewById(R.id.volume_seekbar);
            final TextView toTitleText = to.requireViewById(R.id.title);
            if (fromSeekBar.getVisibility() != View.VISIBLE || toTitleText.getVisibility()
                    != View.VISIBLE) {
                return;
        private void animateCornerAndVolume(int fromProgress, int toProgress) {
            final GradientDrawable layoutBackgroundDrawable =
                    (GradientDrawable) mItemLayout.getBackground();
            final ClipDrawable clipDrawable =
                    (ClipDrawable) ((LayerDrawable) mSeekBar.getProgressDrawable())
                            .findDrawableByLayerId(android.R.id.progress);
            final GradientDrawable progressDrawable = (GradientDrawable) clipDrawable.getDrawable();
            mCornerAnimator.addUpdateListener(animation -> {
                float value = (float) animation.getAnimatedValue();
                layoutBackgroundDrawable.setCornerRadius(value);
                progressDrawable.setCornerRadius(value);
            });
            mVolumeAnimator.setIntValues(fromProgress, toProgress);
            mVolumeAnimator.start();
            mCornerAnimator.start();
        }
            mIsAnimating = true;
            // Animation for title text
            toTitleText.setTypeface(Typeface.create(mContext.getString(
                    com.android.internal.R.string.config_headlineFontFamilyMedium),
                    Typeface.NORMAL));
            toTitleText.animate()
                    .setDuration(ANIM_DURATION)
                    .translationY(-delta)
                    .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
                    .setListener(new AnimatorListenerAdapter() {

        private void initAnimator() {
            mCornerAnimator = ValueAnimator.ofFloat(mController.getInactiveRadius(),
                    mController.getActiveRadius());
            mCornerAnimator.setDuration(ANIM_DURATION);
            mCornerAnimator.setInterpolator(new LinearInterpolator());

            mVolumeAnimator = ValueAnimator.ofInt();
            mVolumeAnimator.addUpdateListener(animation -> {
                int value = (int) animation.getAnimatedValue();
                mSeekBar.setProgress(value);
            });
            mVolumeAnimator.setDuration(ANIM_DURATION);
            mVolumeAnimator.setInterpolator(new LinearInterpolator());
            mVolumeAnimator.addListener(new Animator.AnimatorListener() {
                @Override
                        public void onAnimationEnd(Animator animation) {
                            to.requireViewById(R.id.volume_indeterminate_progress).setVisibility(
                                    View.VISIBLE);
                            // Unset the listener, otherwise this may persist for another view
                            // property animation
                            toTitleText.animate().setListener(null);
                public void onAnimationStart(Animator animation) {
                    mSeekBar.setEnabled(false);
                }
                    });
            // Animation for seek bar
            fromSeekBar.animate()
                    .alpha(0)
                    .setDuration(ANIM_DURATION)
                    .setListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                            final TextView fromTitleText = from.requireViewById(
                                    R.id.two_line_title);
                            fromTitleText.setTypeface(Typeface.create(mContext.getString(
                                    com.android.internal.R.string.config_headlineFontFamily),
                                    Typeface.NORMAL));
                            fromTitleText.animate()
                                    .setDuration(ANIM_DURATION)
                                    .translationY(delta)
                                    .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
                                    .setListener(new AnimatorListenerAdapter() {
                    mSeekBar.setEnabled(true);
                }

                @Override
                                        public void onAnimationEnd(Animator animation) {
                                            mIsAnimating = false;
                                            notifyDataSetChanged();
                                            // Unset the listener, otherwise this may persist for
                                            // another view property animation
                                            fromTitleText.animate().setListener(null);
                public void onAnimationCancel(Animator animation) {
                    mSeekBar.setEnabled(true);
                }
                                    });
                            // Unset the listener, otherwise this may persist for another view
                            // property animation
                            fromSeekBar.animate().setListener(null);

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
        }
Loading