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