com.squareup.picasso.LruCache Java Examples

The following examples show how to use com.squareup.picasso.LruCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageManager.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
/**
 * Enables or disables the disk cache for the life of the application. This method cannot be
 * called more than once per lifetime of the app and should therefore be called only during
 * application startup; subsequent calls have no effect on the disk cache state.
 *
 * Note that when enabling Piccaso cache indicators, you may still find that some images appear
 * as though they've been loaded from disk. This will be true for any app-packaged drawable or
 * bitmap resource that's placed by Picasso. (These are always "from disk" with or without the
 * presence of a disk cache.) Similarly, it's possible to get green-tagged images when using
 * Picasso to "load" manually pre-loaded BitmapDrawables. 
 *
 * @param diskCacheEnabled
 */
public static void setConfiguration(Context context, boolean diskCacheEnabled, Integer cacheHeapPercent) {
    try {

        Picasso.Builder builder = new Picasso.Builder((ArcusApplication.getContext()));

        if (diskCacheEnabled) {
            builder.downloader(new OkHttp3Downloader(new OkHttpClient()));
        }

        if (cacheHeapPercent != null) {
            ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
            int memoryClass = am.getMemoryClass();

            int heapSize = (int) ((float)(1024 * 1024 * memoryClass) * ((float) cacheHeapPercent / 100.0));
            builder.memoryCache(new LruCache(heapSize));
            logger.debug("Setting Picasso in-memory LRU cache max size to {} bytes; {}% of heap sized {}", heapSize, cacheHeapPercent, 1024 * 1024 * memoryClass);
        }

        Picasso.setSingletonInstance(builder.build());

    } catch (IllegalStateException e) {
        logger.warn("Picasso setConfiguration() has already been called; ignoring request.");
    }
}
 
Example #2
Source File: PicassoConfigFactory.java    From ImageLoadPK with Apache License 2.0 5 votes vote down vote up
public static Picasso getPicasso(Context context) {
        if (sPicasso == null) {
            sPicasso = new Picasso.Builder(context)
                    //硬盘缓存池大小
                    .downloader(new OkHttpDownloader(context, ConfigConstants.MAX_CACHE_DISK_SIZE))
                    //内存缓存池大小
                    .memoryCache(new LruCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE))
//                    .defaultBitmapConfig(Bitmap.Config.ARGB_4444)
                    .build();
        }
        return sPicasso;
    }
 
Example #3
Source File: App.java    From greedo-layout-for-android with MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    Picasso picasso = new Picasso.Builder(this)
            .memoryCache(new LruCache(calculateMemoryCacheSize()))
            .build();
    Picasso.setSingletonInstance(picasso);
}
 
Example #4
Source File: SamplePicassoFactory.java    From fresco with MIT License 5 votes vote down vote up
public static Picasso getPicasso(Context context) {
  if (sPicasso == null) {
    sPicasso =
        new Picasso.Builder(context)
            .downloader(new OkHttp3Downloader(context, ConfigConstants.MAX_DISK_CACHE_SIZE))
            .memoryCache(new LruCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE))
            .build();
  }
  return sPicasso;
}