diff options
| author | Vadim Tryshev <vadimt@google.com> | 2017-01-05 18:54:11 -0800 |
|---|---|---|
| committer | Vadim Tryshev <vadimt@google.com> | 2017-01-06 11:42:15 -0800 |
| commit | 311a5b54979afee7e07bf31600182584fde15b4f (patch) | |
| tree | a5dad41fa2d221988ca8112ea0ac87cadd0797d0 /core/java/android/view/FocusFinder.java | |
| parent | f1941775b6e0d4a47ce1cf895a0ea7b41bbaaaeb (diff) | |
Using official names for clusters and sections.
Per the bug, “clusters” and “sections” are already the official names,
and for a general name for both, we use “keyboard navigation
groups”.
Bug: 33708251
Test: N/A.
Change-Id: Ieb1d2e8a1ad758f902b0a925fbe5d187e0f7ea06
Diffstat (limited to 'core/java/android/view/FocusFinder.java')
| -rw-r--r-- | core/java/android/view/FocusFinder.java | 123 |
1 files changed, 63 insertions, 60 deletions
diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index 1a4f0d1ae803..a07a7ef600bf 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -16,8 +16,8 @@ package android.view; -import static android.view.View.FOCUS_GROUP_CLUSTER; -import static android.view.View.FOCUS_GROUP_SECTION; +import static android.view.View.KEYBOARD_NAVIGATION_GROUP_CLUSTER; +import static android.view.View.KEYBOARD_NAVIGATION_GROUP_SECTION; import android.annotation.NonNull; import android.annotation.Nullable; @@ -25,7 +25,7 @@ import android.graphics.Rect; import android.util.ArrayMap; import android.util.SparseArray; import android.util.SparseBooleanArray; -import android.view.View.FocusGroupType; +import android.view.View.KeyboardNavigationGroupType; import java.util.ArrayList; import java.util.Collections; @@ -110,30 +110,31 @@ public class FocusFinder { } /** - * Find the root of the next keyboard navigation cluster after the current one. - * @param focusGroupType Type of the focus group + * Find the root of the next keyboard navigation group after the current one. The group type can + * be either a cluster or a section. + * @param groupType Type of the keyboard navigation group * @param root The view tree to look inside. Cannot be null - * @param currentCluster The starting point of the search. Null means the default cluster + * @param currentGroup The starting point of the search. Null means the default group * @param direction Direction to look - * @return The next cluster, or null if none exists + * @return The next group, or null if none exists */ - public View findNextKeyboardNavigationCluster( - @FocusGroupType int focusGroupType, + public View findNextKeyboardNavigationGroup( + @KeyboardNavigationGroupType int groupType, @NonNull View root, - @Nullable View currentCluster, + @Nullable View currentGroup, int direction) { View next = null; - final ArrayList<View> clusters = mTempList; + final ArrayList<View> groups = mTempList; try { - clusters.clear(); - root.addKeyboardNavigationClusters(focusGroupType, clusters, direction); - if (!clusters.isEmpty()) { - next = findNextKeyboardNavigationCluster( - focusGroupType, root, currentCluster, clusters, direction); + groups.clear(); + root.addKeyboardNavigationGroups(groupType, groups, direction); + if (!groups.isEmpty()) { + next = findNextKeyboardNavigationGroup( + groupType, root, currentGroup, groups, direction); } } finally { - clusters.clear(); + groups.clear(); } return next; } @@ -206,25 +207,25 @@ public class FocusFinder { } } - private View findNextKeyboardNavigationCluster( - @FocusGroupType int focusGroupType, + private View findNextKeyboardNavigationGroup( + @KeyboardNavigationGroupType int groupType, View root, - View currentCluster, - List<View> clusters, + View currentGroup, + List<View> groups, int direction) { - final int count = clusters.size(); + final int count = groups.size(); switch (direction) { case View.FOCUS_FORWARD: case View.FOCUS_DOWN: case View.FOCUS_RIGHT: - return getNextKeyboardNavigationCluster( - focusGroupType, root, currentCluster, clusters, count); + return getNextKeyboardNavigationGroup( + groupType, root, currentGroup, groups, count); case View.FOCUS_BACKWARD: case View.FOCUS_UP: case View.FOCUS_LEFT: - return getPreviousKeyboardNavigationCluster( - focusGroupType, root, currentCluster, clusters, count); + return getPreviousKeyboardNavigationGroup( + groupType, root, currentGroup, groups, count); default: throw new IllegalArgumentException("Unknown direction: " + direction); } @@ -330,67 +331,69 @@ public class FocusFinder { return null; } - private static View getNextKeyboardNavigationCluster( - @FocusGroupType int focusGroupType, + private static View getNextKeyboardNavigationGroup( + @KeyboardNavigationGroupType int groupType, View root, - View currentCluster, - List<View> clusters, + View currentGroup, + List<View> groups, int count) { - if (currentCluster == null) { - // The current cluster is the default one. - // The next cluster after the default one is the first one. - // Note that the caller guarantees that 'clusters' is not empty. - return clusters.get(0); + if (currentGroup == null) { + // The current group is the default one. + // The next group after the default one is the first one. + // Note that the caller guarantees that 'group' is not empty. + return groups.get(0); } - final int position = clusters.lastIndexOf(currentCluster); + final int position = groups.lastIndexOf(currentGroup); if (position >= 0 && position + 1 < count) { - // Return the next non-default cluster if we can find it. - return clusters.get(position + 1); + // Return the next non-default group if we can find it. + return groups.get(position + 1); } - switch (focusGroupType) { - case FOCUS_GROUP_CLUSTER: + switch (groupType) { + case KEYBOARD_NAVIGATION_GROUP_CLUSTER: // The current cluster is the last one. The next one is the default one, i.e. the // root. return root; - case FOCUS_GROUP_SECTION: + case KEYBOARD_NAVIGATION_GROUP_SECTION: // There is no "default section", hence returning the first one. - return clusters.get(0); + return groups.get(0); default: - throw new IllegalArgumentException("Unknown focus group type: " + focusGroupType); + throw new IllegalArgumentException( + "Unknown keyboard navigation group type: " + groupType); } } - private static View getPreviousKeyboardNavigationCluster( - @FocusGroupType int focusGroupType, + private static View getPreviousKeyboardNavigationGroup( + @KeyboardNavigationGroupType int groupType, View root, - View currentCluster, - List<View> clusters, + View currentGroup, + List<View> groups, int count) { - if (currentCluster == null) { - // The current cluster is the default one. - // The previous cluster before the default one is the last one. - // Note that the caller guarantees that 'clusters' is not empty. - return clusters.get(count - 1); + if (currentGroup == null) { + // The current group is the default one. + // The previous group before the default one is the last one. + // Note that the caller guarantees that 'groups' is not empty. + return groups.get(count - 1); } - final int position = clusters.indexOf(currentCluster); + final int position = groups.indexOf(currentGroup); if (position > 0) { - // Return the previous non-default cluster if we can find it. - return clusters.get(position - 1); + // Return the previous non-default group if we can find it. + return groups.get(position - 1); } - switch (focusGroupType) { - case FOCUS_GROUP_CLUSTER: + switch (groupType) { + case KEYBOARD_NAVIGATION_GROUP_CLUSTER: // The current cluster is the first one. The previous one is the default one, i.e. // the root. return root; - case FOCUS_GROUP_SECTION: + case KEYBOARD_NAVIGATION_GROUP_SECTION: // There is no "default section", hence returning the last one. - return clusters.get(count - 1); + return groups.get(count - 1); default: - throw new IllegalArgumentException("Unknown focus group type: " + focusGroupType); + throw new IllegalArgumentException( + "Unknown keyboard navigation group type: " + groupType); } } |
