Loading packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -95,8 +95,12 @@ public class NearestTouchFrame extends FrameLayout { } } private View findNearestChild(MotionEvent event) { private View findNearestChild(MotionEvent event) { return mClickableChildren.stream().map(v -> new Pair<>(distance(v, event), v)) return mClickableChildren .min(Comparator.comparingInt(f -> f.first)).get().second; .stream() .filter(v -> v.isAttachedToWindow()) .map(v -> new Pair<>(distance(v, event), v)) .min(Comparator.comparingInt(f -> f.first)) .get().second; } } private int distance(View v, MotionEvent event) { private int distance(View v, MotionEvent event) { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java +20 −0 Original line number Original line Diff line number Diff line Loading @@ -88,6 +88,25 @@ public class NearestTouchFrameTest extends SysuiTestCase { ev.recycle(); ev.recycle(); } } @Test public void testNearestView_DetachedViewsExcluded() { View left = mockViewAt(0, 0, 10, 10); when(left.isAttachedToWindow()).thenReturn(false); View right = mockViewAt(20, 0, 10, 10); mNearestTouchFrame.addView(left); mNearestTouchFrame.addView(right); mNearestTouchFrame.onMeasure(0, 0); // Would go to left view if attached, but goes to right instead as left should be detached. MotionEvent ev = MotionEvent.obtain(0, 0, 0, 12 /* x */, 5 /* y */, 0); mNearestTouchFrame.onTouchEvent(ev); verify(right).onTouchEvent(eq(ev)); ev.recycle(); } @Test @Test public void testHorizontalSelection_Left() { public void testHorizontalSelection_Left() { View left = mockViewAt(0, 0, 10, 10); View left = mockViewAt(0, 0, 10, 10); Loading Loading @@ -161,6 +180,7 @@ public class NearestTouchFrameTest extends SysuiTestCase { return null; return null; }).when(v).getLocationInWindow(any()); }).when(v).getLocationInWindow(any()); when(v.isClickable()).thenReturn(true); when(v.isClickable()).thenReturn(true); when(v.isAttachedToWindow()).thenReturn(true); // Stupid final methods. // Stupid final methods. v.setLeft(0); v.setLeft(0); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java +6 −2 Original line number Original line Diff line number Diff line Loading @@ -95,8 +95,12 @@ public class NearestTouchFrame extends FrameLayout { } } private View findNearestChild(MotionEvent event) { private View findNearestChild(MotionEvent event) { return mClickableChildren.stream().map(v -> new Pair<>(distance(v, event), v)) return mClickableChildren .min(Comparator.comparingInt(f -> f.first)).get().second; .stream() .filter(v -> v.isAttachedToWindow()) .map(v -> new Pair<>(distance(v, event), v)) .min(Comparator.comparingInt(f -> f.first)) .get().second; } } private int distance(View v, MotionEvent event) { private int distance(View v, MotionEvent event) { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NearestTouchFrameTest.java +20 −0 Original line number Original line Diff line number Diff line Loading @@ -88,6 +88,25 @@ public class NearestTouchFrameTest extends SysuiTestCase { ev.recycle(); ev.recycle(); } } @Test public void testNearestView_DetachedViewsExcluded() { View left = mockViewAt(0, 0, 10, 10); when(left.isAttachedToWindow()).thenReturn(false); View right = mockViewAt(20, 0, 10, 10); mNearestTouchFrame.addView(left); mNearestTouchFrame.addView(right); mNearestTouchFrame.onMeasure(0, 0); // Would go to left view if attached, but goes to right instead as left should be detached. MotionEvent ev = MotionEvent.obtain(0, 0, 0, 12 /* x */, 5 /* y */, 0); mNearestTouchFrame.onTouchEvent(ev); verify(right).onTouchEvent(eq(ev)); ev.recycle(); } @Test @Test public void testHorizontalSelection_Left() { public void testHorizontalSelection_Left() { View left = mockViewAt(0, 0, 10, 10); View left = mockViewAt(0, 0, 10, 10); Loading Loading @@ -161,6 +180,7 @@ public class NearestTouchFrameTest extends SysuiTestCase { return null; return null; }).when(v).getLocationInWindow(any()); }).when(v).getLocationInWindow(any()); when(v.isClickable()).thenReturn(true); when(v.isClickable()).thenReturn(true); when(v.isAttachedToWindow()).thenReturn(true); // Stupid final methods. // Stupid final methods. v.setLeft(0); v.setLeft(0); Loading