public static InputStream getInputStream(Context context, String fileName) throws IOException { return context.getResources().getAssets().open(fileName); }
public static byte[] readAsset(Context context, String filename) throws IOException { InputStream in = context.getResources().getAssets().open(filename); try { return readAllBytes(in); } finally { in.close(); } }
private static boolean assetExists(Context context, String fileName) throws IOException { int i = fileName.lastIndexOf('/'); String path = i >= 0 ? fileName.substring(0, i) : ""; String file = i >= 0 ? fileName.substring(i + 1) : fileName; return Arrays.asList(context.getResources().getAssets().list(path)).contains(file); }
private InputStream initPerformanceTest() { try { final File file = new File(writePerformanceTestPath); if (file.exists()) { file.delete(); } file.createNewFile(); return getResources().getAssets().open("performance_test_data"); } catch (IOException e) { e.printStackTrace(); } return null; }
public RequestHandler(Context context) { mContext = context; mAssets = context.getResources().getAssets(); mGson = new GsonBuilder().serializeNulls().create(); }
Resources standardResources = context.getResources(); AssetManager assets = standardResources.getAssets(); DisplayMetrics metrics = standardResources.getDisplayMetrics(); Configuration config = new Configuration(standardResources.getConfiguration()); config.locale = Locale.US; Resources defaultResources = new Resources(assets, metrics, config);
public static InputStream getInputStream(Context context, String fileName) throws IOException { return context.getResources().getAssets().open(fileName); }
private ShadowLegacyAssetManager getShadowAssetManager() { return legacyShadowOf(getResources().getAssets()); }
public SubClassResources(Resources res) { super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration()); } }
private static boolean assetExists(Context context, String fileName) throws IOException { int i = fileName.lastIndexOf('/'); String path = i >= 0 ? fileName.substring(0, i) : ""; String file = i >= 0 ? fileName.substring(i + 1) : fileName; return Arrays.asList(context.getResources().getAssets().list(path)).contains(file); }
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; } }); }
@Before public void setUp() throws Exception { resources = ApplicationProvider.getApplicationContext().getResources(); assetManager = resources.getAssets(); }
private Resources.NotFoundException newNotFoundException(int id) { ResourceTable resourceTable = legacyShadowOf(realResources.getAssets()).getResourceTable(); ResName resName = resourceTable.getResName(id); if (resName == null) { return new Resources.NotFoundException("resource ID #0x" + Integer.toHexString(id)); } else { return new Resources.NotFoundException(resName.getFullyQualifiedName()); } }
@Before public void setup() throws Exception { Context context = getTargetContext(); assetManager = context.getResources().getAssets(); }
@Implementation public TypedArray obtainStyledAttributes(Resources.Theme wrapper, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { Resources resources = wrapper.getResources(); AssetManager assets = resources.getAssets(); return legacyShadowOf(assets) .attrsToTypedArray(resources, set, attrs, defStyleAttr, getNativePtr(), defStyleRes); }
@Implementation protected InputStream openRawResource(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets()); ResourceTable resourceTable = shadowAssetManager.getResourceTable(); InputStream inputStream = resourceTable.getRawValue(id, shadowAssetManager.config); if (inputStream == null) { throw newNotFoundException(id); } else { return inputStream; } } else { return directlyOn(realResources, Resources.class).openRawResource(id); } }
private static FileDescriptor getImageFd() throws Exception { return ApplicationProvider.getApplicationContext() .getResources() .getAssets() .openFd("robolectric.png") .getFileDescriptor(); }
@Implementation protected TypedArray obtainAttributes(AttributeSet set, int[] attrs) { if (isLegacyAssetManager()) { return legacyShadowOf(realResources.getAssets()) .attrsToTypedArray(realResources, set, attrs, 0, 0, 0); } else { return directlyOn(realResources, Resources.class).obtainAttributes(set, attrs); } }
@Implementation protected TypedArray obtainTypedArray(int id) throws Resources.NotFoundException { if (isLegacyAssetManager()) { ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets()); TypedArray typedArray = shadowAssetManager.getTypedArrayResource(realResources, id); if (typedArray != null) { return typedArray; } else { throw newNotFoundException(id); } } else { return directlyOn(realResources, Resources.class).obtainTypedArray(id); } }
@HiddenApi @Implementation protected XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException { if (isLegacyAssetManager()) { ShadowLegacyAssetManager shadowAssetManager = legacyShadowOf(realResources.getAssets()); return shadowAssetManager.loadXmlResourceParser(resId, type); } else { return directlyOn(realResources, Resources.class, "loadXmlResourceParser", ClassParameter.from(int.class, resId), ClassParameter.from(String.class, type)); } }