• Android Universal Image Loader 流程分析(1)


    只是分析流程

    public void displayImage(String uri, ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener) {
            checkConfiguration();
            if (imageView == null) {
                throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
            }
            if (listener == null) {
                listener = emptyListener;
            }
            if (options == null) {
                options = configuration.defaultDisplayImageOptions;
            }
    
            if (TextUtils.isEmpty(uri)) {
                engine.cancelDisplayTaskFor(imageView);
                listener.onLoadingStarted(uri, imageView);
                if (options.shouldShowImageForEmptyUri()) {
                    imageView.setImageResource(options.getImageForEmptyUri());
                } else {
                    imageView.setImageBitmap(null);
                }
                listener.onLoadingComplete(uri, imageView, null);
                return;
            }
    
            ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageView, configuration.maxImageWidthForMemoryCache,
                    configuration.maxImageHeightForMemoryCache);
            String memoryCacheKey = MemoryCacheUtil.generateKey(uri, targetSize);
            engine.prepareDisplayTaskFor(imageView, memoryCacheKey);
    
            listener.onLoadingStarted(uri, imageView);
            Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);
            if (bmp != null && !bmp.isRecycled()) {
                if (configuration.loggingEnabled) L.i(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
    
                if (options.shouldPostProcess()) {
                    ImageLoadingInfo imageLoadingInfo = new ImageLoadingInfo(uri, imageView, targetSize, memoryCacheKey, options, listener,
                            engine.getLockForUri(uri));
                    ProcessAndDisplayImageTask displayTask = new ProcessAndDisplayImageTask(engine, bmp, imageLoadingInfo, options.getHandler());
                    engine.submit(displayTask);
                } else {
                    options.getDisplayer().display(bmp, imageView);
                    listener.onLoadingComplete(uri, imageView, bmp);
                }
            } else {
                if (options.shouldShowStubImage()) {
                    imageView.setImageResource(options.getStubImage());
                } else {
                    if (options.isResetViewBeforeLoading()) {
                        imageView.setImageBitmap(null);
                    }
                }
    
                ImageLoadingInfo imageLoadingInfo = new ImageLoadingInfo(uri, imageView, targetSize, memoryCacheKey, options, listener, engine.getLockForUri(uri));
                LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(engine, imageLoadingInfo, options.getHandler());
                engine.submit(displayTask);
            }
        }

    1.检查内存中是否存在

    2.如果存在 执行ProcessAndDisplayImageTask  得到bitmap  处理bitmap 显示

    3.不存在 则 执行LoadAndDisplayImageTask 


    。。。。。LoadAndDisplayImageTask。。
    。。
    @Override public void run() { if (waitIfPaused()) return; if (delayIfNeed()) return; ReentrantLock loadFromUriLock = imageLoadingInfo.loadFromUriLock; log(LOG_START_DISPLAY_IMAGE_TASK); if (loadFromUriLock.isLocked()) { log(LOG_WAITING_FOR_IMAGE_LOADED); } loadFromUriLock.lock(); Bitmap bmp; try { if (checkTaskIsNotActual()) return; bmp = configuration.memoryCache.get(memoryCacheKey); if (bmp == null) { bmp = tryLoadBitmap(); if (bmp == null) return; if (checkTaskIsNotActual() || checkTaskIsInterrupted()) return; if (options.shouldPreProcess()) { log(LOG_PREPROCESS_IMAGE); bmp = options.getPreProcessor().process(bmp); if (bmp == null) { L.w(WARNING_PRE_PROCESSOR_NULL); } } if (bmp != null && options.isCacheInMemory()) { log(LOG_CACHE_IMAGE_IN_MEMORY); configuration.memoryCache.put(memoryCacheKey, bmp); } } else { log(LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING); } if (bmp != null && options.shouldPostProcess()) { log(LOG_POSTPROCESS_IMAGE); bmp = options.getPostProcessor().process(bmp); if (bmp == null) { L.w(WARNING_POST_PROCESSOR_NULL, memoryCacheKey); } } } finally { loadFromUriLock.unlock(); } if (checkTaskIsNotActual() || checkTaskIsInterrupted()) return; DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask(bmp, imageLoadingInfo, engine); displayBitmapTask.setLoggingEnabled(loggingEnabled); handler.post(displayBitmapTask); }

    4. 本地loadBitmap

    5. 判读是否存内存,如果需要存内存则存map

    6.处理图片

    7.显示图片

  • 相关阅读:
    Spring Boot应用程序属性
    Spring Boot Bean和依赖注入
    Spring Boot构建系统
    Spring Boot Tomcat部署
    Spring Boot引导过程
    Spring Boot快速入门
    Spring Boot简介
    eclipse中将项目打包成jar的两种方法,及其问题与解决方法
    配置Zuul代理下游的认证
    WireMock和Spring MVC模拟器
  • 原文地址:https://www.cnblogs.com/wjw334/p/3635899.html
Copyright © 2020-2023  润新知