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

Commit 97f3a42d authored by Matt Pietal's avatar Matt Pietal
Browse files

Update view when locale changes

Updating the locale would leave lockscreen smartspace showing the old
locale. Need to force a rebuild of the view to reflect the update.

Fixes: 225843613
Test: atest KeyguardStatusViewControllerTest KeyguardClockSwitchControllerTest
Change-Id: If37e138925c7ea8cb13dad4fa2f687215d1a7ff9
parent 94c91a89
Loading
Loading
Loading
Loading
+25 −12
Original line number Diff line number Diff line
@@ -237,23 +237,12 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        mStatusArea = mView.findViewById(R.id.keyguard_status_area);

        if (mSmartspaceController.isEnabled()) {
            mSmartspaceView = mSmartspaceController.buildAndConnectView(mView);
            View ksv = mView.findViewById(R.id.keyguard_slice_view);
            int ksvIndex = mStatusArea.indexOfChild(ksv);
            ksv.setVisibility(View.GONE);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    MATCH_PARENT, WRAP_CONTENT);

            mStatusArea.addView(mSmartspaceView, ksvIndex, lp);
            int startPadding = getContext().getResources()
                    .getDimensionPixelSize(R.dimen.below_clock_padding_start);
            int endPadding = getContext().getResources()
                    .getDimensionPixelSize(R.dimen.below_clock_padding_end);
            mSmartspaceView.setPaddingRelative(startPadding, 0, endPadding, 0);

            addSmartspaceView(ksvIndex);
            updateClockLayout();
            mKeyguardUnlockAnimationController.setLockscreenSmartspace(mSmartspaceView);
        }

        mSecureSettings.registerContentObserverForUser(
@@ -287,6 +276,30 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
                mKeyguardUnlockAnimationListener);
    }

    void onLocaleListChanged() {
        if (mSmartspaceController.isEnabled()) {
            int index = mStatusArea.indexOfChild(mSmartspaceView);
            if (index >= 0) {
                mStatusArea.removeView(mSmartspaceView);
                addSmartspaceView(index);
            }
        }
    }

    private void addSmartspaceView(int index) {
        mSmartspaceView = mSmartspaceController.buildAndConnectView(mView);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                MATCH_PARENT, WRAP_CONTENT);
        mStatusArea.addView(mSmartspaceView, index, lp);
        int startPadding = getContext().getResources().getDimensionPixelSize(
                R.dimen.below_clock_padding_start);
        int endPadding = getContext().getResources().getDimensionPixelSize(
                R.dimen.below_clock_padding_end);
        mSmartspaceView.setPaddingRelative(startPadding, 0, endPadding, 0);

        mKeyguardUnlockAnimationController.setLockscreenSmartspace(mSmartspaceView);
    }

    /**
     * Apply dp changes on font/scale change
     */
+1 −0
Original line number Diff line number Diff line
@@ -224,6 +224,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
        @Override
        public void onLocaleListChanged() {
            refreshTime();
            mKeyguardClockSwitchController.onLocaleListChanged();
        }

        @Override
+10 −1
Original line number Diff line number Diff line
@@ -229,12 +229,21 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
    @Test
    public void testSmartspaceEnabledRemovesKeyguardStatusArea() {
        when(mSmartspaceController.isEnabled()).thenReturn(true);
        when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView);
        mController.init();

        assertEquals(View.GONE, mSliceView.getVisibility());
    }

    @Test
    public void onLocaleListChangedRebuildsSmartspaceView() {
        when(mSmartspaceController.isEnabled()).thenReturn(true);
        mController.init();

        mController.onLocaleListChanged();
        // Should be called once on initial setup, then once again for locale change
        verify(mSmartspaceController, times(2)).buildAndConnectView(mView);
    }

    @Test
    public void testSmartspaceDisabledShowsKeyguardStatusArea() {
        when(mSmartspaceController.isEnabled()).thenReturn(false);
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController;

import org.junit.Before;
@@ -117,4 +118,16 @@ public class KeyguardStatusViewControllerTest extends SysuiTestCase {

        verify(mKeyguardStatusView).setChildrenTranslationYExcludingMediaView(translationY);
    }

    @Test
    public void onLocaleListChangedNotifiesClockSwitchController() {
        ArgumentCaptor<ConfigurationListener> configurationListenerArgumentCaptor =
                ArgumentCaptor.forClass(ConfigurationListener.class);

        mController.onViewAttached();
        verify(mConfigurationController).addCallback(configurationListenerArgumentCaptor.capture());

        configurationListenerArgumentCaptor.getValue().onLocaleListChanged();
        verify(mKeyguardClockSwitchController).onLocaleListChanged();
    }
}