Example #1
0
  private void copyImageToCatroid(String originalImagePath) {
    int[] imageDimensions = ImageEditing.getImageDimensions(originalImagePath);

    if (imageDimensions[0] < 0 || imageDimensions[1] < 0) {
      Utils.showErrorDialog(getActivity(), getString(R.string.error_load_image));
      return;
    }

    File oldFile = new File(originalImagePath);

    try {
      if (originalImagePath.equals("")) {
        throw new IOException();
      }

      String projectName = ProjectManager.getInstance().getCurrentProject().getName();
      File imageFile = StorageHandler.getInstance().copyImage(projectName, originalImagePath, null);

      String imageName;
      int extensionDotIndex = oldFile.getName().lastIndexOf('.');
      if (extensionDotIndex > 0) {
        imageName = oldFile.getName().substring(0, extensionDotIndex);
      } else {
        imageName = oldFile.getName();
      }

      String imageFileName = imageFile.getName();
      // if pixmap cannot be created, image would throw an Exception in stage
      // so has to be loaded again with other Config
      Pixmap pixmap = null;
      pixmap = Utils.getPixmapFromFile(imageFile);

      if (pixmap == null) {
        ImageEditing.overwriteImageFileWithNewBitmap(imageFile);
        pixmap = Utils.getPixmapFromFile(imageFile);

        if (pixmap == null) {
          Utils.showErrorDialog(getActivity(), getString(R.string.error_load_image));
          StorageHandler.getInstance().deleteFile(imageFile.getAbsolutePath());
          return;
        }
      }
      pixmap = null;
      updateLookAdapter(imageName, imageFileName);
    } catch (IOException e) {
      Utils.showErrorDialog(getActivity(), getString(R.string.error_load_image));
    }
    getLoaderManager().destroyLoader(ID_LOADER_MEDIA_IMAGE);
    getActivity().sendBroadcast(new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED));
  }