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