Search in sources :

Example 86 with InflateException

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

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 87 with InflateException

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

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 88 with InflateException

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

the class AnimatorInflater method getPVH.

private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId, int valueToId, String propertyName) {
    TypedValue tvFrom = styledAttributes.peekValue(valueFromId);
    boolean hasFrom = (tvFrom != null);
    int fromType = hasFrom ? tvFrom.type : 0;
    TypedValue tvTo = styledAttributes.peekValue(valueToId);
    boolean hasTo = (tvTo != null);
    int toType = hasTo ? tvTo.type : 0;
    if (valueType == VALUE_TYPE_UNDEFINED) {
        // Check whether it's color type. If not, fall back to default type (i.e. float type)
        if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) {
            valueType = VALUE_TYPE_COLOR;
        } else {
            valueType = VALUE_TYPE_FLOAT;
        }
    }
    boolean getFloats = (valueType == VALUE_TYPE_FLOAT);
    PropertyValuesHolder returnValue = null;
    if (valueType == VALUE_TYPE_PATH) {
        String fromString = styledAttributes.getString(valueFromId);
        String toString = styledAttributes.getString(valueToId);
        PathParser.PathData nodesFrom = fromString == null ? null : new PathParser.PathData(fromString);
        PathParser.PathData nodesTo = toString == null ? null : new PathParser.PathData(toString);
        if (nodesFrom != null || nodesTo != null) {
            if (nodesFrom != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                if (nodesTo != null) {
                    if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                        throw new InflateException(" Can't morph from " + fromString + " to " + toString);
                    }
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo);
                } else {
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom);
                }
            } else if (nodesTo != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo);
            }
        }
    } else {
        TypeEvaluator evaluator = null;
        // Integer and float value types are handled here.
        if (valueType == VALUE_TYPE_COLOR) {
            // special case for colors: ignore valueType and get ints
            evaluator = ArgbEvaluator.getInstance();
        }
        if (getFloats) {
            float valueFrom;
            float valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = styledAttributes.getDimension(valueFromId, 0f);
                } else {
                    valueFrom = styledAttributes.getFloat(valueFromId, 0f);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = styledAttributes.getDimension(valueToId, 0f);
                    } else {
                        valueTo = styledAttributes.getFloat(valueToId, 0f);
                    }
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom);
                }
            } else {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = styledAttributes.getDimension(valueToId, 0f);
                } else {
                    valueTo = styledAttributes.getFloat(valueToId, 0f);
                }
                returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo);
            }
        } else {
            int valueFrom;
            int valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f);
                } else if (isColorType(fromType)) {
                    valueFrom = styledAttributes.getColor(valueFromId, 0);
                } else {
                    valueFrom = styledAttributes.getInt(valueFromId, 0);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom);
                }
            } else {
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo);
                }
            }
        }
        if (returnValue != null && evaluator != null) {
            returnValue.setEvaluator(evaluator);
        }
    }
    return returnValue;
}
Also used : PathParser(android.util.PathParser) InflateException(android.view.InflateException) TypedValue(android.util.TypedValue)

Example 89 with InflateException

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

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 90 with InflateException

use of android.view.InflateException in project little-bear-dictionary by daimajia.

the class GenericInflater method createItem.

@SuppressWarnings("unchecked")
public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
    Constructor<?> constructor = GenericInflater.constructorMap.get(name);
    try {
        if (constructor == null) {
            Class<?> clazz = context.getClassLoader().loadClass(prefix != null ? prefix + name : name);
            constructor = findConstructor(clazz);
            GenericInflater.constructorMap.put(name, constructor);
        }
        Object[] args = constructorArgs;
        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 (Exception e) {
        InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + constructor.toString());
        ie.initCause(e);
        throw ie;
    }
}
Also used : InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) InflateException(android.view.InflateException) IOException(java.io.IOException)

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