Search in sources :

Example 11 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class AndroidThemePreviewPanel method rebuild.

/**
   * Rebuild the preview
   * @param forceRepaint if true, a component repaint will be issued
   */
private void rebuild(boolean forceRepaint) {
    try {
        Configuration configuration = myContext.getConfiguration();
        int minApiLevel = configuration.getTarget() != null ? configuration.getTarget().getVersion().getApiLevel() : Integer.MAX_VALUE;
        ThemePreviewBuilder builder = new ThemePreviewBuilder().setBackgroundColor(getBackground()).addAllComponents(ThemePreviewBuilder.AVAILABLE_BASE_COMPONENTS).addNavigationBar(configuration.supports(Features.THEME_PREVIEW_NAVIGATION_BAR)).addAllComponents(myCustomComponents).addComponentFilter(new ThemePreviewBuilder.SearchFilter(mySearchTerm)).addComponentFilter(new ThemePreviewBuilder.ApiLevelFilter(minApiLevel)).addComponentFilter(myGroupFilter);
        myIsAppCompatTheme = ThemeEditorUtils.isSelectedAppCompatTheme(myContext);
        if (myIsAppCompatTheme) {
            builder.addComponentFilter(mySupportReplacementsFilter).addAllComponents(mySupportLibraryComponents);
        // sometimes we come here when the mySupportLibraryComponents and the mySupportReplacementsFilter are not ready yet
        // that is not too bad, as when they are ready, we will call reload again, and then the components list will be correct.
        }
        myAndroidPreviewPanel.setDocument(builder.build());
        if (forceRepaint) {
            repaint();
        }
    } catch (ParserConfigurationException e) {
        LOG.error("Unable to generate dynamic theme preview", e);
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 12 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class VariantItemListener method itemStateChanged.

@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() != ItemEvent.SELECTED) {
        return;
    }
    VariantsComboItem item = (VariantsComboItem) e.getItem();
    Configuration oldConfiguration = myContext.getConfiguration();
    ConfigurationManager manager = oldConfiguration.getConfigurationManager();
    Configuration newConfiguration = Configuration.create(manager, null, null, item.getRestrictedConfiguration());
    // Target and locale are global so we need to set them in the configuration manager when updated
    VersionQualifier newVersionQualifier = item.getRestrictedConfiguration().getVersionQualifier();
    if (newVersionQualifier != null) {
        IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
        assert realTarget != null;
        manager.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
    } else {
        manager.setTarget(null);
    }
    LocaleQualifier newLocaleQualifier = item.getRestrictedConfiguration().getLocaleQualifier();
    manager.setLocale(newLocaleQualifier != null ? Locale.create(newLocaleQualifier) : Locale.ANY);
    oldConfiguration.setDevice(null, false);
    Configuration.copyCompatible(newConfiguration, oldConfiguration);
    oldConfiguration.updated(ConfigurationListener.MASK_FOLDERCONFIG);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier)

Example 13 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class AndroidThemePreviewPanel method refreshConfiguration.

private void refreshConfiguration() {
    Configuration configuration = myContext.getConfiguration();
    myAndroidPreviewPanel.updateConfiguration(configuration);
    refreshScale();
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 14 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class RenderService method warnIfObsoleteLayoutLib.

private static void warnIfObsoleteLayoutLib(@NotNull final Module module, @NotNull RenderLogger logger, @Nullable final EditorDesignSurface surface, @NotNull IAndroidTarget target) {
    if (!ourWarnAboutObsoleteLayoutLibVersions) {
        return;
    }
    if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
        // We are using the version shipped with studio, it can never be obsolete. StudioEmbeddedRenderTarget does not implement getVersion.
        ourWarnAboutObsoleteLayoutLibVersions = false;
        return;
    }
    if (target instanceof CompatibilityRenderTarget) {
        target = ((CompatibilityRenderTarget) target).getRenderTarget();
    }
    final AndroidVersion version = target.getVersion();
    final int revision;
    // are minimum revisions; if a later version is available, it will be installed.
    switch(version.getFeatureLevel()) {
        case 23:
            revision = 2;
            break;
        case 22:
            revision = 2;
            break;
        case 21:
            revision = 2;
            break;
        case 20:
            revision = 2;
            break;
        case 19:
            revision = 4;
            break;
        case 18:
            revision = 3;
            break;
        case 17:
            revision = 3;
            break;
        case 16:
            revision = 5;
            break;
        case 15:
            revision = 5;
            break;
        case 14:
            revision = 4;
            break;
        case 13:
            revision = 1;
            break;
        case 12:
            revision = 3;
            break;
        case 11:
            revision = 2;
            break;
        case 10:
            revision = 2;
            break;
        case 8:
            revision = 3;
            break;
        default:
            revision = -1;
            break;
    }
    if (revision >= 0 && target.getRevision() < revision) {
        RenderProblem.Html problem = RenderProblem.create(WARNING);
        problem.tag("obsoleteLayoutlib");
        HtmlBuilder builder = problem.getHtmlBuilder();
        builder.add("Using an obsolete version of the " + target.getVersionName() + " layout library which contains many known bugs: ");
        builder.addLink("Install Update", logger.getLinkManager().createRunnableLink(() -> {
            // Don't warn again
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourWarnAboutObsoleteLayoutLibVersions = false;
            List<String> requested = Lists.newArrayList();
            // The revision to install. Note that this will install a higher version than this if available;
            // e.g. even if we ask for version 4, if revision 7 is available it will be installed, not revision 4.
            requested.add(DetailsTypes.getPlatformPath(version));
            ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(module.getProject(), requested);
            if (dialog != null && dialog.showAndGet()) {
                if (surface != null) {
                    // Force the target to be recomputed; this will pick up the new revision object from the local sdk.
                    Configuration configuration = surface.getConfiguration();
                    if (configuration != null) {
                        configuration.getConfigurationManager().setTarget(null);
                    }
                    surface.requestRender();
                    // However, due to issue https://code.google.com/p/android/issues/detail?id=76096 it may not yet
                    // take effect.
                    Messages.showInfoMessage(module.getProject(), "Note: Due to a bug you may need to restart the IDE for the new layout library to fully take effect", "Restart Recommended");
                }
            }
        }));
        builder.addLink(", ", "Ignore For Now", null, logger.getLinkManager().createRunnableLink(() -> {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourWarnAboutObsoleteLayoutLibVersions = false;
            if (surface != null) {
                surface.requestRender();
            }
        }));
        logger.addMessage(problem);
    }
}
Also used : CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) Configuration(com.android.tools.idea.configurations.Configuration) HtmlBuilder(com.android.utils.HtmlBuilder) List(java.util.List) AndroidVersion(com.android.sdklib.AndroidVersion) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 15 with Configuration

use of com.android.tools.idea.configurations.Configuration in project android by JetBrains.

the class FmGetApplicationThemeMethod method exec.

@Override
public Object exec(List arguments) throws TemplateModelException {
    String modulePath = (String) myParamMap.get(TemplateMetadata.ATTR_PROJECT_OUT);
    if (modulePath == null) {
        return null;
    }
    Module module = FmUtil.findModule(modulePath);
    if (module == null) {
        return null;
    }
    ThemeHelper helper = new ThemeHelper(module);
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return null;
    }
    VirtualFile projectFile = module.getProject().getProjectFile();
    if (projectFile == null) {
        return null;
    }
    ConfigurationManager manager = facet.getConfigurationManager();
    Configuration configuration = manager.getConfiguration(projectFile);
    String themeName = helper.getAppThemeName();
    if (themeName == null) {
        return null;
    }
    Map<String, Object> map = Maps.newHashMap();
    map.put("name", themeName);
    map.put("isAppCompat", helper.isAppCompatTheme(themeName));
    Boolean hasActionBar = ThemeHelper.hasActionBar(configuration, themeName);
    addDerivedTheme(map, themeName, "NoActionBar", hasActionBar == Boolean.FALSE, helper, configuration);
    addDerivedTheme(map, themeName, "AppBarOverlay", false, helper, configuration);
    addDerivedTheme(map, themeName, "PopupOverlay", false, helper, configuration);
    return map;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ThemeHelper(com.android.tools.idea.npw.ThemeHelper) Configuration(com.android.tools.idea.configurations.Configuration) Module(com.intellij.openapi.module.Module) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3