Android4.0 Gallery Gallery2 Code Analysis (ii) data management and data loading

Source: Internet
Author: User

Android4.0 Gallery Gallery2 Code Analysis (ii) data management and data loading2012-09-07 11:19 8152 People read review (a) collection report Code Analysis Android Album optimization work

Android4.0 Gallery Gallery2 Code Analysis (ii) data management and data loading

Image Library Data Management

Gallery2 Data Management DataManager (responsibilities: Managing Data Sources)-MediaSource (Responsibilities: Managing Datasets)-MediaSet (Responsibilities: Managing Data Items). All data sources are initialized in DataManager (Localsource, Picasasource, Mtpsource, Combosource, Clustersource, Filtersource, UriSource, Snailsource), the data source is placed in a hash table, providing access operations. MediaSource is responsible for managing the data set, taking Loacalsource as an example, from his createmediaobject function can be seen, according to the path he can create Localmediaset, Localmedia, Localimage, Localvideo and so on. Mediaset is responsible for managing data item Mediaitem. Gallery Data Management brief diagram-1


Figure-1: Gallery Data Management simplified diagram

The loading process for two data items (Mediaitem).

Here's an example of the process of albumpage loading a thumbnail list. Albumsetpage loading album thumbnails and photopage loading a larger image, please analyze it yourself.

In the album page (albumpage) and thumbnail data loading are related to the two member variables Albumdataloader and Albumslotrender. Albumdataloader is responsible for maintaining the data to be loaded to provide a management, the data items to be loaded Mediaitem placed in the linked list for access operations, dynamic additions and deletions to change the operation. In the Onresume function of the Albumpage class, call Albumdataloader's Resume,albumdataloader resume creates a thread that handles changes to the data at any time (Mediaitem additions and deletions). The Albumdataloader process is shown in Figure 2.

The action process of Figure -2:albumdataloader

Albumdataloader is responsible for the maintenance of the data model, Albumslotrender is responsible for the data thumbnail loading work, in order to improve performance, data loading uses a "thread pool." Albumslotrender gets the data to be loaded from Albumdataloader Mediaitem, depending on the state of each mediaitem to determine whether the bitmap thumbnail is needed to load, recycle, or wait. For thumbnails that need to be loaded, commit to the thread pool. The Albumslotrender process is shown in Figure 3. Data loading process, "synchronization problem" in fact, it needs to focus on analysis, because of limited time, here is the abbreviation, forgive me!

The action process of Figure -3:albumslotrender

Three follow-up code analysis, general outline

Android4.0 Gallery Gallery2 Code Analysis (iii) State Management and window switching

Android4.0 Gallery Gallery2 Code Analysis (iv) Message processing (clicks and gestures)

Android4.0 Gallery Gallery2 Code Analysis (v) management of various data sources and data sources

Android4.0 Gallery Gallery2 Code Analysis (vi) possible rendering of data elements and their diversity

Android4.0 Gallery Gallery2 Code Analysis (vii) Implementation of remote control

Android4.0 Gallery Gallery2 Code Analysis (eight) and data-scanning thread data interaction

Android4.0 Gallery Gallery2 Code Analysis (ix) Some of the areas that can be optimized

Android4.0 Gallery Gallery2 Code Analysis (ii) data management and data loading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.