diff options
| author | 2014-09-11 23:24:46 +0000 | |
|---|---|---|
| committer | 2014-09-11 23:24:48 +0000 | |
| commit | 34e53ab66e9e25150479a0c524183e853accce45 (patch) | |
| tree | bfe60f0ebd7857bf311cd552b6d19d5ef3c42a04 | |
| parent | 36f6951e325feb32f9fe61a80e120dacfd41d473 (diff) | |
| parent | e3cb7baeb9563cd78fecbd84f9ab43be62d25013 (diff) | |
Merge "Vertically align toolbar child views with similar gravities" into lmp-dev
| -rw-r--r-- | core/java/android/widget/Toolbar.java | 76 | ||||
| -rw-r--r-- | core/res/res/values-sw600dp-land/dimens_material.xml | 23 | ||||
| -rw-r--r-- | core/res/res/values/dimens_material.xml | 8 | ||||
| -rw-r--r-- | core/res/res/values/styles_material.xml | 3 |
4 files changed, 78 insertions, 32 deletions
diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java index be28199b3636..ba2d5b82e248 100644 --- a/core/java/android/widget/Toolbar.java +++ b/core/java/android/widget/Toolbar.java @@ -37,7 +37,6 @@ import android.view.View; import android.view.ViewGroup; import com.android.internal.R; -import com.android.internal.app.ToolbarActionBar; import com.android.internal.view.menu.MenuBuilder; import com.android.internal.view.menu.MenuItemImpl; import com.android.internal.view.menu.MenuPresenter; @@ -1007,8 +1006,15 @@ public class Toolbar extends ViewGroup { } private void addSystemView(View v) { - final LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT); + final ViewGroup.LayoutParams vlp = v.getLayoutParams(); + final LayoutParams lp; + if (vlp == null) { + lp = generateDefaultLayoutParams(); + } else if (!checkLayoutParams(vlp)) { + lp = generateLayoutParams(vlp); + } else { + lp = (LayoutParams) vlp; + } lp.mViewType = LayoutParams.SYSTEM; addView(v, lp); } @@ -1280,27 +1286,36 @@ public class Toolbar extends ViewGroup { final int[] collapsingMargins = mTempMargins; collapsingMargins[0] = collapsingMargins[1] = 0; + // Align views within the minimum toolbar height, if set. + final int alignmentHeight = getMinimumHeight(); + if (shouldLayout(mNavButtonView)) { if (isRtl) { - right = layoutChildRight(mNavButtonView, right, collapsingMargins); + right = layoutChildRight(mNavButtonView, right, collapsingMargins, + alignmentHeight); } else { - left = layoutChildLeft(mNavButtonView, left, collapsingMargins); + left = layoutChildLeft(mNavButtonView, left, collapsingMargins, + alignmentHeight); } } if (shouldLayout(mCollapseButtonView)) { if (isRtl) { - right = layoutChildRight(mCollapseButtonView, right, collapsingMargins); + right = layoutChildRight(mCollapseButtonView, right, collapsingMargins, + alignmentHeight); } else { - left = layoutChildLeft(mCollapseButtonView, left, collapsingMargins); + left = layoutChildLeft(mCollapseButtonView, left, collapsingMargins, + alignmentHeight); } } if (shouldLayout(mMenuView)) { if (isRtl) { - left = layoutChildLeft(mMenuView, left, collapsingMargins); + left = layoutChildLeft(mMenuView, left, collapsingMargins, + alignmentHeight); } else { - right = layoutChildRight(mMenuView, right, collapsingMargins); + right = layoutChildRight(mMenuView, right, collapsingMargins, + alignmentHeight); } } @@ -1311,17 +1326,21 @@ public class Toolbar extends ViewGroup { if (shouldLayout(mExpandedActionView)) { if (isRtl) { - right = layoutChildRight(mExpandedActionView, right, collapsingMargins); + right = layoutChildRight(mExpandedActionView, right, collapsingMargins, + alignmentHeight); } else { - left = layoutChildLeft(mExpandedActionView, left, collapsingMargins); + left = layoutChildLeft(mExpandedActionView, left, collapsingMargins, + alignmentHeight); } } if (shouldLayout(mLogoView)) { if (isRtl) { - right = layoutChildRight(mLogoView, right, collapsingMargins); + right = layoutChildRight(mLogoView, right, collapsingMargins, + alignmentHeight); } else { - left = layoutChildLeft(mLogoView, left, collapsingMargins); + left = layoutChildLeft(mLogoView, left, collapsingMargins, + alignmentHeight); } } @@ -1434,13 +1453,15 @@ public class Toolbar extends ViewGroup { addCustomViewsWithGravity(mTempViews, Gravity.LEFT); final int leftViewsCount = mTempViews.size(); for (int i = 0; i < leftViewsCount; i++) { - left = layoutChildLeft(mTempViews.get(i), left, collapsingMargins); + left = layoutChildLeft(mTempViews.get(i), left, collapsingMargins, + alignmentHeight); } addCustomViewsWithGravity(mTempViews, Gravity.RIGHT); final int rightViewsCount = mTempViews.size(); for (int i = 0; i < rightViewsCount; i++) { - right = layoutChildRight(mTempViews.get(i), right, collapsingMargins); + right = layoutChildRight(mTempViews.get(i), right, collapsingMargins, + alignmentHeight); } // Centered views try to center with respect to the whole bar, but views pinned @@ -1459,8 +1480,10 @@ public class Toolbar extends ViewGroup { final int centerViewsCount = mTempViews.size(); for (int i = 0; i < centerViewsCount; i++) { - centerLeft = layoutChildLeft(mTempViews.get(i), centerLeft, collapsingMargins); + centerLeft = layoutChildLeft(mTempViews.get(i), centerLeft, collapsingMargins, + alignmentHeight); } + mTempViews.clear(); } @@ -1483,46 +1506,49 @@ public class Toolbar extends ViewGroup { return width; } - private int layoutChildLeft(View child, int left, int[] collapsingMargins) { + private int layoutChildLeft(View child, int left, int[] collapsingMargins, + int alignmentHeight) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int l = lp.leftMargin - collapsingMargins[0]; left += Math.max(0, l); collapsingMargins[0] = Math.max(0, -l); - final int top = getChildTop(child); + final int top = getChildTop(child, alignmentHeight); final int childWidth = child.getMeasuredWidth(); child.layout(left, top, left + childWidth, top + child.getMeasuredHeight()); left += childWidth + lp.rightMargin; return left; } - private int layoutChildRight(View child, int right, int[] collapsingMargins) { + private int layoutChildRight(View child, int right, int[] collapsingMargins, + int alignmentHeight) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int r = lp.rightMargin - collapsingMargins[1]; right -= Math.max(0, r); collapsingMargins[1] = Math.max(0, -r); - final int top = getChildTop(child); + final int top = getChildTop(child, alignmentHeight); final int childWidth = child.getMeasuredWidth(); child.layout(right - childWidth, top, right, top + child.getMeasuredHeight()); right -= childWidth + lp.leftMargin; return right; } - private int getChildTop(View child) { + private int getChildTop(View child, int alignmentHeight) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); + final int childHeight = child.getMeasuredHeight(); + final int alignmentOffset = alignmentHeight > 0 ? (childHeight - alignmentHeight) / 2 : 0; switch (getChildVerticalGravity(lp.gravity)) { case Gravity.TOP: - return getPaddingTop(); + return getPaddingTop() - alignmentOffset; case Gravity.BOTTOM: - return getHeight() - getPaddingBottom() - - child.getMeasuredHeight() - lp.bottomMargin; + return getHeight() - getPaddingBottom() - childHeight + - lp.bottomMargin - alignmentOffset; default: case Gravity.CENTER_VERTICAL: final int paddingTop = getPaddingTop(); final int paddingBottom = getPaddingBottom(); final int height = getHeight(); - final int childHeight = child.getMeasuredHeight(); final int space = height - paddingTop - paddingBottom; int spaceAbove = (space - childHeight) / 2; if (spaceAbove < lp.topMargin) { diff --git a/core/res/res/values-sw600dp-land/dimens_material.xml b/core/res/res/values-sw600dp-land/dimens_material.xml new file mode 100644 index 000000000000..f8f16e231f70 --- /dev/null +++ b/core/res/res/values-sw600dp-land/dimens_material.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<resources> + + <!-- Use the default title sizes on tablets. --> + <dimen name="text_size_title_material_toolbar">@dimen/text_size_title_material</dimen> + <!-- Use the default subtitle sizes on tablets. --> + <dimen name="text_size_subtitle_material_toolbar">@dimen/text_size_subhead_material</dimen> + +</resources> diff --git a/core/res/res/values/dimens_material.xml b/core/res/res/values/dimens_material.xml index 275a5ec0ad56..3e64f30f51f8 100644 --- a/core/res/res/values/dimens_material.xml +++ b/core/res/res/values/dimens_material.xml @@ -41,11 +41,11 @@ <dimen name="text_size_headline_material">24sp</dimen> <dimen name="text_size_title_material">20sp</dimen> <dimen name="text_size_subhead_material">16sp</dimen> - <dimen name="text_size_title_material_toolbar">20dp</dimen> - <dimen name="text_size_subtitle_material_toolbar">16dp</dimen> + <dimen name="text_size_title_material_toolbar">@dimen/text_size_title_material</dimen> + <dimen name="text_size_subtitle_material_toolbar">@dimen/text_size_subhead_material</dimen> <dimen name="text_size_menu_material">16sp</dimen> - <dimen name="text_size_body_2_material">14sp</dimen> - <dimen name="text_size_body_1_material">14sp</dimen> + <dimen name="text_size_body_2_material">16sp</dimen> + <dimen name="text_size_body_1_material">16sp</dimen> <dimen name="text_size_caption_material">12sp</dimen> <dimen name="text_size_button_material">14sp</dimen> diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml index 26c7d10732dc..836f886fa0d1 100644 --- a/core/res/res/values/styles_material.xml +++ b/core/res/res/values/styles_material.xml @@ -851,10 +851,7 @@ please see styles_device_defaults.xml. <item name="src">@drawable/ic_menu_moreoverflow_material</item> <item name="background">?attr/actionBarItemBackground</item> <item name="contentDescription">@string/action_menu_overflow_description</item> - <item name="minWidth">@dimen/action_button_min_width_material</item> - <item name="minHeight">@dimen/action_button_min_height_material</item> <item name="paddingEnd">12dp</item> - <item name="scaleType">center</item> </style> <style name="Widget.Material.ActionBar.TabView" parent="Widget.ActionBar.TabView"> |