Search in sources :

Example 86 with TypedArray

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);
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 87 with TypedArray

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;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) TypedArray(android.content.res.TypedArray)

Example 88 with TypedArray

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());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 89 with TypedArray

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);
}
Also used : TypedArray(android.content.res.TypedArray)

Example 90 with TypedArray

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();
}
Also used : TypedArray(android.content.res.TypedArray)

Aggregations

TypedArray (android.content.res.TypedArray)2031 Paint (android.graphics.Paint)193 TypedValue (android.util.TypedValue)190 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)162 Drawable (android.graphics.drawable.Drawable)119 Resources (android.content.res.Resources)118 View (android.view.View)117 Context (android.content.Context)80 XmlResourceParser (android.content.res.XmlResourceParser)80 ColorStateList (android.content.res.ColorStateList)78 AttributeSet (android.util.AttributeSet)78 IOException (java.io.IOException)77 SuppressLint (android.annotation.SuppressLint)66 TextPaint (android.text.TextPaint)63 TextView (android.widget.TextView)63 ViewGroup (android.view.ViewGroup)59 Bundle (android.os.Bundle)48 Point (android.graphics.Point)43 LayoutInflater (android.view.LayoutInflater)42 ImageView (android.widget.ImageView)40