Android5.1 Gallery Gallery2 Code Analysis data loading process

Source: Internet
Author: User

Picture data loading process.

Gallery---->galleryactivity------>albumsetpage------->albumpage--------->photopage

Album set photo set a picture

1,albumsetpage.java

private void Initializedata (Bundle data) {

String MediaPath = data.getstring (Albumsetpage.key_media_path);

Mmediaset = Mactivity.getdatamanager (). Getmediaset (MediaPath);

Mselectionmanager.setsourcemediaset (Mmediaset);

Malbumsetdataadapter = new Albumsetdataloader (

Mactivity, Mmediaset, data_cache_size);

Malbumsetdataadapter.setloadinglistener (New Myloadinglistener ());

}

add back function, when Albumsetdataloader.java when changes occur, update the interface .

2,albumsetdataloader.java

public void Resume () {

Msource.addcontentlistener (Msourcelistener);

Mreloadtask = new Reloadtask ();

Mreloadtask.start ();

Adds a callback function that loads data when the database changes.

3,localalbumset.java (extends MediaSet)

public void Addcontentlistener (Contentlistener listener) {

M: [BUG. MODIFY] Avoid concurrentmodificationexception @{

/*mlisteners.put (listener, NULL); */

Synchronized (Weak_hash_map_lock) {

Mlisteners.put (listener, NULL);

}

Increase the callback to deal directly with the database.

4,datamanager.java

Public synchronized void Initializesourcemap () {

if (!msourcemap.isempty ()) return;

The order matters, the UriSource must come last

Addsource (New Localsource (mapplication));

New Localsource.java

5,localsource.java (extends MediaSource)

@Override

Public mediaobject createmediaobject (path Path) {

Galleryapp app = Mapplication;

Switch (mmatcher.match (path)) {

Case Local_all_albumset:

Case Local_image_albumset:

Case Local_video_albumset:

return new Localalbumset (path, mapplication);

New Localalbumset

6,localalbumset.java (extends MediaSet)

Public Localalbumset (path path, Galleryapp application) {

Super (Path, Nextversionnumber ());

mapplication = Application;

Mhandler = new Handler (Application.getmainlooper ());

Mtype = Gettypefrompath (path);

Mnotifier = new Changenotifier (this, mwatchuris, application);

Mname = Application.getresources (). GetString (

R.string.set_label_local_albums);

}

private static final uri[] Mwatchuris =

{Images.Media.EXTERNAL_CONTENT_URI, Video.Media.EXTERNAL_CONTENT_URI};

will monitor the image and video URLs to be monitored Add to Changenotifier the.

7,changenotifier.java

Public Changenotifier (MediaSet set, uri[] URIs, Galleryapp application) {

Mmediaset = set;

for (int i = 0; i < uris.length; i++) {

Application.getdatamanager (). Registerchangenotifier (Uris[i], this);

Register the URL.

8,datamanager.java

public void Registerchangenotifier (Uri uri, Changenotifier notifier) {

Notifybroker broker = NULL;

Synchronized (MNOTIFIERMAP) {

Broker = Mnotifiermap.get (URI);

if (broker = = null) {

Broker = new Notifybroker (Mdefaultmainhandler);

Mapplication.getcontentresolver ()

. Registercontentobserver (URI, true, broker);

Mnotifiermap.put (URI, broker);

}

}

Broker.registernotifier (notifier);

}

the URL and Notifybroker to associate, when the URL Callback class broker is called when a change occurs

9,datamanager.java

private static class Notifybroker extends Contentobserver {

@Override

Public synchronized void OnChange (Boolean selfchange) {

For (Changenotifier Notifier:mNotifiers.keySet ()) {

Notifier.onchange (Selfchange);

}

}

when the URL is called when a change occurs. Notifier.onchange (Selfchange)

----- àmmediaset.notifycontentchanged ();(Changenotifier.java)

-- àlistener.oncontentdirty ();(Localalbumset.java (extends MediaSet))

Android5.1 Gallery Gallery2 Code Analysis data loading process

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.