Search in sources :

Example 1 with ModuleTemplateProvider

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));
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ModuleTemplate(com.android.tools.idea.npw.ModuleTemplate) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) FormFactor(com.android.tools.idea.npw.FormFactor) ModuleTemplateProvider(com.android.tools.idea.npw.ModuleTemplateProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FormFactor (com.android.tools.idea.npw.FormFactor)1 ModuleTemplate (com.android.tools.idea.npw.ModuleTemplate)1 ModuleTemplateProvider (com.android.tools.idea.npw.ModuleTemplateProvider)1 ScopedStateStore (com.android.tools.idea.wizard.dynamic.ScopedStateStore)1 ImmutableList (com.google.common.collect.ImmutableList)1 Nullable (org.jetbrains.annotations.Nullable)1