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

Commit a8151e4e authored by Abodunrinwa Toki's avatar Abodunrinwa Toki
Browse files

Hide floating toolbar when selection is out of bounds.

Bug: 20212141
Change-Id: I7844308e339ba9a5027c629da8090053011e019d
parent 1f21d2a8
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -40,6 +40,8 @@ public class FloatingActionMode extends ActionMode {
    private final Rect mContentRectOnWindow;
    private final Rect mPreviousContentRectOnWindow;
    private final int[] mViewPosition;
    private final Rect mViewRect;
    private final Rect mScreenRect;
    private final View mOriginatingView;

    private final Runnable mMovingOff = new Runnable() {
@@ -68,6 +70,8 @@ public class FloatingActionMode extends ActionMode {
        mContentRectOnWindow = new Rect();
        mPreviousContentRectOnWindow = new Rect();
        mViewPosition = new int[2];
        mViewRect = new Rect();
        mScreenRect = new Rect();
        mOriginatingView = Preconditions.checkNotNull(originatingView);
        mOriginatingView.getLocationInWindow(mViewPosition);
    }
@@ -117,6 +121,11 @@ public class FloatingActionMode extends ActionMode {
    public void updateViewLocationInWindow() {
        checkToolbarInitialized();
        mOriginatingView.getLocationInWindow(mViewPosition);
        mViewRect.set(
                mViewPosition[0],
                mViewPosition[1],
                mViewPosition[0] + mOriginatingView.getWidth(),
                mViewPosition[1] + mOriginatingView.getHeight());
        repositionToolbar();
    }

@@ -135,6 +144,23 @@ public class FloatingActionMode extends ActionMode {
            mFloatingToolbar.updateLayout();
        }
        mPreviousContentRectOnWindow.set(mContentRectOnWindow);

        if (isContentRectWithinBounds()) {
            mFloatingToolbarVisibilityHelper.setOutOfBounds(false);
        } else {
            mFloatingToolbarVisibilityHelper.setOutOfBounds(true);
        }
    }

    private boolean isContentRectWithinBounds() {
       mScreenRect.set(
           0,
           0,
           mContext.getResources().getDisplayMetrics().widthPixels,
           mContext.getResources().getDisplayMetrics().heightPixels);

       return Rect.intersects(mContentRectOnWindow, mScreenRect)
           && Rect.intersects(mContentRectOnWindow, mViewRect);
    }

    private void notifyContentRectMoving() {