Using a proxy call for isAttachedToWindow for pre 19 devices

Bug: 17423114
Change-Id: I6f0cc306b7fcc8087b4e4fc92bb8796d51a989d6
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 6caa1cf..7a16914 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -16,6 +16,7 @@
 
 package com.android.launcher3;
 
+import android.annotation.TargetApi;
 import android.app.Activity;
 import android.content.ActivityNotFoundException;
 import android.content.ComponentName;
@@ -38,6 +39,8 @@
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.PaintDrawable;
 import android.os.Build;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
 import android.util.Log;
 import android.util.Pair;
 import android.util.SparseArray;
@@ -495,4 +498,14 @@
         }
         return null;
     }
+
+    @TargetApi(Build.VERSION_CODES.KITKAT)
+    public static boolean isViewAttachedToWindow(View v) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+            return v.isAttachedToWindow();
+        } else {
+            // A proxy call which returns null, if the view is not attached to the window.
+            return v.getKeyDispatcherState() != null;
+        }
+    }
 }