diff options
author | Chih-Chung Chang <chihchung@google.com> | 2012-05-09 21:17:10 +0800 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2012-05-09 21:17:10 +0800 |
commit | 3b4a8aeb0353fa18a2b5267b3952a80a6c6d4d13 (patch) | |
tree | 6a199b625e2ad628a7d6c7105e2ad488a20dc8f2 /src/com/android/gallery3d/data | |
parent | 78d5dac00fd19fdc34269aae7653f9f4839dc357 (diff) | |
download | android_packages_apps_Gallery2-3b4a8aeb0353fa18a2b5267b3952a80a6c6d4d13.tar.gz android_packages_apps_Gallery2-3b4a8aeb0353fa18a2b5267b3952a80a6c6d4d13.tar.bz2 android_packages_apps_Gallery2-3b4a8aeb0353fa18a2b5267b3952a80a6c6d4d13.zip |
Handle ScreenNail size change.
Bug: 6355399
Change-Id: Ice7560c12aa06cf8ac58cc3883f0888b5c6e71a5
Diffstat (limited to 'src/com/android/gallery3d/data')
-rw-r--r-- | src/com/android/gallery3d/data/SnailAlbum.java | 17 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/SnailItem.java | 16 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/SnailSource.java | 26 |
3 files changed, 34 insertions, 25 deletions
diff --git a/src/com/android/gallery3d/data/SnailAlbum.java b/src/com/android/gallery3d/data/SnailAlbum.java index 39467bbaa..cd4f803ad 100644 --- a/src/com/android/gallery3d/data/SnailAlbum.java +++ b/src/com/android/gallery3d/data/SnailAlbum.java @@ -17,15 +17,17 @@ package com.android.gallery3d.data; import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; // This is a simple MediaSet which contains only one MediaItem -- a SnailItem. public class SnailAlbum extends MediaSet { - - private MediaItem mItem; + private static final String TAG = "SnailAlbum"; + private SnailItem mItem; + private AtomicBoolean mDirty = new AtomicBoolean(false); public SnailAlbum(Path path, MediaItem item) { super(path, nextVersionNumber()); - mItem = item; + mItem = (SnailItem) item; } @Override @@ -57,6 +59,15 @@ public class SnailAlbum extends MediaSet { @Override public long reload() { + if (mDirty.compareAndSet(true, false)) { + mItem.updateVersion(); + mDataVersion = nextVersionNumber(); + } return mDataVersion; } + + public void notifyChange() { + mDirty.set(true); + notifyContentChanged(); + } } diff --git a/src/com/android/gallery3d/data/SnailItem.java b/src/com/android/gallery3d/data/SnailItem.java index 2836a19bb..fdb1b0d56 100644 --- a/src/com/android/gallery3d/data/SnailItem.java +++ b/src/com/android/gallery3d/data/SnailItem.java @@ -27,11 +27,11 @@ import com.android.gallery3d.util.ThreadPool.JobContext; // used so we can show an foreign component (like an // android.view.View) instead of a Bitmap. public class SnailItem extends MediaItem { + private static final String TAG = "SnailItem"; private ScreenNail mScreenNail; - public SnailItem(Path path, ScreenNail screenNail) { + public SnailItem(Path path) { super(path, nextVersionNumber()); - mScreenNail = screenNail; } @Override @@ -77,4 +77,16 @@ public class SnailItem extends MediaItem { public int getHeight() { return 0; } + + ////////////////////////////////////////////////////////////////////////// + // Extra methods for SnailItem + ////////////////////////////////////////////////////////////////////////// + + public void setScreenNail(ScreenNail screenNail) { + mScreenNail = screenNail; + } + + public void updateVersion() { + mDataVersion = nextVersionNumber(); + } } diff --git a/src/com/android/gallery3d/data/SnailSource.java b/src/com/android/gallery3d/data/SnailSource.java index e74a8bb94..5f663d2ec 100644 --- a/src/com/android/gallery3d/data/SnailSource.java +++ b/src/com/android/gallery3d/data/SnailSource.java @@ -15,9 +15,7 @@ */ package com.android.gallery3d.data; -import android.util.SparseArray; import com.android.gallery3d.app.GalleryApp; -import com.android.gallery3d.ui.ScreenNail; public class SnailSource extends MediaSource { private static final String TAG = "SnailSource"; @@ -27,7 +25,6 @@ public class SnailSource extends MediaSource { private GalleryApp mApplication; private PathMatcher mMatcher; private static int sNextId; - private static SparseArray<ScreenNail> sRegistry = new SparseArray<ScreenNail>(); public SnailSource(GalleryApp application) { super("snail"); @@ -49,19 +46,17 @@ public class SnailSource extends MediaSource { return new SnailAlbum(path, item); case SNAIL_ITEM: { int id = mMatcher.getIntVar(0); - return new SnailItem(path, lookupScreenNail(id)); + return new SnailItem(path); } } return null; } - // Registers a ScreenNail and returns the id of it. You can obtain the Path - // of the MediaItem associated with the ScreenNail by getItemPath(), and the - // Path of the MediaSet containing that MediaItem by getSetPath(). - public static synchronized int registerScreenNail(ScreenNail s) { - int id = sNextId++; - sRegistry.put(id, s); - return id; + // Registers a new SnailAlbum containing a SnailItem and returns the id of + // them. You can obtain the Path of the SnailAlbum and SnailItem associated + // with the id by getSetPath and getItemPath(). + public static synchronized int newId() { + return sNextId++; } public static Path getSetPath(int id) { @@ -71,13 +66,4 @@ public class SnailSource extends MediaSource { public static Path getItemPath(int id) { return Path.fromString("/snail/item").getChild(id); } - - public static synchronized void unregisterScreenNail(ScreenNail s) { - int index = sRegistry.indexOfValue(s); - sRegistry.removeAt(index); - } - - private static synchronized ScreenNail lookupScreenNail(int id) { - return sRegistry.get(id); - } } |