Updated support for animator in MediaNowPlayingView pre-Lollipop

propertyValuesHolder is not supported pre-L which was causing crash for
API 21 and below. Moved all the animation for the MediaNowPlayingView
inside the code.

Test: MediaNowPlayingViewTest
Bug: 31687045
Change-Id: I139bdc61841b64f26f4ed9b719605d9f86feab7a
(cherry picked from commit a49ace0cc347f152d2847ca1290d9150a0413b31)
diff --git a/v17/leanback/res/animator/lb_playback_now_bar1_animator.xml b/v17/leanback/res/animator/lb_playback_now_bar1_animator.xml
deleted file mode 100644
index 10be669..0000000
--- a/v17/leanback/res/animator/lb_playback_now_bar1_animator.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
-                android:duration="2320"
-                android:repeatCount="infinite"
-                android:interpolator="@android:anim/linear_interpolator">
-    <propertyValuesHolder android:propertyName="scaleY" >
-
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.25" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.75" />
-
-        <keyframe android:value="0.833" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="1.0" />
-
-        <keyframe android:value="0.833" />
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.5" />
-        <keyframe android:value="0.333" />
-        <keyframe android:value="0.167" />
-
-        <keyframe android:value="0.333" />
-        <keyframe android:value="0.5" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.917" />
-
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.25" />
-        <keyframe android:value="0.417" />
-
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.25" />
-        <keyframe android:value="0.333" />
-        <keyframe android:value="0.417" />
-
-    </propertyValuesHolder>
-</objectAnimator>
\ No newline at end of file
diff --git a/v17/leanback/res/animator/lb_playback_now_bar2_animator.xml b/v17/leanback/res/animator/lb_playback_now_bar2_animator.xml
deleted file mode 100644
index 9b583b9..0000000
--- a/v17/leanback/res/animator/lb_playback_now_bar2_animator.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
-                android:duration="2080"
-                android:repeatCount="infinite"
-                android:interpolator="@android:anim/linear_interpolator">
-    <propertyValuesHolder android:propertyName="scaleY" >
-
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="1.0" />
-
-        <keyframe android:value="0.917" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.917" />
-
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="1.0" />
-
-        <keyframe android:value="0.917" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.25" />
-        <keyframe android:value="0.417" />
-
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="0.75" />
-
-        <keyframe android:value="0.667" />
-        <keyframe android:value="1.0" />
-
-    </propertyValuesHolder>
-</objectAnimator>
\ No newline at end of file
diff --git a/v17/leanback/res/animator/lb_playback_now_bar3_animator.xml b/v17/leanback/res/animator/lb_playback_now_bar3_animator.xml
deleted file mode 100644
index c842100..0000000
--- a/v17/leanback/res/animator/lb_playback_now_bar3_animator.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
-                android:duration="2000"
-                android:repeatCount="infinite"
-                android:interpolator="@android:anim/linear_interpolator">
-    <propertyValuesHolder android:propertyName="scaleY" >
-
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.833" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.917" />
-
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.667" />
-
-        <keyframe android:value="0.75" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.75" />
-
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.917" />
-        <keyframe android:value="1.0" />
-        <keyframe android:value="0.833" />
-
-        <keyframe android:value="0.667" />
-        <keyframe android:value="0.75" />
-        <keyframe android:value="0.583" />
-        <keyframe android:value="0.417" />
-        <keyframe android:value="0.25" />
-
-        <keyframe android:value="0.667" />
-
-    </propertyValuesHolder>
-</objectAnimator>
\ No newline at end of file
diff --git a/v17/leanback/src/android/support/v17/leanback/widget/MediaNowPlayingView.java b/v17/leanback/src/android/support/v17/leanback/widget/MediaNowPlayingView.java
index cb2691c..901ff55 100644
--- a/v17/leanback/src/android/support/v17/leanback/widget/MediaNowPlayingView.java
+++ b/v17/leanback/src/android/support/v17/leanback/widget/MediaNowPlayingView.java
@@ -13,19 +13,20 @@
  */
 package android.support.v17.leanback.widget;
 
+import static android.support.annotation.RestrictTo.Scope.GROUP_ID;
+
 import android.animation.Animator;
-import android.animation.AnimatorInflater;
 import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
 import android.content.Context;
 import android.support.annotation.RestrictTo;
+import android.support.v17.leanback.R;
 import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.animation.LinearInterpolator;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
-import android.support.v17.leanback.R;
-
-import static android.support.annotation.RestrictTo.Scope.GROUP_ID;
 
 /**
  * The view displaying 3 animated peak meters next to each other when a media item is playing.
@@ -40,6 +41,7 @@
     private final ObjectAnimator mObjectAnimator1;
     private final ObjectAnimator mObjectAnimator2;
     private final ObjectAnimator mObjectAnimator3;
+    protected final LinearInterpolator mLinearInterpolator = new LinearInterpolator();
 
     public MediaNowPlayingView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -57,17 +59,31 @@
         setDropScale(mImage2);
         setDropScale(mImage3);
 
-        mObjectAnimator1 = (ObjectAnimator) AnimatorInflater.loadAnimator(context,
-                R.animator.lb_playback_now_bar1_animator);
-        mObjectAnimator1.setTarget(mImage1);
+        mObjectAnimator1 = ObjectAnimator.ofFloat(mImage1, "scaleY", 5f / 12f, 3f / 12f, 5f / 12f,
+                7f / 12f, 9f / 12f, 10f / 12f, 11f / 12f, 12f / 12f, 11f / 12f, 12f / 12f,
+                10f / 12f, 8f / 12f, 6f / 12f, 4f / 12f, 2f / 12f, 4f / 12f, 6f / 12f, 7f / 12f,
+                9f / 12f, 11f / 12f, 9f / 12f, 7f / 12f, 5f / 12f, 3f / 12f, 5f / 12f, 8f / 12f,
+                5f / 12f, 3f / 12f, 4f / 12f, 5f / 12f);
+        mObjectAnimator1.setRepeatCount(ValueAnimator.INFINITE);
+        mObjectAnimator1.setDuration(2320);
+        mObjectAnimator1.setInterpolator(mLinearInterpolator);
 
-        mObjectAnimator2 = (ObjectAnimator) AnimatorInflater.loadAnimator(context,
-                R.animator.lb_playback_now_bar2_animator);
-        mObjectAnimator2.setTarget(mImage2);
+        mObjectAnimator2 = ObjectAnimator.ofFloat(mImage2, "scaleY", 12f / 12f, 11f / 12f,
+                10f / 12f, 11f / 12f, 12f / 12f, 11f / 12f, 9f / 12f, 7f / 12f, 9f / 12f, 11f / 12f,
+                12f / 12f, 10f / 12f, 8f / 12f, 10f / 12f, 12f / 12f, 11f / 12f, 9f / 12f, 5f / 12f,
+                3f / 12f, 5f / 12f, 8f / 12f, 10f / 12f, 12f / 12f, 10f / 12f, 9f / 12f, 8f / 12f,
+                12f / 12f);
+        mObjectAnimator2.setRepeatCount(ValueAnimator.INFINITE);
+        mObjectAnimator2.setDuration(2080);
+        mObjectAnimator2.setInterpolator(mLinearInterpolator);
 
-        mObjectAnimator3 = (ObjectAnimator) AnimatorInflater.loadAnimator(context,
-                R.animator.lb_playback_now_bar3_animator);
-        mObjectAnimator3.setTarget(mImage3);
+        mObjectAnimator3 = ObjectAnimator.ofFloat(mImage3, "scaleY", 8f / 12f, 9f / 12f, 10f / 12f,
+                12f / 12f, 11f / 12f, 9f / 12f, 7f / 12f, 5f / 12f, 7f / 12f, 8f / 12f, 9f / 12f,
+                12f / 12f, 11f / 12f, 12f / 12f, 9f / 12f, 7f / 12f, 9f / 12f, 11f / 12f, 12f / 12f,
+                10f / 12f, 8f / 12f, 9f / 12f, 7f / 12f, 5f / 12f, 3f / 12f, 8f / 12f);
+        mObjectAnimator3.setRepeatCount(ValueAnimator.INFINITE);
+        mObjectAnimator3.setDuration(2000);
+        mObjectAnimator3.setInterpolator(mLinearInterpolator);
     }
 
     static void setDropScale(View view) {
diff --git a/v17/leanback/tests/java/android/support/v17/leanback/widget/MediaNowPlayingViewTest.java b/v17/leanback/tests/java/android/support/v17/leanback/widget/MediaNowPlayingViewTest.java
new file mode 100644
index 0000000..dc6354c
--- /dev/null
+++ b/v17/leanback/tests/java/android/support/v17/leanback/widget/MediaNowPlayingViewTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.support.v17.leanback.widget;
+
+
+import android.content.Context;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+/**
+ * Testing MediaNowPlayingView widget
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+
+public class MediaNowPlayingViewTest {
+    private Context mContext;
+
+    @Before
+    public void setup() throws Exception {
+        mContext = InstrumentationRegistry.getTargetContext();
+    }
+
+    @Test
+    public void testViewCreation() {
+        new MediaNowPlayingView(mContext, null);
+    }
+}