From 42e039cd6a37b20fc99fdedaadfafcceea050736 Mon Sep 17 00:00:00 2001 From: "jorgegil@google.com" Date: Wed, 3 Feb 2021 14:48:37 -0800 Subject: [PATCH] Run alignment logic of menu icons when the menu is created The algorithm's icon arrangement logic was previously ran in onBoundsChange, which could cause the icons to be misaligned the very first time the menu is shown after being created. This change ensures that the algorithm does an initial run when the menu is first created. Bug: 178708863 Test: manual - open YT PIP, tap to see menu, see the gear icon is aligned to the top-start corner Change-Id: I2cb53578db897af62be7ebd3ed40946e16606568 --- .../pip/phone/PipMenuIconsAlgorithm.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuIconsAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuIconsAlgorithm.java index 6d12752d9218f..3eeba6eb53668 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuIconsAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMenuIconsAlgorithm.java @@ -31,7 +31,6 @@ public class PipMenuIconsAlgorithm { private static final String TAG = "PipMenuIconsAlgorithm"; - private boolean mFinishedLayout = false; protected ViewGroup mViewRoot; protected ViewGroup mTopEndContainer; protected View mDragHandle; @@ -51,27 +50,16 @@ public class PipMenuIconsAlgorithm { mDragHandle = dragHandle; mSettingsButton = settingsButton; mDismissButton = dismissButton; + + bindInitialViewState(); } /** * Updates the position of the drag handle based on where the PIP window is on the screen. */ public void onBoundsChanged(Rect bounds) { - if (mViewRoot == null || mTopEndContainer == null || mDragHandle == null - || mSettingsButton == null || mDismissButton == null) { - Log.e(TAG, "One if the required views is null."); - return; - } - - //We only need to calculate the layout once since it does not change. - if (!mFinishedLayout) { - mTopEndContainer.removeView(mSettingsButton); - mViewRoot.addView(mSettingsButton); - - setLayoutGravity(mDragHandle, Gravity.START | Gravity.TOP); - setLayoutGravity(mSettingsButton, Gravity.START | Gravity.TOP); - mFinishedLayout = true; - } + // On phones, the menu icons are always static and will never move based on the PIP window + // position. No need to do anything here. } /** @@ -84,4 +72,22 @@ public class PipMenuIconsAlgorithm { v.setLayoutParams(params); } } + + /** Calculate the initial state of the menu icons. Called when the menu is first created. */ + private void bindInitialViewState() { + if (mViewRoot == null || mTopEndContainer == null || mDragHandle == null + || mSettingsButton == null || mDismissButton == null) { + Log.e(TAG, "One of the required views is null."); + return; + } + // The menu view layout starts out with the settings button aligned at the top|end of the + // view group next to the dismiss button. On phones, the settings button should be aligned + // to the top|start of the view, so move it to parent view group to then align it to the + // top|start of the menu. + mTopEndContainer.removeView(mSettingsButton); + mViewRoot.addView(mSettingsButton); + + setLayoutGravity(mDragHandle, Gravity.START | Gravity.TOP); + setLayoutGravity(mSettingsButton, Gravity.START | Gravity.TOP); + } }