Loading core/java/android/view/View.java +16 −18 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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); } } } Loading core/java/android/view/ViewGroup.java +6 −3 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -3398,6 +3398,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus) { clearChildFocus(view); ensureInputFocusOnFirstFocusable(); } } Loading Loading @@ -3450,7 +3451,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (view == focused) { view.clearFocusForRemoval(); view.unFocus(); clearChildFocus = view; } Loading @@ -3474,6 +3475,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus != null) { clearChildFocus(clearChildFocus); ensureInputFocusOnFirstFocusable(); } } Loading Loading @@ -3519,7 +3521,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (view == focused) { view.clearFocusForRemoval(); view.unFocus(); clearChildFocus = view; } Loading @@ -3542,6 +3544,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus != null) { clearChildFocus(clearChildFocus); ensureInputFocusOnFirstFocusable(); } } Loading Loading
core/java/android/view/View.java +16 −18 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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); } } } Loading
core/java/android/view/ViewGroup.java +6 −3 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -3398,6 +3398,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus) { clearChildFocus(view); ensureInputFocusOnFirstFocusable(); } } Loading Loading @@ -3450,7 +3451,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (view == focused) { view.clearFocusForRemoval(); view.unFocus(); clearChildFocus = view; } Loading @@ -3474,6 +3475,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus != null) { clearChildFocus(clearChildFocus); ensureInputFocusOnFirstFocusable(); } } Loading Loading @@ -3519,7 +3521,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager } if (view == focused) { view.clearFocusForRemoval(); view.unFocus(); clearChildFocus = view; } Loading @@ -3542,6 +3544,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if (clearChildFocus != null) { clearChildFocus(clearChildFocus); ensureInputFocusOnFirstFocusable(); } } Loading