use of com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache in project ForPDA by RadiationX.
the class App method initImageLoader.
public static void initImageLoader(Context context) {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).imageDownloader(new BaseImageDownloader(context) {
final Pattern pattern4pda = Pattern.compile("(?:http?s?:)?\\/\\/.*?4pda\\.(?:ru|to)");
@Override
public InputStream getStream(String imageUri, Object extra) throws IOException {
if (imageUri.substring(0, 2).equals("//"))
imageUri = "http:".concat(imageUri);
Log.d(App.class.getSimpleName(), "ImageLoader getStream " + imageUri);
return super.getStream(imageUri, extra);
}
@Override
protected HttpURLConnection createConnection(String url, Object extra) throws IOException {
HttpURLConnection conn = super.createConnection(url, extra);
if (pattern4pda.matcher(url).find()) {
Map<String, Cookie> cookies = Client.get().getClientCookies();
String stringCookies = "";
for (Map.Entry<String, Cookie> cookieEntry : cookies.entrySet()) {
stringCookies = stringCookies.concat(cookieEntry.getKey()).concat("=").concat(cookieEntry.getValue().value()).concat(";");
}
conn.setRequestProperty("Cookie", stringCookies);
}
return conn;
}
}).threadPoolSize(5).threadPriority(Thread.MIN_PRIORITY).denyCacheImageMultipleSizesInMemory().memoryCache(// 5 Mb
new UsingFreqLimitedMemoryCache(5 * 1024 * 1024)).diskCacheFileNameGenerator(new HashCodeFileNameGenerator()).defaultDisplayImageOptions(options.build()).build();
ImageLoader.getInstance().init(config);
}
Aggregations