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