Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3224f353 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Clean up ViewStub inflation to ensure it has resources"

parents 079aa89f 39a72dd2
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ import java.lang.ref.WeakReference;
 */
@RemoteView
public final class ViewStub extends View {
    private int mLayoutResource = 0;
    private int mInflatedId;
    private int mLayoutResource;

    private WeakReference<View> mInflatedViewRef;

@@ -78,7 +78,7 @@ public final class ViewStub extends View {
    private OnInflateListener mInflateListener;

    public ViewStub(Context context) {
        initialize(context);
        this(context, 0);
    }

    /**
@@ -88,38 +88,29 @@ public final class ViewStub extends View {
     * @param layoutResource The reference to a layout resource that will be inflated.
     */
    public ViewStub(Context context, int layoutResource) {
        this(context, null);

        mLayoutResource = layoutResource;
        initialize(context);
    }

    public ViewStub(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    @SuppressWarnings({"UnusedDeclaration"})
    public ViewStub(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public ViewStub(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.ViewStub, defStyleAttr, defStyleRes);
        super(context);

        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.ViewStub, defStyleAttr, defStyleRes);
        mInflatedId = a.getResourceId(R.styleable.ViewStub_inflatedId, NO_ID);
        mLayoutResource = a.getResourceId(R.styleable.ViewStub_layout, 0);

        a.recycle();

        a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.View, defStyleAttr, defStyleRes);
        mID = a.getResourceId(R.styleable.View_id, NO_ID);
        mID = a.getResourceId(R.styleable.ViewStub_id, NO_ID);
        a.recycle();

        initialize(context);
    }

    private void initialize(Context context) {
        mContext = context;
        setVisibility(GONE);
        setWillNotDraw(true);
    }
+2 −0
Original line number Diff line number Diff line
@@ -2722,6 +2722,8 @@
    <!-- A {@link android.view.ViewStub} lets you lazily include other XML layouts
         inside your application at runtime. -->
    <declare-styleable name="ViewStub">
        <!-- Supply an identifier name for this view. -->
        <attr name="id" />
        <!-- Supply an identifier for the layout resource to inflate when the ViewStub
             becomes visible or when forced to do so. The layout resource must be a
             valid reference to a layout. -->