private void createProject() {
    ProjectManager projectManager = ProjectManager.getInstance();
    Project project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite firstSprite = new Sprite("cat");
    Script testScript = new StartScript(firstSprite);

    SetLookBrick setLookBrick = new SetLookBrick(firstSprite);
    testScript.addBrick(setLookBrick);

    firstSprite.addScript(testScript);
    project.addSprite(firstSprite);

    projectManager.setProject(project);
    projectManager.setCurrentSprite(firstSprite);
    projectManager.setCurrentScript(testScript);
    lookDataList = projectManager.getCurrentSprite().getLookDataList();

    lookFile =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image.png",
            RESOURCE_LOOK,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData = new LookData();
    lookData.setLookFilename(lookFile.getName());
    lookData.setLookName(lookName);

    lookFile2 =
        UiTestUtils.saveFileToProject(
            UiTestUtils.DEFAULT_TEST_PROJECT_NAME,
            "image2.png",
            RESOURCE_LOOK2,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    LookData lookData2 = new LookData();
    lookData2.setLookFilename(lookFile2.getName());
    lookData2.setLookName(lookName2);

    lookDataList.add(lookData);
    lookDataList.add(lookData2);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(lookData2.getChecksum(), lookData2.getAbsolutePath());
  }
  private void createProject() {
    Project project = new Project(null, UiTestUtils.PROJECTNAME1);

    Sprite spriteCat = new Sprite(backgroundName);
    Script startScriptCat = new StartScript();
    Script scriptTappedCat = new WhenScript();
    Brick setXBrick = new SetXBrick(50);
    Brick setYBrick = new SetYBrick(50);
    Brick changeXBrick = new ChangeXByNBrick(50);
    startScriptCat.addBrick(setYBrick);
    startScriptCat.addBrick(setXBrick);
    scriptTappedCat.addBrick(changeXBrick);

    spriteCat.addScript(startScriptCat);
    spriteCat.addScript(scriptTappedCat);
    project.addSprite(spriteCat);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(spriteCat);
    ProjectManager.getInstance().setCurrentScript(startScriptCat);

    File imageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "catroid_sunglasses.png",
            org.catrobat.catroid.test.R.drawable.catroid_sunglasses,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);

    ProjectManager projectManager = ProjectManager.getInstance();
    List<LookData> lookDataList = projectManager.getCurrentSprite().getLookDataList();
    LookData lookData = new LookData();
    lookData.setLookFilename(imageFile.getName());
    lookData.setLookName("Catroid sun");
    lookDataList.add(lookData);
    projectManager
        .getFileChecksumContainer()
        .addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());

    File soundFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            "longsound.mp3",
            org.catrobat.catroid.test.R.raw.longsound,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.SOUND);
    SoundInfo soundInfo = new SoundInfo();
    soundInfo.setSoundFileName(soundFile.getName());
    soundInfo.setTitle("longsound");

    List<SoundInfo> soundInfoList = ProjectManager.getInstance().getCurrentSprite().getSoundList();
    soundInfoList.add(soundInfo);
    ProjectManager.getInstance()
        .getFileChecksumContainer()
        .addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath());
  }
Exemple #3
0
 private Object readResolve() {
   // filling FileChecksumContainer:
   if (ProjectManager.getInstance().getCurrentProject() != null) {
     FileChecksumContainer container = ProjectManager.getInstance().getFileChecksumContainer();
     for (SoundInfo soundInfo : soundList) {
       container.addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath());
     }
     for (LookData lookData : lookList) {
       container.addChecksum(lookData.getChecksum(), lookData.getAbsolutePath());
     }
   }
   return this;
 }
Exemple #4
0
  private void loadPocketPaintImageIntoCatroid(Intent intent) {
    Bundle bundle = intent.getExtras();
    String pathOfPocketPaintImage = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT);

    int[] imageDimensions = ImageEditing.getImageDimensions(pathOfPocketPaintImage);
    if (imageDimensions[0] < 0 || imageDimensions[1] < 0) {
      Utils.showErrorDialog(getActivity(), this.getString(R.string.error_load_image));
      return;
    }

    String actualChecksum = Utils.md5Checksum(new File(pathOfPocketPaintImage));

    // If look changed --> saving new image with new checksum and changing lookData
    if (!selectedLookData.getChecksum().equalsIgnoreCase(actualChecksum)) {
      String oldFileName = selectedLookData.getLookFileName();
      String newFileName = oldFileName.substring(oldFileName.indexOf('_') + 1);

      // HACK for https://github.com/Catrobat/Catroid/issues/81
      if (!newFileName.endsWith(".png")) {
        newFileName = newFileName + ".png";
      }

      String projectName = ProjectManager.getInstance().getCurrentProject().getName();

      try {
        File newLookFile =
            StorageHandler.getInstance()
                .copyImage(projectName, pathOfPocketPaintImage, newFileName);
        File temporaryPictureFileInPocketPaint = new File(pathOfPocketPaintImage);
        temporaryPictureFileInPocketPaint.delete(); // delete temp file in paintroid

        StorageHandler.getInstance()
            .deleteFile(
                selectedLookData.getAbsolutePath()); // reduce usage in container or delete it

        selectedLookData.setLookFilename(newLookFile.getName());
        selectedLookData.resetThumbnailBitmap();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }