Search in sources :

Example 81 with Implementation

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

the class ShadowAssetManager method openFd.

@Implementation
public final AssetFileDescriptor openFd(String fileName) throws IOException {
    File file = new File(ShadowApplication.getInstance().getAppManifest().getAssetsDirectory().join(fileName).getPath());
    ParcelFileDescriptor parcelFileDescriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
    return new AssetFileDescriptor(parcelFileDescriptor, 0, file.length());
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) FsFile(org.robolectric.res.FsFile) Implementation(org.robolectric.annotation.Implementation)

Example 82 with Implementation

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

the class ShadowDateIntervalFormat method formatDateInterval.

@Implementation
public static String formatDateInterval(long address, long fromDate, long toDate) {
    StringBuffer buffer = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    INTERVAL_CACHE.get(address).format(new com.ibm.icu.util.DateInterval(fromDate, toDate), buffer, pos);
    return buffer.toString();
}
Also used : FieldPosition(java.text.FieldPosition) Implementation(org.robolectric.annotation.Implementation)

Example 83 with Implementation

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

the class ShadowDrawable method createFromPath.

@Implementation
public static Drawable createFromPath(String pathName) {
    BitmapDrawable drawable = new BitmapDrawable(ReflectionHelpers.callConstructor(Bitmap.class));
    shadowOf(drawable).drawableCreateFromPath = pathName;
    // start off not invalidated
    shadowOf(drawable).validate();
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Implementation(org.robolectric.annotation.Implementation)

Example 84 with Implementation

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

the class ShadowDrawable method createFromResourceStream.

// todo: this sucks, it's all just so we can detect 9-patches
@Implementation
public static Drawable createFromResourceStream(Resources res, TypedValue value, InputStream is, String srcName, BitmapFactory.Options opts) {
    if (is == null) {
        return null;
    }
    Rect pad = new Rect();
    if (opts == null)
        opts = new BitmapFactory.Options();
    opts.inScreenDensity = DisplayMetrics.DENSITY_DEFAULT;
    Bitmap bm = BitmapFactory.decodeResourceStream(res, value, is, pad, opts);
    if (bm != null) {
        boolean isNinePatch = srcName != null && srcName.contains(".9.");
        if (isNinePatch) {
            ReflectionHelpers.callInstanceMethod(bm, "setNinePatchChunk", ClassParameter.from(byte[].class, new byte[0]));
        }
        byte[] np = bm.getNinePatchChunk();
        if (np == null || !NinePatch.isNinePatchChunk(np)) {
            np = null;
            pad = null;
        }
        if (np != null) {
            // todo: wrong
            return new NinePatchDrawable(res, bm, np, pad, srcName);
        }
        return new BitmapDrawable(res, bm);
    }
    return null;
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Implementation(org.robolectric.annotation.Implementation)

Example 85 with Implementation

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

the class ShadowDrawable method hashCode.

@Override
@Implementation
public int hashCode() {
    Rect bounds = realDrawable.getBounds();
    int result = bounds != null ? bounds.hashCode() : 0;
    result = 31 * result + intrinsicWidth;
    result = 31 * result + intrinsicHeight;
    return result;
}
Also used : Rect(android.graphics.Rect) 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