diff options
Diffstat (limited to 'tools')
17 files changed, 259 insertions, 146 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/aapt2/Main.cpp b/tools/aapt2/Main.cpp index 025ede5..91639c5 100644 --- a/tools/aapt2/Main.cpp +++ b/tools/aapt2/Main.cpp @@ -189,16 +189,16 @@ void versionStylesForCompat(const std::shared_ptr<ResourceTable>& table) { } struct CompileItem { - Source source; ResourceName name; ConfigDescription config; + Source source; std::string extension; }; struct LinkItem { - Source source; ResourceName name; ConfigDescription config; + Source source; std::string originalPath; ZipFile* apk; std::u16string originalPackage; @@ -236,7 +236,8 @@ std::string buildFileReference(const LinkItem& item) { return buildFileReference(item.name, item.config, getExtension<char>(item.originalPath)); } -bool addFileReference(const std::shared_ptr<ResourceTable>& table, const CompileItem& item) { +template <typename T> +bool addFileReference(const std::shared_ptr<ResourceTable>& table, const T& item) { StringPool& pool = table->getValueStringPool(); StringPool::Ref ref = pool.makeRef(util::utf8ToUtf16(buildFileReference(item)), StringPool::Context{ 0, item.config }); @@ -334,9 +335,40 @@ bool compileXml(const AaptOptions& options, const std::shared_ptr<ResourceTable> return true; } -bool linkXml(const AaptOptions& options, const std::shared_ptr<IResolver>& resolver, - const LinkItem& item, const void* data, size_t dataLen, ZipFile* outApk, - std::queue<LinkItem>* outQueue) { +/** + * Determines if a layout should be auto generated based on SDK level. We do not + * generate a layout if there is already a layout defined whose SDK version is greater than + * the one we want to generate. + */ +bool shouldGenerateVersionedResource(const std::shared_ptr<const ResourceTable>& table, + const ResourceName& name, const ConfigDescription& config, + int sdkVersionToGenerate) { + assert(sdkVersionToGenerate > config.sdkVersion); + const ResourceTableType* type; + const ResourceEntry* entry; + std::tie(type, entry) = table->findResource(name); + assert(type && entry); + + auto iter = std::lower_bound(entry->values.begin(), entry->values.end(), config, + [](const ResourceConfigValue& lhs, const ConfigDescription& config) -> bool { + return lhs.config < config; + }); + + assert(iter != entry->values.end()); + ++iter; + + if (iter == entry->values.end()) { + return true; + } + + ConfigDescription newConfig = config; + newConfig.sdkVersion = sdkVersionToGenerate; + return newConfig < iter->config; +} + +bool linkXml(const AaptOptions& options, const std::shared_ptr<ResourceTable>& table, + const std::shared_ptr<IResolver>& resolver, const LinkItem& item, + const void* data, size_t dataLen, ZipFile* outApk, std::queue<LinkItem>* outQueue) { std::shared_ptr<android::ResXMLTree> tree = std::make_shared<android::ResXMLTree>(); if (tree->setTo(data, dataLen, false) != android::NO_ERROR) { return false; @@ -376,9 +408,21 @@ bool linkXml(const AaptOptions& options, const std::shared_ptr<IResolver>& resol if (minStrippedSdk.value() > 0) { // Something was stripped, so let's generate a new file // with the version of the smallest SDK version stripped. - LinkItem newWork = item; - newWork.config.sdkVersion = minStrippedSdk.value(); - outQueue->push(newWork); + // We can only generate a versioned layout if there doesn't exist a layout + // with sdk version greater than the current one but less than the one we + // want to generate. + if (shouldGenerateVersionedResource(table, item.name, item.config, + minStrippedSdk.value())) { + LinkItem newWork = item; + newWork.config.sdkVersion = minStrippedSdk.value(); + outQueue->push(newWork); + + if (!addFileReference(table, newWork)) { + Logger::error(options.output) << "failed to add auto-versioned resource '" + << newWork.name << "'." << std::endl; + return false; + } + } } if (outApk->add(outBuffer, buildFileReference(item).data(), ZipEntry::kCompressDeflated, @@ -604,7 +648,7 @@ static void addApkFilesToLinkQueue(const std::u16string& package, const Source& newSource.path += "/"; newSource.path += pathUtf8; outLinkQueue->push(LinkItem{ - newSource, name, value.config, pathUtf8, apk.get(), + name, value.config, newSource, pathUtf8, apk.get(), table->getPackage() }); // Now rewrite the file path. if (mangle) { @@ -743,8 +787,8 @@ bool link(const AaptOptions& options, const std::shared_ptr<ResourceTable>& outT void* uncompressedData = item.apk->uncompress(entry); assert(uncompressedData); - if (!linkXml(options, resolver, item, uncompressedData, entry->getUncompressedLen(), - &outApk, &linkQueue)) { + if (!linkXml(options, outTable, resolver, item, uncompressedData, + entry->getUncompressedLen(), &outApk, &linkQueue)) { Logger::error(options.output) << "failed to link '" << item.originalPath << "'." << std::endl; return false; @@ -862,9 +906,9 @@ bool compile(const AaptOptions& options, const std::shared_ptr<ResourceTable>& t } compileQueue.push(CompileItem{ - source, ResourceName{ table->getPackage(), *type, pathData.name }, pathData.config, + source, pathData.extension }); } diff --git a/tools/aapt2/data/Makefile b/tools/aapt2/data/Makefile index 6b5fafa..ce5201b 100644 --- a/tools/aapt2/data/Makefile +++ b/tools/aapt2/data/Makefile @@ -49,7 +49,7 @@ $(info PRIVATE_INTERMEDIATE_TABLES = $(PRIVATE_INTERMEDIATE_TABLES)) # returns: out/values-v4.apk: res/values-v4/styles.xml res/values-v4/colors.xml define make-collect-rule $(LOCAL_OUT)/$1.apk: $(filter $(LOCAL_RESOURCE_DIR)/$1/%,$(PRIVATE_RESOURCES)) - $(AAPT) compile --package $(LOCAL_PACKAGE) --binding $(LOCAL_GEN) -o $$@ $$^ + $(AAPT) compile --package $(LOCAL_PACKAGE) -o $$@ $$^ endef # Collect: out/values-v4.apk <- res/values-v4/styles.xml res/values-v4/colors.xml diff --git a/tools/layoutlib/.idea/libraries/framework_jar.xml b/tools/layoutlib/.idea/libraries/framework_jar.xml new file mode 100644 index 0000000..6695a36 --- /dev/null +++ b/tools/layoutlib/.idea/libraries/framework_jar.xml @@ -0,0 +1,13 @@ +<component name="libraryTable"> + <library name="framework.jar"> + <CLASSES> + <root url="jar://$PROJECT_DIR$/../../../../out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="file://$PROJECT_DIR$/../../core/java" /> + <root url="file://$PROJECT_DIR$/../../graphics/java" /> + <root url="file://$PROJECT_DIR$/../../../../libcore/luni/src/main/java" /> + </SOURCES> + </library> +</component>
\ No newline at end of file diff --git a/tools/layoutlib/.idea/libraries/layoutlib_api_prebuilt.xml b/tools/layoutlib/.idea/libraries/layoutlib_api_prebuilt.xml new file mode 100644 index 0000000..a873600 --- /dev/null +++ b/tools/layoutlib/.idea/libraries/layoutlib_api_prebuilt.xml @@ -0,0 +1,11 @@ +<component name="libraryTable"> + <library name="layoutlib_api-prebuilt"> + <CLASSES> + <root url="jar://$PROJECT_DIR$/../../../../prebuilts/misc/common/layoutlib_api/layoutlib_api-prebuilt.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$PROJECT_DIR$/../../../../prebuilts/misc/common/layoutlib_api/layoutlib_api-sources.jar!/" /> + </SOURCES> + </library> +</component>
\ No newline at end of file diff --git a/tools/layoutlib/bridge/bridge.iml b/tools/layoutlib/bridge/bridge.iml index d2b1259..af2fe7f 100644 --- a/tools/layoutlib/bridge/bridge.iml +++ b/tools/layoutlib/bridge/bridge.iml @@ -24,17 +24,7 @@ </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="module-library"> - <library name="layoutlib_api-prebuilt"> - <CLASSES> - <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/layoutlib_api/layoutlib_api-prebuilt.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES> - <root url="jar://$MODULE_DIR$/../../../../../prebuilts/misc/common/layoutlib_api/layoutlib_api-sources.jar!/" /> - </SOURCES> - </library> - </orderEntry> + <orderEntry type="library" name="layoutlib_api-prebuilt" level="project" /> <orderEntry type="module-library"> <library name="ninepatch-prebuilt"> <CLASSES> @@ -60,19 +50,7 @@ </SOURCES> </library> </orderEntry> - <orderEntry type="module-library"> - <library name="framework.jar"> - <CLASSES> - <root url="jar://$MODULE_DIR$/../../../../../out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar!/" /> - </CLASSES> - <JAVADOC /> - <SOURCES> - <root url="file://$MODULE_DIR$/../../../core/java" /> - <root url="file://$MODULE_DIR$/../../../graphics/java" /> - <root url="file://$MODULE_DIR$/../../../../../libcore/luni/src/main/java" /> - </SOURCES> - </library> - </orderEntry> + <orderEntry type="library" name="framework.jar" level="project" /> <orderEntry type="module-library" scope="TEST"> <library name="kxml2-2.3.0"> <CLASSES> 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; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java index 6ca22b0..646f960 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ParserFactory.java @@ -19,7 +19,6 @@ package com.android.layoutlib.bridge.impl; import com.android.annotations.NonNull; import com.android.annotations.Nullable; -import com.android.ide.common.rendering.api.LayoutlibCallback; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -44,10 +43,11 @@ public class ParserFactory { // Used to get a new XmlPullParser from the client. @Nullable - private static LayoutlibCallback sLayoutlibCallback; + private static com.android.ide.common.rendering.api.ParserFactory sParserFactory; - public static void setLayoutlibCallback(@Nullable LayoutlibCallback callback) { - sLayoutlibCallback = callback; + public static void setParserFactory( + @Nullable com.android.ide.common.rendering.api.ParserFactory parserFactory) { + sParserFactory = parserFactory; } @NonNull @@ -77,10 +77,10 @@ public class ParserFactory { @NonNull public static XmlPullParser instantiateParser(@Nullable String name) throws XmlPullParserException { - if (sLayoutlibCallback == null) { + if (sParserFactory == null) { throw new XmlPullParserException("ParserFactory not initialized."); } - XmlPullParser parser = sLayoutlibCallback.createParser(name); + XmlPullParser parser = sParserFactory.createParser(name); parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); return parser; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index 66b0023..2b95488 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -39,8 +39,6 @@ import android.view.inputmethod.InputMethodManager_Accessor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; -import javax.swing.text.html.parser.Parser; - import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED; import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT; import static com.android.ide.common.rendering.api.Result.Status.SUCCESS; @@ -102,7 +100,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso } // setup the ParserFactory - ParserFactory.setLayoutlibCallback(mParams.getLayoutlibCallback()); + ParserFactory.setParserFactory(mParams.getLayoutlibCallback().getParserFactory()); HardwareConfig hardwareConfig = mParams.getHardwareConfig(); @@ -276,7 +274,7 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso mContext.getRenderResources().setFrameworkResourceIdProvider(null); mContext.getRenderResources().setLogger(null); } - ParserFactory.setLayoutlibCallback(null); + ParserFactory.setParserFactory(null); } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java index 677c744..a3fde866 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java @@ -16,6 +16,7 @@ package com.android.layoutlib.bridge.impl; +import com.android.SdkConstants; import com.android.annotations.NonNull; import com.android.ide.common.rendering.api.DensityBasedResourceValue; import com.android.ide.common.rendering.api.LayoutLog; @@ -70,6 +71,10 @@ public final class ResourceHelper { public static int getColor(String value) { if (value != null) { if (!value.startsWith("#")) { + if (value.startsWith(SdkConstants.PREFIX_THEME_REF)) { + throw new NumberFormatException(String.format( + "Attribute '%s' not found. Are you using the right theme?", value)); + } throw new NumberFormatException( String.format("Color value '%s' must start with #", value)); } diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java index 509f5eb..4623f69 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParserTest.java @@ -17,15 +17,7 @@ package com.android.layoutlib.bridge.android; import com.android.annotations.NonNull; -import com.android.ide.common.rendering.api.ActionBarCallback; -import com.android.ide.common.rendering.api.AdapterBinding; -import com.android.ide.common.rendering.api.ILayoutPullParser; -import com.android.ide.common.rendering.api.LayoutlibCallback; -import com.android.ide.common.rendering.api.ResourceReference; -import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.impl.ParserFactory; -import com.android.resources.ResourceType; -import com.android.util.Pair; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -41,7 +33,7 @@ public class BridgeXmlBlockParserTest { @BeforeClass public static void setUp() { - ParserFactory.setLayoutlibCallback(new LayoutlibTestCallback()); + ParserFactory.setParserFactory(new ParserFactoryImpl()); } @Test @@ -129,78 +121,16 @@ public class BridgeXmlBlockParserTest { @AfterClass public static void tearDown() { - ParserFactory.setLayoutlibCallback(null); + ParserFactory.setParserFactory(null); } - private static class LayoutlibTestCallback extends LayoutlibCallback { + private static class ParserFactoryImpl + extends com.android.ide.common.rendering.api.ParserFactory { @NonNull @Override public XmlPullParser createParser(String displayName) throws XmlPullParserException { return new KXmlParser(); } - - @Override - public boolean supports(int ideFeature) { - throw new AssertionError(); - } - - @Override - public Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs) - throws Exception { - throw new AssertionError(); - } - - @Override - public String getNamespace() { - throw new AssertionError(); - } - - @Override - @SuppressWarnings("deprecation") - public Pair<ResourceType, String> resolveResourceId(int id) { - throw new AssertionError(); - } - - @Override - public String resolveResourceId(int[] id) { - throw new AssertionError(); - } - - @Override - public Integer getResourceId(ResourceType type, String name) { - throw new AssertionError(); - } - - @Override - @SuppressWarnings("deprecation") - public ILayoutPullParser getParser(String layoutName) { - throw new AssertionError(); - } - - @Override - public ILayoutPullParser getParser(ResourceValue layoutResource) { - throw new AssertionError(); - } - - @Override - public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie, - ResourceReference itemRef, int fullPosition, int positionPerType, - int fullParentPosition, int parentPositionPerType, ResourceReference viewRef, - ViewAttribute viewAttribute, Object defaultValue) { - throw new AssertionError(); - } - - @Override - public AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, - Object adapterCookie, - Object viewObject) { - throw new AssertionError(); - } - - @Override - public ActionBarCallback getActionBarCallback() { - throw new AssertionError(); - } } } diff --git a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java index b1a1f4d..ab682fd 100644 --- a/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java +++ b/tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/setup/LayoutLibTestCallback.java @@ -23,6 +23,7 @@ import com.android.ide.common.rendering.api.ActionBarCallback; import com.android.ide.common.rendering.api.AdapterBinding; import com.android.ide.common.rendering.api.ILayoutPullParser; import com.android.ide.common.rendering.api.LayoutlibCallback; +import com.android.ide.common.rendering.api.ParserFactory; import com.android.ide.common.rendering.api.ResourceReference; import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.resources.IntArrayWrapper; @@ -32,6 +33,7 @@ import com.android.utils.ILogger; import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.lang.reflect.Constructor; @@ -163,7 +165,14 @@ public class LayoutLibTestCallback extends LayoutlibCallback { @NonNull @Override - public XmlPullParser createParser(@Nullable String name) { - return new KXmlParser(); + public ParserFactory getParserFactory() { + return new ParserFactory() { + @NonNull + @Override + public XmlPullParser createParser(@Nullable String debugName) + throws XmlPullParserException { + return new KXmlParser(); + } + }; } } |
