温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

优秀的开源框架学习

发布时间:2020-07-05 19:49:32 来源:网络 阅读:447 作者:屠夫章哥 栏目:移动开发

ButterKnife基本使用 http://www.cnblogs.com/mengdd/archive/2015/06/23/4595973.html 


Android SlidingMenu 使用详解

http://blog.csdn.net/lmj623565791/article/details/36677279


ImageLoader的源码分析:

这个库封装的层次实在是太多了!!!可以借鉴作者是怎么封装类的!!!


DisplayImageOptions  Builder     配置一些参数

ImageLoaderEngine             引擎类

ProcessAndDisplayImageTask        

ImageLoadingInfo              存储一些下载相关的信息

。。。 

从ImageLoader.getInstance().displayImage这个方法追溯,这个方法可以选传url,p_w_picpath,也可以传

入参数和进度监听者。

1)ImageLoader的实例化采用单例设计模式

2)ImageLoader的初始化init方法会初始化引擎ImageLoaderEngine,并传入DisplayImageOptions参数

  》ImageLoaderEngine封装了一些线程池的操作

  》这个类里还用到FlushedInputStream这个类,FlushedInputStream会避免个别的错误Issue 6066:  BitmapFactory.decodeStream() fails if InputStream.skip() does not skip fully  

  》类中用同步Map来存储ImageView的缓存key值。 

  》submit会将任务提交到线程池

3)判断uri为不为null,为null会将参数DisplayImageOptions中的默认图片设置给ImageView。

  同时会回调监听者的一些方法

 从参数DisplayImageOptions中得到最大的图片尺寸

  根据url和图片的最大尺寸来生成缓存的key

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 大致的思路:

 》在Application里init  

   初始化参数DisplayImageOptions并传递给ImageLoaderEngine类。

   ImageLoaderEngine主要是维护了一些线程池,对Runnable任务进行管理。

   任务主要是通过Handler来实现线程间的通讯。

 》在display里解析DisplayImageOptions封装的参数信息 

  

 》判断对url==null作处理 

 

 》获取key

 String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);

  ++DisplayImageOptions.Builder在初始化build()的时候,如果用户没有设置某些参数,它会自动

  进行一些默认设置,通过DefaultConfigurationFactory这个类。

public ImageLoaderConfiguration build() {
			initEmptyFieldsWithDefaultValues();
			return new ImageLoaderConfiguration(this);
}

  ++initEmptyFieldsWithDefaultValues方法进行的一些主要的初始化操作:

 如diskCache、memoryCache、downloader等,很好地体现了面向对象的编程思想。

private void initEmptyFieldsWithDefaultValues() {
			if (taskExecutor == null) {
				taskExecutor = DefaultConfigurationFactory
						.createExecutor(threadPoolSize, threadPriority, tasksProcessingType);
			} else {
				customExecutor = true;
			}
			if (taskExecutorForCachedImages == null) {
				taskExecutorForCachedImages = DefaultConfigurationFactory
						.createExecutor(threadPoolSize, threadPriority, tasksProcessingType);
			} else {
				customExecutorForCachedImages = true;
			}
			if (diskCache == null) {
				if (diskCacheFileNameGenerator == null) {
					diskCacheFileNameGenerator = DefaultConfigurationFactory.createFileNameGenerator();
				}
				diskCache = DefaultConfigurationFactory
						.createDiskCache(context, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
			}
			if (memoryCache == null) {
				memoryCache = DefaultConfigurationFactory.createMemoryCache(context, memoryCacheSize);
			}
			if (denyCacheImageMultipleSizesInMemory) {
				memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
			}
			if (downloader == null) {
				downloader = DefaultConfigurationFactory.createImageDownloader(context);
			}
			if (decoder == null) {
				decoder = DefaultConfigurationFactory.createImageDecoder(writeLogs);
			}
			if (defaultDisplayImageOptions == null) {
				defaultDisplayImageOptions = DisplayImageOptions.createSimple();
			}
		}
	}

 

 》根据key从缓存中获取Bitmap

 Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);

  判断缓存中有没有得到Bitmap

   

  LoadAndDisplayImageTask,从网络上下载图片位于tryLoadBitmap()这个方法当中

  通过BaseImageDecoder这个类的decode方法下载网络图片,通过BaseImageDownloader获得输入流,

 网络请求采用的是HttpURLConnection。


Freco图片加载框架:

1.缓存

在5.0以下系统,Bitmap缓存位于ashmem,这样Bitmap对象的创建和释放将不会引发GC,更少的GC会使你的APP运行得更加流畅。

5.0及其以上系统,相比之下,内存管理有了很大改进,所以Bitmap缓存直接位于Java的heap上。

当应用在后台运行是,该内存会被清空。

2.渐进式JPEG图

Fresco 支持渐进式的网络JPEG图。在开始加载之后,图会从模糊到清晰渐渐呈现。

你可以设置一个清晰度标准,在未达到这个清晰度之前,会一直显示占位图。

渐进式JPEG图仅仅支持网络图。

3.渐进式JPEG图

   

  

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI