Search in sources :

Example 1 with NinePatchInputStream

use of android.content.res.BridgeResources.NinePatchInputStream in project android_frameworks_base by ParanoidAndroid.

the class BitmapFactory_Delegate method nativeDecodeStream.

@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, Rect padding, Options opts, boolean applyScale, float scale) {
    Bitmap bm = null;
    //TODO support rescaling
    Density density = Density.MEDIUM;
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
    }
    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(), true, /*isMutable*/
            density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            // 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, true, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(android.content.res.BridgeResources.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

NinePatchInputStream (android.content.res.BridgeResources.NinePatchInputStream)1 NinePatchChunk (com.android.ninepatch.NinePatchChunk)1 Density (com.android.resources.Density)1 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)1 IOException (java.io.IOException)1