diff options
author | Fabrice Di Meglio <fdimeglio@google.com> | 2012-03-23 18:09:20 -0700 |
---|---|---|
committer | Fabrice Di Meglio <fdimeglio@google.com> | 2012-03-23 18:19:10 -0700 |
commit | 702e8f9b9294d8227deae6e1f125a768ee4a28d4 (patch) | |
tree | a6fd24cdf71d27618d17ce0c926167f81aa71fbf /core/java/android | |
parent | 2c4eabced0971d3b6b5e76dd925afcb0a7f59f1c (diff) | |
download | frameworks_base-702e8f9b9294d8227deae6e1f125a768ee4a28d4.zip frameworks_base-702e8f9b9294d8227deae6e1f125a768ee4a28d4.tar.gz frameworks_base-702e8f9b9294d8227deae6e1f125a768ee4a28d4.tar.bz2 |
Fix bug #6213159 FocusFinder should be able to take care of Views direction
- use RTL layout direction as input to decide what to do
Change-Id: Ied825963992e5406f546a937857c5ca4101977bb
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/view/FocusFinder.java | 82 |
1 files changed, 61 insertions, 21 deletions
diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index d9bf918..9639faf 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -79,25 +79,45 @@ public class FocusFinder { switch (direction) { case View.FOCUS_RIGHT: case View.FOCUS_DOWN: + setFocusBottomRight(root); + break; case View.FOCUS_FORWARD: - final int rootTop = root.getScrollY(); - final int rootLeft = root.getScrollX(); - mFocusedRect.set(rootLeft, rootTop, rootLeft, rootTop); + if (focused != null && focused.isLayoutRtl()) { + setFocusTopLeft(root); + } else { + setFocusBottomRight(root); + } break; case View.FOCUS_LEFT: case View.FOCUS_UP: + setFocusTopLeft(root); + break; case View.FOCUS_BACKWARD: - final int rootBottom = root.getScrollY() + root.getHeight(); - final int rootRight = root.getScrollX() + root.getWidth(); - mFocusedRect.set(rootRight, rootBottom, - rootRight, rootBottom); + if (focused != null && focused.isLayoutRtl()) { + setFocusBottomRight(root); + } else { + setFocusTopLeft(root); break; + } } } return findNextFocus(root, focused, mFocusedRect, direction); } + private void setFocusTopLeft(ViewGroup root) { + final int rootBottom = root.getScrollY() + root.getHeight(); + final int rootRight = root.getScrollX() + root.getWidth(); + mFocusedRect.set(rootRight, rootBottom, + rootRight, rootBottom); + } + + private void setFocusBottomRight(ViewGroup root) { + final int rootTop = root.getScrollY(); + final int rootLeft = root.getScrollX(); + mFocusedRect.set(rootLeft, rootTop, rootLeft, rootTop); + } + /** * Find the next view to take focus in root's descendants, searching from * a particular rectangle in root's coordinates. @@ -135,22 +155,10 @@ public class FocusFinder { final int count = focusables.size(); switch (direction) { case View.FOCUS_FORWARD: - if (focused != null) { - int position = focusables.lastIndexOf(focused); - if (position >= 0 && position + 1 < count) { - return focusables.get(position + 1); - } - } - return focusables.get(0); + return getForwardFocusable(focused, focusables, count); case View.FOCUS_BACKWARD: - if (focused != null) { - int position = focusables.indexOf(focused); - if (position > 0) { - return focusables.get(position - 1); - } - } - return focusables.get(count - 1); + return getBackwardFocusable(focused, focusables, count); } return null; } @@ -193,6 +201,38 @@ public class FocusFinder { return closest; } + private View getForwardFocusable(View focused, ArrayList<View> focusables, int count) { + return (focused != null && focused.isLayoutRtl()) ? + getPreviousFocusable(focused, focusables, count) : + getNextFocusable(focused, focusables, count); + } + + private View getNextFocusable(View focused, ArrayList<View> focusables, int count) { + if (focused != null) { + int position = focusables.lastIndexOf(focused); + if (position >= 0 && position + 1 < count) { + return focusables.get(position + 1); + } + } + return focusables.get(0); + } + + private View getBackwardFocusable(View focused, ArrayList<View> focusables, int count) { + return (focused != null && focused.isLayoutRtl()) ? + getNextFocusable(focused, focusables, count) : + getPreviousFocusable(focused, focusables, count); + } + + private View getPreviousFocusable(View focused, ArrayList<View> focusables, int count) { + if (focused != null) { + int position = focusables.indexOf(focused); + if (position > 0) { + return focusables.get(position - 1); + } + } + return focusables.get(count - 1); + } + /** * Is rect1 a better candidate than rect2 for a focus search in a particular * direction from a source rect? This is the core routine that determines |