Search in sources :

Example 1 with TemplateManager

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

the class ChooseTemplateStep method getTemplateList.

/**
   * Search the given folder for a list of templates and populate the display list.
   */
protected static List<MetadataListItem> getTemplateList(TemplateWizardState state, String templateFolder, @Nullable Set<String> excluded) {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> templates = manager.getTemplates(templateFolder);
    return getTemplateList(state, templates, excluded);
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File)

Example 2 with TemplateManager

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

the class NewFormFactorModulePath method getAvailableFormFactorModulePaths.

public static List<NewFormFactorModulePath> getAvailableFormFactorModulePaths(@NotNull Disposable disposable) {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    List<NewFormFactorModulePath> toReturn = Lists.newArrayList();
    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;
        }
        NewFormFactorModulePath path = new NewFormFactorModulePath(formFactor, templateFile, disposable);
        toReturn.add(path);
    }
    Collections.sort(toReturn, (p1, p2) -> p1.myFormFactor.compareTo(p2.myFormFactor));
    return toReturn;
}
Also used : TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 3 with TemplateManager

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

the class ImportSourceModulePath method createImportTemplateWithCustomName.

@NotNull
protected static MetadataListItem createImportTemplateWithCustomName(@NotNull final String importTemplateName, @Nullable final String description) {
    // Now, we're going to add in two pointers to the same template
    File moduleTemplate = new File(TemplateManager.getTemplateRootFolder(), FileUtil.join(Template.CATEGORY_PROJECTS, "ImportExistingProject"));
    TemplateManager manager = TemplateManager.getInstance();
    TemplateMetadata metadata = manager.getTemplateMetadata(moduleTemplate);
    assert metadata != null;
    return new MetadataListItem(moduleTemplate, metadata) {

        @Override
        public String toString() {
            return importTemplateName;
        }

        @Nullable
        @Override
        public String getDescription() {
            return description == null ? super.getDescription() : description;
        }
    };
}
Also used : MetadataListItem(com.android.tools.idea.npw.ChooseTemplateStep.MetadataListItem) TemplateManager(com.android.tools.idea.templates.TemplateManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TemplateManager

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

the class NewAndroidModuleDescriptionProvider method getDescriptions.

@Override
public Collection<ModuleTemplateGalleryEntry> getDescriptions() {
    ArrayList<ModuleTemplateGalleryEntry> res = new ArrayList<>();
    TemplateManager manager = TemplateManager.getInstance();
    List<File> applicationTemplates = manager.getTemplatesInCategory(Template.CATEGORY_APPLICATION);
    for (File templateFile : applicationTemplates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(templateFile);
        if (metadata == null || metadata.getFormFactor() == null) {
            continue;
        }
        int minSdk = metadata.getMinSdk();
        FormFactor formFactor = FormFactor.get(metadata.getFormFactor());
        if (formFactor == FormFactor.CAR) {
        // Auto is not a standalone module (but rather a modification to a mobile module)
        } else if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
        // Hidden if not installed
        } else if (formFactor.equals(FormFactor.MOBILE)) {
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, false, AndroidIcons.ModuleTemplates.Mobile, message("android.wizard.module.new.mobile"), metadata.getTitle()));
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, true, AndroidIcons.ModuleTemplates.Android, message("android.wizard.module.new.library"), metadata.getDescription()));
        } else {
            res.add(new AndroidModuleTemplateGalleryEntry(templateFile, formFactor, minSdk, false, getModuleTypeIcon(formFactor), metadata.getTitle(), metadata.getDescription()));
        }
    }
    return res;
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) ArrayList(java.util.ArrayList) TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 5 with TemplateManager

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

the class TemplateListProvider method getTemplateList.

/**
   * Search the given folder for a list of templates and populate the display list.
   */
private static TemplateEntry[] getTemplateList(@NotNull FormFactor formFactor, @NotNull String category, @Nullable Set<String> excluded) {
    TemplateManager manager = TemplateManager.getInstance();
    List<File> templates = manager.getTemplatesInCategory(category);
    List<TemplateEntry> metadataList = new ArrayList<>(templates.size());
    for (File template : templates) {
        TemplateMetadata metadata = manager.getTemplateMetadata(template);
        if (metadata == null || !metadata.isSupported()) {
            continue;
        }
        // Don't include this template if it's been excluded
        if (excluded != null && excluded.contains(metadata.getTitle())) {
            continue;
        }
        // If a form factor has been specified, ensure that requirement is met.
        if (!formFactor.id.equalsIgnoreCase(metadata.getFormFactor())) {
            continue;
        }
        metadataList.add(new TemplateEntry(template, metadata));
    }
    return ArrayUtil.toObjectArray(metadataList, TemplateEntry.class);
}
Also used : 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