From 9af0b4f7be14f2b3ed0ecc843c57ea47ec288e55 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 2 Jun 2009 21:56:27 -0700 Subject: [PATCH] Add new listener to GestureOverlayView. This listener fires whenever the overlay thinks the user is starting a new gesture. This allows Home to snap the workspace back to its original position during a gesture operation. --- api/current.xml | 93 ++++++++++++++++--- .../android/gesture/GestureOverlayView.java | 47 +++++++++- 2 files changed, 124 insertions(+), 16 deletions(-) diff --git a/api/current.xml b/api/current.xml index 3a310347188c5..9e9eaad45e0e6 100644 --- a/api/current.xml +++ b/api/current.xml @@ -1145,6 +1145,17 @@ visibility="public" > + + - - + + + + + + + + + + + + + + + + + + + + mOnGesturePerformedListeners = new ArrayList(); + // TODO: Make this a list of WeakReferences + private final ArrayList mOnGesturingListeners = + new ArrayList(); private boolean mHandleGestureActions; @@ -319,6 +322,18 @@ public class GestureOverlayView extends FrameLayout { mHandleGestureActions = false; } + public void addOnGesturingListener(OnGesturingListener listener) { + mOnGesturingListeners.add(listener); + } + + public void removeOnGesturingListener(OnGesturingListener listener) { + mOnGesturingListeners.remove(listener); + } + + public void removeAllOnGesturingListeners() { + mOnGesturingListeners.clear(); + } + public boolean isGesturing() { return mIsGesturing; } @@ -401,7 +416,7 @@ public class GestureOverlayView extends FrameLayout { MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); final ArrayList listeners = mOnGestureListeners; - final int count = listeners.size(); + int count = listeners.size(); for (int i = 0; i < count; i++) { listeners.get(i).onGestureCancelled(this, event); } @@ -411,6 +426,12 @@ public class GestureOverlayView extends FrameLayout { clear(false); mIsGesturing = false; mStrokeBuffer.clear(); + + final ArrayList otherListeners = mOnGesturingListeners; + count = otherListeners.size(); + for (int i = 0; i < count; i++) { + otherListeners.get(i).onGesturingEnded(this); + } } @Override @@ -577,6 +598,12 @@ public class GestureOverlayView extends FrameLayout { mIsGesturing = true; setCurrentColor(mCertainGestureColor); + + final ArrayList listeners = mOnGesturingListeners; + int count = listeners.size(); + for (int i = 0; i < count; i++) { + listeners.get(i).onGesturingStarted(this); + } } } } @@ -621,6 +648,12 @@ public class GestureOverlayView extends FrameLayout { mStrokeBuffer.clear(); mIsGesturing = false; + + final ArrayList listeners = mOnGesturingListeners; + int count = listeners.size(); + for (int i = 0; i < count; i++) { + listeners.get(i).onGesturingEnded(this); + } } private void cancelGesture(MotionEvent event) { @@ -635,12 +668,10 @@ public class GestureOverlayView extends FrameLayout { } private void fireOnGesturePerformed() { - final ArrayList actionListeners = - mOnGesturePerformedListeners; + final ArrayList actionListeners = mOnGesturePerformedListeners; final int count = actionListeners.size(); for (int i = 0; i < count; i++) { - actionListeners.get(i).onGesturePerformed(GestureOverlayView.this, - mCurrentGesture); + actionListeners.get(i).onGesturePerformed(GestureOverlayView.this, mCurrentGesture); } } @@ -683,6 +714,12 @@ public class GestureOverlayView extends FrameLayout { } } + public static interface OnGesturingListener { + void onGesturingStarted(GestureOverlayView overlay); + + void onGesturingEnded(GestureOverlayView overlay); + } + public static interface OnGestureListener { void onGestureStarted(GestureOverlayView overlay, MotionEvent event);