diff options
author | Doris Liu <tianliu@google.com> | 2015-04-18 00:14:14 +0000 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2015-04-18 00:14:14 +0000 |
commit | 7513aab4dfa33130fd846bf033f4878ae1c75914 (patch) | |
tree | ed583da74cf511e7108f434c60e25948c70f4070 /core/java/android/animation | |
parent | 5ed54c743c04e2bc349e12c31adb67cbc3094651 (diff) | |
download | frameworks_base-7513aab4dfa33130fd846bf033f4878ae1c75914.zip frameworks_base-7513aab4dfa33130fd846bf033f4878ae1c75914.tar.gz frameworks_base-7513aab4dfa33130fd846bf033f4878ae1c75914.tar.bz2 |
Revert "Use real screen size to scale duration"
This reverts commit 5ed54c743c04e2bc349e12c31adb67cbc3094651.
Reverting to avoid build breakage.
Change-Id: Ib73056bb5a11e718cbc82db5917946bdf8db06dc
Diffstat (limited to 'core/java/android/animation')
-rw-r--r-- | core/java/android/animation/Animator.java | 32 | ||||
-rw-r--r-- | core/java/android/animation/AnimatorInflater.java | 53 |
2 files changed, 27 insertions, 58 deletions
diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java index 068f700..02a329d 100644 --- a/core/java/android/animation/Animator.java +++ b/core/java/android/animation/Animator.java @@ -16,7 +16,6 @@ package android.animation; -import android.content.Context; import android.content.res.Configuration; import android.content.res.ConstantState; import android.content.res.Resources; @@ -38,7 +37,7 @@ public abstract class Animator implements Cloneable { public static final int HINT_NO_SCALE = 0; /** - * Set this scale hint (using {@link #setDurationScaleHint(Context, int)} when the animation's + * Set this scale hint (using {@link #setDurationScaleHint(int, Resources)} when the animation's * moving distance is proportional to the screen size. (e.g. a view coming in from the bottom of * the screen to top/center). With this scale hint set, the animation duration will be * automatically scaled based on screen size. @@ -46,7 +45,7 @@ public abstract class Animator implements Cloneable { public static final int HINT_DISTANCE_PROPORTIONAL_TO_SCREEN_SIZE = 1; /** - * Set this scale hint (using {@link #setDurationScaleHint(Context, int)}) if the animation + * Set this scale hint (using {@link #setDurationScaleHint(int, Resources)}) if the animation * has pre-defined moving distance in dp that does not vary from device to device. This is * extremely useful when the animation needs to run on both phones/tablets and TV, because TV * has inflated dp and therefore will have a longer visual arc for the same animation than on @@ -238,27 +237,12 @@ public abstract class Animator implements Cloneable { * users' field of view. Therefore, the duration scale factor is determined by the ratio of the * angular movement on current devices to that on the baseline device (i.e. Nexus 5). * - * @param context Context used to determine the display metrics * @param hint an indicator on how the animation is defined. The hint could be * {@link #HINT_NO_SCALE}, {@link #HINT_DISTANCE_PROPORTIONAL_TO_SCREEN_SIZE} or * {@link #HINT_DISTANCE_DEFINED_IN_DP}. + * @param res The resources {@see android.content.res.Resources} for getting display metrics */ - public void setDurationScaleHint(Context context, int hint) { - if (ANIM_DEBUG) { - Log.d("ANIM_DEBUG", "distance based duration hint: " + hint); - } - if (hint == mDurationScaleHint) { - return; - } - if (hint == HINT_NO_SCALE) { - mDurationScaleHint = hint; - return; - } - DisplayMetrics metrics = AnimationUtils.getRealDisplayMetrics(context); - setDurationScaleHint(context.getResources(), metrics, hint); - } - - void setDurationScaleHint(Resources res, DisplayMetrics metrics, int hint) { + public void setDurationScaleHint(int hint, Resources res) { if (ANIM_DEBUG) { Log.d("ANIM_DEBUG", "distance based duration hint: " + hint); } @@ -268,9 +252,9 @@ public abstract class Animator implements Cloneable { mDurationScaleHint = hint; if (hint != HINT_NO_SCALE) { int uiMode = res.getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK; - float dpi = metrics.xdpi; - float width = metrics.widthPixels / dpi; - float height = metrics.heightPixels / dpi; + DisplayMetrics metrics = res.getDisplayMetrics(); + float width = metrics.widthPixels / metrics.xdpi; + float height = metrics.heightPixels / metrics.ydpi; float viewingDistance = AnimationUtils.getViewingDistance(width, height, uiMode); if (ANIM_DEBUG) { Log.d("ANIM_DEBUG", "width, height, viewing distance, uimode: " @@ -279,7 +263,7 @@ public abstract class Animator implements Cloneable { mScreenSizeBasedDurationScale = AnimationUtils .getScreenSizeBasedDurationScale(width, height, viewingDistance); mDpBasedDurationScale = AnimationUtils.getDpBasedDurationScale( - metrics.density, dpi, viewingDistance); + metrics.density, metrics.xdpi, viewingDistance); if (ANIM_DEBUG) { Log.d("ANIM_DEBUG", "screen based scale, dp based scale: " + mScreenSizeBasedDurationScale + ", " + mDpBasedDurationScale); diff --git a/core/java/android/animation/AnimatorInflater.java b/core/java/android/animation/AnimatorInflater.java index 630a2cc..224e8e9 100644 --- a/core/java/android/animation/AnimatorInflater.java +++ b/core/java/android/animation/AnimatorInflater.java @@ -26,7 +26,6 @@ import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.Path; import android.util.AttributeSet; -import android.util.DisplayMetrics; import android.util.Log; import android.util.PathParser; import android.util.StateSet; @@ -86,47 +85,34 @@ public class AnimatorInflater { /** * Loads an {@link Animator} object from a resource * - * @param context Context used to access resources + * @param context Application context used to access resources * @param id The resource id of the animation to load * @return The animator object reference by the specified id * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded */ public static Animator loadAnimator(Context context, @AnimatorRes int id) throws NotFoundException { - return loadAnimator(context, context.getTheme(), id); + return loadAnimator(context.getResources(), context.getTheme(), id); } /** * Loads an {@link Animator} object from a resource * - * @param context Context used to access resources + * @param resources The resources * @param theme The theme * @param id The resource id of the animation to load * @return The animator object reference by the specified id * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded * @hide */ - public static Animator loadAnimator(Context context, Theme theme, int id) + public static Animator loadAnimator(Resources resources, Theme theme, int id) throws NotFoundException { - return loadAnimator(context, theme, id, 1); + return loadAnimator(resources, theme, id, 1); } /** @hide */ public static Animator loadAnimator(Resources resources, Theme theme, int id, float pathErrorScale) throws NotFoundException { - DisplayMetrics metrics = resources.getDisplayMetrics(); - return loadAnimator(resources, theme, id, pathErrorScale, metrics); - } - - private static Animator loadAnimator(Context context, Theme theme, int id, float pathErrorScale) - throws NotFoundException { - DisplayMetrics metrics = AnimationUtils.getRealDisplayMetrics(context); - return loadAnimator(context.getResources(), theme, id, pathErrorScale, metrics); - } - - private static Animator loadAnimator(Resources resources, Theme theme, int id, - float pathErrorScale, DisplayMetrics metrics) { - final ConfigurationBoundResourceCache<Animator> animatorCache = resources .getAnimatorCache(); Animator animator = animatorCache.get(id, theme); @@ -141,7 +127,7 @@ public class AnimatorInflater { XmlResourceParser parser = null; try { parser = resources.getAnimation(id); - animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale, metrics); + animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale); if (animator != null) { animator.appendChangingConfigurations(getChangingConfigs(resources, id)); final ConstantState<Animator> constantState = animator.createConstantState(); @@ -253,8 +239,7 @@ public class AnimatorInflater { } if (animator == null) { animator = createAnimatorFromXml(context.getResources(), - context.getTheme(), parser, 1f, - AnimationUtils.getRealDisplayMetrics(context)); + context.getTheme(), parser, 1f); } if (animator == null) { @@ -671,15 +656,15 @@ public class AnimatorInflater { } private static Animator createAnimatorFromXml(Resources res, Theme theme, XmlPullParser parser, - float pixelSize, DisplayMetrics metrics) + float pixelSize) throws XmlPullParserException, IOException { return createAnimatorFromXml(res, theme, parser, Xml.asAttributeSet(parser), null, 0, - pixelSize, metrics); + pixelSize); } private static Animator createAnimatorFromXml(Resources res, Theme theme, XmlPullParser parser, - AttributeSet attrs, AnimatorSet parent, int sequenceOrdering, float pixelSize, - DisplayMetrics metrics) throws XmlPullParserException, IOException { + AttributeSet attrs, AnimatorSet parent, int sequenceOrdering, float pixelSize) + throws XmlPullParserException, IOException { Animator anim = null; ArrayList<Animator> childAnims = null; @@ -698,9 +683,9 @@ public class AnimatorInflater { boolean gotValues = false; if (name.equals("objectAnimator")) { - anim = loadObjectAnimator(res, theme, attrs, pixelSize, metrics); + anim = loadObjectAnimator(res, theme, attrs, pixelSize); } else if (name.equals("animator")) { - anim = loadAnimator(res, theme, attrs, null, pixelSize, metrics); + anim = loadAnimator(res, theme, attrs, null, pixelSize); } else if (name.equals("set")) { anim = new AnimatorSet(); TypedArray a; @@ -712,10 +697,10 @@ public class AnimatorInflater { anim.appendChangingConfigurations(a.getChangingConfigurations()); int ordering = a.getInt(R.styleable.AnimatorSet_ordering, TOGETHER); createAnimatorFromXml(res, theme, parser, attrs, (AnimatorSet) anim, ordering, - pixelSize, metrics); + pixelSize); final int hint = a.getInt(R.styleable.AnimatorSet_durationScaleHint, HINT_NO_SCALE); - anim.setDurationScaleHint(res, metrics, hint); + anim.setDurationScaleHint(hint, res); a.recycle(); } else if (name.equals("propertyValuesHolder")) { PropertyValuesHolder[] values = loadValues(res, theme, parser, @@ -995,10 +980,10 @@ public class AnimatorInflater { } private static ObjectAnimator loadObjectAnimator(Resources res, Theme theme, AttributeSet attrs, - float pathErrorScale, DisplayMetrics metrics) throws NotFoundException { + float pathErrorScale) throws NotFoundException { ObjectAnimator anim = new ObjectAnimator(); - loadAnimator(res, theme, attrs, anim, pathErrorScale, metrics); + loadAnimator(res, theme, attrs, anim, pathErrorScale); return anim; } @@ -1013,7 +998,7 @@ public class AnimatorInflater { * ObjectAnimator */ private static ValueAnimator loadAnimator(Resources res, Theme theme, - AttributeSet attrs, ValueAnimator anim, float pathErrorScale, DisplayMetrics metrics) + AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws NotFoundException { TypedArray arrayAnimator = null; TypedArray arrayObjectAnimator = null; @@ -1054,7 +1039,7 @@ public class AnimatorInflater { final int hint = arrayAnimator.getInt(R.styleable.Animator_durationScaleHint, HINT_NO_SCALE); - anim.setDurationScaleHint(res, metrics, hint); + anim.setDurationScaleHint(hint, res); arrayAnimator.recycle(); if (arrayObjectAnimator != null) { arrayObjectAnimator.recycle(); |