summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Svetoslav Ganov <svetoslavganov@google.com> 2012-04-04 19:01:13 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2012-04-04 19:01:13 -0700
commitb39e509f43665f20877e590d007ac4dfab4d918c (patch)
tree65df9f555271bab655ac80a3692bfcc9a1d42f44
parenta393bedb6da5ef5aecadc26b8895f669448aa0e0 (diff)
parent57cadf2a97a81e5bea49bac573249076ebd95a93 (diff)
Merge "Fixing broken clear focus behavior."
-rw-r--r--core/java/android/view/View.java34
-rw-r--r--core/java/android/view/ViewGroup.java9
2 files changed, 22 insertions, 21 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 4b35c72df9cc..5d7c8cd15669 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4032,8 +4032,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
* <p>
* <strong>Note:</strong> When a View clears focus the framework is trying
* to give focus to the first focusable View from the top. Hence, if this
- * View is the first from the top that can take focus, then its focus will
- * not be cleared nor will the focus change callback be invoked.
+ * View is the first from the top that can take focus, then all callbacks
+ * related to clearing focus will be invoked after wich the framework will
+ * give focus to this view.
* </p>
*/
public void clearFocus() {
@@ -4050,25 +4051,22 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
onFocusChanged(false, 0, null);
refreshDrawableState();
+
+ ensureInputFocusOnFirstFocusable();
}
}
- /**
- * Called to clear the focus of a view that is about to be removed.
- * Doesn't call clearChildFocus, which prevents this view from taking
- * focus again before it has been removed from the parent
- */
- void clearFocusForRemoval() {
- if ((mPrivateFlags & FOCUSED) != 0) {
- mPrivateFlags &= ~FOCUSED;
-
- onFocusChanged(false, 0, null);
- refreshDrawableState();
-
- // The view cleared focus and invoked the callbacks, so now is the
- // time to give focus to the the first focusable from the top to
- // ensure that the gain focus is announced after clear focus.
- getRootView().requestFocus(FOCUS_FORWARD);
+ void ensureInputFocusOnFirstFocusable() {
+ View root = getRootView();
+ if (root != null) {
+ // Find the first focusble from the top.
+ View next = root.focusSearch(FOCUS_FORWARD);
+ if (next != null) {
+ // Giving focus to the found focusable will not
+ // perform a search since we found a view that is
+ // guaranteed to be able to take focus.
+ next.requestFocus(FOCUS_FORWARD);
+ }
}
}
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index ae5debe19463..121b544bf62c 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -3375,7 +3375,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
boolean clearChildFocus = false;
if (view == mFocused) {
- view.clearFocusForRemoval();
+ view.unFocus();
clearChildFocus = true;
}
@@ -3398,6 +3398,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
if (clearChildFocus) {
clearChildFocus(view);
+ ensureInputFocusOnFirstFocusable();
}
}
@@ -3450,7 +3451,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
if (view == focused) {
- view.clearFocusForRemoval();
+ view.unFocus();
clearChildFocus = view;
}
@@ -3474,6 +3475,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
if (clearChildFocus != null) {
clearChildFocus(clearChildFocus);
+ ensureInputFocusOnFirstFocusable();
}
}
@@ -3519,7 +3521,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
}
if (view == focused) {
- view.clearFocusForRemoval();
+ view.unFocus();
clearChildFocus = view;
}
@@ -3542,6 +3544,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
if (clearChildFocus != null) {
clearChildFocus(clearChildFocus);
+ ensureInputFocusOnFirstFocusable();
}
}