Search in sources :

Example 56 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class Typeface method init.

/*
     * (non-Javadoc)
     *
     * This should only be called once, from the static class initializer block.
     */
private static void init() {
    // Load font config and initialize Minikin state
    File systemFontConfigLocation = getSystemFontConfigLocation();
    File configFilename = new File(systemFontConfigLocation, FONTS_CONFIG);
    try {
        FileInputStream fontsIn = new FileInputStream(configFilename);
        FontListParser.Config fontConfig = FontListParser.parse(fontsIn);
        Map<String, ByteBuffer> bufferForPath = new HashMap<String, ByteBuffer>();
        List<FontFamily> familyList = new ArrayList<FontFamily>();
        // this is an enhancement from pre-Minikin behavior.
        for (int i = 0; i < fontConfig.families.size(); i++) {
            FontListParser.Family f = fontConfig.families.get(i);
            if (i == 0 || f.name == null) {
                familyList.add(makeFamilyFromParsed(f, bufferForPath));
            }
        }
        sFallbackFonts = familyList.toArray(new FontFamily[familyList.size()]);
        setDefault(Typeface.createFromFamilies(sFallbackFonts));
        Map<String, Typeface> systemFonts = new HashMap<String, Typeface>();
        for (int i = 0; i < fontConfig.families.size(); i++) {
            Typeface typeface;
            FontListParser.Family f = fontConfig.families.get(i);
            if (f.name != null) {
                if (i == 0) {
                    // The first entry is the default typeface; no sense in
                    // duplicating the corresponding FontFamily.
                    typeface = sDefaultTypeface;
                } else {
                    FontFamily fontFamily = makeFamilyFromParsed(f, bufferForPath);
                    FontFamily[] families = { fontFamily };
                    typeface = Typeface.createFromFamiliesWithDefault(families);
                }
                systemFonts.put(f.name, typeface);
            }
        }
        for (FontListParser.Alias alias : fontConfig.aliases) {
            Typeface base = systemFonts.get(alias.toName);
            Typeface newFace = base;
            int weight = alias.weight;
            if (weight != 400) {
                newFace = new Typeface(nativeCreateWeightAlias(base.native_instance, weight));
            }
            systemFonts.put(alias.name, newFace);
        }
        sSystemFontMap = systemFonts;
    } catch (RuntimeException e) {
        Log.w(TAG, "Didn't create default family (most likely, non-Minikin build)", e);
    // TODO: normal in non-Minikin case, remove or make error when Minikin-only
    } catch (FileNotFoundException e) {
        Log.e(TAG, "Error opening " + configFilename, e);
    } catch (IOException e) {
        Log.e(TAG, "Error reading " + configFilename, e);
    } catch (XmlPullParserException e) {
        Log.e(TAG, "XML parse exception for " + configFilename, e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File)

Example 57 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class AnimatedStateListDrawable method parseTransition.

private int parseTransition(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
    // This allows state list drawable item elements to be themed at
    // inflation time but does NOT make them work for Zygote preload.
    final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.AnimatedStateListDrawableTransition);
    final int fromId = a.getResourceId(R.styleable.AnimatedStateListDrawableTransition_fromId, 0);
    final int toId = a.getResourceId(R.styleable.AnimatedStateListDrawableTransition_toId, 0);
    final boolean reversible = a.getBoolean(R.styleable.AnimatedStateListDrawableTransition_reversible, false);
    Drawable dr = a.getDrawable(R.styleable.AnimatedStateListDrawableTransition_drawable);
    a.recycle();
    // attributes and extracting states.
    if (dr == null) {
        int type;
        while ((type = parser.next()) == XmlPullParser.TEXT) {
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException(parser.getPositionDescription() + ": <transition> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
    }
    return mState.addTransition(fromId, toId, dr, reversible);
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 58 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class AnimatedStateListDrawable method parseItem.

private int parseItem(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
    // This allows state list drawable item elements to be themed at
    // inflation time but does NOT make them work for Zygote preload.
    final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.AnimatedStateListDrawableItem);
    final int keyframeId = a.getResourceId(R.styleable.AnimatedStateListDrawableItem_id, 0);
    Drawable dr = a.getDrawable(R.styleable.AnimatedStateListDrawableItem_drawable);
    a.recycle();
    final int[] states = extractStateSet(attrs);
    // attributes and extracting states.
    if (dr == null) {
        int type;
        while ((type = parser.next()) == XmlPullParser.TEXT) {
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
    }
    return mState.addStateSet(states, dr, keyframeId);
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 59 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class BitmapDrawable method applyTheme.

@Override
public void applyTheme(Theme t) {
    super.applyTheme(t);
    final BitmapState state = mBitmapState;
    if (state == null) {
        return;
    }
    if (state.mThemeAttrs != null) {
        final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.BitmapDrawable);
        try {
            updateStateFromTypedArray(a);
        } catch (XmlPullParserException e) {
            rethrowAsRuntimeException(e);
        } finally {
            a.recycle();
        }
    }
    // Apply theme to contained color state list.
    if (state.mTint != null && state.mTint.canApplyTheme()) {
        state.mTint = state.mTint.obtainForTheme(t);
    }
    // Update local properties.
    updateLocalState(t.getResources());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 60 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException in project platform_frameworks_base by android.

the class UsageStatsXml method read.

static void read(InputStream in, IntervalStats statsOut) throws IOException {
    XmlPullParser parser = Xml.newPullParser();
    try {
        parser.setInput(in, "utf-8");
        XmlUtils.beginDocument(parser, USAGESTATS_TAG);
        String versionStr = parser.getAttributeValue(null, VERSION_ATTR);
        try {
            switch(Integer.parseInt(versionStr)) {
                case 1:
                    UsageStatsXmlV1.read(parser, statsOut);
                    break;
                default:
                    Slog.e(TAG, "Unrecognized version " + versionStr);
                    throw new IOException("Unrecognized version " + versionStr);
            }
        } catch (NumberFormatException e) {
            Slog.e(TAG, "Bad version");
            throw new IOException(e);
        }
    } catch (XmlPullParserException e) {
        Slog.e(TAG, "Failed to parse Xml", e);
        throw new IOException(e);
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1071 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)440 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)186 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)99 PackageManager (android.content.pm.PackageManager)62 HashMap (java.util.HashMap)58 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)57 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)54 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43