summaryrefslogtreecommitdiff
path: root/core/java/android/view/InsetsState.java
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2020-05-29 18:01:04 +0200
committerAdrian Roos <roosa@google.com>2020-06-05 14:46:14 +0200
commit8d04bcbc43d669644910c681389b504ce1296109 (patch)
tree5291c7fbc5cf3a6527465c3c0a49a854c0326544 /core/java/android/view/InsetsState.java
parentb0033693a89923a80f9973e41b45ddcef2ec7ae9 (diff)
Insets: allow controlling insets as long as the window is covering in the relevant direction
Fixes: 154745615 Test: InsetsStateTest Change-Id: I666a7eee82c15f0c5594c0acbd1a4f0186bcdc01
Diffstat (limited to 'core/java/android/view/InsetsState.java')
-rw-r--r--core/java/android/view/InsetsState.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/core/java/android/view/InsetsState.java b/core/java/android/view/InsetsState.java
index 9896aa4fe214..f77593155e4c 100644
--- a/core/java/android/view/InsetsState.java
+++ b/core/java/android/view/InsetsState.java
@@ -238,6 +238,44 @@ public class InsetsState implements Parcelable {
return insets.toRect();
}
+ /**
+ * Calculate which insets *cannot* be controlled, because the frame does not cover the
+ * respective side of the inset.
+ *
+ * If the frame of our window doesn't cover the entire inset, the control API makes very
+ * little sense, as we don't deal with negative insets.
+ */
+ @InsetsType
+ public int calculateUncontrollableInsetsFromFrame(Rect frame) {
+ int blocked = 0;
+ for (int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
+ InsetsSource source = mSources.get(type);
+ if (source == null) {
+ continue;
+ }
+ if (!canControlSide(frame, getInsetSide(
+ source.calculateInsets(frame, true /* ignoreVisibility */)))) {
+ blocked |= toPublicType(type);
+ }
+ }
+ return blocked;
+ }
+
+ private boolean canControlSide(Rect frame, int side) {
+ switch (side) {
+ case ISIDE_LEFT:
+ case ISIDE_RIGHT:
+ return frame.left == mDisplayFrame.left && frame.right == mDisplayFrame.right;
+ case ISIDE_TOP:
+ case ISIDE_BOTTOM:
+ return frame.top == mDisplayFrame.top && frame.bottom == mDisplayFrame.bottom;
+ case ISIDE_FLOATING:
+ return true;
+ default:
+ return false;
+ }
+ }
+
private void processSource(InsetsSource source, Rect relativeFrame, boolean ignoreVisibility,
Insets[] typeInsetsMap, @Nullable @InternalInsetsSide SparseIntArray typeSideMap,
@Nullable boolean[] typeVisibilityMap) {