Search in sources :

Example 61 with Implementation

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

the class ShadowResources method loadDrawable.

@HiddenApi
@Implementation
public Drawable loadDrawable(TypedValue value, int id) {
    Drawable drawable = directlyOn(realResources, Resources.class, "loadDrawable", ClassParameter.from(TypedValue.class, value), ClassParameter.from(int.class, id));
    setCreatedFromResId(realResources, id, drawable);
    return drawable;
}
Also used : Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TypedValue(android.util.TypedValue) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 62 with Implementation

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

the class ShadowDefaultRequestDirector method execute.

@Implementation
public HttpResponse execute(HttpHost httpHost, HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
    if (FakeHttp.getFakeHttpLayer().isInterceptingHttpRequests()) {
        return FakeHttp.getFakeHttpLayer().emulateRequest(httpHost, httpRequest, httpContext, realObject);
    } else {
        FakeHttp.getFakeHttpLayer().addRequestInfo(new HttpRequestInfo(httpRequest, httpHost, httpContext, redirector));
        HttpResponse response = redirector.execute(httpHost, httpRequest, httpContext);
        if (FakeHttp.getFakeHttpLayer().isInterceptingResponseContent()) {
            interceptResponseContent(response);
        }
        FakeHttp.getFakeHttpLayer().addHttpResponse(response);
        return response;
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) Implementation(org.robolectric.annotation.Implementation)

Example 63 with Implementation

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

the class ShadowMessageQueue method enqueueMessage.

@Implementation
public boolean enqueueMessage(final Message msg, long when) {
    final boolean retval = directlyOn(realQueue, MessageQueue.class, "enqueueMessage", from(Message.class, msg), from(long.class, when));
    if (retval) {
        final Runnable callback = new Runnable() {

            @Override
            public void run() {
                synchronized (realQueue) {
                    Message m = getHead();
                    if (m == null) {
                        return;
                    }
                    Message n = shadowOf(m).getNext();
                    if (m == msg) {
                        setHead(n);
                        dispatchMessage(msg);
                        return;
                    }
                    while (n != null) {
                        if (n == msg) {
                            n = shadowOf(n).getNext();
                            shadowOf(m).setNext(n);
                            dispatchMessage(msg);
                            return;
                        }
                        m = n;
                        n = shadowOf(m).getNext();
                    }
                }
            }
        };
        shadowOf(msg).setScheduledRunnable(callback);
        if (when == 0) {
            scheduler.postAtFrontOfQueue(callback);
        } else {
            scheduler.postDelayed(callback, when - scheduler.getCurrentTime());
        }
    }
    return retval;
}
Also used : Message(android.os.Message) Implementation(org.robolectric.annotation.Implementation)

Example 64 with Implementation

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

the class ShadowMotionEvent method obtain.

@Implementation
public static MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, int metaState) {
    try {
        Constructor<MotionEvent> constructor = MotionEvent.class.getDeclaredConstructor();
        constructor.setAccessible(true);
        MotionEvent motionEvent = constructor.newInstance();
        ShadowMotionEvent shadowMotionEvent = Shadows.shadowOf(motionEvent);
        shadowMotionEvent.x[0] = x;
        shadowMotionEvent.y[0] = y;
        shadowMotionEvent.action = action;
        shadowMotionEvent.downTime = downTime;
        shadowMotionEvent.eventTime = eventTime;
        return motionEvent;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : MotionEvent(android.view.MotionEvent) Implementation(org.robolectric.annotation.Implementation)

Example 65 with Implementation

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

the class ShadowNotificationManager method getActiveNotifications.

@Implementation(minSdk = Build.VERSION_CODES.M)
public StatusBarNotification[] getActiveNotifications() {
    StatusBarNotification[] statusBarNotifications = new StatusBarNotification[notifications.size()];
    int i = 0;
    for (Map.Entry<Key, Notification> entry : notifications.entrySet()) {
        statusBarNotifications[i++] = new StatusBarNotification(RuntimeEnvironment.application.getPackageName(), null, /* opPkg */
        entry.getKey().id, entry.getKey().tag, android.os.Process.myUid(), /* uid */
        android.os.Process.myPid(), /* initialPid */
        0, /* score */
        entry.getValue(), android.os.Process.myUserHandle(), 0);
    }
    return statusBarNotifications;
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) Map(java.util.Map) HashMap(java.util.HashMap) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) 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