Use a selector instead of loading resource for drop target.

Test: manual
Bug: 187355401,187035471
Change-Id: I65fef2c810c791c3282bd4a087359f6cff774cc4
diff --git a/res/drawable/drop_target_background.xml b/res/drawable/drop_target_background.xml
new file mode 100644
index 0000000..7e07bf5
--- /dev/null
+++ b/res/drawable/drop_target_background.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2021 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:state_selected="true"
+        android:drawable="@drawable/drop_target_frame_hover" />
+    <item android:state_selected="false"
+        android:drawable="@drawable/drop_target_frame" />
+</selector>
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 92824ad..0c389aa 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -271,7 +271,7 @@
         <item name="android:textSize">@dimen/drop_target_text_size</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">end</item>
-        <item name="android:background">@drawable/drop_target_frame</item>
+        <item name="android:background">@drawable/drop_target_background</item>
     </style>
 
     <style name="DropTargetButton" parent="DropTargetButtonBase" />
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index af77bf8..7db34a5 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -142,11 +142,6 @@
         }
     }
 
-    private void setBackgroundDrawable(int resId) {
-        Drawable bd = AppCompatResources.getDrawable(getContext(), resId);
-        setBackground(bd);
-    }
-
     @Override
     public final void onDragEnter(DragObject d) {
         if (!mAccessibleDrag && !mTextVisible) {
@@ -172,7 +167,7 @@
         }
 
         d.dragView.setAlpha(DRAG_VIEW_HOVER_OVER_OPACITY);
-        setBackgroundDrawable(R.drawable.drop_target_frame_hover);
+        setSelected(true);
         if (d.stateAnnouncer != null) {
             d.stateAnnouncer.cancel();
         }
@@ -190,7 +185,7 @@
 
         if (!d.dragComplete) {
             d.dragView.setAlpha(1f);
-            setBackgroundDrawable(R.drawable.drop_target_frame);
+            setSelected(false);
         } else {
             d.dragView.setAlpha(DRAG_VIEW_HOVER_OVER_OPACITY);
         }
@@ -230,6 +225,7 @@
     public void onDragEnd() {
         mActive = false;
         setOnClickListener(null);
+        setSelected(false);
     }
 
     /**