Search in sources :

Example 86 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawingToCanvas.

@Test
public void shouldReceiveDescriptionWhenDrawingToCanvas() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    canvas.drawBitmap(bitmap2, 0, 0, null);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\nBitmap Two");
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Test(org.junit.Test)

Example 87 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowCanvasTest method shouldDescribeBitmapDrawing_withDestinationRect.

@Test
public void shouldDescribeBitmapDrawing_withDestinationRect() throws Exception {
    Canvas canvas = new Canvas(targetBitmap);
    canvas.drawBitmap(imageBitmap, new Rect(1, 2, 3, 4), new Rect(5, 6, 7, 8), new Paint());
    assertEquals("Bitmap for file:/an/image.jpg at (5,6) with height=2 and width=2 taken from Rect(1, 2 - 3, 4)", shadowOf(canvas).getDescription());
}
Also used : Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 88 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowCanvasTest method drawArc_shouldRecordArcHistoryEvents.

@Test
public void drawArc_shouldRecordArcHistoryEvents() throws Exception {
    Canvas canvas = new Canvas();
    RectF oval0 = new RectF();
    RectF oval1 = new RectF();
    Paint paint0 = new Paint();
    Paint paint1 = new Paint();
    canvas.drawArc(oval0, 1f, 2f, true, paint0);
    canvas.drawArc(oval1, 3f, 4f, false, paint1);
    ShadowCanvas shadowCanvas = shadowOf(canvas);
    assertThat(shadowCanvas.getDrawnArc(0).oval).isEqualTo(oval0);
    assertThat(shadowCanvas.getDrawnArc(0).startAngle).isEqualTo(1f);
    assertThat(shadowCanvas.getDrawnArc(0).sweepAngle).isEqualTo(2f);
    assertThat(shadowCanvas.getDrawnArc(0).useCenter).isTrue();
    assertThat(shadowCanvas.getDrawnArc(0).paint).isSameAs(paint0);
    assertThat(shadowCanvas.getDrawnArc(1).oval).isEqualTo(oval1);
    assertThat(shadowCanvas.getDrawnArc(1).startAngle).isEqualTo(3f);
    assertThat(shadowCanvas.getDrawnArc(1).sweepAngle).isEqualTo(4f);
    assertThat(shadowCanvas.getDrawnArc(1).useCenter).isFalse();
    assertThat(shadowCanvas.getDrawnArc(1).paint).isSameAs(paint1);
}
Also used : RectF(android.graphics.RectF) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 89 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowBitmapTest method shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect.

@Test
public void shouldReceiveDescriptionWhenDrawABitmapToCanvasWithAPaintEffect() throws Exception {
    Bitmap bitmap1 = create("Bitmap One", 100, 100);
    Bitmap bitmap2 = create("Bitmap Two", 100, 100);
    Canvas canvas = new Canvas(bitmap1);
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix()));
    canvas.drawBitmap(bitmap2, new Matrix(), paint);
    assertThat(shadowOf(bitmap1).getDescription()).isEqualTo("Bitmap One\n" + "Bitmap Two with ColorMatrixColorFilter<1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0>" + " transformed by Matrix[pre=[], set={}, post=[]]");
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Bitmap(android.graphics.Bitmap) ColorMatrix(android.graphics.ColorMatrix) Matrix(android.graphics.Matrix) Canvas(android.graphics.Canvas) ColorMatrix(android.graphics.ColorMatrix) Paint(android.graphics.Paint) Test(org.junit.Test)

Example 90 with Canvas

use of android.graphics.Canvas in project robolectric by robolectric.

the class ShadowCanvasTest method drawOval_shouldRecordOvalHistoryEvents.

@Test
public void drawOval_shouldRecordOvalHistoryEvents() throws Exception {
    Canvas canvas = new Canvas();
    RectF oval0 = new RectF();
    RectF oval1 = new RectF();
    Paint paint0 = new Paint();
    paint0.setColor(Color.RED);
    Paint paint1 = new Paint();
    paint1.setColor(Color.WHITE);
    canvas.drawOval(oval0, paint0);
    canvas.drawOval(oval1, paint1);
    ShadowCanvas shadowCanvas = shadowOf(canvas);
    assertThat(shadowCanvas.getDrawnOval(0).oval).isEqualTo(oval0);
    assertThat(shadowCanvas.getDrawnOval(0).paint.getColor()).isEqualTo(Color.RED);
    assertThat(shadowCanvas.getDrawnOval(1).oval).isEqualTo(oval1);
    assertThat(shadowCanvas.getDrawnOval(1).paint.getColor()).isEqualTo(Color.WHITE);
}
Also used : RectF(android.graphics.RectF) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Test(org.junit.Test)

Aggregations

Canvas (android.graphics.Canvas)1237 Bitmap (android.graphics.Bitmap)890 Paint (android.graphics.Paint)609 Rect (android.graphics.Rect)257 BitmapDrawable (android.graphics.drawable.BitmapDrawable)192 RectF (android.graphics.RectF)136 PorterDuffXfermode (android.graphics.PorterDuffXfermode)103 Matrix (android.graphics.Matrix)80 Point (android.graphics.Point)76 Drawable (android.graphics.drawable.Drawable)68 BitmapShader (android.graphics.BitmapShader)60 Test (org.junit.Test)46 IOException (java.io.IOException)43 FileOutputStream (java.io.FileOutputStream)40 View (android.view.View)39 Path (android.graphics.Path)38 File (java.io.File)37 SuppressLint (android.annotation.SuppressLint)36 ColorMatrix (android.graphics.ColorMatrix)36 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)33