Search in sources :

Example 1 with FormFactor

use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.

the class FormFactorUtils method getFormFactorsImage.

/**
   * Create an image showing icons for each of the available form factors. The icons are drawn from left to right, using the form factors
   * large icon. This is an example of this method usage:
   * <pre>
   * <code>
   * myJLabel.setIcon(getFormFactorsImage(myJLabel, true));
   * </code>
   * </pre>
   * @param component Icon will be drawn in the context of the given {@code component}
   * @param requireEmulator If true, only include icons for form factors that have an emulator available.
   * @return <code>null</code> if it can't create a graphics Object to render the image (for example not enough memory)
   */
@Nullable
public static Icon getFormFactorsImage(JComponent component, boolean requireEmulator) {
    int width = 0;
    int height = 0;
    for (FormFactor formFactor : FormFactor.values()) {
        if (formFactor == FormFactor.GLASS) {
            continue;
        }
        if (requireEmulator && !formFactor.hasEmulator()) {
            continue;
        }
        Icon icon = formFactor.getLargeIcon();
        height = Math.max(height, icon.getIconHeight());
        width += formFactor.getLargeIcon().getIconWidth();
    }
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    int x = 0;
    for (FormFactor formFactor : FormFactor.values()) {
        if (requireEmulator && !formFactor.hasEmulator()) {
            continue;
        }
        if (formFactor == FormFactor.GLASS) {
            continue;
        }
        Icon icon = formFactor.getLargeIcon();
        icon.paintIcon(component, graphics, x, 0);
        x += icon.getIconWidth();
    }
    if (graphics != null) {
        graphics.dispose();
        return new ImageIcon(image);
    } else {
        return null;
    }
}
Also used : FormFactor(com.android.tools.idea.npw.FormFactor) BufferedImage(java.awt.image.BufferedImage) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with FormFactor

use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.

the class AndroidVersionsInfo method loadRemoteTargets.

private void loadRemoteTargets(@NotNull FormFactor myFormFactor, int minSdkLevel, @NotNull List<VersionItem> versionItemList, ItemsLoaded completedCallback) {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    final Runnable runCallbacks = () -> {
        if (completedCallback != null) {
            completedCallback.onDataLoadedFinished(versionItemList);
        }
    };
    RepoManager.RepoLoadedCallback onComplete = packages -> {
        addPackages(myFormFactor, versionItemList, packages.getNewPkgs(), minSdkLevel);
        addOfflineLevels(myFormFactor, versionItemList);
        runCallbacks.run();
    };
    // We need to pick up addons that don't have a target created due to the base platform not being installed.
    RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(myFormFactor, versionItemList, packages.getLocalPackages().values(), minSdkLevel);
    Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
        addOfflineLevels(myFormFactor, versionItemList);
        runCallbacks.run();
    }, ModalityState.any());
    StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
    sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
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) RepoManager(com.android.repository.api.RepoManager) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioDownloader(com.android.tools.idea.sdk.StudioDownloader)

Example 3 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 4 with FormFactor

use of com.android.tools.idea.npw.FormFactor in project android by JetBrains.

the class DeviceMenuAction method createPopupActionGroup.

@Override
@NotNull
protected DefaultActionGroup createPopupActionGroup() {
    DefaultActionGroup group = new DefaultActionGroup(null, true);
    Configuration configuration = myRenderContext.getConfiguration();
    if (configuration == null) {
        return group;
    }
    Device current = configuration.getDevice();
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();
    if (LIST_RECENT_DEVICES) {
        List<Device> recent = configurationManager.getDevices();
        if (recent.size() > 1) {
            boolean separatorNeeded = false;
            for (Device device : recent) {
                String label = getLabel(device, isNexus(device));
                Icon icon = getDeviceClassIcon(device);
                group.add(new SetDeviceAction(myRenderContext, label, device, icon, device == current));
                separatorNeeded = true;
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
    }
    AndroidFacet facet = AndroidFacet.getInstance(configurationManager.getModule());
    if (facet == null) {
        // Unlikely, but has happened - see http://b.android.com/68091
        return group;
    }
    if (!deviceList.isEmpty()) {
        Map<String, List<Device>> manufacturers = new TreeMap<>();
        for (Device device : deviceList) {
            List<Device> devices;
            if (manufacturers.containsKey(device.getManufacturer())) {
                devices = manufacturers.get(device.getManufacturer());
            } else {
                devices = new ArrayList<>();
                manufacturers.put(device.getManufacturer(), devices);
            }
            devices.add(device);
        }
        List<Device> nexus = new ArrayList<>();
        Map<FormFactor, List<Device>> deviceMap = Maps.newEnumMap(FormFactor.class);
        for (FormFactor factor : FormFactor.values()) {
            deviceMap.put(factor, Lists.newArrayList());
        }
        for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {
                if (isNexus(device) && !device.getManufacturer().equals(MANUFACTURER_GENERIC) && !isWear(device) && !isTv(device)) {
                    nexus.add(device);
                } else {
                    deviceMap.get(FormFactor.getFormFactor(device)).add(device);
                }
            }
        }
        sortDevicesByScreenSize(nexus);
        for (List<Device> list : splitDevicesByScreenSize(nexus)) {
            addNexusDeviceSection(group, current, list);
            group.addSeparator();
        }
        addDeviceSection(group, current, deviceMap, false, FormFactor.WEAR);
        group.addSeparator();
        addDeviceSection(group, current, deviceMap, false, FormFactor.TV);
        group.addSeparator();
        final AvdManager avdManager = facet.getAvdManagerSilently();
        if (avdManager != null) {
            boolean separatorNeeded = false;
            boolean first = true;
            for (AvdInfo avd : avdManager.getValidAvds()) {
                Device device = configurationManager.createDeviceForAvd(avd);
                if (device != null) {
                    String avdName = "AVD: " + avd.getName();
                    boolean selected = current != null && (current.getDisplayName().equals(avdName) || current.getId().equals(avdName));
                    Icon icon = first ? getDeviceClassIcon(device) : null;
                    group.add(new SetDeviceAction(myRenderContext, avdName, device, icon, selected));
                    first = false;
                    separatorNeeded = true;
                }
            }
            if (separatorNeeded) {
                group.addSeparator();
            }
        }
        DefaultActionGroup genericGroup = new DefaultActionGroup("_Generic Phones and Tablets", true);
        sortDevicesByScreenSize(deviceMap.get(FormFactor.MOBILE));
        addDeviceSection(genericGroup, current, deviceMap, true, FormFactor.MOBILE);
        group.add(genericGroup);
    }
    group.add(new RunAndroidAvdManagerAction("Add Device Definition..."));
    return group;
}
Also used : Device(com.android.sdklib.devices.Device) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) FormFactor(com.android.tools.idea.npw.FormFactor) AvdManager(com.android.sdklib.internal.avd.AvdManager) RunAndroidAvdManagerAction(org.jetbrains.android.actions.RunAndroidAvdManagerAction) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FormFactor

use of com.android.tools.idea.npw.FormFactor 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)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