Revert "Use real screen size to scale duration"

This reverts commit 5ed54c743c04e2bc349e12c31adb67cbc3094651.

Reverting to avoid build breakage.

Change-Id: Ib73056bb5a11e718cbc82db5917946bdf8db06dc
diff --git a/api/current.txt b/api/current.txt
index c5d4cdd..4a3b3dc 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -2879,7 +2879,7 @@
     method public void removePauseListener(android.animation.Animator.AnimatorPauseListener);
     method public void resume();
     method public abstract android.animation.Animator setDuration(long);
-    method public void setDurationScaleHint(android.content.Context, int);
+    method public void setDurationScaleHint(int, android.content.res.Resources);
     method public abstract void setInterpolator(android.animation.TimeInterpolator);
     method public abstract void setStartDelay(long);
     method public void setTarget(java.lang.Object);
diff --git a/api/system-current.txt b/api/system-current.txt
index 7dcc8ac..4b283fe0 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -2959,7 +2959,7 @@
     method public void removePauseListener(android.animation.Animator.AnimatorPauseListener);
     method public void resume();
     method public abstract android.animation.Animator setDuration(long);
-    method public void setDurationScaleHint(android.content.Context, int);
+    method public void setDurationScaleHint(int, android.content.res.Resources);
     method public abstract void setInterpolator(android.animation.TimeInterpolator);
     method public abstract void setStartDelay(long);
     method public void setTarget(java.lang.Object);
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 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 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 @@
      * 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 @@
         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 @@
             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.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 @@
     /**
      * 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 @@
         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 @@
                         }
                         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 @@
     }
 
     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 @@
             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 @@
                 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 @@
     }
 
     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 @@
      *            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 @@
 
         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();
diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java
index 4ca4add..0417921 100644
--- a/core/java/android/view/animation/AnimationUtils.java
+++ b/core/java/android/view/animation/AnimationUtils.java
@@ -16,10 +16,7 @@
 
 package android.view.animation;
 
-import android.app.Activity;
 import android.content.res.Configuration;
-import android.util.DisplayMetrics;
-import android.view.WindowManager;
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -51,7 +48,7 @@
     private static final float RECOMMENDED_FIELD_OF_VIEW_FOR_TV = 40f;
     private static final float ESTIMATED_VIEWING_DISTANCE_FOR_WATCH = 11f;
     private static final float AVERAGE_VIEWING_DISTANCE_FOR_PHONES = 14.2f;
-    private static final float N5_DIAGONAL_VIEW_ANGLE = 19.887228f;
+    private static final float N5_DIAGONAL_VIEW_ANGLE = 19.58f;
     private static final float N5_DENSITY = 3.0f;
     private static final float N5_DPI = 443f;
 
@@ -455,18 +452,4 @@
                 AVERAGE_VIEWING_DISTANCE_FOR_PHONES) * 2;
         return anglePerDp / baselineAnglePerDp;
     }
-
-    /**
-     * @hide
-     */
-    public static DisplayMetrics getRealDisplayMetrics(Context context) {
-        DisplayMetrics metrics = new DisplayMetrics();
-        if (context instanceof Activity) {
-            ((Activity) context).getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
-        } else {
-            ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
-                    .getRealMetrics(metrics);
-        }
-        return metrics;
-    }
 }