Loading core/java/android/view/InsetsSource.java +25 −0 Original line number Diff line number Diff line Loading @@ -357,6 +357,31 @@ public class InsetsSource implements Parcelable { } else if (mTmpFrame.right == relativeFrame.right) { return Insets.of(0, 0, mTmpFrame.width(), 0); } } else { // The source doesn't cover the width or the height of relativeFrame, but just parts of // them. Here uses mSideHint to decide which side should be inset. switch (mSideHint) { case SIDE_LEFT: if (mTmpFrame.left == relativeFrame.left) { return Insets.of(mTmpFrame.width(), 0, 0, 0); } break; case SIDE_TOP: if (mTmpFrame.top == relativeFrame.top) { return Insets.of(0, mTmpFrame.height(), 0, 0); } break; case SIDE_RIGHT: if (mTmpFrame.right == relativeFrame.right) { return Insets.of(0, 0, mTmpFrame.width(), 0); } break; case SIDE_BOTTOM: if (mTmpFrame.bottom == relativeFrame.bottom) { return Insets.of(0, 0, 0, mTmpFrame.height()); } break; } } return Insets.NONE; } Loading core/tests/coretests/src/android/view/InsetsSourceTest.java +96 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,102 @@ public class InsetsSourceTest { assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftCenter() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftTop() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftBottom() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topCenter() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topLeft() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topRight() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightCenter() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightTop() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightBottom() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomCenter() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomLeft() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomRight() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateVisibleInsets_override() { mSource.setFrame(new Rect(0, 0, 500, 100)); Loading Loading
core/java/android/view/InsetsSource.java +25 −0 Original line number Diff line number Diff line Loading @@ -357,6 +357,31 @@ public class InsetsSource implements Parcelable { } else if (mTmpFrame.right == relativeFrame.right) { return Insets.of(0, 0, mTmpFrame.width(), 0); } } else { // The source doesn't cover the width or the height of relativeFrame, but just parts of // them. Here uses mSideHint to decide which side should be inset. switch (mSideHint) { case SIDE_LEFT: if (mTmpFrame.left == relativeFrame.left) { return Insets.of(mTmpFrame.width(), 0, 0, 0); } break; case SIDE_TOP: if (mTmpFrame.top == relativeFrame.top) { return Insets.of(0, mTmpFrame.height(), 0, 0); } break; case SIDE_RIGHT: if (mTmpFrame.right == relativeFrame.right) { return Insets.of(0, 0, mTmpFrame.width(), 0); } break; case SIDE_BOTTOM: if (mTmpFrame.bottom == relativeFrame.bottom) { return Insets.of(0, 0, 0, mTmpFrame.height()); } break; } } return Insets.NONE; } Loading
core/tests/coretests/src/android/view/InsetsSourceTest.java +96 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,102 @@ public class InsetsSourceTest { assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftCenter() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftTop() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_leftBottom() { mSource.setFrame(new Rect(0, 0, 100, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false); assertEquals(Insets.of(100, 0, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topCenter() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topLeft() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_topRight() { mSource.setFrame(new Rect(0, 0, 500, 100)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false); assertEquals(Insets.of(0, 100, 0, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightCenter() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 400), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightTop() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, -100, 500, 400), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_rightBottom() { mSource.setFrame(new Rect(400, 0, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(0, 100, 500, 600), false); assertEquals(Insets.of(0, 0, 100, 0), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomCenter() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 600, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomLeft() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(-100, 0, 400, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateInsets_partialSideIntersection_bottomRight() { mSource.setFrame(new Rect(0, 400, 500, 500)); mSource.updateSideHint(new Rect(0, 0, 500, 500)); Insets insets = mSource.calculateInsets(new Rect(100, 0, 600, 500), false); assertEquals(Insets.of(0, 0, 0, 100), insets); } @Test public void testCalculateVisibleInsets_override() { mSource.setFrame(new Rect(0, 0, 500, 100)); Loading