Android4.4 Telephony流程分析——連絡人(Contact)列表縮圖的載入過程

來源:互聯網
上載者:User

Android4.4 Telephony流程分析——連絡人(Contact)列表縮圖的載入過程

本文代碼以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中。

 

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.