Merge "Enforce mutual exclusivity in setScrollCaptureHint" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-04-20 13:20:13 +00:00
committed by Android (Google) Code Review
2 changed files with 16 additions and 0 deletions

View File

@@ -30143,6 +30143,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
*/
public void setScrollCaptureHint(@ScrollCaptureHint int hint) {
mPrivateFlags4 &= ~PFLAG4_SCROLL_CAPTURE_HINT_MASK;
// Since include/exclude are mutually exclusive, exclude takes precedence.
if ((hint & SCROLL_CAPTURE_HINT_EXCLUDE) != 0) {
hint &= ~SCROLL_CAPTURE_HINT_INCLUDE;
}
mPrivateFlags4 |= ((hint << PFLAG4_SCROLL_CAPTURE_HINT_SHIFT)
& PFLAG4_SCROLL_CAPTURE_HINT_MASK);
}

View File

@@ -92,6 +92,18 @@ public class ViewGroupScrollCaptureTest {
viewGroup.getScrollCaptureHint());
}
/** Make sure the hint flags are saved and loaded correctly. */
@Test
public void testSetScrollCaptureHint_mutuallyExclusiveFlags() throws Exception {
final Context context = getInstrumentation().getContext();
final MockViewGroup viewGroup = new MockViewGroup(context);
viewGroup.setScrollCaptureHint(
View.SCROLL_CAPTURE_HINT_INCLUDE | View.SCROLL_CAPTURE_HINT_EXCLUDE);
assertEquals("Mutually exclusive flags were not resolved correctly",
ViewGroup.SCROLL_CAPTURE_HINT_EXCLUDE, viewGroup.getScrollCaptureHint());
}
/**
* Ensure a ViewGroup with 'scrollCaptureHint=auto', but no ScrollCaptureCallback set dispatches
* correctly. Verifies that the framework helper is called. Verifies a that non-null callback