Search in sources :

Example 76 with ResourceValue

use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by AOSPA.

the class AppCompatActionBar method getInflater.

@Override
protected LayoutInflater getInflater(BridgeContext context) {
    // Other than the resource resolution part, the code has been taken from the support
    // library. see code from line 269 onwards in
    // https://android.googlesource.com/platform/frameworks/support/+/android-5.1.0_r1/v7/appcompat/src/android/support/v7/app/ActionBarActivityDelegateBase.java
    Context themedContext = context;
    RenderResources resources = context.getRenderResources();
    ResourceValue actionBarTheme = resources.findItemInTheme("actionBarTheme", false);
    if (actionBarTheme != null) {
        // resolve it, if needed.
        actionBarTheme = resources.resolveResValue(actionBarTheme);
    }
    if (actionBarTheme instanceof StyleResourceValue) {
        int styleId = context.getDynamicIdByStyle(((StyleResourceValue) actionBarTheme));
        if (styleId != 0) {
            themedContext = new ContextThemeWrapper(context, styleId);
        }
    }
    return LayoutInflater.from(themedContext);
}
Also used : Context(android.content.Context) BridgeContext(com.android.layoutlib.bridge.android.BridgeContext) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ContextThemeWrapper(android.view.ContextThemeWrapper) RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue)

Example 77 with ResourceValue

use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by AOSPA.

the class BridgeActionBar method setTitle.

private void setTitle() {
    RenderResources res = mBridgeContext.getRenderResources();
    String title = mParams.getAppLabel();
    ResourceValue titleValue = res.findResValue(title, false);
    if (titleValue != null && titleValue.getValue() != null) {
        setTitle(titleValue.getValue());
    } else {
        setTitle(title);
    }
}
Also used : RenderResources(com.android.ide.common.rendering.api.RenderResources) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 78 with ResourceValue

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

the class GradleInstantRunAndroidTest method testResourceChangeIsDetected.

public void testResourceChangeIsDetected() throws Exception {
    myFixture.copyFileToProject(BASEDIR + "AndroidManifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML);
    myFixture.copyFileToProject(BASEDIR + "res/values/strings.xml", "res/values/strings.xml");
    myFixture.copyFileToProject(BASEDIR + "res/drawable-hdpi/ic_launcher.png", "res/drawable-hdpi/ic_launcher.png");
    HashCode hash = GradleInstantRunContext.getManifestResourcesHash(myFacet);
    // change a resource not referenced from manifest
    AppResourceRepository repository = AppResourceRepository.create(myFacet);
    ResourceValue resValue = repository.getConfiguredValue(ResourceType.STRING, "title_section1", new FolderConfiguration());
    resValue.setValue("foo");
    assertEquals("Hash should not change if a resource not referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
    // change the app_name referenced from manifest
    resValue = repository.getConfiguredValue(ResourceType.STRING, "app_name", new FolderConfiguration());
    resValue.setValue("testapp");
    assertNotEquals("Hash should change if a resource referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
    // change the contents of the launcher icon referenced from manifest
    hash = GradleInstantRunContext.getManifestResourcesHash(myFacet);
    myFixture.copyFileToProject(BASEDIR + "res/drawable-mdpi/ic_launcher.png", "res/drawable-hdpi/ic_launcher.png");
    assertNotEquals("Hash should change if a resource referenced from the manifest is changed", hash, GradleInstantRunContext.getManifestResourcesHash(myFacet));
}
Also used : HashCode(com.google.common.hash.HashCode) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 79 with ResourceValue

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

the class NlOldPalettePanel method setColors.

private void setColors() {
    Color background;
    Color foreground;
    Configuration configuration = null;
    if (myDesignSurface != null) {
        configuration = myDesignSurface.getConfiguration();
    }
    ResourceResolver resolver = null;
    if (configuration != null) {
        resolver = configuration.getResourceResolver();
    }
    if (resolver == null || myMode != Mode.PREVIEW) {
        foreground = UIUtil.getTreeForeground();
        background = UIUtil.getTreeBackground();
    } else {
        ResourceValue windowBackground = resolver.findItemInTheme("colorBackground", true);
        background = ResourceHelper.resolveColor(resolver, windowBackground, myProject);
        if (background == null) {
            background = UIUtil.getTreeBackground();
        }
        ResourceValue textForeground = resolver.findItemInTheme("colorForeground", true);
        foreground = ResourceHelper.resolveColor(resolver, textForeground, myProject);
        if (foreground == null) {
            foreground = UIUtil.getTreeForeground();
        }
        // Ensure the colors can be differentiated:
        if (Math.abs(ImageUtils.getBrightness(background.getRGB()) - ImageUtils.getBrightness(foreground.getRGB())) < 64) {
            if (ImageUtils.getBrightness(background.getRGB()) < 128) {
                foreground = JBColor.WHITE;
            } else {
                foreground = JBColor.BLACK;
            }
        }
    }
    myPaletteTree.setBackground(background);
    myPaletteTree.setForeground(foreground);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) JBColor(com.intellij.ui.JBColor) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue)

Example 80 with ResourceValue

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

the class ThemeEditorTable method getPopupMenuAtCell.

private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
    if (row < 0 || column < 0) {
        return null;
    }
    TableModel rawModel = getModel();
    if (!(rawModel instanceof AttributesTableModel)) {
        return null;
    }
    final AttributesTableModel model = (AttributesTableModel) rawModel;
    AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
    if (contents instanceof AttributesTableModel.AttributeContents) {
        final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
        final EditedStyleItem item = attribute.getValue();
        if (item == null) {
            return null;
        }
        final JBPopupMenu popupMenu = new JBPopupMenu();
        if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
            popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    myGoToListener.goTo(item);
                }
            });
        } else {
            final ResourceResolver resolver = myContext.getResourceResolver();
            assert resolver != null;
            final Project project = myContext.getProject();
            final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
            final File file = new File(resourceValue.getValue());
            final VirtualFileManager manager = VirtualFileManager.getInstance();
            final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
            if (virtualFile != null) {
                popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
                        FileEditorManager.getInstance(project).openEditor(descriptor, true);
                    }
                });
            }
        }
        myJavadocAction.setCurrentItem(item);
        popupMenu.add(myJavadocAction);
        final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
        if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
            popupMenu.add(new AbstractAction("Reset value") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    selectedStyle.removeAttribute(item.getQualifiedName());
                    model.fireTableCellUpdated(attribute.getRowIndex(), 0);
                }
            });
        }
        return popupMenu;
    } else if (contents instanceof AttributesTableModel.ParentAttribute) {
        final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
        if (parentStyle == null) {
            return null;
        }
        final JBPopupMenu menu = new JBPopupMenu();
        menu.add(new AbstractAction(GO_TO_DECLARATION) {

            @Override
            public void actionPerformed(ActionEvent e) {
                myGoToListener.goToParent();
            }
        });
        return menu;
    }
    return null;
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) ActionEvent(java.awt.event.ActionEvent) JBPopupMenu(com.intellij.openapi.ui.JBPopupMenu) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle) Project(com.intellij.openapi.project.Project) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TableModel(javax.swing.table.TableModel) AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel)

Aggregations

ResourceValue (com.android.ide.common.rendering.api.ResourceValue)243 StyleResourceValue (com.android.ide.common.rendering.api.StyleResourceValue)82 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)80 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)69 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)56 RenderResources (com.android.ide.common.rendering.api.RenderResources)48 File (java.io.File)44 BridgeContext (com.android.layoutlib.bridge.android.BridgeContext)40 ResourceType (com.android.resources.ResourceType)31 XmlPullParser (org.xmlpull.v1.XmlPullParser)28 TypedValue (android.util.TypedValue)26 FileNotFoundException (java.io.FileNotFoundException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)23 AttrResourceValue (com.android.ide.common.rendering.api.AttrResourceValue)22 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)22 Context (android.content.Context)16 NotNull (org.jetbrains.annotations.NotNull)14 ResourceResolver (com.android.ide.common.resources.ResourceResolver)13 BridgeTypedArray (android.content.res.BridgeTypedArray)12 NotFoundException (android.content.res.Resources.NotFoundException)12