Search in sources :

Example 56 with InflateException

use of android.view.InflateException in project android_frameworks_base by DirtyUnicorns.

the class Transition method parseMatchOrder.

private static int[] parseMatchOrder(String matchOrderString) {
    StringTokenizer st = new StringTokenizer(matchOrderString, ",");
    int[] matches = new int[st.countTokens()];
    int index = 0;
    while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
        if (MATCH_ID_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_ID;
        } else if (MATCH_INSTANCE_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_INSTANCE;
        } else if (MATCH_NAME_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_NAME;
        } else if (MATCH_VIEW_NAME_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_NAME;
        } else if (MATCH_ITEM_ID_STR.equalsIgnoreCase(token)) {
            matches[index] = Transition.MATCH_ITEM_ID;
        } else if (token.isEmpty()) {
            int[] smallerMatches = new int[matches.length - 1];
            System.arraycopy(matches, 0, smallerMatches, 0, index);
            matches = smallerMatches;
            index--;
        } else {
            throw new InflateException("Unknown match type in matchOrder: '" + token + "'");
        }
        index++;
    }
    return matches;
}
Also used : StringTokenizer(java.util.StringTokenizer) InflateException(android.view.InflateException)

Example 57 with InflateException

use of android.view.InflateException in project android_frameworks_base by DirtyUnicorns.

the class PathInterpolator method parseInterpolatorFromTypeArray.

private void parseInterpolatorFromTypeArray(TypedArray a) {
    // will be all coming from pathData.
    if (a.hasValue(R.styleable.PathInterpolator_pathData)) {
        String pathData = a.getString(R.styleable.PathInterpolator_pathData);
        Path path = PathParser.createPathFromPathData(pathData);
        if (path == null) {
            throw new InflateException("The path is null, which is created" + " from " + pathData);
        }
        initPath(path);
    } else {
        if (!a.hasValue(R.styleable.PathInterpolator_controlX1)) {
            throw new InflateException("pathInterpolator requires the controlX1 attribute");
        } else if (!a.hasValue(R.styleable.PathInterpolator_controlY1)) {
            throw new InflateException("pathInterpolator requires the controlY1 attribute");
        }
        float x1 = a.getFloat(R.styleable.PathInterpolator_controlX1, 0);
        float y1 = a.getFloat(R.styleable.PathInterpolator_controlY1, 0);
        boolean hasX2 = a.hasValue(R.styleable.PathInterpolator_controlX2);
        boolean hasY2 = a.hasValue(R.styleable.PathInterpolator_controlY2);
        if (hasX2 != hasY2) {
            throw new InflateException("pathInterpolator requires both controlX2 and controlY2 for cubic Beziers.");
        }
        if (!hasX2) {
            initQuad(x1, y1);
        } else {
            float x2 = a.getFloat(R.styleable.PathInterpolator_controlX2, 0);
            float y2 = a.getFloat(R.styleable.PathInterpolator_controlY2, 0);
            initCubic(x1, y1, x2, y2);
        }
    }
}
Also used : Path(android.graphics.Path) InflateException(android.view.InflateException)

Example 58 with InflateException

use of android.view.InflateException in project material-components-android by material-components.

the class TabLayoutTest method testInflateTabLayoutWithNonTabItem.

@Test
@UiThreadTest
public void testInflateTabLayoutWithNonTabItem() throws Throwable {
    try {
        final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
        inflater.inflate(R.layout.design_tabs_with_non_tabitems, null);
    } catch (Throwable throwable) {
        assertTrue(throwable instanceof InflateException || throwable instanceof IllegalArgumentException);
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) InflateException(android.view.InflateException) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 59 with InflateException

use of android.view.InflateException in project Transitions-Everywhere by andkulikov.

the class TransitionInflater method createCustom.

private Object createCustom(AttributeSet attrs, Class expectedType, String tag) {
    String className = attrs.getAttributeValue(null, "class");
    if (className == null) {
        throw new InflateException(tag + " tag must have a 'class' attribute");
    }
    try {
        synchronized (sConstructors) {
            Constructor constructor = sConstructors.get(className);
            if (constructor == null) {
                Class c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
                if (c != null) {
                    constructor = c.getConstructor(sConstructorSignature);
                    if (!constructor.isAccessible()) {
                        constructor.setAccessible(true);
                    }
                    sConstructors.put(className, constructor);
                }
            }
            return constructor.newInstance(mContext, attrs);
        }
    } catch (InstantiationException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (ClassNotFoundException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (InvocationTargetException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (NoSuchMethodException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    } catch (IllegalAccessException e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InflateException(android.view.InflateException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 60 with InflateException

use of android.view.InflateException in project Transitions-Everywhere by andkulikov.

the class TransitionInflater method createTransitionFromXml.

//
// Transition loading
//
private Transition createTransitionFromXml(XmlPullParser parser, AttributeSet attrs, Transition parent) throws XmlPullParserException, IOException {
    Transition transition = null;
    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();
    TransitionSet transitionSet = (parent instanceof TransitionSet) ? (TransitionSet) parent : null;
    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if ("fade".equals(name)) {
            transition = new Fade(mContext, attrs);
        } else if ("changeBounds".equals(name)) {
            transition = new ChangeBounds(mContext, attrs);
        } else if ("slide".equals(name)) {
            transition = new Slide(mContext, attrs);
        } else if ("explode".equals(name)) {
            transition = new Explode(mContext, attrs);
        } else if ("changeImageTransform".equals(name)) {
            transition = new ChangeImageTransform(mContext, attrs);
        } else if ("changeTransform".equals(name)) {
            transition = new ChangeTransform(mContext, attrs);
        } else if ("changeClipBounds".equals(name)) {
            transition = new ChangeClipBounds(mContext, attrs);
        } else if ("autoTransition".equals(name)) {
            transition = new AutoTransition(mContext, attrs);
        } else if ("recolor".equals(name)) {
            transition = new Recolor(mContext, attrs);
        } else if ("changeScroll".equals(name)) {
            transition = new ChangeScroll(mContext, attrs);
        } else if ("transitionSet".equals(name)) {
            transition = new TransitionSet(mContext, attrs);
        } else if ("scale".equals(name)) {
            transition = new Scale(mContext, attrs);
        } else if ("translation".equals(name)) {
            transition = new TranslationTransition(mContext, attrs);
        } else if ("transition".equals(name)) {
            transition = (Transition) createCustom(attrs, Transition.class, "transition");
        } else if ("targets".equals(name)) {
            getTargetIds(parser, attrs, parent);
        } else if ("arcMotion".equals(name)) {
            parent.setPathMotion(new ArcMotion(mContext, attrs));
        } else if ("pathMotion".equals(name)) {
            parent.setPathMotion((PathMotion) createCustom(attrs, PathMotion.class, "pathMotion"));
        } else if ("patternPathMotion".equals(name)) {
            parent.setPathMotion(new PatternPathMotion(mContext, attrs));
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
        if (transition != null) {
            if (!parser.isEmptyElementTag()) {
                createTransitionFromXml(parser, attrs, transition);
            }
            if (transitionSet != null) {
                transitionSet.addTransition(transition);
                transition = null;
            } else if (parent != null) {
                throw new InflateException("Could not add transition to another transition.");
            }
        }
    }
    return transition;
}
Also used : Scale(com.transitionseverywhere.extra.Scale) TranslationTransition(com.transitionseverywhere.extra.TranslationTransition) TranslationTransition(com.transitionseverywhere.extra.TranslationTransition) InflateException(android.view.InflateException)

Aggregations

InflateException (android.view.InflateException)91 IOException (java.io.IOException)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 AttributeSet (android.util.AttributeSet)28 XmlResourceParser (android.content.res.XmlResourceParser)18 Constructor (java.lang.reflect.Constructor)13 Path (android.graphics.Path)10 View (android.view.View)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 StringTokenizer (java.util.StringTokenizer)6 NonNull (android.annotation.NonNull)5 SuppressLint (android.annotation.SuppressLint)5 PathParser (android.util.PathParser)5 TypedValue (android.util.TypedValue)5 ExpandedMenuView (android.support.v7.internal.view.menu.ExpandedMenuView)4 ActionBarView (android.support.v7.internal.widget.ActionBarView)4 ViewGroup (android.view.ViewGroup)4 AlertDialog (android.app.AlertDialog)2 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2