use of com.android.tools.idea.npw.ModuleTemplateProvider in project android by JetBrains.
the class ChooseModuleTypeStep method init.
@Override
public void init() {
super.init();
ImmutableList.Builder<ModuleTemplate> deviceTemplates = ImmutableList.builder();
ImmutableList.Builder<ModuleTemplate> extrasTemplates = ImmutableList.builder();
Set<FormFactor> formFactorSet = Sets.newHashSet();
// Android device templates are shown first, with less important templates following
for (ModuleTemplateProvider provider : myModuleTypesProviders) {
for (ModuleTemplate moduleTemplate : provider.getModuleTemplates()) {
FormFactor formFactor = moduleTemplate.getFormFactor();
if (formFactor != null) {
if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
// Hidden if not installed
continue;
}
if (formFactor != FormFactor.CAR) {
// Auto is not a standalone module (but rather a modification to a mobile module):
deviceTemplates.add(moduleTemplate);
formFactorSet.add(formFactor);
}
} else {
extrasTemplates.add(moduleTemplate);
}
}
}
for (final FormFactor formFactor : formFactorSet) {
registerValueDeriver(FormFactorUtils.getInclusionKey(formFactor), new ValueDeriver<Boolean>() {
@Nullable
@Override
public Boolean deriveValue(@NotNull ScopedStateStore state, @Nullable ScopedStateStore.Key changedKey, @Nullable Boolean currentValue) {
ModuleTemplate moduleTemplate = myState.get(SELECTED_MODULE_TYPE_KEY);
return moduleTemplate != null && Objects.equal(formFactor, moduleTemplate.getFormFactor());
}
});
}
List<ModuleTemplate> galleryTemplatesList = deviceTemplates.build();
List<ModuleTemplate> extrasTemplatesList = extrasTemplates.build();
Iterable<ModuleTemplate> allTemplates = Iterables.concat(galleryTemplatesList, extrasTemplatesList);
myFormFactorGallery.setModel(JBList.createDefaultListModel(Iterables.toArray(allTemplates, ModuleTemplate.class)));
ModuleTypeBinding binding = new ModuleTypeBinding();
register(SELECTED_MODULE_TYPE_KEY, myPanel, binding);
myFormFactorGallery.addListSelectionListener(new ModuleTypeSelectionListener());
if (!galleryTemplatesList.isEmpty()) {
myState.put(SELECTED_MODULE_TYPE_KEY, galleryTemplatesList.get(0));
}
}
Aggregations