public SettingsBuilder() { settings = new LoaderSettings(); }
public SettingsBuilder addHeader(String key, String value) { settings.addHeader(key, value); return this; }
private Bitmap getNotFoundImage() { String key = "resource" + notFoundResourceId + width + height; Bitmap b = loaderSettings.getResCacheManager().get(key, width, height); if (b != null) { return b; } if (context != null){ if (loaderSettings.isAlwaysUseOriginalSize()) { b = loaderSettings.getBitmapUtil().decodeResourceBitmap(context, width, height, notFoundResourceId); } else { b = loaderSettings.getBitmapUtil().decodeResourceBitmapAndScale(context, width, height, notFoundResourceId, loaderSettings.isAllowUpsampling()); } loaderSettings.getResCacheManager().put(key, b); } return b; }
Bitmap bm = loaderSettings.getCacheManager().get(url, width, height); if (bm == null) { File imageFile = loaderSettings.getFileManager().getFile(url, width, height); if (!imageFile.exists()) { loaderSettings.getNetworkManager().retrieveImage(url, imageFile); if (loaderSettings.isAlwaysUseOriginalSize()) { b = loaderSettings.getBitmapUtil().decodeFile(imageFile, width, height); } else { b = loaderSettings.getBitmapUtil().decodeFileAndScale(imageFile, width, height, loaderSettings.isAllowUpsampling()); loaderSettings.getCacheManager().put(url, b);
private Bitmap getImageFromFile(File imageFile) { Bitmap b; if (loaderSettings.isAlwaysUseOriginalSize()) { b = loaderSettings.getBitmapUtil().decodeFile(imageFile, width, height); } else { b = loaderSettings.getBitmapUtil().decodeFileAndScale(imageFile, width, height, loaderSettings.isAllowUpsampling()); } if (b == null) { // decoding failed loaderSettings.getCacheManager().remove(url); return b; } if (saveScaledImage) { saveScaledImage(imageFile, b); } loaderSettings.getCacheManager().put(url, b); return b; }
OutputStream os = null; HttpURLConnection conn = null; applyChangeonSdkVersion(settings.getSdkVersion()); try { conn = openConnection(url); conn.setConnectTimeout(settings.getConnectionTimeout()); conn.setReadTimeout(settings.getReadTimeout()); if (conn != null && settings.getDisconnectOnEveryCall()) { conn.disconnect();
private Bitmap getResourceAsBitmap(ImageWrapper w, int resId) { Bitmap b = loaderSettings.getResCacheManager().get("" + resId, w.getWidth(), w.getHeight()); if (b != null) { return b; } b = loaderSettings.getBitmapUtil().decodeResourceBitmapAndScale(w, resId, loaderSettings.isAllowUpsampling()); loaderSettings.getResCacheManager().put(String.valueOf(resId), b); return b; }
@Override public InputStream retrieveInputStream(String url) { HttpURLConnection conn = null; try { conn = openConnection(url); conn.setConnectTimeout(settings.getConnectionTimeout()); conn.setReadTimeout(settings.getReadTimeout()); return conn.getInputStream(); } catch (FileNotFoundException fnfe) { throw new ImageNotFoundException(); } catch (Throwable ex) { return null; } }
public CacheManager getCacheManager() { return loaderSettings.getCacheManager(); }
public FileManager getFileManager() { return loaderSettings.getFileManager(); }
private void deleteOldFiles(final long expirationPeriod) { final String cacheDir = loaderSettings.getCacheDir().getAbsolutePath(); Thread cleaner = new Thread(new Runnable() { @Override public void run() { try { new FileUtil().reduceFileCache(cacheDir, expirationPeriod); } catch (Throwable t) { // Don't have to fail in case there } } }); cleaner.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); cleaner.start(); }
private void handleHeaders(HttpURLConnection conn) { Map<String, String> headers = settings.getHeaders(); if (headers != null) { for (String key : headers.keySet()) { conn.setRequestProperty(key, headers.get(key)); } } }
/** * CleanOldFile is removing all the files in the cache directory where the * timestamp is older then the expiration time. */ @Override public void cleanOldFiles() { deleteOldFiles(loaderSettings.getExpirationPeriod()); }
private void setResource(ImageWrapper w, int resId) { Bitmap b = loaderSettings.getResCacheManager().get("" + resId, w.getWidth(), w.getHeight()); if (b != null) { w.setBitmap(b, false); return; } b = loaderSettings.getBitmapUtil().decodeResourceBitmapAndScale(w, resId, loaderSettings.isAllowUpsampling()); loaderSettings.getResCacheManager().put("" + resId, b); w.setBitmap(b, false); }
private Bitmap getCachedBitmap(ImageWrapper w) { return loaderSettings.getCacheManager().get(w.getUrl(), w.getHeight(), w.getWidth()); }
private void saveScaledImage(File imageFile, Bitmap b) { loaderSettings.getFileManager().saveBitmap(imageFile.getAbsolutePath(), b, width, height); }
@Override public File getFile(String url) { url = processUrl(url); String filename = String.valueOf(url.hashCode()); return new File(loaderSettings.getCacheDir(), filename); }
private Bitmap getPreviewCachedBitmap(ImageWrapper w) { return loaderSettings.getCacheManager().get(w.getPreviewUrl(), w.getPreviewHeight(), w.getPreviewWidth()); }
private File getImageFile(ImageWrapper imageWrapper) { File imageFile = null; if (imageWrapper.isSaveThumbnail()) { imageFile = loaderSettings.getFileManager().getFile(url, width, height); } if (imageFile == null || !imageFile.exists()) { imageFile = loaderSettings.getFileManager().getFile(url); if (imageWrapper.isSaveThumbnail()) { saveScaledImage = true; } } return imageFile; }
@Override public File getFile(String url, int width, int height) { url = processUrl(url); String filename = url.hashCode() + "-" + width + "x" + height; return new File(loaderSettings.getCacheDir(), filename); }