Пример #1
0
  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());
  }
Пример #3
0
  private void updateLookAdapter(String name, String fileName) {
    name = Utils.getUniqueLookName(name);

    LookData lookData = new LookData();
    lookData.setLookFilename(fileName);
    lookData.setLookName(name);
    lookDataList.add(lookData);

    adapter.notifyDataSetChanged();

    if (lookDataListChangedAfterNewListener != null) {
      lookDataListChangedAfterNewListener.onLookDataListChangedAfterNew(lookData);
    }

    // scroll down the list to the new item:
    final ListView listView = getListView();
    listView.post(
        new Runnable() {
          @Override
          public void run() {
            listView.setSelection(listView.getCount() - 1);
          }
        });
  }
Пример #4
0
  private boolean handleOkButton() {
    EditText editText = (EditText) dialogView.findViewById(R.id.dialog_new_object_name_edit_text);
    String newSpriteName;
    if (editText.length() == 0) {
      newSpriteName = editText.getHint().toString();
    } else {
      newSpriteName = editText.getText().toString().trim();
    }
    if (newSpriteName.contains(".")) {
      int fileExtensionPosition = newSpriteName.indexOf(".");
      newSpriteName = newSpriteName.substring(0, fileExtensionPosition);
    }

    ProjectManager projectManager = ProjectManager.getInstance();

    if (newSpriteName.equalsIgnoreCase("")) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_invalid);
      return false;
    }

    if (projectManager.spriteExists(newSpriteName)) {
      Utils.showErrorDialog(getActivity(), R.string.spritename_already_exists);
      return false;
    }

    Sprite sprite = new Sprite(newSpriteName);
    projectManager.addSprite(sprite);

    LookData lookData;
    try {
      File newLookFile =
          StorageHandler.getInstance()
              .copyImage(projectManager.getCurrentProject().getName(), lookUri.getPath(), null);

      String imageFileName = newLookFile.getName();
      Utils.rewriteImageFileForStage(getActivity(), newLookFile);

      lookData = new LookData();
      lookData.setLookFilename(imageFileName);
      lookData.setLookName(newSpriteName);
    } catch (IOException exception) {
      Utils.showErrorDialog(getActivity(), R.string.error_load_image);
      exception.printStackTrace();

      return false;
    }

    sprite.getLookDataList().add(lookData);

    if (requestedAction == ActionAfterFinished.ACTION_UPDATE_SPINNER && spinnerAdapter != null) {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
      spinnerAdapter.refreshSpinnerAfterNewSprite(getActivity(), newSpriteName);
    } else {
      Intent broadcastIntent;
      broadcastIntent = new Intent(ScriptActivity.ACTION_SPRITES_LIST_CHANGED);
      getActivity().sendBroadcast(broadcastIntent);
    }

    if (requestedAction == ActionAfterFinished.ACTION_FORWARD_TO_NEW_OBJECT) {
      projectManager.setCurrentSprite(sprite);

      Intent intent = new Intent(getActivity(), ProgramMenuActivity.class);
      intent.putExtra(
          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY, ScriptActivity.FRAGMENT_SCRIPTS);
      startActivity(intent);
    }
    dismiss();
    return true;
  }
Пример #5
0
  private void createProject() {
    ScreenValues.SCREEN_HEIGHT = SCREEN_HEIGHT;
    ScreenValues.SCREEN_WIDTH = SCREEN_WIDTH;

    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);

    // yellow Sprite
    Sprite yellowSprite = new Sprite("yellowSprite");
    StartScript yellowStartScript = new StartScript();
    LookData yellowLookData = new LookData();
    String yellowImageName = "yellow_image.bmp";

    yellowLookData.setLookName(yellowImageName);

    yellowSprite.getLookDataList().add(yellowLookData);

    yellowStartScript.addBrick(new PlaceAtBrick(-21, 21));

    yellowSprite.addScript(yellowStartScript);

    WhenScript yellowWhenScript = new WhenScript();
    SetGhostEffectBrick yellowSetGhostEffectBrick = new SetGhostEffectBrick(100d);
    yellowWhenScript.addBrick(yellowSetGhostEffectBrick);

    yellowSprite.addScript(yellowWhenScript);

    // blue Sprite
    Sprite blueSprite = new Sprite("blueSprite");
    StartScript blueStartScript = new StartScript();
    LookData blueLookData = new LookData();
    String blueImageName = "blue_image.bmp";

    blueLookData.setLookName(blueImageName);

    blueSprite.getLookDataList().add(blueLookData);

    blueStartScript.addBrick(new PlaceAtBrick(21, 21));

    blueSprite.addScript(blueStartScript);

    WhenScript blueWhenScript = new WhenScript();
    SetSizeToBrick blueSetSizeToBrick = new SetSizeToBrick(200d);
    blueWhenScript.addBrick(blueSetSizeToBrick);

    blueSprite.addScript(blueWhenScript);

    // green Sprite
    Sprite greenSprite = new Sprite("greenSprite");
    StartScript greenStartScript = new StartScript();
    LookData greenLookData = new LookData();
    String greenImageName = "green_image.bmp";

    greenLookData.setLookName(greenImageName);

    greenSprite.getLookDataList().add(greenLookData);

    greenStartScript.addBrick(new PlaceAtBrick(21, -21));

    greenSprite.addScript(greenStartScript);

    WhenScript greenWhenScript = new WhenScript();
    ComeToFrontBrick greenComeToFrontBrick = new ComeToFrontBrick();
    greenWhenScript.addBrick(greenComeToFrontBrick);

    greenSprite.addScript(greenWhenScript);

    // red Sprite
    Sprite redSprite = new Sprite("redSprite");
    StartScript redStartScript = new StartScript();
    LookData redLookData = new LookData();
    String redImageName = "red_image.bmp";

    redLookData.setLookName(redImageName);

    redSprite.getLookDataList().add(redLookData);

    redStartScript.addBrick(new PlaceAtBrick(-21, -21));

    redSprite.addScript(redStartScript);

    WhenScript redWhenScript = new WhenScript();
    ComeToFrontBrick redComeToFrontBrick = new ComeToFrontBrick();
    SetBrightnessBrick redSetBrightnessBrick = new SetBrightnessBrick(50d);
    TurnLeftBrick redTurnLeftBrick = new TurnLeftBrick(45d);
    redWhenScript.addBrick(redComeToFrontBrick);
    redWhenScript.addBrick(redSetBrightnessBrick);
    redWhenScript.addBrick(redTurnLeftBrick);

    redSprite.addScript(redWhenScript);

    // black Sprite
    Sprite blackSprite = new Sprite("blackSprite");
    StartScript blackStartScript = new StartScript();
    LookData blackLookData = new LookData();
    String blackImageName = "black_image.bmp";

    blackLookData.setLookName(blackImageName);

    blackSprite.getLookDataList().add(blackLookData);

    blackStartScript.addBrick(new PlaceAtBrick(-50, 50));

    blackSprite.addScript(blackStartScript);

    WhenScript blackWhenScript = new WhenScript();
    ComeToFrontBrick blackComeToFrontBrick = new ComeToFrontBrick();
    SetBrightnessBrick blackSetBrightnessBrick = new SetBrightnessBrick(150d);
    blackWhenScript.addBrick(blackComeToFrontBrick);
    blackWhenScript.addBrick(blackSetBrightnessBrick);

    blackSprite.addScript(blackWhenScript);

    project.addSprite(blackSprite);
    project.addSprite(yellowSprite);
    project.addSprite(redSprite);
    project.addSprite(greenSprite);
    project.addSprite(blueSprite);

    StorageHandler.getInstance().saveProject(project);

    File yellowImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            yellowImageName,
            org.catrobat.catroid.test.R.raw.yellow_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File greenImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            greenImageName,
            org.catrobat.catroid.test.R.raw.green_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File blueImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            blueImageName,
            org.catrobat.catroid.test.R.raw.blue_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File redImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            redImageName,
            org.catrobat.catroid.test.R.raw.red_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    File blackImageFile =
        UiTestUtils.saveFileToProject(
            project.getName(),
            blackImageName,
            org.catrobat.catroid.test.R.raw.black_image,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.IMAGE);
    yellowLookData.setLookFilename(yellowImageFile.getName());
    greenLookData.setLookFilename(greenImageFile.getName());
    blueLookData.setLookFilename(blueImageFile.getName());
    redLookData.setLookFilename(redImageFile.getName());
    blackLookData.setLookFilename(blackImageFile.getName());

    StorageHandler.getInstance().saveProject(project);
    ProjectManager.getInstance().setProject(project);
  }