A brave new world for window insets (1/n)

This CL starts a journey to discover a brave new inset world. The
path to get us there may be rocky, but it's going to be rocky.

One of the main pledges of the new API is that an app can retrieve
what is causing a certain inset easily. For that, we need to
dispatch metadata who is causing what inset, such that we can query
it from the client side.

Furthermore, the client will be able to manipulate insets directly,
but also listen to animation changes. We don't want to go through
window manager for that, thus, there needs to be a local codepath
from (global window state -> WindowInsets).

Because we have these two requirements, we dispatch the relevant
global window state for insets, represented by InsetsState, and
dispatch it to the client. On the client side we take the frame
and the InsetsState and generate WindowInsets out of it.

Bug: 118118435
Test: InsetsSourceTest, InsetsStateTest, InsetsSourceProviderTest,
InsetsStateControllerTest
Change-Id: I2bfe9dda376512916261823fc2ee35cbedeb6731
This commit is contained in:
Jorim Jaggi
2018-09-26 16:55:15 +02:00
parent e30fc89f6e
commit f96c90ac6c
28 changed files with 1304 additions and 35 deletions

View File

@@ -81,6 +81,17 @@ public final class Insets {
return new Rect(left, top, right, bottom);
}
/**
* Add two Insets.
*
* @param a The first Insets to add.
* @param b The second Insets to add.
* @return a + b, i. e. all insets on every side are added together.
*/
public static @NonNull Insets add(@NonNull Insets a, @NonNull Insets b) {
return Insets.of(a.left + b.left, a.top + b.top, a.right + b.right, a.bottom + b.bottom);
}
/**
* Two Insets instances are equal iff they belong to the same class and their fields are
* pairwise equal.

View File

@@ -105,6 +105,20 @@ public final class Rect implements Parcelable {
}
}
/**
* @hide
*/
public Rect(@Nullable Insets r) {
if (r == null) {
left = top = right = bottom = 0;
} else {
left = r.left;
top = r.top;
right = r.right;
bottom = r.bottom;
}
}
/**
* Returns a copy of {@code r} if {@code r} is not {@code null}, or {@code null} otherwise.
*
@@ -417,6 +431,18 @@ public final class Rect implements Parcelable {
bottom -= insets.bottom;
}
/**
* Insets the rectangle on all sides specified by the dimensions of {@code insets}.
* @hide
* @param insets The insets to inset the rect by.
*/
public void inset(Insets insets) {
left += insets.left;
top += insets.top;
right -= insets.right;
bottom -= insets.bottom;
}
/**
* Insets the rectangle on all sides specified by the insets.
* @hide