From 03f2fcbd88478636acc9d67b9698b50e5b3eae25 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Thu, 1 Jun 2017 17:34:13 -0700 Subject: [PATCH] Better error message for AVD Moved the error checking to an earlier stage of the AVD, so that the error message can contain more information. BUG: 36571432 Test: Follow the repro step in b/36244835, the error message is much clear now. Change-Id: Ibc6a0e666cc4c23c3dfa589755a77a015da2db1c --- .../drawable/AnimatedVectorDrawable.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index 00b5eda6d7fff..90d6ab867fe15 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -834,6 +834,16 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { final Animator localAnimator = animator.clone(); final String targetName = mTargetNameMap.get(animator); final Object target = mVectorDrawable.getTargetByName(targetName); + if (!mShouldIgnoreInvalidAnim) { + if (target == null) { + throw new IllegalStateException("Target with the name \"" + targetName + + "\" cannot be found in the VectorDrawable to be animated."); + } else if (!(target instanceof VectorDrawable.VectorDrawableState) + && !(target instanceof VectorDrawable.VObject)) { + throw new UnsupportedOperationException("Target should be either VGroup, VPath," + + " or ConstantState, " + target.getClass() + " is not supported"); + } + } localAnimator.setTarget(target); return localAnimator; } @@ -1321,16 +1331,10 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { throw new IllegalArgumentException("ClipPath only supports PathData " + "property"); } - } } else if (target instanceof VectorDrawable.VectorDrawableState) { createRTAnimatorForRootGroup(values, animator, (VectorDrawable.VectorDrawableState) target, startTime); - } else if (!mDrawable.mAnimatedVectorState.mShouldIgnoreInvalidAnim) { - // Should never get here - throw new UnsupportedOperationException("Target should be either VGroup, VPath, " + - "or ConstantState, " + target == null ? "Null target" : target.getClass() + - " is not supported"); } }