use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowAccessibilityNodeInfo method obtain.
@Implementation
public static AccessibilityNodeInfo obtain(View view) {
// We explicitly avoid allocating the AccessibilityNodeInfo from the actual pool by using the
// private constructor. Not doing so affects test suites which use both shadow and
// non-shadow objects.
final AccessibilityNodeInfo obtainedInstance = ReflectionHelpers.callConstructor(AccessibilityNodeInfo.class);
final ShadowAccessibilityNodeInfo shadowObtained = ((ShadowAccessibilityNodeInfo) ShadowExtractor.extract(obtainedInstance));
/*
* We keep a separate list of actions for each object newly obtained
* from a view, and perform a shallow copy during getClone. That way the
* list of actions performed contains all actions performed on the view
* by the tree of nodes initialized from it. Note that initializing two
* nodes with the same view will not merge the two lists, as so the list
* of performed actions will not contain all actions performed on the
* underlying view.
*/
shadowObtained.performedActionAndArgsList = new LinkedList<>();
shadowObtained.view = view;
sAllocationCount++;
StrictEqualityNodeWrapper wrapper = new StrictEqualityNodeWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
orderedInstances.put(sAllocationCount, wrapper);
return obtainedInstance;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowAccessibilityWindowInfo method obtain.
@Implementation
public static AccessibilityWindowInfo obtain(AccessibilityWindowInfo window) {
final ShadowAccessibilityWindowInfo shadowInfo = ((ShadowAccessibilityWindowInfo) ShadowExtractor.extract(window));
final AccessibilityWindowInfo obtainedInstance = shadowInfo.getClone();
StrictEqualityWindowWrapper wrapper = new StrictEqualityWindowWrapper(obtainedInstance);
obtainedInstances.put(wrapper, Thread.currentThread().getStackTrace());
return obtainedInstance;
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowActivity method dismissDialog.
@Implementation
public final void dismissDialog(int id) {
final Dialog dialog = dialogForId.get(id);
if (dialog == null) {
throw new IllegalArgumentException();
}
dialog.dismiss();
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowActivity method setDefaultKeyMode.
@Implementation
public void setDefaultKeyMode(int keyMode) {
mDefaultKeyMode = keyMode;
// This list must remain in sync with the switch in onKeyDown()
switch(mDefaultKeyMode) {
case Activity.DEFAULT_KEYS_DISABLE:
case Activity.DEFAULT_KEYS_SHORTCUT:
// not used in these modes
mDefaultKeySsb = null;
break;
case Activity.DEFAULT_KEYS_DIALER:
case Activity.DEFAULT_KEYS_SEARCH_LOCAL:
case Activity.DEFAULT_KEYS_SEARCH_GLOBAL:
mDefaultKeySsb = new SpannableStringBuilder();
Selection.setSelection(mDefaultKeySsb, 0);
break;
default:
throw new IllegalArgumentException();
}
}
use of org.robolectric.annotation.Implementation in project robolectric by robolectric.
the class ShadowBitmap method createBitmap.
@Implementation
public static Bitmap createBitmap(DisplayMetrics displayMetrics, int width, int height, Bitmap.Config config) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("width and height must be > 0");
}
Bitmap scaledBitmap = ReflectionHelpers.callConstructor(Bitmap.class);
ShadowBitmap shadowBitmap = shadowOf(scaledBitmap);
shadowBitmap.setDescription("Bitmap (" + width + " x " + height + ")");
shadowBitmap.width = width;
shadowBitmap.height = height;
shadowBitmap.config = config;
shadowBitmap.setMutable(true);
if (displayMetrics != null) {
shadowBitmap.density = displayMetrics.densityDpi;
}
shadowBitmap.setPixels(new int[shadowBitmap.getHeight() * shadowBitmap.getWidth()], 0, shadowBitmap.getWidth(), 0, 0, shadowBitmap.getWidth(), shadowBitmap.getHeight());
return scaledBitmap;
}
Aggregations