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

Commit c82a7e34 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge changes Ifd2de38a,I57633d60

* changes:
  Divider tuning
  Fix unneccesary activity relaunches
parents 88766a2b df012d51
Loading
Loading
Loading
Loading
+46 −15
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.policy;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.Log;

import java.util.ArrayList;

@@ -30,6 +31,9 @@ import java.util.ArrayList;
 */
public class DividerSnapAlgorithm {

    private static final int MIN_FLING_VELOCITY_DP_PER_SECOND = 400;
    private static final int MIN_DISMISS_VELOCITY_DP_PER_SECOND = 600;

    /**
     * 3 snap targets: left/top has 16:9 ratio (for videos), 1:1, and right/bottom has 16:9 ratio
     */
@@ -46,6 +50,7 @@ public class DividerSnapAlgorithm {
    private static final int SNAP_ONLY_1_1 = 2;

    private final float mMinFlingVelocityPxPerSecond;
    private final float mMinDismissVelocityPxPerSecond;
    private final int mDisplayWidth;
    private final int mDisplayHeight;
    private final int mDividerSize;
@@ -64,10 +69,12 @@ public class DividerSnapAlgorithm {
    private final SnapTarget mDismissEndTarget;
    private final SnapTarget mMiddleTarget;

    public DividerSnapAlgorithm(Resources res, float minFlingVelocityPxPerSecond,
            int displayWidth, int displayHeight, int dividerSize, boolean isHorizontalDivision,
            Rect insets) {
        mMinFlingVelocityPxPerSecond = minFlingVelocityPxPerSecond;
    public DividerSnapAlgorithm(Resources res, int displayWidth, int displayHeight, int dividerSize,
            boolean isHorizontalDivision, Rect insets) {
        mMinFlingVelocityPxPerSecond =
                MIN_FLING_VELOCITY_DP_PER_SECOND * res.getDisplayMetrics().density;
        mMinDismissVelocityPxPerSecond =
                MIN_DISMISS_VELOCITY_DP_PER_SECOND * res.getDisplayMetrics().density;
        mDividerSize = dividerSize;
        mDisplayWidth = displayWidth;
        mDisplayHeight = displayHeight;
@@ -85,15 +92,24 @@ public class DividerSnapAlgorithm {
    }

    public SnapTarget calculateSnapTarget(int position, float velocity) {
        if (Math.abs(velocity) < mMinFlingVelocityPxPerSecond) {
            return snap(position);
        return calculateSnapTarget(position, velocity, true /* hardDismiss */);
    }
        if (position < mFirstSplitTarget.position && velocity < 0) {

    /**
     * @param position the top/left position of the divider
     * @param velocity current dragging velocity
     * @param hardDismiss if set, make it a bit harder to get reach the dismiss targets
     */
    public SnapTarget calculateSnapTarget(int position, float velocity, boolean hardDismiss) {
        if (position < mFirstSplitTarget.position && velocity < -mMinDismissVelocityPxPerSecond) {
            return mDismissStartTarget;
        }
        if (position > mLastSplitTarget.position && velocity > 0) {
        if (position > mLastSplitTarget.position && velocity > mMinDismissVelocityPxPerSecond) {
            return mDismissEndTarget;
        }
        if (Math.abs(velocity) < mMinFlingVelocityPxPerSecond) {
            return snap(position, hardDismiss);
        }
        if (velocity < 0) {
            return mFirstSplitTarget;
        } else {
@@ -102,7 +118,7 @@ public class DividerSnapAlgorithm {
    }

    public SnapTarget calculateNonDismissingSnapTarget(int position) {
        SnapTarget target = snap(position);
        SnapTarget target = snap(position, false /* hardDismiss */);
        if (target == mDismissStartTarget) {
            return mFirstSplitTarget;
        } else if (target == mDismissEndTarget) {
@@ -146,12 +162,16 @@ public class DividerSnapAlgorithm {
        return mDismissEndTarget;
    }

    private SnapTarget snap(int position) {
    private SnapTarget snap(int position, boolean hardDismiss) {
        int minIndex = -1;
        int minDistance = Integer.MAX_VALUE;
        float minDistance = Float.MAX_VALUE;
        int size = mTargets.size();
        for (int i = 0; i < size; i++) {
            int distance = Math.abs(position - mTargets.get(i).position);
            SnapTarget target = mTargets.get(i);
            float distance = Math.abs(position - target.position);
            if (hardDismiss) {
                distance /= target.distanceMultiplier;
            }
            if (distance < minDistance) {
                minIndex = i;
                minDistance = distance;
@@ -165,7 +185,7 @@ public class DividerSnapAlgorithm {
        int dividerMax = isHorizontalDivision
                ? mDisplayHeight
                : mDisplayWidth;
        mTargets.add(new SnapTarget(-mDividerSize, SnapTarget.FLAG_DISMISS_START));
        mTargets.add(new SnapTarget(-mDividerSize, SnapTarget.FLAG_DISMISS_START, 0.35f));
        switch (mSnapMode) {
            case SNAP_MODE_16_9:
                addRatio16_9Targets(isHorizontalDivision);
@@ -177,7 +197,7 @@ public class DividerSnapAlgorithm {
                addMiddleTarget(isHorizontalDivision);
                break;
        }
        mTargets.add(new SnapTarget(dividerMax, SnapTarget.FLAG_DISMISS_END));
        mTargets.add(new SnapTarget(dividerMax, SnapTarget.FLAG_DISMISS_END, 0.35f));
    }

    private void addFixedDivisionTargets(boolean isHorizontalDivision) {
@@ -232,9 +252,20 @@ public class DividerSnapAlgorithm {
        public final int position;
        public final int flag;

        /**
         * Multiplier used to calculate distance to snap position. The lower this value, the harder
         * it's to snap on this target
         */
        private final float distanceMultiplier;

        public SnapTarget(int position, int flag) {
            this(position, flag, 1f);
        }

        public SnapTarget(int position, int flag, float distanceMultiplier) {
            this.position = position;
            this.flag = flag;
            this.distanceMultiplier = distanceMultiplier;
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -229,7 +229,7 @@
                  android:resumeWhilePausing="true"
                  android:screenOrientation="behind"
                  android:resizeableActivity="true"
                  android:configChanges="orientation|screenSize|smallestScreenSize"
                  android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|layoutDirection"
                  android:theme="@style/RecentsTheme.Wallpaper">
            <intent-filter>
                <action android:name="com.android.systemui.recents.TOGGLE_RECENTS" />
+13 −10
Original line number Diff line number Diff line
@@ -167,8 +167,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
    public boolean startDragging(boolean animate) {
        mHandle.setTouching(true, animate);
        mDockSide = mWindowManagerProxy.getDockSide();
        mSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(),
                mFlingAnimationUtils.getMinVelocityPxPerSecond(), mDisplayWidth,
        mSnapAlgorithm = new DividerSnapAlgorithm(getContext().getResources(), mDisplayWidth,
                mDisplayHeight, mDividerSize, isHorizontalDivision(), mStableInsets);
        if (mDockSide != WindowManager.DOCKED_INVALID) {
            mWindowManagerProxy.setResizing(true);
@@ -180,9 +179,9 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        }
    }

    public void stopDragging(int position, float velocity) {
    public void stopDragging(int position, float velocity, boolean avoidDismissStart) {
        mHandle.setTouching(false, true /* animate */);
        fling(position, velocity);
        fling(position, velocity, avoidDismissStart);
        mWindowManager.setSlippery(true);
        releaseBackground();
    }
@@ -225,7 +224,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                if (mMoving && mDockSide != WindowManager.DOCKED_INVALID) {
                    int position = calculatePosition(x, y);
                    SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position,
                            0 /* velocity */);
                            0 /* velocity */, false /* hardDismiss */);
                    resizeStack(calculatePosition(x, y), snapTarget.position, snapTarget);
                }
                break;
@@ -239,7 +238,7 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                mVelocityTracker.computeCurrentVelocity(1000);
                int position = calculatePosition(x, y);
                stopDragging(position, isHorizontalDivision() ? mVelocityTracker.getYVelocity()
                        : mVelocityTracker.getXVelocity());
                        : mVelocityTracker.getXVelocity(), false /* avoidDismissStart */);
                mMoving = false;
                break;
        }
@@ -250,8 +249,12 @@ public class DividerView extends FrameLayout implements OnTouchListener,
        event.setLocation(event.getRawX(), event.getRawY());
    }

    private void fling(int position, float velocity) {
        final SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position, velocity);
    private void fling(int position, float velocity, boolean avoidDismissStart) {
        SnapTarget snapTarget = mSnapAlgorithm.calculateSnapTarget(position, velocity);
        if (avoidDismissStart && snapTarget == mSnapAlgorithm.getDismissStartTarget()) {
            snapTarget = mSnapAlgorithm.getFirstSplitTarget();
        }
        final SnapTarget finalTarget = snapTarget;

        ValueAnimator anim = ValueAnimator.ofInt(position, snapTarget.position);
        anim.addUpdateListener(new AnimatorUpdateListener() {
@@ -260,13 +263,13 @@ public class DividerView extends FrameLayout implements OnTouchListener,
                resizeStack((Integer) animation.getAnimatedValue(),
                        animation.getAnimatedFraction() == 1f
                                ? TASK_POSITION_SAME
                                : snapTarget.position, snapTarget);
                                : finalTarget.position, finalTarget);
            }
        });
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                commitSnapFlags(snapTarget);
                commitSnapFlags(finalTarget);
                mWindowManagerProxy.setResizing(false);
                mDockSide = WindowManager.DOCKED_INVALID;
            }
+3 −2
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
            if (mDragMode == DRAG_MODE_DIVIDER) {
                int position = !mIsVertical ? (int) event.getRawY() : (int) event.getRawX();
                SnapTarget snapTarget = mDivider.getView().getSnapAlgorithm()
                        .calculateSnapTarget(position, 0f /* velocity */);
                        .calculateSnapTarget(position, 0f /* velocity */, false /* hardDismiss */);
                mDivider.getView().resizeStack(position, snapTarget.position, snapTarget);
            } else if (mDragMode == DRAG_MODE_RECENTS) {
                mRecentsComponent.onDraggingInRecents(event.getRawY());
@@ -242,7 +242,8 @@ public class NavigationBarGestureHelper extends GestureDetector.SimpleOnGestureL
                                : (int) event.getRawY(),
                        mIsVertical
                                ? mVelocityTracker.getXVelocity()
                                : mVelocityTracker.getYVelocity());
                                : mVelocityTracker.getYVelocity(),
                        true /* avoidDismissStart */);
            } else if (mDragMode == DRAG_MODE_RECENTS) {
                mRecentsComponent.onDraggingInRecentsEnded(mVelocityTracker.getYVelocity());
            }
+8 −0
Original line number Diff line number Diff line
@@ -4243,6 +4243,14 @@ final class ActivityStack {

    private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
            Configuration oldTaskOverride) {

        // If we went from full-screen to non-full-screen, make sure to use the correct
        // configuration task diff, so the diff stays as small as possible.
        if (Configuration.EMPTY.equals(oldTaskOverride)
                && !Configuration.EMPTY.equals(taskConfig)) {
            oldTaskOverride = record.task.extractOverrideConfig(record.configuration);
        }

        // Determine what has changed.  May be nothing, if this is a config
        // that has come back from the app after going idle.  In that case
        // we just want to leave the official config object now in the
Loading