Search in sources :

Example 6 with ILayoutPullParser

use of com.android.ide.common.rendering.api.ILayoutPullParser in project platform_frameworks_base by android.

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 7 with ILayoutPullParser

use of com.android.ide.common.rendering.api.ILayoutPullParser in project android_frameworks_base by ParanoidAndroid.

the class BridgeContext method inflateView.

public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, boolean attachToRoot, boolean skipCallbackParser) {
    boolean isPlatformLayout = resource.isFramework();
    if (isPlatformLayout == false && skipCallbackParser == false) {
        // 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), 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);
                // 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), 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, 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 8 with ILayoutPullParser

use of com.android.ide.common.rendering.api.ILayoutPullParser in project android by JetBrains.

the class LayoutPullParserFactory method create.

@Nullable
public static ILayoutPullParser create(@NotNull final RenderTask renderTask) {
    final ResourceFolderType folderType = renderTask.getFolderType();
    if (folderType == null) {
        return null;
    }
    if ((folderType == ResourceFolderType.DRAWABLE || folderType == ResourceFolderType.MENU || folderType == ResourceFolderType.XML) && !ApplicationManager.getApplication().isReadAccessAllowed()) {
        return ApplicationManager.getApplication().runReadAction((Computable<ILayoutPullParser>) () -> create(renderTask));
    }
    XmlFile file = renderTask.getPsiFile();
    if (file == null) {
        throw new IllegalArgumentException("RenderTask always should always have PsiFile when it has ResourceFolderType");
    }
    switch(folderType) {
        case LAYOUT:
            {
                RenderLogger logger = renderTask.getLogger();
                Set<XmlTag> expandNodes = renderTask.getExpandNodes();
                HardwareConfig hardwareConfig = renderTask.getHardwareConfigHelper().getConfig();
                return LayoutPsiPullParser.create(file, logger, expandNodes, hardwareConfig.getDensity());
            }
        case DRAWABLE:
            renderTask.setDecorations(false);
            return createDrawableParser(file);
        case MENU:
            if (renderTask.supportsCapability(Features.ACTION_BAR)) {
                return new MenuLayoutParserFactory(renderTask).render();
            }
            renderTask.setRenderingMode(V_SCROLL);
            renderTask.setDecorations(false);
            return new MenuPreviewRenderer(renderTask, file).render();
        case XML:
            {
                // Switch on root type
                XmlTag rootTag = file.getRootTag();
                if (rootTag != null) {
                    String tag = rootTag.getName();
                    if (tag.equals(TAG_APPWIDGET_PROVIDER)) {
                        // Widget
                        renderTask.setDecorations(false);
                        return createWidgetParser(rootTag);
                    } else if (tag.equals(TAG_PREFERENCE_SCREEN)) {
                        RenderLogger logger = renderTask.getLogger();
                        Set<XmlTag> expandNodes = renderTask.getExpandNodes();
                        HardwareConfig hardwareConfig = renderTask.getHardwareConfigHelper().getConfig();
                        return LayoutPsiPullParser.create(file, logger, expandNodes, hardwareConfig.getDensity());
                    }
                }
                return null;
            }
        default:
            // Should have been prevented by isSupported(PsiFile)
            assert false : folderType;
            return null;
    }
}
Also used : Set(java.util.Set) HardwareConfig(com.android.ide.common.rendering.api.HardwareConfig) XmlFile(com.intellij.psi.xml.XmlFile) ResourceFolderType(com.android.resources.ResourceFolderType) ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with ILayoutPullParser

use of com.android.ide.common.rendering.api.ILayoutPullParser in project android by JetBrains.

the class MenuPreviewRendererTest method test.

public void test() throws Exception {
    myFixture.copyFileToProject("menus/strings.xml", "res/menu/strings.xml");
    VirtualFile file = myFixture.copyFileToProject("menus/menu1.xml", "res/menu/menu1.xml");
    assertNotNull(file);
    RenderTask task = createRenderTask(file);
    assertNotNull(task);
    ILayoutPullParser parser = LayoutPullParserFactory.create(task);
    assertTrue(parser instanceof DomPullParser);
    Element root = ((DomPullParser) parser).getRoot();
    String layout = XmlPrettyPrinter.prettyPrint(root, true);
    String oldXml = "<LinearLayout\n" + "xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "layout_width=\"fill_parent\"\n" + "layout_height=\"fill_parent\"\n" + "orientation=\"vertical\" >\n" + "<LinearLayout\n" + "    layout_width=\"wrap_content\"\n" + "    layout_height=\"wrap_content\"\n" + "    layout_gravity=\"right\"\n" + "    background=\"@android:drawable/menu_panel_holo_dark\"\n" + "    orientation=\"vertical\" >\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Declared 2\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Radio 1\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "\n" + "        <RadioButton\n" + "            layout_width=\"wrap_content\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            clickable=\"false\"\n" + "            duplicateParentState=\"true\"\n" + "            focusable=\"false\" />\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Radio 2\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "\n" + "        <RadioButton\n" + "            layout_width=\"wrap_content\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            clickable=\"false\"\n" + "            duplicateParentState=\"true\"\n" + "            focusable=\"false\" />\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                enabled=\"false\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Check\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "\n" + "        <CheckBox\n" + "            layout_width=\"wrap_content\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            clickable=\"false\"\n" + "            duplicateParentState=\"true\"\n" + "            enabled=\"false\"\n" + "            focusable=\"false\" />\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Declared 5\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"@string/key1\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Declared 4\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Declared 1\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "    <ImageView\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"1dp\"\n" + "        background=\"?android:attr/dividerHorizontal\" />\n" + "\n" + "    <LinearLayout\n" + "        layout_width=\"fill_parent\"\n" + "        layout_height=\"?android:attr/dropdownListPreferredItemHeight\"\n" + "        minWidth=\"196dip\"\n" + "        paddingEnd=\"16dip\" >\n" + "\n" + "        <RelativeLayout\n" + "            layout_width=\"0dp\"\n" + "            layout_height=\"wrap_content\"\n" + "            layout_gravity=\"center_vertical\"\n" + "            layout_marginLeft=\"16dip\"\n" + "            layout_weight=\"1\"\n" + "            duplicateParentState=\"true\" >\n" + "\n" + "            <TextView\n" + "                id=\"@+id/title\"\n" + "                layout_width=\"wrap_content\"\n" + "                layout_height=\"wrap_content\"\n" + "                layout_alignParentLeft=\"true\"\n" + "                layout_alignParentTop=\"true\"\n" + "                duplicateParentState=\"true\"\n" + "                ellipsize=\"marquee\"\n" + "                fadingEdge=\"horizontal\"\n" + "                singleLine=\"true\"\n" + "                text=\"Declared 3\"\n" + "                textAlignment=\"viewStart\"\n" + "                textAppearance=\"?android:attr/textAppearanceLargePopupMenu\" />\n" + "        </RelativeLayout>\n" + "    </LinearLayout>\n" + "\n" + "</LinearLayout>\n" + "<View\n" + "    layout_width=\"fill_parent\"\n" + "    layout_height=\"fill_parent\"\n" + "    layout_weight=\"1\" />\n" + "<TextView\n" + "    layout_width=\"fill_parent\"\n" + "    layout_height=\"wrap_content\"\n" + "    layout_margin=\"5dp\"\n" + "    gravity=\"center\"\n" + "    text=\"(Note: Menu preview is only approximate)\"\n" + "    textColor=\"#ff0000\" />\n" + "</LinearLayout>\n";
    String newXml = "<FrameLayout\n" + "xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "android:layout_width=\"match_parent\"\n" + "android:layout_height=\"match_parent\" />\n";
    oldXml = oldXml.replace("\n", SdkUtils.getLineSeparator());
    newXml = newXml.replace("\n", SdkUtils.getLineSeparator());
    if (task.getLayoutLib().supports(Features.ACTION_BAR)) {
        checkRendering(task, "menu/menu1.png");
        assertEquals(newXml, layout);
    } else {
        assertEquals(oldXml, layout);
        System.err.println("Not running MenuPreviewRendererTest.test: Associated layoutlib in test SDK needs " + "to use API 21 or higher");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ILayoutPullParser(com.android.ide.common.rendering.api.ILayoutPullParser) Element(org.w3c.dom.Element)

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