Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce33622a authored by Daniel Sandler's avatar Daniel Sandler Committed by Android (Google) Code Review
Browse files

Merge "Bring back the 'more notifications' icon." into ics-mr1

parents 538dc6ac 05e2414e
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -31,21 +31,35 @@
    <LinearLayout android:id="@+id/icons"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:orientation="horizontal"
        >

        <com.android.systemui.statusbar.phone.IconMerger android:id="@+id/notificationIcons"
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            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:paddingLeft="6dip"
                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>
+13 −0
Original line number Diff line number Diff line
@@ -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;
+32 −86
Original line number Diff line number Diff line
@@ -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);

        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;
            }
        checkOverflow(r - l);
    }

        // 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());
        }
        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 int N = getChildCount();
        int visibleChildren = 0;
        for (int i=0; i<N; i++) {
            if (getChildAt(i).getVisibility() != GONE) visibleChildren++;
        }
        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);
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -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);