Skip to content

Commit 4954213

Browse files
dsandlerAndroid (Google) Code Review
authored andcommitted
Merge "Cascading clear-all in the phone notifications panel."
2 parents f2bf2be + 8ba33c9 commit 4954213

2 files changed

Lines changed: 86 additions & 15 deletions

File tree

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

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import com.android.systemui.statusbar.policy.BatteryController;
8888
import com.android.systemui.statusbar.policy.LocationController;
8989
import com.android.systemui.statusbar.policy.NetworkController;
90+
import com.android.systemui.statusbar.policy.NotificationRowLayout;
9091

9192
public class PhoneStatusBar extends StatusBar {
9293
static final String TAG = "PhoneStatusBar";
@@ -103,8 +104,10 @@ public class PhoneStatusBar extends StatusBar {
103104
static final int EXPANDED_LEAVE_ALONE = -10000;
104105
static final int EXPANDED_FULL_OPEN = -10001;
105106

106-
private static final int MSG_ANIMATE = 1000;
107-
private static final int MSG_ANIMATE_REVEAL = 1001;
107+
private static final int MSG_ANIMATE = 100;
108+
private static final int MSG_ANIMATE_REVEAL = 101;
109+
private static final int MSG_OPEN_NOTIFICATION_PANEL = 1000;
110+
private static final int MSG_CLOSE_NOTIFICATION_PANEL = 1001;
108111
private static final int MSG_SHOW_INTRUDER = 1002;
109112
private static final int MSG_HIDE_INTRUDER = 1003;
110113
private static final int MSG_OPEN_RECENTS_PANEL = 1020;
@@ -165,7 +168,7 @@ public class PhoneStatusBar extends StatusBar {
165168

166169
// all notifications
167170
NotificationData mNotificationData = new NotificationData();
168-
ViewGroup mPile;
171+
NotificationRowLayout mPile;
169172

170173
// position
171174
int[] mPositionTmp = new int[2];
@@ -324,14 +327,15 @@ public void onSystemUiVisibilityChange(int visibility) {
324327

325328
mExpandedDialog = new ExpandedDialog(context);
326329
mExpandedView = expanded;
327-
mPile = (ViewGroup)expanded.findViewById(R.id.latestItems);
330+
mPile = (NotificationRowLayout)expanded.findViewById(R.id.latestItems);
328331
mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout);
329332
mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle);
330333
mNoNotificationsTitle.setVisibility(View.GONE); // disabling for now
331334

332335
mClearButton = expanded.findViewById(R.id.clear_all_button);
333336
mClearButton.setOnClickListener(mClearButtonListener);
334337
mClearButton.setAlpha(0f);
338+
mClearButton.setEnabled(false);
335339
mDateView = (DateView)expanded.findViewById(R.id.date);
336340
mSettingsButton = expanded.findViewById(R.id.settings_button);
337341
mSettingsButton.setOnClickListener(mSettingsButtonListener);
@@ -1005,6 +1009,7 @@ private void setAreThereNotifications() {
10051009
} else {
10061010
mClearButton.setAlpha(clearable ? 1.0f : 0.0f);
10071011
}
1012+
mClearButton.setEnabled(clearable);
10081013

10091014
/*
10101015
if (mNoNotificationsTitle.isShown()) {
@@ -1114,6 +1119,12 @@ public void handleMessage(Message m) {
11141119
case MSG_ANIMATE_REVEAL:
11151120
doRevealAnimation();
11161121
break;
1122+
case MSG_OPEN_NOTIFICATION_PANEL:
1123+
animateExpand();
1124+
break;
1125+
case MSG_CLOSE_NOTIFICATION_PANEL:
1126+
animateCollapse();
1127+
break;
11171128
case MSG_SHOW_INTRUDER:
11181129
setIntruderAlertVisibility(true);
11191130
break;
@@ -1181,6 +1192,10 @@ public void animateCollapse() {
11811192
}
11821193

11831194
public void animateCollapse(boolean excludeRecents) {
1195+
animateCollapse(excludeRecents, 1.0f);
1196+
}
1197+
1198+
public void animateCollapse(boolean excludeRecents, float velocityMultiplier) {
11841199
if (SPEW) {
11851200
Slog.d(TAG, "animateCollapse(): mExpanded=" + mExpanded
11861201
+ " mExpandedVisible=" + mExpandedVisible
@@ -1209,7 +1224,7 @@ public void animateCollapse(boolean excludeRecents) {
12091224
// and doesn't try to re-open the windowshade.
12101225
mExpanded = true;
12111226
prepareTracking(y, false);
1212-
performFling(y, -mSelfCollapseVelocityPx, true);
1227+
performFling(y, -mSelfCollapseVelocityPx*velocityMultiplier, true);
12131228
}
12141229

12151230
void performExpand() {
@@ -2086,13 +2101,57 @@ void performDisableActions(int net) {
20862101
}
20872102

20882103
private View.OnClickListener mClearButtonListener = new View.OnClickListener() {
2104+
final int mini(int a, int b) {
2105+
return (b>a?a:b);
2106+
}
20892107
public void onClick(View v) {
2090-
try {
2091-
mBarService.onClearAllNotifications();
2092-
} catch (RemoteException ex) {
2093-
// system process is dead if we're here.
2108+
synchronized (mNotificationData) {
2109+
// let's also queue up 400ms worth of animated dismissals
2110+
final int N = mini(5, mPile.getChildCount());
2111+
2112+
final ArrayList<View> snapshot = new ArrayList<View>(N);
2113+
for (int i=0; i<N; i++) {
2114+
final View child = mPile.getChildAt(i);
2115+
if (mPile.canChildBeDismissed(child)) snapshot.add(child);
2116+
}
2117+
new Thread(new Runnable() {
2118+
@Override
2119+
public void run() {
2120+
final int ROW_DELAY = 100;
2121+
2122+
mHandler.postDelayed(new Runnable() {
2123+
public void run() {
2124+
animateCollapse(false, 0f);
2125+
}
2126+
}, (N-1) * ROW_DELAY);
2127+
2128+
mHandler.postDelayed(new Runnable() {
2129+
public void run() {
2130+
try {
2131+
mBarService.onClearAllNotifications();
2132+
} catch (RemoteException ex) { }
2133+
}
2134+
}, N * ROW_DELAY + 500);
2135+
2136+
mPile.setAnimateBounds(false); // temporarily disable some re-layouts
2137+
2138+
for (View v : snapshot) {
2139+
final View _v = v;
2140+
mHandler.post(new Runnable() {
2141+
@Override
2142+
public void run() {
2143+
mPile.dismissRowAnimated(_v, (int)(ROW_DELAY*0.25f));
2144+
}
2145+
});
2146+
try {
2147+
Thread.sleep(ROW_DELAY);
2148+
} catch (InterruptedException ex) { }
2149+
}
2150+
2151+
mPile.setAnimateBounds(true); // reenable layout animation
2152+
}
2153+
}).start();
20942154
}
2095-
animateCollapse();
20962155
}
20972156
};
20982157

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public class NotificationRowLayout extends ViewGroup implements SwipeHelper.Call
4444
private static final boolean DEBUG = false;
4545
private static final boolean SLOW_ANIMATIONS = DEBUG;
4646

47-
private static final boolean ANIMATE_LAYOUT = true;
48-
4947
private static final int APPEAR_ANIM_LEN = SLOW_ANIMATIONS ? 5000 : 250;
5048
private static final int DISAPPEAR_ANIM_LEN = APPEAR_ANIM_LEN;
5149

50+
boolean mAnimateBounds = true;
51+
5252
Rect mTmpRect = new Rect();
5353
int mNumRows = 0;
5454
int mRowHeight = 0;
@@ -93,6 +93,10 @@ public void onChildViewRemoved(View parent, View child) {
9393
mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
9494
}
9595

96+
public void setAnimateBounds(boolean anim) {
97+
mAnimateBounds = anim;
98+
}
99+
96100
@Override
97101
public boolean onInterceptTouchEvent(MotionEvent ev) {
98102
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
@@ -165,7 +169,7 @@ public void addView(View child, int index, LayoutParams params) {
165169

166170
final View childF = child;
167171

168-
if (ANIMATE_LAYOUT) {
172+
if (mAnimateBounds) {
169173
child.setPivotY(0);
170174
final ObjectAnimator alphaFade = ObjectAnimator.ofFloat(child, "alpha", 0f, 1f);
171175
alphaFade.setDuration(APPEAR_ANIM_LEN);
@@ -185,10 +189,18 @@ public void onAnimationEnd(Animator animation) {
185189
}
186190
}
187191

192+
public void dismissRowAnimated(View child) {
193+
dismissRowAnimated(child, 0);
194+
}
195+
196+
public void dismissRowAnimated(View child, int vel) {
197+
mSwipeHelper.dismissChild(child, vel);
198+
}
199+
188200
@Override
189201
public void removeView(View child) {
190202
final View childF = child;
191-
if (ANIMATE_LAYOUT) {
203+
if (mAnimateBounds) {
192204
if (mAppearingViews.containsKey(child)) {
193205
mAppearingViews.remove(child);
194206
}
@@ -264,7 +276,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
264276

265277
mNumRows = numRows;
266278

267-
if (ANIMATE_LAYOUT && isShown()) {
279+
if (mAnimateBounds && isShown()) {
268280
ObjectAnimator.ofInt(this, "forcedHeight", computedHeight)
269281
.setDuration(APPEAR_ANIM_LEN)
270282
.start();

0 commit comments

Comments
 (0)