Merge "Move bounds adjustment logic to LaunchParamsUtil" into tm-qpr-dev

This commit is contained in:
Kazuki Takise
2022-11-19 00:58:36 +00:00
committed by Android (Google) Code Review
2 changed files with 52 additions and 44 deletions

View File

@@ -26,6 +26,7 @@ import android.annotation.NonNull;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Size; import android.util.Size;
import android.view.View;
/** /**
* The static class that defines some utility constants and functions that are shared among launch * The static class that defines some utility constants and functions that are shared among launch
@@ -43,6 +44,8 @@ class LaunchParamsUtil {
private static final int DEFAULT_LANDSCAPE_FREEFORM_WIDTH_DP = 1064; private static final int DEFAULT_LANDSCAPE_FREEFORM_WIDTH_DP = 1064;
private static final int DEFAULT_LANDSCAPE_FREEFORM_HEIGHT_DP = 600; private static final int DEFAULT_LANDSCAPE_FREEFORM_HEIGHT_DP = 600;
private static final int DISPLAY_EDGE_OFFSET_DP = 27;
private LaunchParamsUtil() {} private LaunchParamsUtil() {}
/** /**
@@ -126,4 +129,44 @@ class LaunchParamsUtil {
return new Size(adjWidth, adjHeight); return new Size(adjWidth, adjHeight);
} }
static void adjustBoundsToFitInDisplayArea(@NonNull Rect stableBounds, int layoutDirection,
@NonNull ActivityInfo.WindowLayout layout,
@NonNull Rect inOutBounds) {
if (stableBounds.width() < inOutBounds.width()
|| stableBounds.height() < inOutBounds.height()) {
// There is no way for us to fit the bounds in the displayArea without changing width
// or height. Just move the start to align with the displayArea.
final int left = layoutDirection == View.LAYOUT_DIRECTION_RTL
? stableBounds.right - inOutBounds.right + inOutBounds.left
: stableBounds.left;
inOutBounds.offsetTo(left, stableBounds.top);
return;
}
final int dx;
if (inOutBounds.right > stableBounds.right) {
// Right edge is out of displayArea.
dx = stableBounds.right - inOutBounds.right;
} else if (inOutBounds.left < stableBounds.left) {
// Left edge is out of displayArea.
dx = stableBounds.left - inOutBounds.left;
} else {
// Vertical edges are all in displayArea.
dx = 0;
}
final int dy;
if (inOutBounds.top < stableBounds.top) {
// Top edge is out of displayArea.
dy = stableBounds.top - inOutBounds.top;
} else if (inOutBounds.bottom > stableBounds.bottom) {
// Bottom edge is out of displayArea.
dy = stableBounds.bottom - inOutBounds.bottom;
} else {
// Horizontal edges are all in displayArea.
dy = 0;
}
inOutBounds.offset(dx, dy);
}
} }

View File

@@ -50,7 +50,6 @@ import android.graphics.Rect;
import android.util.Size; import android.util.Size;
import android.util.Slog; import android.util.Slog;
import android.view.Gravity; import android.view.Gravity;
import android.view.View;
import android.window.WindowContainerToken; import android.window.WindowContainerToken;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
@@ -370,7 +369,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
if (resolvedMode == WINDOWING_MODE_FREEFORM) { if (resolvedMode == WINDOWING_MODE_FREEFORM) {
// Make sure bounds are in the displayArea. // Make sure bounds are in the displayArea.
if (currentParams.mPreferredTaskDisplayArea != taskDisplayArea) { if (currentParams.mPreferredTaskDisplayArea != taskDisplayArea) {
adjustBoundsToFitInDisplayArea(taskDisplayArea, outParams.mBounds); adjustBoundsToFitInDisplayArea(taskDisplayArea, layout, outParams.mBounds);
} }
// Even though we want to keep original bounds, we still don't want it to stomp on // Even though we want to keep original bounds, we still don't want it to stomp on
// an existing task. // an existing task.
@@ -771,7 +770,7 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
// we may need to move it back to the displayArea. // we may need to move it back to the displayArea.
LaunchParamsUtil.centerBounds(displayArea, mTmpBounds.width(), mTmpBounds.height(), LaunchParamsUtil.centerBounds(displayArea, mTmpBounds.width(), mTmpBounds.height(),
inOutBounds); inOutBounds);
adjustBoundsToFitInDisplayArea(displayArea, inOutBounds); adjustBoundsToFitInDisplayArea(displayArea, layout, inOutBounds);
if (DEBUG) appendLog("freeform-size-mismatch=" + inOutBounds); if (DEBUG) appendLog("freeform-size-mismatch=" + inOutBounds);
} }
@@ -818,47 +817,13 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
} }
private void adjustBoundsToFitInDisplayArea(@NonNull TaskDisplayArea displayArea, private void adjustBoundsToFitInDisplayArea(@NonNull TaskDisplayArea displayArea,
@NonNull ActivityInfo.WindowLayout layout,
@NonNull Rect inOutBounds) { @NonNull Rect inOutBounds) {
final Rect stableBounds = mTmpStableBounds; final int layoutDirection = mSupervisor.mRootWindowContainer.getConfiguration()
displayArea.getStableRect(stableBounds); .getLayoutDirection();
displayArea.getStableRect(mTmpStableBounds);
if (stableBounds.width() < inOutBounds.width() LaunchParamsUtil.adjustBoundsToFitInDisplayArea(mTmpStableBounds, layoutDirection, layout,
|| stableBounds.height() < inOutBounds.height()) { inOutBounds);
// There is no way for us to fit the bounds in the displayArea without changing width
// or height. Just move the start to align with the displayArea.
final int layoutDirection =
mSupervisor.mRootWindowContainer.getConfiguration().getLayoutDirection();
final int left = layoutDirection == View.LAYOUT_DIRECTION_RTL
? stableBounds.right - inOutBounds.right + inOutBounds.left
: stableBounds.left;
inOutBounds.offsetTo(left, stableBounds.top);
return;
}
final int dx;
if (inOutBounds.right > stableBounds.right) {
// Right edge is out of displayArea.
dx = stableBounds.right - inOutBounds.right;
} else if (inOutBounds.left < stableBounds.left) {
// Left edge is out of displayArea.
dx = stableBounds.left - inOutBounds.left;
} else {
// Vertical edges are all in displayArea.
dx = 0;
}
final int dy;
if (inOutBounds.top < stableBounds.top) {
// Top edge is out of displayArea.
dy = stableBounds.top - inOutBounds.top;
} else if (inOutBounds.bottom > stableBounds.bottom) {
// Bottom edge is out of displayArea.
dy = stableBounds.bottom - inOutBounds.bottom;
} else {
// Horizontal edges are all in displayArea.
dy = 0;
}
inOutBounds.offset(dx, dy);
} }
/** /**