Fix nav bar spacing for tablets.

Change-Id: Ieee2c2174a3041a0f967cc75bbe74d8bf882ced7
This commit is contained in:
Deepanshu Gupta
2015-05-18 11:58:31 -07:00
parent 3dc19883c5
commit 71dc5ee224
3 changed files with 99 additions and 21 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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;