Merge "Fix API feedback on Color" into oc-dev am: 03758701fb
am: 7700c2b238

Change-Id: I64f6dcabfd1722475947be3b3e3cc636b724dbed
diff --git a/graphics/java/android/graphics/Color.java b/graphics/java/android/graphics/Color.java
index 218b857c..8cbf921 100644
--- a/graphics/java/android/graphics/Color.java
+++ b/graphics/java/android/graphics/Color.java
@@ -538,7 +538,7 @@
     /**
      * Returns the value of the alpha component in the range \([0..1]\).
      * Calling this method is equivalent to
-     * <code>getComponent(getComponentCount())</code>.
+     * <code>getComponent(getComponentCount() - 1)</code>.
      *
      * @see #red()
      * @see #green()
@@ -690,9 +690,8 @@
      * Returns the color space encoded in the specified color long.
      *
      * @param color The color long whose color space to extract
-     * @return A non-null color space instance. If the color long encodes
-     * an unknown or invalid color space, the {@link ColorSpace.Named#SRGB sRGB}
-     * color space is returned
+     * @return A non-null color space instance
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      *
      * @see #red(long)
      * @see #green(long)
@@ -787,6 +786,7 @@
      *
      * @param color The color to test
      * @return True if the color is in the sRGB color space, false otherwise
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      *
      * @see #isInColorSpace(long, ColorSpace)
      * @see #isWideGamut(long)
@@ -802,6 +802,7 @@
      *
      * @param color The color to test
      * @return True if the color is in a wide-gamut color space, false otherwise
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      *
      * @see #isInColorSpace(long, ColorSpace)
      * @see #isSrgb(long)
@@ -831,6 +832,7 @@
      * a color space conversion is applied if needed.
      *
      * @return An ARGB color in the sRGB color space
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      */
     @ColorInt
     public static int toArgb(@ColorLong long color) {
@@ -873,6 +875,7 @@
      *
      * @param color The color long to create a <code>Color</code> from
      * @return A non-null instance of {@link Color}
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      */
     @NonNull
     public static Color valueOf(@ColorLong long color) {
@@ -1100,6 +1103,7 @@
      * @param color The color long to convert
      * @param colorSpace The destination color space
      * @return A color long in the destination color space
+     * @throws IllegalArgumentException If the encoded color space is invalid or unknown
      */
     @ColorLong
     public static long convert(@ColorLong long color, @NonNull ColorSpace colorSpace) {
@@ -1206,7 +1210,7 @@
      * @return A value between 0 (darkest black) and 1 (lightest white)
      *
      * @throws IllegalArgumentException If the specified color's color space
-     * does not use the {@link ColorSpace.Model#RGB RGB} color model
+     * is unknown or does not use the {@link ColorSpace.Model#RGB RGB} color model
      */
     public static float luminance(@ColorLong long color) {
         ColorSpace colorSpace = colorSpace(color);
diff --git a/graphics/java/android/graphics/ColorSpace.java b/graphics/java/android/graphics/ColorSpace.java
index 8f78319..67504cf 100644
--- a/graphics/java/android/graphics/ColorSpace.java
+++ b/graphics/java/android/graphics/ColorSpace.java
@@ -1338,9 +1338,8 @@
     }
 
     /**
-     * <p>Returns an instance of {@link ColorSpace} whose ID matches the specified
-     * ID. If the ID is < 0 or &gt; {@link #MAX_ID}, calling this method is equivalent
-     * to calling <code>get(Named.SRGB)</code>.</p>
+     * <p>Returns an instance of {@link ColorSpace} whose ID matches the
+     * specified ID.</p>
      *
      * <p>This method always returns the same instance for a given ID.</p>
      *
@@ -1348,11 +1347,14 @@
      *
      * @param index An integer ID between {@link #MIN_ID} and {@link #MAX_ID}
      * @return A non-null {@link ColorSpace} instance
+     * @throws IllegalArgumentException If the ID does not match the ID of one of the
+     *         {@link Named named color spaces}
      */
     @NonNull
     static ColorSpace get(@IntRange(from = MIN_ID, to = MAX_ID) int index) {
         if (index < 0 || index > Named.values().length) {
-            return get(Named.SRGB);
+            throw new IllegalArgumentException("Invalid ID, must be in the range [0.." +
+                    Named.values().length + "]");
         }
         return sNamedColorSpaces[index];
     }