Android4.4 Telephony流程分析——联系人(Contact)列表缩略图的加载过程

来源:互联网 发布:matlab字符串数组赋值 编辑:程序博客网 时间:2024/04/30 12:36

本文代码以MTK平台Android 4.4.2为分析对象,与Google原生AOSP有些许差异,请读者知悉。


Android联系人列表的缩略图加载主要用到ContactPhotoManager.java这个类,这是个抽象类,实现了ComponentCallbacks2接口,其内部有个它的具体实现类,叫ContactPhotoManagerImpl,ContactPhotoManagerImpl继承了ContactPhotoManager并实现了android.os.Handler.Callback接口,里面主要用了预加载、异步查询和两个LruCache缓存对象(mBitmapHolderCache和mBitmapCache)来提升缩略图的显示速度,关于LruCache类的使用,可查看Android官方文档Caching Bitmaps或者中文翻译版。本文主要了解缩略图的预加载(Contact.apk启动时就开始加载,准确的说是联系人收藏页面(ContactTileListFragment)加载时)、异步查询过程(ListView显示时使用getView()对缩略图的加载过程与预加载类似)。



预加载过程主要是关注加载状态的变化mPreloadStatus就比较容易理解,

     private static final int PRELOAD_STATUS_NOT_STARTED = 0; //预加载还没开始        private static final int PRELOAD_STATUS_IN_PROGRESS = 1; //预加载进行中        private static final int PRELOAD_STATUS_DONE = 2; //预加载完成
step16,queryPhotosForPreload()中查询contact2.db的contact表,找到有缩略图的联系人的PHOTO_ID,预加载最多加载MAX_PHOTOS_TO_PRELOAD条,

        /**         * Maximum number of photos to preload.  If the cache size is 2Mb and         * the expected average size of a photo is 4kb, then this number should be 2Mb/4kb = 500.         */        private static final int MAX_PHOTOS_TO_PRELOAD = 100;

将查询到的PHOTO_ID放入预加载列表mPreloadPhotoIds中。

step19,

            int preloadSize = mPreloadPhotoIds.size();            while (preloadSize > 0 && mPhotoIds.size() < PRELOAD_BATCH) {                preloadSize--;                count++;                Long photoId = mPreloadPhotoIds.get(preloadSize);                mPhotoIds.add(photoId);                mPhotoIdsAsStrings.add(photoId.toString());                mPreloadPhotoIds.remove(preloadSize);            }

给mPhotoIds和mPhotoIdsAsStrings赋值,规则情况源码。

step20,loadThumbnails()中对会用到上面两个集合,再次查询Data表,将缩略图查询出来。step24会将缩略图缓存到LruCache对象mBitmapHolderCache中。


心急下班,不说了。。。



右键复制图片地址,在浏览器中打开即可查看大图。

未完待续,有不对的地方,请指正。



0 0