Java Code Examples for com.facebook.imagepipeline.image.CloseableImage#getSizeInBytes()

The following examples show how to use com.facebook.imagepipeline.image.CloseableImage#getSizeInBytes() . 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: BitmapCountingMemoryCacheFactory.java    From fresco with MIT License 6 votes vote down vote up
public static CountingMemoryCache<CacheKey, CloseableImage> get(
    Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
    MemoryTrimmableRegistry memoryTrimmableRegistry,
    CountingMemoryCache.CacheTrimStrategy trimStrategy,
    @Nullable CountingMemoryCache.EntryStateObserver<CacheKey> observer) {

  ValueDescriptor<CloseableImage> valueDescriptor =
      new ValueDescriptor<CloseableImage>() {
        @Override
        public int getSizeInBytes(CloseableImage value) {
          return value.getSizeInBytes();
        }
      };

  CountingMemoryCache<CacheKey, CloseableImage> countingCache =
      new CountingMemoryCache<>(
          valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, observer);

  memoryTrimmableRegistry.registerMemoryTrimmable(countingCache);

  return countingCache;
}
 
Example 2
Source File: BitmapCountingMemoryCacheFactory.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
public static CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> get(
    Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
    MemoryTrimmableRegistry memoryTrimmableRegistry) {
  MemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage, Void> memoryCacheIndex =
      new SimpleMemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage>();

  CountingMemoryCache.ValueInfoCallback<CloseableImage> valueTypeDescriptor =
      new CountingMemoryCache.ValueInfoCallback<CloseableImage>() {
        @Override
        public long getSizeInBytes(CloseableImage value) {
          return value.getSizeInBytes();
        }
      };

  CountingMemoryCache.CacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy();

  CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> countingCache =
      new CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void>(
          memoryCacheIndex,
          valueTypeDescriptor,
          trimStrategy,
          bitmapMemoryCacheParamsSupplier);

   memoryTrimmableRegistry.registerMemoryTrimmable(countingCache);

  return countingCache;
}