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");
}
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());
}
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);
}
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=[]]");
}
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);
}
Aggregations