diff options
| author | 2022-02-09 14:21:49 +0000 | |
|---|---|---|
| committer | 2022-02-10 23:15:20 +0000 | |
| commit | 3bb6ce2bc761194e7026e04358f8cc2ea1de5e09 (patch) | |
| tree | eb727be4fe5fd229da40ad12936b8d173a79170a | |
| parent | f327db562514924d2837156c4b3cca8348b6de08 (diff) | |
[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
3 files changed, 21 insertions, 26 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManagerAbstract.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManagerAbstract.java index bdf9d513f298..7014fcc0e874 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManagerAbstract.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManagerAbstract.java @@ -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); } } @@ -304,6 +298,14 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana } /** + * 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. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduDialogLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduDialogLayout.java index b22b829eebd8..bc1d19bfcec2 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduDialogLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduDialogLayout.java @@ -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. * diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java index d5aefb1a7e5c..c461ebcb55ea 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduWindowManager.java @@ -103,7 +103,6 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { protected View createLayout() { setSeenLetterboxEducation(); mLayout = inflateLayout(); - mLayout.inject(this); mAnimationController.startEnterAnimation(mLayout, /* endCallback= */ this::setDismissOnClickListener); @@ -145,15 +144,22 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract { } @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() { |