Search in sources :

Example 6 with FormFactor

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;
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with FormFactor

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;
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) ArrayList(java.util.ArrayList) TemplateManager(com.android.tools.idea.templates.TemplateManager) File(java.io.File) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 8 with FormFactor

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;
        }
    }
}
Also used : java.util(java.util) SdkConstants(com.android.SdkConstants) ModalityState(com.intellij.openapi.application.ModalityState) RemotePackage(com.android.repository.api.RemotePackage) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidTargetHash(com.android.sdklib.AndroidTargetHash) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) DetailsTypes(com.android.sdklib.repository.meta.DetailsTypes) AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) FormFactor(com.android.tools.idea.npw.FormFactor) RepoPackage(com.android.repository.api.RepoPackage) AndroidVersion(com.android.sdklib.AndroidVersion) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata) AndroidSdkUtils(org.jetbrains.android.sdk.AndroidSdkUtils) TemplateUtils(com.android.tools.idea.templates.TemplateUtils) Collectors(java.util.stream.Collectors) IdDisplay(com.android.sdklib.repository.IdDisplay) Sets(com.google.common.collect.Sets) ProgressIndicator(com.android.repository.api.ProgressIndicator) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable) SdkVersionInfo(com.android.sdklib.SdkVersionInfo) StudioSettingsController(com.android.tools.idea.sdk.StudioSettingsController) TypeDetails(com.android.repository.impl.meta.TypeDetails) ApplicationManager(com.intellij.openapi.application.ApplicationManager) RepoManager(com.android.repository.api.RepoManager) SystemImage(com.android.sdklib.repository.targets.SystemImage) NotNull(org.jetbrains.annotations.NotNull) RepoPackage(com.android.repository.api.RepoPackage)

Example 9 with FormFactor

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);
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) Test(org.junit.Test)

Aggregations

FormFactor (com.android.tools.idea.npw.FormFactor)9 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 TemplateMetadata (com.android.tools.idea.templates.TemplateMetadata)3 ImmutableList (com.google.common.collect.ImmutableList)3 SdkConstants (com.android.SdkConstants)2 ProgressIndicator (com.android.repository.api.ProgressIndicator)2 RemotePackage (com.android.repository.api.RemotePackage)2 RepoManager (com.android.repository.api.RepoManager)2 RepoPackage (com.android.repository.api.RepoPackage)2 TypeDetails (com.android.repository.impl.meta.TypeDetails)2 AndroidTargetHash (com.android.sdklib.AndroidTargetHash)2 AndroidVersion (com.android.sdklib.AndroidVersion)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)2 SdkVersionInfo (com.android.sdklib.SdkVersionInfo)2 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)2 IdDisplay (com.android.sdklib.repository.IdDisplay)2 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)2 AndroidTargetManager (com.android.sdklib.repository.targets.AndroidTargetManager)2 SystemImage (com.android.sdklib.repository.targets.SystemImage)2