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;
}
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;
}
}
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;
}
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);
}
}
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;
}
Aggregations