Skip to content

Commit 259c8b7

Browse files
cwrenAndroid (Google) Code Review
authored andcommitted
Merge "Allow pinch gestures to spill over into the shade header." into jb-dev
2 parents b46f3f6 + 5de6e94 commit 259c8b7

File tree

4 files changed

+77
-40
lines changed

4 files changed

+77
-40
lines changed

packages/SystemUI/src/com/android/systemui/ExpandHelper.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
public class ExpandHelper implements Gefingerpoken, OnClickListener {
3333
public interface Callback {
34-
View getChildAtPosition(MotionEvent ev);
34+
View getChildAtRawPosition(float x, float y);
3535
View getChildAtPosition(float x, float y);
3636
boolean canChildBeExpanded(View v);
3737
boolean setUserExpandedChild(View v, boolean userxpanded);
@@ -62,6 +62,7 @@ public interface Callback {
6262
private Context mContext;
6363

6464
private boolean mStretching;
65+
private View mEventSource;
6566
private View mCurrView;
6667
private View mCurrViewTopGlow;
6768
private View mCurrViewBottomGlow;
@@ -141,7 +142,19 @@ public ExpandHelper(Context context, Callback callback, int small, int large) {
141142
@Override
142143
public boolean onScaleBegin(ScaleGestureDetector detector) {
143144
if (DEBUG) Log.v(TAG, "onscalebegin()");
144-
View v = mCallback.getChildAtPosition(detector.getFocusX(), detector.getFocusY());
145+
float x = detector.getFocusX();
146+
float y = detector.getFocusY();
147+
148+
View v = null;
149+
if (mEventSource != null) {
150+
int[] location = new int[2];
151+
mEventSource.getLocationOnScreen(location);
152+
x += (float) location[0];
153+
y += (float) location[1];
154+
v = mCallback.getChildAtRawPosition(x, y);
155+
} else {
156+
v = mCallback.getChildAtPosition(x, y);
157+
}
145158

146159
// your fingers have to be somewhat close to the bounds of the view in question
147160
mInitialTouchFocusY = detector.getFocusY();
@@ -189,6 +202,11 @@ public void onScaleEnd(ScaleGestureDetector detector) {
189202
}
190203
});
191204
}
205+
206+
public void setEventSource(View eventSource) {
207+
mEventSource = eventSource;
208+
}
209+
192210
public void setGlow(float glow) {
193211
if (!mGlowAnimationSet.isRunning() || glow == 0f) {
194212
if (mGlowAnimationSet.isRunning()) {
@@ -211,7 +229,6 @@ public void setGlow(float glow) {
211229
}
212230
}
213231
}
214-
215232
public boolean onInterceptTouchEvent(MotionEvent ev) {
216233
if (DEBUG) Log.d(TAG, "interceptTouch: act=" + (ev.getAction()) +
217234
" stretching=" + mStretching);
@@ -223,11 +240,13 @@ public boolean onTouchEvent(MotionEvent ev) {
223240
final int action = ev.getAction();
224241
if (DEBUG) Log.d(TAG, "touch: act=" + (action) + " stretching=" + mStretching);
225242
if (mStretching) {
243+
if (DEBUG) Log.d(TAG, "detector ontouch");
226244
mDetector.onTouchEvent(ev);
227245
}
228246
switch (action) {
229247
case MotionEvent.ACTION_UP:
230248
case MotionEvent.ACTION_CANCEL:
249+
if (DEBUG) Log.d(TAG, "cancel");
231250
mStretching = false;
232251
clearView();
233252
break;

packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public boolean onTouch(View v, MotionEvent event) {
289289
animateCollapse();
290290
}
291291
}
292-
return true;
292+
return mStatusBarWindow.onTouchEvent(event);
293293
}});
294294

295295
mStatusBarView = (PhoneStatusBarView) mStatusBarWindow.findViewById(R.id.status_bar);

packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,39 @@
1818

1919
import android.content.Context;
2020
import android.util.AttributeSet;
21+
import android.util.Log;
2122
import android.view.KeyEvent;
23+
import android.view.MotionEvent;
2224
import android.widget.FrameLayout;
2325
import android.widget.TextSwitcher;
2426

27+
import com.android.systemui.ExpandHelper;
28+
import com.android.systemui.R;
29+
import com.android.systemui.statusbar.policy.NotificationRowLayout;
30+
2531

2632
public class StatusBarWindowView extends FrameLayout
2733
{
34+
private static final String TAG = "StatusBarWindowView";
35+
36+
private ExpandHelper mExpandHelper;
37+
private NotificationRowLayout latestItems;
38+
2839
PhoneStatusBar mService;
2940

3041
public StatusBarWindowView(Context context, AttributeSet attrs) {
3142
super(context, attrs);
43+
setMotionEventSplittingEnabled(false);
44+
}
45+
46+
@Override
47+
protected void onAttachedToWindow () {
48+
super.onAttachedToWindow();
49+
latestItems = (NotificationRowLayout) findViewById(R.id.latestItems);
50+
int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
51+
int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
52+
mExpandHelper = new ExpandHelper(mContext, latestItems, minHeight, maxHeight);
53+
mExpandHelper.setEventSource(this);
3254
}
3355

3456
@Override
@@ -43,5 +65,25 @@ public boolean dispatchKeyEvent(KeyEvent event) {
4365
}
4466
return super.dispatchKeyEvent(event);
4567
}
68+
69+
@Override
70+
public boolean onInterceptTouchEvent(MotionEvent ev) {
71+
MotionEvent cancellation = MotionEvent.obtain(ev);
72+
cancellation.setAction(MotionEvent.ACTION_CANCEL);
73+
74+
boolean intercept = mExpandHelper.onInterceptTouchEvent(ev) ||
75+
super.onInterceptTouchEvent(ev);
76+
if (intercept) {
77+
latestItems.onInterceptTouchEvent(cancellation);
78+
}
79+
return intercept;
80+
}
81+
82+
@Override
83+
public boolean onTouchEvent(MotionEvent ev) {
84+
boolean handled = mExpandHelper.onTouchEvent(ev) ||
85+
super.onTouchEvent(ev);
86+
return handled;
87+
}
4688
}
4789

packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import android.widget.LinearLayout;
3737

3838
import com.android.systemui.ExpandHelper;
39-
import com.android.systemui.Gefingerpoken;
4039
import com.android.systemui.R;
4140
import com.android.systemui.SwipeHelper;
4241
import com.android.systemui.statusbar.NotificationData;
@@ -62,9 +61,6 @@ public class NotificationRowLayout
6261
HashMap<View, ValueAnimator> mDisappearingViews = new HashMap<View, ValueAnimator>();
6362

6463
private SwipeHelper mSwipeHelper;
65-
private ExpandHelper mExpandHelper;
66-
67-
private Gefingerpoken mCurrentHelper;
6864

6965
// Flag set during notification removal animation to avoid causing too much work until
7066
// animation is done
@@ -81,8 +77,6 @@ public NotificationRowLayout(Context context, AttributeSet attrs, int defStyle)
8177

8278
setOrientation(LinearLayout.VERTICAL);
8379

84-
setMotionEventSplittingEnabled(false);
85-
8680
if (DEBUG) {
8781
setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
8882
@Override
@@ -101,9 +95,6 @@ public void onChildViewRemoved(View parent, View child) {
10195
float densityScale = getResources().getDisplayMetrics().density;
10296
float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
10397
mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
104-
int minHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_min_height);
105-
int maxHeight = getResources().getDimensionPixelSize(R.dimen.notification_row_max_height);
106-
mExpandHelper = new ExpandHelper(mContext, this, minHeight, maxHeight);
10798
}
10899

109100
public void setLongPressListener(View.OnLongClickListener listener) {
@@ -135,39 +126,17 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
135126
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
136127
if (DEBUG) logLayoutTransition();
137128

138-
MotionEvent cancellation = MotionEvent.obtain(ev);
139-
cancellation.setAction(MotionEvent.ACTION_CANCEL);
140-
141-
if (mSwipeHelper.onInterceptTouchEvent(ev)) {
142-
if (DEBUG) Log.v(TAG, "will swipe");
143-
mCurrentHelper = mSwipeHelper;
144-
mExpandHelper.onInterceptTouchEvent(cancellation);
145-
return true;
146-
} else if (mExpandHelper.onInterceptTouchEvent(ev)) {
147-
if (DEBUG) Log.v(TAG, "will stretch");
148-
mCurrentHelper = mExpandHelper;
149-
mSwipeHelper.onInterceptTouchEvent(cancellation);
150-
return true;
151-
} else {
152-
mCurrentHelper = null;
153-
if (super.onInterceptTouchEvent(ev)) {
154-
if (DEBUG) Log.v(TAG, "intercepting ourselves");
155-
mSwipeHelper.onInterceptTouchEvent(cancellation);
156-
mExpandHelper.onInterceptTouchEvent(cancellation);
157-
return true;
158-
}
159-
}
160-
return false;
129+
return mSwipeHelper.onInterceptTouchEvent(ev) ||
130+
super.onInterceptTouchEvent(ev);
161131
}
162132

163133
@Override
164134
public boolean onTouchEvent(MotionEvent ev) {
165135
if (DEBUG) Log.v(TAG, "onTouchEvent()");
166136
if (DEBUG) logLayoutTransition();
167-
if (mCurrentHelper != null) {
168-
return mCurrentHelper.onTouchEvent(ev);
169-
}
170-
return super.onTouchEvent(ev);
137+
138+
return mSwipeHelper.onTouchEvent(ev) ||
139+
super.onTouchEvent(ev);
171140
}
172141

173142
public boolean canChildBeDismissed(View v) {
@@ -202,6 +171,13 @@ public void onDragCancelled(View v) {
202171
public View getChildAtPosition(MotionEvent ev) {
203172
return getChildAtPosition(ev.getX(), ev.getY());
204173
}
174+
175+
public View getChildAtRawPosition(float touchX, float touchY) {
176+
int[] location = new int[2];
177+
getLocationOnScreen(location);
178+
return getChildAtPosition((float) (touchX - location[0]), (float) (touchY - location[1]));
179+
}
180+
205181
public View getChildAtPosition(float touchX, float touchY) {
206182
// find the view under the pointer, accounting for GONE views
207183
final int count = getChildCount();

0 commit comments

Comments
 (0)