Merge "DO NOT MERGE Rename PointerIcon and Pointer Capture APIs" into nyc-dev
diff --git a/v4/api/current.txt b/v4/api/current.txt
index 709740b..4a16350 100644
--- a/v4/api/current.txt
+++ b/v4/api/current.txt
@@ -2520,32 +2520,32 @@
   }
 
   public final class PointerIconCompat {
-    method public static android.support.v4.view.PointerIconCompat createCustomIcon(android.graphics.Bitmap, float, float);
+    method public static android.support.v4.view.PointerIconCompat create(android.graphics.Bitmap, float, float);
     method public static android.support.v4.view.PointerIconCompat getSystemIcon(android.content.Context, int);
-    method public static android.support.v4.view.PointerIconCompat loadCustomIcon(android.content.res.Resources, int);
-    field public static final int STYLE_ALIAS = 1010; // 0x3f2
-    field public static final int STYLE_ALL_SCROLL = 1013; // 0x3f5
-    field public static final int STYLE_ARROW = 1000; // 0x3e8
-    field public static final int STYLE_CELL = 1006; // 0x3ee
-    field public static final int STYLE_CONTEXT_MENU = 1001; // 0x3e9
-    field public static final int STYLE_COPY = 1011; // 0x3f3
-    field public static final int STYLE_CROSSHAIR = 1007; // 0x3ef
-    field public static final int STYLE_DEFAULT = 1000; // 0x3e8
-    field public static final int STYLE_GRAB = 1020; // 0x3fc
-    field public static final int STYLE_GRABBING = 1021; // 0x3fd
-    field public static final int STYLE_HAND = 1002; // 0x3ea
-    field public static final int STYLE_HELP = 1003; // 0x3eb
-    field public static final int STYLE_HORIZONTAL_DOUBLE_ARROW = 1014; // 0x3f6
-    field public static final int STYLE_NO_DROP = 1012; // 0x3f4
-    field public static final int STYLE_NULL = 0; // 0x0
-    field public static final int STYLE_TEXT = 1008; // 0x3f0
-    field public static final int STYLE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017; // 0x3f9
-    field public static final int STYLE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016; // 0x3f8
-    field public static final int STYLE_VERTICAL_DOUBLE_ARROW = 1015; // 0x3f7
-    field public static final int STYLE_VERTICAL_TEXT = 1009; // 0x3f1
-    field public static final int STYLE_WAIT = 1004; // 0x3ec
-    field public static final int STYLE_ZOOM_IN = 1018; // 0x3fa
-    field public static final int STYLE_ZOOM_OUT = 1019; // 0x3fb
+    method public static android.support.v4.view.PointerIconCompat load(android.content.res.Resources, int);
+    field public static final int TYPE_ALIAS = 1010; // 0x3f2
+    field public static final int TYPE_ALL_SCROLL = 1013; // 0x3f5
+    field public static final int TYPE_ARROW = 1000; // 0x3e8
+    field public static final int TYPE_CELL = 1006; // 0x3ee
+    field public static final int TYPE_CONTEXT_MENU = 1001; // 0x3e9
+    field public static final int TYPE_COPY = 1011; // 0x3f3
+    field public static final int TYPE_CROSSHAIR = 1007; // 0x3ef
+    field public static final int TYPE_DEFAULT = 1000; // 0x3e8
+    field public static final int TYPE_GRAB = 1020; // 0x3fc
+    field public static final int TYPE_GRABBING = 1021; // 0x3fd
+    field public static final int TYPE_HAND = 1002; // 0x3ea
+    field public static final int TYPE_HELP = 1003; // 0x3eb
+    field public static final int TYPE_HORIZONTAL_DOUBLE_ARROW = 1014; // 0x3f6
+    field public static final int TYPE_NO_DROP = 1012; // 0x3f4
+    field public static final int TYPE_NULL = 0; // 0x0
+    field public static final int TYPE_TEXT = 1008; // 0x3f0
+    field public static final int TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017; // 0x3f9
+    field public static final int TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016; // 0x3f8
+    field public static final int TYPE_VERTICAL_DOUBLE_ARROW = 1015; // 0x3f7
+    field public static final int TYPE_VERTICAL_TEXT = 1009; // 0x3f1
+    field public static final int TYPE_WAIT = 1004; // 0x3ec
+    field public static final int TYPE_ZOOM_IN = 1018; // 0x3fa
+    field public static final int TYPE_ZOOM_OUT = 1019; // 0x3fb
   }
 
   public final class ScaleGestureDetectorCompat {
@@ -2629,6 +2629,7 @@
     method public static boolean hasNestedScrollingParent(android.view.View);
     method public static boolean hasOnClickListeners(android.view.View);
     method public static boolean hasOverlappingRendering(android.view.View);
+    method public static boolean hasPointerCapture(android.view.View);
     method public static boolean hasTransientState(android.view.View);
     method public static boolean isAttachedToWindow(android.view.View);
     method public static boolean isInLayout(android.view.View);
@@ -2649,7 +2650,9 @@
     method public static void postInvalidateOnAnimation(android.view.View, int, int, int, int);
     method public static void postOnAnimation(android.view.View, java.lang.Runnable);
     method public static void postOnAnimationDelayed(android.view.View, java.lang.Runnable, long);
+    method public static void releasePointerCapture(android.view.View);
     method public static void requestApplyInsets(android.view.View);
+    method public static void requestPointerCapture(android.view.View);
     method public static int resolveSizeAndState(int, int, int);
     method public static void setAccessibilityDelegate(android.view.View, android.support.v4.view.AccessibilityDelegateCompat);
     method public static void setAccessibilityLiveRegion(android.view.View, int);
@@ -2673,6 +2676,7 @@
     method public static void setPaddingRelative(android.view.View, int, int, int, int);
     method public static void setPivotX(android.view.View, float);
     method public static void setPivotY(android.view.View, float);
+    method public static void setPointerIcon(android.view.View, android.support.v4.view.PointerIconCompat);
     method public static void setRotation(android.view.View, float);
     method public static void setRotationX(android.view.View, float);
     method public static void setRotationY(android.view.View, float);
diff --git a/v4/api24/android/support/v4/view/PointerIconCompatApi24.java b/v4/api24/android/support/v4/view/PointerIconCompatApi24.java
index c9f4377..d8c7ff0 100644
--- a/v4/api24/android/support/v4/view/PointerIconCompatApi24.java
+++ b/v4/api24/android/support/v4/view/PointerIconCompatApi24.java
@@ -26,11 +26,11 @@
         return PointerIcon.getSystemIcon(context, style);
     }
 
-    public static Object createCustomIcon(Bitmap bitmap, float hotSpotX, float hotSpotY) {
-        return PointerIcon.createCustomIcon(bitmap, hotSpotX, hotSpotY);
+    public static Object create(Bitmap bitmap, float hotSpotX, float hotSpotY) {
+        return PointerIcon.create(bitmap, hotSpotX, hotSpotY);
     }
 
-    public static Object loadCustomIcon(Resources resources, int resourceId) {
-        return PointerIcon.loadCustomIcon(resources, resourceId);
+    public static Object load(Resources resources, int resourceId) {
+        return PointerIcon.load(resources, resourceId);
     }
 }
diff --git a/v4/api24/android/support/v4/view/ViewCompatApi24.java b/v4/api24/android/support/v4/view/ViewCompatApi24.java
new file mode 100644
index 0000000..91d917b
--- /dev/null
+++ b/v4/api24/android/support/v4/view/ViewCompatApi24.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (C) 2016 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.
+ */
+
+package android.support.v4.view;
+
+import android.view.PointerIcon;
+import android.view.View;
+
+class ViewCompatApi24 {
+    public static void requestPointerCapture(View view) {
+        view.requestPointerCapture();
+    }
+
+    public static boolean hasPointerCapture(View view) {
+        return view.hasPointerCapture();
+    }
+
+    public static void releasePointerCapture(View view) {
+        view.releasePointerCapture();
+    }
+
+    public static void setPointerIcon(View view, Object pointerIcon) {
+        view.setPointerIcon((PointerIcon)pointerIcon);
+    }
+}
diff --git a/v4/java/android/support/v4/view/PointerIconCompat.java b/v4/java/android/support/v4/view/PointerIconCompat.java
index 2e78ffa..70344b8 100644
--- a/v4/java/android/support/v4/view/PointerIconCompat.java
+++ b/v4/java/android/support/v4/view/PointerIconCompat.java
@@ -26,74 +26,74 @@
  * level 4 in a backwards compatible fashion.
  */
 public final class PointerIconCompat {
-    /** Synonym for {@link android.view.PointerIcon#STYLE_NULL} */
-    public static final int STYLE_NULL = 0;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_NULL} */
+    public static final int TYPE_NULL = 0;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_ARROW} */
-    public static final int STYLE_ARROW = 1000;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_ARROW} */
+    public static final int TYPE_ARROW = 1000;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_CONTEXT_MENU} */
-    public static final int STYLE_CONTEXT_MENU = 1001;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_CONTEXT_MENU} */
+    public static final int TYPE_CONTEXT_MENU = 1001;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_HAND} */
-    public static final int STYLE_HAND = 1002;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_HAND} */
+    public static final int TYPE_HAND = 1002;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_HELP} */
-    public static final int STYLE_HELP = 1003;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_HELP} */
+    public static final int TYPE_HELP = 1003;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_WAIT} */
-    public static final int STYLE_WAIT = 1004;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_WAIT} */
+    public static final int TYPE_WAIT = 1004;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_CELL} */
-    public static final int STYLE_CELL = 1006;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_CELL} */
+    public static final int TYPE_CELL = 1006;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_CROSSHAIR} */
-    public static final int STYLE_CROSSHAIR = 1007;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_CROSSHAIR} */
+    public static final int TYPE_CROSSHAIR = 1007;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_TEXT} */
-    public static final int STYLE_TEXT = 1008;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_TEXT} */
+    public static final int TYPE_TEXT = 1008;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_VERTICAL_TEXT} */
-    public static final int STYLE_VERTICAL_TEXT = 1009;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_VERTICAL_TEXT} */
+    public static final int TYPE_VERTICAL_TEXT = 1009;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_ALIAS} */
-    public static final int STYLE_ALIAS = 1010;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_ALIAS} */
+    public static final int TYPE_ALIAS = 1010;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_COPY} */
-    public static final int STYLE_COPY = 1011;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_COPY} */
+    public static final int TYPE_COPY = 1011;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_NO_DROP} */
-    public static final int STYLE_NO_DROP = 1012;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_NO_DROP} */
+    public static final int TYPE_NO_DROP = 1012;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_ALL_SCROLL} */
-    public static final int STYLE_ALL_SCROLL = 1013;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_ALL_SCROLL} */
+    public static final int TYPE_ALL_SCROLL = 1013;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_HORIZONTAL_DOUBLE_ARROW} */
-    public static final int STYLE_HORIZONTAL_DOUBLE_ARROW = 1014;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_HORIZONTAL_DOUBLE_ARROW} */
+    public static final int TYPE_HORIZONTAL_DOUBLE_ARROW = 1014;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_VERTICAL_DOUBLE_ARROW} */
-    public static final int STYLE_VERTICAL_DOUBLE_ARROW = 1015;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_VERTICAL_DOUBLE_ARROW} */
+    public static final int TYPE_VERTICAL_DOUBLE_ARROW = 1015;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW} */
-    public static final int STYLE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW} */
+    public static final int TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW = 1016;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW} */
-    public static final int STYLE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW} */
+    public static final int TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW = 1017;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_ZOOM_IN} */
-    public static final int STYLE_ZOOM_IN = 1018;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_ZOOM_IN} */
+    public static final int TYPE_ZOOM_IN = 1018;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_ZOOM_OUT} */
-    public static final int STYLE_ZOOM_OUT = 1019;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_ZOOM_OUT} */
+    public static final int TYPE_ZOOM_OUT = 1019;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_GRAB} */
-    public static final int STYLE_GRAB = 1020;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_GRAB} */
+    public static final int TYPE_GRAB = 1020;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_GRABBING} */
-    public static final int STYLE_GRABBING = 1021;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_GRABBING} */
+    public static final int TYPE_GRABBING = 1021;
 
-    /** Synonym for {@link android.view.PointerIcon#STYLE_DEFAULT} */
-    public static final int STYLE_DEFAULT = STYLE_ARROW;
+    /** Synonym for {@link android.view.PointerIcon#TYPE_DEFAULT} */
+    public static final int TYPE_DEFAULT = TYPE_ARROW;
 
 
     private Object mPointerIcon;
@@ -102,10 +102,6 @@
         mPointerIcon = pointerIcon;
     }
 
-    private static PointerIconCompat create(Object pointerIcon) {
-        return new PointerIconCompat(pointerIcon);
-    }
-
     /**
      * @hide
      */
@@ -115,8 +111,8 @@
 
     interface PointerIconCompatImpl {
         Object getSystemIcon(Context context, int style);
-        Object createCustomIcon(Bitmap bitmap, float hotSpotX, float hotSpotY);
-        Object loadCustomIcon(Resources resources, int resourceId);
+        Object create(Bitmap bitmap, float hotSpotX, float hotSpotY);
+        Object load(Resources resources, int resourceId);
     }
 
     static class BasePointerIconCompatImpl implements PointerIconCompatImpl {
@@ -126,12 +122,12 @@
         }
 
         @Override
-        public Object createCustomIcon(Bitmap bitmap, float hotSpotX, float hotSpotY) {
+        public Object create(Bitmap bitmap, float hotSpotX, float hotSpotY) {
             return null;
         }
 
         @Override
-        public Object loadCustomIcon(Resources resources, int resourceId) {
+        public Object load(Resources resources, int resourceId) {
             return null;
         }
     }
@@ -143,13 +139,13 @@
         }
 
         @Override
-        public Object createCustomIcon(Bitmap bitmap, float hotSpotX, float hotSpotY) {
-            return PointerIconCompatApi24.createCustomIcon(bitmap, hotSpotX, hotSpotY);
+        public Object create(Bitmap bitmap, float hotSpotX, float hotSpotY) {
+            return PointerIconCompatApi24.create(bitmap, hotSpotX, hotSpotY);
         }
 
         @Override
-        public Object loadCustomIcon(Resources resources, int resourceId) {
-            return PointerIconCompatApi24.loadCustomIcon(resources, resourceId);
+        public Object load(Resources resources, int resourceId) {
+            return PointerIconCompatApi24.load(resources, resourceId);
         }
     }
 
@@ -173,7 +169,7 @@
      * @throws IllegalArgumentException if context is null.
      */
     public static PointerIconCompat getSystemIcon(Context context, int style) {
-        return create(IMPL.getSystemIcon(context, style));
+        return new PointerIconCompat(IMPL.getSystemIcon(context, style));
     }
 
     /**
@@ -189,8 +185,8 @@
      * @throws IllegalArgumentException if bitmap is null, or if the x/y hotspot
      *         parameters are invalid.
      */
-    public static PointerIconCompat createCustomIcon(Bitmap bitmap, float hotSpotX, float hotSpotY) {
-        return create(IMPL.createCustomIcon(bitmap, hotSpotX, hotSpotY));
+    public static PointerIconCompat create(Bitmap bitmap, float hotSpotX, float hotSpotY) {
+        return new PointerIconCompat(IMPL.create(bitmap, hotSpotX, hotSpotY));
     }
 
     /**
@@ -214,7 +210,7 @@
      * @throws Resources.NotFoundException if the resource was not found or the drawable
      * linked in the resource was not found.
      */
-    public static PointerIconCompat loadCustomIcon(Resources resources, int resourceId) {
-        return create(IMPL.loadCustomIcon(resources, resourceId));
+    public static PointerIconCompat load(Resources resources, int resourceId) {
+        return new PointerIconCompat(IMPL.load(resources, resourceId));
     }
 }
diff --git a/v4/java/android/support/v4/view/ViewCompat.java b/v4/java/android/support/v4/view/ViewCompat.java
index 0c74c66..d9326c5 100644
--- a/v4/java/android/support/v4/view/ViewCompat.java
+++ b/v4/java/android/support/v4/view/ViewCompat.java
@@ -478,6 +478,10 @@
         int getScrollIndicators(View view);
         void offsetTopAndBottom(View view, int offset);
         void offsetLeftAndRight(View view, int offset);
+        void requestPointerCapture(View view);
+        boolean hasPointerCapture(View view);
+        void releasePointerCapture(View view);
+        void setPointerIcon(View view, PointerIconCompat pointerIcon);
     }
 
     static class BaseViewCompatImpl implements ViewCompatImpl {
@@ -1106,6 +1110,26 @@
         public void offsetTopAndBottom(View view, int offset) {
             ViewCompatBase.offsetTopAndBottom(view, offset);
         }
+
+        @Override
+        public void requestPointerCapture(View view) {
+            // no-op
+        }
+
+        @Override
+        public boolean hasPointerCapture(View view) {
+            return false;
+        }
+
+        @Override
+        public void releasePointerCapture(View view) {
+            // no-op
+        }
+
+        @Override
+        public void setPointerIcon(View view, PointerIconCompat pointerIcon) {
+            // no-op
+        }
     }
 
     static class EclairMr1ViewCompatImpl extends BaseViewCompatImpl {
@@ -1747,10 +1771,34 @@
         }
     }
 
+    static class Api24ViewCompatImpl extends MarshmallowViewCompatImpl {
+        @Override
+        public void requestPointerCapture(View view) {
+            ViewCompatApi24.requestPointerCapture(view);
+        }
+
+        @Override
+        public boolean hasPointerCapture(View view) {
+            return ViewCompatApi24.hasPointerCapture(view);
+        }
+
+        @Override
+        public void releasePointerCapture(View view) {
+            ViewCompatApi24.releasePointerCapture(view);
+        }
+
+        @Override
+        public void setPointerIcon(View view, PointerIconCompat pointerIconCompat) {
+            ViewCompatApi24.setPointerIcon(view, pointerIconCompat.getPointerIcon());
+        }
+    }
+
     static final ViewCompatImpl IMPL;
     static {
         final int version = android.os.Build.VERSION.SDK_INT;
-        if (version >= 23) {
+        if (BuildCompat.isAtLeastN()) {
+            IMPL = new Api24ViewCompatImpl();
+        } else if (version >= 23) {
             IMPL = new MarshmallowViewCompatImpl();
         } else if (version >= 21) {
             IMPL = new LollipopViewCompatImpl();
@@ -3437,5 +3485,56 @@
         return IMPL.getScrollIndicators(view);
     }
 
+    /**
+     * Request capturing further mouse events.
+     *
+     * When the view captures, the pointer icon will disappear and will not change its
+     * position. Further pointer events will come to the capturing view, and the pointer movements
+     * will can be detected through {@link MotionEvent#AXIS_RELATIVE_X} and
+     * {@link MotionEvent#AXIS_RELATIVE_Y}. Non-mouse events (touchscreens, or stylus) will not
+     * be affected.
+     *
+     * The capture will be released through {@link #releasePointerCapture(View)}, or will be lost
+     * automatically when the view or containing window disappear.
+     *
+     * @return true when succeeds.
+     * @see #releasePointerCapture(View)
+     * @see #hasPointerCapture(View)
+     */
+    public static void requestPointerCapture(@NonNull View view) {
+        IMPL.requestPointerCapture(view);
+    }
+
+    /**
+     * Checks the capture status of mouse events.
+     *
+     * @return true if the view has the capture.
+     * @see #requestPointerCapture(View)
+     * @see #hasPointerCapture(View)
+     */
+    public static boolean hasPointerCapture(@NonNull View view) {
+        return IMPL.hasPointerCapture(view);
+    }
+
+    /**
+     * Release the current capture of mouse events.
+     *
+     * If the view does not have the capture, it will do nothing.
+     * @see #requestPointerCapture(View)
+     * @see #hasPointerCapture(View)
+     */
+    public static void releasePointerCapture(@NonNull View view) {
+        IMPL.releasePointerCapture(view);
+    }
+
+
+    /**
+     * Set the pointer icon for the current view.
+     * @param pointerIcon A PointerIconCompat instance which will be shown when the mouse hovers.
+     */
+    public static void setPointerIcon(@NonNull View view, PointerIconCompat pointerIcon) {
+        IMPL.setPointerIcon(view, pointerIcon);
+    }
+
     protected ViewCompat() {}
 }