Rotates the expand/collapse arrow

bug: 16787869
Change-Id: I1b9fea6fa4d75b202b1ef20336abfd9b19efcc30
diff --git a/res/drawable/expanding_entry_card_collapse_white_24.xml b/res/drawable/expanding_entry_card_collapse_white_24.xml
deleted file mode 100644
index a38706e..0000000
--- a/res/drawable/expanding_entry_card_collapse_white_24.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 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.
--->
-
-<rotate xmlns:android="http://schemas.android.com/apk/res/android"
-        android:drawable="@drawable/expanding_entry_card_expand_white_24"
-        android:fromDegrees="180"
-        android:toDegrees="0"/>
\ No newline at end of file
diff --git a/res/layout/quickcontact_expanding_entry_card_button.xml b/res/layout/quickcontact_expanding_entry_card_button.xml
index 7bf7e67..1f0c724 100644
--- a/res/layout/quickcontact_expanding_entry_card_button.xml
+++ b/res/layout/quickcontact_expanding_entry_card_button.xml
@@ -30,15 +30,24 @@
         android:layout_height="wrap_content"
         android:orientation="horizontal" >
 
+        <ImageView
+            android:id="@+id/arrow"
+            android:src="@drawable/expanding_entry_card_expand_white_24"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/expanding_entry_card_item_padding_start"
+            android:paddingBottom="@dimen/expanding_entry_card_button_padding_vertical"
+            android:paddingTop="@dimen/expanding_entry_card_button_padding_vertical"
+            android:layout_weight="0" />
+
         <TextView
             android:id="@+id/text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:drawablePadding="@dimen/expanding_entry_card_item_image_spacing"
+            android:paddingStart="@dimen/expanding_entry_card_item_image_spacing"
             android:gravity="center_vertical"
             android:layout_weight="0"
             android:paddingBottom="@dimen/expanding_entry_card_button_padding_vertical"
-            android:paddingStart="@dimen/expanding_entry_card_item_padding_start"
             android:paddingTop="@dimen/expanding_entry_card_button_padding_vertical"
             android:textColor="@color/expanding_entry_card_button_text_color"
             android:textSize="@dimen/expanding_entry_card_title_text_size" />
diff --git a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
index 6812ac4..49a2b85 100644
--- a/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
+++ b/src/com/android/contacts/quickcontact/ExpandingEntryCardView.java
@@ -15,6 +15,7 @@
  */
 package com.android.contacts.quickcontact;
 
+import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
@@ -177,8 +178,7 @@
     private boolean mAllEntriesInflated = false;
     private List<List<View>> mEntryViews;
     private LinearLayout mEntriesViewGroup;
-    private final Drawable mCollapseArrowDrawable;
-    private final Drawable mExpandArrowDrawable;
+    private final ImageView mExpandCollapseArrow;
     private int mThemeColor;
     private ColorFilter mThemeColorFilter;
     private boolean mIsAlwaysExpanded;
@@ -211,14 +211,11 @@
                 expandingEntryCardView.findViewById(R.id.content_area_linear_layout);
         mTitleTextView = (TextView) expandingEntryCardView.findViewById(R.id.title);
         mContainer = (LinearLayout) expandingEntryCardView.findViewById(R.id.container);
-        mCollapseArrowDrawable =
-                getResources().getDrawable(R.drawable.expanding_entry_card_collapse_white_24);
-        mExpandArrowDrawable =
-                getResources().getDrawable(R.drawable.expanding_entry_card_expand_white_24);
 
         mExpandCollapseButton = inflater.inflate(
                 R.layout.quickcontact_expanding_entry_card_button, this, false);
         mExpandCollapseTextView = (TextView) mExpandCollapseButton.findViewById(R.id.text);
+        mExpandCollapseArrow = (ImageView) mExpandCollapseButton.findViewById(R.id.arrow);
         mExpandCollapseButton.setOnClickListener(mExpandCollapseButtonListener);
         mBadgeContainer = (LinearLayout) mExpandCollapseButton.findViewById(R.id.badge_container);
 
@@ -256,10 +253,10 @@
         mAnimationViewGroup = animationViewGroup;
 
         if (mIsExpanded) {
-            updateExpandCollapseButton(getCollapseButtonText());
+            updateExpandCollapseButton(getCollapseButtonText(), /* duration = */ 0);
             inflateAllEntries(layoutInflater);
         } else {
-            updateExpandCollapseButton(getExpandButtonText());
+            updateExpandCollapseButton(getExpandButtonText(), /* duration = */ 0);
             inflateInitialEntries(layoutInflater);
         }
         insertEntriesIntoViewGroup();
@@ -468,8 +465,7 @@
 
             // Expand/Collapse
             mExpandCollapseTextView.setTextColor(mThemeColor);
-            mCollapseArrowDrawable.setColorFilter(mThemeColorFilter);
-            mExpandArrowDrawable.setColorFilter(mThemeColorFilter);
+            mExpandCollapseArrow.setColorFilter(mThemeColorFilter);
         }
     }
 
@@ -577,16 +573,20 @@
         return view;
     }
 
-    private void updateExpandCollapseButton(CharSequence buttonText) {
-        final Drawable arrow = mIsExpanded ? mCollapseArrowDrawable : mExpandArrowDrawable;
-        updateBadges();
-        if (getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
-            mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, arrow,
-                    null);
+    private void updateExpandCollapseButton(CharSequence buttonText, long duration) {
+        if (mIsExpanded) {
+            final ObjectAnimator animator = ObjectAnimator.ofFloat(mExpandCollapseArrow,
+                    "rotation", 180);
+            animator.setDuration(duration);
+            animator.start();
         } else {
-            mExpandCollapseTextView.setCompoundDrawablesWithIntrinsicBounds(arrow, null, null,
-                    null);
+            final ObjectAnimator animator = ObjectAnimator.ofFloat(mExpandCollapseArrow,
+                    "rotation", 0);
+            animator.setDuration(duration);
+            animator.start();
         }
+        updateBadges();
+
         mExpandCollapseTextView.setText(buttonText);
     }
 
@@ -665,13 +665,15 @@
         // In order to insert new entries, we may need to inflate them for the first time
         inflateAllEntries(LayoutInflater.from(getContext()));
         insertEntriesIntoViewGroup();
-        updateExpandCollapseButton(getCollapseButtonText());
+        updateExpandCollapseButton(getCollapseButtonText(),
+                DURATION_EXPAND_ANIMATION_CHANGE_BOUNDS);
     }
 
     private void collapse() {
         final int startingHeight = mEntriesViewGroup.getMeasuredHeight();
         mIsExpanded = false;
-        updateExpandCollapseButton(getExpandButtonText());
+        updateExpandCollapseButton(getExpandButtonText(),
+                DURATION_COLLAPSE_ANIMATION_CHANGE_BOUNDS);
 
         final ChangeBounds boundsTransition = new ChangeBounds();
         boundsTransition.setDuration(DURATION_COLLAPSE_ANIMATION_CHANGE_BOUNDS);