public void testClipartSource() throws Exception {
    myState.put(ATTR_SOURCE_TYPE, SourceType.CLIPART);

    ArgumentCaptor<ActionBarIconGenerator.ActionBarOptions> argument = runImageTest();

    BufferedImage expectedImage =
        GraphicGenerator.getClipartImage(myState.getString(ATTR_CLIPART_NAME));
    assertImagesSimilar("ClipartImage", expectedImage, argument.getValue().sourceImage, 5.0f);
  }
Esempio n. 2
0
  Map<String, Map<String, BufferedImage>> generateImages(boolean previewOnly) {
    // Map of ids to images: Preserve insertion order (the densities)
    Map<String, Map<String, BufferedImage>> categoryMap =
        new LinkedHashMap<String, Map<String, BufferedImage>>();

    CreateAssetSetWizard wizard = (CreateAssetSetWizard) getWizard();
    AssetType type = wizard.getAssetType();
    boolean crop = mTrimCheckBox.getSelection();

    BufferedImage sourceImage = null;
    if (mImageRadio.getSelection()) {
      // Load the image
      // TODO: Only do this when the source image type is image
      String path = mImagePathText.getText().trim();
      if (path.length() == 0) {
        setErrorMessage("Enter a filename");
        return Collections.emptyMap();
      }
      File file = new File(path);
      if (!file.exists()) {
        setErrorMessage(String.format("%1$s does not exist", file.getPath()));
        return Collections.emptyMap();
      }

      setErrorMessage(null);
      sourceImage = getImage(path, false);
      if (sourceImage != null) {
        if (crop) {
          sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
        }
        int padding = getPadding();
        if (padding != 0) {
          sourceImage = Util.paddedImage(sourceImage, padding);
        }
      }
    } else if (mTextRadio.getSelection()) {
      String text = mText.getText();
      TextRenderUtil.Options options = new TextRenderUtil.Options();
      options.font = getSelectedFont();
      int color;
      if (type.needsColors()) {
        color = 0xFF000000 | (mFgColor.red << 16) | (mFgColor.green << 8) | mFgColor.blue;
      } else {
        color = 0xFFFFFFFF;
      }
      options.foregroundColor = color;
      sourceImage = TextRenderUtil.renderTextImage(text, getPadding(), options);

      if (crop) {
        sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
      }

      int padding = getPadding();
      if (padding != 0) {
        sourceImage = Util.paddedImage(sourceImage, padding);
      }
    } else {
      assert mClipartRadio.getSelection();
      assert mSelectedClipart != null;
      try {
        sourceImage = GraphicGenerator.getClipartImage(mSelectedClipart);

        if (crop) {
          sourceImage = ImageUtils.cropBlank(sourceImage, null, TYPE_INT_ARGB);
        }

        if (type.needsColors()) {
          int color = 0xFF000000 | (mFgColor.red << 16) | (mFgColor.green << 8) | mFgColor.blue;
          Paint paint = new java.awt.Color(color);
          sourceImage = Util.filledImage(sourceImage, paint);
        }

        int padding = getPadding();
        if (padding != 0) {
          sourceImage = Util.paddedImage(sourceImage, padding);
        }
      } catch (IOException e) {
        AdtPlugin.log(e, null);
        return categoryMap;
      }
    }

    GraphicGenerator generator = null;
    GraphicGenerator.Options options = null;
    switch (type) {
      case LAUNCHER:
        {
          generator = new LauncherIconGenerator();
          LauncherIconGenerator.LauncherOptions launcherOptions =
              new LauncherIconGenerator.LauncherOptions();
          launcherOptions.shape =
              mCircleButton.getSelection()
                  ? GraphicGenerator.Shape.CIRCLE
                  : GraphicGenerator.Shape.SQUARE;
          launcherOptions.crop = mCropRadio.getSelection();

          if (SUPPORT_LAUNCHER_ICON_TYPES) {
            launcherOptions.style =
                mFancyRadio.getSelection()
                    ? GraphicGenerator.Style.FANCY
                    : mGlossyRadio.getSelection()
                        ? GraphicGenerator.Style.GLOSSY
                        : GraphicGenerator.Style.SIMPLE;
          } else {
            launcherOptions.style = GraphicGenerator.Style.SIMPLE;
          }

          int color = (mBgColor.red << 16) | (mBgColor.green << 8) | mBgColor.blue;
          launcherOptions.backgroundColor = color;
          // Flag which tells the generator iterator to include a web graphic
          launcherOptions.isWebGraphic = !previewOnly;
          options = launcherOptions;

          break;
        }
      case MENU:
        generator = new MenuIconGenerator();
        options = new GraphicGenerator.Options();
        break;
      case ACTIONBAR:
        {
          generator = new ActionBarIconGenerator();
          ActionBarIconGenerator.ActionBarOptions actionBarOptions =
              new ActionBarIconGenerator.ActionBarOptions();
          actionBarOptions.theme =
              mHoloDarkRadio.getSelection()
                  ? ActionBarIconGenerator.Theme.HOLO_DARK
                  : ActionBarIconGenerator.Theme.HOLO_LIGHT;

          options = actionBarOptions;
          break;
        }
      case NOTIFICATION:
        {
          generator = new NotificationIconGenerator();
          NotificationIconGenerator.NotificationOptions notificationOptions =
              new NotificationIconGenerator.NotificationOptions();
          notificationOptions.shape =
              mCircleButton.getSelection()
                  ? GraphicGenerator.Shape.CIRCLE
                  : GraphicGenerator.Shape.SQUARE;
          options = notificationOptions;
          break;
        }
      case TAB:
        generator = new TabIconGenerator();
        options = new TabIconGenerator.TabOptions();
        break;
      default:
        AdtPlugin.log(IStatus.ERROR, "Unsupported asset type: %1$s", type);
        return categoryMap;
    }

    options.sourceImage = sourceImage;

    IProject project = wizard.getProject();
    Pair<Integer, Integer> v = ManifestInfo.computeSdkVersions(project);
    options.minSdk = v.getFirst();

    String baseName = wizard.getBaseName();
    generator.generate(null, categoryMap, this, options, baseName);

    return categoryMap;
  }