summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Jiaming Liu <jiamingliu@google.com> 2024-05-07 01:04:36 +0000
committer Jiaming Liu <jiamingliu@google.com> 2024-05-10 18:36:01 +0000
commitfa1334dabb1ab4a069354894ce1083e34f8b4b17 (patch)
tree13a65c6ee1e3d6f0014e165f19282c61e4827bf7 /libs
parent80f02617dc6324f8fd97cd0b25794ab0a70c8ee4 (diff)
[Divider] Allow divider drag handle overlay on primary container
Adjust the computation of the divider surface bounds so that the drag handle can be placed on top of the primary container when the divider width is less than the drag handle size. Bug: 327067596 Test: atest DividerPresenterTest Change-Id: I71fd03a0e7351a68585d2cd30077a8a26adea752
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java81
1 files changed, 66 insertions, 15 deletions
diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java
index a0d6fce4c39b..cded27eec240 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java
@@ -439,10 +439,6 @@ class DividerPresenter implements View.OnTouchListener {
}
if (dividerAttributes.getDividerType() == DividerAttributes.DIVIDER_TYPE_DRAGGABLE) {
- // Draggable divider width must be larger than the drag handle size.
- widthDp = Math.max(widthDp,
- getDimensionDp(R.dimen.activity_embedding_divider_touch_target_width));
-
// Update minRatio and maxRatio only when it is a draggable divider.
if (minRatio == RATIO_SYSTEM_DEFAULT) {
minRatio = DEFAULT_MIN_RATIO;
@@ -877,17 +873,21 @@ class DividerPresenter implements View.OnTouchListener {
@NonNull
private final FrameLayout mDividerLayout;
@NonNull
+ private final View mDividerLine;
+ private View mDragHandle;
+ @NonNull
private final View.OnTouchListener mListener;
@NonNull
private Properties mProperties;
private int mDividerWidthPx;
+ private int mHandleWidthPx;
@Nullable
private SurfaceControl mPrimaryVeil;
@Nullable
private SurfaceControl mSecondaryVeil;
private boolean mIsDragging;
private int mDividerPosition;
- private View mDragHandle;
+ private int mDividerSurfaceWidthPx;
private Renderer(@NonNull Properties properties, @NonNull View.OnTouchListener listener) {
mProperties = properties;
@@ -905,6 +905,7 @@ class DividerPresenter implements View.OnTouchListener {
context, displayManager.getDisplay(mProperties.mDisplayId),
mWindowlessWindowManager, "DividerContainer");
mDividerLayout = new FrameLayout(context);
+ mDividerLine = new View(context);
update();
}
@@ -921,6 +922,17 @@ class DividerPresenter implements View.OnTouchListener {
mDividerWidthPx = getDividerWidthPx(mProperties.mDividerAttributes);
mDividerPosition = mProperties.mInitialDividerPosition;
mWindowlessWindowManager.setConfiguration(mProperties.mConfiguration);
+
+ if (mProperties.mDividerAttributes.getDividerType()
+ == DividerAttributes.DIVIDER_TYPE_DRAGGABLE) {
+ // TODO(b/329193115) support divider on secondary display
+ final Context context = ActivityThread.currentActivityThread().getApplication();
+ mHandleWidthPx = context.getResources().getDimensionPixelSize(
+ R.dimen.activity_embedding_divider_touch_target_width);
+ } else {
+ mHandleWidthPx = 0;
+ }
+
// TODO handle synchronization between surface transactions and WCT.
final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
updateSurface(t);
@@ -950,13 +962,45 @@ class DividerPresenter implements View.OnTouchListener {
*/
private void updateSurface(@NonNull SurfaceControl.Transaction t) {
final Rect taskBounds = mProperties.mConfiguration.windowConfiguration.getBounds();
+
+ int dividerSurfacePosition;
+ if (mProperties.mDividerAttributes.getDividerType()
+ == DividerAttributes.DIVIDER_TYPE_DRAGGABLE) {
+ // When the divider drag handle width is larger than the divider width, the position
+ // of the divider surface is adjusted so that it is large enough to host both the
+ // divider line and the divider drag handle.
+ mDividerSurfaceWidthPx = Math.max(mDividerWidthPx, mHandleWidthPx);
+ dividerSurfacePosition =
+ mProperties.mIsReversedLayout
+ ? mDividerPosition
+ : mDividerPosition + mDividerWidthPx - mDividerSurfaceWidthPx;
+ dividerSurfacePosition = Math.clamp(dividerSurfacePosition, 0,
+ mProperties.mIsVerticalSplit ? taskBounds.width() : taskBounds.height());
+ } else {
+ mDividerSurfaceWidthPx = mDividerWidthPx;
+ dividerSurfacePosition = mDividerPosition;
+ }
+
if (mProperties.mIsVerticalSplit) {
- t.setPosition(mDividerSurface, mDividerPosition, 0.0f);
- t.setWindowCrop(mDividerSurface, mDividerWidthPx, taskBounds.height());
+ t.setPosition(mDividerSurface, dividerSurfacePosition, 0.0f);
+ t.setWindowCrop(mDividerSurface, mDividerSurfaceWidthPx, taskBounds.height());
} else {
- t.setPosition(mDividerSurface, 0.0f, mDividerPosition);
- t.setWindowCrop(mDividerSurface, taskBounds.width(), mDividerWidthPx);
+ t.setPosition(mDividerSurface, 0.0f, dividerSurfacePosition);
+ t.setWindowCrop(mDividerSurface, taskBounds.width(), mDividerSurfaceWidthPx);
}
+
+ // Update divider line position in the surface
+ if (!mProperties.mIsReversedLayout) {
+ final int offset = mDividerPosition - dividerSurfacePosition;
+ mDividerLine.setX(mProperties.mIsVerticalSplit ? offset : 0);
+ mDividerLine.setY(mProperties.mIsVerticalSplit ? 0 : offset);
+ } else {
+ // For reversed layout, the divider line is always at the start of the divider
+ // surface.
+ mDividerLine.setX(0);
+ mDividerLine.setY(0);
+ }
+
if (mIsDragging) {
updateVeils(t);
}
@@ -971,14 +1015,14 @@ class DividerPresenter implements View.OnTouchListener {
final Rect taskBounds = mProperties.mConfiguration.windowConfiguration.getBounds();
final WindowManager.LayoutParams lp = mProperties.mIsVerticalSplit
? new WindowManager.LayoutParams(
- mDividerWidthPx,
+ mDividerSurfaceWidthPx,
taskBounds.height(),
TYPE_APPLICATION_PANEL,
FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_SLIPPERY,
PixelFormat.TRANSLUCENT)
: new WindowManager.LayoutParams(
taskBounds.width(),
- mDividerWidthPx,
+ mDividerSurfaceWidthPx,
TYPE_APPLICATION_PANEL,
FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_SLIPPERY,
PixelFormat.TRANSLUCENT);
@@ -995,12 +1039,19 @@ class DividerPresenter implements View.OnTouchListener {
*/
private void updateDivider(@NonNull SurfaceControl.Transaction t) {
mDividerLayout.removeAllViews();
- if (mProperties.mIsDraggableExpandType) {
+ mDividerLayout.addView(mDividerLine);
+ if (mProperties.mIsDraggableExpandType && !mIsDragging) {
// If a container is fully expanded, the divider overlays on the expanded container.
- mDividerLayout.setBackgroundColor(Color.TRANSPARENT);
+ mDividerLine.setBackgroundColor(Color.TRANSPARENT);
} else {
- mDividerLayout.setBackgroundColor(mProperties.mDividerAttributes.getDividerColor());
+ mDividerLine.setBackgroundColor(mProperties.mDividerAttributes.getDividerColor());
}
+ final Rect taskBounds = mProperties.mConfiguration.windowConfiguration.getBounds();
+ mDividerLine.setLayoutParams(
+ mProperties.mIsVerticalSplit
+ ? new FrameLayout.LayoutParams(mDividerWidthPx, taskBounds.height())
+ : new FrameLayout.LayoutParams(taskBounds.width(), mDividerWidthPx)
+ );
if (mProperties.mDividerAttributes.getDividerType()
== DividerAttributes.DIVIDER_TYPE_DRAGGABLE) {
createVeils();
@@ -1027,7 +1078,7 @@ class DividerPresenter implements View.OnTouchListener {
R.dimen.activity_embedding_divider_touch_target_width));
params.gravity = Gravity.CENTER;
button.setLayoutParams(params);
- button.setBackgroundColor(R.color.transparent);
+ button.setBackgroundColor(Color.TRANSPARENT);
final Drawable handle = context.getResources().getDrawable(
R.drawable.activity_embedding_divider_handle, context.getTheme());