Search in sources :

Example 86 with Implementation

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

the class ShadowActivityThread method getPackageManager.

@Implementation
public static Object getPackageManager() {
    ClassLoader classLoader = ShadowActivityThread.class.getClassLoader();
    Class<?> iPackageManagerClass;
    try {
        iPackageManagerClass = classLoader.loadClass("android.content.pm.IPackageManager");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return Proxy.newProxyInstance(classLoader, new Class[] { iPackageManagerClass }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, @NotNull Method method, Object[] args) throws Exception {
            if (method.getName().equals("getApplicationInfo")) {
                String packageName = (String) args[0];
                int flags = (Integer) args[1];
                try {
                    return RuntimeEnvironment.application.getPackageManager().getApplicationInfo(packageName, flags);
                } catch (PackageManager.NameNotFoundException e) {
                    return null;
                }
            } else if (method.getName().equals("notifyPackageUse")) {
                return null;
            }
            throw new UnsupportedOperationException("sorry, not supporting " + method + " yet!");
        }
    });
}
Also used : Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Implementation(org.robolectric.annotation.Implementation)

Example 87 with Implementation

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

the class ShadowAppWidgetHost method createView.

@Implementation
public AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
    AppWidgetHostView hostView = new AppWidgetHostView(context);
    hostView.setAppWidget(appWidgetId, appWidget);
    Shadows.shadowOf(hostView).setHost(realAppWidgetHost);
    return hostView;
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Implementation(org.robolectric.annotation.Implementation)

Example 88 with Implementation

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

the class ShadowApplication method sendOrderedBroadcast.

@Implementation
public void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) {
    List<Wrapper> receivers = getAppropriateWrappers(intent, receiverPermission);
    sortByPriority(receivers);
    receivers.add(new Wrapper(resultReceiver, null, this.realApplication, null, scheduler));
    postOrderedToWrappers(receivers, intent, initialCode, initialData, initialExtras);
}
Also used : ContextWrapper(android.content.ContextWrapper) Implementation(org.robolectric.annotation.Implementation)

Example 89 with Implementation

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

the class ShadowApplication method unregisterReceiver.

@Implementation
public void unregisterReceiver(BroadcastReceiver broadcastReceiver) {
    boolean found = false;
    Iterator<Wrapper> iterator = registeredReceivers.iterator();
    while (iterator.hasNext()) {
        Wrapper wrapper = iterator.next();
        if (wrapper.broadcastReceiver == broadcastReceiver) {
            iterator.remove();
            found = true;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("Receiver not registered: " + broadcastReceiver);
    }
}
Also used : ContextWrapper(android.content.ContextWrapper) Implementation(org.robolectric.annotation.Implementation)

Example 90 with Implementation

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

the class ShadowLocaleData method get.

@Implementation
public static LocaleData get(Locale locale) {
    LocaleData localeData = (LocaleData) Shadow.newInstanceOf(REAL_CLASS_NAME);
    if (locale == null) {
        locale = Locale.getDefault();
    }
    setEnUsLocaleData(localeData);
    return localeData;
}
Also used : LocaleData(libcore.icu.LocaleData) 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