From 71dc5ee2244aa409c0426d3583a014e30d6cf07e Mon Sep 17 00:00:00 2001 From: Deepanshu Gupta Date: Mon, 18 May 2015 11:58:31 -0700 Subject: Fix nav bar spacing for tablets. Change-Id: Ieee2c2174a3041a0f967cc75bbe74d8bf882ced7 --- .../bridge/resources/bars/navigation_bar.xml | 32 +++++++++++--- .../bridge/resources/bars/navigation_bar600dp.xml | 49 ++++++++++++++++++++++ .../layoutlib/bridge/bars/NavigationBar.java | 39 ++++++++++------- 3 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 tools/layoutlib/bridge/resources/bars/navigation_bar600dp.xml (limited to 'tools') 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 @@ + + + android:layout_height="wrap_content" + android:visibility="invisible"/> + android:layout_weight="1" + android:visibility="invisible"/> + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:layout_weight="1" + android:visibility="invisible"/> + android:layout_height="wrap_content" + android:visibility="invisible"/> 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 @@ + + + + + + + + + + + + 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; -- cgit v1.1