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

Commit 1b12ef55 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Divider tuning

- Take insets into account for calculating dismissing fraction,
but don't dim into 100% when the device has insets at that
side.
- When applying parallax to the top side, apply less.

Change-Id: Id1af37e6f7af43ec3682dad4ad1ce68034301b4d
parent c6c89a82
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ public class DividerSnapAlgorithm {
    private final Rect mInsets = new Rect();
    private final int mSnapMode;
    private final float mFixedRatio;
    private boolean mIsHorizontalDivision;

    /** The first target which is still splitting the screen */
    private final SnapTarget mFirstSplitTarget;
@@ -78,6 +79,7 @@ public class DividerSnapAlgorithm {
        mDividerSize = dividerSize;
        mDisplayWidth = displayWidth;
        mDisplayHeight = displayHeight;
        mIsHorizontalDivision = isHorizontalDivision;
        mInsets.set(insets);
        mSnapMode = res.getInteger(
                com.android.internal.R.integer.config_dockedStackDividerSnapMode);
@@ -130,10 +132,12 @@ public class DividerSnapAlgorithm {

    public float calculateDismissingFraction(int position) {
        if (position < mFirstSplitTarget.position) {
            return 1f - (float) position / mFirstSplitTarget.position;
            return 1f - (float) (position - getStartInset())
                    / (mFirstSplitTarget.position - getStartInset());
        } else if (position > mLastSplitTarget.position) {
            return (float) (position - mLastSplitTarget.position)
                    / (mDismissEndTarget.position - mLastSplitTarget.position);
                    / (mDismissEndTarget.position - getEndInset()
                            - mLastSplitTarget.position - mDividerSize);
        }
        return 0f;
    }
@@ -167,6 +171,22 @@ public class DividerSnapAlgorithm {
        return mDismissEndTarget;
    }

    private int getStartInset() {
        if (mIsHorizontalDivision) {
            return mInsets.top;
        } else {
            return mInsets.left;
        }
    }

    private int getEndInset() {
        if (mIsHorizontalDivision) {
            return mInsets.bottom;
        } else {
            return mInsets.right;
        }
    }

    private SnapTarget snap(int position, boolean hardDismiss) {
        int minIndex = -1;
        float minDistance = Float.MAX_VALUE;
+53 −8
Original line number Diff line number Diff line
@@ -184,8 +184,17 @@ public class DividerView extends FrameLayout implements OnTouchListener,

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (mStableInsets.left != insets.getStableInsetLeft()
                || mStableInsets.top != insets.getStableInsetTop()
                || mStableInsets.right != insets.getStableInsetRight()
                || mStableInsets.bottom != insets.getStableInsetBottom()) {
            mStableInsets.set(insets.getStableInsetLeft(), insets.getStableInsetTop(),
                    insets.getStableInsetRight(), insets.getStableInsetBottom());
            if (mSnapAlgorithm != null) {
                mSnapAlgorithm = null;
                getSnapAlgorithm();
            }
        }
        return super.onApplyWindowInsets(insets);
    }

@@ -496,12 +505,42 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        } else {
            mWindowManagerProxy.resizeDockedStack(mDockedRect, null, null, null, null);
        }
        SnapTarget closestDismissTarget = mSnapAlgorithm.getClosestDismissTarget(position);
        float dimFraction = getDimFraction(position, closestDismissTarget);
        mWindowManagerProxy.setResizeDimLayer(dimFraction != 0f,
                getStackIdForDismissTarget(closestDismissTarget),
                dimFraction);
    }

    private float getDimFraction(int position, SnapTarget dismissTarget) {
        float fraction = mSnapAlgorithm.calculateDismissingFraction(position);
        fraction = Math.max(0, Math.min(fraction, 1f));
        fraction = DIM_INTERPOLATOR.getInterpolation(fraction);
        mWindowManagerProxy.setResizeDimLayer(fraction != 0f,
                getStackIdForDismissTarget(mSnapAlgorithm.getClosestDismissTarget(position)),
                fraction);
        if (hasInsetsAtDismissTarget(dismissTarget)) {

            // Less darkening with system insets.
            fraction *= 0.8f;
        }
        return fraction;
    }

    /**
     * @return true if and only if there are system insets at the location of the dismiss target
     */
    private boolean hasInsetsAtDismissTarget(SnapTarget dismissTarget) {
        if (isHorizontalDivision()) {
            if (dismissTarget == mSnapAlgorithm.getDismissStartTarget()) {
                return mStableInsets.top != 0;
            } else {
                return mStableInsets.bottom != 0;
            }
        } else {
            if (dismissTarget == mSnapAlgorithm.getDismissStartTarget()) {
                return mStableInsets.left != 0;
            } else {
                return mStableInsets.right != 0;
            }
        }
    }

    /**
@@ -587,7 +626,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        }
        if (dismissTarget != null && fraction > 0f
                && isDismissing(splitTarget, position, dockSide)) {
            fraction = calculateParallaxDismissingFraction(fraction);
            fraction = calculateParallaxDismissingFraction(fraction, dockSide);
            int offsetPosition = (int) (taskPosition +
                    fraction * (dismissTarget.position - splitTarget.position));
            int width = taskRect.width();
@@ -617,8 +656,14 @@ public class DividerView extends FrameLayout implements OnTouchListener,
     * @return for a specified {@code fraction}, this returns an adjusted value that simulates a
     *         slowing down parallax effect
     */
    private static float calculateParallaxDismissingFraction(float fraction) {
        return SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;
    private static float calculateParallaxDismissingFraction(float fraction, int dockSide) {
        float result = SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;

        // Less parallax at the top, just because.
        if (dockSide == WindowManager.DOCKED_TOP) {
            result /= 2f;
        }
        return result;
    }

    private static boolean isDismissing(SnapTarget snapTarget, int position, int dockSide) {