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);
}
refreshDrawableState();
- if (!rootViewRequestFocus()) {
+ if (propagate && (!refocus || !rootViewRequestFocus())) {
notifyGlobalFocusCleared(this);
}
}
System.out.println(this + " unFocus()");
}
- if ((mPrivateFlags & PFLAG_FOCUSED) != 0) {
- mPrivateFlags &= ~PFLAG_FOCUSED;
-
- onFocusChanged(false, 0, null);
- refreshDrawableState();
- }
+ clearFocusInternal(false, false);
}
/**
// 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;
}
}