Search in sources :

Example 1 with IInnerImageSetter

use of com.example.test.andlang.util.imageload.IInnerImageSetter in project AndLang by wugemu.

the class BaseLangApplication method initImageLoad.

private void initImageLoad() {
    // 配置uil工具
    File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), tmpImageDir);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).memoryCacheExtraOptions(480, // default = device screen dimensions
    800).threadPriority(// default
    Thread.NORM_PRIORITY - 1).tasksProcessingOrder(// default
    QueueProcessingType.FIFO).threadPoolSize(3).denyCacheImageMultipleSizesInMemory().memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(// default
    13).diskCache(new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 缓冲大小
    50 * 1024 * 1024).diskCacheFileCount(// 缓冲文件数目
    100).diskCacheFileNameGenerator(// default
    new HashCodeFileNameGenerator()).imageDownloader(// default
    new BaseImageDownloader(this)).defaultDisplayImageOptions(// default
    DisplayImageOptions.createSimple()).writeDebugLogs().build();
    // 2.单例ImageLoader类的初始化
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);
    ImageLoadUtils.setImageSetter(new IInnerImageSetter() {

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().display(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrlCenterCrop(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGifCenterCrop(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayCenterCrop(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrlFitCenter(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGifFitCenter(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayFitCenter(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadCircleImageUrl(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayHead(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageRound(@NonNull IMAGE view, @Nullable String url, float round) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayRoundImg(getApplicationContext(), url, view, round);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadByImageLoader(@NonNull IMAGE view, @Nullable String url) {
            // 测试比较加载速度使用
            ImageLoader.getInstance().displayImage(url, view, BOUTIQUE_OPTIPON);
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageRes(@NonNull IMAGE view, @Nullable int resId) {
            GlideUtil.getInstance().displayLocRes(getApplicationContext(), resId, view);
        }
    });
}
Also used : HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) IInnerImageSetter(com.example.test.andlang.util.imageload.IInnerImageSetter) UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) LruMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Aggregations

IInnerImageSetter (com.example.test.andlang.util.imageload.IInnerImageSetter)1 UnlimitedDiskCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache)1 HashCodeFileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator)1 LruMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache)1 ImageLoader (com.nostra13.universalimageloader.core.ImageLoader)1 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)1 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)1 File (java.io.File)1