diff options
author | Tor Norbye <tnorbye@google.com> | 2015-03-06 23:15:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-06 23:15:27 +0000 |
commit | c0a1b7f9a6a496deb68b095d122ca85f22daad98 (patch) | |
tree | 9c109f1612b670720a74c991f0b3b925dadb5af7 /graphics | |
parent | 376eb17e0e44f6b99e3dbd6964eb48f0afa80d7c (diff) | |
parent | 80756e38882720860db52f1fcc21fa1505a02abf (diff) | |
download | frameworks_base-c0a1b7f9a6a496deb68b095d122ca85f22daad98.zip frameworks_base-c0a1b7f9a6a496deb68b095d122ca85f22daad98.tar.gz frameworks_base-c0a1b7f9a6a496deb68b095d122ca85f22daad98.tar.bz2 |
Merge "Annotate ARGB integer parameters with @ColorInt"
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 10 | ||||
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 5 | ||||
-rw-r--r-- | graphics/java/android/graphics/Color.java | 43 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/ColorDrawable.java | 6 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/Drawable.java | 3 | ||||
-rw-r--r-- | graphics/java/android/graphics/drawable/GradientDrawable.java | 11 |
7 files changed, 51 insertions, 31 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 5b20d48..aae11cd 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -16,6 +16,7 @@ package android.graphics; +import android.annotation.ColorInt; import android.annotation.NonNull; import android.os.Parcel; import android.os.Parcelable; @@ -1278,7 +1279,7 @@ public final class Bitmap implements Parcelable { * * @throws IllegalStateException if the bitmap is not mutable. */ - public void eraseColor(int c) { + public void eraseColor(@ColorInt int c) { checkRecycled("Can't erase a recycled bitmap"); if (!isMutable()) { throw new IllegalStateException("cannot erase immutable bitmaps"); @@ -1296,6 +1297,7 @@ public final class Bitmap implements Parcelable { * @return The argb {@link Color} at the specified coordinate * @throws IllegalArgumentException if x, y exceed the bitmap's bounds */ + @ColorInt public int getPixel(int x, int y) { checkRecycled("Can't call getPixel() on a recycled bitmap"); checkPixelAccess(x, y); @@ -1325,7 +1327,7 @@ public final class Bitmap implements Parcelable { * @throws ArrayIndexOutOfBoundsException if the pixels array is too small * to receive the specified number of pixels. */ - public void getPixels(int[] pixels, int offset, int stride, + public void getPixels(@ColorInt int[] pixels, int offset, int stride, int x, int y, int width, int height) { checkRecycled("Can't call getPixels() on a recycled bitmap"); if (width == 0 || height == 0) { @@ -1407,7 +1409,7 @@ public final class Bitmap implements Parcelable { * @throws IllegalArgumentException if x, y are outside of the bitmap's * bounds. */ - public void setPixel(int x, int y, int color) { + public void setPixel(int x, int y, @ColorInt int color) { checkRecycled("Can't call setPixel() on a recycled bitmap"); if (!isMutable()) { throw new IllegalStateException(); @@ -1439,7 +1441,7 @@ public final class Bitmap implements Parcelable { * @throws ArrayIndexOutOfBoundsException if the pixels array is too small * to receive the specified number of pixels. */ - public void setPixels(int[] pixels, int offset, int stride, + public void setPixels(@ColorInt int[] pixels, int offset, int stride, int x, int y, int width, int height) { checkRecycled("Can't call setPixels() on a recycled bitmap"); if (!isMutable()) { diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 85fa3cb..55b7277 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -16,6 +16,7 @@ package android.graphics; +import android.annotation.ColorInt; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -1012,7 +1013,7 @@ public class Canvas { * * @param color the color to draw onto the canvas */ - public void drawColor(int color) { + public void drawColor(@ColorInt int color) { native_drawColor(mNativeCanvasWrapper, color, PorterDuff.Mode.SRC_OVER.nativeInt); } @@ -1023,7 +1024,7 @@ public class Canvas { * @param color the color to draw with * @param mode the porter-duff mode to apply to the color */ - public void drawColor(int color, @NonNull PorterDuff.Mode mode) { + public void drawColor(@ColorInt int color, @NonNull PorterDuff.Mode mode) { native_drawColor(mNativeCanvasWrapper, color, mode.nativeInt); } diff --git a/graphics/java/android/graphics/Color.java b/graphics/java/android/graphics/Color.java index 3fe5672..df0ebee 100644 --- a/graphics/java/android/graphics/Color.java +++ b/graphics/java/android/graphics/Color.java @@ -16,6 +16,7 @@ package android.graphics; +import android.annotation.ColorInt; import android.util.MathUtils; import com.android.internal.util.XmlUtils; @@ -35,23 +36,24 @@ import java.util.Locale; * 0xFFFFFFFF */ public class Color { - public static final int BLACK = 0xFF000000; - public static final int DKGRAY = 0xFF444444; - public static final int GRAY = 0xFF888888; - public static final int LTGRAY = 0xFFCCCCCC; - public static final int WHITE = 0xFFFFFFFF; - public static final int RED = 0xFFFF0000; - public static final int GREEN = 0xFF00FF00; - public static final int BLUE = 0xFF0000FF; - public static final int YELLOW = 0xFFFFFF00; - public static final int CYAN = 0xFF00FFFF; - public static final int MAGENTA = 0xFFFF00FF; - public static final int TRANSPARENT = 0; + @ColorInt public static final int BLACK = 0xFF000000; + @ColorInt public static final int DKGRAY = 0xFF444444; + @ColorInt public static final int GRAY = 0xFF888888; + @ColorInt public static final int LTGRAY = 0xFFCCCCCC; + @ColorInt public static final int WHITE = 0xFFFFFFFF; + @ColorInt public static final int RED = 0xFFFF0000; + @ColorInt public static final int GREEN = 0xFF00FF00; + @ColorInt public static final int BLUE = 0xFF0000FF; + @ColorInt public static final int YELLOW = 0xFFFFFF00; + @ColorInt public static final int CYAN = 0xFF00FFFF; + @ColorInt public static final int MAGENTA = 0xFFFF00FF; + @ColorInt public static final int TRANSPARENT = 0; /** * Return the alpha component of a color int. This is the same as saying * color >>> 24 */ + @ColorInt public static int alpha(int color) { return color >>> 24; } @@ -60,6 +62,7 @@ public class Color { * Return the red component of a color int. This is the same as saying * (color >> 16) & 0xFF */ + @ColorInt public static int red(int color) { return (color >> 16) & 0xFF; } @@ -68,6 +71,7 @@ public class Color { * Return the green component of a color int. This is the same as saying * (color >> 8) & 0xFF */ + @ColorInt public static int green(int color) { return (color >> 8) & 0xFF; } @@ -76,6 +80,7 @@ public class Color { * Return the blue component of a color int. This is the same as saying * color & 0xFF */ + @ColorInt public static int blue(int color) { return color & 0xFF; } @@ -90,6 +95,7 @@ public class Color { * @param green Green component [0..255] of the color * @param blue Blue component [0..255] of the color */ + @ColorInt public static int rgb(int red, int green, int blue) { return (0xFF << 24) | (red << 16) | (green << 8) | blue; } @@ -104,6 +110,7 @@ public class Color { * @param green Green component [0..255] of the color * @param blue Blue component [0..255] of the color */ + @ColorInt public static int argb(int alpha, int red, int green, int blue) { return (alpha << 24) | (red << 16) | (green << 8) | blue; } @@ -115,7 +122,7 @@ public class Color { * * @hide Pending API council */ - public static float hue(int color) { + public static float hue(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; @@ -157,7 +164,7 @@ public class Color { * * @hide Pending API council */ - public static float saturation(int color) { + public static float saturation(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; @@ -184,7 +191,7 @@ public class Color { * * @hide Pending API council */ - public static float brightness(int color) { + public static float brightness(@ColorInt int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; @@ -206,6 +213,7 @@ public class Color { * 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', * 'silver', 'teal'. */ + @ColorInt public static int parseColor(String colorString) { if (colorString.charAt(0) == '#') { // Use a long to avoid rollovers on #ffXXXXXX @@ -237,6 +245,7 @@ public class Color { * * @hide Pending API council */ + @ColorInt public static int HSBtoColor(float[] hsb) { return HSBtoColor(hsb[0], hsb[1], hsb[2]); } @@ -254,6 +263,7 @@ public class Color { * * @hide Pending API council */ + @ColorInt public static int HSBtoColor(float h, float s, float b) { h = MathUtils.constrain(h, 0.0f, 1.0f); s = MathUtils.constrain(s, 0.0f, 1.0f); @@ -332,7 +342,7 @@ public class Color { * @param color the argb color to convert. The alpha component is ignored. * @param hsv 3 element array which holds the resulting HSV components. */ - public static void colorToHSV(int color, float hsv[]) { + public static void colorToHSV(@ColorInt int color, float hsv[]) { RGBToHSV((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, hsv); } @@ -379,6 +389,7 @@ public class Color { * * @hide */ + @ColorInt public static int getHtmlColor(String color) { Integer i = sColorNameMap.get(color.toLowerCase(Locale.ROOT)); if (i != null) { diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 681bc62..0656b2e 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -16,6 +16,7 @@ package android.graphics; +import android.annotation.ColorInt; import android.text.GraphicsOperations; import android.text.SpannableString; import android.text.SpannedString; @@ -777,6 +778,7 @@ public class Paint { * * @return the paint's color (and alpha). */ + @ColorInt public native int getColor(); /** @@ -787,7 +789,7 @@ public class Paint { * * @param color The new color (including alpha) to set in the paint. */ - public native void setColor(int color); + public native void setColor(@ColorInt int color); /** * Helper to getColor() that just returns the color's alpha value. This is diff --git a/graphics/java/android/graphics/drawable/ColorDrawable.java b/graphics/java/android/graphics/drawable/ColorDrawable.java index 85e02b7..f75ab36 100644 --- a/graphics/java/android/graphics/drawable/ColorDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorDrawable.java @@ -16,6 +16,7 @@ package android.graphics.drawable; +import android.annotation.ColorInt; import android.annotation.NonNull; import android.graphics.*; import android.graphics.PorterDuff.Mode; @@ -62,7 +63,7 @@ public class ColorDrawable extends Drawable { * * @param color The color to draw. */ - public ColorDrawable(int color) { + public ColorDrawable(@ColorInt int color) { mColorState = new ColorState(); setColor(color); @@ -117,6 +118,7 @@ public class ColorDrawable extends Drawable { * * @return int The color to draw. */ + @ColorInt public int getColor() { return mColorState.mUseColor; } @@ -128,7 +130,7 @@ public class ColorDrawable extends Drawable { * * @param color The color to draw. */ - public void setColor(int color) { + public void setColor(@ColorInt int color) { if (mColorState.mBaseColor != color || mColorState.mUseColor != color) { mColorState.mBaseColor = mColorState.mUseColor = color; invalidateSelf(); diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 2cc192c..16760c7 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -16,6 +16,7 @@ package android.graphics.drawable; +import android.annotation.ColorInt; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.res.ColorStateList; @@ -544,7 +545,7 @@ public abstract class Drawable { * @see #setTintList(ColorStateList) * @see #setTintMode(PorterDuff.Mode) */ - public void setTint(int tintColor) { + public void setTint(@ColorInt int tintColor) { setTintList(ColorStateList.valueOf(tintColor)); } diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java index 6ea23d4..eff152c 100644 --- a/graphics/java/android/graphics/drawable/GradientDrawable.java +++ b/graphics/java/android/graphics/drawable/GradientDrawable.java @@ -16,6 +16,7 @@ package android.graphics.drawable; +import android.annotation.ColorInt; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; @@ -181,7 +182,7 @@ public class GradientDrawable extends Drawable { * Create a new gradient drawable given an orientation and an array * of colors for the gradient. */ - public GradientDrawable(Orientation orientation, int[] colors) { + public GradientDrawable(Orientation orientation, @ColorInt int[] colors) { this(new GradientState(orientation, colors), null); } @@ -250,7 +251,7 @@ public class GradientDrawable extends Drawable { * @see #mutate() * @see #setStroke(int, int, float, float) */ - public void setStroke(int width, int color) { + public void setStroke(int width, @ColorInt int color) { setStroke(width, color, 0, 0); } @@ -286,7 +287,7 @@ public class GradientDrawable extends Drawable { * @see #mutate() * @see #setStroke(int, int) */ - public void setStroke(int width, int color, float dashWidth, float dashGap) { + public void setStroke(int width, @ColorInt int color, float dashWidth, float dashGap) { mGradientState.setStroke(width, ColorStateList.valueOf(color), dashWidth, dashGap); setStrokeInternal(width, color, dashWidth, dashGap); } @@ -501,7 +502,7 @@ public class GradientDrawable extends Drawable { * @see #mutate() * @see #setColor(int) */ - public void setColors(int[] colors) { + public void setColors(@ColorInt int[] colors) { mGradientState.setColors(colors); mGradientIsDirty = true; invalidateSelf(); @@ -713,7 +714,7 @@ public class GradientDrawable extends Drawable { * @see #mutate() * @see #setColors(int[]) */ - public void setColor(int argb) { + public void setColor(@ColorInt int argb) { mGradientState.setColorStateList(ColorStateList.valueOf(argb)); mFillPaint.setColor(argb); invalidateSelf(); |