WindowInsets: populate system gesture and tappable element insets
Also fixes an infinite recursion when invoking TestableContext.(un)registerComponentCallbacks(). Test: atest WindowInsetsPolicyTest Bug: 126511573 Change-Id: I5c9f40054493a83746bce6124d72412e8eb8a0d1
This commit is contained in:
@@ -17,7 +17,10 @@
|
||||
package android.view;
|
||||
|
||||
import static android.view.ViewRootImpl.NEW_INSETS_MODE_FULL;
|
||||
import static android.view.ViewRootImpl.NEW_INSETS_MODE_NONE;
|
||||
import static android.view.WindowInsets.Type.MANDATORY_SYSTEM_GESTURES;
|
||||
import static android.view.WindowInsets.Type.SIZE;
|
||||
import static android.view.WindowInsets.Type.SYSTEM_GESTURES;
|
||||
import static android.view.WindowInsets.Type.indexOf;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
@@ -55,6 +58,12 @@ public class InsetsState implements Parcelable {
|
||||
TYPE_SIDE_BAR_1,
|
||||
TYPE_SIDE_BAR_2,
|
||||
TYPE_SIDE_BAR_3,
|
||||
TYPE_TOP_GESTURES,
|
||||
TYPE_BOTTOM_GESTURES,
|
||||
TYPE_LEFT_GESTURES,
|
||||
TYPE_RIGHT_GESTURES,
|
||||
TYPE_TOP_TAPPABLE_ELEMENT,
|
||||
TYPE_BOTTOM_TAPPABLE_ELEMENT,
|
||||
TYPE_IME
|
||||
})
|
||||
public @interface InternalInsetType {}
|
||||
@@ -73,8 +82,16 @@ public class InsetsState implements Parcelable {
|
||||
public static final int TYPE_SIDE_BAR_2 = 2;
|
||||
public static final int TYPE_SIDE_BAR_3 = 3;
|
||||
|
||||
public static final int TYPE_TOP_GESTURES = 4;
|
||||
public static final int TYPE_BOTTOM_GESTURES = 5;
|
||||
public static final int TYPE_LEFT_GESTURES = 6;
|
||||
public static final int TYPE_RIGHT_GESTURES = 7;
|
||||
public static final int TYPE_TOP_TAPPABLE_ELEMENT = 8;
|
||||
public static final int TYPE_BOTTOM_TAPPABLE_ELEMENT = 9;
|
||||
|
||||
/** Input method window. */
|
||||
public static final int TYPE_IME = 4;
|
||||
public static final int TYPE_IME = 10;
|
||||
|
||||
static final int LAST_TYPE = TYPE_IME;
|
||||
|
||||
// Derived types
|
||||
@@ -137,17 +154,6 @@ public class InsetsState implements Parcelable {
|
||||
&& legacyContentInsets != null && legacyStableInsets != null) {
|
||||
WindowInsets.assignCompatInsets(typeInsetsMap, legacyContentInsets);
|
||||
WindowInsets.assignCompatInsets(typeMaxInsetsMap, legacyStableInsets);
|
||||
|
||||
// TODO: set system gesture insets based on actual system gesture area.
|
||||
typeInsetsMap[Type.indexOf(Type.systemGestures())] = Insets.of(legacyContentInsets);
|
||||
typeInsetsMap[Type.indexOf(Type.mandatorySystemGestures())] =
|
||||
Insets.of(legacyContentInsets);
|
||||
typeInsetsMap[Type.indexOf(Type.tappableElement())] = Insets.of(legacyContentInsets);
|
||||
|
||||
typeMaxInsetsMap[Type.indexOf(Type.systemGestures())] = Insets.of(legacyStableInsets);
|
||||
typeMaxInsetsMap[Type.indexOf(Type.mandatorySystemGestures())] =
|
||||
Insets.of(legacyStableInsets);
|
||||
typeMaxInsetsMap[Type.indexOf(Type.tappableElement())] = Insets.of(legacyStableInsets);
|
||||
}
|
||||
for (int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
|
||||
InsetsSource source = mSources.get(type);
|
||||
@@ -159,7 +165,9 @@ public class InsetsState implements Parcelable {
|
||||
&& (type == TYPE_TOP_BAR || type == TYPE_NAVIGATION_BAR);
|
||||
boolean skipIme = source.getType() == TYPE_IME
|
||||
&& (legacySoftInputMode & LayoutParams.SOFT_INPUT_ADJUST_RESIZE) == 0;
|
||||
if (skipSystemBars || skipIme) {
|
||||
boolean skipLegacyTypes = ViewRootImpl.sNewInsetsMode == NEW_INSETS_MODE_NONE
|
||||
&& (toPublicType(type) & Type.compatSystemInsets()) != 0;
|
||||
if (skipSystemBars || skipIme || skipLegacyTypes) {
|
||||
typeVisibilityMap[indexOf(toPublicType(type))] = source.isVisible();
|
||||
continue;
|
||||
}
|
||||
@@ -183,7 +191,25 @@ public class InsetsState implements Parcelable {
|
||||
@Nullable boolean[] typeVisibilityMap) {
|
||||
Insets insets = source.calculateInsets(relativeFrame, ignoreVisibility);
|
||||
|
||||
int index = indexOf(toPublicType(source.getType()));
|
||||
int type = toPublicType(source.getType());
|
||||
processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap,
|
||||
insets, type);
|
||||
|
||||
if (type == MANDATORY_SYSTEM_GESTURES) {
|
||||
// Mandatory system gestures are also system gestures.
|
||||
// TODO: find a way to express this more generally. One option would be to define
|
||||
// Type.systemGestureInsets() as NORMAL | MANDATORY, but then we lose the
|
||||
// ability to set systemGestureInsets() independently from
|
||||
// mandatorySystemGestureInsets() in the Builder.
|
||||
processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap,
|
||||
insets, SYSTEM_GESTURES);
|
||||
}
|
||||
}
|
||||
|
||||
private void processSourceAsPublicType(InsetsSource source, Insets[] typeInsetsMap,
|
||||
@InsetSide @Nullable SparseIntArray typeSideMap,
|
||||
@Nullable boolean[] typeVisibilityMap, Insets insets, int type) {
|
||||
int index = indexOf(type);
|
||||
Insets existing = typeInsetsMap[index];
|
||||
if (existing == null) {
|
||||
typeInsetsMap[index] = insets;
|
||||
@@ -300,6 +326,15 @@ public class InsetsState implements Parcelable {
|
||||
return Type.SIDE_BARS;
|
||||
case TYPE_IME:
|
||||
return Type.IME;
|
||||
case TYPE_TOP_GESTURES:
|
||||
case TYPE_BOTTOM_GESTURES:
|
||||
return Type.MANDATORY_SYSTEM_GESTURES;
|
||||
case TYPE_LEFT_GESTURES:
|
||||
case TYPE_RIGHT_GESTURES:
|
||||
return Type.SYSTEM_GESTURES;
|
||||
case TYPE_TOP_TAPPABLE_ELEMENT:
|
||||
case TYPE_BOTTOM_TAPPABLE_ELEMENT:
|
||||
return Type.TAPPABLE_ELEMENT;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown type: " + type);
|
||||
}
|
||||
@@ -336,10 +371,20 @@ public class InsetsState implements Parcelable {
|
||||
return "TYPE_SIDE_BAR_2";
|
||||
case TYPE_SIDE_BAR_3:
|
||||
return "TYPE_SIDE_BAR_3";
|
||||
case TYPE_IME:
|
||||
return "TYPE_IME";
|
||||
case TYPE_TOP_GESTURES:
|
||||
return "TYPE_TOP_GESTURES";
|
||||
case TYPE_BOTTOM_GESTURES:
|
||||
return "TYPE_BOTTOM_GESTURES";
|
||||
case TYPE_LEFT_GESTURES:
|
||||
return "TYPE_LEFT_GESTURES";
|
||||
case TYPE_RIGHT_GESTURES:
|
||||
return "TYPE_RIGHT_GESTURES";
|
||||
case TYPE_TOP_TAPPABLE_ELEMENT:
|
||||
return "TYPE_TOP_TAPPABLE_ELEMENT";
|
||||
case TYPE_BOTTOM_TAPPABLE_ELEMENT:
|
||||
return "TYPE_BOTTOM_TAPPABLE_ELEMENT";
|
||||
default:
|
||||
return "TYPE_UNKNOWN";
|
||||
return "TYPE_UNKNOWN_" + type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1916,16 +1916,10 @@ public final class ViewRootImpl implements ViewParent,
|
||||
}
|
||||
contentInsets = ensureInsetsNonNegative(contentInsets, "content");
|
||||
stableInsets = ensureInsetsNonNegative(stableInsets, "stable");
|
||||
if (sNewInsetsMode != NEW_INSETS_MODE_NONE) {
|
||||
mLastWindowInsets = mInsetsController.calculateInsets(
|
||||
mContext.getResources().getConfiguration().isScreenRound(),
|
||||
mAttachInfo.mAlwaysConsumeSystemBars, displayCutout,
|
||||
contentInsets, stableInsets, mWindowAttributes.softInputMode);
|
||||
} else {
|
||||
mLastWindowInsets = new WindowInsets(contentInsets, stableInsets,
|
||||
mContext.getResources().getConfiguration().isScreenRound(),
|
||||
mAttachInfo.mAlwaysConsumeSystemBars, displayCutout);
|
||||
}
|
||||
mLastWindowInsets = mInsetsController.calculateInsets(
|
||||
mContext.getResources().getConfiguration().isScreenRound(),
|
||||
mAttachInfo.mAlwaysConsumeSystemBars, displayCutout,
|
||||
contentInsets, stableInsets, mWindowAttributes.softInputMode);
|
||||
}
|
||||
return mLastWindowInsets;
|
||||
}
|
||||
|
||||
@@ -29,9 +29,6 @@ import static android.view.WindowInsets.Type.TOP_BAR;
|
||||
import static android.view.WindowInsets.Type.all;
|
||||
import static android.view.WindowInsets.Type.compatSystemInsets;
|
||||
import static android.view.WindowInsets.Type.indexOf;
|
||||
import static android.view.WindowInsets.Type.mandatorySystemGestures;
|
||||
import static android.view.WindowInsets.Type.systemGestures;
|
||||
import static android.view.WindowInsets.Type.tappableElement;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.IntRange;
|
||||
@@ -225,10 +222,6 @@ public final class WindowInsets {
|
||||
}
|
||||
Insets[] typeInsetMap = new Insets[SIZE];
|
||||
assignCompatInsets(typeInsetMap, insets);
|
||||
// TODO: set system gesture insets based on actual system gesture area.
|
||||
typeInsetMap[indexOf(systemGestures())] = Insets.of(insets);
|
||||
typeInsetMap[indexOf(mandatorySystemGestures())] = Insets.of(insets);
|
||||
typeInsetMap[indexOf(tappableElement())] = Insets.of(insets);
|
||||
return typeInsetMap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user