Search in sources :

Example 31 with Implementation

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;
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Implementation(org.robolectric.annotation.Implementation)

Example 32 with Implementation

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;
}
Also used : AccessibilityWindowInfo(android.view.accessibility.AccessibilityWindowInfo) Implementation(org.robolectric.annotation.Implementation)

Example 33 with Implementation

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();
}
Also used : Dialog(android.app.Dialog) Implementation(org.robolectric.annotation.Implementation)

Example 34 with Implementation

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();
    }
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) Implementation(org.robolectric.annotation.Implementation)

Example 35 with Implementation

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;
}
Also used : Bitmap(android.graphics.Bitmap) 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