Using drawable states for drag and drop.

Now we're using states for icons, background colors,
and text colors. The framework updates these automatically
so we're not updating stuff when we receive DragEvents.

Change-Id: I16c14cc8681b8249428876f6bc435ac9a8de93cc
(cherry picked from commit 05eca5b9b96778122e6a4c4b66bec604f0103bea)
diff --git a/res/color/folder_item_text_color.xml b/res/color/folder_item_text_color.xml
index ab79a8d..47e27f0 100644
--- a/res/color/folder_item_text_color.xml
+++ b/res/color/folder_item_text_color.xml
@@ -16,7 +16,10 @@
      limitations under the License.
 -->
 
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item app:state_drag_mode="true" android:state_drag_can_accept="false"
+          android:color="@color/folder_disabled_drop_target_text_color" />
     <item android:state_activated="true" android:color="@android:color/white" />
     <item android:color="@color/dark_gray_text_color" />
 </selector>
diff --git a/res/drawable/folder_item.xml b/res/drawable/folder_item.xml
index c28ae55..4fd24d0 100644
--- a/res/drawable/folder_item.xml
+++ b/res/drawable/folder_item.xml
@@ -16,7 +16,13 @@
      limitations under the License.
 -->
 
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
+<selector xmlns:android="http://schemas.android.com/apk/res/android"
+          xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item app:state_drag_mode="true"
+          android:state_drag_can_accept="true" android:state_drag_hovered="true"
+          android:drawable="@drawable/list_pressed_holo" />
+    <item app:state_drag_mode="true"
+          android:drawable="@drawable/ic_drawer_divider" />
     <item android:state_pressed="true" android:drawable="@drawable/list_pressed_holo" />
     <item android:state_activated="true" android:drawable="@color/mail_app_blue" />
     <item android:state_focused="true" android:drawable="@drawable/list_focused_holo" />
diff --git a/src/com/android/mail/ui/FolderItemView.java b/src/com/android/mail/ui/FolderItemView.java
index c9b6e06..9e3b1c3 100644
--- a/src/com/android/mail/ui/FolderItemView.java
+++ b/src/com/android/mail/ui/FolderItemView.java
@@ -43,22 +43,9 @@
  */
 public class FolderItemView extends RelativeLayout {
     private final String LOG_TAG = LogTag.getLogTag();
-    // Static colors
-    private static int NON_DROPPABLE_TARGET_TEXT_COLOR;
-
-    // Static bitmap
-    private static Bitmap SHORTCUT_ICON;
-
-    // These are fine to be static, as these Drawables only have one state
-    private static Drawable DROPPABLE_HOVER_BACKGROUND;
-    private static Drawable DRAG_STEADY_STATE_BACKGROUND;
 
     private static final int[] STATE_DRAG_MODE = {R.attr.state_drag_mode};
 
-    private Drawable mBackground;
-    private ColorStateList mInitialFolderTextColor;
-    private ColorStateList mInitialUnreadCountTextColor;
-
     private Folder mFolder;
     private TextView mFolderTextView;
     private TextView mUnreadCountTextView;
@@ -102,23 +89,10 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-        if (SHORTCUT_ICON == null) {
-            final Resources res = getResources();
-            SHORTCUT_ICON = BitmapFactory.decodeResource(
-                    res, R.mipmap.ic_launcher_shortcut_folder);
-            DROPPABLE_HOVER_BACKGROUND =
-                    res.getDrawable(R.drawable.folder_drag_target);
-            DRAG_STEADY_STATE_BACKGROUND =
-                    res.getDrawable(R.drawable.folder_no_hover);
-            NON_DROPPABLE_TARGET_TEXT_COLOR =
-                    res.getColor(R.color.folder_disabled_drop_target_text_color);
-        }
+
         mFolderTextView = (TextView)findViewById(R.id.name);
         mUnreadCountTextView = (TextView)findViewById(R.id.unread);
         mUnseenCountTextView = (TextView)findViewById(R.id.unseen);
-        mBackground = getBackground();
-        mInitialFolderTextColor = mFolderTextView.getTextColors();
-        mInitialUnreadCountTextColor = mUnreadCountTextView.getTextColors();
         mFolderParentIcon = (ImageView) findViewById(R.id.folder_parent_icon);
     }
 
@@ -227,48 +201,20 @@
     public boolean onDragEvent(DragEvent event) {
         switch (event.getAction()) {
             case DragEvent.ACTION_DRAG_STARTED:
-                // Set the background to a steady state background.
-                setBackgroundDrawable(DRAG_STEADY_STATE_BACKGROUND);
+                // Set drag mode state to true now that we have entered drag mode.
+                // This change updates the states of icons and text colors.
+                // Additional drawable states are updated by the framework
+                // based on the DragEvent.
                 setDragMode(true);
-
-                // If this folder is not a drop target, dim the text.
-                if (!isDroppableTarget(event)) {
-                    // Make sure we update this at the time we drop on the target.
-                    mInitialFolderTextColor = mFolderTextView.getTextColors();
-                    mInitialUnreadCountTextColor = mUnreadCountTextView.getTextColors();
-                    mFolderTextView.setTextColor(NON_DROPPABLE_TARGET_TEXT_COLOR);
-                    mUnreadCountTextView.setTextColor(NON_DROPPABLE_TARGET_TEXT_COLOR);
-                    return false;
-                }
-                return true;
-
             case DragEvent.ACTION_DRAG_ENTERED:
-                // Change background color to indicate this folder is the drop target.
-                if (isDroppableTarget(event)) {
-                    setBackgroundDrawable(DROPPABLE_HOVER_BACKGROUND);
-                    return true;
-                }
-                break;
-
             case DragEvent.ACTION_DRAG_EXITED:
-                // If this is a droppable target, make sure that it is set back to steady state,
-                // when the drag leaves the view.
-                if (isDroppableTarget(event)) {
-                    setBackgroundDrawable(DRAG_STEADY_STATE_BACKGROUND);
-                    return true;
-                }
-                break;
-
+                // All of these states return based on isDroppableTarget's return value.
+                // If modifying, watch the switch's drop-through effects.
+                return isDroppableTarget(event);
             case DragEvent.ACTION_DRAG_ENDED:
-                // Reset the text of the non draggable views back to the color it had been..
-                if (!isDroppableTarget(event)) {
-                    mFolderTextView.setTextColor(mInitialFolderTextColor);
-                    mUnreadCountTextView.setTextColor(mInitialUnreadCountTextColor);
-                }
-
+                // Set drag mode to false since we're leaving drag mode.
+                // Updates all the states of icons and text colors back to non-drag values.
                 setDragMode(false);
-                // Restore the background of the view.
-                setBackgroundDrawable(mBackground);
                 return true;
 
             case DragEvent.ACTION_DRAG_LOCATION: