DO NOT MERGE Expose util for setting custom drawable states

Expose helper method to allow an application to set its own custom
drawable states.

Bug: 216643999
Test: manual
Change-Id: Ic1c996878e969ce1ec75d0f595b069dc102491ec
diff --git a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUiUtils.java b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUiUtils.java
index a2ba477..17d01b9 100644
--- a/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUiUtils.java
+++ b/car-ui-lib/car-ui-lib/src/main/java/com/android/car/ui/utils/CarUiUtils.java
@@ -334,7 +334,7 @@
             return;
         }
         initializeRestrictedState(view);
-        applyStatesToAllViews(view, restricted ? sRestrictedState : null, null);
+        applyDrawableStatesToAllViews(view, restricted ? sRestrictedState : null, null);
     }
 
     /**
@@ -351,7 +351,7 @@
         initializeRestrictedState(view);
         int[] statesToAdd = enabled ? new int[] {android.R.attr.state_enabled} : null;
         int[] statesToRemove = enabled ? null : new int[] {android.R.attr.state_enabled};
-        applyStatesToAllViews(view, statesToAdd, statesToRemove);
+        applyDrawableStatesToAllViews(view, statesToAdd, statesToRemove);
     }
 
     /**
@@ -380,7 +380,27 @@
             statesToAdd = sRestrictedState;
         }
         int[] statesToRemove = enabled ? null : new int[] {android.R.attr.state_enabled};
-        applyStatesToAllViews(view, statesToAdd, statesToRemove);
+        applyDrawableStatesToAllViews(view, statesToAdd, statesToRemove);
+    }
+
+    /**
+     * Traverses the view hierarchy, and whenever it sees a {@link DrawableStateView}, adds and
+     * removes the specified states from the view.
+     *
+     * Note that this will remove any other drawable states added by other calls to
+     * {@link DrawableStateView#setExtraDrawableState(int[], int[])}
+     */
+    public static void applyDrawableStatesToAllViews(@NonNull View view, int[] statesToAdd,
+            int[] statesToRemove) {
+        if (view instanceof DrawableStateView) {
+            ((DrawableStateView) view).setExtraDrawableState(statesToAdd, statesToRemove);
+        }
+        if (view instanceof ViewGroup) {
+            ViewGroup vg = (ViewGroup) view;
+            for (int i = 0; i < vg.getChildCount(); i++) {
+                applyDrawableStatesToAllViews(vg.getChildAt(i), statesToAdd, statesToRemove);
+            }
+        }
     }
 
     private static void initializeRestrictedState(@NonNull View view) {
@@ -399,17 +419,4 @@
             };
         }
     }
-
-    private static void applyStatesToAllViews(@NonNull View view, int[] statesToAdd,
-            int[] statesToRemove) {
-        if (view instanceof DrawableStateView) {
-            ((DrawableStateView) view).setExtraDrawableState(statesToAdd, statesToRemove);
-        }
-        if (view instanceof ViewGroup) {
-            ViewGroup vg = (ViewGroup) view;
-            for (int i = 0; i < vg.getChildCount(); i++) {
-                applyStatesToAllViews(vg.getChildAt(i), statesToAdd, statesToRemove);
-            }
-        }
-    }
 }