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

Commit cfa9474d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing the volume dialog to show only the volume control stream every time."

parents 8d3a1492 e87b1374
Loading
Loading
Loading
Loading
+101 −69
Original line number Original line Diff line number Diff line
@@ -112,20 +112,26 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                    // TODO: Include zoneId into consideration.
                    // TODO: Include zoneId into consideration.
                    // For instance
                    // For instance
                    // - single display + single-zone, ignore zoneId
                    // - single display + single-zone, ignore zoneId
            // - multi-display + single-zone, zoneId is fixed, may show volume bar on all displays
                    // - multi-display + single-zone, zoneId is fixed, may show volume bar on all
                    // displays
                    // - single-display + multi-zone, may show volume bar on primary display only
                    // - single-display + multi-zone, may show volume bar on primary display only
            // - multi-display + multi-zone, may show volume bar on display specified by zoneId
                    // - multi-display + multi-zone, may show volume bar on display specified by
                    // zoneId
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    int value = getSeekbarValue(mCarAudioManager, groupId);
                    int value = getSeekbarValue(mCarAudioManager, groupId);
            // Do not update the progress if it is the same as before. When car audio manager sets
                    // Do not update the progress if it is the same as before. When car audio
            // its group volume caused by the seekbar progress changed, it also triggers this
                    // manager sets
            // callback. Updating the seekbar at the same time could block the continuous seeking.
                    // its group volume caused by the seekbar progress changed, it also triggers
                    // this
                    // callback. Updating the seekbar at the same time could block the continuous
                    // seeking.
                    if (value != volumeItem.progress) {
                    if (value != volumeItem.progress) {
                        volumeItem.listItem.setProgress(value);
                        volumeItem.listItem.setProgress(value);
                        volumeItem.progress = value;
                        volumeItem.progress = value;
                    }
                    }
                    if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
                    if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
                mHandler.obtainMessage(H.SHOW, Events.SHOW_REASON_VOLUME_CHANGED).sendToTarget();
                        mHandler.obtainMessage(H.SHOW,
                                Events.SHOW_REASON_VOLUME_CHANGED).sendToTarget();
                    }
                    }
                }
                }


@@ -137,6 +143,8 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    private boolean mHovering;
    private boolean mHovering;
    private boolean mShowing;
    private boolean mShowing;
    private boolean mExpanded;
    private boolean mExpanded;
    private View mExpandIcon;
    private VolumeItem mDefaultVolumeItem;
    private final ServiceConnection mServiceConnection = new ServiceConnection() {
    private final ServiceConnection mServiceConnection = new ServiceConnection() {
        @Override
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
        public void onServiceConnected(ComponentName name, IBinder service) {
@@ -151,10 +159,8 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                    mAvailableVolumeItems.add(volumeItem);
                    mAvailableVolumeItems.add(volumeItem);
                    // The first one is the default item.
                    // The first one is the default item.
                    if (groupId == 0) {
                    if (groupId == 0) {
                        volumeItem.defaultItem = true;
                        mDefaultVolumeItem = volumeItem;
                        addSeekbarListItem(volumeItem, groupId,
                        setupDefaultListItem();
                                R.drawable.car_ic_keyboard_arrow_down,
                                new ExpandIconListener());
                    }
                    }
                }
                }


@@ -178,6 +184,13 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        }
        }
    };
    };


    private void setupDefaultListItem() {
        mDefaultVolumeItem.defaultItem = true;
        addSeekbarListItem(mDefaultVolumeItem, /* volumeGroupId = */0,
                R.drawable.car_ic_keyboard_arrow_down, new ExpandIconListener()
        );
    }

    public CarVolumeDialogImpl(Context context) {
    public CarVolumeDialogImpl(Context context) {
        mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
        mContext = new ContextThemeWrapper(context, com.android.systemui.R.style.qs_theme);
        mKeyguard = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
        mKeyguard = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
@@ -294,7 +307,9 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            return;
            return;
        }
        }
        mShowing = true;
        mShowing = true;

        if (mVolumeLineItems.isEmpty()) {
            setupDefaultListItem();
        }
        mDialog.show();
        mDialog.show();
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
    }
    }
@@ -340,6 +355,13 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                    }
                    }
                    mDialog.dismiss();
                    mDialog.dismiss();
                    mShowing = false;
                    mShowing = false;
                    mShowing = false;
                    // if mExpandIcon is null that means user never clicked on the expanded arrow
                    // which implies that the dialog is still not expanded. In that case we do
                    // not want to reset the state
                    if (mExpandIcon != null && mExpanded) {
                        toggleDialogExpansion(/* isClicked = */ false);
                    }
                }, DISMISS_DELAY_IN_MILLIS))
                }, DISMISS_DELAY_IN_MILLIS))
                .start();
                .start();


@@ -517,9 +539,14 @@ public class CarVolumeDialogImpl implements VolumeDialog {
    }
    }


    private final class ExpandIconListener implements View.OnClickListener {
    private final class ExpandIconListener implements View.OnClickListener {

        @Override
        @Override
        public void onClick(final View v) {
        public void onClick(final View v) {
            mExpandIcon = v;
            toggleDialogExpansion(true);
        }
    }

    private void toggleDialogExpansion(boolean isClicked) {
        mExpanded = !mExpanded;
        mExpanded = !mExpanded;
        Animator inAnimator;
        Animator inAnimator;
        if (mExpanded) {
        if (mExpanded) {
@@ -535,6 +562,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            }
            }
            inAnimator = AnimatorInflater.loadAnimator(
            inAnimator = AnimatorInflater.loadAnimator(
                    mContext, R.anim.car_arrow_fade_in_rotate_up);
                    mContext, R.anim.car_arrow_fade_in_rotate_up);

        } else {
        } else {
            // Only keeping the default stream if it is not expended.
            // Only keeping the default stream if it is not expended.
            Iterator itr = mVolumeLineItems.iterator();
            Iterator itr = mVolumeLineItems.iterator();
@@ -557,11 +585,15 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        inAnimator.setStartDelay(ARROW_FADE_IN_START_DELAY_IN_MILLIS);
        inAnimator.setStartDelay(ARROW_FADE_IN_START_DELAY_IN_MILLIS);
        AnimatorSet animators = new AnimatorSet();
        AnimatorSet animators = new AnimatorSet();
        animators.playTogether(outAnimator, inAnimator);
        animators.playTogether(outAnimator, inAnimator);
            animators.setTarget(v);
        if (!isClicked) {
            // Do not animate when the state is called to reset the dialogs view and not clicked
            // by user.
            animators.setDuration(0);
        }
        animators.setTarget(mExpandIcon);
        animators.start();
        animators.start();
        mPagedListAdapter.notifyDataSetChanged();
        mPagedListAdapter.notifyDataSetChanged();
    }
    }
    }


    private final class VolumeSeekBarChangeListener implements OnSeekBarChangeListener {
    private final class VolumeSeekBarChangeListener implements OnSeekBarChangeListener {