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

Commit 9abad3b1 authored by Angela Wang's avatar Angela Wang Committed by Android (Google) Code Review
Browse files

Merge "Rename some methods of AmbientVolumeUi" into main

parents a142edbd f3703dad
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -94,16 +94,16 @@ public interface AmbientVolumeUi {
     *
     * <p> If the UI is not expandable, it implies the UI will always stay in collapsed mode
     */
    void setExpandable(boolean expandable);
    void setControlExpandable(boolean expandable);

    /** @return if the UI is expandable. */
    boolean isExpandable();
    boolean isControlExpandable();

    /** Sets if the UI is in expanded mode. */
    void setExpanded(boolean expanded);
    void setControlExpanded(boolean expanded);

    /** @return if the UI is in expanded mode. */
    boolean isExpanded();
    boolean isControlExpanded();

    /**
     * Sets if the UI is capable to mute the ambient of the remote device.
+6 −6
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class AmbientVolumeUiController implements
            Log.d(TAG, "onAmbientChanged, value:" + gainSettings + ", device:" + device);
        }
        HearingDeviceLocalDataManager.Data data = mLocalDataManager.get(device);
        final boolean expanded = mAmbientLayout.isExpanded();
        final boolean expanded = mAmbientLayout.isControlExpanded();
        final boolean isInitiatedFromUi = (expanded && data.ambient() == gainSettings)
                || (!expanded && data.groupAmbient() == gainSettings);
        if (isInitiatedFromUi) {
@@ -176,13 +176,13 @@ public class AmbientVolumeUiController implements
            if (!mAmbientLayout.isMuted()) {
                // Apply previous collapsed/expanded volume to remote device
                HearingDeviceLocalDataManager.Data data = mLocalDataManager.get(d);
                int volume = mAmbientLayout.isExpanded()
                int volume = mAmbientLayout.isControlExpanded()
                        ? data.ambient() : data.groupAmbient();
                mVolumeController.setAmbient(d, volume);
            }
            // Update new value to local data
            mLocalDataManager.updateAmbientControlExpanded(d,
                    mAmbientLayout.isExpanded());
                    mAmbientLayout.isControlExpanded());
        });
        mLocalDataManager.flush();
    }
@@ -322,7 +322,7 @@ public class AmbientVolumeUiController implements
            }
        }

        mAmbientLayout.setExpandable(mSideToDeviceMap.size() >  1);
        mAmbientLayout.setControlExpandable(mSideToDeviceMap.size() >  1);
        mAmbientLayout.setupSliders(mSideToDeviceMap);
        refresh();
    }
@@ -412,7 +412,7 @@ public class AmbientVolumeUiController implements
        // Update ambient volume
        final int leftAmbient = leftState != null ? leftState.gainSetting() : INVALID_VOLUME;
        final int rightAmbient = rightState != null ? rightState.gainSetting() : INVALID_VOLUME;
        if (mAmbientLayout.isExpanded()) {
        if (mAmbientLayout.isControlExpanded()) {
            setVolumeIfValid(SIDE_LEFT, leftAmbient);
            setVolumeIfValid(SIDE_RIGHT, rightAmbient);
        } else {
@@ -451,7 +451,7 @@ public class AmbientVolumeUiController implements
    }

    private void setAmbientControlExpanded(boolean expanded) {
        mAmbientLayout.setExpanded(expanded);
        mAmbientLayout.setControlExpanded(expanded);
        mSideToDeviceMap.forEach((s, d) -> {
            // Update new value to local data
            mLocalDataManager.updateAmbientControlExpanded(d, expanded);
+8 −8
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ public class AmbientVolumeUiControllerTest {

        mController.loadDevice(mCachedDevice);

        verify(mAmbientLayout).setExpandable(false);
        verify(mAmbientLayout).setControlExpandable(false);
    }

    @Test
@@ -145,7 +145,7 @@ public class AmbientVolumeUiControllerTest {

        mController.loadDevice(mCachedDevice);

        verify(mAmbientLayout).setExpandable(true);
        verify(mAmbientLayout).setControlExpandable(true);
    }

    @Test
@@ -204,7 +204,7 @@ public class AmbientVolumeUiControllerTest {
    }

    @Test
    public void onDeviceLocalDataChange_verifySetExpandedAndDataUpdated() {
    public void onDeviceLocalDataChange_verifySetControlExpandedAndDataUpdated() {
        final boolean testExpanded = true;
        HearingDeviceLocalDataManager.Data data = new HearingDeviceLocalDataManager.Data.Builder()
                .ambient(0).groupAmbient(0).ambientControlExpanded(testExpanded).build();
@@ -213,7 +213,7 @@ public class AmbientVolumeUiControllerTest {
        mController.onDeviceLocalDataChange(TEST_ADDRESS, data);
        shadowOf(Looper.getMainLooper()).idle();

        verify(mAmbientLayout).setExpanded(testExpanded);
        verify(mAmbientLayout).setControlExpanded(testExpanded);
        verifyDeviceDataUpdated(mDevice);
    }

@@ -222,7 +222,7 @@ public class AmbientVolumeUiControllerTest {
        HearingDeviceLocalDataManager.Data data = new HearingDeviceLocalDataManager.Data.Builder()
                .ambient(10).groupAmbient(10).ambientControlExpanded(true).build();
        when(mLocalDataManager.get(mDevice)).thenReturn(data);
        when(mAmbientLayout.isExpanded()).thenReturn(true);
        when(mAmbientLayout.isControlExpanded()).thenReturn(true);

        mController.onAmbientChanged(mDevice, 10);
        verify(mController, never()).refresh();
@@ -236,7 +236,7 @@ public class AmbientVolumeUiControllerTest {
        AmbientVolumeController.RemoteAmbientState state =
                new AmbientVolumeController.RemoteAmbientState(MUTE_NOT_MUTED, 0);
        when(mVolumeController.refreshAmbientState(mDevice)).thenReturn(state);
        when(mAmbientLayout.isExpanded()).thenReturn(false);
        when(mAmbientLayout.isControlExpanded()).thenReturn(false);

        mController.onMuteChanged(mDevice, MUTE_NOT_MUTED);
        verify(mController, never()).refresh();
@@ -249,11 +249,11 @@ public class AmbientVolumeUiControllerTest {
    public void refresh_leftAndRightDifferentGainSetting_expandControl() {
        prepareRemoteData(mDevice, 10, MUTE_NOT_MUTED);
        prepareRemoteData(mMemberDevice, 20, MUTE_NOT_MUTED);
        when(mAmbientLayout.isExpanded()).thenReturn(false);
        when(mAmbientLayout.isControlExpanded()).thenReturn(false);

        mController.refresh();

        verify(mAmbientLayout).setExpanded(true);
        verify(mAmbientLayout).setControlExpanded(true);
    }

    @Test
+14 −14
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {
    public void setUp() {
        mLayout = new AmbientVolumeLayout(mContext);
        mLayout.setListener(mListener);
        mLayout.setExpandable(true);
        mLayout.setControlExpandable(true);
        mLayout.setMutable(true);

        prepareDevices();
@@ -100,29 +100,29 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {
    }

    @Test
    public void setExpandable_expandable_expandIconVisible() {
        mLayout.setExpandable(true);
    public void setControlExpandable_expandable_expandIconVisible() {
        mLayout.setControlExpandable(true);

        assertThat(mExpandIcon.getVisibility()).isEqualTo(VISIBLE);
    }

    @Test
    public void setExpandable_notExpandable_expandIconGone() {
        mLayout.setExpandable(false);
    public void setControlExpandable_notExpandable_expandIconGone() {
        mLayout.setControlExpandable(false);

        assertThat(mExpandIcon.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void setExpanded_expanded_assertControlUiCorrect() {
        mLayout.setExpanded(true);
    public void setControlExpanded_expanded_assertControlUiCorrect() {
        mLayout.setControlExpanded(true);

        assertControlUiCorrect();
    }

    @Test
    public void setExpanded_notExpanded_assertControlUiCorrect() {
        mLayout.setExpanded(false);
    public void setControlExpanded_notExpanded_assertControlUiCorrect() {
        mLayout.setControlExpanded(false);

        assertControlUiCorrect();
    }
@@ -158,7 +158,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {
    @Test
    public void updateLayout_unmuteAndExpanded_volumeIconIsCorrect() {
        mLayout.setMuted(false);
        mLayout.setExpanded(true);
        mLayout.setControlExpanded(true);
        mLayout.updateLayout();

        int expectedLevel = calculateVolumeLevel(TEST_LEFT_VOLUME_LEVEL, TEST_RIGHT_VOLUME_LEVEL);
@@ -168,7 +168,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {
    @Test
    public void updateLayout_unmuteAndNotExpanded_volumeIconIsCorrect() {
        mLayout.setMuted(false);
        mLayout.setExpanded(false);
        mLayout.setControlExpanded(false);
        mLayout.updateLayout();

        int expectedLevel = calculateVolumeLevel(TEST_UNIFIED_VOLUME_LEVEL,
@@ -178,7 +178,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {

    @Test
    public void setSliderEnabled_expandedAndLeftIsDisabled_volumeIconIsCorrect() {
        mLayout.setExpanded(true);
        mLayout.setControlExpanded(true);
        mLayout.setSliderEnabled(SIDE_LEFT, false);

        int expectedLevel = calculateVolumeLevel(0, TEST_RIGHT_VOLUME_LEVEL);
@@ -187,7 +187,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {

    @Test
    public void setSliderValue_expandedAndLeftValueChanged_volumeIconIsCorrect() {
        mLayout.setExpanded(true);
        mLayout.setControlExpanded(true);
        mLayout.setSliderValue(SIDE_LEFT, 4);

        int expectedLevel = calculateVolumeLevel(4, TEST_RIGHT_VOLUME_LEVEL);
@@ -199,7 +199,7 @@ public class AmbientVolumeLayoutTest extends SysuiTestCase {
    }

    private void assertControlUiCorrect() {
        final boolean expanded = mLayout.isExpanded();
        final boolean expanded = mLayout.isControlExpanded();
        final Map<Integer, AmbientVolumeSlider> sliders = mLayout.getSliders();
        if (expanded) {
            assertThat(sliders.get(SIDE_UNIFIED).getVisibility()).isEqualTo(GONE);
+6 −6
Original line number Diff line number Diff line
@@ -119,7 +119,7 @@ public class AmbientVolumeLayout extends LinearLayout implements AmbientVolumeUi

        mExpandIcon = requireViewById(R.id.ambient_expand_icon);
        mExpandIcon.setOnClickListener(v -> {
            setExpanded(!mExpanded);
            setControlExpanded(!mExpanded);
            if (mUiEventLogger != null) {
                HearingDevicesUiEvent uiEvent = mExpanded
                        ? HearingDevicesUiEvent.HEARING_DEVICES_AMBIENT_EXPAND_CONTROLS
@@ -139,21 +139,21 @@ public class AmbientVolumeLayout extends LinearLayout implements AmbientVolumeUi
    }

    @Override
    public void setExpandable(boolean expandable) {
    public void setControlExpandable(boolean expandable) {
        mExpandable = expandable;
        if (!mExpandable) {
            setExpanded(false);
            setControlExpanded(false);
        }
        updateExpandIcon();
    }

    @Override
    public boolean isExpandable() {
    public boolean isControlExpandable() {
        return mExpandable;
    }

    @Override
    public void setExpanded(boolean expanded) {
    public void setControlExpanded(boolean expanded) {
        if (!mExpandable && expanded) {
            return;
        }
@@ -163,7 +163,7 @@ public class AmbientVolumeLayout extends LinearLayout implements AmbientVolumeUi
    }

    @Override
    public boolean isExpanded() {
    public boolean isControlExpanded() {
        return mExpanded;
    }