Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3ec733b authored by Tor Norbye's avatar Tor Norbye
Browse files

Annotate methods with size and range annotations

Change-Id: I666861f0dfae31402b1280e9a966a583b88e2e1a
parent 1c2bf03d
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@ import android.animation.StateListAnimator;
import android.annotation.CallSuper;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.FloatRange;
import android.annotation.IdRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.content.ClipData;
import android.content.Context;
import android.content.res.ColorStateList;
@@ -10580,7 +10582,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *
     * @attr ref android.R.styleable#View_alpha
     */
    public void setAlpha(float alpha) {
    public void setAlpha(@FloatRange(from=0.0, to=1.0) float alpha) {
        ensureTransformationInfo();
        if (mTransformationInfo.mAlpha != alpha) {
            mTransformationInfo.mAlpha = alpha;
@@ -17028,7 +17030,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *
     * @param location an array of two integers in which to hold the coordinates
     */
    public void getLocationOnScreen(int[] location) {
    public void getLocationOnScreen(@Size(2) int[] location) {
        getLocationInWindow(location);
        final AttachInfo info = mAttachInfo;
@@ -17045,7 +17047,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *
     * @param location an array of two integers in which to hold the coordinates
     */
    public void getLocationInWindow(int[] location) {
    public void getLocationInWindow(@Size(2) int[] location) {
        if (location == null || location.length < 2) {
            throw new IllegalArgumentException("location must be an array of two integers");
        }
@@ -18889,7 +18891,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @see #dispatchNestedPreScroll(int, int, int[], int[])
     */
    public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed,
            int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow) {
            int dxUnconsumed, int dyUnconsumed, @Nullable @Size(2) int[] offsetInWindow) {
        if (isNestedScrollingEnabled() && mNestedScrollingParent != null) {
            if (dxConsumed != 0 || dyConsumed != 0 || dxUnconsumed != 0 || dyUnconsumed != 0) {
                int startX = 0;
@@ -18937,7 +18939,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * @return true if the parent consumed some or all of the scroll delta
     * @see #dispatchNestedScroll(int, int, int, int, int[])
     */
    public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
    public boolean dispatchNestedPreScroll(int dx, int dy,
            @Nullable @Size(2) int[] consumed, @Nullable @Size(2) int[] offsetInWindow) {
        if (isNestedScrollingEnabled() && mNestedScrollingParent != null) {
            if (dx != 0 || dy != 0) {
                int startX = 0;
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view.animation;

import android.annotation.FloatRange;
import android.graphics.Matrix;
import android.graphics.Rect;

@@ -163,7 +164,7 @@ public class Transformation {
     * Sets the degree of transparency
     * @param alpha 1.0 means fully opaqe and 0.0 means fully transparent
     */
    public void setAlpha(float alpha) {
    public void setAlpha(@FloatRange(from=0.0, to=1.0) float alpha) {
        mAlpha = alpha;
    }

+10 −6
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.ColorInt;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.text.GraphicsOperations;
import android.text.SpannableString;
import android.text.SpannedString;
@@ -1055,14 +1056,15 @@ public class Canvas {
     *                 "points" that are drawn is really (count >> 1).
     * @param paint    The paint used to draw the points
     */
    public void drawPoints(float[] pts, int offset, int count, @NonNull Paint paint) {
    public void drawPoints(@Size(multiple=2) float[] pts, int offset, int count,
            @NonNull Paint paint) {
        native_drawPoints(mNativeCanvasWrapper, pts, offset, count, paint.getNativeInstance());
    }

    /**
     * Helper for drawPoints() that assumes you want to draw the entire array
     */
    public void drawPoints(@NonNull float[] pts, @NonNull Paint paint) {
    public void drawPoints(@Size(multiple=2) @NonNull float[] pts, @NonNull Paint paint) {
        drawPoints(pts, 0, pts.length, paint);
    }

@@ -1105,11 +1107,11 @@ public class Canvas {
     *                 (count >> 2).
     * @param paint    The paint used to draw the points
     */
    public void drawLines(float[] pts, int offset, int count, Paint paint) {
    public void drawLines(@Size(min=4,multiple=2) float[] pts, int offset, int count, Paint paint) {
        native_drawLines(mNativeCanvasWrapper, pts, offset, count, paint.getNativeInstance());
    }

    public void drawLines(@NonNull float[] pts, @NonNull Paint paint) {
    public void drawLines(@Size(min=4,multiple=2) @NonNull float[] pts, @NonNull Paint paint) {
        drawLines(pts, 0, pts.length, paint);
    }

@@ -1829,7 +1831,8 @@ public class Canvas {
     * @param paint    The paint used for the text (e.g. color, size, style)
     */
    @Deprecated
    public void drawPosText(@NonNull char[] text, int index, int count, @NonNull float[] pos,
    public void drawPosText(@NonNull char[] text, int index, int count,
            @NonNull @Size(multiple=2) float[] pos,
            @NonNull Paint paint) {
        if (index < 0 || index + count > text.length || count*2 > pos.length) {
            throw new IndexOutOfBoundsException();
@@ -1852,7 +1855,8 @@ public class Canvas {
     * @param paint The paint used for the text (e.g. color, size, style)
     */
    @Deprecated
    public void drawPosText(@NonNull String text, @NonNull float[] pos, @NonNull Paint paint) {
    public void drawPosText(@NonNull String text, @NonNull @Size(multiple=2) float[] pos,
            @NonNull Paint paint) {
        drawPosText(text.toCharArray(), 0, text.length(), pos, paint);
    }

+7 −6
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.ColorInt;
import android.annotation.Size;
import android.util.MathUtils;
import com.android.internal.util.XmlUtils;

@@ -214,7 +215,7 @@ public class Color {
     * 'silver', 'teal'.
     */
    @ColorInt
    public static int parseColor(String colorString) {
    public static int parseColor(@Size(min=1) String colorString) {
        if (colorString.charAt(0) == '#') {
            // Use a long to avoid rollovers on #ffXXXXXX
            long color = Long.parseLong(colorString.substring(1), 16);
@@ -246,7 +247,7 @@ public class Color {
     * @hide Pending API council
     */
    @ColorInt
    public static int HSBtoColor(float[] hsb) {
    public static int HSBtoColor(@Size(3) float[] hsb) {
        return HSBtoColor(hsb[0], hsb[1], hsb[2]);
    }
    
@@ -327,7 +328,7 @@ public class Color {
     * @param blue  blue component value [0..255]
     * @param hsv  3 element array which holds the resulting HSV components.
     */
    public static void RGBToHSV(int red, int green, int blue, float hsv[]) {
    public static void RGBToHSV(int red, int green, int blue, @Size(3) float hsv[]) {
        if (hsv.length < 3) {
            throw new RuntimeException("3 components required for hsv");
        }
@@ -342,7 +343,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(@ColorInt int color, float hsv[]) {
    public static void colorToHSV(@ColorInt int color, @Size(3) float hsv[]) {
        RGBToHSV((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF, hsv);
    }

@@ -355,7 +356,7 @@ public class Color {
     * @param hsv  3 element array which holds the input HSV components.
     * @return the resulting argb color
    */
    public static int HSVToColor(float hsv[]) {
    public static int HSVToColor(@Size(3) float hsv[]) {
        return HSVToColor(0xFF, hsv);
    }

@@ -370,7 +371,7 @@ public class Color {
     * @param hsv  3 element array which holds the input HSV components.
     * @return the resulting argb color
    */
    public static int HSVToColor(int alpha, float hsv[]) {
    public static int HSVToColor(int alpha, @Size(3) float hsv[]) {
        if (hsv.length < 3) {
            throw new RuntimeException("3 components required for hsv");
        }
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.graphics;

import android.annotation.FloatRange;
import android.annotation.NonNull;
import android.graphics.drawable.Drawable;

@@ -101,7 +102,7 @@ public final class Outline {
     * assumed by the drawing system to fully cover content beneath it,
     * meaning content beneath may be optimized away.
     */
    public void setAlpha(float alpha) {
    public void setAlpha(@FloatRange(from=0.0, to=1.0) float alpha) {
        mAlpha = alpha;
    }