Ejemplo n.º 1
0
 @Implementation
 public static Camera open(int cameraId) {
   lastOpenedCameraId = cameraId;
   Camera camera = Robolectric.newInstanceOf(Camera.class);
   Robolectric.shadowOf(camera).id = cameraId;
   return camera;
 }
Ejemplo n.º 2
0
 public static void setSystemResources(ResourceLoader systemResourceLoader) {
   AssetManager assetManager = Robolectric.newInstanceOf(AssetManager.class);
   DisplayMetrics metrics = new DisplayMetrics();
   Configuration config = new Configuration();
   system =
       ShadowResources.bind(new Resources(assetManager, metrics, config), systemResourceLoader);
 }
Ejemplo n.º 3
0
 @Implementation
 public Camera.Parameters getParameters() {
   if (null == parameters) {
     parameters = Robolectric.newInstanceOf(Camera.Parameters.class);
   }
   return parameters;
 }
Ejemplo n.º 4
0
 @Implementation
 public static CookieManager getInstance() {
   if (sRef == null) {
     sRef = Robolectric.newInstanceOf(CookieManager.class);
   }
   return sRef;
 }
Ejemplo n.º 5
0
 @Implementation
 public Camera.Size getPreviewSize() {
   Camera.Size previewSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0);
   previewSize.width = previewWidth;
   previewSize.height = previewHeight;
   return previewSize;
 }
Ejemplo n.º 6
0
 @Implementation
 public Camera.Size getPictureSize() {
   Camera.Size pictureSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0);
   pictureSize.width = pictureWidth;
   pictureSize.height = pictureHeight;
   return pictureSize;
 }
Ejemplo n.º 7
0
 @Implementation
 public Bitmap copy(Bitmap.Config config, boolean isMutable) {
   Bitmap newBitmap = Robolectric.newInstanceOf(Bitmap.class);
   ShadowBitmap shadowBitmap = shadowOf(newBitmap);
   shadowBitmap.createdFromBitmap = realBitmap;
   shadowBitmap.config = config;
   shadowBitmap.mutable = isMutable;
   return newBitmap;
 }
Ejemplo n.º 8
0
  @Implementation
  public DisplayMetrics getDisplayMetrics() {
    if (displayMetrics == null) {
      if (display == null) {
        display = Robolectric.newInstanceOf(Display.class);
      }

      displayMetrics = new DisplayMetrics();
      display.getMetrics(displayMetrics);
    }
    displayMetrics.density = this.density;
    return displayMetrics;
  }
Ejemplo n.º 9
0
  @Implementation
  public static Bitmap createBitmap(int width, int height, Bitmap.Config config) {
    if (width <= 0 || height <= 0) {
      throw new IllegalArgumentException("width and height must be > 0");
    }
    Bitmap scaledBitmap = Robolectric.newInstanceOf(Bitmap.class);
    ShadowBitmap shadowBitmap = shadowOf(scaledBitmap);

    shadowBitmap.setDescription("Bitmap (" + width + " x " + height + ")");

    shadowBitmap.width = width;
    shadowBitmap.height = height;
    shadowBitmap.config = config;
    return scaledBitmap;
  }
Ejemplo n.º 10
0
  @Implementation
  public static Bitmap createBitmap(
      Bitmap src, int x, int y, int width, int height, Matrix matrix, boolean filter) {
    if (x == 0
        && y == 0
        && width == src.getWidth()
        && height == src.getHeight()
        && (matrix == null || matrix.isIdentity())) {
      return src; // Return the original.
    }

    if (x + width > src.getWidth()) {
      throw new IllegalArgumentException("x + width must be <= bitmap.width()");
    }
    if (y + height > src.getHeight()) {
      throw new IllegalArgumentException("y + height must be <= bitmap.height()");
    }

    Bitmap newBitmap = Robolectric.newInstanceOf(Bitmap.class);
    ShadowBitmap shadowBitmap = shadowOf(newBitmap);

    shadowBitmap.appendDescription(shadowOf(src).getDescription());
    shadowBitmap.appendDescription(" at (" + x + "," + y);
    shadowBitmap.appendDescription(" with width " + width + " and height " + height);
    if (matrix != null) {
      shadowBitmap.appendDescription(" using matrix " + matrix);
    }
    if (filter) {
      shadowBitmap.appendDescription(" with filter");
    }

    shadowBitmap.createdFromBitmap = src;
    shadowBitmap.createdFromX = x;
    shadowBitmap.createdFromY = y;
    shadowBitmap.createdFromWidth = width;
    shadowBitmap.createdFromHeight = height;
    shadowBitmap.createdFromMatrix = matrix;
    shadowBitmap.createdFromFilter = filter;
    shadowBitmap.width = width;
    shadowBitmap.height = height;
    return newBitmap;
  }
Ejemplo n.º 11
0
  @Implementation
  public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) {
    if (dstWidth == src.getWidth() && dstHeight == src.getHeight() && !filter) {
      return src; // Return the original.
    }

    Bitmap scaledBitmap = Robolectric.newInstanceOf(Bitmap.class);
    ShadowBitmap shadowBitmap = shadowOf(scaledBitmap);

    shadowBitmap.appendDescription(shadowOf(src).getDescription());
    shadowBitmap.appendDescription(" scaled to " + dstWidth + " x " + dstHeight);
    if (filter) {
      shadowBitmap.appendDescription(" with filter " + filter);
    }

    shadowBitmap.createdFromBitmap = src;
    shadowBitmap.createdFromFilter = filter;
    shadowBitmap.width = dstWidth;
    shadowBitmap.height = dstHeight;
    return scaledBitmap;
  }
Ejemplo n.º 12
0
  @Test
  public void startAndStopManagingCursorTracksCursors() throws Exception {
    TestActivity activity = new TestActivity();

    ShadowActivity shadow = shadowOf(activity);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(0);

    Cursor c = Robolectric.newInstanceOf(SQLiteCursor.class);
    activity.startManagingCursor(c);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(1);
    assertThat(shadow.getManagedCursors().get(0)).isSameAs(c);

    activity.stopManagingCursor(c);

    assertThat(shadow.getManagedCursors()).isNotNull();
    assertThat(shadow.getManagedCursors().size()).isEqualTo(0);
  }
Ejemplo n.º 13
0
  @Implementation
  public static Bitmap createBitmap(Bitmap src, int x, int y, int width, int height) {
    if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight()) {
      return src; // Return the original.
    }

    Bitmap newBitmap = Robolectric.newInstanceOf(Bitmap.class);
    ShadowBitmap shadowBitmap = shadowOf(newBitmap);

    shadowBitmap.appendDescription(shadowOf(src).getDescription());
    shadowBitmap.appendDescription(" at (" + x + "," + y);
    shadowBitmap.appendDescription(" with width " + width + " and height " + height);

    shadowBitmap.createdFromBitmap = src;
    shadowBitmap.createdFromX = x;
    shadowBitmap.createdFromY = y;
    shadowBitmap.createdFromWidth = width;
    shadowBitmap.createdFromHeight = height;
    shadowBitmap.width = width;
    shadowBitmap.height = height;
    return newBitmap;
  }
Ejemplo n.º 14
0
 @Implementation
 public PowerManager.WakeLock newWakeLock(int flags, String tag) {
   PowerManager.WakeLock wl = Robolectric.newInstanceOf(PowerManager.WakeLock.class);
   Robolectric.getShadowApplication().addWakeLock(wl);
   return wl;
 }
Ejemplo n.º 15
0
 @Test
 public void getDetailedState_shouldReturnTheAssignedState() throws Exception {
   NetworkInfo networkInfo = Robolectric.newInstanceOf(NetworkInfo.class);
   shadowOf(networkInfo).setDetailedState(NetworkInfo.DetailedState.SCANNING);
   assertThat(networkInfo.getDetailedState(), equalTo(NetworkInfo.DetailedState.SCANNING));
 }
Ejemplo n.º 16
0
 private void addSize(List<Camera.Size> sizes, int width, int height) {
   Camera.Size newSize = Robolectric.newInstanceOf(Camera.class).new Size(0, 0);
   newSize.width = width;
   newSize.height = height;
   sizes.add(newSize);
 }
Ejemplo n.º 17
0
 @Implementation
 public Bitmap getDrawingCache() {
   return Robolectric.newInstanceOf(Bitmap.class);
 }