use of android.content.res.AssetManager.AssetInputStream in project robolectric by robolectric.
the class ShadowBitmapFactory method decodeStream.
@Implementation
protected static Bitmap decodeStream(InputStream is, Rect outPadding, BitmapFactory.Options opts) {
byte[] ninePatchChunk = null;
if (is instanceof AssetInputStream) {
ShadowAssetInputStream sais = Shadow.extract(is);
if (sais.isNinePatch()) {
ninePatchChunk = new byte[0];
}
if (sais.getDelegate() != null) {
is = sais.getDelegate();
}
}
try {
if (is != null) {
is.reset();
}
} catch (IOException e) {
// ignore
}
boolean isNamedStream = is instanceof NamedStream;
String name = isNamedStream ? is.toString().replace("stream for ", "") : null;
RobolectricBufferedImage image = isNamedStream ? null : getImageFromStream(is);
if (!allowInvalidImageData && image == null) {
if (opts != null) {
opts.outWidth = -1;
opts.outHeight = -1;
}
return null;
}
Bitmap bitmap = create(name, outPadding, opts, null, image);
ReflectionHelpers.callInstanceMethod(bitmap, "setNinePatchChunk", ClassParameter.from(byte[].class, ninePatchChunk));
ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
shadowBitmap.createdFromStream = is;
if (image != null && opts != null) {
opts.outMimeType = image.getMimeType();
}
return bitmap;
}
use of android.content.res.AssetManager.AssetInputStream in project robolectric by robolectric.
the class ShadowAssetInputStream method createAssetInputStream.
static AssetInputStream createAssetInputStream(InputStream delegateInputStream, long assetPtr, AssetManager assetManager) {
Asset asset = NATIVE_ASSET_REGISTRY.getNativeObject(assetPtr);
AssetInputStream ais = ReflectionHelpers.callConstructor(AssetInputStream.class, from(AssetManager.class, assetManager), from(long.class, assetPtr));
ShadowAssetInputStream sais = Shadow.extract(ais);
if (sais instanceof ShadowLegacyAssetInputStream) {
ShadowLegacyAssetInputStream slais = (ShadowLegacyAssetInputStream) sais;
slais.setDelegate(delegateInputStream);
slais.setNinePatch(asset.isNinePatch());
}
return ais;
}
use of android.content.res.AssetManager.AssetInputStream in project robolectric by robolectric.
the class ShadowImageDecoder method ImageDecoder_nCreateAsset.
protected static ImageDecoder ImageDecoder_nCreateAsset(long asset_ptr, Source source) throws DecodeException {
// Asset* asset = reinterpret_cast<Asset*>(assetPtr);
// SkStream stream = new AssetStreamAdaptor(asset);
// return jniCreateDecoder(stream, source);
Resources resources = ReflectionHelpers.getField(source, "mResources");
AssetInputStream assetInputStream = ShadowAssetInputStream.createAssetInputStream(null, asset_ptr, resources.getAssets());
return jniCreateDecoder(new ImgStream() {
@Override
protected InputStream getInputStream() {
return assetInputStream;
}
});
}
Aggregations