Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0a6f41e authored by Jorge Gil's avatar Jorge Gil Committed by Automerger Merge Worker
Browse files

Merge "Run alignment logic of menu icons when the menu is created" into sc-dev am: bec99582

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13472373

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I439830cad6bf6987df06c705a0769d02ff17a8bf
parents 36fdcb7f bec99582
Loading
Loading
Loading
Loading
+22 −16
Original line number Diff line number Diff line
@@ -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);
    }
}