Merge "Run alignment logic of menu icons when the menu is created" into sc-dev
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user