use of com.android.tools.idea.templates.TemplateMetadata 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;
}
use of com.android.tools.idea.templates.TemplateMetadata 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;
}
};
}
use of com.android.tools.idea.templates.TemplateMetadata in project android by JetBrains.
the class TemplateWizardStep method deriveValues.
/**
* Called by update() to write derived values to the template model.
*/
protected void deriveValues() {
TemplateMetadata metadata = myTemplateState.getTemplateMetadata();
if (metadata == null) {
return;
}
for (String changedParamId : myIdsWithNewValues) {
for (String paramName : myParamFields.keySet()) {
Parameter param = myTemplateState.hasTemplate() ? metadata.getParameter(paramName) : null;
// If this parameter is null or doesn't have anything to update (both visibility and suggestion are null or empty), skip it.
if (param == null || ((param.suggest == null || param.suggest.isEmpty()) && (param.visibility == null || param.visibility.isEmpty()))) {
continue;
}
// If this parameter has dynamic visibility, calculate it and process accordingly
if (param.visibility != null && param.visibility.contains(changedParamId)) {
updateVisibility(param);
}
// Don't process hidden fields
if (myTemplateState.myHidden.contains(paramName)) {
continue;
}
// and add it for consideration so that things dependent on it can be updated
if (param.suggest != null && param.suggest.contains(changedParamId)) {
final String updated = myStringEvaluator.evaluate(param.suggest, myTemplateState.getParameters());
if (updated != null && !updated.equals(myTemplateState.get(param.id))) {
myIdsWithNewValues.add(param.id);
updateDerivedValue(param.id, (JTextField) myParamFields.get(param.id), new Callable<String>() {
@Override
public String call() throws Exception {
return updated;
}
});
}
}
}
}
}
use of com.android.tools.idea.templates.TemplateMetadata 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;
}
use of com.android.tools.idea.templates.TemplateMetadata 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);
}
Aggregations