Loading core/java/android/view/LayoutInflater.java +7 −12 Original line number Diff line number Diff line Loading @@ -833,6 +833,7 @@ public abstract class LayoutInflater { final int depth = parser.getDepth(); int type; boolean pendingRequestFocus = false; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { Loading @@ -844,7 +845,8 @@ public abstract class LayoutInflater { final String name = parser.getName(); if (TAG_REQUEST_FOCUS.equals(name)) { parseRequestFocus(parser, parent); pendingRequestFocus = true; consumeChildElements(parser); } else if (TAG_TAG.equals(name)) { parseViewTag(parser, parent, attrs); } else if (TAG_INCLUDE.equals(name)) { Loading @@ -863,22 +865,15 @@ public abstract class LayoutInflater { } } if (pendingRequestFocus) { parent.restoreDefaultFocus(); } if (finishInflate) { parent.onFinishInflate(); } } /** * Parses a <code><request-focus></code> element and requests focus on * the containing View. */ private void parseRequestFocus(XmlPullParser parser, View view) throws XmlPullParserException, IOException { view.requestFocus(); consumeChildElements(parser); } /** * Parses a <code><tag></code> element and sets a keyed tag on the * containing View. Loading core/java/android/view/ViewRootImpl.java +27 −8 Original line number Diff line number Diff line Loading @@ -163,6 +163,17 @@ public final class ViewRootImpl implements ViewParent, static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); /** * Signals that compatibility booleans have been initialized according to * target SDK versions. */ private static boolean sCompatibilityDone = false; /** * Always assign focus if a focusable View is available. */ private static boolean sAlwaysAssignFocus; /** * This list must only be modified by the main thread, so a lock is only needed when changing * the list or when accessing the list from a non-main thread. Loading Loading @@ -451,6 +462,13 @@ public final class ViewRootImpl implements ViewParent, mFallbackEventHandler = new PhoneFallbackEventHandler(context); mChoreographer = Choreographer.getInstance(); mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); if (!sCompatibilityDone) { sAlwaysAssignFocus = mTargetSdkVersion < Build.VERSION_CODES.O; sCompatibilityDone = true; } loadSystemProperties(); } Loading Loading @@ -2180,7 +2198,7 @@ public final class ViewRootImpl implements ViewParent, } } if (mFirst) { if (mFirst && sAlwaysAssignFocus) { // handle first focus request if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: mView.hasFocus()=" + mView.hasFocus()); Loading Loading @@ -3290,7 +3308,9 @@ public final class ViewRootImpl implements ViewParent, checkThread(); if (mView != null) { if (!mView.hasFocus()) { if (sAlwaysAssignFocus) { v.requestFocus(); } } else { // the one case where will transfer focus away from the current one // is if the current view is a view group that prefers to give focus Loading Loading @@ -4463,9 +4483,7 @@ public final class ViewRootImpl implements ViewParent, return true; } } else { // find the best view to give focus to in this non-touch-mode with no-focus View v = focusSearch(null, direction); if (v != null && v.requestFocus(direction)) { if (mView.restoreDefaultFocus()) { return true; } } Loading @@ -4475,9 +4493,10 @@ public final class ViewRootImpl implements ViewParent, private boolean performKeyboardGroupNavigation(int direction) { final View focused = mView.findFocus(); View cluster = focused != null ? focused.keyboardNavigationClusterSearch(null, direction) : keyboardNavigationClusterSearch(null, direction); if (focused == null && mView.restoreDefaultFocus()) { return true; } View cluster = focused.keyboardNavigationClusterSearch(null, direction); // Since requestFocus only takes "real" focus directions (and therefore also // restoreFocusInCluster), convert forward/backward focus into FOCUS_DOWN. Loading Loading
core/java/android/view/LayoutInflater.java +7 −12 Original line number Diff line number Diff line Loading @@ -833,6 +833,7 @@ public abstract class LayoutInflater { final int depth = parser.getDepth(); int type; boolean pendingRequestFocus = false; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { Loading @@ -844,7 +845,8 @@ public abstract class LayoutInflater { final String name = parser.getName(); if (TAG_REQUEST_FOCUS.equals(name)) { parseRequestFocus(parser, parent); pendingRequestFocus = true; consumeChildElements(parser); } else if (TAG_TAG.equals(name)) { parseViewTag(parser, parent, attrs); } else if (TAG_INCLUDE.equals(name)) { Loading @@ -863,22 +865,15 @@ public abstract class LayoutInflater { } } if (pendingRequestFocus) { parent.restoreDefaultFocus(); } if (finishInflate) { parent.onFinishInflate(); } } /** * Parses a <code><request-focus></code> element and requests focus on * the containing View. */ private void parseRequestFocus(XmlPullParser parser, View view) throws XmlPullParserException, IOException { view.requestFocus(); consumeChildElements(parser); } /** * Parses a <code><tag></code> element and sets a keyed tag on the * containing View. Loading
core/java/android/view/ViewRootImpl.java +27 −8 Original line number Diff line number Diff line Loading @@ -163,6 +163,17 @@ public final class ViewRootImpl implements ViewParent, static final ArrayList<ComponentCallbacks> sConfigCallbacks = new ArrayList(); /** * Signals that compatibility booleans have been initialized according to * target SDK versions. */ private static boolean sCompatibilityDone = false; /** * Always assign focus if a focusable View is available. */ private static boolean sAlwaysAssignFocus; /** * This list must only be modified by the main thread, so a lock is only needed when changing * the list or when accessing the list from a non-main thread. Loading Loading @@ -451,6 +462,13 @@ public final class ViewRootImpl implements ViewParent, mFallbackEventHandler = new PhoneFallbackEventHandler(context); mChoreographer = Choreographer.getInstance(); mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE); if (!sCompatibilityDone) { sAlwaysAssignFocus = mTargetSdkVersion < Build.VERSION_CODES.O; sCompatibilityDone = true; } loadSystemProperties(); } Loading Loading @@ -2180,7 +2198,7 @@ public final class ViewRootImpl implements ViewParent, } } if (mFirst) { if (mFirst && sAlwaysAssignFocus) { // handle first focus request if (DEBUG_INPUT_RESIZE) Log.v(mTag, "First: mView.hasFocus()=" + mView.hasFocus()); Loading Loading @@ -3290,7 +3308,9 @@ public final class ViewRootImpl implements ViewParent, checkThread(); if (mView != null) { if (!mView.hasFocus()) { if (sAlwaysAssignFocus) { v.requestFocus(); } } else { // the one case where will transfer focus away from the current one // is if the current view is a view group that prefers to give focus Loading Loading @@ -4463,9 +4483,7 @@ public final class ViewRootImpl implements ViewParent, return true; } } else { // find the best view to give focus to in this non-touch-mode with no-focus View v = focusSearch(null, direction); if (v != null && v.requestFocus(direction)) { if (mView.restoreDefaultFocus()) { return true; } } Loading @@ -4475,9 +4493,10 @@ public final class ViewRootImpl implements ViewParent, private boolean performKeyboardGroupNavigation(int direction) { final View focused = mView.findFocus(); View cluster = focused != null ? focused.keyboardNavigationClusterSearch(null, direction) : keyboardNavigationClusterSearch(null, direction); if (focused == null && mView.restoreDefaultFocus()) { return true; } View cluster = focused.keyboardNavigationClusterSearch(null, direction); // Since requestFocus only takes "real" focus directions (and therefore also // restoreFocusInCluster), convert forward/backward focus into FOCUS_DOWN. Loading