use of com.android.ide.common.rendering.api.ILayoutPullParser in project android_frameworks_base by ResurrectionRemix.
the class BridgeContext method inflateView.
public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, boolean attachToRoot, boolean skipCallbackParser) {
boolean isPlatformLayout = resource.isFramework();
if (!isPlatformLayout && !skipCallbackParser) {
// check if the project callback can provide us with a custom parser.
ILayoutPullParser parser = getParser(resource);
if (parser != null) {
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.TRUE);
} finally {
popParser();
}
}
}
ResourceValue resValue;
if (resource instanceof ResourceValue) {
resValue = (ResourceValue) resource;
} else {
if (isPlatformLayout) {
resValue = mRenderResources.getFrameworkResource(ResourceType.LAYOUT, resource.getName());
} else {
resValue = mRenderResources.getProjectResource(ResourceType.LAYOUT, resource.getName());
}
}
if (resValue != null) {
File xml = new File(resValue.getValue());
if (xml.isFile()) {
// give that to our XmlBlockParser
try {
XmlPullParser parser = ParserFactory.create(xml, true);
// set the resource ref to have correct view cookies
mBridgeInflater.setResourceReference(resource);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.FALSE);
} finally {
popParser();
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + xml, e, null);
// we'll return null below.
} catch (FileNotFoundException e) {
// this shouldn't happen since we check above.
} finally {
mBridgeInflater.setResourceReference(null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s is missing!", xml), null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "", resource.getName()), null);
}
return Pair.of(null, Boolean.FALSE);
}
use of com.android.ide.common.rendering.api.ILayoutPullParser in project android_frameworks_base by DirtyUnicorns.
the class BridgeContext method inflateView.
public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, boolean attachToRoot, boolean skipCallbackParser) {
boolean isPlatformLayout = resource.isFramework();
if (!isPlatformLayout && !skipCallbackParser) {
// check if the project callback can provide us with a custom parser.
ILayoutPullParser parser = getParser(resource);
if (parser != null) {
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.TRUE);
} finally {
popParser();
}
}
}
ResourceValue resValue;
if (resource instanceof ResourceValue) {
resValue = (ResourceValue) resource;
} else {
if (isPlatformLayout) {
resValue = mRenderResources.getFrameworkResource(ResourceType.LAYOUT, resource.getName());
} else {
resValue = mRenderResources.getProjectResource(ResourceType.LAYOUT, resource.getName());
}
}
if (resValue != null) {
File xml = new File(resValue.getValue());
if (xml.isFile()) {
// give that to our XmlBlockParser
try {
XmlPullParser parser = ParserFactory.create(xml, true);
// set the resource ref to have correct view cookies
mBridgeInflater.setResourceReference(resource);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.FALSE);
} finally {
popParser();
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + xml, e, null);
// we'll return null below.
} catch (FileNotFoundException e) {
// this shouldn't happen since we check above.
} finally {
mBridgeInflater.setResourceReference(null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s is missing!", xml), null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "", resource.getName()), null);
}
return Pair.of(null, Boolean.FALSE);
}
use of com.android.ide.common.rendering.api.ILayoutPullParser in project android_frameworks_base by AOSPA.
the class BridgeContext method inflateView.
public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, boolean attachToRoot, boolean skipCallbackParser) {
boolean isPlatformLayout = resource.isFramework();
if (!isPlatformLayout && !skipCallbackParser) {
// check if the project callback can provide us with a custom parser.
ILayoutPullParser parser = getParser(resource);
if (parser != null) {
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.TRUE);
} finally {
popParser();
}
}
}
ResourceValue resValue;
if (resource instanceof ResourceValue) {
resValue = (ResourceValue) resource;
} else {
if (isPlatformLayout) {
resValue = mRenderResources.getFrameworkResource(ResourceType.LAYOUT, resource.getName());
} else {
resValue = mRenderResources.getProjectResource(ResourceType.LAYOUT, resource.getName());
}
}
if (resValue != null) {
File xml = new File(resValue.getValue());
if (xml.isFile()) {
// give that to our XmlBlockParser
try {
XmlPullParser parser = ParserFactory.create(xml, true);
// set the resource ref to have correct view cookies
mBridgeInflater.setResourceReference(resource);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.FALSE);
} finally {
popParser();
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + xml, e, null);
// we'll return null below.
} catch (FileNotFoundException e) {
// this shouldn't happen since we check above.
} finally {
mBridgeInflater.setResourceReference(null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s is missing!", xml), null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "", resource.getName()), null);
}
return Pair.of(null, Boolean.FALSE);
}
use of com.android.ide.common.rendering.api.ILayoutPullParser in project android by JetBrains.
the class LayoutPullParserFactoryTest method testRenderDrawable.
public void testRenderDrawable() throws Exception {
VirtualFile file = myFixture.copyFileToProject("drawables/progress_horizontal.xml", "res/drawable/progress_horizontal.xml");
assertNotNull(file);
RenderTask task = createRenderTask(file);
assertNotNull(task);
ILayoutPullParser parser = LayoutPullParserFactory.create(task);
assertTrue(parser instanceof DomPullParser);
Element root = ((DomPullParser) parser).getRoot();
String actualLayout = XmlPrettyPrinter.prettyPrint(root, true);
String expectedLayout = Joiner.on(SdkUtils.getLineSeparator()).join("<ImageView", "xmlns:android=\"http://schemas.android.com/apk/res/android\"", "layout_width=\"fill_parent\"", "layout_height=\"fill_parent\"", "src=\"@drawable/progress_horizontal\" />", "");
assertEquals(expectedLayout, actualLayout);
checkRendering(task, "drawable/progress_horizontal.png");
}
use of com.android.ide.common.rendering.api.ILayoutPullParser in project android_frameworks_base by crdroidandroid.
the class BridgeContext method inflateView.
public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, boolean attachToRoot, boolean skipCallbackParser) {
boolean isPlatformLayout = resource.isFramework();
if (!isPlatformLayout && !skipCallbackParser) {
// check if the project callback can provide us with a custom parser.
ILayoutPullParser parser = getParser(resource);
if (parser != null) {
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.TRUE);
} finally {
popParser();
}
}
}
ResourceValue resValue;
if (resource instanceof ResourceValue) {
resValue = (ResourceValue) resource;
} else {
if (isPlatformLayout) {
resValue = mRenderResources.getFrameworkResource(ResourceType.LAYOUT, resource.getName());
} else {
resValue = mRenderResources.getProjectResource(ResourceType.LAYOUT, resource.getName());
}
}
if (resValue != null) {
File xml = new File(resValue.getValue());
if (xml.isFile()) {
// give that to our XmlBlockParser
try {
XmlPullParser parser = ParserFactory.create(xml, true);
// set the resource ref to have correct view cookies
mBridgeInflater.setResourceReference(resource);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, this, resource.isFramework());
try {
pushParser(blockParser);
return Pair.of(mBridgeInflater.inflate(blockParser, parent, attachToRoot), Boolean.FALSE);
} finally {
popParser();
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + xml, e, null);
// we'll return null below.
} catch (FileNotFoundException e) {
// this shouldn't happen since we check above.
} finally {
mBridgeInflater.setResourceReference(null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s is missing!", xml), null);
}
} else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "", resource.getName()), null);
}
return Pair.of(null, Boolean.FALSE);
}
Aggregations