summaryrefslogtreecommitdiff
path: root/core/java/android/widget/Gallery.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:51:23 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:51:23 -0800
commitb798689749c64baba81f02e10cf2157c747d6b46 (patch)
treeda394a395ddb1a6cf69193314846b03fe47a397e /core/java/android/widget/Gallery.java
parentf013e1afd1e68af5e3b868c26a653bbfb39538f8 (diff)
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'core/java/android/widget/Gallery.java')
-rw-r--r--core/java/android/widget/Gallery.java52
1 files changed, 47 insertions, 5 deletions
diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java
index d886155f3aef..cabca4024d26 100644
--- a/core/java/android/widget/Gallery.java
+++ b/core/java/android/widget/Gallery.java
@@ -56,7 +56,13 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
private static final String TAG = "Gallery";
private static final boolean localLOGV = Config.LOGV;
-
+
+ /**
+ * Duration in milliseconds from the start of a scroll during which we're
+ * unsure whether the user is scrolling or flinging.
+ */
+ private static final int SCROLL_TO_FLING_UNCERTAINTY_TIMEOUT = 250;
+
/**
* Horizontal spacing between items.
*/
@@ -104,6 +110,17 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
* Executes the delta scrolls from a fling or scroll movement.
*/
private FlingRunnable mFlingRunnable = new FlingRunnable();
+
+ /**
+ * Sets mSuppressSelectionChanged = false. This is used to set it to false
+ * in the future. It will also trigger a selection changed.
+ */
+ private Runnable mDisableSuppressSelectionChangedRunnable = new Runnable() {
+ public void run() {
+ mSuppressSelectionChanged = false;
+ selectionChanged();
+ }
+ };
/**
* When fling runnable runs, it resets this to false. Any method along the
@@ -142,6 +159,12 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
private boolean mReceivedInvokeKeyDown;
private AdapterContextMenuInfo mContextMenuInfo;
+
+ /**
+ * If true, this onScroll is the first for this user's drag (remember, a
+ * drag sends many onScrolls).
+ */
+ private boolean mIsFirstScroll;
public Gallery(Context context) {
this(context, null);
@@ -861,8 +884,13 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (!mShouldCallbackDuringFling) {
+ // We want to suppress selection changes
+
+ // Remove any future code to set mSuppressSelectionChanged = false
+ removeCallbacks(mDisableSuppressSelectionChangedRunnable);
+
// This will get reset once we scroll into slots
- mSuppressSelectionChanged = true;
+ if (!mSuppressSelectionChanged) mSuppressSelectionChanged = true;
}
// Fling the gallery!
@@ -891,13 +919,24 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
// As the user scrolls, we want to callback selection changes so related-
// info on the screen is up-to-date with the gallery's selection
- if (mSuppressSelectionChanged) {
- mSuppressSelectionChanged = false;
+ if (!mShouldCallbackDuringFling) {
+ if (mIsFirstScroll) {
+ /*
+ * We're not notifying the client of selection changes during
+ * the fling, and this scroll could possibly be a fling. Don't
+ * do selection changes until we're sure it is not a fling.
+ */
+ if (!mSuppressSelectionChanged) mSuppressSelectionChanged = true;
+ postDelayed(mDisableSuppressSelectionChangedRunnable, SCROLL_TO_FLING_UNCERTAINTY_TIMEOUT);
+ }
+ } else {
+ if (mSuppressSelectionChanged) mSuppressSelectionChanged = false;
}
// Track the motion
trackMotionScroll(-1 * (int) distanceX);
-
+
+ mIsFirstScroll = false;
return true;
}
@@ -917,6 +956,9 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
mDownTouchView.setPressed(true);
}
+ // Reset the multiple-scroll tracking state
+ mIsFirstScroll = true;
+
// Must return true to get matching events for this down event.
return true;
}