@Implementation public static Drawable createFromPath(String pathName) { BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class)); shadowOf(drawable).drawableCreateFromPath = pathName; shadowOf(drawable).validate(); // start off not invalidated return drawable; }
public static Drawable createFromResourceId(int resourceId) { Bitmap bitmap = ReflectionHelpers.callConstructor(Bitmap.class); shadowOf(bitmap).createdFromResId = resourceId; BitmapDrawable drawable = new BitmapDrawable(bitmap); shadowOf(drawable).validate(); // start off not invalidated shadowOf(drawable).createdFromResId = resourceId; return drawable; }
@Implementation public static Drawable createFromStream(InputStream is, String srcName) { if (corruptStreamSources.contains(srcName)) { return null; } BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class)); shadowOf(drawable).createdFromInputStream = is; shadowOf(drawable).drawableCreateFromStreamSource = srcName; shadowOf(drawable).validate(); // start off not invalidated return drawable; }
@Implementation public static AccessibilityEvent obtain(int eventType) { // We explicitly avoid allocating the AccessibilityEvent from the actual pool by using // the private constructor. Not doing so affects test suites which use both shadow and // non-shadow objects. final AccessibilityEvent obtainedInstance = ReflectionHelpers.callConstructor(AccessibilityEvent.class); final ShadowAccessibilityEvent shadowObtained = ((ShadowAccessibilityEvent) ShadowExtractor.extract(obtainedInstance)); sAllocationCount++; StrictEqualityEventWrapper wrapper = new StrictEqualityEventWrapper(obtainedInstance); obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace()); orderedInstances.put(sAllocationCount, wrapper); shadowObtained.eventType = eventType; return obtainedInstance; }
/** @return A shallow copy. */ private AccessibilityEvent getClone() { // We explicitly avoid allocating the AccessibilityEvent from the actual pool by using // the private constructor. Not doing so affects test suites which use both shadow and // non-shadow objects. final AccessibilityEvent newEvent = ReflectionHelpers.callConstructor(AccessibilityEvent.class); final ShadowAccessibilityEvent newShadow = (ShadowAccessibilityEvent) ShadowExtractor.extract(newEvent); newShadow.eventType = eventType; newShadow.contentDescription = contentDescription; newShadow.packageName = packageName; newShadow.className = className; newShadow.enabled = enabled; newShadow.setParcelableData(getParcelableData()); return newEvent; }
@Implementation public Bitmap getDrawingCache() { return ReflectionHelpers.callConstructor(Bitmap.class); }
private static Looper newLooper(boolean canQuit) { return ReflectionHelpers.callConstructor(Looper.class, from(boolean.class, canQuit)); }