From 3f51e3cfd474fa6bb2a77f397eceeeb8954d2b1f Mon Sep 17 00:00:00 2001 From: lumark Date: Tue, 23 Jul 2019 21:18:17 +0800 Subject: Fix ActivityView surface can't visible for ActivityViewTest CL [1] introduced ActivityView's surface view set alpha as zero by default. but SurfaceView ignores alpha value by default. So to archieve SurfaceView can support alpha value and then introduced CL[2]. with that CL, it will affect ActivityView that can't see the surface because of this zero alpha value. Since CLs[1] & [2] are mainly considered for BubbleController to implement content visiblity with setting surface view's alpha value without flickering, and in BubbleExpandedView#onFinishInflate has already called setContentVisibility(false) to set ActivityView's alpha value as zero before add this view. So removing ActivityView's default zero alpha value would be fine, since it may not always the case that need to set zero alpha but need to show the black rectangle surface for user. (i.e. ActivityViewTest or Android Auto) Also, refined ActivityView#setAlpha for some stuff to make it clear. [1]: Ie5aed373996419b059935889b564ca91c2e3cf23 [2]: I86847de59109b2adf12a2c7c50c988c2cbcf0450 Bug: 137937105 Test: manual as below steps 1) make & install ActivityViewTest 2) launch "AV Main" shortcut 3) press "Test ActivityView" -> "Launch test activity" 4) see if launched Acitvity is visible as expected. Test: atest ActivityViewTest, observe if ActivityView is visible during testing. Change-Id: Iaf480912f06a6851001a42bf90e4d962c8a88a37 --- core/java/android/app/ActivityView.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'core/java/android/app/ActivityView.java') diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index 415ec64dc126..e8918285777b 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -120,8 +120,10 @@ public class ActivityView extends ViewGroup { mActivityTaskManager = ActivityTaskManager.getService(); mSurfaceView = new SurfaceView(context); + // Since ActivityView#getAlpha has been overridden, we should use parent class's alpha + // as master to synchronize surface view's alpha value. + mSurfaceView.setAlpha(super.getAlpha()); mSurfaceView.setUseAlpha(); - mSurfaceView.setAlpha(0f); mSurfaceCallback = new SurfaceCallback(); mSurfaceView.getHolder().addCallback(mSurfaceCallback); addView(mSurfaceView); @@ -348,9 +350,20 @@ public class ActivityView extends ViewGroup { mSurfaceView.layout(0 /* left */, 0 /* top */, r - l /* right */, b - t /* bottom */); } + /** + * Sets the alpha value when the content of {@link SurfaceView} needs to show or hide. + *

Note: The surface view may ignore the alpha value in some cases. Refer to + * {@link SurfaceView#setAlpha} for more details. + * + * @param alpha The opacity of the view. + */ @Override public void setAlpha(float alpha) { - mSurfaceView.setAlpha(alpha); + super.setAlpha(alpha); + + if (mSurfaceView != null) { + mSurfaceView.setAlpha(alpha); + } } @Override -- cgit v1.2.3