Search in sources :

Example 11 with InflateException

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

the class AnimatorInflater method setupObjectAnimator.

/**
     * Setup ObjectAnimator's property or values from pathData.
     *
     * @param anim The target Animator which will be updated.
     * @param arrayObjectAnimator TypedArray for the ObjectAnimator.
     * @param getFloats True if the value type is float.
     * @param pixelSize The relative pixel size, used to calculate the
     *                  maximum error for path animations.
     */
private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator, boolean getFloats, float pixelSize) {
    ObjectAnimator oa = (ObjectAnimator) anim;
    String pathData = arrayObjectAnimator.getString(R.styleable.PropertyAnimator_pathData);
    // Here we are dealing with case 2:
    if (pathData != null) {
        String propertyXName = arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyXName);
        String propertyYName = arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyYName);
        if (propertyXName == null && propertyYName == null) {
            throw new InflateException(arrayObjectAnimator.getPositionDescription() + " propertyXName or propertyYName is needed for PathData");
        } else {
            Path path = PathParser.createPathFromPathData(pathData);
            // max half a pixel error
            float error = 0.5f * pixelSize;
            PathKeyframes keyframeSet = KeyframeSet.ofPath(path, error);
            Keyframes xKeyframes;
            Keyframes yKeyframes;
            if (getFloats) {
                xKeyframes = keyframeSet.createXFloatKeyframes();
                yKeyframes = keyframeSet.createYFloatKeyframes();
            } else {
                xKeyframes = keyframeSet.createXIntKeyframes();
                yKeyframes = keyframeSet.createYIntKeyframes();
            }
            PropertyValuesHolder x = null;
            PropertyValuesHolder y = null;
            if (propertyXName != null) {
                x = PropertyValuesHolder.ofKeyframes(propertyXName, xKeyframes);
            }
            if (propertyYName != null) {
                y = PropertyValuesHolder.ofKeyframes(propertyYName, yKeyframes);
            }
            if (x == null) {
                oa.setValues(y);
            } else if (y == null) {
                oa.setValues(x);
            } else {
                oa.setValues(x, y);
            }
        }
    } else {
        String propertyName = arrayObjectAnimator.getString(R.styleable.PropertyAnimator_propertyName);
        oa.setPropertyName(propertyName);
    }
}
Also used : Path(android.graphics.Path) InflateException(android.view.InflateException)

Example 12 with InflateException

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

the class GenericInflater method inflate.

/**
     * Inflate a new hierarchy from the specified XML node. Throws
     * InflaterException if there is an error.
     * <p>
     * <em><strong>Important</strong></em>&nbsp;&nbsp;&nbsp;For performance
     * reasons, inflation relies heavily on pre-processing of XML files
     * that is done at build time. Therefore, it is not currently possible to
     * use inflater with an XmlPullParser over a plain XML file at runtime.
     * 
     * @param parser XML dom node containing the description of the
     *        hierarchy.
     * @param root Optional to be the parent of the generated hierarchy (if
     *        <em>attachToRoot</em> is true), or else simply an object that
     *        provides a set of values for root of the returned
     *        hierarchy (if <em>attachToRoot</em> is false.)
     * @param attachToRoot Whether the inflated hierarchy should be attached to
     *        the root parameter?
     * @return The root of the inflated hierarchy. If root was supplied and
     *         attachToRoot is true, this is root; otherwise it is the root of
     *         the inflated XML file.
     */
public T inflate(XmlPullParser parser, P root, boolean attachToRoot) {
    synchronized (mConstructorArgs) {
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        mConstructorArgs[0] = mContext;
        T result = (T) root;
        try {
            // Look for the root node.
            int type;
            while ((type = parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) {
                ;
            }
            if (type != parser.START_TAG) {
                throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
            }
            if (DEBUG) {
                System.out.println("**************************");
                System.out.println("Creating root: " + parser.getName());
                System.out.println("**************************");
            }
            // Temp is the root that was found in the xml
            T xmlRoot = createItemFromTag(parser, parser.getName(), attrs);
            result = (T) onMergeRoots(root, attachToRoot, (P) xmlRoot);
            if (DEBUG) {
                System.out.println("-----> start inflating children");
            }
            // Inflate all children under temp
            rInflate(parser, result, attrs);
            if (DEBUG) {
                System.out.println("-----> done inflating children");
            }
        } catch (InflateException e) {
            throw e;
        } 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;
        }
        return result;
    }
}
Also used : AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 13 with InflateException

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

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 ("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 : InflateException(android.view.InflateException)

Example 14 with InflateException

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

the class GenericInflater method createItem.

/**
     * Low-level function for instantiating by name. This attempts to
     * instantiate class of the given <var>name</var> found in this
     * inflater's ClassLoader.
     * 
     * <p>
     * There are two things that can happen in an error case: either the
     * exception describing the error will be thrown, or a null will be
     * returned. You must deal with both possibilities -- the former will happen
     * the first time createItem() is called for a class of a particular name,
     * the latter every time there-after for that class name.
     * 
     * @param name The full name of the class to be instantiated.
     * @param attrs The XML attributes supplied for this instance.
     * 
     * @return The newly instantied item, or null.
     */
public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
    Constructor constructor = (Constructor) sConstructorMap.get(name);
    try {
        if (null == constructor) {
            // Class not found in the cache, see if it's real,
            // and try to add it
            Class clazz = mContext.getClassLoader().loadClass(prefix != null ? (prefix + name) : name);
            constructor = clazz.getConstructor(mConstructorSignature);
            constructor.setAccessible(true);
            sConstructorMap.put(name, constructor);
        }
        Object[] args = mConstructorArgs;
        args[1] = attrs;
        return (T) constructor.newInstance(args);
    } catch (NoSuchMethodException e) {
        InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (prefix != null ? (prefix + name) : name));
        ie.initCause(e);
        throw ie;
    } catch (ClassNotFoundException e) {
        // If loadClass fails, we should propagate the exception.
        throw e;
    } catch (Exception e) {
        InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + constructor.getClass().getName());
        ie.initCause(e);
        throw ie;
    }
}
Also used : Constructor(java.lang.reflect.Constructor) InflateException(android.view.InflateException) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) InflateException(android.view.InflateException)

Example 15 with InflateException

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

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)

Aggregations

InflateException (android.view.InflateException)100 IOException (java.io.IOException)51 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)48 AttributeSet (android.util.AttributeSet)30 XmlResourceParser (android.content.res.XmlResourceParser)19 Constructor (java.lang.reflect.Constructor)13 View (android.view.View)12 Path (android.graphics.Path)10 SuppressLint (android.annotation.SuppressLint)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 StringTokenizer (java.util.StringTokenizer)6 NonNull (android.annotation.NonNull)5 PathParser (android.util.PathParser)5 TypedValue (android.util.TypedValue)5 NonNull (android.support.annotation.NonNull)4 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)3 LayoutInflater (android.view.LayoutInflater)3