public AnimatedVectorDrawableState(AnimatedVectorDrawableState copy) { if (copy != null) { mChangingConfigurations = copy.mChangingConfigurations; if (copy.mVectorDrawable != null) { mVectorDrawable = (VectorDrawable) copy.mVectorDrawable.getConstantState().newDrawable(); mVectorDrawable.mutate(); mVectorDrawable.setAllowCaching(false); mVectorDrawable.setBounds(copy.mVectorDrawable.getBounds()); } if (copy.mAnimators != null) { final int numAnimators = copy.mAnimators.size(); mAnimators = new ArrayList<Animator>(numAnimators); mTargetNameMap = new ArrayMap<Animator, String>(numAnimators); for (int i = 0; i < numAnimators; ++i) { Animator anim = copy.mAnimators.get(i); Animator animClone = anim.clone(); String targetName = copy.mTargetNameMap.get(anim); Object targetObject = mVectorDrawable.getTargetByName(targetName); animClone.setTarget(targetObject); mAnimators.add(animClone); mTargetNameMap.put(animClone, targetName); } } } else { mVectorDrawable = new VectorDrawable(); } }
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(); 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(); } }