Ejemplo n.º 1
0
Archivo: Main.java Proyecto: MIPS/sdk
  /**
   * Displays the list of available AVDs for the given AvdManager.
   *
   * @param avdManager
   */
  public void displayAvdList(AvdManager avdManager) {
    mSdkLog.printf("Available Android Virtual Devices:\n");

    AvdInfo[] avds = avdManager.getValidAvds();
    for (int index = 0; index < avds.length; index++) {
      AvdInfo info = avds[index];
      if (index > 0) {
        mSdkLog.printf("---------\n");
      }
      mSdkLog.printf("    Name: %s\n", info.getName());
      mSdkLog.printf("    Path: %s\n", info.getPath());

      // get the target of the AVD
      IAndroidTarget target = info.getTarget();
      if (target.isPlatform()) {
        mSdkLog.printf(
            "  Target: %s (API level %s)\n", target.getName(), target.getVersion().getApiString());
      } else {
        mSdkLog.printf("  Target: %s (%s)\n", target.getName(), target.getVendor());
        mSdkLog.printf(
            "          Based on Android %s (API level %s)\n",
            target.getVersionName(), target.getVersion().getApiString());
      }

      // display some extra values.
      Map<String, String> properties = info.getProperties();
      if (properties != null) {
        String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
        if (skin != null) {
          mSdkLog.printf("    Skin: %s\n", skin);
        }
        String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
        if (sdcard == null) {
          sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
        }
        if (sdcard != null) {
          mSdkLog.printf("  Sdcard: %s\n", sdcard);
        }
        String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT);
        if (snapshot != null) {
          mSdkLog.printf("Snapshot: %s\n", snapshot);
        }
      }
    }

    // Are there some unused AVDs?
    AvdInfo[] badAvds = avdManager.getBrokenAvds();

    if (badAvds.length == 0) {
      return;
    }

    mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n");
    boolean needSeparator = false;
    for (AvdInfo info : badAvds) {
      if (needSeparator) {
        mSdkLog.printf("---------\n");
      }
      mSdkLog.printf("    Name: %s\n", info.getName() == null ? "--" : info.getName());
      mSdkLog.printf("    Path: %s\n", info.getPath() == null ? "--" : info.getPath());

      String error = info.getErrorMessage();
      mSdkLog.printf("   Error: %s\n", error == null ? "Uknown error" : error);
      needSeparator = true;
    }
  }
  static void show(final ConfigurationChooser chooser, ToolItem combo) {
    Configuration configuration = chooser.getConfiguration();
    Device current = configuration.getDevice();
    Menu menu = new Menu(chooser.getShell(), SWT.POP_UP);

    List<Device> deviceList = chooser.getDeviceList();
    Sdk sdk = Sdk.getCurrent();
    if (sdk != null) {
      AvdManager avdManager = sdk.getAvdManager();
      if (avdManager != null) {
        boolean separatorNeeded = false;
        AvdInfo[] avds = avdManager.getValidAvds();
        for (AvdInfo avd : avds) {
          for (Device device : deviceList) {
            if (device.getManufacturer().equals(avd.getDeviceManufacturer())
                && device.getName().equals(avd.getDeviceName())) {
              separatorNeeded = true;
              MenuItem item = new MenuItem(menu, SWT.CHECK);
              item.setText(avd.getName());
              item.setSelection(current == device);

              item.addSelectionListener(new DeviceMenuListener(chooser, device));
            }
          }
        }

        if (separatorNeeded) {
          @SuppressWarnings("unused")
          MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);
        }
      }
    }

    // Group the devices by manufacturer, then put them in the menu.
    // If we don't have anything but Nexus devices, group them together rather than
    // make many manufacturer submenus.
    boolean haveNexus = false;
    boolean haveNonNexus = false;
    if (!deviceList.isEmpty()) {
      Map<String, List<Device>> manufacturers = new TreeMap<String, List<Device>>();
      for (Device device : deviceList) {
        List<Device> devices;
        if (isNexus(device)) {
          haveNexus = true;
        } else if (!isGeneric(device)) {
          haveNonNexus = true;
        }
        if (manufacturers.containsKey(device.getManufacturer())) {
          devices = manufacturers.get(device.getManufacturer());
        } else {
          devices = new ArrayList<Device>();
          manufacturers.put(device.getManufacturer(), devices);
        }
        devices.add(device);
      }
      if (haveNonNexus) {
        for (List<Device> devices : manufacturers.values()) {
          Menu manufacturerMenu = menu;
          if (manufacturers.size() > 1) {
            MenuItem item = new MenuItem(menu, SWT.CASCADE);
            item.setText(devices.get(0).getManufacturer());
            manufacturerMenu = new Menu(menu);
            item.setMenu(manufacturerMenu);
          }
          for (final Device device : devices) {
            MenuItem deviceItem = new MenuItem(manufacturerMenu, SWT.CHECK);
            deviceItem.setText(getGenericLabel(device));
            deviceItem.setSelection(current == device);
            deviceItem.addSelectionListener(new DeviceMenuListener(chooser, device));
          }
        }
      } else {
        List<Device> nexus = new ArrayList<Device>();
        List<Device> generic = new ArrayList<Device>();
        if (haveNexus) {
          // Nexus
          for (List<Device> devices : manufacturers.values()) {
            for (Device device : devices) {
              if (isNexus(device)) {
                if (device.getManufacturer().equals(GENERIC)) {
                  generic.add(device);
                } else {
                  nexus.add(device);
                }
              } else {
                generic.add(device);
              }
            }
          }
        }

        if (!nexus.isEmpty()) {
          sortNexusList(nexus);
          for (final Device device : nexus) {
            MenuItem item = new MenuItem(menu, SWT.CHECK);
            item.setText(getNexusLabel(device));
            item.setSelection(current == device);
            item.addSelectionListener(new DeviceMenuListener(chooser, device));
          }

          @SuppressWarnings("unused")
          MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);
        }

        // Generate the generic menu.
        Collections.reverse(generic);
        for (final Device device : generic) {
          MenuItem item = new MenuItem(menu, SWT.CHECK);
          item.setText(getGenericLabel(device));
          item.setSelection(current == device);
          item.addSelectionListener(new DeviceMenuListener(chooser, device));
        }
      }
    }

    @SuppressWarnings("unused")
    MenuItem separator = new MenuItem(menu, SWT.SEPARATOR);

    ConfigurationMenuListener.addTogglePreviewModeAction(
        menu, "Preview All Screens", chooser, RenderPreviewMode.SCREENS);

    Rectangle bounds = combo.getBounds();
    Point location = new Point(bounds.x, bounds.y + bounds.height);
    location = combo.getParent().toDisplay(location);
    menu.setLocation(location.x, location.y);
    menu.setVisible(true);
  }