viewpager/src/androidTest/java/android/support/v4/testutils/TestUtils.java
public static void assertAllPixelsOfColor(String failMessagePrefix, @NonNull Drawable drawable,
            int drawableWidth, int drawableHeight, @ColorInt int color,
            boolean throwExceptionIfFails) {
        // Create a bitmap
        Bitmap bitmap = Bitmap.createBitmap(drawableWidth, drawableHeight, Bitmap.Config.ARGB_8888);
        // Create a canvas that wraps the bitmap
        Canvas canvas = new Canvas(bitmap);
        // Configure the drawable to have bounds that match its intrinsic size
        drawable.setBounds(0, 0, drawableWidth, drawableHeight);
        // And ask the drawable to draw itself to the canvas / bitmap
        drawable.draw(canvas);

        try {
            int[] rowPixels = new int[drawableWidth];
            for (int row = 0; row < drawableHeight; row++) {
                bitmap.getPixels(rowPixels, 0, drawableWidth, 0, row, drawableWidth, 1);
                for (int column = 0; column < drawableWidth; column++) {
                    if (rowPixels[column] != color) {
                        String mismatchDescription = failMessagePrefix
                                + ": expected all drawable colors to be ["
                                + Color.red(color) + "," + Color.green(color) + ","
                                + Color.blue(color)
                                + "] but at position (" + row + "," + column + ") found ["
                                + Color.red(rowPixels[column]) + ","
                                + Color.green(rowPixels[column]) + ","
                                + Color.blue(rowPixels[column]) + "]";
                        if (throwExceptionIfFails) {
                            throw new RuntimeException(mismatchDescription);
                        } else {
                            fail(mismatchDescription);
                        }
                    }
                }
            }
        } finally {
            bitmap.recycle();
        }
    }
/**
     * Checks whether all the pixels in the specified drawable are of the same specified color.
     *
     * In case there is a color mismatch, the behavior of this method depends on the
     * <code>throwExceptionIfFails</code> parameter. If it is <code>true</code>, this method will
     * throw an <code>Exception</code> describing the mismatch. Otherwise this method will call
     * <code>Assert.fail</code> with detailed description of the mismatch.
     */
Checks whether all the pixels in the specified drawable are of the same specified color.
In case there is a color mismatch, the behavior of this method depends on the
throwExceptionIfFails parameter. If it is true, this method will
throw an Exception describing the mismatch. Otherwise this method will call
Assert.fail with detailed description of the mismatch.
Checks whether all the pixels in the specified drawable are of the same specified color . In case there is a color mismatch the behavior of this method depends on the throwExceptionIfFails parameter . If it is true this method will throw an Exception describing the mismatch . Otherwise this method will call Assert . fail with detailed description of the mismatch .
public static void assertAllPixelsOfColor(String failMessagePrefix, @NonNull Drawable drawable,
            int drawableWidth, int drawableHeight, @ColorInt int color,
            boolean throwExceptionIfFails) {
        Bitmap bitmap = Bitmap.createBitmap(drawableWidth, drawableHeight, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawableWidth, drawableHeight);
        drawable.draw(canvas);
        try {
            int[] rowPixels = new int[drawableWidth];
            for (int row = 0; row < drawableHeight; row++) {
                bitmap.getPixels(rowPixels, 0, drawableWidth, 0, row, drawableWidth, 1);
                for (int column = 0; column < drawableWidth; column++) {
                    if (rowPixels[column] != color) {
                        String mismatchDescription = failMessagePrefix
                                + ": expected all drawable colors to be ["
                                + Color.red(color) + "," + Color.green(color) + ","
                                + Color.blue(color)
                                + "] but at position (" + row + "," + column + ") found ["
                                + Color.red(rowPixels[column]) + ","
                                + Color.green(rowPixels[column]) + ","
                                + Color.blue(rowPixels[column]) + "]";
                        if (throwExceptionIfFails) {
                            throw new RuntimeException(mismatchDescription);
                        } else {
                            fail(mismatchDescription);
                        }
                    }
                }
            }
        } finally {
            bitmap.recycle();
        }
    }
public static void assertAllPixelsOfColor ( String failMessagePrefix , @ NonNull Drawable drawable , int drawableWidth , int drawableHeight , @ ColorInt int color , boolean throwExceptionIfFails ) { Bitmap bitmap = Bitmap . createBitmap ( drawableWidth , drawableHeight , Bitmap . Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( bitmap ) ; drawable . setBounds ( 0 , 0 , drawableWidth , drawableHeight ) ; drawable . draw ( canvas ) ; try { int [ ] rowPixels = new int [ drawableWidth ] ; for ( int row = 0 ; row < drawableHeight ; row ++ ) { bitmap . getPixels ( rowPixels , 0 , drawableWidth , 0 , row , drawableWidth , 1 ) ; for ( int column = 0 ; column < drawableWidth ; column ++ ) { if ( rowPixels [ column ] != color ) { String mismatchDescription = failMessagePrefix + ": expected all drawable colors to be [" + Color . red ( color ) + "," + Color . green ( color ) + "," + Color . blue ( color ) + "] but at position (" + row + "," + column + ") found [" + Color . red ( rowPixels [ column ] ) + "," + Color . green ( rowPixels [ column ] ) + "," + Color . blue ( rowPixels [ column ] ) + "]" ; if ( throwExceptionIfFails ) { throw new RuntimeException ( mismatchDescription ) ; } else { fail ( mismatchDescription ) ; } } } } } finally { bitmap . recycle ( ) ; } }
Checks whether all the pixels in the specified drawable are of the same specified color.
Checks whether all the pixels in the specified drawable are of the same specified color .
// Create a bitmap // Create a canvas that wraps the bitmap // Configure the drawable to have bounds that match its intrinsic size // And ask the drawable to draw itself to the canvas / bitmap