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;
}
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;
}
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++;
}
}
Aggregations