Home | History | Annotate | Download | only in shadows
      1 package org.robolectric.shadows;
      2 
      3 import static org.robolectric.res.android.Registries.NATIVE_ASSET_REGISTRY;
      4 import static org.robolectric.util.ReflectionHelpers.ClassParameter.from;
      5 
      6 import android.content.res.AssetManager;
      7 import android.content.res.AssetManager.AssetInputStream;
      8 import java.io.InputStream;
      9 import org.robolectric.res.android.Asset;
     10 import org.robolectric.shadow.api.Shadow;
     11 import org.robolectric.util.ReflectionHelpers;
     12 
     13 @SuppressWarnings("UnusedDeclaration")
     14 public abstract class ShadowAssetInputStream {
     15 
     16   static AssetInputStream createAssetInputStream(InputStream delegateInputStream, long assetPtr,
     17       AssetManager assetManager) {
     18     Asset asset = NATIVE_ASSET_REGISTRY.getNativeObject(assetPtr);
     19 
     20     AssetInputStream ais = ReflectionHelpers.callConstructor(AssetInputStream.class,
     21         from(AssetManager.class, assetManager),
     22         from(long.class, assetPtr));
     23 
     24     ShadowAssetInputStream sais = Shadow.extract(ais);
     25     if (sais instanceof ShadowLegacyAssetInputStream) {
     26       ShadowLegacyAssetInputStream slais = (ShadowLegacyAssetInputStream) sais;
     27       slais.setDelegate(delegateInputStream);
     28       slais.setNinePatch(asset.isNinePatch());
     29     }
     30     return ais;
     31   }
     32 
     33   public static class Picker extends ResourceModeShadowPicker<ShadowAssetInputStream> {
     34 
     35     public Picker() {
     36       super(ShadowLegacyAssetInputStream.class, ShadowArscAssetInputStream.class,
     37           ShadowArscAssetInputStream.class);
     38     }
     39   }
     40 
     41   abstract InputStream getDelegate();
     42 
     43   abstract boolean isNinePatch();
     44 
     45 }
     46