Skip to content

Commit 230e86a

Browse files
cwrenAndroid (Google) Code Review
authored andcommitted
Merge "Auto-expand the top notification." into jb-dev
2 parents 0a6a123 + 8fd1265 commit 230e86a

File tree

7 files changed

+118
-16
lines changed

7 files changed

+118
-16
lines changed

packages/SystemUI/res/values/ids.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717

1818
<resources>
1919
<item type="id" name="expandable_tag" />
20+
<item type="id" name="user_expanded_tag" />
2021
</resources>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface Callback {
3434
View getChildAtPosition(MotionEvent ev);
3535
View getChildAtPosition(float x, float y);
3636
boolean canChildBeExpanded(View v);
37+
boolean setUserExpandedChild(View v, boolean userxpanded);
3738
}
3839

3940
private static final String TAG = "ExpandHelper";
@@ -272,6 +273,7 @@ private void finishScale(boolean force) {
272273
mScaleAnimation.start();
273274
mStretching = false;
274275
setGlow(0f);
276+
mCallback.setUserExpandedChild(mCurrView, h == mNaturalHeight);
275277
if (DEBUG) Log.d(TAG, "scale was finished on view: " + mCurrView);
276278
clearView();
277279
}

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,17 +486,7 @@ protected boolean inflateViews(NotificationData.Entry entry, ViewGroup parent)
486486
// for blaming (see SwipeHelper.setLongPressListener)
487487
row.setTag(sbn.pkg);
488488

489-
// XXX: temporary: while testing big notifications, auto-expand all of them
490489
ViewGroup.LayoutParams lp = row.getLayoutParams();
491-
Boolean expandable = Boolean.FALSE;
492-
if (large != null) {
493-
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
494-
expandable = Boolean.TRUE;
495-
} else {
496-
lp.height = rowHeight;
497-
}
498-
row.setLayoutParams(lp);
499-
row.setTag(R.id.expandable_tag, expandable);
500490
workAroundBadLayerDrawableOpacity(row);
501491
View vetoButton = updateNotificationVetoButton(row, sbn);
502492
vetoButton.setContentDescription(mContext.getString(
@@ -562,10 +552,11 @@ protected boolean inflateViews(NotificationData.Entry entry, ViewGroup parent)
562552

563553
applyLegacyRowBackground(sbn, content);
564554

555+
row.setTag(R.id.expandable_tag, Boolean.valueOf(large != null));
565556
entry.row = row;
566557
entry.content = content;
567558
entry.expanded = expandedOneU;
568-
entry.expandedLarge = expandedOneU;
559+
entry.setLargeView(expandedLarge);
569560

570561
return true;
571562
}
@@ -674,6 +665,7 @@ protected StatusBarNotification removeNotificationViews(IBinder key) {
674665
// Remove the expanded view.
675666
ViewGroup rowParent = (ViewGroup)entry.row.getParent();
676667
if (rowParent != null) rowParent.removeView(entry.row);
668+
updateExpansionStates();
677669
updateNotificationIcons();
678670

679671
return entry.notification;
@@ -712,16 +704,53 @@ protected StatusBarIconView addNotificationViews(IBinder key,
712704
if (DEBUG) {
713705
Slog.d(TAG, "addNotificationViews: added at " + pos);
714706
}
707+
updateExpansionStates();
715708
updateNotificationIcons();
716709

717710
return iconView;
718711
}
719712

713+
protected boolean expandView(NotificationData.Entry entry, boolean expand) {
714+
if (entry.expandable()) {
715+
int rowHeight =
716+
mContext.getResources().getDimensionPixelSize(R.dimen.notification_height);
717+
ViewGroup.LayoutParams lp = entry.row.getLayoutParams();
718+
if (expand) {
719+
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
720+
} else {
721+
lp.height = rowHeight;
722+
}
723+
entry.row.setLayoutParams(lp);
724+
return expand;
725+
} else {
726+
return false;
727+
}
728+
}
729+
730+
protected void updateExpansionStates() {
731+
int N = mNotificationData.size();
732+
for (int i = 0; i < N; i++) {
733+
NotificationData.Entry entry = mNotificationData.get(i);
734+
if (i == (N-1)) {
735+
if (DEBUG) Slog.d(TAG, "expanding top notification at " + i);
736+
expandView(entry, true);
737+
} else {
738+
if (!entry.userExpanded()) {
739+
if (DEBUG) Slog.d(TAG, "collapsing notification at " + i);
740+
expandView(entry, false);
741+
} else {
742+
if (DEBUG) Slog.d(TAG, "ignoring user-modified notification at " + i);
743+
}
744+
}
745+
}
746+
}
747+
720748
protected abstract void haltTicker();
721749
protected abstract void setAreThereNotifications();
722750
protected abstract void updateNotificationIcons();
723751
protected abstract void tick(IBinder key, StatusBarNotification n, boolean firstTime);
724752
protected abstract void updateExpandedViewPos(int expandedPosition);
753+
protected abstract int getExpandedViewMaxHeight();
725754

726755
protected boolean isTopNotification(ViewGroup parent, NotificationData.Entry entry) {
727756
return parent.indexOfChild(entry.row) == 0;
@@ -798,6 +827,7 @@ public void updateNotification(IBinder key, StatusBarNotification notification)
798827
handleNotificationError(key, notification, "Couldn't update icon: " + ic);
799828
return;
800829
}
830+
updateExpansionStates();
801831
}
802832
catch (RuntimeException e) {
803833
// It failed to add cleanly. Log, and remove the view from the panel.
@@ -807,6 +837,9 @@ public void updateNotification(IBinder key, StatusBarNotification notification)
807837
}
808838
} else {
809839
if (DEBUG) Slog.d(TAG, "not reusing notification for key: " + key);
840+
if (DEBUG) Slog.d(TAG, "contents was " + (contentsUnchanged ? "unchanged" : "changed"));
841+
if (DEBUG) Slog.d(TAG, "order was " + (orderUnchanged ? "unchanged" : "changed"));
842+
if (DEBUG) Slog.d(TAG, "notification is " + (isTopAnyway ? "top" : "not top"));
810843
removeNotificationViews(key);
811844
addNotificationViews(key, notification);
812845
}

packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.widget.ImageView;
2323

2424
import com.android.internal.statusbar.StatusBarNotification;
25+
import com.android.systemui.R;
2526

2627
import java.util.Comparator;
2728
import java.util.ArrayList;
@@ -38,13 +39,32 @@ public static final class Entry {
3839
public View content; // takes the click events and sends the PendingIntent
3940
public View expanded; // the inflated RemoteViews
4041
public ImageView largeIcon;
41-
public View expandedLarge;
42+
protected View expandedLarge;
4243
public Entry() {}
4344
public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) {
4445
this.key = key;
4546
this.notification = n;
4647
this.icon = ic;
4748
}
49+
public void setLargeView(View expandedLarge) {
50+
this.expandedLarge = expandedLarge;
51+
writeBooleanTag(row, R.id.expandable_tag, expandedLarge != null);
52+
}
53+
public View getLargeView() {
54+
return expandedLarge;
55+
}
56+
/**
57+
* Return whether the entry can be expanded.
58+
*/
59+
public boolean expandable() {
60+
return NotificationData.getIsExpandable(row);
61+
}
62+
/**
63+
* Return whether the entry has been manually expanded by the user.
64+
*/
65+
public boolean userExpanded() {
66+
return NotificationData.getUserExpanded(row);
67+
}
4868
}
4969
private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
5070
private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
@@ -134,4 +154,41 @@ public boolean hasClearableItems() {
134154
}
135155
return false;
136156
}
157+
158+
protected static boolean readBooleanTag(View view, int id) {
159+
if (view != null) {
160+
Object value = view.getTag(id);
161+
return value != null && value instanceof Boolean && ((Boolean) value).booleanValue();
162+
}
163+
return false;
164+
}
165+
166+
protected static boolean writeBooleanTag(View view, int id, boolean value) {
167+
if (view != null) {
168+
view.setTag(id, Boolean.valueOf(value));
169+
return value;
170+
}
171+
return false;
172+
}
173+
174+
/**
175+
* Return whether the entry can be expanded.
176+
*/
177+
public static boolean getIsExpandable(View row) {
178+
return readBooleanTag(row, R.id.expandable_tag);
179+
}
180+
181+
/**
182+
* Return whether the entry has been manually expanded by the user.
183+
*/
184+
public static boolean getUserExpanded(View row) {
185+
return readBooleanTag(row, R.id.user_expanded_tag);
186+
}
187+
188+
/**
189+
* Set whether the entry has been manually expanded by the user.
190+
*/
191+
public static boolean setUserExpanded(View row, boolean userExpanded) {
192+
return writeBooleanTag(row, R.id.user_expanded_tag, userExpanded);
193+
}
137194
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,8 @@ static final float saturate(float a) {
17711771
return a < 0f ? 0f : (a > 1f ? 1f : a);
17721772
}
17731773

1774-
int getExpandedViewMaxHeight() {
1774+
@Override
1775+
protected int getExpandedViewMaxHeight() {
17751776
return mDisplayMetrics.heightPixels - mNotificationPanelMarginBottomPx;
17761777
}
17771778

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.android.systemui.Gefingerpoken;
4040
import com.android.systemui.R;
4141
import com.android.systemui.SwipeHelper;
42+
import com.android.systemui.statusbar.NotificationData;
4243

4344
import java.util.HashMap;
4445

@@ -175,9 +176,11 @@ public boolean canChildBeDismissed(View v) {
175176
}
176177

177178
public boolean canChildBeExpanded(View v) {
178-
Object isExpandable = v.getTag(R.id.expandable_tag);
179-
return isExpandable != null && isExpandable instanceof Boolean &&
180-
((Boolean)isExpandable).booleanValue();
179+
return NotificationData.getIsExpandable(v);
180+
}
181+
182+
public boolean setUserExpandedChild(View v, boolean userExpanded) {
183+
return NotificationData.setUserExpanded(v, userExpanded);
181184
}
182185

183186
public void onChildDismissed(View v) {

packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ protected void addPanelWindows() {
348348
scroller.setFillViewport(true);
349349
}
350350

351+
@Override
352+
protected int getExpandedViewMaxHeight() {
353+
return getNotificationPanelHeight();
354+
}
355+
351356
private int getNotificationPanelHeight() {
352357
final Resources res = mContext.getResources();
353358
final Display d = WindowManagerImpl.getDefault().getDefaultDisplay();

0 commit comments

Comments
 (0)