Search in sources :

Example 6 with MockView

use of com.android.layoutlib.bridge.MockView in project android_frameworks_base by crdroidandroid.

the class BridgeInflater method createViewFromTag.

@Override
public View createViewFromTag(View parent, String name, Context context, AttributeSet attrs, boolean ignoreThemeAttr) {
    View view;
    try {
        view = super.createViewFromTag(parent, name, context, attrs, ignoreThemeAttr);
    } catch (InflateException e) {
        // Apply a theme wrapper, if allowed and one is specified.
        if (!ignoreThemeAttr) {
            final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);
            final int themeResId = ta.getResourceId(0, 0);
            if (themeResId != 0) {
                context = new ContextThemeWrapper(context, themeResId);
            }
            ta.recycle();
        }
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            // There is some unknown inflation exception in inflating a View that was found.
            view = new MockView(context, attrs);
            ((MockView) view).setText(name);
            Bridge.getLog().error(LayoutLog.TAG_BROKEN, e.getMessage(), e, null);
        } else {
            final Object lastContext = mConstructorArgs[0];
            mConstructorArgs[0] = context;
            // try to load the class from using the custom view loader
            try {
                view = loadCustomView(name, attrs);
            } catch (Exception e2) {
                // Wrap the real exception in an InflateException so that the calling
                // method can deal with it.
                InflateException exception = new InflateException();
                if (!e2.getClass().equals(ClassNotFoundException.class)) {
                    exception.initCause(e2);
                } else {
                    exception.initCause(e);
                }
                throw exception;
            } finally {
                mConstructorArgs[0] = lastContext;
            }
        }
    }
    setupViewInContext(view, attrs);
    return view;
}
Also used : MockView(com.android.layoutlib.bridge.MockView) TypedArray(android.content.res.TypedArray) MockView(com.android.layoutlib.bridge.MockView)

Aggregations

MockView (com.android.layoutlib.bridge.MockView)6 TypedArray (android.content.res.TypedArray)5 NotNull (org.jetbrains.annotations.NotNull)1