use of android.content.res.TypedArray 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 android.content.res.TypedArray in project platform_frameworks_base by android.
the class AnimatedVectorDrawable method inflate.
@Override
public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
final AnimatedVectorDrawableState state = mAnimatedVectorState;
int eventType = parser.getEventType();
float pathErrorScale = 1;
final int innerDepth = parser.getDepth() + 1;
// Parse everything until the end of the animated-vector element.
while (eventType != XmlPullParser.END_DOCUMENT && (parser.getDepth() >= innerDepth || eventType != XmlPullParser.END_TAG)) {
if (eventType == XmlPullParser.START_TAG) {
final String tagName = parser.getName();
if (ANIMATED_VECTOR.equals(tagName)) {
final TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.AnimatedVectorDrawable);
int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0);
if (drawableRes != 0) {
VectorDrawable vectorDrawable = (VectorDrawable) res.getDrawable(drawableRes, theme).mutate();
vectorDrawable.setAllowCaching(false);
vectorDrawable.setCallback(mCallback);
pathErrorScale = vectorDrawable.getPixelSize();
if (state.mVectorDrawable != null) {
state.mVectorDrawable.setCallback(null);
}
state.mVectorDrawable = vectorDrawable;
}
a.recycle();
} else if (TARGET.equals(tagName)) {
final TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.AnimatedVectorDrawableTarget);
final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_name);
final int animResId = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_animation, 0);
if (animResId != 0) {
if (theme != null) {
// The animator here could be ObjectAnimator or AnimatorSet.
final Animator animator = AnimatorInflater.loadAnimator(res, theme, animResId, pathErrorScale);
updateAnimatorProperty(animator, target, state.mVectorDrawable, state.mShouldIgnoreInvalidAnim);
state.addTargetAnimator(target, animator);
} else {
// The animation may be theme-dependent. As a
// workaround until Animator has full support for
// applyTheme(), postpone loading the animator
// until we have a theme in applyTheme().
state.addPendingAnimator(animResId, pathErrorScale, target);
}
}
a.recycle();
}
}
eventType = parser.next();
}
// If we don't have any pending animations, we don't need to hold a
// reference to the resources.
mRes = state.mPendingAnims == null ? null : res;
}
use of android.content.res.TypedArray 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 android.content.res.TypedArray in project platform_frameworks_base by android.
the class BitmapDrawable method inflate.
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs, theme);
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.BitmapDrawable);
updateStateFromTypedArray(a);
verifyRequiredAttributes(a);
a.recycle();
// Update local properties.
updateLocalState(r);
}
use of android.content.res.TypedArray in project platform_frameworks_base by android.
the class ClipDrawable method inflate.
@Override
public void inflate(@NonNull Resources r, @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme) throws XmlPullParserException, IOException {
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.ClipDrawable);
// Inflation will advance the XmlPullParser and AttributeSet.
super.inflate(r, parser, attrs, theme);
updateStateFromTypedArray(a);
verifyRequiredAttributes(a);
a.recycle();
}
Aggregations