|
27 | 27 | import android.view.Gravity; |
28 | 28 | import android.view.MotionEvent; |
29 | 29 | import android.view.ScaleGestureDetector; |
| 30 | +import android.view.ScaleGestureDetector.OnScaleGestureListener; |
30 | 31 | import android.view.View; |
31 | 32 | import android.view.ViewConfiguration; |
32 | 33 | import android.view.ViewGroup; |
33 | 34 | import android.view.View.OnClickListener; |
34 | 35 |
|
35 | | -import java.util.Stack; |
36 | | - |
37 | 36 | public class ExpandHelper implements Gefingerpoken, OnClickListener { |
38 | 37 | public interface Callback { |
39 | 38 | View getChildAtRawPosition(float x, float y); |
@@ -110,6 +109,32 @@ public interface Callback { |
110 | 109 |
|
111 | 110 | private View mScrollView; |
112 | 111 |
|
| 112 | + private OnScaleGestureListener mScaleGestureListener |
| 113 | + = new ScaleGestureDetector.SimpleOnScaleGestureListener() { |
| 114 | + @Override |
| 115 | + public boolean onScaleBegin(ScaleGestureDetector detector) { |
| 116 | + if (DEBUG_SCALE) Slog.v(TAG, "onscalebegin()"); |
| 117 | + float focusX = detector.getFocusX(); |
| 118 | + float focusY = detector.getFocusY(); |
| 119 | + |
| 120 | + final View underFocus = findView(focusX, focusY); |
| 121 | + if (underFocus != null) { |
| 122 | + startExpanding(underFocus, STRETCH); |
| 123 | + } |
| 124 | + return mExpanding; |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public boolean onScale(ScaleGestureDetector detector) { |
| 129 | + if (DEBUG_SCALE) Slog.v(TAG, "onscale() on " + mCurrView); |
| 130 | + return true; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public void onScaleEnd(ScaleGestureDetector detector) { |
| 135 | + } |
| 136 | + }; |
| 137 | + |
113 | 138 | private class ViewScaler { |
114 | 139 | View mView; |
115 | 140 |
|
@@ -201,31 +226,7 @@ public void onAnimationEnd(Animator animation) { |
201 | 226 | final ViewConfiguration configuration = ViewConfiguration.get(mContext); |
202 | 227 | mTouchSlop = configuration.getScaledTouchSlop(); |
203 | 228 |
|
204 | | - mSGD = new ScaleGestureDetector(context, |
205 | | - new ScaleGestureDetector.SimpleOnScaleGestureListener() { |
206 | | - @Override |
207 | | - public boolean onScaleBegin(ScaleGestureDetector detector) { |
208 | | - if (DEBUG_SCALE) Slog.v(TAG, "onscalebegin()"); |
209 | | - float focusX = detector.getFocusX(); |
210 | | - float focusY = detector.getFocusY(); |
211 | | - |
212 | | - final View underFocus = findView(focusX, focusY); |
213 | | - if (underFocus != null) { |
214 | | - startExpanding(underFocus, STRETCH); |
215 | | - } |
216 | | - return mExpanding; |
217 | | - } |
218 | | - |
219 | | - @Override |
220 | | - public boolean onScale(ScaleGestureDetector detector) { |
221 | | - if (DEBUG_SCALE) Slog.v(TAG, "onscale() on " + mCurrView); |
222 | | - return true; |
223 | | - } |
224 | | - |
225 | | - @Override |
226 | | - public void onScaleEnd(ScaleGestureDetector detector) { |
227 | | - } |
228 | | - }); |
| 229 | + mSGD = new ScaleGestureDetector(context, mScaleGestureListener); |
229 | 230 | } |
230 | 231 |
|
231 | 232 | private void updateExpansion() { |
@@ -586,6 +587,17 @@ public void onClick(View v) { |
586 | 587 | clearView(); |
587 | 588 | } |
588 | 589 |
|
| 590 | + /** |
| 591 | + * Use this to abort any pending expansions in progress. |
| 592 | + */ |
| 593 | + public void cancel() { |
| 594 | + finishExpanding(true); |
| 595 | + clearView(); |
| 596 | + |
| 597 | + // reset the gesture detector |
| 598 | + mSGD = new ScaleGestureDetector(mContext, mScaleGestureListener); |
| 599 | + } |
| 600 | + |
589 | 601 | /** |
590 | 602 | * Triggers haptic feedback. |
591 | 603 | */ |
|
0 commit comments