diff options
author | Adam Cohen <adamcohen@google.com> | 2012-05-11 15:57:05 -0700 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2012-05-13 15:59:07 -0700 |
commit | 0e56cc9fd6814af5813e73ba7a71bf1d51d4208a (patch) | |
tree | 8a93d6e0bde4d497db82493ab69576813c39fbbf /src/com | |
parent | 28b952ad3ec46ba9d14063797c1c96984ade8deb (diff) | |
download | packages_apps_trebuchet-0e56cc9fd6814af5813e73ba7a71bf1d51d4208a.zip packages_apps_trebuchet-0e56cc9fd6814af5813e73ba7a71bf1d51d4208a.tar.gz packages_apps_trebuchet-0e56cc9fd6814af5813e73ba7a71bf1d51d4208a.tar.bz2 |
Fixing bug where widget could get added to drag layer and not removed (issue 6282757)
Change-Id: Ibc32b48f12e1c37267e140e82e1620bcb407963c
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher2/AppsCustomizePagedView.java | 54 | ||||
-rw-r--r-- | src/com/android/launcher2/PagedViewWidget.java | 9 |
2 files changed, 41 insertions, 22 deletions
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 2518c6c..f2c50a4 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -49,7 +49,6 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; @@ -171,7 +170,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource, PagedViewIcon.PressedCallback, PagedViewWidget.ShortPressListener, LauncherTransitionable { - static final String LOG_TAG = "AppsCustomizePagedView"; + static final String TAG = "AppsCustomizePagedView"; /** * The different content types that this paged view can show. @@ -490,7 +489,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mWidgets.add(widget); } } else { - Log.e(LOG_TAG, "Widget " + widget.provider + " has invalid dimensions (" + + Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")"); } } @@ -612,32 +611,43 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void onShortPress(View v) { // We are anticipating a long press, and we use this time to load bind and instantiate // the widget. This will need to be cleaned up if it turns out no long press occurs. + if (mCreateWidgetInfo != null) { + // Just in case the cleanup process wasn't properly executed. This shouldn't happen. + cleanupWidgetPreloading(false); + } mCreateWidgetInfo = new PendingAddWidgetInfo((PendingAddWidgetInfo) v.getTag()); preloadWidget(mCreateWidgetInfo); } - private void cleanupWidgetPreloading() { - PendingAddWidgetInfo info = mCreateWidgetInfo; - mCreateWidgetInfo = null; - if (mWidgetCleanupState >= 0 && mWidgetLoadingId != -1) { - mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); - } - if (mWidgetCleanupState == WIDGET_BOUND) { - removeCallbacks(mInflateWidgetRunnable); - } else if (mWidgetCleanupState == WIDGET_INFLATED) { - AppWidgetHostView widget = info.boundWidget; - int widgetId = widget.getAppWidgetId(); - mLauncher.getAppWidgetHost().deleteAppWidgetId(widgetId); - mLauncher.getDragLayer().removeView(widget); + private void cleanupWidgetPreloading(boolean widgetWasAdded) { + if (!widgetWasAdded) { + // If the widget was not added, we may need to do further cleanup. + PendingAddWidgetInfo info = mCreateWidgetInfo; + mCreateWidgetInfo = null; + // First step was to allocate a widget id, revert that. + if ((mWidgetCleanupState == WIDGET_BOUND || mWidgetCleanupState == WIDGET_INFLATED) && + mWidgetLoadingId != -1) { + mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); + } + if (mWidgetCleanupState == WIDGET_BOUND) { + // We never actually inflated the widget, so remove the callback to do so. + removeCallbacks(mInflateWidgetRunnable); + } else if (mWidgetCleanupState == WIDGET_INFLATED) { + // The widget was inflated and added to the DragLayer -- remove it. + AppWidgetHostView widget = info.boundWidget; + mLauncher.getDragLayer().removeView(widget); + } } mWidgetCleanupState = WIDGET_NO_CLEANUP_REQUIRED; mWidgetLoadingId = -1; + mCreateWidgetInfo = null; + PagedViewWidget.resetShortPressTarget(); } @Override public void cleanUpShortPress(View v) { if (!mDraggingWidget) { - cleanupWidgetPreloading(); + cleanupWidgetPreloading(false); } } @@ -829,8 +839,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } d.deferDragViewCleanupPostAnimation = false; - cleanupWidgetPreloading(); } + cleanupWidgetPreloading(success); mDraggingWidget = false; } @@ -838,7 +848,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen public void onFlingToDeleteCompleted() { // We just dismiss the drag when we fling, so cleanup here endDragging(null, true, true); - cleanupWidgetPreloading(); + cleanupWidgetPreloading(false); mDraggingWidget = false; } @@ -1130,7 +1140,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen if (previewImage != 0) { drawable = mPackageManager.getDrawable(packageName, previewImage, null); if (drawable == null) { - Log.w(LOG_TAG, "Can't load widget preview drawable 0x" + + Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(previewImage) + " for provider: " + provider); } } @@ -1620,8 +1630,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen @Override public void dumpState() { // TODO: Dump information related to current list of Applications, Widgets, etc. - ApplicationInfo.dumpApplicationInfoList(LOG_TAG, "mApps", mApps); - dumpAppWidgetProviderInfoList(LOG_TAG, "mWidgets", mWidgets); + ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps); + dumpAppWidgetProviderInfoList(TAG, "mWidgets", mWidgets); } private void dumpAppWidgetProviderInfoList(String tag, String label, diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java index 774bf1f..f78aa4c 100644 --- a/src/com/android/launcher2/PagedViewWidget.java +++ b/src/com/android/launcher2/PagedViewWidget.java @@ -42,6 +42,7 @@ public class PagedViewWidget extends LinearLayout { CheckForShortPress mPendingCheckForShortPress = null; ShortPressListener mShortPressListener = null; boolean mShortPressTriggered = false; + static PagedViewWidget sShortpressTarget = null; public PagedViewWidget(Context context) { this(context, null); @@ -141,13 +142,16 @@ public class PagedViewWidget extends LinearLayout { class CheckForShortPress implements Runnable { public void run() { if (mShortPressListener != null) { + if (sShortpressTarget != null) return; mShortPressListener.onShortPress(PagedViewWidget.this); } + sShortpressTarget = PagedViewWidget.this; mShortPressTriggered = true; } } private void checkForShortPress() { + if (sShortpressTarget != null) return; if (mPendingCheckForShortPress == null) { mPendingCheckForShortPress = new CheckForShortPress(); } @@ -173,6 +177,10 @@ public class PagedViewWidget extends LinearLayout { } } + static void resetShortPressTarget() { + sShortpressTarget = null; + } + @Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); @@ -190,6 +198,7 @@ public class PagedViewWidget extends LinearLayout { 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 |