Tabnine Logo
ShadowCanvas
Code IndexAdd Tabnine to your IDE (free)

How to use
ShadowCanvas
in
org.robolectric.shadows

Best Java code snippets using org.robolectric.shadows.ShadowCanvas (Showing top 20 results out of 315)

origin: robolectric/robolectric

/**
 * Returns a textual representation of the appearance of the object.
 *
 * @param canvas the canvas to visualize
 * @return The textual representation of the appearance of the object.
 */
public static String visualize(Canvas canvas) {
 ShadowCanvas shadowCanvas = Shadow.extract(canvas);
 return shadowCanvas.getDescription();
}
origin: robolectric/robolectric

@Test
public void resetCanvasHistory_shouldClearTheHistoryAndDescription() throws Exception {
 Canvas canvas = new Canvas();
 canvas.drawPath(new Path(), new Paint());
 canvas.drawText("hi", 1, 2, new Paint());
 ShadowCanvas shadow = shadowOf(canvas);
 shadow.resetCanvasHistory();
 assertThat(shadow.getPathPaintHistoryCount()).isEqualTo(0);
 assertThat(shadow.getTextHistoryCount()).isEqualTo(0);
 assertEquals("", shadow.getDescription());
}
origin: robolectric/robolectric

@Implementation
protected void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
 describeBitmap(bitmap, paint);
 int x = (int) (left + translateX);
 int y = (int) (top + translateY);
 if (x != 0 || y != 0) {
  appendDescription(" at (" + x + "," + y + ")");
}
 if (scaleX != 1 && scaleY != 1) {
  appendDescription(" scaled by (" + scaleX + "," + scaleY + ")");
 }
}
origin: robolectric/robolectric

private void separateLines() {
 if (getDescription().length() != 0) {
  appendDescription("\n");
 }
}
origin: robolectric/robolectric

@Implementation
protected void drawPath(Path path, Paint paint) {
 pathPaintEvents.add(new PathPaintHistoryEvent(new Path(path), new Paint(paint)));
 separateLines();
 ShadowPath shadowPath = Shadow.extract(path);
 appendDescription("Path " + shadowPath.getPoints().toString());
}
origin: robolectric/robolectric

private void describeBitmap(Bitmap bitmap, Paint paint) {
 separateLines();
 ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
 appendDescription(shadowBitmap.getDescription());
 if (paint != null) {
  ColorFilter colorFilter = paint.getColorFilter();
  if (colorFilter != null) {
   if (colorFilter instanceof ColorMatrixColorFilter) {
    ColorMatrixColorFilter colorMatrixColorFilter = (ColorMatrixColorFilter) colorFilter;
    ShadowColorMatrixColorFilter shadowColorMatrixColorFilter =
      Shadow.extract(colorMatrixColorFilter);
    ColorMatrix colorMatrix = shadowColorMatrixColorFilter.getMatrix();
    appendDescription(" with ColorMatrixColorFilter<" + formatColorMatric(colorMatrix) + ">");
   } else {
    appendDescription(" with " + colorFilter);
   }
  }
 }
}
origin: robolectric/robolectric

@Implementation
protected void drawColor(int color) {
 appendDescription("draw color " + color);
}
origin: robolectric/robolectric

public boolean hasDrawnPath() {
 return getPathPaintHistoryCount() > 0;
}
origin: robolectric/robolectric

@Test
public void drawPath_shouldRecordThePathAndThePaint() throws Exception {
 Canvas canvas = new Canvas(targetBitmap);
 Path path = new Path();
 path.lineTo(10, 10);
 Paint paint = new Paint();
 paint.setColor(Color.RED);
 paint.setAlpha(7);
 canvas.drawPath(path, paint);
 // changing the values on this Paint shouldn't affect recorded painted path
 paint.setColor(Color.BLUE);
 paint.setAlpha(8);
 ShadowCanvas shadow = shadowOf(canvas);
 assertThat(shadow.getPathPaintHistoryCount()).isEqualTo(1);
 ShadowPath drawnPath = shadowOf(shadow.getDrawnPath(0));
 assertEquals(drawnPath.getPoints().get(0), new ShadowPath.Point(10, 10, LINE_TO));
 Paint drawnPathPaint = shadow.getDrawnPathPaint(0);
 assertThat(drawnPathPaint.getColor()).isEqualTo(Color.RED);
 assertThat(drawnPathPaint.getAlpha()).isEqualTo(7);
}
origin: robolectric/robolectric

@Test
public void drawPath_shouldRecordThePointsOfEachPathEvenWhenItIsTheSameInstance() throws Exception {
 Canvas canvas = new Canvas(targetBitmap);
 Paint paint = new Paint();
 Path path = new Path();
 path.lineTo(10, 10);
 canvas.drawPath(path, paint);
 path.reset();
 path.lineTo(20, 20);
 canvas.drawPath(path, paint);
 ShadowCanvas shadow = shadowOf(canvas);
 assertThat(shadow.getPathPaintHistoryCount()).isEqualTo(2);
 assertEquals(shadowOf(shadow.getDrawnPath(0)).getPoints().get(0), new ShadowPath.Point(10, 10, LINE_TO));
 assertEquals(shadowOf(shadow.getDrawnPath(1)).getPoints().get(0), new ShadowPath.Point(20, 20, LINE_TO));
}
origin: org.robolectric/shadows-core-v23

private void describeBitmap(Bitmap bitmap, Paint paint) {
 separateLines();
 appendDescription(shadowOf(bitmap).getDescription());
 if (paint != null) {
  ColorFilter colorFilter = paint.getColorFilter();
  if (colorFilter != null) {
   appendDescription(" with " + colorFilter);
  }
 }
}
origin: org.robolectric/shadows-core

private void separateLines() {
 if (getDescription().length() != 0) {
  appendDescription("\n");
 }
}
origin: org.robolectric/shadows-framework

private void describeBitmap(Bitmap bitmap, Paint paint) {
 separateLines();
 ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
 appendDescription(shadowBitmap.getDescription());
 if (paint != null) {
  ColorFilter colorFilter = paint.getColorFilter();
  if (colorFilter != null) {
   if (colorFilter instanceof ColorMatrixColorFilter) {
    ColorMatrixColorFilter colorMatrixColorFilter = (ColorMatrixColorFilter) colorFilter;
    ShadowColorMatrixColorFilter shadowColorMatrixColorFilter =
      Shadow.extract(colorMatrixColorFilter);
    ColorMatrix colorMatrix = shadowColorMatrixColorFilter.getMatrix();
    appendDescription(" with ColorMatrixColorFilter<" + formatColorMatric(colorMatrix) + ">");
   } else {
    appendDescription(" with " + colorFilter);
   }
  }
 }
}
origin: robolectric/robolectric

@Implementation
protected void draw(android.graphics.Canvas canvas) {
 Drawable background = realView.getBackground();
 if (background != null) {
  ShadowCanvas shadowCanvas = Shadow.extract(canvas);
  shadowCanvas.appendDescription("background:");
  background.draw(canvas);
 }
}
origin: org.robolectric/shadows-core

public boolean hasDrawnPath() {
 return getPathPaintHistoryCount() > 0;
}
origin: robolectric/robolectric

@Implementation
protected void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
 describeBitmap(bitmap, paint);
 StringBuilder descriptionBuilder = new StringBuilder();
 if (dst != null) {
  descriptionBuilder.append(" at (").append(dst.left).append(",").append(dst.top)
    .append(") with height=").append(dst.height()).append(" and width=").append(dst.width());
 }
 if (src != null) {
  descriptionBuilder.append( " taken from ").append(src.toString());
 }
 appendDescription(descriptionBuilder.toString());
}
origin: robolectric/robolectric

/**
 * Returns a textual representation of the appearance of the object.
 *
 * @param view the view to visualize
 * @return Textual representation of the appearance of the object.
 */
public static String visualize(View view) {
 Canvas canvas = new Canvas();
 view.draw(canvas);
 ShadowCanvas shadowCanvas = Shadow.extract(canvas);
 return shadowCanvas.getDescription();
}
origin: org.robolectric/framework

private void describeBitmap(Bitmap bitmap, Paint paint) {
 separateLines();
 appendDescription(shadowOf(bitmap).getDescription());
 if (paint != null) {
  ColorFilter colorFilter = paint.getColorFilter();
  if (colorFilter != null) {
   appendDescription(" with " + colorFilter);
  }
 }
}
origin: org.robolectric/shadows-core-v23

private void separateLines() {
 if (getDescription().length() != 0) {
  appendDescription("\n");
 }
}
origin: org.robolectric/shadows-core-v23

@Implementation
public void drawColor(int color) {
 appendDescription("draw color " + color);
}
org.robolectric.shadowsShadowCanvas

Javadoc

Broken. This implementation is very specific to the application for which it was developed. Todo: Reimplement. Consider using the same strategy of collecting a history of draw events and providing methods for writing queries based on type, number, and order of events.

Most used methods

  • getDescription
  • getPathPaintHistoryCount
  • appendDescription
  • describeBitmap
  • separateLines
  • formatColorMatric
  • getArcPaintHistoryCount
  • getDrawnArc
  • getDrawnCircle
  • getDrawnLine
  • getDrawnOval
  • getDrawnPath
  • getDrawnOval,
  • getDrawnPath,
  • getDrawnPathPaint,
  • getDrawnRect,
  • getDrawnTextEvent,
  • getLinePaintHistoryCount,
  • getOvalPaintHistoryCount,
  • getRectPaintHistoryCount,
  • getTextHistoryCount,
  • resetCanvasHistory

Popular in Java

  • Running tasks concurrently on multiple threads
  • findViewById (Activity)
  • getExternalFilesDir (Context)
  • getSystemService (Context)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • JTextField (javax.swing)
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now