Merge "Set communal view alpha."

This commit is contained in:
Bryce Lee
2021-08-31 17:15:07 +00:00
committed by Android (Google) Code Review
5 changed files with 47 additions and 0 deletions

View File

@@ -160,6 +160,21 @@ public class CommunalHostViewController extends ViewController<CommunalHostView>
statusBarState, keyguardFadingAway, goingToFullShade, oldStatusBarState);
}
/**
* Set keyguard status view alpha.
*/
public void setAlpha(float alpha) {
if (!mKeyguardVisibilityHelper.isVisibilityAnimating()) {
mView.setAlpha(alpha);
// Some communal view implementations, such as SurfaceViews, do not behave correctly
// inheriting the alpha of their parent. Directly set child alpha here to work around
// this.
for (int i = mView.getChildCount() - 1; i >= 0; --i) {
mView.getChildAt(i).setAlpha(alpha);
}
}
}
@Override
public void init() {
super.init();

View File

@@ -209,6 +209,7 @@ public class CommunalSurfaceViewController extends ViewController<SurfaceView> {
if (surfacePackage != null) {
mView.setChildSurfacePackage(surfacePackage);
mView.setZOrderOnTop(true);
mView.setUseAlpha();
mView.postInvalidate();
mCommunalStateController.setCommunalViewShowing(true);
} else {

View File

@@ -1574,6 +1574,12 @@ public class NotificationPanelViewController extends PanelViewController {
return true;
}
private void updateCommunal() {
if (mCommunalViewController != null) {
mCommunalViewController.setAlpha(mKeyguardOnlyContentAlpha);
}
}
private void updateClock() {
float alpha = mClockPositionResult.clockAlpha * mKeyguardOnlyContentAlpha;
mKeyguardStatusViewController.setAlpha(alpha);
@@ -2675,6 +2681,7 @@ public class NotificationPanelViewController extends PanelViewController {
updateKeyguardBottomAreaAlpha();
}
updateClock();
updateCommunal();
}
private void trackMovement(MotionEvent event) {

View File

@@ -77,6 +77,9 @@ public class CommunalHostViewControllerTest extends SysuiTestCase {
@Mock
private CommunalSource mCommunalSource;
@Mock
private View mChildView;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
@@ -211,4 +214,16 @@ public class CommunalHostViewControllerTest extends SysuiTestCase {
// Verify state controller is notified communal view is hidden.
verify(mCommunalStateController).setCommunalViewShowing(false);
}
@Test
public void testAlphaPropagation() {
final float alpha = 0.8f;
// Ensure alpha setting is propagated to children.
when(mCommunalView.getChildCount()).thenReturn(1);
when(mCommunalView.getChildAt(0)).thenReturn(mChildView);
mController.setAlpha(alpha);
verify(mChildView).setAlpha(alpha);
verify(mCommunalView).setAlpha(alpha);
}
}

View File

@@ -29,6 +29,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeast;
@@ -901,6 +902,14 @@ public class NotificationPanelViewTest extends SysuiTestCase {
anyBoolean(), anyBoolean(), anyInt());
}
@Test
public void testCommunalAlphaUpdate() {
// Verify keyguard content alpha changes are propagate. Note the actual value set is not
// checked since an interpolation is applied to the incoming value.
mNotificationPanelViewController.setKeyguardOnlyContentAlpha(0.8f);
verify(mCommunalHostViewController).setAlpha(anyFloat());
}
private void triggerPositionClockAndNotifications() {
mNotificationPanelViewController.closeQs();
}