Search in sources :

Example 1 with UsingFreqLimitedMemoryCache

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);
}
Also used : Cookie(okhttp3.Cookie) Pattern(java.util.regex.Pattern) HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) UsingFreqLimitedMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache) HttpURLConnection(java.net.HttpURLConnection) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashCodeFileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator)1 UsingFreqLimitedMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache)1 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)1 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)1 HttpURLConnection (java.net.HttpURLConnection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 Cookie (okhttp3.Cookie)1