[12/n] Letterbox Education: relayout but don't update surface position when bounds change.

The position of the letterbox education is fixed to the top left corner (0,0) of the task (parent surface) so there is no need to set the position of the surface because this is the default position of a surface (relative to its parent).

We do however need to update the dimensions of the layout (relayout) when the task bounds change because they are dependant on them.

Finally, there is no need to relayout when View#onLayout is called because neither the surface position nor the layout's dimensions depend on changes in the layout itself.

Bug: 215314668
Test: N/A
Change-Id: I17850b4106b13809e51cf2b9b83c6d67151a9df5
This commit is contained in:
tomnatan
2022-02-09 14:21:49 +00:00
committed by Tom Natan
parent f327db5625
commit 3bb6ce2bc7
3 changed files with 21 additions and 26 deletions

View File

@@ -140,11 +140,8 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
/**
* Whether the layout is eligible to be shown according to the internal state of the subclass.
* Returns true by default if subclass doesn't override this method.
*/
protected boolean eligibleToShowLayout() {
return true;
}
protected abstract boolean eligibleToShowLayout();
@Override
public void setConfiguration(Configuration configuration) {
@@ -214,8 +211,7 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
boolean layoutDirectionUpdated =
mTaskConfig.getLayoutDirection() != prevTaskConfig.getLayoutDirection();
if (boundsUpdated || layoutDirectionUpdated) {
// Reposition the UI surfaces.
updateSurfacePosition();
updateSurface();
}
if (layout != null && layoutDirectionUpdated) {
@@ -226,7 +222,6 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
return true;
}
/**
* Updates the visibility of the layout.
*
@@ -253,8 +248,7 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
displayLayout.getStableBounds(curStableBounds);
mDisplayLayout = displayLayout;
if (!prevStableBounds.equals(curStableBounds)) {
// Stable bounds changed, update UI surface positions.
updateSurfacePosition();
updateSurface();
mStableBounds.set(curStableBounds);
}
}
@@ -303,6 +297,14 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
updateSurfacePosition();
}
/**
* Updates the surface following a change in the task bounds, display layout stable bounds,
* or the layout direction.
*/
protected void updateSurface() {
updateSurfacePosition();
}
/**
* Updates the position of the surface with respect to the task bounds and display layout
* stable bounds.

View File

@@ -36,8 +36,6 @@ class LetterboxEduDialogLayout extends FrameLayout {
// The alpha of a background is a number between 0 (fully transparent) to 255 (fully opaque).
// 204 is simply 255 * 0.8.
static final int BACKGROUND_DIM_ALPHA = 204;
private LetterboxEduWindowManager mWindowManager;
private View mDialogContainer;
private Drawable mBackgroundDim;
@@ -58,10 +56,6 @@ class LetterboxEduDialogLayout extends FrameLayout {
super(context, attrs, defStyleAttr, defStyleRes);
}
void inject(LetterboxEduWindowManager windowManager) {
mWindowManager = windowManager;
}
View getDialogContainer() {
return mDialogContainer;
}
@@ -70,13 +64,6 @@ class LetterboxEduDialogLayout extends FrameLayout {
return mBackgroundDim;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
// Need to relayout after visibility changes since they affect size.
mWindowManager.relayout();
}
/**
* Register a callback for the dismiss button and background dim.
*

View File

@@ -103,7 +103,6 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
protected View createLayout() {
setSeenLetterboxEducation();
mLayout = inflateLayout();
mLayout.inject(this);
mAnimationController.startEnterAnimation(mLayout, /* endCallback= */
this::setDismissOnClickListener);
@@ -144,16 +143,23 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
return super.updateCompatInfo(taskInfo, taskListener, canShow);
}
@Override
protected void updateSurface() {
// We need to relayout because the layout dimensions depend on the task bounds.
relayout();
}
@Override
protected void updateSurfacePosition(Rect taskBounds, Rect stableBounds) {
updateSurfacePosition(/* positionX= */ taskBounds.left, /* positionY= */ taskBounds.top);
// Nothing to do, since the position of the surface is fixed to the top left corner (0,0)
// of the task (parent surface), which is the default position of a surface.
}
@Override
protected WindowManager.LayoutParams getWindowLayoutParams() {
final Rect taskBounds = mTaskConfig.windowConfiguration.getBounds();
return getWindowLayoutParams(/* width= */ taskBounds.right - taskBounds.left,
/* height= */ taskBounds.bottom - taskBounds.top);
return getWindowLayoutParams(/* width= */ taskBounds.width(), /* height= */
taskBounds.height());
}
private boolean getHasSeenLetterboxEducation() {