diff options
author | Adam Cohen <adamcohen@google.com> | 2012-01-23 17:28:51 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2012-02-13 13:30:32 -0800 |
commit | ed66b2bac7447febe2e405b4ce725cae4f6b5988 (patch) | |
tree | 8c3e31c514a976a9d1e7045206e21da12c031559 /src/com/android/launcher2/PagedViewWidget.java | |
parent | 933cc5061100f22c22d66d280b6fdd07634f45a6 (diff) | |
download | android_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.tar.gz android_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.tar.bz2 android_packages_apps_Trebuchet-ed66b2bac7447febe2e405b4ce725cae4f6b5988.zip |
Improving widget transitions:
-> When a widget has no configuration activity, we bind
and inflate it when the user picks it up. This allows
us to smoothly transition between it's preview and
some actual state of the widget when it is dropped.
-> When a widget has a configuration activity, we delay
the above process until the configuration activity
has been run at which time we transition between
the preview and the actual widget.
Change-Id: I5265cd98400d70e5e75c3dcd21e322ed0b352d7b
Diffstat (limited to 'src/com/android/launcher2/PagedViewWidget.java')
-rw-r--r-- | src/com/android/launcher2/PagedViewWidget.java | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java index 12e9c4673..5ba869118 100644 --- a/src/com/android/launcher2/PagedViewWidget.java +++ b/src/com/android/launcher2/PagedViewWidget.java @@ -23,6 +23,7 @@ import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -40,6 +41,9 @@ public class PagedViewWidget extends LinearLayout { private ImageView mPreviewImageView; private String mDimensionsFormatString; + CheckForShortPress mPendingCheckForShortPress = null; + ShortPressListener mShortPressListener = null; + boolean mShortPressTriggered = false; public PagedViewWidget(Context context) { this(context, null); @@ -127,8 +131,67 @@ public class PagedViewWidget extends LinearLayout { } } + void setShortPressListener(ShortPressListener listener) { + mShortPressListener = listener; + } + + interface ShortPressListener { + void onShortPress(View v); + void cleanUpShortPress(View v); + } + + class CheckForShortPress implements Runnable { + public void run() { + if (mShortPressListener != null) { + mShortPressListener.onShortPress(PagedViewWidget.this); + } + mShortPressTriggered = true; + } + } + + private void checkForShortPress() { + if (mPendingCheckForShortPress == null) { + mPendingCheckForShortPress = new CheckForShortPress(); + } + postDelayed(mPendingCheckForShortPress, 120); + } + + /** + * Remove the longpress detection timer. + */ + private void removeShortPressCallback() { + if (mPendingCheckForShortPress != null) { + removeCallbacks(mPendingCheckForShortPress); + } + } + + private void cleanUpShortPress() { + removeShortPressCallback(); + if (mShortPressTriggered) { + if (mShortPressListener != null) { + mShortPressListener.cleanUpShortPress(PagedViewWidget.this); + } + mShortPressTriggered = false; + } + } + @Override public boolean onTouchEvent(MotionEvent event) { + super.onTouchEvent(event); + + switch (event.getAction()) { + case MotionEvent.ACTION_UP: + cleanUpShortPress(); + break; + case MotionEvent.ACTION_DOWN: + checkForShortPress(); + break; + case MotionEvent.ACTION_CANCEL: + cleanUpShortPress(); + break; + case MotionEvent.ACTION_MOVE: + break; + } // We eat up the touch events here, since the PagedView (which uses the same swiping // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when // the user is scrolling between pages. This means that if the pages themselves don't @@ -136,6 +199,6 @@ public class PagedViewWidget extends LinearLayout { // onTouchEvent() handling will prevent further intercept touch events from being called // (it's the same view in that case). This is not ideal, but to prevent more changes, // we just always mark the touch event as handled. - return super.onTouchEvent(event) || true; + return true; } } |