Search in sources :

Example 1 with ThemeHelper

use of com.android.tools.idea.npw.ThemeHelper in project android by JetBrains.

the class NewAndroidComponentAction method update.

@Override
public void update(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    Module module = LangDataKeys.MODULE.getData(dataContext);
    if (module == null) {
        return;
    }
    AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(module);
    if (moduleInfo == null) {
        return;
    }
    Presentation presentation = e.getPresentation();
    int moduleMinSdkVersion = moduleInfo.getMinSdkVersion().getApiLevel();
    if (myMinSdkVersion > moduleMinSdkVersion) {
        presentation.setText(AndroidBundle.message("android.wizard.action.requires.minsdk", myTemplateName, myMinSdkVersion));
        presentation.setEnabled(false);
    } else if (myRequireAppTheme) {
        ThemeHelper themeHelper = new ThemeHelper(module);
        if (themeHelper.getAppThemeName() == null) {
            presentation.setText(AndroidBundle.message("android.wizard.action.no.app.theme", myTemplateName));
            presentation.setEnabled(false);
        }
    }
}
Also used : AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) ThemeHelper(com.android.tools.idea.npw.ThemeHelper) Module(com.intellij.openapi.module.Module)

Example 2 with ThemeHelper

use of com.android.tools.idea.npw.ThemeHelper 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

ThemeHelper (com.android.tools.idea.npw.ThemeHelper)2 Module (com.intellij.openapi.module.Module)2 Configuration (com.android.tools.idea.configurations.Configuration)1 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)1 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1