Example usage for android.view InflateException InflateException

List of usage examples for android.view InflateException InflateException

Introduction

In this page you can find the example usage for android.view InflateException InflateException.

Prototype

public InflateException(Throwable throwable) 

Source Link

Usage

From source file:com.givewaygames.transition.TransitionInflater.java

/**
 * Loads a {@link Transition} object from a resource
 *
 * @param resource The resource id of the transition to load
 * @return The loaded Transition object/* w  ww . java2 s.co  m*/
 * @throws android.content.res.Resources.NotFoundException when the
 * transition cannot be loaded
 */
public Transition inflateTransition(int resource) {
    XmlResourceParser parser = mContext.getResources().getXml(resource);
    try {
        return createTransitionFromXml(parser, Xml.asAttributeSet(parser), null);
    } catch (XmlPullParserException e) {
        InflateException ex = new InflateException(e.getMessage());
        ex.initCause(e);
        throw ex;
    } catch (IOException e) {
        InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage());
        ex.initCause(e);
        throw ex;
    } finally {
        parser.close();
    }
}

From source file:org.mariotaku.twidere.util.ThemedLayoutInflaterFactory.java

public static View createCustomView(String name, Context context, AttributeSet attrs) {
    if (!name.contains("."))
        return null;
    boolean whiteListed = false;
    for (String prefix : sCustomViewPrefixWhiteList) {
        if (name.startsWith(prefix)) {
            whiteListed = true;/*from w w  w.j av a 2s  .  com*/
            break;
        }
    }
    if (!whiteListed)
        return null;
    //noinspection TryWithIdenticalCatches
    try {
        Constructor<?> constructor = sConstructorCache.get(name);
        if (constructor == null) {
            final Class<?> viewCls = Class.forName(name);
            if (!View.class.isAssignableFrom(viewCls))
                return null;
            constructor = viewCls.getConstructor(Context.class, AttributeSet.class);
            sConstructorCache.put(name, constructor);
        }
        return (View) constructor.newInstance(context, attrs);
    } catch (ClassNotFoundException ignore) {
    } catch (NoSuchMethodException e) {
        throw new InflateException(e);
    } catch (InvocationTargetException e) {
        throw new InflateException(e);
    } catch (InstantiationException e) {
        throw new InflateException(e);
    } catch (IllegalAccessException e) {
        throw new InflateException(e);
    }
    return null;
}

From source file:android.support.graphics.drawable.PathInterpolatorCompat.java

private void parseInterpolatorFromTypeArray(TypedArray a, XmlPullParser parser) {
    // If there is pathData defined in the xml file, then the controls points
    // will be all coming from pathData.
    if (TypedArrayUtils.hasAttribute(parser, "pathData")) {
        String pathData = TypedArrayUtils.getNamedString(a, parser, "pathData",
                AndroidResources.STYLEABLE_PATH_INTERPOLATOR_PATH_DATA);
        Path path = PathParser.createPathFromPathData(pathData);
        if (path == null) {
            throw new InflateException("The path is null, which is created" + " from " + pathData);
        }/*w ww. j a  v  a 2  s. c o  m*/
        initPath(path);
    } else {
        if (!TypedArrayUtils.hasAttribute(parser, "controlX1")) {
            throw new InflateException("pathInterpolator requires the controlX1 attribute");
        } else if (!TypedArrayUtils.hasAttribute(parser, "controlY1")) {
            throw new InflateException("pathInterpolator requires the controlY1 attribute");
        }
        float x1 = TypedArrayUtils.getNamedFloat(a, parser, "controlX1",
                AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_X_1, 0);
        float y1 = TypedArrayUtils.getNamedFloat(a, parser, "controlY1",
                AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_Y_1, 0);

        boolean hasX2 = TypedArrayUtils.hasAttribute(parser, "controlX2");
        boolean hasY2 = TypedArrayUtils.hasAttribute(parser, "controlY2");

        if (hasX2 != hasY2) {
            throw new InflateException(
                    "pathInterpolator requires both controlX2 and" + " controlY2 for cubic Beziers.");
        }

        if (!hasX2) {
            initQuad(x1, y1);
        } else {
            float x2 = TypedArrayUtils.getNamedFloat(a, parser, "controlX2",
                    AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_X_2, 0);
            float y2 = TypedArrayUtils.getNamedFloat(a, parser, "controlY2",
                    AndroidResources.STYLEABLE_PATH_INTERPOLATOR_CONTROL_Y_2, 0);
            initCubic(x1, y1, x2, y2);
        }
    }
}

From source file:android.support.transition.TransitionInflater.java

/**
 * Loads a {@link TransitionManager} object from a resource
 *
 * @param resource The resource id of the transition manager to load
 * @return The loaded TransitionManager object
 * @throws android.content.res.Resources.NotFoundException when the
 *                                                         transition manager cannot be loaded
 *//* w w  w. j  a  v  a2 s. c o m*/
public TransitionManager inflateTransitionManager(int resource, ViewGroup sceneRoot) {
    XmlResourceParser parser = mContext.getResources().getXml(resource);
    try {
        return createTransitionManagerFromXml(parser, Xml.asAttributeSet(parser), sceneRoot);
    } catch (XmlPullParserException e) {
        InflateException ex = new InflateException(e.getMessage());
        ex.initCause(e);
        throw ex;
    } catch (IOException e) {
        InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage());
        ex.initCause(e);
        throw ex;
    } finally {
        parser.close();
    }
}

From source file:dev.drsoran.moloko.util.UIUtils.java

public final static void inflateTags(Context context, ViewGroup container, Collection<String> tags,
        Bundle configuration) {/* w w w  .  j  a  va  2 s . c  om*/
    if (configuration == null) {
        configuration = Bundle.EMPTY;
    }

    final int tagPos = getTaggedViewPos(container, "tag_name");

    if (tagPos != -1) {
        container.removeViews(tagPos, container.getChildCount() - tagPos);
    }

    // inflate the stub and add tags
    if (tags.size() > 0 && !configuration.containsKey(REMOVE_ALL_TAGS)) {
        try {
            final String[] tagsToRemove = configuration.getStringArray(REMOVE_TAGS_EQUALS);

            for (String tagText : tags) {
                boolean remove = false;

                if (tagsToRemove != null) {
                    for (int i = 0; i < tagsToRemove.length && !remove; i++) {
                        remove = tagsToRemove[i].equalsIgnoreCase(tagText);
                    }
                }

                if (!remove) {
                    final TextView tagView = (TextView) View.inflate(context, R.layout.tag_button, null);
                    tagView.setText(tagText);
                    container.addView(tagView);
                }
            }
        } catch (Throwable e) {
            throw new InflateException(e);
        }
    }

    if (container.getChildCount() > 0)
        container.setVisibility(View.VISIBLE);
    else
        container.setVisibility(View.GONE);
}

From source file:android.support.transition.TransitionInflater.java

private Transition createTransitionFromXml(XmlPullParser parser, AttributeSet attrs, Transition parent)
        throws XmlPullParserException, IOException {

    Transition transition = null;//from w w w.  j  a v  a2s .c o  m

    // 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 ("changeScroll".equals(name)) {
            transition = new ChangeScroll(mContext, attrs);
        } else if ("transitionSet".equals(name)) {
            transition = new TransitionSet(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)) {
            if (parent == null) {
                throw new RuntimeException("Invalid use of arcMotion element");
            }
            parent.setPathMotion(new ArcMotion(mContext, attrs));
        } else if ("pathMotion".equals(name)) {
            if (parent == null) {
                throw new RuntimeException("Invalid use of pathMotion element");
            }
            parent.setPathMotion((PathMotion) createCustom(attrs, PathMotion.class, "pathMotion"));
        } else if ("patternPathMotion".equals(name)) {
            if (parent == null) {
                throw new RuntimeException("Invalid use of patternPathMotion element");
            }
            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;
}

From source file:android.support.transition.TransitionInflater.java

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");
    }//from w  w w .  ja  va 2 s  .c o m

    try {
        synchronized (CONSTRUCTORS) {
            Constructor constructor = CONSTRUCTORS.get(className);
            if (constructor == null) {
                @SuppressWarnings("unchecked")
                Class<?> c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
                if (c != null) {
                    constructor = c.getConstructor(CONSTRUCTOR_SIGNATURE);
                    constructor.setAccessible(true);
                    CONSTRUCTORS.put(className, constructor);
                }
            }
            //noinspection ConstantConditions
            return constructor.newInstance(mContext, attrs);
        }
    } catch (Exception e) {
        throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
    }
}

From source file:biz.varkon.shelvesom.server.CVInfo.java

/**
 * Parses a valid XML response from the specified input stream. This method
 * must invoke parse//from   ww w .j ava 2  s  .c o  m
 * {@link ResponseParser#parseResponse(org.xmlpull.v1.XmlPullParser)} if the
 * XML response is valid, or throw an exception if it is not.
 * 
 * @param in
 *            The input stream containing the response sent by the web
 *            service.
 * @param responseParser
 *            The parser to use when the response is valid.
 * 
 * @throws java.io.IOException
 */
public static void parseResponse(InputStream in, ResponseParser responseParser,
        IOUtilities.inputTypes inputType) throws IOException {
    final XmlPullParser parser = Xml.newPullParser();
    try {
        parser.setInput(new InputStreamReader(in));

        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
            // Empty
        }

        if (type != XmlPullParser.START_TAG) {
            throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
        }

        String name;
        boolean valid = false;
        final int topDepth = parser.getDepth();

        while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > topDepth)
                && type != XmlPullParser.END_DOCUMENT) {

            if (type != XmlPullParser.START_TAG) {
                continue;
            }

            name = parser.getName();

            if (RESPONSE_TAG_RESULTS.equals(name)) {
                valid = true;
                break;
            }
        }

        if (valid)
            responseParser.parseResponse(parser);

    } catch (XmlPullParserException e) {
        final IOException ioe = new IOException("Could not parse the response");
        ioe.initCause(e);
        throw ioe;
    }
}

From source file:com.transitionseverywhere.TransitionInflater.java

private Transition createTransitionFromXml(XmlPullParser parser, AttributeSet attrs, Transition parent)
        throws XmlPullParserException, IOException {

    Transition transition = null;//from   ww  w  .j av  a 2 s .c o m

    // 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;
}

From source file:com.transitionseverywhere.TransitionInflater.java

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");
    }/*from  ww  w. ja  va  2 s.c o  m*/

    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);
    }
}