com.nostra13.universalimageloader.utils.MemoryCacheUtils Java Examples

The following examples show how to use com.nostra13.universalimageloader.utils.MemoryCacheUtils. 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: ImageLoaderConfiguration.java    From letv with Apache License 2.0 5 votes vote down vote up
private void initEmptyFieldsWithDefaultValues() {
    if (this.taskExecutor == null) {
        this.taskExecutor = DefaultConfigurationFactory.createExecutor(this.threadPoolSize, this.threadPriority, this.tasksProcessingType);
    } else {
        this.customExecutor = true;
    }
    if (this.taskExecutorForCachedImages == null) {
        this.taskExecutorForCachedImages = DefaultConfigurationFactory.createExecutor(this.threadPoolSize, this.threadPriority, this.tasksProcessingType);
    } else {
        this.customExecutorForCachedImages = true;
    }
    if (this.diskCache == null) {
        if (this.diskCacheFileNameGenerator == null) {
            this.diskCacheFileNameGenerator = DefaultConfigurationFactory.createFileNameGenerator();
        }
        this.diskCache = DefaultConfigurationFactory.createDiskCache(this.context, this.diskCacheFileNameGenerator, this.diskCacheSize, this.diskCacheFileCount);
    }
    if (this.memoryCache == null) {
        this.memoryCache = DefaultConfigurationFactory.createMemoryCache(this.memoryCacheSize);
    }
    if (this.denyCacheImageMultipleSizesInMemory) {
        this.memoryCache = new FuzzyKeyMemoryCache(this.memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
    }
    if (this.downloader == null) {
        this.downloader = DefaultConfigurationFactory.createImageDownloader(this.context);
    }
    if (this.decoder == null) {
        this.decoder = DefaultConfigurationFactory.createImageDecoder(this.writeLogs);
    }
    if (this.defaultDisplayImageOptions == null) {
        this.defaultDisplayImageOptions = DisplayImageOptions.createSimple();
    }
}
 
Example #2
Source File: ThumbViewActivity.java    From PinchImageView with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_thumb_view);

    final DisplayImageOptions thumbOptions = new DisplayImageOptions.Builder().cacheInMemory(true).build();
    final ImageLoader imageLoader = Global.getImageLoader(getApplicationContext());

    final ViewGroup root = (ViewGroup) findViewById(R.id.root);
    int l = root.getChildCount();
    for (int i = 0; i < l; i++) {
        final int fi = i;
        final ImageView thumb = (ImageView) ((ViewGroup) root.getChildAt(i)).getChildAt(0);
        final ImageViewAware thumbAware = new ImageViewAware(thumb);
        final String url = Global.getTestImage(i).getThumb(100, 100).url;
        imageLoader.displayImage(url, thumbAware, thumbOptions);
        thumb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ThumbViewActivity.this, PicViewActivity.class);
                intent.putExtra("image", Global.getTestImage(fi));
                ImageSize targetSize = new ImageSize(thumbAware.getWidth(), thumbAware.getHeight());
                String memoryCacheKey = MemoryCacheUtils.generateKey(url, targetSize);
                intent.putExtra("cache_key", memoryCacheKey);
                Rect rect = new Rect();
                thumb.getGlobalVisibleRect(rect);
                intent.putExtra("rect", rect);
                intent.putExtra("scaleType", thumb.getScaleType());
                startActivity(intent);
            }
        });
    }
}
 
Example #3
Source File: ApngImageLoadingListener.java    From apng-view with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
    if (view == null) return;

    Object tag = view.getTag(R.id.tag_image);
    if (enableDebugLog) FLog.d("tag: %s", tag);

    if (tag != null && tag instanceof String) {
        String actualUri = tag.toString();

        File pngFile = AssistUtil.getCopiedFile(context, actualUri);

        if (pngFile == null) {
            if (enableDebugLog) FLog.w("Can't locate the file!!! %s", actualUri);

        } else if (pngFile.exists()) {
            boolean isApng = AssistUtil.isApng(pngFile);

            if (isApng) {
                if (enableDebugLog) FLog.d("Setup apng drawable");
                ApngDrawable drawable = new ApngDrawable(context, loadedImage, Uri.fromFile(pngFile));
                ((ImageView) view).setImageDrawable(drawable);
            } else {
                ((ImageView) view).setImageBitmap(loadedImage);
            }

        } else {
            if (enableDebugLog) FLog.d("Clear cache and reload");
            MemoryCacheUtils.removeFromCache(actualUri, ApngImageLoader.getInstance().getMemoryCache());
            DiskCacheUtils.removeFromCache(actualUri, ApngImageLoader.getInstance().getDiskCache());

            ApngImageLoader.getInstance().displayImage(actualUri, (ImageView) view, this);
        }
    }

    if (shouldForward()) callback.onLoadFinish(true, imageUri, view);
}
 
Example #4
Source File: ImageLoader.java    From letv with Apache License 2.0 4 votes vote down vote up
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
    checkConfiguration();
    if (imageAware == null) {
        throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
    }
    if (listener == null) {
        listener = this.emptyListener;
    }
    if (options == null) {
        options = this.configuration.defaultDisplayImageOptions;
    }
    if (TextUtils.isEmpty(uri)) {
        this.engine.cancelDisplayTaskFor(imageAware);
        listener.onLoadingStarted(uri, imageAware.getWrappedView());
        if (options.shouldShowImageForEmptyUri()) {
            imageAware.setImageDrawable(options.getImageForEmptyUri(this.configuration.resources));
        } else {
            imageAware.setImageDrawable(null);
        }
        listener.onLoadingComplete(uri, imageAware.getWrappedView(), null);
        return;
    }
    ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, this.configuration.getMaxImageSize());
    String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);
    this.engine.prepareDisplayTaskFor(imageAware, memoryCacheKey);
    listener.onLoadingStarted(uri, imageAware.getWrappedView());
    Bitmap bmp = (Bitmap) this.configuration.memoryCache.get(memoryCacheKey);
    if (bmp == null || bmp.isRecycled()) {
        if (options.shouldShowImageOnLoading()) {
            imageAware.setImageDrawable(options.getImageOnLoading(this.configuration.resources));
        } else if (options.isResetViewBeforeLoading()) {
            imageAware.setImageDrawable(null);
        }
        LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(this.engine, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
        if (options.isSyncLoading()) {
            displayTask.run();
            return;
        } else {
            this.engine.submit(displayTask);
            return;
        }
    }
    L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
    if (options.shouldPostProcess()) {
        ProcessAndDisplayImageTask displayTask2 = new ProcessAndDisplayImageTask(this.engine, bmp, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
        if (options.isSyncLoading()) {
            displayTask2.run();
            return;
        } else {
            this.engine.submit(displayTask2);
            return;
        }
    }
    options.getDisplayer().display(bmp, imageAware, LoadedFrom.MEMORY_CACHE);
    listener.onLoadingComplete(uri, imageAware.getWrappedView(), bmp);
}
 
Example #5
Source File: BraceletImageLoader.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public List getMemoryCache(String s)
{
    return MemoryCacheUtils.findCachedBitmapsForImageUri(s, b.getMemoryCache());
}
 
Example #6
Source File: BraceletImageLoader.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public void removeImageCache(String s)
{
    MemoryCacheUtils.removeFromCache(s, b.getMemoryCache());
    DiskCacheUtils.removeFromCache(s, b.getDiscCache());
}