Search in sources :

Example 91 with Implementation

use of org.robolectric.annotation.Implementation in project robolectric by robolectric.

the class ShadowBitmap method createBitmap.

@Implementation
public static Bitmap createBitmap(int[] colors, int width, int height, Bitmap.Config config) {
    if (colors.length != width * height) {
        throw new IllegalArgumentException("array length (" + colors.length + ") did not match width * height (" + (width * height) + ")");
    }
    Bitmap newBitmap = Bitmap.createBitmap(width, height, config);
    ShadowBitmap shadowBitmap = shadowOf(newBitmap);
    shadowBitmap.setMutable(false);
    shadowBitmap.createdFromColors = colors;
    shadowBitmap.colors = new int[colors.length];
    System.arraycopy(colors, 0, shadowBitmap.colors, 0, colors.length);
    return newBitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 92 with Implementation

use of org.robolectric.annotation.Implementation in project robolectric by robolectric.

the class ShadowBitmapFactory method decodeFileDescriptor.

@Implementation
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) {
    Bitmap bitmap = create("fd:" + fd, opts);
    ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap);
    shadowBitmap.createdFromFileDescriptor = fd;
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 93 with Implementation

use of org.robolectric.annotation.Implementation in project robolectric by robolectric.

the class ShadowBitmapFactory method decodeFile.

@Implementation
public static Bitmap decodeFile(String pathName, BitmapFactory.Options options) {
    Bitmap bitmap = create("file:" + pathName, options);
    ShadowBitmap shadowBitmap = Shadows.shadowOf(bitmap);
    shadowBitmap.createdFromPath = pathName;
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 94 with Implementation

use of org.robolectric.annotation.Implementation in project robolectric by robolectric.

the class ShadowBitmapFactory method decodeResource.

@Implementation
public static Bitmap decodeResource(Resources res, int id, BitmapFactory.Options options) {
    if (id == 0) {
        return null;
    }
    Bitmap bitmap = create("resource:" + RuntimeEnvironment.application.getResources().getResourceName(id), options);
    Shadows.shadowOf(bitmap).createdFromResId = id;
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Implementation(org.robolectric.annotation.Implementation)

Example 95 with Implementation

use of org.robolectric.annotation.Implementation in project robolectric by robolectric.

the class ShadowLocalBroadcastManager method sendBroadcast.

@Implementation
public boolean sendBroadcast(Intent intent) {
    boolean sent = false;
    sentBroadcastIntents.add(intent);
    List<Wrapper> copy = new ArrayList<>();
    copy.addAll(registeredReceivers);
    for (Wrapper wrapper : copy) {
        if (wrapper.intentFilter.matchAction(intent.getAction())) {
            final int match = wrapper.intentFilter.matchData(intent.getType(), intent.getScheme(), intent.getData());
            if (match != IntentFilter.NO_MATCH_DATA && match != IntentFilter.NO_MATCH_TYPE) {
                sent = true;
                final BroadcastReceiver receiver = wrapper.broadcastReceiver;
                final Intent broadcastIntent = intent;
                Robolectric.getForegroundThreadScheduler().post(new Runnable() {

                    @Override
                    public void run() {
                        receiver.onReceive(RuntimeEnvironment.application, broadcastIntent);
                    }
                });
            }
        }
    }
    return sent;
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Implementation (org.robolectric.annotation.Implementation)114 Bitmap (android.graphics.Bitmap)17 HiddenApi (org.robolectric.annotation.HiddenApi)10 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 View (android.view.View)6 IOException (java.io.IOException)6 ContentProvider (android.content.ContentProvider)5 IContentProvider (android.content.IContentProvider)5 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)5 Rect (android.graphics.Rect)4 Message (android.os.Message)4 RealObject (org.robolectric.annotation.RealObject)4 FileTypedResource (org.robolectric.res.FileTypedResource)4 Point (android.graphics.Point)3 AccessibilityWindowInfo (android.view.accessibility.AccessibilityWindowInfo)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 LinkedList (java.util.LinkedList)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2