diff options
| author | 2016-11-28 18:26:24 -0800 | |
|---|---|---|
| committer | 2016-12-16 10:41:44 -0800 | |
| commit | 418b1fc512815501925006bf1f5d7b26ad94b6c7 (patch) | |
| tree | 30a11a494bcadcf4436df66b96656e4daeaec6e8 | |
| parent | e298756bf819cea685bf843189800b6a5fda2466 (diff) | |
Restricting navigation into and from clusters.
Tabbing loops inside cluster. Tabbing outside of clusters (i.e. in
the default cluster) won’t enter clusters. Initial focus won’t go
into a cluster.
Arrows work like before.
Bug: 32151632
Test: Manual checks. CTS test will be added after feature freeze.
Change-Id: Icecbd75394e2dd4afe2e1c4e6bc9ac64f6785699
| -rw-r--r-- | core/java/android/view/ViewGroup.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index c83298b873a2..7340cf712ca0 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -869,10 +869,13 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager */ @Override public View focusSearch(View focused, int direction) { - if (isRootNamespace()) { + if (isRootNamespace() + || isKeyboardNavigationCluster() + && (direction == FOCUS_FORWARD || direction == FOCUS_BACKWARD)) { // root namespace means we should consider ourselves the top of the // tree for focus searching; otherwise we could be focus searching - // into other tabs. see LocalActivityManager and TabHost for more info + // into other tabs. see LocalActivityManager and TabHost for more info. + // Cluster's root works same way for the forward and backward navigation. return FocusFinder.getInstance().findNextFocus(this, focused, direction); } else if (mParent != null) { return mParent.focusSearch(focused, direction); @@ -1104,6 +1107,12 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager @Override public void addFocusables(ArrayList<View> views, int direction, int focusableMode) { + if (isKeyboardNavigationCluster() + && (direction == FOCUS_FORWARD || direction == FOCUS_BACKWARD) && !hasFocus()) { + // A cluster cannot be focus-entered from outside using forward/backward navigation. + return; + } + final int focusableCount = views.size(); final int descendantFocusability = getDescendantFocusability(); @@ -3026,7 +3035,8 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager final View[] children = mChildren; for (int i = index; i != end; i += increment) { View child = children[i]; - if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) { + if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE + && !child.isKeyboardNavigationCluster()) { if (child.requestFocus(direction, previouslyFocusedRect)) { return true; } |