Example usage for android.content.res Resources obtainAttributes

List of usage examples for android.content.res Resources obtainAttributes

Introduction

In this page you can find the example usage for android.content.res Resources obtainAttributes.

Prototype

public TypedArray obtainAttributes(AttributeSet set, @StyleableRes int[] attrs) 

Source Link

Document

Retrieve a set of basic attribute values from an AttributeSet, not performing styling of them using a theme and/or style resources.

Usage

From source file:android.support.v7.content.res.AppCompatColorStateListInflater.java

private static TypedArray obtainAttributes(Resources res, Resources.Theme theme, AttributeSet set,
        int[] attrs) {
    return theme == null ? res.obtainAttributes(set, attrs) : theme.obtainStyledAttributes(set, attrs, 0, 0);
}

From source file:android.support.graphics.drawable.VectorDrawableCommon.java

/**
 * Obtains styled attributes from the theme, if available, or unstyled
 * resources if the theme is null./* w ww.  j  a  v  a2s  .com*/
 */
static TypedArray obtainAttributes(Resources res, Resources.Theme theme, AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}

From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java

/**
 * Obtains styled attributes from the theme, if available, or unstyled
 * resources if the theme is null.//from  w  ww.  j a  v  a 2s .co m
 */
static TypedArray obtainAttributes(Resources res, Theme theme, AttributeSet set, int[] attrs) {
    if (theme == null) {
        return res.obtainAttributes(set, attrs);
    }
    return theme.obtainStyledAttributes(set, attrs, 0, 0);
}

From source file:android.support.wear.widget.CircularProgressLayout.java

public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mProgressDrawable = new CircularProgressDrawable(context);
    mProgressDrawable.setProgressRotation(DEFAULT_ROTATION);
    mProgressDrawable.setStrokeCap(Paint.Cap.BUTT);
    setBackground(mProgressDrawable);//from   www.  j  a v  a  2s . c  om

    // If a child view is added, make it center aligned so it fits in the progress drawable.
    setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
        @Override
        public void onChildViewAdded(View parent, View child) {
            // Ensure that child view is aligned in center
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            params.gravity = Gravity.CENTER;
            child.setLayoutParams(params);
        }

        @Override
        public void onChildViewRemoved(View parent, View child) {

        }
    });

    mController = new CircularProgressLayoutController(this);

    Resources r = context.getResources();
    TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout);

    if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE
            || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) {
        int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors,
                R.array.circular_progress_layout_color_scheme_colors);
        setColorSchemeColors(getColorListFromResources(r, arrayResId));
    } else {
        setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK));
    }

    setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth,
            r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width)));

    setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor,
            ContextCompat.getColor(context, R.color.circular_progress_layout_background_color)));

    setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false));

    a.recycle();
}

From source file:com.hippo.vectorold.drawable.AnimatedVectorDrawable.java

public void inflate(Context context, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    Resources res = context.getResources();
    int eventType = parser.getEventType();
    float pathErrorScale = 1;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            final String tagName = parser.getName();
            if (ANIMATED_VECTOR.equals(tagName)) {
                final TypedArray a = res.obtainAttributes(attrs, R.styleable.AnimatedVectorDrawable);
                int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0);
                if (drawableRes != 0) {
                    VectorDrawable vectorDrawable = (VectorDrawable) res.getDrawable(drawableRes).mutate();
                    vectorDrawable.setAllowCaching(false);
                    pathErrorScale = vectorDrawable.getPixelSize();
                    mAnimatedVectorState.mVectorDrawable = vectorDrawable;
                }//from w w w.j av  a  2s  . co m
                a.recycle();
            } else if (TARGET.equals(tagName)) {
                final TypedArray a = res.obtainAttributes(attrs, R.styleable.AnimatedVectorDrawableTarget);
                final String target = a.getString(R.styleable.AnimatedVectorDrawableTarget_name);

                int id = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_animation, 0);
                if (id != 0) {
                    Animator objectAnimator = AnimatorInflater.loadAnimator(context, id, pathErrorScale);
                    setupAnimatorsForTarget(target, objectAnimator);
                }
                a.recycle();
            }
        }

        eventType = parser.next();
    }
}

From source file:com.hippo.vectorold.drawable.VectorDrawable.java

@Override
public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = new VPathRenderer();
    state.mVPathRenderer = pathRenderer;

    final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawable);
    updateStateFromTypedArray(a);/*from   w  w  w  .j a va  2s  .c o  m*/
    a.recycle();

    state.mCacheDirty = true;
    inflateInternal(res, parser, attrs);

    mTintFilter = DrawableUtils.updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode);
}

From source file:net.zhuoweizhang.vectordrawable.VectorDrawable.java

@Override
public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    Theme theme = null;/* www .  jav a2  s. c o m*/
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = new VPathRenderer();
    state.mVPathRenderer = pathRenderer;

    final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawable);
    updateStateFromTypedArray(a);
    a.recycle();

    state.mCacheDirty = true;
    inflateInternal(res, parser, attrs, theme);

    mTintFilter = null; //updateTintFilter(mTintFilter, state.mTint, state.mTintMode);
}

From source file:com.grottworkshop.gwsvectorsandboxlib.VectorDrawable.java

@Override
public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    // TODO THEME Not supported yet
    Theme theme = null;//from w ww .j av  a 2s .  c om
    final VectorDrawableState state = mVectorState;
    final VPathRenderer pathRenderer = new VPathRenderer();
    state.mVPathRenderer = pathRenderer;

    final TypedArray a = res.obtainAttributes(attrs, R.styleable.VectorDrawable);
    updateStateFromTypedArray(a);
    a.recycle();

    state.mCacheDirty = true;
    inflateInternal(res, parser, attrs, theme);

    mTintFilter = updateTintFilter(this, mTintFilter, state.mTint, state.mTintMode);
}

From source file:com.androzic.Preferences.java

/**
 * Parse the given XML file as a header description, adding each
 * parsed Header into the target list.//w ww.  j av  a 2 s  . c  om
 *
 * @param resid
 *            The XML resource to load and parse.
 * @param target
 *            The list in which the parsed headers should be placed.
 */
public void loadHeadersFromResource(int resid, List<Header> target) {
    Androzic application = Androzic.getApplication();
    XmlResourceParser parser = null;
    try {
        Resources resources = getResources();
        parser = resources.getXml(resid);
        AttributeSet attrs = Xml.asAttributeSet(parser);

        int type;
        //noinspection StatementWithEmptyBody
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
            // Parse next until start tag is found
        }

        String nodeName = parser.getName();
        if (!"preference-headers".equals(nodeName)) {
            throw new RuntimeException("XML document must start with <preference-headers> tag; found" + nodeName
                    + " at " + parser.getPositionDescription());
        }

        Bundle curBundle = null;

        final int outerDepth = parser.getDepth();
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                continue;
            }

            nodeName = parser.getName();
            if ("header".equals(nodeName)) {
                Header header = new Header();

                TypedArray sa = resources.obtainAttributes(attrs, R.styleable.PreferenceHeader);
                header.id = sa.getResourceId(R.styleable.PreferenceHeader_id, (int) HEADER_ID_UNDEFINED);
                TypedValue tv = sa.peekValue(R.styleable.PreferenceHeader_title);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.titleRes = tv.resourceId;
                    } else {
                        header.title = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_summary);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.summaryRes = tv.resourceId;
                    } else {
                        header.summary = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbTitle);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.breadCrumbTitleRes = tv.resourceId;
                    } else {
                        header.breadCrumbTitle = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbShortTitle);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.breadCrumbShortTitleRes = tv.resourceId;
                    } else {
                        header.breadCrumbShortTitle = tv.string;
                    }
                }
                header.iconRes = sa.getResourceId(R.styleable.PreferenceHeader_icon, 0);
                header.fragment = sa.getString(R.styleable.PreferenceHeader_fragment);
                header.help = sa.getResourceId(R.styleable.PreferenceHeader_help, 0);
                sa.recycle();

                if (curBundle == null) {
                    curBundle = new Bundle();
                }

                final int innerDepth = parser.getDepth();
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                        && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                    if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                        continue;
                    }

                    String innerNodeName = parser.getName();
                    if (innerNodeName.equals("extra")) {
                        resources.parseBundleExtra(innerNodeName, attrs, curBundle);
                        XmlUtils.skipCurrentTag(parser);

                    } else if (innerNodeName.equals("intent")) {
                        header.intent = Intent.parseIntent(resources, parser, attrs);

                    } else {
                        XmlUtils.skipCurrentTag(parser);
                    }
                }

                if (curBundle.size() > 0) {
                    header.fragmentArguments = curBundle;
                    curBundle = null;
                }

                if (header.id == R.id.pref_plugins && application.getPluginsPreferences().size() == 0)
                    continue;

                target.add(header);
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
        }

    } catch (XmlPullParserException | IOException e) {
        throw new RuntimeException("Error parsing headers", e);
    } finally {
        if (parser != null)
            parser.close();
    }

}

From source file:android.support.graphics.drawable.AnimatedVectorDrawableCompat.java

@Override
public void inflate(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme)
        throws XmlPullParserException, IOException {
    if (mDelegateDrawable != null) {
        DrawableCompat.inflate(mDelegateDrawable, res, parser, attrs, theme);
        return;//from   w w w  .  ja  v a2  s .  c  om
    }
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            final String tagName = parser.getName();
            if (DBG_ANIMATION_VECTOR_DRAWABLE) {
                Log.v(LOGTAG, "tagName is " + tagName);
            }
            if (ANIMATED_VECTOR.equals(tagName)) {
                final TypedArray a = obtainAttributes(res, theme, attrs,
                        AndroidResources.styleable_AnimatedVectorDrawable);

                int drawableRes = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawable_drawable,
                        0);
                if (DBG_ANIMATION_VECTOR_DRAWABLE) {
                    Log.v(LOGTAG, "drawableRes is " + drawableRes);
                }
                if (drawableRes != 0) {
                    VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(res, drawableRes, theme);
                    vectorDrawable.setAllowCaching(false);
                    vectorDrawable.setCallback(mCallback);
                    if (mAnimatedVectorState.mVectorDrawable != null) {
                        mAnimatedVectorState.mVectorDrawable.setCallback(null);
                    }
                    mAnimatedVectorState.mVectorDrawable = vectorDrawable;
                }
                a.recycle();
            } else if (TARGET.equals(tagName)) {
                final TypedArray a = res.obtainAttributes(attrs,
                        AndroidResources.styleable_AnimatedVectorDrawableTarget);
                final String target = a.getString(AndroidResources.styleable_AnimatedVectorDrawableTarget_name);

                int id = a.getResourceId(AndroidResources.styleable_AnimatedVectorDrawableTarget_animation, 0);
                if (id != 0) {
                    if (mContext != null) {
                        Animator objectAnimator = AnimatorInflater.loadAnimator(mContext, id);
                        setupAnimatorsForTarget(target, objectAnimator);
                    } else {
                        throw new IllegalStateException("Context can't be null when inflating" + " animators");
                    }
                }
                a.recycle();
            }
        }

        eventType = parser.next();
    }
}