diff --git a/libs/WindowManager/Shell/res/layout/letterbox_education_dialog_layout.xml b/libs/WindowManager/Shell/res/layout/letterbox_education_dialog_layout.xml
index 5beaa8798247d..95923763d889c 100644
--- a/libs/WindowManager/Shell/res/layout/letterbox_education_dialog_layout.xml
+++ b/libs/WindowManager/Shell/res/layout/letterbox_education_dialog_layout.xml
@@ -22,81 +22,101 @@
-
-
+ android:alpha="0"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintWidth_max="@dimen/letterbox_education_dialog_width"
+ app:layout_constrainedHeight="true">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/libs/WindowManager/Shell/res/values/dimen.xml b/libs/WindowManager/Shell/res/values/dimen.xml
index 7a398c5045469..8a8231d00195d 100644
--- a/libs/WindowManager/Shell/res/values/dimen.xml
+++ b/libs/WindowManager/Shell/res/values/dimen.xml
@@ -225,15 +225,18 @@
48dp
+
+ 472dp
+
+
+ 16dp
+
140dp
24dp
-
- 444dp
-
200dp
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManager.java
index 3a37b5e5f128b..7c6780a632c09 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManager.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/CompatUIWindowManager.java
@@ -189,15 +189,18 @@ class CompatUIWindowManager extends CompatUIWindowManagerAbstract {
}
@Override
- protected void updateSurfacePosition(Rect taskBounds, Rect stableBounds) {
+ @VisibleForTesting
+ public void updateSurfacePosition() {
if (mLayout == null) {
return;
}
// Position of the button in the container coordinate.
+ final Rect taskBounds = getTaskBounds();
+ final Rect taskStableBounds = getTaskStableBounds();
final int positionX = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL
- ? stableBounds.left - taskBounds.left
- : stableBounds.right - taskBounds.left - mLayout.getMeasuredWidth();
- final int positionY = stableBounds.bottom - taskBounds.top
+ ? taskStableBounds.left - taskBounds.left
+ : taskStableBounds.right - taskBounds.left - mLayout.getMeasuredWidth();
+ final int positionY = taskStableBounds.bottom - taskBounds.top
- mLayout.getMeasuredHeight();
updateSurfacePosition(positionX, positionY);
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 7014fcc0e874c..5679bc479f93c 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
@@ -51,15 +51,15 @@ import com.android.wm.shell.common.SyncTransactionQueue;
*/
public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowManager {
- protected final SyncTransactionQueue mSyncQueue;
- protected final int mDisplayId;
protected final int mTaskId;
-
protected Context mContext;
- protected Configuration mTaskConfig;
- protected ShellTaskOrganizer.TaskListener mTaskListener;
- protected DisplayLayout mDisplayLayout;
- protected final Rect mStableBounds;
+
+ private final SyncTransactionQueue mSyncQueue;
+ private final int mDisplayId;
+ private Configuration mTaskConfig;
+ private ShellTaskOrganizer.TaskListener mTaskListener;
+ private DisplayLayout mDisplayLayout;
+ private final Rect mStableBounds;
/**
* Utility class for adding and releasing a View hierarchy for this {@link
@@ -211,7 +211,7 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
boolean layoutDirectionUpdated =
mTaskConfig.getLayoutDirection() != prevTaskConfig.getLayoutDirection();
if (boundsUpdated || layoutDirectionUpdated) {
- updateSurface();
+ onParentBoundsChanged();
}
if (layout != null && layoutDirectionUpdated) {
@@ -248,8 +248,9 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
displayLayout.getStableBounds(curStableBounds);
mDisplayLayout = displayLayout;
if (!prevStableBounds.equals(curStableBounds)) {
- updateSurface();
+ // mStableBounds should be updated before we call onParentBoundsChanged.
mStableBounds.set(curStableBounds);
+ onParentBoundsChanged();
}
}
@@ -289,51 +290,39 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
}
/** Re-layouts the view host and updates the surface position. */
- public void relayout() {
+ void relayout() {
+ relayout(getWindowLayoutParams());
+ }
+
+ protected void relayout(WindowManager.LayoutParams windowLayoutParams) {
if (mViewHost == null) {
return;
}
- mViewHost.relayout(getWindowLayoutParams());
+ mViewHost.relayout(windowLayoutParams);
updateSurfacePosition();
}
/**
- * Updates the surface following a change in the task bounds, display layout stable bounds,
- * or the layout direction.
+ * Called following a change in the task bounds, display layout stable bounds, or the layout
+ * direction.
*/
- protected void updateSurface() {
+ protected void onParentBoundsChanged() {
updateSurfacePosition();
}
/**
- * Updates the position of the surface with respect to the task bounds and display layout
- * stable bounds.
+ * Updates the position of the surface with respect to the parent bounds.
*/
- @VisibleForTesting
- void updateSurfacePosition() {
- if (mLeash == null) {
- return;
- }
- // Use stable bounds to prevent controls from overlapping with system bars.
- final Rect taskBounds = mTaskConfig.windowConfiguration.getBounds();
- final Rect stableBounds = new Rect();
- mDisplayLayout.getStableBounds(stableBounds);
- stableBounds.intersect(taskBounds);
-
- updateSurfacePosition(taskBounds, stableBounds);
- }
-
- /**
- * Updates the position of the surface with respect to the given {@code taskBounds} and {@code
- * stableBounds}.
- */
- protected abstract void updateSurfacePosition(Rect taskBounds, Rect stableBounds);
+ protected abstract void updateSurfacePosition();
/**
* Updates the position of the surface with respect to the given {@code positionX} and {@code
* positionY}.
*/
protected void updateSurfacePosition(int positionX, int positionY) {
+ if (mLeash == null) {
+ return;
+ }
mSyncQueue.runInSync(t -> {
if (mLeash == null || !mLeash.isValid()) {
Log.w(getTag(), "The leash has been released.");
@@ -347,6 +336,17 @@ public abstract class CompatUIWindowManagerAbstract extends WindowlessWindowMana
return mContext.getResources().getConfiguration().getLayoutDirection();
}
+ protected Rect getTaskBounds() {
+ return mTaskConfig.windowConfiguration.getBounds();
+ }
+
+ /** Returns the intersection between the task bounds and the display layout stable bounds. */
+ protected Rect getTaskStableBounds() {
+ final Rect result = new Rect(mStableBounds);
+ result.intersect(getTaskBounds());
+ return result;
+ }
+
@VisibleForTesting
SurfaceControlViewHost createSurfaceViewHost() {
return new SurfaceControlViewHost(mContext, mContext.getDisplay(), this);
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduAnimationController.java
index eff2602d8eac5..3810ecaf9f9e8 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduAnimationController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterboxedu/LetterboxEduAnimationController.java
@@ -43,6 +43,8 @@ import com.android.internal.policy.TransitionAnimation;
class LetterboxEduAnimationController {
private static final String TAG = "LetterboxEduAnimation";
+ private static final int ENTER_ANIM_START_DELAY_MILLIS = 500;
+
private final TransitionAnimation mTransitionAnimation;
private final String mPackageName;
@AnyRes
@@ -87,6 +89,9 @@ class LetterboxEduAnimationController {
mDialogAnimation.getDuration());
mBackgroundDimAnimator.addListener(getDimAnimatorListener());
+ mDialogAnimation.setStartOffset(ENTER_ANIM_START_DELAY_MILLIS);
+ mBackgroundDimAnimator.setStartDelay(ENTER_ANIM_START_DELAY_MILLIS);
+
dialogContainer.startAnimation(mDialogAnimation);
mBackgroundDimAnimator.start();
}
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 bc1d19bfcec2d..bb6fe98169059 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
@@ -20,7 +20,8 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
-import android.widget.FrameLayout;
+
+import androidx.constraintlayout.widget.ConstraintLayout;
import com.android.wm.shell.R;
@@ -31,7 +32,7 @@ import com.android.wm.shell.R;
* background dim which dismisses the dialog when clicked.
*/
// TODO(b/215316431): Add tests
-class LetterboxEduDialogLayout extends FrameLayout {
+class LetterboxEduDialogLayout extends ConstraintLayout {
// The alpha of a background is a number between 0 (fully transparent) to 255 (fully opaque).
// 204 is simply 255 * 0.8.
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 074610bfce494..bb4d4275d47fc 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
@@ -26,6 +26,7 @@ import android.graphics.Rect;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import com.android.wm.shell.R;
@@ -109,6 +110,7 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
protected View createLayout() {
setSeenLetterboxEducation();
mLayout = inflateLayout();
+ updateDialogMargins();
mAnimationController.startEnterAnimation(mLayout, /* endCallback= */
this::setDismissOnClickListener);
@@ -116,6 +118,22 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
return mLayout;
}
+ private void updateDialogMargins() {
+ if (mLayout == null) {
+ return;
+ }
+ final View dialogContainer = mLayout.getDialogContainer();
+ MarginLayoutParams marginParams = (MarginLayoutParams) dialogContainer.getLayoutParams();
+ int verticalMargin = (int) mContext.getResources().getDimension(
+ R.dimen.letterbox_education_dialog_margin);
+
+ final Rect taskBounds = getTaskBounds();
+ final Rect taskStableBounds = getTaskStableBounds();
+ marginParams.topMargin = taskStableBounds.top - taskBounds.top + verticalMargin;
+ marginParams.bottomMargin = taskBounds.bottom - taskStableBounds.bottom + verticalMargin;
+ dialogContainer.setLayoutParams(marginParams);
+ }
+
private LetterboxEduDialogLayout inflateLayout() {
return (LetterboxEduDialogLayout) LayoutInflater.from(mContext).inflate(
R.layout.letterbox_education_dialog_layout, null);
@@ -150,20 +168,26 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
}
@Override
- protected void updateSurface() {
- // We need to relayout because the layout dimensions depend on the task bounds.
- relayout();
+ protected void onParentBoundsChanged() {
+ if (mLayout == null) {
+ return;
+ }
+ // Both the layout dimensions and dialog margins depend on the parent bounds.
+ WindowManager.LayoutParams windowLayoutParams = getWindowLayoutParams();
+ mLayout.setLayoutParams(windowLayoutParams);
+ updateDialogMargins();
+ relayout(windowLayoutParams);
}
@Override
- protected void updateSurfacePosition(Rect taskBounds, Rect stableBounds) {
+ protected void updateSurfacePosition() {
// 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();
+ final Rect taskBounds = getTaskBounds();
return getWindowLayoutParams(/* width= */ taskBounds.width(), /* height= */
taskBounds.height());
}