diff options
| -rw-r--r-- | core/java/android/view/LayoutInflater.java | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java index 80a3cf0f14a2..723289005651 100644 --- a/core/java/android/view/LayoutInflater.java +++ b/core/java/android/view/LayoutInflater.java @@ -17,6 +17,7 @@ package android.view; import android.annotation.LayoutRes; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemService; import android.annotation.UnsupportedAppUsage; @@ -774,24 +775,8 @@ public abstract class LayoutInflater { ta.recycle(); } - if (name.equals(TAG_1995)) { - // Let's party like it's 1995! - return new BlinkLayout(context, attrs); - } - try { - View view; - if (mFactory2 != null) { - view = mFactory2.onCreateView(parent, name, context, attrs); - } else if (mFactory != null) { - view = mFactory.onCreateView(name, context, attrs); - } else { - view = null; - } - - if (view == null && mPrivateFactory != null) { - view = mPrivateFactory.onCreateView(parent, name, context, attrs); - } + View view = tryCreateView(parent, name, context, attrs); if (view == null) { final Object lastContext = mConstructorArgs[0]; @@ -826,6 +811,48 @@ public abstract class LayoutInflater { } /** + * Tries to create a view from a tag name using the supplied attribute set. + * + * This method gives the factory provided by {@link LayoutInflater#setFactory} and + * {@link LayoutInflater#setFactory2} a chance to create a view. However, it does not apply all + * of the general view creation logic, and thus may return {@code null} for some tags. This + * method is used by {@link LayoutInflater#inflate} in creating {@code View} objects. + * + * @hide for use by precompiled layouts. + * + * @param parent the parent view, used to inflate layout params + * @param name the name of the XML tag used to define the view + * @param context the inflation context for the view, typically the + * {@code parent} or base layout inflater context + * @param attrs the attribute set for the XML tag used to define the view + */ + @UnsupportedAppUsage(trackingBug = 122360734) + @Nullable + public final View tryCreateView(@Nullable View parent, @NonNull String name, + @NonNull Context context, + @NonNull AttributeSet attrs) { + if (name.equals(TAG_1995)) { + // Let's party like it's 1995! + return new BlinkLayout(context, attrs); + } + + View view; + if (mFactory2 != null) { + view = mFactory2.onCreateView(parent, name, context, attrs); + } else if (mFactory != null) { + view = mFactory.onCreateView(name, context, attrs); + } else { + view = null; + } + + if (view == null && mPrivateFactory != null) { + view = mPrivateFactory.onCreateView(parent, name, context, attrs); + } + + return view; + } + + /** * Recursive method used to inflate internal (non-root) children. This * method calls through to {@link #rInflate} using the parent context as * the inflation context. |