diff options
| author | 2011-11-10 11:56:49 -0500 | |
|---|---|---|
| committer | 2011-11-10 12:42:30 -0500 | |
| commit | 05e2414ef5a3a8fecbabc1f220c9925539d51f7a (patch) | |
| tree | 01b5be5c8e4614717018d95bb027004951e69e32 | |
| parent | 2375d16378e6f8b7694c5a2cd9e0622e382e6049 (diff) | |
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
4 files changed, 75 insertions, 99 deletions
diff --git a/packages/SystemUI/res/layout/status_bar.xml b/packages/SystemUI/res/layout/status_bar.xml index af2c93c19f5a..b1aaade7c914 100644 --- a/packages/SystemUI/res/layout/status_bar.xml +++ b/packages/SystemUI/res/layout/status_bar.xml @@ -31,21 +31,35 @@ <LinearLayout android:id="@+id/icons" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="horizontal"> - - <com.android.systemui.statusbar.phone.IconMerger android:id="@+id/notificationIcons" + android:paddingLeft="6dip" + android:paddingRight="6dip" + android:orientation="horizontal" + > + + <LinearLayout android:layout_width="0dip" - android:layout_weight="1" android:layout_height="match_parent" - android:layout_alignParentLeft="true" - android:paddingLeft="6dip" - android:gravity="center_vertical" - android:orientation="horizontal"/> - + android:layout_weight="1" + android:orientation="horizontal" + > + <com.android.systemui.statusbar.StatusBarIconView android:id="@+id/moreIcon" + android:layout_width="@dimen/status_bar_icon_size" + android:layout_height="match_parent" + android:src="@drawable/stat_notify_more" + android:visibility="gone" + /> + + <com.android.systemui.statusbar.phone.IconMerger android:id="@+id/notificationIcons" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentLeft="true" + android:gravity="center_vertical" + android:orientation="horizontal"/> + </LinearLayout> + <LinearLayout android:id="@+id/statusIcons" android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_alignParentRight="true" android:gravity="center_vertical" android:orientation="horizontal"/> @@ -53,7 +67,7 @@ android:id="@+id/signal_battery_cluster" android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_marginRight="6dp" + android:paddingLeft="2dp" android:orientation="horizontal" android:gravity="center" > @@ -66,7 +80,7 @@ android:id="@+id/battery" android:layout_height="wrap_content" android:layout_width="wrap_content" - android:paddingLeft="6dip" + android:paddingLeft="4dip" /> </LinearLayout> @@ -76,7 +90,7 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:singleLine="true" - android:paddingRight="6dip" + android:paddingLeft="6dip" android:gravity="center_vertical|left" /> </LinearLayout> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index 69978378d140..8228df5a1fcd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -25,6 +25,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.text.TextUtils; +import android.util.AttributeSet; import android.util.Slog; import android.util.Log; import android.view.ViewDebug; @@ -75,6 +76,18 @@ public class StatusBarIconView extends AnimatedImageView { setScaleType(ImageView.ScaleType.CENTER); } + public StatusBarIconView(Context context, AttributeSet attrs) { + super(context, attrs); + final Resources res = context.getResources(); + final int outerBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_size); + final int imageBounds = res.getDimensionPixelSize(R.dimen.status_bar_icon_drawing_size); + final float scale = (float)imageBounds / (float)outerBounds; + setScaleX(scale); + setScaleY(scale); + final float alpha = res.getFraction(R.dimen.status_bar_icon_drawing_alpha, 1, 1); + setAlpha(alpha); + } + private static boolean streq(String a, String b) { if (a == b) { return true; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java index 20215bd5cbf0..0640282422d9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java @@ -30,113 +30,59 @@ import com.android.systemui.statusbar.StatusBarIconView; public class IconMerger extends LinearLayout { private static final String TAG = "IconMerger"; + private static final boolean DEBUG = false; private int mIconSize; - private StatusBarIconView mMoreView; - private StatusBarIcon mMoreIcon = new StatusBarIcon(null, R.drawable.stat_notify_more, 0, 0, - null); + private View mMoreView; public IconMerger(Context context, AttributeSet attrs) { super(context, attrs); mIconSize = context.getResources().getDimensionPixelSize( - com.android.internal.R.dimen.status_bar_icon_size); + R.dimen.status_bar_icon_size); - mMoreView = new StatusBarIconView(context, "more", null); - mMoreView.set(mMoreIcon); - super.addView(mMoreView, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize)); + if (DEBUG) { + setBackgroundColor(0x800099FF); + } } - public void addView(StatusBarIconView v, int index, LinearLayout.LayoutParams p) { - super.addView(v, index+1, p); + public void setOverflowIndicator(View v) { + mMoreView = v; } - public void addView(StatusBarIconView v, int index) { - super.addView(v, index+1, new LinearLayout.LayoutParams(mIconSize, mIconSize)); + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + // we need to constrain this to an integral multiple of our children + int width = getMeasuredWidth(); + setMeasuredDimension(width - (width % mIconSize), getMeasuredHeight()); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); + checkOverflow(r - l); + } - final int maxWidth = r - l; - final int N = getChildCount(); - int i; - - // get the rightmost one, and see if we even need to do anything - int fitRight = -1; - for (i=N-1; i>=0; i--) { - final View child = getChildAt(i); - if (child.getVisibility() != GONE) { - fitRight = child.getRight(); - break; - } - } - - // find the first visible one that isn't the more icon - final StatusBarIconView moreView = mMoreView; - int fitLeft = -1; - int startIndex = -1; - for (i=0; i<N; i++) { - final View child = getChildAt(i); - if (child == moreView) { - startIndex = i+1; - } - else if (child.getVisibility() != GONE) { - fitLeft = child.getLeft(); - break; - } - } + private void checkOverflow(int width) { + if (mMoreView == null) return; - if (moreView == null || startIndex < 0) { - return; - /* - throw new RuntimeException("Status Bar / IconMerger moreView == " + moreView - + " startIndex=" + startIndex); - */ - } - - // if it fits without the more icon, then hide the more icon and update fitLeft - // so everything gets pushed left - int adjust = 0; - if (fitRight - fitLeft <= maxWidth) { - adjust = fitLeft - moreView.getLeft(); - fitLeft -= adjust; - fitRight -= adjust; - moreView.layout(0, moreView.getTop(), 0, moreView.getBottom()); + final int N = getChildCount(); + int visibleChildren = 0; + for (int i=0; i<N; i++) { + if (getChildAt(i).getVisibility() != GONE) visibleChildren++; } - int extra = fitRight - r; - int shift = -1; - - int breakingPoint = fitLeft + extra + adjust; - int number = 0; - for (i=startIndex; i<N; i++) { - final StatusBarIconView child = (StatusBarIconView)getChildAt(i); - if (child.getVisibility() != GONE) { - int childLeft = child.getLeft(); - int childRight = child.getRight(); - if (childLeft < breakingPoint) { - // hide this one - child.layout(0, child.getTop(), 0, child.getBottom()); - int n = child.getStatusBarIcon().number; - if (n == 0) { - number += 1; - } else if (n > 0) { - number += n; - } - } else { - // decide how much to shift by - if (shift < 0) { - shift = childLeft - fitLeft; - } - // shift this left by shift - child.layout(childLeft-shift, child.getTop(), - childRight-shift, child.getBottom()); + final boolean overflowShown = (mMoreView.getVisibility() == View.VISIBLE); + // let's assume we have one more slot if the more icon is already showing + if (overflowShown) visibleChildren --; + final boolean moreRequired = visibleChildren * mIconSize > width; + if (moreRequired != overflowShown) { + post(new Runnable() { + @Override + public void run() { + mMoreView.setVisibility(moreRequired ? View.VISIBLE : View.GONE); } - } + }); } - - mMoreIcon.number = number; - mMoreView.set(mMoreIcon); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index b0e6968c46fd..9160a138f588 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -149,6 +149,7 @@ public class PhoneStatusBar extends StatusBar { // icons LinearLayout mIcons; IconMerger mNotificationIcons; + View mMoreIcon; LinearLayout mStatusIcons; // expanded notifications @@ -307,6 +308,8 @@ public class PhoneStatusBar extends StatusBar { mPixelFormat = PixelFormat.OPAQUE; mStatusIcons = (LinearLayout)sb.findViewById(R.id.statusIcons); mNotificationIcons = (IconMerger)sb.findViewById(R.id.notificationIcons); + mMoreIcon = sb.findViewById(R.id.moreIcon); + mNotificationIcons.setOverflowIndicator(mMoreIcon); mIcons = (LinearLayout)sb.findViewById(R.id.icons); mTickerView = sb.findViewById(R.id.ticker); |