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:android.support.graphics.drawable.AnimatorInflaterCompat.java

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 {//w w w.  j a  v a2  s .c o  m
            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.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
        PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(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;
}

From source file:com.ridgelineapps.wallpaper.photosite.TumblrUtils.java

private void parseResponse(InputStream in, ResponseParser responseParser) throws IOException {
    final XmlPullParser parser = Xml.newPullParser();
    try {//from w w w .  j  a  va2  s.c om
        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 = parser.getName();
        //            if (RESPONSE_TAG_RSP.equals(name)) {
        //                final String value = parser.getAttributeValue(null, RESPONSE_ATTR_STAT);
        //                if (!RESPONSE_STATUS_OK.equals(value)) {
        //                    throw new IOException("Wrong status: " + value);
        //                }
        //            }

        responseParser.parseResponse(parser);

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

From source file:android.transitions.everywhere.Transition.java

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;/* ww  w.  j  a v a  2  s .c  o  m*/
            index--;
        } else {
            throw new InflateException("Unknown match type in matchOrder: '" + token + "'");
        }
        index++;
    }
    return matches;
}

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

/**
 * Setup ObjectAnimator's property or values from pathData.
 *
 * @param anim                The target Animator which will be updated.
 * @param arrayObjectAnimator TypedArray for the ObjectAnimator.
 * @param pixelSize           The relative pixel size, used to calculate the
 *//*from  www  . jav  a  2  s  . c o  m*/
private static void setupObjectAnimator(ValueAnimator anim, TypedArray arrayObjectAnimator, int valueType,
        float pixelSize, XmlPullParser parser) {
    ObjectAnimator oa = (ObjectAnimator) anim;
    String pathData = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "pathData",
            AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PATH_DATA);

    // Path can be involved in an ObjectAnimator in the following 3 ways:
    // 1) Path morphing: the property to be animated is pathData, and valueFrom and valueTo
    //    are both of pathType. valueType = pathType needs to be explicitly defined.
    // 2) A property in X or Y dimension can be animated along a path: the property needs to be
    //    defined in propertyXName or propertyYName attribute, the path will be defined in the
    //    pathData attribute. valueFrom and valueTo will not be necessary for this animation.
    // 3) PathInterpolator can also define a path (in pathData) for its interpolation curve.
    // Here we are dealing with case 2:
    if (pathData != null) {
        String propertyXName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyXName",
                AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_X_NAME);
        String propertyYName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyYName",
                AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_Y_NAME);

        if (valueType == VALUE_TYPE_PATH || valueType == VALUE_TYPE_UNDEFINED) {
            // When pathData is defined, we are in case #2 mentioned above. ValueType can only
            // be float type, or int type. Otherwise we fallback to default type.
            valueType = VALUE_TYPE_FLOAT;
        }
        if (propertyXName == null && propertyYName == null) {
            throw new InflateException(arrayObjectAnimator.getPositionDescription()
                    + " propertyXName or propertyYName is needed for PathData");
        } else {
            Path path = PathParser.createPathFromPathData(pathData);
            setupPathMotion(path, oa, 0.5f * pixelSize, propertyXName, propertyYName);
        }
    } else {
        String propertyName = TypedArrayUtils.getNamedString(arrayObjectAnimator, parser, "propertyName",
                AndroidResources.STYLEABLE_PROPERTY_ANIMATOR_PROPERTY_NAME);
        oa.setPropertyName(propertyName);
    }

    return;

}

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

/**
 * Parses a valid XML response from the specified input stream. This method
 * must invoke parse// w  ww .ja  va 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_REQUEST.equals(name)) {
                valid = isRequestValid(parser);
                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.ridgelineapps.wallpaper.photosite.FlickrUtils.java

/**
 * Parses a valid Flickr XML response from the specified input stream. When the Flickr
 * response contains the OK tag, the response is sent to the specified response parser.
 *
 * @param in The input stream containing the response sent by Flickr.
 * @param responseParser The parser to use when the response is valid.
 * //from ww w  .  ja va 2  s  .  c om
 * @throws IOException
 */
private void parseResponse(InputStream in, ResponseParser responseParser) 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 = parser.getName();
        if (RESPONSE_TAG_RSP.equals(name)) {
            final String value = parser.getAttributeValue(null, RESPONSE_ATTR_STAT);
            if (!RESPONSE_STATUS_OK.equals(value)) {
                throw new IOException("Wrong status: " + value);
            }
        }

        responseParser.parseResponse(parser);

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