When creating docked stack, use SnapAlgorithm

To make sure the bounds snapped to a snap position are
set from the very beginning.

Change-Id: I0ebc463926dd17e0deeefc211b097f28a6456b96
This commit is contained in:
Jorim Jaggi
2016-01-06 17:18:44 +01:00
parent f3b34603de
commit d434dcbfc9
2 changed files with 26 additions and 7 deletions

View File

@@ -62,6 +62,7 @@ public class DividerSnapAlgorithm {
private final SnapTarget mDismissStartTarget;
private final SnapTarget mDismissEndTarget;
private final SnapTarget mMiddleTarget;
public DividerSnapAlgorithm(Resources res, float minFlingVelocityPxPerSecond,
int displayWidth, int displayHeight, int dividerSize, boolean isHorizontalDivision,
@@ -80,6 +81,7 @@ public class DividerSnapAlgorithm {
mLastSplitTarget = mTargets.get(mTargets.size() - 2);
mDismissStartTarget = mTargets.get(0);
mDismissEndTarget = mTargets.get(mTargets.size() - 1);
mMiddleTarget = mTargets.get(mTargets.size() / 2);
}
public SnapTarget calculateSnapTarget(int position, float velocity) {
@@ -215,6 +217,10 @@ public class DividerSnapAlgorithm {
SnapTarget.FLAG_NONE));
}
public SnapTarget getMiddleTarget() {
return mMiddleTarget;
}
/**
* Represents a snap target for the divider.
*/

View File

@@ -38,6 +38,7 @@ import java.util.ArrayList;
import static android.app.ActivityManager.DOCKED_STACK_CREATE_MODE_TOP_OR_LEFT;
import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.WindowManager.DOCKED_BOTTOM;
import static android.view.WindowManager.DOCKED_INVALID;
import static android.view.WindowManager.DOCKED_LEFT;
@@ -539,20 +540,32 @@ public class TaskStack implements DimLayer.DimLayerUser {
outBounds.set(mService.mDockedStackCreateBounds);
return;
}
// The initial bounds of the docked stack when it is created half the screen space and
// its bounds can be adjusted after that. The bounds of all other stacks are adjusted
// to occupy whatever screen space the docked stack isn't occupying.
// The initial bounds of the docked stack when it is created about half the screen space
// and its bounds can be adjusted after that. The bounds of all other stacks are
// adjusted to occupy whatever screen space the docked stack isn't occupying.
final DisplayInfo di = mDisplayContent.getDisplayInfo();
mService.mPolicy.getStableInsetsLw(di.rotation, di.logicalWidth, di.logicalHeight,
mTmpRect2);
final int position = new DividerSnapAlgorithm(mService.mContext.getResources(),
0 /* minFlingVelocityPxPerSecond */,
di.logicalWidth,
di.logicalHeight,
dockDividerWidth,
mService.mCurConfiguration.orientation == ORIENTATION_PORTRAIT,
mTmpRect2).getMiddleTarget().position;
if (dockOnTopOrLeft) {
if (splitHorizontally) {
outBounds.right = displayRect.centerX() - dockDividerWidth / 2;
outBounds.right = position;
} else {
outBounds.bottom = displayRect.centerY() - dockDividerWidth / 2;
outBounds.bottom = position;
}
} else {
if (splitHorizontally) {
outBounds.left = displayRect.centerX() + dockDividerWidth / 2;
outBounds.left = position - dockDividerWidth;
} else {
outBounds.top = displayRect.centerY() + dockDividerWidth / 2;
outBounds.top = position - dockDividerWidth;
}
}
return;