Skip to content

Commit 05e2414

Browse files
committed
Bring back the 'more notifications' icon.
In fact, there's even more going on here. Icons were appearing cut off because of the unusual width of icons on the right-hand side of the status bar; we now take extra steps to ensure that the IconMerger is only wide enough to show an integral number of icons. But that causes problems with the rest of the status bar the IconMerger makes itself thinner than the overall layout requires, so there's now a containing layout to absorb the additional horizontal space properly. Bug: 5136545 Change-Id: I8c4d1ee2bcd976c452510b33c196fbe0c3e8c660
1 parent 2375d16 commit 05e2414

File tree

4 files changed

+75
-99
lines changed

4 files changed

+75
-99
lines changed

packages/SystemUI/res/layout/status_bar.xml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,43 @@
3131
<LinearLayout android:id="@+id/icons"
3232
android:layout_width="match_parent"
3333
android:layout_height="match_parent"
34-
android:orientation="horizontal">
35-
36-
<com.android.systemui.statusbar.phone.IconMerger android:id="@+id/notificationIcons"
34+
android:paddingLeft="6dip"
35+
android:paddingRight="6dip"
36+
android:orientation="horizontal"
37+
>
38+
39+
<LinearLayout
3740
android:layout_width="0dip"
38-
android:layout_weight="1"
3941
android:layout_height="match_parent"
40-
android:layout_alignParentLeft="true"
41-
android:paddingLeft="6dip"
42-
android:gravity="center_vertical"
43-
android:orientation="horizontal"/>
44-
42+
android:layout_weight="1"
43+
android:orientation="horizontal"
44+
>
45+
<com.android.systemui.statusbar.StatusBarIconView android:id="@+id/moreIcon"
46+
android:layout_width="@dimen/status_bar_icon_size"
47+
android:layout_height="match_parent"
48+
android:src="@drawable/stat_notify_more"
49+
android:visibility="gone"
50+
/>
51+
52+
<com.android.systemui.statusbar.phone.IconMerger android:id="@+id/notificationIcons"
53+
android:layout_width="match_parent"
54+
android:layout_height="match_parent"
55+
android:layout_alignParentLeft="true"
56+
android:gravity="center_vertical"
57+
android:orientation="horizontal"/>
58+
</LinearLayout>
59+
4560
<LinearLayout android:id="@+id/statusIcons"
4661
android:layout_width="wrap_content"
4762
android:layout_height="match_parent"
48-
android:layout_alignParentRight="true"
4963
android:gravity="center_vertical"
5064
android:orientation="horizontal"/>
5165

5266
<LinearLayout
5367
android:id="@+id/signal_battery_cluster"
5468
android:layout_width="wrap_content"
5569
android:layout_height="match_parent"
56-
android:layout_marginRight="6dp"
70+
android:paddingLeft="2dp"
5771
android:orientation="horizontal"
5872
android:gravity="center"
5973
>
@@ -66,7 +80,7 @@
6680
android:id="@+id/battery"
6781
android:layout_height="wrap_content"
6882
android:layout_width="wrap_content"
69-
android:paddingLeft="6dip"
83+
android:paddingLeft="4dip"
7084
/>
7185
</LinearLayout>
7286

@@ -76,7 +90,7 @@
7690
android:layout_width="wrap_content"
7791
android:layout_height="match_parent"
7892
android:singleLine="true"
79-
android:paddingRight="6dip"
93+
android:paddingLeft="6dip"
8094
android:gravity="center_vertical|left"
8195
/>
8296
</LinearLayout>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.graphics.Paint;
2626
import android.graphics.Rect;
2727
import android.text.TextUtils;
28+
import android.util.AttributeSet;
2829
import android.util.Slog;
2930
import android.util.Log;
3031
import android.view.ViewDebug;
@@ -75,6 +76,18 @@ public StatusBarIconView(Context context, String slot, Notification notification
7576
setScaleType(ImageView.ScaleType.CENTER);
7677
}
7778

79+
public StatusBarIconView(Context context, AttributeSet attrs) {
80+
super(context, attrs);
81+
final Resources res = context.getResources();
82+
final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size);
83+
final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size);
84+
final float scale = (float)imageBounds / (float)outerBounds;
85+
setScaleX(scale);
86+
setScaleY(scale);
87+
final float alpha = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1);
88+
setAlpha(alpha);
89+
}
90+
7891
private static boolean streq(String a, String b) {
7992
if (a == b) {
8093
return true;

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

Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -30,113 +30,59 @@
3030

3131
public class IconMerger extends LinearLayout {
3232
private static final String TAG = "IconMerger";
33+
private static final boolean DEBUG = false;
3334

3435
private int mIconSize;
35-
private StatusBarIconView mMoreView;
36-
private StatusBarIcon mMoreIcon = new StatusBarIcon(null, R.drawable.stat_notify_more, 0, 0,
37-
null);
36+
private View mMoreView;
3837

3938
public IconMerger(Context context, AttributeSet attrs) {
4039
super(context, attrs);
4140

4241
mIconSize = context.getResources().getDimensionPixelSize(
43-
com.android.internal.R.dimen.status_bar_icon_size);
42+
R.dimen.status_bar_icon_size);
4443

45-
mMoreView = new StatusBarIconView(context, "more", null);
46-
mMoreView.set(mMoreIcon);
47-
super.addView(mMoreView, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize));
44+
if (DEBUG) {
45+
setBackgroundColor(0x800099FF);
46+
}
4847
}
4948

50-
public void addView(StatusBarIconView v, int index, LinearLayout.LayoutParams p) {
51-
super.addView(v, index+1, p);
49+
public void setOverflowIndicator(View v) {
50+
mMoreView = v;
5251
}
5352

54-
public void addView(StatusBarIconView v, int index) {
55-
super.addView(v, index+1, new LinearLayout.LayoutParams(mIconSize, mIconSize));
53+
@Override
54+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
56+
// we need to constrain this to an integral multiple of our children
57+
int width = getMeasuredWidth();
58+
setMeasuredDimension(width - (width % mIconSize), getMeasuredHeight());
5659
}
5760

5861
@Override
5962
protected void onLayout(boolean changed, int l, int t, int r, int b) {
6063
super.onLayout(changed, l, t, r, b);
64+
checkOverflow(r - l);
65+
}
6166

62-
final int maxWidth = r - l;
63-
final int N = getChildCount();
64-
int i;
65-
66-
// get the rightmost one, and see if we even need to do anything
67-
int fitRight = -1;
68-
for (i=N-1; i>=0; i--) {
69-
final View child = getChildAt(i);
70-
if (child.getVisibility() != GONE) {
71-
fitRight = child.getRight();
72-
break;
73-
}
74-
}
75-
76-
// find the first visible one that isn't the more icon
77-
final StatusBarIconView moreView = mMoreView;
78-
int fitLeft = -1;
79-
int startIndex = -1;
80-
for (i=0; i<N; i++) {
81-
final View child = getChildAt(i);
82-
if (child == moreView) {
83-
startIndex = i+1;
84-
}
85-
else if (child.getVisibility() != GONE) {
86-
fitLeft = child.getLeft();
87-
break;
88-
}
89-
}
67+
private void checkOverflow(int width) {
68+
if (mMoreView == null) return;
9069

91-
if (moreView == null || startIndex < 0) {
92-
return;
93-
/*
94-
throw new RuntimeException("Status Bar / IconMerger moreView == " + moreView
95-
+ " startIndex=" + startIndex);
96-
*/
97-
}
98-
99-
// if it fits without the more icon, then hide the more icon and update fitLeft
100-
// so everything gets pushed left
101-
int adjust = 0;
102-
if (fitRight - fitLeft <= maxWidth) {
103-
adjust = fitLeft - moreView.getLeft();
104-
fitLeft -= adjust;
105-
fitRight -= adjust;
106-
moreView.layout(0, moreView.getTop(), 0, moreView.getBottom());
70+
final int N = getChildCount();
71+
int visibleChildren = 0;
72+
for (int i=0; i<N; i++) {
73+
if (getChildAt(i).getVisibility() != GONE) visibleChildren++;
10774
}
108-
int extra = fitRight - r;
109-
int shift = -1;
110-
111-
int breakingPoint = fitLeft + extra + adjust;
112-
int number = 0;
113-
for (i=startIndex; i<N; i++) {
114-
final StatusBarIconView child = (StatusBarIconView)getChildAt(i);
115-
if (child.getVisibility() != GONE) {
116-
int childLeft = child.getLeft();
117-
int childRight = child.getRight();
118-
if (childLeft < breakingPoint) {
119-
// hide this one
120-
child.layout(0, child.getTop(), 0, child.getBottom());
121-
int n = child.getStatusBarIcon().number;
122-
if (n == 0) {
123-
number += 1;
124-
} else if (n > 0) {
125-
number += n;
126-
}
127-
} else {
128-
// decide how much to shift by
129-
if (shift < 0) {
130-
shift = childLeft - fitLeft;
131-
}
132-
// shift this left by shift
133-
child.layout(childLeft-shift, child.getTop(),
134-
childRight-shift, child.getBottom());
75+
final boolean overflowShown = (mMoreView.getVisibility() == View.VISIBLE);
76+
// let's assume we have one more slot if the more icon is already showing
77+
if (overflowShown) visibleChildren --;
78+
final boolean moreRequired = visibleChildren * mIconSize > width;
79+
if (moreRequired != overflowShown) {
80+
post(new Runnable() {
81+
@Override
82+
public void run() {
83+
mMoreView.setVisibility(moreRequired ? View.VISIBLE : View.GONE);
13584
}
136-
}
85+
});
13786
}
138-
139-
mMoreIcon.number = number;
140-
mMoreView.set(mMoreIcon);
14187
}
14288
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public class PhoneStatusBar extends StatusBar {
149149
// icons
150150
LinearLayout mIcons;
151151
IconMerger mNotificationIcons;
152+
View mMoreIcon;
152153
LinearLayout mStatusIcons;
153154

154155
// expanded notifications
@@ -307,6 +308,8 @@ protected View makeStatusBarView() {
307308
mPixelFormat = PixelFormat.OPAQUE;
308309
mStatusIcons = (LinearLayout)sb.findViewById(R.id.statusIcons);
309310
mNotificationIcons = (IconMerger)sb.findViewById(R.id.notificationIcons);
311+
mMoreIcon = sb.findViewById(R.id.moreIcon);
312+
mNotificationIcons.setOverflowIndicator(mMoreIcon);
310313
mIcons = (LinearLayout)sb.findViewById(R.id.icons);
311314
mTickerView = sb.findViewById(R.id.ticker);
312315

0 commit comments

Comments
 (0)