summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorChih-Chung Chang <chihchung@google.com>2012-05-09 21:17:10 +0800
committerChih-Chung Chang <chihchung@google.com>2012-05-09 21:17:10 +0800
commit82f7ac999aae05b251cfe2c886020780832cd4a3 (patch)
treed025462eb456fc3fb63a1ac0f18d4080fc9923e0 /src/com/android
parentebf0f78490f851766f643d3d45fa351f4e92e091 (diff)
downloadandroid_packages_apps_Snap-82f7ac999aae05b251cfe2c886020780832cd4a3.tar.gz
android_packages_apps_Snap-82f7ac999aae05b251cfe2c886020780832cd4a3.tar.bz2
android_packages_apps_Snap-82f7ac999aae05b251cfe2c886020780832cd4a3.zip
Handle ScreenNail size change.
Bug: 6355399 Change-Id: Ice7560c12aa06cf8ac58cc3883f0888b5c6e71a5
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/gallery3d/app/AppBridge.java2
-rw-r--r--src/com/android/gallery3d/app/PhotoPage.java32
-rw-r--r--src/com/android/gallery3d/data/SnailAlbum.java17
-rw-r--r--src/com/android/gallery3d/data/SnailItem.java16
-rw-r--r--src/com/android/gallery3d/data/SnailSource.java26
-rw-r--r--src/com/android/gallery3d/ui/PhotoView.java4
6 files changed, 59 insertions, 38 deletions
diff --git a/src/com/android/gallery3d/app/AppBridge.java b/src/com/android/gallery3d/app/AppBridge.java
index e8cf8731b..90cbd0bbb 100644
--- a/src/com/android/gallery3d/app/AppBridge.java
+++ b/src/com/android/gallery3d/app/AppBridge.java
@@ -57,6 +57,8 @@ public abstract class AppBridge implements Parcelable {
public boolean switchWithCaptureAnimation(int offset);
// Enable or disable the swiping gestures (the default is enabled).
public void setSwipingEnabled(boolean enabled);
+ // Notify that the ScreenNail is changed.
+ public void notifyScreenNailChanged();
}
// If server is null, the services are not available.
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index 783d0ed25..3f9f05728 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -44,6 +44,8 @@ import com.android.gallery3d.data.MediaObject;
import com.android.gallery3d.data.MediaSet;
import com.android.gallery3d.data.MtpDevice;
import com.android.gallery3d.data.Path;
+import com.android.gallery3d.data.SnailAlbum;
+import com.android.gallery3d.data.SnailItem;
import com.android.gallery3d.data.SnailSource;
import com.android.gallery3d.picasasource.PicasaSource;
import com.android.gallery3d.ui.DetailsHelper;
@@ -116,8 +118,8 @@ public class PhotoPage extends ActivityState implements
// This is the original mSetPathString before adding the camera preview item.
private String mOriginalSetPathString;
private AppBridge mAppBridge;
- private ScreenNail mScreenNail;
- private MediaItem mScreenNailItem;
+ private SnailItem mScreenNailItem;
+ private SnailAlbum mScreenNailSet;
private OrientationManager mOrientationManager;
private NfcAdapter mNfcAdapter;
@@ -180,14 +182,17 @@ public class PhotoPage extends ActivityState implements
mOrientationManager.lockOrientation();
// Get the ScreenNail from AppBridge and register it.
- mScreenNail = mAppBridge.attachScreenNail();
- int id = SnailSource.registerScreenNail(mScreenNail);
+ int id = SnailSource.newId();
Path screenNailSetPath = SnailSource.getSetPath(id);
Path screenNailItemPath = SnailSource.getItemPath(id);
- mScreenNailItem = (MediaItem) mActivity.getDataManager()
+ mScreenNailSet = (SnailAlbum) mActivity.getDataManager()
+ .getMediaObject(screenNailSetPath);
+ mScreenNailItem = (SnailItem) mActivity.getDataManager()
.getMediaObject(screenNailItemPath);
+ mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
- // Combine the original MediaSet with the one for CameraScreenNail.
+ // Combine the original MediaSet with the one for ScreenNail
+ // from AppBridge.
mSetPathString = "/combo/item/{" + screenNailSetPath +
"," + mSetPathString + "}";
@@ -427,8 +432,7 @@ public class PhotoPage extends ActivityState implements
protected void onBackPressed() {
if (mShowDetails) {
hideDetails();
- } else if (mScreenNail == null
- || !switchWithCaptureAnimation(-1)) {
+ } else if (mAppBridge == null || !switchWithCaptureAnimation(-1)) {
// We are leaving this page. Set the result now.
setResult();
super.onBackPressed();
@@ -490,6 +494,12 @@ public class PhotoPage extends ActivityState implements
}
@Override
+ public void notifyScreenNailChanged() {
+ mScreenNailItem.setScreenNail(mAppBridge.attachScreenNail());
+ mScreenNailSet.notifyChange();
+ }
+
+ @Override
protected boolean onCreateActionBar(Menu menu) {
MenuInflater inflater = ((Activity) mActivity).getMenuInflater();
inflater.inflate(R.menu.photo, menu);
@@ -744,11 +754,11 @@ public class PhotoPage extends ActivityState implements
@Override
protected void onDestroy() {
if (mAppBridge != null) {
- // Unregister the ScreenNail and notify mAppBridge.
- SnailSource.unregisterScreenNail(mScreenNail);
+ mScreenNailItem.setScreenNail(null);
mAppBridge.detachScreenNail();
mAppBridge = null;
- mScreenNail = null;
+ mScreenNailSet = null;
+ mScreenNailItem = null;
}
mOrientationManager.removeListener(this);
mActivity.getGLRoot().setOrientationSource(null);
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);
- }
}
diff --git a/src/com/android/gallery3d/ui/PhotoView.java b/src/com/android/gallery3d/ui/PhotoView.java
index 3c90d9982..cd11b8e27 100644
--- a/src/com/android/gallery3d/ui/PhotoView.java
+++ b/src/com/android/gallery3d/ui/PhotoView.java
@@ -377,8 +377,8 @@ public class PhotoView extends GLView {
mDisplayRotation = displayRotation;
mCompensation = compensation;
- // We need to change the size and rotation of the Camera ScreenNail, but
- // we don't want it to animate because the size doen't actually
+ // We need to change the size and rotation of the Camera ScreenNail,
+ // but we don't want it to animate because the size doen't actually
// change in the eye of the user.
for (int i = -SCREEN_NAIL_MAX; i <= SCREEN_NAIL_MAX; i++) {
Picture p = mPictures.get(i);