Rename PointerIcon and Pointer Capture APIs

This is a response to API council feedback.

Bug: 26830970
Change-Id: I4f525015275c4d068cef081a6465c1b77dcce625
diff --git a/compat/api/current.txt b/compat/api/current.txt
index eb5ff59..0e014e7 100644
--- a/compat/api/current.txt
+++ b/compat/api/current.txt
@@ -1251,9 +1251,9 @@
   }
 
   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);
+    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
@@ -1360,6 +1360,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);
@@ -1380,7 +1381,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);
@@ -1404,6 +1407,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/compat/api24/android/support/v4/view/PointerIconCompatApi24.java b/compat/api24/android/support/v4/view/PointerIconCompatApi24.java
index 6fa8707..d8c7ff0 100644
--- a/compat/api24/android/support/v4/view/PointerIconCompatApi24.java
+++ b/compat/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 null;
+    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 null;
+    public static Object load(Resources resources, int resourceId) {
+        return PointerIcon.load(resources, resourceId);
     }
 }
diff --git a/compat/api24/android/support/v4/view/ViewCompatApi24.java b/compat/api24/android/support/v4/view/ViewCompatApi24.java
new file mode 100644
index 0000000..91d917b
--- /dev/null
+++ b/compat/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/compat/java/android/support/v4/view/PointerIconCompat.java b/compat/java/android/support/v4/view/PointerIconCompat.java
index 6548543..70344b8 100644
--- a/compat/java/android/support/v4/view/PointerIconCompat.java
+++ b/compat/java/android/support/v4/view/PointerIconCompat.java
@@ -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/compat/java/android/support/v4/view/ViewCompat.java b/compat/java/android/support/v4/view/ViewCompat.java
index 5912156..f44f6cf 100644
--- a/compat/java/android/support/v4/view/ViewCompat.java
+++ b/compat/java/android/support/v4/view/ViewCompat.java
@@ -476,6 +476,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 {
@@ -1134,6 +1138,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 HCViewCompatImpl extends BaseViewCompatImpl {
@@ -1752,10 +1776,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();
@@ -3441,5 +3489,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() {}
 }