diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2015-05-18 19:30:57 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-18 19:30:58 +0000 |
commit | 1af9913819643a9577a0a73530fe88c3bfd682a9 (patch) | |
tree | 5b96b9ceb290100a5171c3a5d655cadcd4b1ef74 /tools | |
parent | 9939961db9765f4e900955cf64ce1c3ceeb9362e (diff) | |
parent | 71dc5ee2244aa409c0426d3583a014e30d6cf07e (diff) | |
download | frameworks_base-1af9913819643a9577a0a73530fe88c3bfd682a9.zip frameworks_base-1af9913819643a9577a0a73530fe88c3bfd682a9.tar.gz frameworks_base-1af9913819643a9577a0a73530fe88c3bfd682a9.tar.bz2 |
Merge "Fix nav bar spacing for tablets." into mnc-dev
Diffstat (limited to 'tools')
3 files changed, 99 insertions, 21 deletions
diff --git a/tools/layoutlib/bridge/resources/bars/navigation_bar.xml b/tools/layoutlib/bridge/resources/bars/navigation_bar.xml index 79920a1..55bd1d2 100644 --- a/tools/layoutlib/bridge/resources/bars/navigation_bar.xml +++ b/tools/layoutlib/bridge/resources/bars/navigation_bar.xml @@ -1,8 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 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. + --> + <merge xmlns:android="http://schemas.android.com/apk/res/android"> <View android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content" + android:visibility="invisible"/> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" @@ -10,20 +27,23 @@ <View android:layout_height="wrap_content" android:layout_width="wrap_content" - android:layout_weight="1"/> + android:layout_weight="1" + android:visibility="invisible"/> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside"/> <View - android:layout_height="wrap_content" - android:layout_width="wrap_content" - android:layout_weight="1"/> + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:layout_weight="1" + android:visibility="invisible"/> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="centerInside"/> <View android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content" + android:visibility="invisible"/> </merge> diff --git a/tools/layoutlib/bridge/resources/bars/navigation_bar600dp.xml b/tools/layoutlib/bridge/resources/bars/navigation_bar600dp.xml new file mode 100644 index 0000000..e208a0d --- /dev/null +++ b/tools/layoutlib/bridge/resources/bars/navigation_bar600dp.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 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. + --> + +<merge xmlns:android="http://schemas.android.com/apk/res/android"> + <View + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:visibility="invisible"/> + <ImageView + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerInside"/> + <View + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:visibility="invisible"/> + <ImageView + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerInside"/> + <View + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:visibility="invisible"/> + <ImageView + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:scaleType="centerInside"/> + <View + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:visibility="invisible"/> +</merge> diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java index 16f477b..dcf82a3 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java @@ -41,6 +41,9 @@ public class NavigationBar extends CustomBar { private static final int WIDTH_DEFAULT = 36; private static final int WIDTH_SW360 = 40; private static final int WIDTH_SW600 = 48; + private static final String LAYOUT_XML = "/bars/navigation_bar.xml"; + private static final String LAYOUT_600DP_XML = "/bars/navigation_bar600dp.xml"; + /** * Constructor to be used when creating the {@link NavigationBar} as a regular control. @@ -59,8 +62,8 @@ public class NavigationBar extends CustomBar { public NavigationBar(BridgeContext context, Density density, int orientation, boolean isRtl, boolean rtlEnabled, int simulatedPlatformVersion) throws XmlPullParserException { - super(context, orientation, "/bars/navigation_bar.xml", "navigation_bar.xml", - simulatedPlatformVersion); + super(context, orientation, getShortestWidth(context)>= 600 ? LAYOUT_600DP_XML : LAYOUT_XML, + "navigation_bar.xml", simulatedPlatformVersion); int color = getThemeAttrColor(ATTR_COLOR, true); setBackgroundColor(color == 0 ? 0xFF000000 : color); @@ -87,13 +90,19 @@ public class NavigationBar extends CustomBar { } private void setupNavBar(BridgeContext context, int orientation) { + float sw = getShortestWidth(context); View leftPadding = getChildAt(0); View rightPadding = getChildAt(6); - setSize(context, leftPadding, orientation, getSidePadding(context)); - setSize(context, rightPadding, orientation, getSidePadding(context)); + setSize(context, leftPadding, orientation, getSidePadding(sw)); + setSize(context, rightPadding, orientation, getSidePadding(sw)); + int navButtonWidth = getWidth(sw); for (int i = 1; i < 6; i += 2) { View navButton = getChildAt(i); - setSize(context, navButton, orientation, getWidth(context)); + setSize(context, navButton, orientation, navButtonWidth); + } + if (sw >= 600) { + setSize(context, getChildAt(2), orientation, 128); + setSize(context, getChildAt(4), orientation, 128); } } @@ -108,11 +117,7 @@ public class NavigationBar extends CustomBar { view.setLayoutParams(layoutParams); } - private static int getSidePadding(BridgeContext context) { - DisplayMetrics metrics = context.getMetrics(); - float sw = metrics.widthPixels > metrics.heightPixels - ? metrics.heightPixels : metrics.widthPixels; - sw /= metrics.density; + private static int getSidePadding(float sw) { if (sw >= 400) { return PADDING_WIDTH_SW400; } @@ -122,11 +127,7 @@ public class NavigationBar extends CustomBar { return PADDING_WIDTH_DEFAULT; } - private static int getWidth(BridgeContext context) { - DisplayMetrics metrics = context.getMetrics(); - float sw = metrics.widthPixels > metrics.heightPixels - ? metrics.heightPixels : metrics.widthPixels; - sw /= metrics.density; + private static int getWidth(float sw) { if (sw >= 600) { return WIDTH_SW600; } @@ -136,6 +137,14 @@ public class NavigationBar extends CustomBar { return WIDTH_DEFAULT; } + private static float getShortestWidth(BridgeContext context) { + DisplayMetrics metrics = context.getMetrics(); + float sw = metrics.widthPixels < metrics.heightPixels ? + metrics.widthPixels : metrics.heightPixels; + sw /= metrics.density; + return sw; + } + @Override protected TextView getStyleableTextView() { return null; |