use of com.android.layoutlib.bridge.util.NinePatchInputStream in project android_frameworks_base by ResurrectionRemix.
the class BitmapFactory_Delegate method nativeDecodeStream.
// ------ Native Delegates ------
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, @Nullable Rect padding, @Nullable Options opts) {
Bitmap bm = null;
Density density = Density.MEDIUM;
Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
if (opts != null) {
density = Density.getEnum(opts.inDensity);
if (opts.inPremultiplied) {
bitmapCreateFlags.add(BitmapCreateFlags.PREMULTIPLIED);
}
opts.inScaled = false;
}
try {
if (is instanceof NinePatchInputStream) {
NinePatchInputStream npis = (NinePatchInputStream) is;
npis.disableFakeMarkSupport();
// load the bitmap as a nine patch
com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
false);
// get the bitmap and chunk objects.
bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), bitmapCreateFlags, density);
NinePatchChunk chunk = ninePatch.getChunk();
// put the chunk in the bitmap
bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
if (padding != null) {
// read the padding
int[] paddingArray = chunk.getPadding();
padding.left = paddingArray[0];
padding.top = paddingArray[1];
padding.right = paddingArray[2];
padding.bottom = paddingArray[3];
}
} else {
// load the bitmap directly.
bm = Bitmap_Delegate.createBitmap(is, bitmapCreateFlags, density);
}
} catch (IOException e) {
Bridge.getLog().error(null, "Failed to load image", e, null);
}
return bm;
}
use of com.android.layoutlib.bridge.util.NinePatchInputStream in project android_frameworks_base by crdroidandroid.
the class Resources_Delegate method openRawResource.
@LayoutlibDelegate
static InputStream openRawResource(Resources resources, int id, TypedValue value) throws NotFoundException {
getValue(resources, id, value, true);
String path = value.string.toString();
File f = new File(path);
if (f.isFile()) {
try {
// and actually load it as a 9-patch instead of a normal bitmap
if (path.toLowerCase().endsWith(NinePatch.EXTENSION_9PATCH)) {
return new NinePatchInputStream(f);
}
return new FileInputStream(f);
} catch (FileNotFoundException e) {
NotFoundException exception = new NotFoundException();
exception.initCause(e);
throw exception;
}
}
throw new NotFoundException();
}
Aggregations