use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class ChooseModuleTypeStep method sortModuleEntries.
@NotNull
private static List<ModuleGalleryEntry> sortModuleEntries(@NotNull List<ModuleGalleryEntry> moduleTypesProviders) {
List<ModuleGalleryEntry> res = new ArrayList<>(moduleTypesProviders);
Collections.sort(res, (t1, t2) -> {
FormFactor f1 = (t1 instanceof ModuleTemplateGalleryEntry) ? ((ModuleTemplateGalleryEntry) t1).getFormFactor() : null;
FormFactor f2 = (t2 instanceof ModuleTemplateGalleryEntry) ? ((ModuleTemplateGalleryEntry) t2).getFormFactor() : null;
if (f1 != null && f2 != null) {
return f1.compareTo(f2);
}
if (f1 != null) {
return -1;
}
if (f2 != null) {
return 1;
}
return StringUtil.naturalCompare(t1.getName(), t2.getName());
});
return res;
}
use of com.android.tools.idea.npw.FormFactor 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.npw.FormFactor in project android by JetBrains.
the class AndroidVersionsInfo method addPackages.
private void addPackages(@NotNull FormFactor myFormFactor, @NotNull List<VersionItem> versionItemList, @NotNull Collection<? extends RepoPackage> packages, int minSdkLevel) {
List<RepoPackage> sorted = packages.stream().filter(repoPackage -> repoPackage != null && filterPkgDesc(repoPackage, myFormFactor, minSdkLevel)).collect(Collectors.toList());
Collections.sort(sorted, (repoPackage, other) -> getAndroidVersion(repoPackage).compareTo(getAndroidVersion(other)));
int existingApiLevel = -1;
int prevInsertedApiLevel = -1;
int index = -1;
for (RepoPackage info : sorted) {
int apiLevel = getFeatureLevel(info);
while (apiLevel > existingApiLevel) {
existingApiLevel = ++index < versionItemList.size() ? versionItemList.get(index).myApiLevel : Integer.MAX_VALUE;
}
if (apiLevel != existingApiLevel && apiLevel != prevInsertedApiLevel) {
versionItemList.add(index++, new VersionItem(info));
prevInsertedApiLevel = apiLevel;
}
}
}
use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.
the class FormFactorApiComboBoxTest method testDefaultSelectedItem.
@Test
public void testDefaultSelectedItem() {
FormFactor formFactor = FormFactor.MOBILE;
assertEquals("none", PropertiesComponent.getInstance().getValue(getPropertiesComponentMinSdkKey(formFactor), "none"));
List<AndroidVersionsInfo.VersionItem> items = Lists.newArrayList(createMockVersionItem(String.valueOf(formFactor.defaultApi - 1)), // Default is at position 1
createMockVersionItem(String.valueOf(formFactor.defaultApi)), createMockVersionItem(String.valueOf(formFactor.defaultApi + 1)), createMockVersionItem(String.valueOf(formFactor.defaultApi + 2)));
FormFactorApiComboBox apiComboBox = new FormFactorApiComboBox();
apiComboBox.init(formFactor, items);
assertEquals(1, apiComboBox.getSelectedIndex());
// Make sure the default does not change if the list is reloaded
apiComboBox.init(formFactor, items);
assertEquals(1, apiComboBox.getSelectedIndex());
apiComboBox.init(formFactor, Lists.reverse(items));
assertEquals(2, apiComboBox.getSelectedIndex());
items.remove(1);
apiComboBox.init(formFactor, items);
assertEquals(0, apiComboBox.getSelectedIndex());
apiComboBox.setSelectedIndex(2);
String savedApi = PropertiesComponent.getInstance().getValue(getPropertiesComponentMinSdkKey(formFactor), "none");
assertEquals(items.get(2).getApiLevelStr(), savedApi);
}
Aggregations