Example usage for android.graphics.drawable VectorDrawable getPixelSize

List of usage examples for android.graphics.drawable VectorDrawable getPixelSize

Introduction

In this page you can find the example usage for android.graphics.drawable VectorDrawable getPixelSize.

Prototype

public float getPixelSize() 

Source Link

Document

The size of a pixel when scaled from the intrinsic dimension to the viewport dimension.

Usage

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;
                }/*  w  w  w .  j  ava  2s . com*/
                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.wnafee.vector.compat.AnimatedVectorDrawable.java

public void inflate(Context c, Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme)
        throws XmlPullParserException, IOException {

    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 = obtainAttributes(res, theme, attrs, R.styleable.AnimatedVectorDrawable);
                int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_android_drawable, 0);
                if (drawableRes != 0) {
                    VectorDrawable vectorDrawable = (VectorDrawable) VectorDrawable.create(res, drawableRes)
                            .mutate();/*  w  ww .  ja  v a  2 s  .  c o  m*/
                    vectorDrawable.setAllowCaching(false);
                    pathErrorScale = vectorDrawable.getPixelSize();
                    mAnimatedVectorState.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_android_name);

                int id = a.getResourceId(R.styleable.AnimatedVectorDrawableTarget_android_animation, 0);
                if (id != 0) {
                    //path animators require separate handling
                    Animator objectAnimator;
                    if (isPath(target)) {
                        objectAnimator = getPathAnimator(c, res, theme, id, pathErrorScale);
                    } else {
                        objectAnimator = AnimatorInflater.loadAnimator(c, id);
                    }
                    setupAnimatorsForTarget(target, objectAnimator);
                }
                a.recycle();
            }
        }

        eventType = parser.next();
    }
}

From source file:com.hippo.vector.AnimatedVectorDrawable.java

public void inflate(Context context, XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {
    final AnimatedVectorDrawableState state = mAnimatedVectorState;

    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 = context.obtainStyledAttributes(attrs, R.styleable.AnimatedVectorDrawable);
                int drawableRes = a.getResourceId(R.styleable.AnimatedVectorDrawable_drawable, 0);
                if (drawableRes != 0) {
                    VectorDrawable vectorDrawable = VectorDrawable.create(context, drawableRes);
                    if (vectorDrawable != null) {
                        vectorDrawable.setAllowCaching(false);
                        vectorDrawable.setCallback(mCallback);
                        pathErrorScale = vectorDrawable.getPixelSize();
                        if (state.mVectorDrawable != null) {
                            state.mVectorDrawable.setCallback(null);
                        }/*from   ww  w .  j a v a  2  s.  com*/
                        state.mVectorDrawable = vectorDrawable;
                    }
                }
                a.recycle();
            } else if (TARGET.equals(tagName)) {
                final TypedArray a = context.obtainStyledAttributes(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) {
                    state.addTargetAnimator(target,
                            AnimatorInflater.loadAnimator(context, animResId, pathErrorScale));
                }
                a.recycle();
            }
        }

        eventType = parser.next();
    }
}