1 // BEGIN-INTERNAL 2 package org.robolectric.shadows; 3 4 import android.graphics.Bitmap; 5 import android.graphics.BitmapFactory; 6 import android.graphics.ImageDecoder; 7 import android.graphics.Point; 8 import android.os.Build; 9 import java.io.IOException; 10 import java.io.InputStream; 11 import org.robolectric.annotation.Implementation; 12 import org.robolectric.annotation.Implements; 13 import org.robolectric.annotation.RealObject; 14 import org.robolectric.util.ReflectionHelpers; 15 import org.robolectric.util.ReflectionHelpers.ClassParameter; 16 17 @SuppressWarnings({"UnusedDeclaration"}) 18 @Implements(value = ImageDecoder.class, minSdk = Build.VERSION_CODES.P) 19 public class ShadowImageDecoder { 20 21 @RealObject private ImageDecoder realObject; 22 23 @Implementation 24 public static ImageDecoder nCreate(long asset, ImageDecoder.Source source) { 25 return ReflectionHelpers.callConstructor(ImageDecoder.class, 26 ClassParameter.from(long.class, 1), 27 ClassParameter.from(int.class, 10), 28 ClassParameter.from(int.class, 10), 29 ClassParameter.from(boolean.class, false), 30 ClassParameter.from(boolean.class, false)); 31 } 32 33 @Implementation 34 public static ImageDecoder nCreate(InputStream is, byte[] storage, ImageDecoder.Source source) { 35 final Point size = ImageUtil.getImageSizeFromStream(is); 36 final int width = size == null ? 10 : size.x; 37 final int height = size == null ? 10 : size.y; 38 39 return ReflectionHelpers.callConstructor(ImageDecoder.class, 40 ClassParameter.from(long.class, 1), 41 ClassParameter.from(int.class, width), 42 ClassParameter.from(int.class, height), 43 ClassParameter.from(boolean.class, false), 44 ClassParameter.from(boolean.class, false)); 45 } 46 47 @Implementation 48 public Bitmap decodeBitmapInternal() throws IOException { 49 final InputStream stream = ReflectionHelpers.getField(realObject, "mInputStream"); 50 if (stream != null) { 51 return BitmapFactory.decodeStream(stream); 52 } 53 54 return null; 55 } 56 } 57 // END-INTERNAL 58