From 951bb421668b82ca014f75d265b161f6ff64d36b Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Mon, 30 Apr 2012 13:15:21 -0700 Subject: [PATCH] Finding focus for from rectangle now working. 1. The FocusFinder code was ignoring the rectangle. bug:6400513 Change-Id: I218425182b9cc2cda01fc4b5d75e9ac94a22561c --- core/java/android/view/FocusFinder.java | 50 ++++++++++++++----------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/core/java/android/view/FocusFinder.java b/core/java/android/view/FocusFinder.java index 98375aeacf245..6bf1888cc2c29 100644 --- a/core/java/android/view/FocusFinder.java +++ b/core/java/android/view/FocusFinder.java @@ -62,7 +62,7 @@ public class FocusFinder { * @return The next focusable view, or null if none exists. */ public final View findNextFocus(ViewGroup root, View focused, int direction) { - return findNextFocus(root, focused, mFocusedRect, direction); + return findNextFocus(root, focused, null, direction); } /** @@ -122,34 +122,40 @@ public class FocusFinder { int direction, ArrayList focusables) { final int directionMasked = (direction & ~View.FOCUS_ACCESSIBILITY); if (focused != null) { + if (focusedRect == null) { + focusedRect = mFocusedRect; + } // fill in interesting rect from focused focused.getFocusedRect(focusedRect); root.offsetDescendantRectToMyCoords(focused, focusedRect); } else { - // make up a rect at top left or bottom right of root - switch (directionMasked) { - case View.FOCUS_RIGHT: - case View.FOCUS_DOWN: - setFocusTopLeft(root, focusedRect); - break; - case View.FOCUS_FORWARD: - if (root.isLayoutRtl()) { - setFocusBottomRight(root, focusedRect); - } else { + if (focusedRect == null) { + focusedRect = mFocusedRect; + // make up a rect at top left or bottom right of root + switch (directionMasked) { + case View.FOCUS_RIGHT: + case View.FOCUS_DOWN: setFocusTopLeft(root, focusedRect); - } - break; + break; + case View.FOCUS_FORWARD: + if (root.isLayoutRtl()) { + setFocusBottomRight(root, focusedRect); + } else { + setFocusTopLeft(root, focusedRect); + } + break; - case View.FOCUS_LEFT: - case View.FOCUS_UP: - setFocusBottomRight(root, focusedRect); - break; - case View.FOCUS_BACKWARD: - if (root.isLayoutRtl()) { - setFocusTopLeft(root, focusedRect); - } else { + case View.FOCUS_LEFT: + case View.FOCUS_UP: setFocusBottomRight(root, focusedRect); - break; + break; + case View.FOCUS_BACKWARD: + if (root.isLayoutRtl()) { + setFocusTopLeft(root, focusedRect); + } else { + setFocusBottomRight(root, focusedRect); + break; + } } } }