Merge "Extend providedInternalInsets to be type specific" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-13 01:53:07 +00:00
committed by Android (Google) Code Review
4 changed files with 93 additions and 33 deletions

View File

@@ -3590,12 +3590,13 @@ public interface WindowManager extends ViewManager {
/**
* If specified, the insets provided by this window will be our window frame minus the
* insets specified by providedInternalInsets. This should not be used together with
* {@link WindowState#mGivenContentInsets}. If both of them are set, both will be applied.
* insets specified by providedInternalInsets for each type. This should not be used
* together with {@link WindowState#mGivenContentInsets}. If both of them are set, both will
* be applied.
*
* @hide
*/
public Insets providedInternalInsets = Insets.NONE;
public Insets[] providedInternalInsets;
/**
* If specified, the insets provided by this window for the IME will be our window frame
@@ -3603,7 +3604,7 @@ public interface WindowManager extends ViewManager {
*
* @hide
*/
public Insets providedInternalImeInsets = Insets.NONE;
public Insets[] providedInternalImeInsets;
/**
* If specified, the frame that used to calculate relative {@link RoundedCorner} will be
@@ -3989,8 +3990,18 @@ public interface WindowManager extends ViewManager {
} else {
out.writeInt(0);
}
providedInternalInsets.writeToParcel(out, 0 /* parcelableFlags */);
providedInternalImeInsets.writeToParcel(out, 0 /* parcelableFlags */);
if (providedInternalInsets != null) {
out.writeInt(providedInternalInsets.length);
out.writeTypedArray(providedInternalInsets, 0 /* parcelableFlags */);
} else {
out.writeInt(0);
}
if (providedInternalImeInsets != null) {
out.writeInt(providedInternalImeInsets.length);
out.writeTypedArray(providedInternalImeInsets, 0 /* parcelableFlags */);
} else {
out.writeInt(0);
}
out.writeBoolean(insetsRoundedCornerFrame);
if (paramsForRotation != null) {
checkNonRecursiveParams();
@@ -4070,8 +4081,16 @@ public interface WindowManager extends ViewManager {
providesInsetsTypes = new int[insetsTypesLength];
in.readIntArray(providesInsetsTypes);
}
providedInternalInsets = Insets.CREATOR.createFromParcel(in);
providedInternalImeInsets = Insets.CREATOR.createFromParcel(in);
int providedInternalInsetsLength = in.readInt();
if (providedInternalInsetsLength > 0) {
providedInternalInsets = new Insets[providedInternalInsetsLength];
in.readTypedArray(providedInternalInsets, Insets.CREATOR);
}
int providedInternalImeInsetsLength = in.readInt();
if (providedInternalImeInsetsLength > 0) {
providedInternalImeInsets = new Insets[providedInternalImeInsetsLength];
in.readTypedArray(providedInternalImeInsets, Insets.CREATOR);
}
insetsRoundedCornerFrame = in.readBoolean();
int paramsForRotationLength = in.readInt();
if (paramsForRotationLength > 0) {
@@ -4374,12 +4393,12 @@ public interface WindowManager extends ViewManager {
changes |= LAYOUT_CHANGED;
}
if (!providedInternalInsets.equals(o.providedInternalInsets)) {
if (!Arrays.equals(providedInternalInsets, o.providedInternalInsets)) {
providedInternalInsets = o.providedInternalInsets;
changes |= LAYOUT_CHANGED;
}
if (!providedInternalImeInsets.equals(o.providedInternalImeInsets)) {
if (!Arrays.equals(providedInternalImeInsets, o.providedInternalImeInsets)) {
providedInternalImeInsets = o.providedInternalImeInsets;
changes |= LAYOUT_CHANGED;
}
@@ -4590,13 +4609,21 @@ public interface WindowManager extends ViewManager {
sb.append(InsetsState.typeToString(providesInsetsTypes[i]));
}
}
if (!providedInternalInsets.equals(Insets.NONE)) {
if (providedInternalInsets != null) {
sb.append(System.lineSeparator());
sb.append(" providedInternalInsets=");
sb.append(providedInternalInsets);
for (int i = 0; i < providedInternalInsets.length; ++i) {
if (i > 0) sb.append(' ');
sb.append((providedInternalInsets[i]));
}
}
if (!providedInternalImeInsets.equals(Insets.NONE)) {
if (providedInternalImeInsets != null) {
sb.append(System.lineSeparator());
sb.append(" providedInternalImeInsets=");
sb.append(providedInternalImeInsets);
for (int i = 0; i < providedInternalImeInsets.length; ++i) {
if (i > 0) sb.append(' ');
sb.append((providedInternalImeInsets[i]));
}
}
if (insetsRoundedCornerFrame) {
sb.append(" insetsRoundedCornerFrame=");

View File

@@ -86,6 +86,7 @@ public class WindowManagerWrapper {
public static final int ITYPE_RIGHT_TAPPABLE_ELEMENT = InsetsState.ITYPE_RIGHT_TAPPABLE_ELEMENT;
public static final int ITYPE_BOTTOM_TAPPABLE_ELEMENT =
InsetsState.ITYPE_BOTTOM_TAPPABLE_ELEMENT;
public static final int ITYPE_SIZE = InsetsState.SIZE;
public static final int ANIMATION_DURATION_RESIZE = InsetsController.ANIMATION_DURATION_RESIZE;
public static final Interpolator RESIZE_INTERPOLATOR = InsetsController.RESIZE_INTERPOLATOR;

View File

@@ -83,6 +83,7 @@ import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
import android.view.InsetsState;
import android.view.InsetsState.InternalInsetsType;
import android.view.InsetsVisibilities;
import android.view.KeyEvent;
@@ -1558,10 +1559,12 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
| WindowManager.LayoutParams.FLAG_SLIPPERY,
PixelFormat.TRANSLUCENT);
lp.gravity = gravity;
lp.providedInternalInsets = new Insets[InsetsState.SIZE];
if (insetsHeight != -1) {
lp.providedInternalInsets = Insets.of(0, height - insetsHeight, 0, 0);
lp.providedInternalInsets[ITYPE_NAVIGATION_BAR] =
Insets.of(0, height - insetsHeight, 0, 0);
} else {
lp.providedInternalInsets = Insets.NONE;
lp.providedInternalInsets[ITYPE_NAVIGATION_BAR] = null;
}
lp.token = new Binder();
lp.accessibilityTitle = mContext.getString(R.string.nav_bar);

View File

@@ -1146,8 +1146,13 @@ public class DisplayPolicy {
mDisplayContent.setInsetProvider(ITYPE_NAVIGATION_BAR, win,
(displayFrames, windowContainer, inOutFrame) -> {
if (!mNavButtonForcedVisible) {
inOutFrame.inset(win.getLayoutingAttrs(
displayFrames.mRotation).providedInternalInsets);
final Insets[] providedInternalInsets = win.getLayoutingAttrs(
displayFrames.mRotation).providedInternalInsets;
if (providedInternalInsets != null
&& providedInternalInsets.length > ITYPE_NAVIGATION_BAR
&& providedInternalInsets[ITYPE_NAVIGATION_BAR] != null) {
inOutFrame.inset(providedInternalInsets[ITYPE_NAVIGATION_BAR]);
}
inOutFrame.inset(win.mGivenContentInsets);
}
},
@@ -1193,13 +1198,16 @@ public class DisplayPolicy {
if (attrs.providesInsetsTypes != null) {
for (@InternalInsetsType int insetsType : attrs.providesInsetsTypes) {
final TriConsumer<DisplayFrames, WindowContainer, Rect> imeFrameProvider =
!attrs.providedInternalImeInsets.equals(Insets.NONE)
? (displayFrames, windowContainer, inOutFrame) -> {
inOutFrame.inset(win.getLayoutingAttrs(
displayFrames.mRotation)
.providedInternalImeInsets);
}
: null;
(displayFrames, windowContainer, inOutFrame) -> {
final Insets[] providedInternalImeInsets =
win.getLayoutingAttrs(displayFrames.mRotation)
.providedInternalImeInsets;
if (providedInternalImeInsets != null
&& providedInternalImeInsets.length > insetsType
&& providedInternalImeInsets[insetsType] != null) {
inOutFrame.inset(providedInternalImeInsets[insetsType]);
}
};
switch (insetsType) {
case ITYPE_STATUS_BAR:
mStatusBarAlt = win;
@@ -1220,8 +1228,13 @@ public class DisplayPolicy {
}
mDisplayContent.setInsetProvider(insetsType, win, (displayFrames,
windowContainer, inOutFrame) -> {
inOutFrame.inset(win.getLayoutingAttrs(
displayFrames.mRotation).providedInternalInsets);
final Insets[] providedInternalInsets = win.getLayoutingAttrs(
displayFrames.mRotation).providedInternalInsets;
if (providedInternalInsets != null
&& providedInternalInsets.length > insetsType
&& providedInternalInsets[insetsType] != null) {
inOutFrame.inset(providedInternalInsets[insetsType]);
}
inOutFrame.inset(win.mGivenContentInsets);
}, imeFrameProvider);
mInsetsSourceWindowsExceptIme.add(win);
@@ -1937,15 +1950,23 @@ public class DisplayPolicy {
&& lp.paramsForRotation[rotation] != null) {
lp = lp.paramsForRotation[rotation];
}
final Insets providedInternalInsets;
if (lp.providedInternalInsets != null
&& lp.providedInternalInsets.length > ITYPE_NAVIGATION_BAR
&& lp.providedInternalInsets[ITYPE_NAVIGATION_BAR] != null) {
providedInternalInsets = lp.providedInternalInsets[ITYPE_NAVIGATION_BAR];
} else {
providedInternalInsets = Insets.NONE;
}
if (position == NAV_BAR_LEFT) {
if (lp.width > lp.providedInternalInsets.right) {
return lp.width - lp.providedInternalInsets.right;
if (lp.width > providedInternalInsets.right) {
return lp.width - providedInternalInsets.right;
} else {
return 0;
}
} else if (position == NAV_BAR_RIGHT) {
if (lp.width > lp.providedInternalInsets.left) {
return lp.width - lp.providedInternalInsets.left;
if (lp.width > providedInternalInsets.left) {
return lp.width - providedInternalInsets.left;
} else {
return 0;
}
@@ -1994,10 +2015,18 @@ public class DisplayPolicy {
return 0;
}
LayoutParams lp = mNavigationBar.getLayoutingAttrs(rotation);
if (lp.height < lp.providedInternalInsets.top) {
final Insets providedInternalInsets;
if (lp.providedInternalInsets != null
&& lp.providedInternalInsets.length > ITYPE_NAVIGATION_BAR
&& lp.providedInternalInsets[ITYPE_NAVIGATION_BAR] != null) {
providedInternalInsets = lp.providedInternalInsets[ITYPE_NAVIGATION_BAR];
} else {
providedInternalInsets = Insets.NONE;
}
if (lp.height < providedInternalInsets.top) {
return 0;
}
return lp.height - lp.providedInternalInsets.top;
return lp.height - providedInternalInsets.top;
}
/**