use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class StateListDrawable method inflateChildElements.
/**
* Inflates child elements from XML.
*/
private void inflateChildElements(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
final StateListState state = mStateListState;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
// 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.StateListDrawableItem);
Drawable dr = a.getDrawable(R.styleable.StateListDrawableItem_drawable);
a.recycle();
final int[] states = extractStateSet(attrs);
// attributes and extracting states.
if (dr == null) {
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);
}
state.addStateSet(states, dr);
}
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class VectorDrawable method inflate.
@Override
public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
if (mVectorState.mRootGroup != null || mVectorState.mNativeTree != null) {
// This VD has been used to display other VD resource content, clean up.
if (mVectorState.mRootGroup != null) {
// Subtract the native allocation for all the nodes.
VMRuntime.getRuntime().registerNativeFree(mVectorState.mRootGroup.getNativeSize());
// Remove child nodes' reference to tree
mVectorState.mRootGroup.setTree(null);
}
mVectorState.mRootGroup = new VGroup();
if (mVectorState.mNativeTree != null) {
// Subtract the native allocation for the tree wrapper, which contains root node
// as well as rendering related data.
VMRuntime.getRuntime().registerNativeFree(mVectorState.NATIVE_ALLOCATION_SIZE);
mVectorState.mNativeTree.release();
}
mVectorState.createNativeTree(mVectorState.mRootGroup);
}
final VectorDrawableState state = mVectorState;
state.setDensity(Drawable.resolveDensity(r, 0));
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.VectorDrawable);
updateStateFromTypedArray(a);
a.recycle();
mDpiScaledDirty = true;
state.mCacheDirty = true;
inflateChildElements(r, parser, attrs, theme);
state.onTreeConstructionFinished();
// Update local properties.
updateLocalState(r);
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class DrawableWrapper method inflate.
@Override
public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs, theme);
final DrawableWrapperState state = mState;
if (state == null) {
return;
}
// The density may have changed since the last update. This will
// apply scaling to any existing constant state properties.
final int densityDpi = r.getDisplayMetrics().densityDpi;
final int targetDensity = densityDpi == 0 ? DisplayMetrics.DENSITY_DEFAULT : densityDpi;
state.setDensity(targetDensity);
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.DrawableWrapper);
updateStateFromTypedArray(a);
a.recycle();
inflateChildDrawable(r, parser, attrs, theme);
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class GradientDrawable method applyTheme.
@Override
public void applyTheme(@NonNull Theme t) {
super.applyTheme(t);
final GradientState state = mGradientState;
if (state == null) {
return;
}
state.setDensity(Drawable.resolveDensity(t.getResources(), 0));
if (state.mThemeAttrs != null) {
final TypedArray a = t.resolveAttributes(state.mThemeAttrs, R.styleable.GradientDrawable);
updateStateFromTypedArray(a);
a.recycle();
}
if (state.mTint != null && state.mTint.canApplyTheme()) {
state.mTint = state.mTint.obtainForTheme(t);
}
if (state.mSolidColors != null && state.mSolidColors.canApplyTheme()) {
state.mSolidColors = state.mSolidColors.obtainForTheme(t);
}
if (state.mStrokeColors != null && state.mStrokeColors.canApplyTheme()) {
state.mStrokeColors = state.mStrokeColors.obtainForTheme(t);
}
applyThemeChildElements(t);
updateLocalState(t.getResources());
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class GradientDrawable method inflate.
@Override
public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs, theme);
mGradientState.setDensity(Drawable.resolveDensity(r, 0));
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.GradientDrawable);
updateStateFromTypedArray(a);
a.recycle();
inflateChildElements(r, parser, attrs, theme);
updateLocalState(r);
}
Aggregations