Search in sources :

Example 1 with ILayoutPullParser

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);
}
Also used : ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File)

Example 2 with ILayoutPullParser

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);
}
Also used : ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File)

Example 3 with ILayoutPullParser

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);
}
Also used : ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File)

Example 4 with ILayoutPullParser

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");
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) Element(org.w3c.dom.Element)

Example 5 with ILayoutPullParser

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);
}
Also used : ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File)

Aggregations

ILayoutPullParser (com.android.ide.common.rendering.api.ILayoutPullParser)9 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)6 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 XmlPullParser (org.xmlpull.v1.XmlPullParser)6 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Element (org.w3c.dom.Element)2 HardwareConfig (com.android.ide.common.rendering.api.HardwareConfig)1 ResourceFolderType (com.android.resources.ResourceFolderType)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Set (java.util.Set)1 Nullable (org.jetbrains.annotations.Nullable)1