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

Commit 4c9765a6 authored by Adam Powell's avatar Adam Powell
Browse files

Don't add title margins during to Toolbar layout if titles don't fit

When all space is consumed in a Toolbar by other views the special
shared title/subtitle margins shouldn't be added to the running
position during layout.

Bug 17253638

Change-Id: I179fcbf286fa68fd8df6e25bb1879bccbf1532ed
parent 7c13bc2a
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -1326,6 +1326,8 @@ public class Toolbar extends ViewGroup {
            final View bottomChild = layoutSubtitle ? mSubtitleTextView : mTitleTextView;
            final LayoutParams toplp = (LayoutParams) topChild.getLayoutParams();
            final LayoutParams bottomlp = (LayoutParams) bottomChild.getLayoutParams();
            final boolean titleHasWidth = layoutTitle && mTitleTextView.getMeasuredWidth() > 0
                    || layoutSubtitle && mSubtitleTextView.getMeasuredWidth() > 0;

            switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.TOP:
@@ -1353,7 +1355,7 @@ public class Toolbar extends ViewGroup {
                    break;
            }
            if (isRtl) {
                final int rd = mTitleMarginStart - collapsingMargins[1];
                final int rd = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[1];
                right -= Math.max(0, rd);
                collapsingMargins[1] = Math.max(0, -rd);
                int titleRight = right;
@@ -1376,9 +1378,11 @@ public class Toolbar extends ViewGroup {
                    subtitleRight = subtitleRight - mTitleMarginEnd;
                    titleTop = subtitleBottom + lp.bottomMargin;
                }
                if (titleHasWidth) {
                    right = Math.min(titleRight, subtitleRight);
                }
            } else {
                final int ld = mTitleMarginStart - collapsingMargins[0];
                final int ld = (titleHasWidth ? mTitleMarginStart : 0) - collapsingMargins[0];
                left += Math.max(0, ld);
                collapsingMargins[0] = Math.max(0, -ld);
                int titleLeft = left;
@@ -1401,9 +1405,11 @@ public class Toolbar extends ViewGroup {
                    subtitleLeft = subtitleRight + mTitleMarginEnd;
                    titleTop = subtitleBottom + lp.bottomMargin;
                }
                if (titleHasWidth) {
                    left = Math.max(titleLeft, subtitleLeft);
                }
            }
        }

        // Get all remaining children sorted for layout. This is all prepared
        // such that absolute layout direction can be used below.