Search in sources :

Example 56 with TypedArray

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

Example 57 with TypedArray

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

Example 58 with TypedArray

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

Example 59 with TypedArray

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

Example 60 with TypedArray

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