Search in sources :

Example 1 with RunAndroidAvdManagerAction

use of org.jetbrains.android.actions.RunAndroidAvdManagerAction 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)

Aggregations

Device (com.android.sdklib.devices.Device)1 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)1 AvdManager (com.android.sdklib.internal.avd.AvdManager)1 FormFactor (com.android.tools.idea.npw.FormFactor)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 RunAndroidAvdManagerAction (org.jetbrains.android.actions.RunAndroidAvdManagerAction)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 NotNull (org.jetbrains.annotations.NotNull)1