summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Fabrice Di Meglio <fdimeglio@google.com> 2012-03-27 16:06:25 -0700
committer Fabrice Di Meglio <fdimeglio@google.com> 2012-03-27 19:04:38 -0700
commit7e0a372978eddf21808bf7fdfe36c1baa7f77e7c (patch)
treed2983446d2eb34ff34ac699f288dbd7d98cc6ea1
parentdb2026000a1d832b60d73e0a046bc8137fbb1960 (diff)
Improve FocusFinder for RTL support
- fix some issues introduced in the previous CL Change-Id: Ib679e9f66b029506c7e07e44b8fef176ad262585
-rw-r--r--core/java/android/view/FocusFinder.java30
1 files changed, 16 insertions, 14 deletions
diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java
index 9639faff3ec3..3529b8e0ebb7 100644
--- a/core/java/android/view/FocusFinder.java
+++ b/core/java/android/view/FocusFinder.java
@@ -54,7 +54,7 @@ public class FocusFinder {
/**
* Find the next view to take focus in root's descendants, starting from the view
* that currently is focused.
- * @param root Contains focused
+ * @param root Contains focused. Cannot be null.
* @param focused Has focus now.
* @param direction Direction to look.
* @return The next focusable view, or null if none exists.
@@ -82,7 +82,7 @@ public class FocusFinder {
setFocusBottomRight(root);
break;
case View.FOCUS_FORWARD:
- if (focused != null && focused.isLayoutRtl()) {
+ if (root.isLayoutRtl()) {
setFocusTopLeft(root);
} else {
setFocusBottomRight(root);
@@ -94,7 +94,7 @@ public class FocusFinder {
setFocusTopLeft(root);
break;
case View.FOCUS_BACKWARD:
- if (focused != null && focused.isLayoutRtl()) {
+ if (root.isLayoutRtl()) {
setFocusBottomRight(root);
} else {
setFocusTopLeft(root);
@@ -121,7 +121,7 @@ public class FocusFinder {
/**
* Find the next view to take focus in root's descendants, searching from
* a particular rectangle in root's coordinates.
- * @param root Contains focusedRect.
+ * @param root Contains focusedRect. Cannot be null.
* @param focusedRect The starting point of the search.
* @param direction Direction to look.
* @return The next focusable view, or null if none exists.
@@ -155,10 +155,10 @@ public class FocusFinder {
final int count = focusables.size();
switch (direction) {
case View.FOCUS_FORWARD:
- return getForwardFocusable(focused, focusables, count);
+ return getForwardFocusable(root, focused, focusables, count);
case View.FOCUS_BACKWARD:
- return getBackwardFocusable(focused, focusables, count);
+ return getBackwardFocusable(root, focused, focusables, count);
}
return null;
}
@@ -201,13 +201,14 @@ public class FocusFinder {
return closest;
}
- private View getForwardFocusable(View focused, ArrayList<View> focusables, int count) {
- return (focused != null && focused.isLayoutRtl()) ?
+ private static View getForwardFocusable(ViewGroup root, View focused,
+ ArrayList<View> focusables, int count) {
+ return (root.isLayoutRtl()) ?
getPreviousFocusable(focused, focusables, count) :
getNextFocusable(focused, focusables, count);
}
- private View getNextFocusable(View focused, ArrayList<View> focusables, int count) {
+ private static View getNextFocusable(View focused, ArrayList<View> focusables, int count) {
if (focused != null) {
int position = focusables.lastIndexOf(focused);
if (position >= 0 && position + 1 < count) {
@@ -217,13 +218,14 @@ public class FocusFinder {
return focusables.get(0);
}
- private View getBackwardFocusable(View focused, ArrayList<View> focusables, int count) {
- return (focused != null && focused.isLayoutRtl()) ?
+ private static View getBackwardFocusable(ViewGroup root, View focused,
+ ArrayList<View> focusables, int count) {
+ return (root.isLayoutRtl()) ?
getNextFocusable(focused, focusables, count) :
getPreviousFocusable(focused, focusables, count);
}
- private View getPreviousFocusable(View focused, ArrayList<View> focusables, int count) {
+ private static View getPreviousFocusable(View focused, ArrayList<View> focusables, int count) {
if (focused != null) {
int position = focusables.indexOf(focused);
if (position > 0) {
@@ -353,7 +355,7 @@ public class FocusFinder {
/**
- * Do the "beams" w.r.t the given direcition's axis of rect1 and rect2 overlap?
+ * Do the "beams" w.r.t the given direction's axis of rect1 and rect2 overlap?
* @param direction the direction (up, down, left, right)
* @param rect1 The first rectangle
* @param rect2 The second rectangle
@@ -441,7 +443,7 @@ public class FocusFinder {
/**
* Find the distance on the minor axis w.r.t the direction to the nearest
- * edge of the destination rectange.
+ * edge of the destination rectangle.
* @param direction the direction (up, down, left, right)
* @param source The source rect.
* @param dest The destination rect.