Search in sources :

Example 6 with TemplateManager

use of com.android.tools.idea.templates.TemplateManager in project android by JetBrains.

the class AndroidModuleTemplatesProvider method getModuleTemplates.

@NotNull
@Override
public Iterable<ModuleTemplate> getModuleTemplates() {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    List<ModuleTemplate> moduleTemplates = Lists.newArrayList();
    for (File templateFile : applicationTemplates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(templateFile);
        if (metadata == null) {
            continue;
        }
        if (metadata.getFormFactor() != null) {
            moduleTemplates.addAll(getModuleTemplates(metadata, FormFactor.get(metadata.getFormFactor())));
        }
    }
    Collections.sort(moduleTemplates, new Comparator<ModuleTemplate>() {

        @Override
        public int compare(ModuleTemplate t1, ModuleTemplate t2) {
            FormFactor f1 = t1.getFormFactor();
            FormFactor f2 = t2.getFormFactor();
            // because of null check before we added ot moduleTemplates list
            assert f1 != null : t1;
            assert f2 != null : t2;
            return f1.compareTo(f2);
        }
    });
    return moduleTemplates;
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with TemplateManager

use of com.android.tools.idea.templates.TemplateManager in project android by JetBrains.

the class ChooseTemplateStep method getTemplateList.

/**
   * Retrieve the metadata for the given list of template files, excluding the files from the excluded set.
   */
protected static List<MetadataListItem> getTemplateList(TemplateWizardState state, List<File> templateFiles, @Nullable Set<String> excluded) {
    TemplateManager manager = TemplateManager.getInstance();
    List<MetadataListItem> metadataList = new ArrayList<>(templateFiles.size());
    for (File template : templateFiles) {
        TemplateMetadata metadata = manager.getTemplateMetadata(template);
        if (metadata == null || !metadata.isSupported()) {
            continue;
        }
        // If we're trying to create a launchable activity, don't include templates that
        // lack the isLauncher parameter.
        Boolean isLauncher = (Boolean) state.get(ATTR_IS_LAUNCHER);
        if (isLauncher != null && isLauncher && metadata.getParameter(TemplateMetadata.ATTR_IS_LAUNCHER) == null) {
            continue;
        }
        // Don't include this template if it's been excluded
        if (excluded != null && excluded.contains(metadata.getTitle())) {
            continue;
        }
        metadataList.add(new MetadataListItem(template, metadata));
    }
    Collections.sort(metadataList);
    return metadataList;
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) ArrayList(java.util.ArrayList) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 8 with TemplateManager

use of com.android.tools.idea.templates.TemplateManager in project android by JetBrains.

the class ConfigureFormFactorStep method populateAdditionalFormFactors.

private void populateAdditionalFormFactors() {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    myFormFactors.clear();
    myFormFactorPanel.removeAll();
    int row = 0;
    for (File templateFile : applicationTemplates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(templateFile);
        if (metadata == null || metadata.getFormFactor() == null) {
            continue;
        }
        FormFactor formFactor = FormFactor.get(metadata.getFormFactor());
        if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
            // Only show Glass if you've already installed the SDK
            continue;
        }
        Integer prevMinSdk = myFormFactors.get(formFactor);
        int templateMinSdk = metadata.getMinSdk();
        if (prevMinSdk == null) {
            myFormFactors.put(formFactor, Math.max(templateMinSdk, formFactor.getMinOfflineApiLevel()));
        } else if (templateMinSdk > prevMinSdk) {
            myFormFactors.put(formFactor, templateMinSdk);
        }
    }
    // One row for each form factor
    GridLayoutManager gridLayoutManager = new GridLayoutManager(myFormFactors.size(), 1);
    gridLayoutManager.setVGap(5);
    gridLayoutManager.setHGap(10);
    myFormFactorPanel.setLayout(gridLayoutManager);
    for (final FormFactor formFactor : myFormFactors.keySet()) {
        GridConstraints c = new GridConstraints();
        c.setRow(row);
        c.setColumn(0);
        c.setFill(GridConstraints.FILL_HORIZONTAL);
        c.setAnchor(GridConstraints.ANCHOR_WEST);
        FormFactorSdkControls controls = new FormFactorSdkControls(formFactor, myFormFactors.get(formFactor), myDisposable, this);
        myControls.add(controls);
        myFormFactorPanel.add(controls.getComponent(), c);
        myFormFactorApiSelectors.put(formFactor, controls);
        row++;
    }
}
Also used : GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Aggregations

TemplateManager (com.android.tools.idea.templates.TemplateManager)8 File (java.io.File)8 TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)7 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 MetadataListItem (com.android.tools.idea.npw.ChooseTemplateStep.MetadataListItem)1 FormFactor (com.android.tools.idea.npw.FormFactor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1