summaryrefslogtreecommitdiffstats
path: root/core/java/android/animation
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2015-04-23 01:13:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-23 01:13:39 +0000
commit7b380329ece8ce0bc93f6b16459dd4a8e594e0e6 (patch)
tree73b253b6fab76dc85d7659e7cff9111bdd53af69 /core/java/android/animation
parent82e92a9e7bd7f9f0d1d7f2e9edf52db49fbdf1d6 (diff)
parenta01fbf35de21cd595d4cda2e83b67c1238e12550 (diff)
downloadframeworks_base-7b380329ece8ce0bc93f6b16459dd4a8e594e0e6.zip
frameworks_base-7b380329ece8ce0bc93f6b16459dd4a8e594e0e6.tar.gz
frameworks_base-7b380329ece8ce0bc93f6b16459dd4a8e594e0e6.tar.bz2
Merge "Infer value type for keyframes when it is undefined"
Diffstat (limited to 'core/java/android/animation')
-rw-r--r--core/java/android/animation/AnimatorInflater.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java
index 224e8e9..e47d017 100644
--- a/core/java/android/animation/AnimatorInflater.java
+++ b/core/java/android/animation/AnimatorInflater.java
@@ -790,6 +790,31 @@ public class AnimatorInflater {
return valuesArray;
}
+ // When no value type is provided in keyframe, we need to infer the type from the value. i.e.
+ // if value is defined in the style of a color value, then the color type is returned.
+ // Otherwise, default float type is returned.
+ private static int inferValueTypeOfKeyframe(Resources res, Theme theme, AttributeSet attrs) {
+ int valueType;
+ TypedArray a;
+ if (theme != null) {
+ a = theme.obtainStyledAttributes(attrs, R.styleable.Keyframe, 0, 0);
+ } else {
+ a = res.obtainAttributes(attrs, R.styleable.Keyframe);
+ }
+
+ TypedValue keyframeValue = a.peekValue(R.styleable.Keyframe_value);
+ boolean hasValue = (keyframeValue != null);
+ // When no value type is provided, check whether it's a color type first.
+ // If not, fall back to default value type (i.e. float type).
+ if (hasValue && isColorType(keyframeValue.type)) {
+ valueType = VALUE_TYPE_COLOR;
+ } else {
+ valueType = VALUE_TYPE_FLOAT;
+ }
+ a.recycle();
+ return valueType;
+ }
+
private static void dumpKeyframes(Object[] keyframes, String header) {
if (keyframes == null || keyframes.length == 0) {
return;
@@ -817,6 +842,9 @@ public class AnimatorInflater {
type != XmlPullParser.END_DOCUMENT) {
String name = parser.getName();
if (name.equals("keyframe")) {
+ if (valueType == VALUE_TYPE_UNDEFINED) {
+ valueType = inferValueTypeOfKeyframe(res, theme, Xml.asAttributeSet(parser));
+ }
Keyframe keyframe = loadKeyframe(res, theme, Xml.asAttributeSet(parser), valueType);
if (keyframe != null) {
if (keyframes == null) {