From 3167c88c2c18eaadb046d41e2108bf45eae0d289 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Tue, 7 May 2013 15:39:55 -0700 Subject: Fix bug #8839681 Reversed Textbox focus order on RTL and android:imeOptions="flagNoExtractUi" - make SequentialFocusComparator RTL-aware Change-Id: I3d9cc81f777d16933a8e1b69f8ed63efa5be0925 --- core/java/android/view/FocusFinder.java | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index b2988ed34971..c2c247ed429b 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -172,6 +172,7 @@ public class FocusFinder { try { // Note: This sort is stable. mSequentialFocusComparator.setRoot(root); + mSequentialFocusComparator.setIsLayoutRtl(root.isLayoutRtl()); Collections.sort(focusables, mSequentialFocusComparator); } finally { mSequentialFocusComparator.recycle(); @@ -180,9 +181,9 @@ public class FocusFinder { final int count = focusables.size(); switch (direction) { case View.FOCUS_FORWARD: - return getForwardFocusable(root, focused, focusables, count); + return getNextFocusable(focused, focusables, count); case View.FOCUS_BACKWARD: - return getBackwardFocusable(root, focused, focusables, count); + return getPreviousFocusable(focused, focusables, count); } return focusables.get(count - 1); } @@ -239,13 +240,6 @@ public class FocusFinder { return closest; } - private static View getForwardFocusable(ViewGroup root, View focused, - ArrayList focusables, int count) { - return (root.isLayoutRtl()) ? - getPreviousFocusable(focused, focusables, count) : - getNextFocusable(focused, focusables, count); - } - private static View getNextFocusable(View focused, ArrayList focusables, int count) { if (focused != null) { int position = focusables.lastIndexOf(focused); @@ -259,13 +253,6 @@ public class FocusFinder { return null; } - private static View getBackwardFocusable(ViewGroup root, View focused, - ArrayList focusables, int count) { - return (root.isLayoutRtl()) ? - getNextFocusable(focused, focusables, count) : - getPreviousFocusable(focused, focusables, count); - } - private static View getPreviousFocusable(View focused, ArrayList focusables, int count) { if (focused != null) { int position = focusables.indexOf(focused); @@ -619,6 +606,7 @@ public class FocusFinder { private final Rect mFirstRect = new Rect(); private final Rect mSecondRect = new Rect(); private ViewGroup mRoot; + private boolean mIsLayoutRtl; public void recycle() { mRoot = null; @@ -628,6 +616,10 @@ public class FocusFinder { mRoot = root; } + public void setIsLayoutRtl(boolean b) { + mIsLayoutRtl = b; + } + public int compare(View first, View second) { if (first == second) { return 0; @@ -641,17 +633,17 @@ public class FocusFinder { } else if (mFirstRect.top > mSecondRect.top) { return 1; } else if (mFirstRect.left < mSecondRect.left) { - return -1; + return mIsLayoutRtl ? 1 : -1; } else if (mFirstRect.left > mSecondRect.left) { - return 1; + return mIsLayoutRtl ? -1 : 1; } else if (mFirstRect.bottom < mSecondRect.bottom) { return -1; } else if (mFirstRect.bottom > mSecondRect.bottom) { return 1; } else if (mFirstRect.right < mSecondRect.right) { - return -1; + return mIsLayoutRtl ? 1 : -1; } else if (mFirstRect.right > mSecondRect.right) { - return 1; + return mIsLayoutRtl ? -1 : 1; } else { // The view are distinct but completely coincident so we consider // them equal for our purposes. Since the sort is stable, this -- cgit v1.2.3-59-g8ed1b