Skip to content

Commit 8fd1265

Browse files
committed
Auto-expand the top notification.
Bug: 6455789 Change-Id: Ia455f204544ad0c41ace77ea3ece6e0d3d3110d9
1 parent 0c8275b commit 8fd1265

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
@@ -485,17 +485,7 @@ protected boolean inflateViews(NotificationData.Entry entry, ViewGroup parent)
485485
// for blaming (see SwipeHelper.setLongPressListener)
486486
row.setTag(sbn.pkg);
487487

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

562552
applyLegacyRowBackground(sbn, content);
563553

554+
row.setTag(R.id.expandable_tag, Boolean.valueOf(large != null));
564555
entry.row = row;
565556
entry.content = content;
566557
entry.expanded = expandedOneU;
567-
entry.expandedLarge = expandedOneU;
558+
entry.setLargeView(expandedLarge);
568559

569560
return true;
570561
}
@@ -673,6 +664,7 @@ protected StatusBarNotification removeNotificationViews(IBinder key) {
673664
// Remove the expanded view.
674665
ViewGroup rowParent = (ViewGroup)entry.row.getParent();
675666
if (rowParent != null) rowParent.removeView(entry.row);
667+
updateExpansionStates();
676668
updateNotificationIcons();
677669

678670
return entry.notification;
@@ -711,16 +703,53 @@ protected StatusBarIconView addNotificationViews(IBinder key,
711703
if (DEBUG) {
712704
Slog.d(TAG, "addNotificationViews: added at " + pos);
713705
}
706+
updateExpansionStates();
714707
updateNotificationIcons();
715708

716709
return iconView;
717710
}
718711

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

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

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)