summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jiaming Liu <jiamingliu@google.com> 2024-04-22 17:56:53 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-04-22 17:56:53 +0000
commit4ed9c85c640db97b4e8b85fd774e9d77bb48f18f (patch)
tree88094deeb20ff6f21107097b4ab1ae875003a090
parentfb0632298cc50760d923e6afb84a884a9b19a7f2 (diff)
parent31e444005b61a0c18c14da8b76673d54a870211f (diff)
Merge "[Divider] Set system default ratios for draggable type only" into main
-rw-r--r--libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java23
-rw-r--r--libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/DividerPresenterTest.java16
2 files changed, 28 insertions, 11 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 0a5a81b4fd8f..a0d6fce4c39b 100644
--- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java
+++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/DividerPresenter.java
@@ -33,6 +33,7 @@ import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSI
import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_RIGHT;
import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_TOP;
+import android.annotation.DimenRes;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.content.Context;
@@ -61,7 +62,6 @@ import android.window.TaskFragmentParentInfo;
import android.window.WindowContainerTransaction;
import androidx.annotation.GuardedBy;
-import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.window.extensions.core.util.function.Consumer;
import androidx.window.extensions.embedding.SplitAttributes.SplitType;
@@ -341,7 +341,7 @@ class DividerPresenter implements View.OnTouchListener {
applicationContext.getResources().getDisplayMetrics());
}
- private static int getDimensionDp(@IdRes int resId) {
+ private static int getDimensionDp(@DimenRes int resId) {
final Context context = ActivityThread.currentActivityThread().getApplication();
final int px = context.getResources().getDimensionPixelSize(resId);
return (int) TypedValue.convertPixelsToDimension(
@@ -431,6 +431,9 @@ class DividerPresenter implements View.OnTouchListener {
return null;
}
int widthDp = dividerAttributes.getWidthDp();
+ float minRatio = dividerAttributes.getPrimaryMinRatio();
+ float maxRatio = dividerAttributes.getPrimaryMaxRatio();
+
if (widthDp == WIDTH_SYSTEM_DEFAULT) {
widthDp = DEFAULT_DIVIDER_WIDTH_DP;
}
@@ -439,16 +442,14 @@ class DividerPresenter implements View.OnTouchListener {
// Draggable divider width must be larger than the drag handle size.
widthDp = Math.max(widthDp,
getDimensionDp(R.dimen.activity_embedding_divider_touch_target_width));
- }
-
- float minRatio = dividerAttributes.getPrimaryMinRatio();
- if (minRatio == RATIO_SYSTEM_DEFAULT) {
- minRatio = DEFAULT_MIN_RATIO;
- }
- float maxRatio = dividerAttributes.getPrimaryMaxRatio();
- if (maxRatio == RATIO_SYSTEM_DEFAULT) {
- maxRatio = DEFAULT_MAX_RATIO;
+ // Update minRatio and maxRatio only when it is a draggable divider.
+ if (minRatio == RATIO_SYSTEM_DEFAULT) {
+ minRatio = DEFAULT_MIN_RATIO;
+ }
+ if (maxRatio == RATIO_SYSTEM_DEFAULT) {
+ maxRatio = DEFAULT_MAX_RATIO;
+ }
}
return new DividerAttributes.Builder(dividerAttributes)
diff --git a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/DividerPresenterTest.java b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/DividerPresenterTest.java
index 49cfeb6e6b58..8aca92e89e6b 100644
--- a/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/DividerPresenterTest.java
+++ b/libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/DividerPresenterTest.java
@@ -266,6 +266,22 @@ public class DividerPresenterTest {
}
@Test
+ public void testSanitizeDividerAttributes_setDefaultValues_fixedDivider() {
+ DividerAttributes attributes =
+ new DividerAttributes.Builder(DividerAttributes.DIVIDER_TYPE_FIXED).build();
+ DividerAttributes sanitized = DividerPresenter.sanitizeDividerAttributes(attributes);
+
+ assertEquals(DividerAttributes.DIVIDER_TYPE_FIXED, sanitized.getDividerType());
+ assertEquals(DividerPresenter.DEFAULT_DIVIDER_WIDTH_DP, sanitized.getWidthDp());
+
+ // The ratios should not be set for fixed divider
+ assertEquals(DividerAttributes.RATIO_SYSTEM_DEFAULT, sanitized.getPrimaryMinRatio(),
+ 0.0f /* delta */);
+ assertEquals(DividerAttributes.RATIO_SYSTEM_DEFAULT, sanitized.getPrimaryMaxRatio(),
+ 0.0f /* delta */);
+ }
+
+ @Test
public void testSanitizeDividerAttributes_notChangingValidValues() {
DividerAttributes attributes =
new DividerAttributes.Builder(DividerAttributes.DIVIDER_TYPE_DRAGGABLE)