From 973f3b4ebf79c8ce9233e2320d13c2b92d420f93 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Tue, 13 Aug 2013 16:57:28 -0700 Subject: [PATCH] Prevent refocus after entering touch mode BUG: 10210009 Change-Id: I9a5d7016728cc7d1fb1c759708b6df41c81865bb --- core/java/android/view/View.java | 24 ++++++++++++++++-------- core/java/android/view/ViewRootImpl.java | 6 +++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 7a8289276ea47..d22a46861f893 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4572,10 +4572,23 @@ public class View implements Drawable.Callback, KeyEvent.Callback, System.out.println(this + " clearFocus()"); } + clearFocusInternal(true, true); + } + + /** + * Clears focus from the view, optionally propagating the change up through + * the parent hierarchy and requesting that the root view place new focus. + * + * @param propagate whether to propagate the change up through the parent + * hierarchy + * @param refocus when propagate is true, specifies whether to request the + * root view place new focus + */ + void clearFocusInternal(boolean propagate, boolean refocus) { if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { mPrivateFlags &= ~PFLAG_FOCUSED; - if (mParent != null) { + if (propagate && mParent != null) { mParent.clearChildFocus(this); } @@ -4583,7 +4596,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, refreshDrawableState(); - if (!rootViewRequestFocus()) { + if (propagate && (!refocus || !rootViewRequestFocus())) { notifyGlobalFocusCleared(this); } } @@ -4613,12 +4626,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, System.out.println(this + " unFocus()"); } - if ((mPrivateFlags & PFLAG_FOCUSED) != 0) { - mPrivateFlags &= ~PFLAG_FOCUSED; - - onFocusChanged(false, 0, null); - refreshDrawableState(); - } + clearFocusInternal(false, false); } /** diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3977a33f3197b..e90705c1ed538 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3271,9 +3271,9 @@ public final class ViewRootImpl implements ViewParent, // focus return ancestorToTakeFocus.requestFocus(); } else { - // nothing appropriate to have focus in touch mode, clear it - // out - focused.clearFocus(); + // There's nothing to focus. Clear and propagate through the + // hierarchy, but don't attempt to place new focus. + focused.clearFocusInternal(true, false); return true; } }