Allow DiP values in the translate XML animation (1/2)

Bug: 215679624
Bug: 217356408
Test: atest TranslateAnimationTest
Change-Id: Icbd6d9832a68f0327bdcd4735f2f597f927caaeb
This commit is contained in:
Jordan Demeulenaere
2022-02-01 13:46:29 +01:00
parent aa45a654ab
commit fad1a8814f
9 changed files with 42 additions and 35 deletions

View File

@@ -1251,18 +1251,19 @@ public abstract class Animation implements Cloneable {
public float value;
/**
* Size descriptions can appear inthree forms:
* Size descriptions can appear in four forms:
* <ol>
* <li>An absolute size. This is represented by a number.</li>
* <li>A size relative to the size of the object being animated. This
* is represented by a number followed by "%".</li> *
* is represented by a number followed by "%".</li>
* <li>A size relative to the size of the parent of object being
* animated. This is represented by a number followed by "%p".</li>
* <li>(Starting from API 32) A complex number.</li>
* </ol>
* @param value The typed value to parse
* @return The parsed version of the description
*/
static Description parseValue(TypedValue value) {
static Description parseValue(TypedValue value, Context context) {
Description d = new Description();
if (value == null) {
d.type = ABSOLUTE;
@@ -1283,6 +1284,11 @@ public abstract class Animation implements Cloneable {
d.type = ABSOLUTE;
d.value = value.data;
return d;
} else if (value.type == TypedValue.TYPE_DIMENSION) {
d.type = ABSOLUTE;
d.value = TypedValue.complexToDimension(value.data,
context.getResources().getDisplayMetrics());
return d;
}
}

View File

@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
/**
* An animation that controls the clip of an object. See the
@@ -66,43 +65,43 @@ public class ClipRectAnimation extends Animation {
com.android.internal.R.styleable.ClipRectAnimation);
Description d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_fromLeft));
com.android.internal.R.styleable.ClipRectAnimation_fromLeft), context);
mFromLeftType = d.type;
mFromLeftValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_fromTop));
com.android.internal.R.styleable.ClipRectAnimation_fromTop), context);
mFromTopType = d.type;
mFromTopValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_fromRight));
com.android.internal.R.styleable.ClipRectAnimation_fromRight), context);
mFromRightType = d.type;
mFromRightValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_fromBottom));
com.android.internal.R.styleable.ClipRectAnimation_fromBottom), context);
mFromBottomType = d.type;
mFromBottomValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_toLeft));
com.android.internal.R.styleable.ClipRectAnimation_toLeft), context);
mToLeftType = d.type;
mToLeftValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_toTop));
com.android.internal.R.styleable.ClipRectAnimation_toTop), context);
mToTopType = d.type;
mToTopValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_toRight));
com.android.internal.R.styleable.ClipRectAnimation_toRight), context);
mToRightType = d.type;
mToRightValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ClipRectAnimation_toBottom));
com.android.internal.R.styleable.ClipRectAnimation_toBottom), context);
mToBottomType = d.type;
mToBottomValue = d.value;

View File

@@ -63,43 +63,43 @@ public class ExtendAnimation extends Animation {
com.android.internal.R.styleable.ExtendAnimation);
Description d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_fromExtendLeft));
com.android.internal.R.styleable.ExtendAnimation_fromExtendLeft), context);
mFromLeftType = d.type;
mFromLeftValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_fromExtendTop));
com.android.internal.R.styleable.ExtendAnimation_fromExtendTop), context);
mFromTopType = d.type;
mFromTopValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_fromExtendRight));
com.android.internal.R.styleable.ExtendAnimation_fromExtendRight), context);
mFromRightType = d.type;
mFromRightValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_fromExtendBottom));
com.android.internal.R.styleable.ExtendAnimation_fromExtendBottom), context);
mFromBottomType = d.type;
mFromBottomValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_toExtendLeft));
com.android.internal.R.styleable.ExtendAnimation_toExtendLeft), context);
mToLeftType = d.type;
mToLeftValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_toExtendTop));
com.android.internal.R.styleable.ExtendAnimation_toExtendTop), context);
mToTopType = d.type;
mToTopValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_toExtendRight));
com.android.internal.R.styleable.ExtendAnimation_toExtendRight), context);
mToRightType = d.type;
mToRightValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ExtendAnimation_toExtendBottom));
com.android.internal.R.styleable.ExtendAnimation_toExtendBottom), context);
mToBottomType = d.type;
mToBottomValue = d.value;

View File

@@ -116,10 +116,12 @@ public class GridLayoutAnimationController extends LayoutAnimationController {
com.android.internal.R.styleable.GridLayoutAnimation);
Animation.Description d = Animation.Description.parseValue(
a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_columnDelay));
a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_columnDelay),
context);
mColumnDelay = d.value;
d = Animation.Description.parseValue(
a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_rowDelay));
a.peekValue(com.android.internal.R.styleable.GridLayoutAnimation_rowDelay),
context);
mRowDelay = d.value;
//noinspection PointlessBitwiseExpression
mDirection = a.getInt(com.android.internal.R.styleable.GridLayoutAnimation_direction,

View File

@@ -106,7 +106,7 @@ public class LayoutAnimationController {
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.LayoutAnimation);
Animation.Description d = Animation.Description.parseValue(
a.peekValue(com.android.internal.R.styleable.LayoutAnimation_delay));
a.peekValue(com.android.internal.R.styleable.LayoutAnimation_delay), context);
mDelay = d.value;
mOrder = a.getInt(com.android.internal.R.styleable.LayoutAnimation_animationOrder, ORDER_NORMAL);

View File

@@ -56,12 +56,12 @@ public class RotateAnimation extends Animation {
mToDegrees = a.getFloat(com.android.internal.R.styleable.RotateAnimation_toDegrees, 0.0f);
Description d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.RotateAnimation_pivotX));
com.android.internal.R.styleable.RotateAnimation_pivotX), context);
mPivotXType = d.type;
mPivotXValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.RotateAnimation_pivotY));
com.android.internal.R.styleable.RotateAnimation_pivotY), context);
mPivotYType = d.type;
mPivotYValue = d.value;

View File

@@ -118,12 +118,12 @@ public class ScaleAnimation extends Animation {
}
Description d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ScaleAnimation_pivotX));
com.android.internal.R.styleable.ScaleAnimation_pivotX), context);
mPivotXType = d.type;
mPivotXValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.ScaleAnimation_pivotY));
com.android.internal.R.styleable.ScaleAnimation_pivotY), context);
mPivotYType = d.type;
mPivotYValue = d.value;

View File

@@ -73,22 +73,22 @@ public class TranslateAnimation extends Animation {
com.android.internal.R.styleable.TranslateAnimation);
Description d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.TranslateAnimation_fromXDelta));
com.android.internal.R.styleable.TranslateAnimation_fromXDelta), context);
mFromXType = d.type;
mFromXValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.TranslateAnimation_toXDelta));
com.android.internal.R.styleable.TranslateAnimation_toXDelta), context);
mToXType = d.type;
mToXValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.TranslateAnimation_fromYDelta));
com.android.internal.R.styleable.TranslateAnimation_fromYDelta), context);
mFromYType = d.type;
mFromYValue = d.value;
d = Description.parseValue(a.peekValue(
com.android.internal.R.styleable.TranslateAnimation_toYDelta));
com.android.internal.R.styleable.TranslateAnimation_toYDelta), context);
mToYType = d.type;
mToYValue = d.value;

View File

@@ -6953,10 +6953,10 @@
</declare-styleable>
<declare-styleable name="TranslateAnimation">
<attr name="fromXDelta" format="float|fraction" />
<attr name="toXDelta" format="float|fraction" />
<attr name="fromYDelta" format="float|fraction" />
<attr name="toYDelta" format="float|fraction" />
<attr name="fromXDelta" format="float|fraction|dimension" />
<attr name="toXDelta" format="float|fraction|dimension" />
<attr name="fromYDelta" format="float|fraction|dimension" />
<attr name="toYDelta" format="float|fraction|dimension" />
</declare-styleable>
<declare-styleable name="AlphaAnimation">