Loading core/java/android/view/InsetsSource.java +24 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.view; import static android.view.InsetsState.ITYPE_IME; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Insets; import android.graphics.Rect; Loading Loading @@ -114,7 +115,7 @@ public class InsetsSource implements Parcelable { if (!ignoreVisibility && !mVisible) { return Insets.NONE; } if (!mTmpFrame.setIntersect(frame, relativeFrame)) { if (!getIntersection(frame, relativeFrame, mTmpFrame)) { return Insets.NONE; } Loading Loading @@ -144,12 +145,33 @@ public class InsetsSource implements Parcelable { } } /** * Outputs the intersection of two rectangles. The shared edges will also be counted in the * intersection. * * @param a The first rectangle being intersected with. * @param b The second rectangle being intersected with. * @param out The rectangle which represents the intersection. * @return {@code true} if there is any intersection. */ private static boolean getIntersection(@NonNull Rect a, @NonNull Rect b, @NonNull Rect out) { if (a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom) { out.left = Math.max(a.left, b.left); out.top = Math.max(a.top, b.top); out.right = Math.min(a.right, b.right); out.bottom = Math.min(a.bottom, b.bottom); return true; } out.setEmpty(); return false; } public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("InsetsSource type="); pw.print(InsetsState.typeToString(mType)); pw.print(" frame="); pw.print(mFrame.toShortString()); if (mVisibleFrame != null) { pw.print(" visibleFrmae="); pw.print(mVisibleFrame.toShortString()); pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString()); } pw.print(" visible="); pw.print(mVisible); pw.println(); Loading core/tests/coretests/src/android/view/InsetsSourceTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,48 @@ public class InsetsSourceTest { assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_noIntersection_vertical() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 500), false); assertEquals(Insets.NONE, insets); } @Test public void testCalculateInsets_zeroWidthIntersection_vertical_start() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(0, 0, 0, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_zeroWidthIntersection_vertical_end() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(500, 0, 500, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_noIntersection_horizontal() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500), false); assertEquals(Insets.NONE, insets); } @Test public void testCalculateInsets_zeroWidthIntersection_horizontal_start() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 0), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_zeroWidthIntersection_horizontal_end() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 500, 500, 500), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateVisibleInsets_override() { mSource.setFrame(new Rect(0, 0, 500, 100)); Loading Loading
core/java/android/view/InsetsSource.java +24 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.view; import static android.view.InsetsState.ITYPE_IME; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Insets; import android.graphics.Rect; Loading Loading @@ -114,7 +115,7 @@ public class InsetsSource implements Parcelable { if (!ignoreVisibility && !mVisible) { return Insets.NONE; } if (!mTmpFrame.setIntersect(frame, relativeFrame)) { if (!getIntersection(frame, relativeFrame, mTmpFrame)) { return Insets.NONE; } Loading Loading @@ -144,12 +145,33 @@ public class InsetsSource implements Parcelable { } } /** * Outputs the intersection of two rectangles. The shared edges will also be counted in the * intersection. * * @param a The first rectangle being intersected with. * @param b The second rectangle being intersected with. * @param out The rectangle which represents the intersection. * @return {@code true} if there is any intersection. */ private static boolean getIntersection(@NonNull Rect a, @NonNull Rect b, @NonNull Rect out) { if (a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom) { out.left = Math.max(a.left, b.left); out.top = Math.max(a.top, b.top); out.right = Math.min(a.right, b.right); out.bottom = Math.min(a.bottom, b.bottom); return true; } out.setEmpty(); return false; } public void dump(String prefix, PrintWriter pw) { pw.print(prefix); pw.print("InsetsSource type="); pw.print(InsetsState.typeToString(mType)); pw.print(" frame="); pw.print(mFrame.toShortString()); if (mVisibleFrame != null) { pw.print(" visibleFrmae="); pw.print(mVisibleFrame.toShortString()); pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString()); } pw.print(" visible="); pw.print(mVisible); pw.println(); Loading
core/tests/coretests/src/android/view/InsetsSourceTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -126,6 +126,48 @@ public class InsetsSourceTest { assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_noIntersection_vertical() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 500), false); assertEquals(Insets.NONE, insets); } @Test public void testCalculateInsets_zeroWidthIntersection_vertical_start() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(0, 0, 0, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_zeroWidthIntersection_vertical_end() { mSource.setFrame(new Rect(0, 0, 500, 100)); Insets insets = mSource.calculateInsets(new Rect(500, 0, 500, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_noIntersection_horizontal() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 500, 500), false); assertEquals(Insets.NONE, insets); } @Test public void testCalculateInsets_zeroWidthIntersection_horizontal_start() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 0, 500, 0), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_zeroWidthIntersection_horizontal_end() { mSource.setFrame(new Rect(0, 0, 100, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 500, 500, 500), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateVisibleInsets_override() { mSource.setFrame(new Rect(0, 0, 500, 100)); Loading