diff options
25 files changed, 132 insertions, 62 deletions
diff --git a/core/java/android/annotation/ColorInt.java b/core/java/android/annotation/ColorInt.java index 762a353..c4c93ee 100644 --- a/core/java/android/annotation/ColorInt.java +++ b/core/java/android/annotation/ColorInt.java @@ -26,7 +26,8 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; /** * Denotes that the annotated element represents a packed color - * int, {@code AARRGGBB}. + * int, {@code AARRGGBB}. If applied to an int array, every element + * in the array represents a color integer. * <p> * public abstract void setTextColor(@ColorInt int color); * }</pre> diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 9c00e1c..593585f 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -16,6 +16,7 @@ package android.app; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.IntDef; import android.annotation.SdkConstant; @@ -338,6 +339,7 @@ public class Notification implements Parcelable * @see #FLAG_SHOW_LIGHTS * @see #flags */ + @ColorInt public int ledARGB; /** @@ -520,12 +522,14 @@ public class Notification implements Parcelable * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are * ignored. */ + @ColorInt public int color = COLOR_DEFAULT; /** * Special value of {@link #color} telling the system not to decorate this notification with * any special color but instead use default colors when presenting this notification. */ + @ColorInt public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT /** @@ -2388,7 +2392,7 @@ public class Notification implements Parcelable * @see Notification#ledOnMS * @see Notification#ledOffMS */ - public Builder setLights(int argb, int onMs, int offMs) { + public Builder setLights(@ColorInt int argb, int onMs, int offMs) { mLedArgb = argb; mLedOnMs = onMs; mLedOffMs = offMs; @@ -2712,7 +2716,7 @@ public class Notification implements Parcelable * * @return The same Builder. */ - public Builder setColor(int argb) { + public Builder setColor(@ColorInt int argb) { mColor = argb; return this; } @@ -5160,7 +5164,7 @@ public class Notification implements Parcelable * automotive setting. This method can be used to override the color provided in the * notification in such a situation. */ - public CarExtender setColor(int color) { + public CarExtender setColor(@ColorInt int color) { mColor = color; return this; } @@ -5170,6 +5174,7 @@ public class Notification implements Parcelable * * @see setColor */ + @ColorInt public int getColor() { return mColor; } diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java index ace402a..841b09d 100644 --- a/core/java/android/content/res/ColorStateList.java +++ b/core/java/android/content/res/ColorStateList.java @@ -16,6 +16,7 @@ package android.content.res; +import android.annotation.ColorInt; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.res.Resources.Theme; @@ -91,7 +92,7 @@ public class ColorStateList implements Parcelable { * Creates a ColorStateList that returns the specified mapping from * states to colors. */ - public ColorStateList(int[][] states, int[] colors) { + public ColorStateList(int[][] states, @ColorInt int[] colors) { mStateSpecs = states; mColors = colors; @@ -102,7 +103,7 @@ public class ColorStateList implements Parcelable { * @return A ColorStateList containing a single color. */ @NonNull - public static ColorStateList valueOf(int color) { + public static ColorStateList valueOf(@ColorInt int color) { synchronized (sCache) { final int index = sCache.indexOfKey(color); if (index >= 0) { @@ -436,6 +437,7 @@ public class ColorStateList implements Parcelable { * * @return the default color in this {@link ColorStateList}. */ + @ColorInt public int getDefaultColor() { return mDefaultColor; } diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java index 584f3f6..5dc9ef9 100644 --- a/core/java/android/content/res/Resources.java +++ b/core/java/android/content/res/Resources.java @@ -16,6 +16,7 @@ package android.content.res; +import android.annotation.ColorInt; import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParser; @@ -925,6 +926,7 @@ public class Resources { * @return A single color value in the form 0xAARRGGBB. * @deprecated Use {@link #getColor(int, Theme)} instead. */ + @ColorInt public int getColor(@ColorRes int id) throws NotFoundException { return getColor(id, null); } @@ -945,6 +947,7 @@ public class Resources { * * @return A single color value in the form 0xAARRGGBB. */ + @ColorInt public int getColor(@ColorRes int id, @Nullable Theme theme) throws NotFoundException { TypedValue value; synchronized (mAccessLock) { diff --git a/core/java/android/content/res/TypedArray.java b/core/java/android/content/res/TypedArray.java index 3e07f0c..410849a 100644 --- a/core/java/android/content/res/TypedArray.java +++ b/core/java/android/content/res/TypedArray.java @@ -17,6 +17,7 @@ package android.content.res; import android.annotation.AnyRes; +import android.annotation.ColorInt; import android.annotation.Nullable; import android.graphics.drawable.Drawable; import android.os.StrictMode; @@ -420,7 +421,8 @@ public class TypedArray { * @throws UnsupportedOperationException if the attribute is defined but is * not an integer color or color state list. */ - public int getColor(int index, int defValue) { + @ColorInt + public int getColor(int index, @ColorInt int defValue) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } diff --git a/core/java/android/gesture/GestureOverlayView.java b/core/java/android/gesture/GestureOverlayView.java index e1a2a25..e0d454c 100644 --- a/core/java/android/gesture/GestureOverlayView.java +++ b/core/java/android/gesture/GestureOverlayView.java @@ -16,6 +16,7 @@ package android.gesture; +import android.annotation.ColorInt; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -204,18 +205,20 @@ public class GestureOverlayView extends FrameLayout { mOrientation = orientation; } - public void setGestureColor(int color) { + public void setGestureColor(@ColorInt int color) { mCertainGestureColor = color; } - public void setUncertainGestureColor(int color) { + public void setUncertainGestureColor(@ColorInt int color) { mUncertainGestureColor = color; } + @ColorInt public int getUncertainGestureColor() { return mUncertainGestureColor; } + @ColorInt public int getGestureColor() { return mCertainGestureColor; } diff --git a/core/java/android/text/TextPaint.java b/core/java/android/text/TextPaint.java index 0447117..4f8cff0 100644 --- a/core/java/android/text/TextPaint.java +++ b/core/java/android/text/TextPaint.java @@ -16,6 +16,7 @@ package android.text; +import android.annotation.ColorInt; import android.graphics.Paint; /** @@ -25,8 +26,10 @@ import android.graphics.Paint; public class TextPaint extends Paint { // Special value 0 means no background paint + @ColorInt public int bgColor; public int baselineShift; + @ColorInt public int linkColor; public int[] drawableState; public float density = 1.0f; @@ -34,6 +37,7 @@ public class TextPaint extends Paint { * Special value 0 means no custom underline * @hide */ + @ColorInt public int underlineColor = 0; /** * Defined as a multiplier of the default underline thickness. Use 1.0f for default thickness. diff --git a/core/java/android/text/style/ForegroundColorSpan.java b/core/java/android/text/style/ForegroundColorSpan.java index c9e09bd..f167aab 100644 --- a/core/java/android/text/style/ForegroundColorSpan.java +++ b/core/java/android/text/style/ForegroundColorSpan.java @@ -16,6 +16,7 @@ package android.text.style; +import android.annotation.ColorInt; import android.os.Parcel; import android.text.ParcelableSpan; import android.text.TextPaint; @@ -26,7 +27,7 @@ public class ForegroundColorSpan extends CharacterStyle private final int mColor; - public ForegroundColorSpan(int color) { + public ForegroundColorSpan(@ColorInt int color) { mColor = color; } @@ -46,6 +47,7 @@ public class ForegroundColorSpan extends CharacterStyle dest.writeInt(mColor); } + @ColorInt public int getForegroundColor() { return mColor; } diff --git a/core/java/android/text/style/QuoteSpan.java b/core/java/android/text/style/QuoteSpan.java index 29dd273..17748ca 100644 --- a/core/java/android/text/style/QuoteSpan.java +++ b/core/java/android/text/style/QuoteSpan.java @@ -16,6 +16,7 @@ package android.text.style; +import android.annotation.ColorInt; import android.graphics.Paint; import android.graphics.Canvas; import android.os.Parcel; @@ -34,7 +35,7 @@ public class QuoteSpan implements LeadingMarginSpan, ParcelableSpan { mColor = 0xff0000ff; } - public QuoteSpan(int color) { + public QuoteSpan(@ColorInt int color) { super(); mColor = color; } @@ -55,6 +56,7 @@ public class QuoteSpan implements LeadingMarginSpan, ParcelableSpan { dest.writeInt(mColor); } + @ColorInt public int getColor() { return mColor; } diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 4b3765a..ed1197c 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -18,6 +18,7 @@ package android.view; import android.animation.AnimatorInflater; import android.animation.StateListAnimator; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.IdRes; import android.annotation.IntDef; @@ -14311,7 +14312,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @see #buildDrawingCache() * @see #getDrawingCache() */ - public void setDrawingCacheBackgroundColor(int color) { + public void setDrawingCacheBackgroundColor(@ColorInt int color) { if (color != mDrawingCacheBackgroundColor) { mDrawingCacheBackgroundColor = color; mPrivateFlags &= ~PFLAG_DRAWING_CACHE_VALID; @@ -14323,6 +14324,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return The background color to used for the drawing cache's bitmap */ + @ColorInt public int getDrawingCacheBackgroundColor() { return mDrawingCacheBackgroundColor; } @@ -15536,6 +15538,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @return The known solid color background for this view, or 0 if the color may vary */ @ViewDebug.ExportedProperty(category = "drawing") + @ColorInt public int getSolidColor() { return 0; } @@ -16222,7 +16225,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @param color the color of the background */ @RemotableViewMethod - public void setBackgroundColor(int color) { + public void setBackgroundColor(@ColorInt int color) { if (mBackground instanceof ColorDrawable) { ((ColorDrawable) mBackground.mutate()).setColor(color); computeOpaqueFlags(); @@ -16238,6 +16241,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * * @return The color of the ColorDrawable background, if set, otherwise 0. */ + @ColorInt public int getBackgroundColor() { if (mBackground instanceof ColorDrawable) { return ((ColorDrawable) mBackground).getColor(); diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index e332135..744f665 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -16,6 +16,7 @@ package android.view; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.IdRes; import android.annotation.LayoutRes; @@ -1069,7 +1070,7 @@ public abstract class Window { public abstract void setTitle(CharSequence title); @Deprecated - public abstract void setTitleColor(int textColor); + public abstract void setTitleColor(@ColorInt int textColor); public abstract void openPanel(int featureId, KeyEvent event); @@ -1835,6 +1836,7 @@ public abstract class Window { /** * @return the color of the status bar. */ + @ColorInt public abstract int getStatusBarColor(); /** @@ -1852,11 +1854,12 @@ public abstract class Window { * The transitionName for the view background will be "android:status:background". * </p> */ - public abstract void setStatusBarColor(int color); + public abstract void setStatusBarColor(@ColorInt int color); /** * @return the color of the navigation bar. */ + @ColorInt public abstract int getNavigationBarColor(); /** @@ -1874,7 +1877,7 @@ public abstract class Window { * The transitionName for the view background will be "android:navigation:background". * </p> */ - public abstract void setNavigationBarColor(int color); + public abstract void setNavigationBarColor(@ColorInt int color); } diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java index 85d77cb..a5524d8 100644 --- a/core/java/android/view/animation/Animation.java +++ b/core/java/android/view/animation/Animation.java @@ -16,6 +16,7 @@ package android.view.animation; +import android.annotation.ColorInt; import android.content.Context; import android.content.res.TypedArray; import android.graphics.RectF; @@ -622,7 +623,7 @@ public abstract class Animation implements Cloneable { * @param bg The background color. If 0, no background. Currently must * be black, with any desired alpha level. */ - public void setBackgroundColor(int bg) { + public void setBackgroundColor(@ColorInt int bg) { mBackgroundColor = bg; } @@ -753,6 +754,7 @@ public abstract class Animation implements Cloneable { /** * Returns the background color behind the animation. */ + @ColorInt public int getBackgroundColor() { return mBackgroundColor; } diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index a6e2952..168066a 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.content.Context; import android.content.Intent; @@ -5982,7 +5983,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te * * @param color The background color */ - public void setCacheColorHint(int color) { + public void setCacheColorHint(@ColorInt int color) { if (color != mCacheColorHint) { mCacheColorHint = color; int count = getChildCount(); @@ -6000,6 +6001,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te * @return The cache color hint */ @ViewDebug.ExportedProperty(category = "drawing") + @ColorInt public int getCacheColorHint() { return mCacheColorHint; } diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java index fd1c4b8..5bc16cb 100644 --- a/core/java/android/widget/CalendarView.java +++ b/core/java/android/widget/CalendarView.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.Widget; import android.content.Context; @@ -140,7 +141,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor */ - public void setSelectedWeekBackgroundColor(int color) { + public void setSelectedWeekBackgroundColor(@ColorInt int color) { mDelegate.setSelectedWeekBackgroundColor(color); } @@ -151,6 +152,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor */ + @ColorInt public int getSelectedWeekBackgroundColor() { return mDelegate.getSelectedWeekBackgroundColor(); } @@ -162,7 +164,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_focusedMonthDateColor */ - public void setFocusedMonthDateColor(int color) { + public void setFocusedMonthDateColor(@ColorInt int color) { mDelegate.setFocusedMonthDateColor(color); } @@ -173,6 +175,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_focusedMonthDateColor */ + @ColorInt public int getFocusedMonthDateColor() { return mDelegate.getFocusedMonthDateColor(); } @@ -184,7 +187,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor */ - public void setUnfocusedMonthDateColor(int color) { + public void setUnfocusedMonthDateColor(@ColorInt int color) { mDelegate.setUnfocusedMonthDateColor(color); } @@ -195,6 +198,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor */ + @ColorInt public int getUnfocusedMonthDateColor() { return mDelegate.getUnfocusedMonthDateColor(); } @@ -206,7 +210,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_weekNumberColor */ - public void setWeekNumberColor(int color) { + public void setWeekNumberColor(@ColorInt int color) { mDelegate.setWeekNumberColor(color); } @@ -217,6 +221,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_weekNumberColor */ + @ColorInt public int getWeekNumberColor() { return mDelegate.getWeekNumberColor(); } @@ -228,7 +233,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor */ - public void setWeekSeparatorLineColor(int color) { + public void setWeekSeparatorLineColor(@ColorInt int color) { mDelegate.setWeekSeparatorLineColor(color); } @@ -239,6 +244,7 @@ public class CalendarView extends FrameLayout { * * @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor */ + @ColorInt public int getWeekSeparatorLineColor() { return mDelegate.getWeekSeparatorLineColor(); } diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index 391347e..9019f31 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.ColorInt; import android.content.res.TypedArray; import android.graphics.Paint; import android.graphics.PorterDuff; @@ -292,7 +293,7 @@ public class EdgeEffect { * * @param color Color in argb */ - public void setColor(int color) { + public void setColor(@ColorInt int color) { mPaint.setColor(color); } @@ -300,6 +301,7 @@ public class EdgeEffect { * Return the color of this edge effect in argb. * @return The color of this edge effect in argb */ + @ColorInt public int getColor() { return mPaint.getColor(); } diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index dd7fa18..a10be11 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.ColorInt; import android.app.ActivityOptions; import android.app.ActivityThread; import android.app.Application; @@ -2263,7 +2264,7 @@ public class RemoteViews implements Parcelable, Filter { * @param color Sets the text color for all the states (normal, selected, * focused) to be this color. */ - public void setTextColor(int viewId, int color) { + public void setTextColor(int viewId, @ColorInt int color) { setInt(viewId, "setTextColor", color); } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index dfe68fd..faf1c40 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -17,6 +17,7 @@ package android.widget; import android.R; +import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.NonNull; import android.annotation.Nullable; @@ -2997,7 +2998,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_textColor */ @android.view.RemotableViewMethod - public void setTextColor(int color) { + public void setTextColor(@ColorInt int color) { mTextColor = ColorStateList.valueOf(color); updateTextColors(); } @@ -3038,6 +3039,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * * @return Returns the current text color. */ + @ColorInt public final int getCurrentTextColor() { return mCurTextColor; } @@ -3048,7 +3050,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_textColorHighlight */ @android.view.RemotableViewMethod - public void setHighlightColor(int color) { + public void setHighlightColor(@ColorInt int color) { if (mHighlightColor != color) { mHighlightColor = color; invalidate(); @@ -3062,6 +3064,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * * @attr ref android.R.styleable#TextView_textColorHighlight */ + @ColorInt public int getHighlightColor() { return mHighlightColor; } @@ -3156,6 +3159,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * * @attr ref android.R.styleable#TextView_shadowColor */ + @ColorInt public int getShadowColor() { return mShadowColor; } @@ -3231,7 +3235,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_textColorHint */ @android.view.RemotableViewMethod - public final void setHintTextColor(int color) { + public final void setHintTextColor(@ColorInt int color) { mHintTextColor = ColorStateList.valueOf(color); updateTextColors(); } @@ -3270,6 +3274,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * * @return Returns the current hint text color. */ + @ColorInt public final int getCurrentHintTextColor() { return mHintTextColor != null ? mCurHintTextColor : mCurTextColor; } @@ -3283,7 +3288,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener * @attr ref android.R.styleable#TextView_textColorLink */ @android.view.RemotableViewMethod - public final void setLinkTextColor(int color) { + public final void setLinkTextColor(@ColorInt int color) { mLinkTextColor = ColorStateList.valueOf(color); updateTextColors(); } diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java index 9bc2aab..d2430bc 100644 --- a/core/java/android/widget/Toolbar.java +++ b/core/java/android/widget/Toolbar.java @@ -16,6 +16,7 @@ package android.widget; +import android.annotation.ColorInt; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.ActionBar; @@ -685,7 +686,7 @@ public class Toolbar extends ViewGroup { * * @param color The new text color in 0xAARRGGBB format */ - public void setTitleTextColor(int color) { + public void setTitleTextColor(@ColorInt int color) { mTitleTextColor = color; if (mTitleTextView != null) { mTitleTextView.setTextColor(color); @@ -697,7 +698,7 @@ public class Toolbar extends ViewGroup { * * @param color The new text color in 0xAARRGGBB format */ - public void setSubtitleTextColor(int color) { + public void setSubtitleTextColor(@ColorInt int color) { mSubtitleTextColor = color; if (mSubtitleTextView != null) { mSubtitleTextView.setTextColor(color); 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(); |