Make sure visible View state is updated before dispatching clicks

Change-Id: If2619ffa760be708efe8b0d2d04e17eb0dc9375e
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 54c805f..e83b9b5 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -1775,6 +1775,7 @@
 
     private CheckForLongPress mPendingCheckForLongPress;
     private CheckForTap mPendingCheckForTap = null;
+    private PerformClick mPerformClick;
     
     private UnsetPressedState mUnsetPressedState;
 
@@ -4330,7 +4331,15 @@
 
                             // Only perform take click actions if we were in the pressed state
                             if (!focusTaken) {
-                                performClick();
+                                // Use a Runnable and post this rather than calling
+                                // performClick directly. This lets other visual state
+                                // of the view update before click actions start.
+                                if (mPerformClick == null) {
+                                    mPerformClick = new PerformClick();
+                                }
+                                if (!post(mPerformClick)) {
+                                    performClick();
+                                }
                             }
                         }
 
@@ -8965,6 +8974,12 @@
         }
     }
 
+    private final class PerformClick implements Runnable {
+        public void run() {
+            performClick();
+        }
+    }
+
     /**
      * Interface definition for a callback to be invoked when a key event is
      * dispatched to this view. The callback will be invoked before the key