diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-08-09 20:52:54 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-08-09 20:52:54 +0200 |
commit | 1bdd1ee021d5e933b81e23fbfb39831b757abf18 (patch) | |
tree | f1720e9bcf76aaac3ccaa91ae663487cbe0b930a /src/org/cyanogenmod/wallpapers/photophase/TextureManager.java | |
parent | 8d87cd8fb5d3993a5857b54583f9a9cdd4bc78b5 (diff) | |
download | android_packages_wallpapers_PhotoPhase-1bdd1ee021d5e933b81e23fbfb39831b757abf18.tar.gz android_packages_wallpapers_PhotoPhase-1bdd1ee021d5e933b81e23fbfb39831b757abf18.tar.bz2 android_packages_wallpapers_PhotoPhase-1bdd1ee021d5e933b81e23fbfb39831b757abf18.zip |
Use an asynchronous model to communicate media partial results (#19)
MediaPictureDiscover(1/2)
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/org/cyanogenmod/wallpapers/photophase/TextureManager.java')
-rw-r--r-- | src/org/cyanogenmod/wallpapers/photophase/TextureManager.java | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java index 35f957b..6e5b577 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java +++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java @@ -284,11 +284,38 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { * {@inheritDoc} */ @Override + public void onStartMediaDiscovered(boolean userRequest) { + // No images but thread should start here to received partial data + if (mBackgroundTask != null) { + mBackgroundTask.setAvailableImages(new File[]{}); + if (!mBackgroundTask.mRun) { + mBackgroundTask.start(); + } else { + synchronized (mBackgroundTask.mLoadSync) { + mBackgroundTask.mLoadSync.notify(); + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void onPartialMediaDiscovered(File[] images, boolean userRequest) { + if (mBackgroundTask != null) { + mBackgroundTask.setPartialAvailableImages(images); + } + } + + /** + * {@inheritDoc} + */ + @Override @SuppressWarnings("boxing") - public void onMediaDiscovered(MediaPictureDiscoverer mpc, File[] images, boolean userRequest) { - // Now we have the paths of the images to use. Start a image loader - // thread to load pictures in background - // Only if the task is created + public void onEndMediaDiscovered(File[] images, boolean userRequest) { + // Now we have the paths of the images to use. Notify to the thread to + // load pictures in background if (mBackgroundTask != null) { mBackgroundTask.setAvailableImages(images); if (!mBackgroundTask.mRun) { @@ -298,7 +325,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { mBackgroundTask.mLoadSync.notify(); } } - + // Audit int found = images == null ? 0 : images.length; Log.d(TAG, "Media picture data reloaded: " + found + " images found."); @@ -369,6 +396,18 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { } /** + * Method that adds some available images. + * + * @param images The current images + */ + public void setPartialAvailableImages(File[] images) { + synchronized (mLoadSync) { + mNewImages.addAll(Arrays.asList(images)); + mEmpty = images.length == 0; + } + } + + /** * Method that reset the current available images queue. */ public void resetAvailableImages() { |