From ac47ff70c322614ff2ca9ad82fe41338daf55877 Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Tue, 23 Oct 2012 10:41:44 -0400 Subject: [PATCH] Reset ExpandHelper when the panel is collapsed. Fixes a rather unpleasant bug in which the ExpandHelper could get locked in "expanding" mode if the panel was closed (for example, with the back button) while you were in the middle of an expand gesture. In this situation ExpandHelper would hungrily eat all future touch events destined for the notification panel, making it impossible to click or even clear any notifications. Bug: 7330828 Change-Id: I9c493db5e8fd8ef1aca53f77820780d60fa4e5a7 --- .../com/android/systemui/ExpandHelper.java | 66 +++++++++++-------- .../statusbar/phone/PhoneStatusBar.java | 1 + .../statusbar/phone/StatusBarWindowView.java | 4 ++ 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ExpandHelper.java b/packages/SystemUI/src/com/android/systemui/ExpandHelper.java index 4e9013f56e879..edfaf493ce4e0 100644 --- a/packages/SystemUI/src/com/android/systemui/ExpandHelper.java +++ b/packages/SystemUI/src/com/android/systemui/ExpandHelper.java @@ -27,13 +27,12 @@ import android.util.Slog; import android.view.Gravity; import android.view.MotionEvent; import android.view.ScaleGestureDetector; +import android.view.ScaleGestureDetector.OnScaleGestureListener; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.View.OnClickListener; -import java.util.Stack; - public class ExpandHelper implements Gefingerpoken, OnClickListener { public interface Callback { View getChildAtRawPosition(float x, float y); @@ -110,6 +109,32 @@ public class ExpandHelper implements Gefingerpoken, OnClickListener { private View mScrollView; + private OnScaleGestureListener mScaleGestureListener + = new ScaleGestureDetector.SimpleOnScaleGestureListener() { + @Override + public boolean onScaleBegin(ScaleGestureDetector detector) { + if (DEBUG_SCALE) Slog.v(TAG, "onscalebegin()"); + float focusX = detector.getFocusX(); + float focusY = detector.getFocusY(); + + final View underFocus = findView(focusX, focusY); + if (underFocus != null) { + startExpanding(underFocus, STRETCH); + } + return mExpanding; + } + + @Override + public boolean onScale(ScaleGestureDetector detector) { + if (DEBUG_SCALE) Slog.v(TAG, "onscale() on " + mCurrView); + return true; + } + + @Override + public void onScaleEnd(ScaleGestureDetector detector) { + } + }; + private class ViewScaler { View mView; @@ -201,31 +226,7 @@ public class ExpandHelper implements Gefingerpoken, OnClickListener { final ViewConfiguration configuration = ViewConfiguration.get(mContext); mTouchSlop = configuration.getScaledTouchSlop(); - mSGD = new ScaleGestureDetector(context, - new ScaleGestureDetector.SimpleOnScaleGestureListener() { - @Override - public boolean onScaleBegin(ScaleGestureDetector detector) { - if (DEBUG_SCALE) Slog.v(TAG, "onscalebegin()"); - float focusX = detector.getFocusX(); - float focusY = detector.getFocusY(); - - final View underFocus = findView(focusX, focusY); - if (underFocus != null) { - startExpanding(underFocus, STRETCH); - } - return mExpanding; - } - - @Override - public boolean onScale(ScaleGestureDetector detector) { - if (DEBUG_SCALE) Slog.v(TAG, "onscale() on " + mCurrView); - return true; - } - - @Override - public void onScaleEnd(ScaleGestureDetector detector) { - } - }); + mSGD = new ScaleGestureDetector(context, mScaleGestureListener); } private void updateExpansion() { @@ -586,6 +587,17 @@ public class ExpandHelper implements Gefingerpoken, OnClickListener { clearView(); } + /** + * Use this to abort any pending expansions in progress. + */ + public void cancel() { + finishExpanding(true); + clearView(); + + // reset the gesture detector + mSGD = new ScaleGestureDetector(mContext, mScaleGestureListener); + } + /** * Triggers haptic feedback. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index f906176650e79..9881df043aac3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1368,6 +1368,7 @@ public class PhoneStatusBar extends BaseStatusBar { mHandler.sendEmptyMessage(MSG_CLOSE_SEARCH_PANEL); } + mStatusBarWindow.cancelExpandHelper(); mStatusBarView.collapseAllPanels(true); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java index 89c70e8c6135a..9bdcf5eb0dc87 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java @@ -119,5 +119,9 @@ public class StatusBarWindowView extends FrameLayout canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), pt); } } + + public void cancelExpandHelper() { + mExpandHelper.cancel(); + } }