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

Commit 48fb6a13 authored by Priyank Singh's avatar Priyank Singh Committed by android-build-merger
Browse files

Merge "Volume dialog should show the volume for the group id that is being...

Merge "Volume dialog should show the volume for the group id that is being changed." into qt-dev am: e2c19dd0
am: fcfa3ed1

Change-Id: I0c18c2cef5d7ccbae55f1ef619fdb68ae97e4ff7
parents 31d9db44 fcfa3ed1
Loading
Loading
Loading
Loading
+18 −35
Original line number Original line Diff line number Diff line
@@ -112,17 +112,22 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                    // zoneId
                    // zoneId
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    int value = getSeekbarValue(mCarAudioManager, groupId);
                    int value = getSeekbarValue(mCarAudioManager, groupId);
                    // find if the group id for which the volume changed is currently being
                    // displayed.
                    boolean isShowing = mCarVolumeLineItems.stream().anyMatch(
                            item -> item.getGroupId() == groupId);
                    // Do not update the progress if it is the same as before. When car audio
                    // Do not update the progress if it is the same as before. When car audio
                    // manager sets
                    // manager sets
                    // its group volume caused by the seekbar progress changed, it also triggers
                    // its group volume caused by the seekbar progress changed, it also triggers
                    // this
                    // this
                    // callback. Updating the seekbar at the same time could block the continuous
                    // callback. Updating the seekbar at the same time could block the continuous
                    // seeking.
                    // seeking.
                    if (value != volumeItem.progress) {
                    if (value != volumeItem.progress && isShowing) {
                        volumeItem.carVolumeItem.setProgress(value);
                        volumeItem.carVolumeItem.setProgress(value);
                        volumeItem.progress = value;
                        volumeItem.progress = value;
                    }
                    }
                    if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
                    if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
                        mCurrentlyDisplayingGroupId = groupId;
                        mHandler.obtainMessage(H.SHOW,
                        mHandler.obtainMessage(H.SHOW,
                                Events.SHOW_REASON_VOLUME_CHANGED).sendToTarget();
                                Events.SHOW_REASON_VOLUME_CHANGED).sendToTarget();
                    }
                    }
@@ -134,10 +139,10 @@ public class CarVolumeDialogImpl implements VolumeDialog {
                }
                }
            };
            };
    private boolean mHovering;
    private boolean mHovering;
    private int mCurrentlyDisplayingGroupId;
    private boolean mShowing;
    private boolean mShowing;
    private boolean mExpanded;
    private boolean mExpanded;
    private View mExpandIcon;
    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) {
@@ -152,8 +157,7 @@ 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) {
                        mDefaultVolumeItem = volumeItem;
                        setuptListItem(0);
                        setupDefaultCarVolumeItem();
                    }
                    }
                }
                }


@@ -177,9 +181,11 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        }
        }
    };
    };


    private void setupDefaultCarVolumeItem() {
    private void setuptListItem(int groupId) {
        mDefaultVolumeItem.defaultItem = true;
        mCarVolumeLineItems.clear();
        addCarVolumeListItem(mDefaultVolumeItem, /* volumeGroupId = */0,
        VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
        volumeItem.defaultItem = true;
        addCarVolumeListItem(volumeItem, /* volumeGroupId = */ groupId,
                R.drawable.car_ic_keyboard_arrow_down, new ExpandIconListener()
                R.drawable.car_ic_keyboard_arrow_down, new ExpandIconListener()
        );
        );
    }
    }
@@ -299,9 +305,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            return;
            return;
        }
        }
        mShowing = true;
        mShowing = true;
        if (mCarVolumeLineItems.isEmpty()) {
        setuptListItem(mCurrentlyDisplayingGroupId);
            setupDefaultCarVolumeItem();
        }
        mDialog.show();
        mDialog.show();
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
        Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked());
    }
    }
@@ -437,7 +441,7 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            carVolumeItem.setSupplementalIcon(/* drawable= */ null,
            carVolumeItem.setSupplementalIcon(/* drawable= */ null,
                    /* showSupplementalIconDivider= */ false);
                    /* showSupplementalIconDivider= */ false);
        }
        }

        carVolumeItem.setGroupId(volumeGroupId);
        mCarVolumeLineItems.add(carVolumeItem);
        mCarVolumeLineItems.add(carVolumeItem);
        volumeItem.carVolumeItem = carVolumeItem;
        volumeItem.carVolumeItem = carVolumeItem;
        volumeItem.progress = progress;
        volumeItem.progress = progress;
@@ -545,11 +549,8 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        Animator inAnimator;
        Animator inAnimator;
        if (mExpanded) {
        if (mExpanded) {
            for (int groupId = 0; groupId < mAvailableVolumeItems.size(); ++groupId) {
            for (int groupId = 0; groupId < mAvailableVolumeItems.size(); ++groupId) {
                // Adding the items which are not coming from the default item.
                if (groupId != mCurrentlyDisplayingGroupId) {
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                    VolumeItem volumeItem = mAvailableVolumeItems.get(groupId);
                if (volumeItem.defaultItem) {
                    updateDefaultVolumeItem(volumeItem.carVolumeItem);
                } else {
                    addCarVolumeListItem(volumeItem, groupId, 0, null);
                    addCarVolumeListItem(volumeItem, groupId, 0, null);
                }
                }
            }
            }
@@ -561,11 +562,8 @@ public class CarVolumeDialogImpl implements VolumeDialog {
            Iterator itr = mCarVolumeLineItems.iterator();
            Iterator itr = mCarVolumeLineItems.iterator();
            while (itr.hasNext()) {
            while (itr.hasNext()) {
                CarVolumeItem carVolumeItem = (CarVolumeItem) itr.next();
                CarVolumeItem carVolumeItem = (CarVolumeItem) itr.next();
                VolumeItem volumeItem = findVolumeItem(carVolumeItem);
                if (carVolumeItem.getGroupId() != mCurrentlyDisplayingGroupId) {
                if (!volumeItem.defaultItem) {
                    itr.remove();
                    itr.remove();
                } else {
                    updateDefaultVolumeItem(carVolumeItem);
                }
                }
            }
            }
            inAnimator = AnimatorInflater.loadAnimator(
            inAnimator = AnimatorInflater.loadAnimator(
@@ -587,21 +585,6 @@ public class CarVolumeDialogImpl implements VolumeDialog {
        mVolumeItemsAdapter.notifyDataSetChanged();
        mVolumeItemsAdapter.notifyDataSetChanged();
    }
    }


    private void updateDefaultVolumeItem(CarVolumeItem carVolumeItem) {
        VolumeItem volumeItem = findVolumeItem(carVolumeItem);

        // When volume dialog is expanded or collapsed the default list item is never
        // reset. Whereas all other list items are removed when the dialog is collapsed and then
        // added when the dialog is expanded using {@link CarVolumeDialogImpl#addCarVolumeListItem}.
        // This sets the progressbar and the tint color of icons for all items other than default
        // if they were changed. For default list item it should be done manually here.
        int color = mContext.getResources().getColor(R.color.car_volume_dialog_tint);
        Drawable primaryIcon = mContext.getResources().getDrawable(volumeItem.icon);
        primaryIcon.mutate().setTint(color);
        volumeItem.carVolumeItem.setPrimaryIcon(primaryIcon);
        volumeItem.carVolumeItem.setProgress(volumeItem.progress);
    }

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


        private final int mVolumeGroupId;
        private final int mVolumeGroupId;
+15 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ public class CarVolumeItem {
    private Drawable mSupplementalIcon;
    private Drawable mSupplementalIcon;
    private View.OnClickListener mSupplementalIconOnClickListener;
    private View.OnClickListener mSupplementalIconOnClickListener;
    private boolean mShowSupplementalIconDivider;
    private boolean mShowSupplementalIconDivider;
    private int mGroupId;


    private int mMax;
    private int mMax;
    private int mProgress;
    private int mProgress;
@@ -85,6 +86,20 @@ public class CarVolumeItem {
        mIsDirty = true;
        mIsDirty = true;
    }
    }


    /**
     * Gets the group id associated.
     */
    public int getGroupId() {
        return mGroupId;
    }

    /**
     * Sets the group id associated.
     */
    public void setGroupId(int groupId) {
        this.mGroupId = groupId;
    }

    /** Sets {@code OnClickListener} for the supplemental icon. */
    /** Sets {@code OnClickListener} for the supplemental icon. */
    public void setSupplementalIconListener(View.OnClickListener listener) {
    public void setSupplementalIconListener(View.OnClickListener listener) {
        mSupplementalIconOnClickListener = listener;
        mSupplementalIconOnClickListener = listener;