Merge "Update view when locale changes" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-06-09 00:25:13 +00:00
committed by Android (Google) Code Review
4 changed files with 49 additions and 13 deletions

View File

@@ -237,23 +237,12 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mStatusArea = mView.findViewById(R.id.keyguard_status_area); mStatusArea = mView.findViewById(R.id.keyguard_status_area);
if (mSmartspaceController.isEnabled()) { if (mSmartspaceController.isEnabled()) {
mSmartspaceView = mSmartspaceController.buildAndConnectView(mView);
View ksv = mView.findViewById(R.id.keyguard_slice_view); View ksv = mView.findViewById(R.id.keyguard_slice_view);
int ksvIndex = mStatusArea.indexOfChild(ksv); int ksvIndex = mStatusArea.indexOfChild(ksv);
ksv.setVisibility(View.GONE); ksv.setVisibility(View.GONE);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( addSmartspaceView(ksvIndex);
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);
updateClockLayout(); updateClockLayout();
mKeyguardUnlockAnimationController.setLockscreenSmartspace(mSmartspaceView);
} }
mSecureSettings.registerContentObserverForUser( mSecureSettings.registerContentObserverForUser(
@@ -287,6 +276,30 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
mKeyguardUnlockAnimationListener); 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 * Apply dp changes on font/scale change
*/ */

View File

@@ -224,6 +224,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
@Override @Override
public void onLocaleListChanged() { public void onLocaleListChanged() {
refreshTime(); refreshTime();
mKeyguardClockSwitchController.onLocaleListChanged();
} }
@Override @Override

View File

@@ -229,12 +229,21 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
@Test @Test
public void testSmartspaceEnabledRemovesKeyguardStatusArea() { public void testSmartspaceEnabledRemovesKeyguardStatusArea() {
when(mSmartspaceController.isEnabled()).thenReturn(true); when(mSmartspaceController.isEnabled()).thenReturn(true);
when(mSmartspaceController.buildAndConnectView(any())).thenReturn(mFakeSmartspaceView);
mController.init(); mController.init();
assertEquals(View.GONE, mSliceView.getVisibility()); 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 @Test
public void testSmartspaceDisabledShowsKeyguardStatusArea() { public void testSmartspaceDisabledShowsKeyguardStatusArea() {
when(mSmartspaceController.isEnabled()).thenReturn(false); when(mSmartspaceController.isEnabled()).thenReturn(false);

View File

@@ -25,6 +25,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.statusbar.phone.ScreenOffAnimationController; import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import org.junit.Before; import org.junit.Before;
@@ -117,4 +118,16 @@ public class KeyguardStatusViewControllerTest extends SysuiTestCase {
verify(mKeyguardStatusView).setChildrenTranslationYExcludingMediaView(translationY); 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();
}
} }