diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/aapt/AaptConfig.cpp | 31 | ||||
-rw-r--r-- | tools/aapt/AaptConfig.h | 1 | ||||
-rw-r--r-- | tools/aapt/SdkConstants.h | 1 | ||||
-rw-r--r-- | tools/aapt/tests/AaptConfig_test.cpp | 16 | ||||
-rw-r--r-- | tools/layoutlib/bridge/resources/bars/navigation_bar.xml | 32 | ||||
-rw-r--r-- | tools/layoutlib/bridge/resources/bars/navigation_bar600dp.xml | 49 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/NavigationBar.java | 39 |
7 files changed, 147 insertions, 22 deletions
diff --git a/tools/aapt/AaptConfig.cpp b/tools/aapt/AaptConfig.cpp index ede9e99..b12867a 100644 --- a/tools/aapt/AaptConfig.cpp +++ b/tools/aapt/AaptConfig.cpp @@ -123,6 +123,14 @@ bool parse(const String8& str, ConfigDescription* out) { part = parts[index].string(); } + if (parseScreenRound(part, &config)) { + index++; + if (index == N) { + goto success; + } + part = parts[index].string(); + } + if (parseOrientation(part, &config)) { index++; if (index == N) { @@ -241,7 +249,9 @@ void applyVersionForCompatibility(ConfigDescription* config) { } uint16_t minSdk = 0; - if (config->density == ResTable_config::DENSITY_ANY) { + if (config->screenLayout2 & ResTable_config::MASK_SCREENROUND) { + minSdk = SDK_MNC; + } else if (config->density == ResTable_config::DENSITY_ANY) { minSdk = SDK_LOLLIPOP; } else if (config->smallestScreenWidthDp != ResTable_config::SCREENWIDTH_ANY || config->screenWidthDp != ResTable_config::SCREENWIDTH_ANY @@ -395,7 +405,26 @@ bool parseScreenLayoutLong(const char* name, ResTable_config* out) { | ResTable_config::SCREENLONG_NO; return true; } + return false; +} +bool parseScreenRound(const char* name, ResTable_config* out) { + if (strcmp(name, kWildcardName) == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_ANY; + return true; + } else if (strcmp(name, "round") == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_YES; + return true; + } else if (strcmp(name, "notround") == 0) { + if (out) out->screenLayout2 = + (out->screenLayout2&~ResTable_config::MASK_SCREENROUND) + | ResTable_config::SCREENROUND_NO; + return true; + } return false; } diff --git a/tools/aapt/AaptConfig.h b/tools/aapt/AaptConfig.h index f73a508..04c763f 100644 --- a/tools/aapt/AaptConfig.h +++ b/tools/aapt/AaptConfig.h @@ -60,6 +60,7 @@ bool parseScreenWidthDp(const char* str, android::ResTable_config* out = NULL); bool parseScreenHeightDp(const char* str, android::ResTable_config* out = NULL); bool parseScreenLayoutSize(const char* str, android::ResTable_config* out = NULL); bool parseScreenLayoutLong(const char* str, android::ResTable_config* out = NULL); +bool parseScreenRound(const char* name, android::ResTable_config* out = NULL); bool parseOrientation(const char* str, android::ResTable_config* out = NULL); bool parseUiModeType(const char* str, android::ResTable_config* out = NULL); bool parseUiModeNight(const char* str, android::ResTable_config* out = NULL); diff --git a/tools/aapt/SdkConstants.h b/tools/aapt/SdkConstants.h index 4e0fe10..16e622a 100644 --- a/tools/aapt/SdkConstants.h +++ b/tools/aapt/SdkConstants.h @@ -38,6 +38,7 @@ enum { SDK_KITKAT_WATCH = 20, SDK_LOLLIPOP = 21, SDK_LOLLIPOP_MR1 = 22, + SDK_MNC = 23, }; #endif // H_AAPT_SDK_CONSTANTS diff --git a/tools/aapt/tests/AaptConfig_test.cpp b/tools/aapt/tests/AaptConfig_test.cpp index 7618974..8bb38ba 100644 --- a/tools/aapt/tests/AaptConfig_test.cpp +++ b/tools/aapt/tests/AaptConfig_test.cpp @@ -19,6 +19,7 @@ #include "AaptConfig.h" #include "ConfigDescription.h" +#include "SdkConstants.h" #include "TestHelper.h" using android::String8; @@ -82,3 +83,18 @@ TEST(AaptConfigTest, TestParsingOfCarAttribute) { EXPECT_TRUE(TestParse("car", &config)); EXPECT_EQ(android::ResTable_config::UI_MODE_TYPE_CAR, config.uiMode); } + +TEST(AaptConfigTest, TestParsingRoundQualifier) { + ConfigDescription config; + EXPECT_TRUE(TestParse("round", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_YES, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MNC, config.sdkVersion); + EXPECT_EQ(String8("round-v23"), config.toString()); + + EXPECT_TRUE(TestParse("notround", &config)); + EXPECT_EQ(android::ResTable_config::SCREENROUND_NO, + config.screenLayout2 & android::ResTable_config::MASK_SCREENROUND); + EXPECT_EQ(SDK_MNC, config.sdkVersion); + EXPECT_EQ(String8("notround-v23"), config.toString()); +} 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; |