protected Bitmap decodeResource(int id, ImageOptions imageOptions) { BitmapFactory.Options factoryOptions = this.bitmapFactoryOptions(imageOptions); return (this.resources != null) ? BitmapFactory.decodeResource(this.resources, id, factoryOptions) : null; }
public void setResources(Resources res) { this.resources = res; ((ImageRetriever) this.imageRetriever).setResources(res); }
protected Bitmap decodeImage(ImageSource imageSource, ImageOptions imageOptions) throws IOException { if (imageSource.isBitmap()) { return imageSource.asBitmap(); } if (imageSource.isBitmapFactory()) { return imageSource.asBitmapFactory().createBitmap(); } if (imageSource.isResource()) { return this.decodeResource(imageSource.asResource(), imageOptions); } if (imageSource.isFilePath()) { return this.decodeFilePath(imageSource.asFilePath(), imageOptions); } if (imageSource.isUrl()) { return this.decodeUrl(imageSource.asUrl(), imageOptions); } return this.decodeUnrecognized(imageSource); }
protected void init() { this.handler = new Handler(this); this.evictionQueue = new ConcurrentLinkedQueue<>(); this.imageRetriever = new ImageRetriever(2); this.urlImageRetriever = new ImageRetriever(8); this.imageRetrieverCache = new SynchronizedMemoryCache<>(this.getCapacity() / 8); Logger.log(Logger.INFO, String.format(Locale.US, "RenderResourceCache initialized %,.0f KB (%,.0f KB retrieval cache)", this.getCapacity() / 1024.0, this.imageRetrieverCache.getCapacity() / 1024.0)); }
@Override protected void retrieveAsync(ImageSource imageSource, ImageOptions imageOptions, Callback<ImageSource, ImageOptions, Bitmap> callback) { try { Bitmap bitmap = this.decodeImage(imageSource, imageOptions); if (bitmap != null) { callback.retrievalSucceeded(this, imageSource, imageOptions, bitmap); } else { callback.retrievalFailed(this, imageSource, null); // failed but no exception } } catch (Throwable logged) { callback.retrievalFailed(this, imageSource, logged); // failed with exception } }
protected Bitmap decodeFilePath(String pathName, ImageOptions imageOptions) { BitmapFactory.Options factoryOptions = this.bitmapFactoryOptions(imageOptions); return BitmapFactory.decodeFile(pathName, factoryOptions); }
protected Bitmap decodeUrl(String urlString, ImageOptions imageOptions) throws IOException { // TODO establish a file caching service for remote resources // TODO retry absent resources, they are currently handled but suppressed entirely after the first failure // TODO configurable connect and read timeouts InputStream stream = null; try { URLConnection conn = new URL(urlString).openConnection(); conn.setConnectTimeout(3000); conn.setReadTimeout(30000); stream = new BufferedInputStream(conn.getInputStream()); BitmapFactory.Options factoryOptions = this.bitmapFactoryOptions(imageOptions); return BitmapFactory.decodeStream(stream, null, factoryOptions); } finally { WWUtil.closeSilently(stream); } }