Beispiel #1
0
  private void createTestProject(String projectName) {
    double size = 0.8;

    Project project = new Project(null, projectName);
    Sprite firstSprite = new Sprite("cat");

    Script testScript = new StartScript();

    brickListToCheck = new ArrayList<Brick>();
    brickListToCheck.add(new HideBrick());
    brickListToCheck.add(new ShowBrick());
    brickListToCheck.add(new SetSizeToBrick(size));

    for (Brick brick : brickListToCheck) {
      testScript.addBrick(brick);
    }

    firstSprite.addScript(testScript);

    project.addSprite(firstSprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(firstSprite);
    ProjectManager.getInstance().setCurrentScript(testScript);
  }
  private void setSpinnerSelection(Spinner spinner) {
    final ArrayList<Sprite> spriteList =
        (ArrayList<Sprite>) ProjectManager.getInstance().getCurrentProject().getSpriteList();

    if (spriteList.contains(pointedObject)) {
      oldSelectedObject = pointedObject.getName();
      spinner.setSelection(
          ((SpinnerAdapterWrapper) spinner.getAdapter())
              .getAdapter()
              .getPosition(pointedObject.getName()),
          true);
    } else {
      if (oldSelectedObject != null && !oldSelectedObject.equals("")) {
        spinner.setSelection(
            ((SpinnerAdapterWrapper) spinner.getAdapter())
                .getAdapter()
                .getPosition(this.oldSelectedObject),
            true);
      } else {
        if (spinner.getAdapter().getCount() > 1) {
          spinner.setSelection(1, true);
        } else {
          spinner.setSelection(0, true);
        }
      }
    }
  }
  private void addScriptToProject(int position, ScriptBrick scriptBrick) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] temp = getScriptAndBrickIndexFromProject(position);

    int scriptPosition = temp[0];
    int brickPosition = temp[1];

    Script newScript = scriptBrick.getScriptSafe();
    if (currentSprite.getNumberOfBricks() > 0) {
      int addScriptTo = position == 0 ? 0 : scriptPosition + 1;
      currentSprite.addScript(addScriptTo, newScript);
    } else {
      currentSprite.addScript(newScript);
    }

    Script previousScript = currentSprite.getScript(scriptPosition);
    if (previousScript != null) {
      Brick brick;
      int size = previousScript.getBrickList().size();
      for (int i = brickPosition; i < size; i++) {
        brick = previousScript.getBrick(brickPosition);
        previousScript.removeBrick(brick);
        newScript.addBrick(brick);
      }
    }
    ProjectManager.getInstance().setCurrentScript(newScript);
  }
  public void testBroadcastWait() {
    Sprite sprite = new Sprite("spriteOne");
    Script scriptWait = new StartScript(sprite);
    BroadcastWaitBrick broadcastWaitBrick = new BroadcastWaitBrick(sprite);
    String message = "waitTest";
    broadcastWaitBrick.setSelectedMessage(message);
    int testPosition = 100;
    SetXBrick setXBrick = new SetXBrick(sprite, testPosition);
    scriptWait.addBrick(broadcastWaitBrick);
    scriptWait.addBrick(setXBrick);
    sprite.addScript(scriptWait);

    BroadcastScript broadcastScript = new BroadcastScript(sprite);
    WaitBrick waitBrick = new WaitBrick(sprite, 500);
    int setTestPosition = 20;
    SetXBrick setXBrick2 = new SetXBrick(sprite, setTestPosition);
    broadcastScript.setBroadcastMessage(message);
    broadcastScript.addBrick(waitBrick);
    broadcastScript.addBrick(setXBrick2);
    sprite.addScript(broadcastScript);

    sprite.startStartScripts();

    try {
      Thread.sleep(1000);
    } catch (InterruptedException ignored) {
    }

    assertEquals("Broadcast and wait failed", testPosition, (int) sprite.costume.getXPosition());
  }
  private void addBrickToPositionInProject(int position, Brick brick) {
    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();

    int[] temp = getScriptAndBrickIndexFromProject(position);

    int scriptPosition = temp[0];
    int brickPosition = temp[1];

    Script script = currentSprite.getScript(scriptPosition);

    if (brick instanceof NestingBrick) {
      ((NestingBrick) draggedBrick).initialize();
      List<NestingBrick> nestingBrickList =
          ((NestingBrick) draggedBrick).getAllNestingBrickParts(true);
      for (int i = 0; i < nestingBrickList.size(); i++) {
        if (nestingBrickList.get(i) instanceof DeadEndBrick) {
          if (i < nestingBrickList.size() - 1) {
            Log.w(TAG, "Adding a DeadEndBrick in the middle of the NestingBricks");
          }
          position = getPositionForDeadEndBrick(position);
          temp = getScriptAndBrickIndexFromProject(position);
          script.addBrick(temp[1], (Brick) nestingBrickList.get(i));
        } else {
          script.addBrick(brickPosition + i, (Brick) nestingBrickList.get(i));
        }
      }
    } else {
      script.addBrick(brickPosition, brick);
    }
  }
Beispiel #6
0
  @Override
  public Sprite clone() {
    final Sprite cloneSprite = new Sprite();

    cloneSprite.setName(this.getName());
    cloneSprite.isBackpackObject = false;

    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    if (currentProject == null || !currentProject.getSpriteList().contains(this)) {
      throw new RuntimeException("The sprite must be in the current project before cloning it.");
    }

    Sprite originalSprite = ProjectManager.getInstance().getCurrentSprite();
    ProjectManager.getInstance().setCurrentSprite(cloneSprite);

    cloneSpriteVariables(currentProject, cloneSprite);
    cloneLooks(cloneSprite);
    cloneSounds(cloneSprite);
    cloneUserBricks(cloneSprite);
    cloneNfcTags(cloneSprite);
    cloneScripts(cloneSprite);

    setUserAndVariableBrickReferences(cloneSprite, userBricks);

    ProjectManager.getInstance().checkCurrentSprite(cloneSprite, false);
    ProjectManager.getInstance().setCurrentSprite(originalSprite);

    return cloneSprite;
  }
  public void testBroadcastWait() {
    Sprite sprite = new Sprite("spriteOne");
    Script scriptWait = new StartScript(sprite);
    String message = "waitTest";
    BroadcastWaitBrick broadcastWaitBrick = new BroadcastWaitBrick(sprite, message);
    int testPosition = 100;
    SetXBrick setXBrick = new SetXBrick(sprite, testPosition);
    scriptWait.addBrick(broadcastWaitBrick);
    scriptWait.addBrick(setXBrick);
    sprite.addScript(scriptWait);

    BroadcastScript broadcastScript = new BroadcastScript(sprite, message);
    WaitBrick waitBrick = new WaitBrick(sprite, 500);
    int setTestPosition = 20;
    SetXBrick setXBrick2 = new SetXBrick(sprite, setTestPosition);
    broadcastScript.addBrick(waitBrick);
    broadcastScript.addBrick(setXBrick2);
    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), "testProject");
    project.addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequence();

    while (!sprite.look.getAllActionsAreFinished()) {
      sprite.look.act(1.0f);
    }

    assertEquals(
        "Broadcast and wait failed",
        testPosition,
        (int) sprite.look.getXInUserInterfaceDimensionUnit());
  }
  public void testBroadcast() {
    Sprite sprite = new SingleSprite("testSprite");
    Script script = new StartScript();
    String message = "simpleTest";
    BroadcastBrick broadcastBrick = new BroadcastBrick(message);
    script.addBrick(broadcastBrick);
    sprite.addScript(script);

    BroadcastScript broadcastScript = new BroadcastScript(message);
    int testPosition = 100;
    SetXBrick testBrick = new SetXBrick(testPosition);
    broadcastScript.addBrick(testBrick);
    sprite.addScript(broadcastScript);

    Project project = new Project(getContext(), UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Scene scene = project.getDefaultScene();
    scene.addSprite(sprite);
    ProjectManager.getInstance().setProject(project);

    sprite.createStartScriptActionSequenceAndPutToMap(new HashMap<String, List<String>>());

    while (!allActionsOfAllSpritesAreFinished()) {
      for (Sprite spriteOfList : ProjectManager.getInstance().getCurrentScene().getSpriteList()) {
        spriteOfList.look.act(1.0f);
      }
    }

    assertEquals(
        "Simple broadcast failed",
        testPosition,
        (int) sprite.look.getXInUserInterfaceDimensionUnit());
  }
Beispiel #9
0
  @Given("^'(\\w+)' has a Start script$")
  public void object_has_start_script(String object) {
    programWaitLockPermits -= 1;
    Project project = ProjectManager.getInstance().getCurrentProject();
    Sprite sprite = Util.findSprite(project, object);
    StartScript script = new StartScript(sprite);

    script.addBrick(
        new CallbackBrick(
            sprite,
            new CallbackBrick.BrickCallback() {
              @Override
              public void onCallback() {
                synchronized (programStartWaitLock) {
                  if (!programHasStarted) {
                    programHasStarted = true;
                    programStartWaitLock.notify();
                  }
                }
              }
            }));

    sprite.addScript(script);
    Cucumber.put(Cucumber.KEY_CURRENT_SCRIPT, script);
  }
Beispiel #10
0
  public int getRequiredResources() {
    int resources = Brick.NO_RESOURCES;

    for (Sprite sprite : spriteList) {
      resources |= sprite.getRequiredResources();
    }
    return resources;
  }
  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());
  }
Beispiel #12
0
  @Override
  public void create() {
    font = new BitmapFont();
    font.setColor(1f, 0f, 0.05f, 1f);
    font.setScale(1.2f);

    project = ProjectManager.getInstance().getCurrentProject();
    pathForScreenshot = Utils.buildProjectPath(project.getName()) + "/";

    virtualWidth = project.getXmlHeader().virtualScreenWidth;
    virtualHeight = project.getXmlHeader().virtualScreenHeight;

    virtualWidthHalf = virtualWidth / 2;
    virtualHeightHalf = virtualHeight / 2;

    stage = new Stage(virtualWidth, virtualHeight, true);
    batch = stage.getSpriteBatch();

    Gdx.gl.glViewport(0, 0, ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT);
    initScreenMode();

    sprites = project.getSpriteList();
    for (Sprite sprite : sprites) {
      sprite.resetSprite();
      sprite.look.createBrightnessContrastShader();
      stage.addActor(sprite.look);
      sprite.resume();
    }

    passepartout =
        new Passepartout(
            ScreenValues.SCREEN_WIDTH,
            ScreenValues.SCREEN_HEIGHT,
            maximizeViewPortWidth,
            maximizeViewPortHeight,
            virtualWidth,
            virtualHeight);
    stage.addActor(passepartout);

    if (DEBUG) {
      OrthoCamController camController = new OrthoCamController(camera);
      InputMultiplexer multiplexer = new InputMultiplexer();
      multiplexer.addProcessor(camController);
      multiplexer.addProcessor(stage);
      Gdx.input.setInputProcessor(multiplexer);
      fpsLogger = new FPSLogger();
    } else {
      Gdx.input.setInputProcessor(stage);
    }

    axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
    skipFirstFrameForAutomaticScreenshot = true;
    if (checkIfAutomaticScreenshotShouldBeTaken) {
      makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME);
    }
  }
Beispiel #13
0
 void menuResume() {
   if (reloadProject) {
     return;
   }
   paused = false;
   SoundManager.getInstance().resume();
   for (Sprite sprite : sprites) {
     sprite.resume();
   }
 }
Beispiel #14
0
 void menuPause() {
   if (finished || reloadProject) {
     return;
   }
   paused = true;
   SoundManager.getInstance().pause();
   for (Sprite sprite : sprites) {
     sprite.pause();
   }
 }
Beispiel #15
0
  @Given("^'(\\w+)' has a When '(\\w+)' script$")
  public void object_has_a_when_script(String object, String message) {
    programWaitLockPermits -= 1;
    Project project = ProjectManager.getInstance().getCurrentProject();
    Sprite sprite = Util.findSprite(project, object);
    BroadcastScript script = new BroadcastScript(sprite, message);

    sprite.addScript(script);
    Cucumber.put(Cucumber.KEY_CURRENT_SCRIPT, script);
  }
Beispiel #16
0
  private void setVariableReferencesOfClonedSprite(Sprite cloneSprite) {
    DataContainer dataContainer =
        ProjectManager.getInstance().getCurrentProject().getDataContainer();
    List<UserVariable> clonedSpriteVariables =
        dataContainer.getOrCreateVariableListForSprite(cloneSprite);
    cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedSpriteVariables);

    List<UserVariable> clonedProjectVariables = dataContainer.getProjectVariables();
    cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedProjectVariables);
  }
Beispiel #17
0
  @Override
  public void execute() {
    /* That's the way how an action is made */
    //		Action action = MoveBy.$(xDestination, yDestination, this.durationInMilliSeconds / 1000);
    //		final CountDownLatch latch = new CountDownLatch(1);
    //		action = action.setCompletionListener(new OnActionCompleted() {
    //			public void completed(Action action) {
    //				latch.countDown();
    //			}
    //		});
    //		sprite.look.action(action);
    //		try {
    //			latch.await();
    //		} catch (InterruptedException e) {
    //		}
    long startTime = System.currentTimeMillis();
    int duration = durationInMilliSeconds;
    while (duration > 0) {
      if (!sprite.isAlive(Thread.currentThread())) {
        break;
      }
      long timeBeforeSleep = System.currentTimeMillis();
      int sleep = 33;
      while (System.currentTimeMillis() <= (timeBeforeSleep + sleep)) {

        if (sprite.isPaused) {
          sleep = (int) ((timeBeforeSleep + sleep) - System.currentTimeMillis());
          long milliSecondsBeforePause = System.currentTimeMillis();
          while (sprite.isPaused) {
            if (sprite.isFinished) {
              return;
            }
            Thread.yield();
          }
          timeBeforeSleep = System.currentTimeMillis();
          startTime += System.currentTimeMillis() - milliSecondsBeforePause;
        }

        Thread.yield();
      }
      long currentTime = System.currentTimeMillis();
      duration -= (int) (currentTime - startTime);
      updatePositions((int) (currentTime - startTime), duration);
      startTime = currentTime;
    }

    if (!sprite.isAlive(Thread.currentThread())) {
      // -stay at last position
    } else {
      sprite.look.aquireXYWidthHeightLock();
      sprite.look.setXYPosition(xDestination, yDestination);
      sprite.look.releaseXYWidthHeightLock();
    }
  }
  public void testAliasesAndXmlHeader() {

    String projectName = "myProject";

    File projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName);
    if (projectFile.exists()) {
      UtilFile.deleteDirectory(projectFile);
    }

    Project project = new Project(getContext(), projectName);
    Sprite sprite = new Sprite("testSprite");
    Script startScript = new StartScript(sprite);
    Script whenScript = new WhenScript(sprite);
    sprite.addScript(startScript);
    sprite.addScript(whenScript);
    project.addSprite(sprite);

    ArrayList<Brick> startScriptBrickList = new ArrayList<Brick>();
    ArrayList<Brick> whenScriptBrickList = new ArrayList<Brick>();
    startScriptBrickList.add(new ChangeXByNBrick(sprite, 4));
    startScriptBrickList.add(new ChangeYByNBrick(sprite, 5));
    startScriptBrickList.add(new ComeToFrontBrick(sprite));
    startScriptBrickList.add(new GoNStepsBackBrick(sprite, 5));
    startScriptBrickList.add(new HideBrick(sprite));
    startScriptBrickList.add(new WhenStartedBrick(sprite, startScript));

    whenScriptBrickList.add(new PlaySoundBrick(sprite));
    whenScriptBrickList.add(new SetSizeToBrick(sprite, 50));
    whenScriptBrickList.add(new SetCostumeBrick(sprite));
    whenScriptBrickList.add(new SetXBrick(sprite, 50));
    whenScriptBrickList.add(new SetYBrick(sprite, 50));
    whenScriptBrickList.add(new ShowBrick(sprite));
    whenScriptBrickList.add(new WaitBrick(sprite, 1000));

    for (Brick b : startScriptBrickList) {
      startScript.addBrick(b);
    }
    for (Brick b : whenScriptBrickList) {
      whenScript.addBrick(b);
    }

    storageHandler.saveProject(project);
    String projectString = TestUtils.getProjectfileAsString(projectName);
    assertFalse("project contains package information", projectString.contains("org.catrobat"));

    String xmlHeader = (String) TestUtils.getPrivateField("XML_HEADER", new XmlSerializer(), false);
    assertTrue(
        "Project file did not contain correct XML header.", projectString.startsWith(xmlHeader));

    projectFile = new File(Constants.DEFAULT_ROOT + "/" + projectName);
    if (projectFile.exists()) {
      UtilFile.deleteDirectory(projectFile);
    }
  }
Beispiel #19
0
 public void rename(String newSpriteName) {
   if ((getRequiredResources() & Brick.PHYSICS) > 0) {
     List<Sprite> spriteList = ProjectManager.getInstance().getCurrentProject().getSpriteList();
     for (Sprite currentSprite : spriteList) {
       if ((currentSprite.getRequiredResources() & Brick.PHYSICS) > 0) {
         currentSprite.updateCollisionBroadcastMessages(getName(), newSpriteName);
       }
     }
   }
   setName(newSpriteName);
 }
Beispiel #20
0
 @Override
 public void pause() {
   if (finished) {
     return;
   }
   if (!paused) {
     SoundManager.getInstance().pause();
     for (Sprite sprite : sprites) {
       sprite.pause();
     }
   }
 }
 public void handleScriptDelete(Sprite spriteToEdit, Script scriptToDelete) {
   spriteToEdit.removeScript(scriptToDelete);
   if (spriteToEdit.getNumberOfScripts() == 0) {
     ProjectManager.getInstance().setCurrentScript(null);
     updateProjectBrickList();
   } else {
     int lastScriptIndex = spriteToEdit.getNumberOfScripts() - 1;
     Script lastScript = spriteToEdit.getScript(lastScriptIndex);
     ProjectManager.getInstance().setCurrentScript(lastScript);
     updateProjectBrickList();
   }
 }
  public void addNewBrick(int position, Brick brickToBeAdded, boolean initInsertedBrick) {

    if (draggedBrick != null) {
      Log.w(TAG, "Want to add Brick while there is another one currently dragged.");
      return;
    }

    Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite();
    int scriptCount = currentSprite.getNumberOfScripts();
    if (scriptCount == 0 && brickToBeAdded instanceof ScriptBrick) {
      currentSprite.addScript(((ScriptBrick) brickToBeAdded).getScriptSafe());
      initBrickList();
      notifyDataSetChanged();
      return;
    }

    if (position < 0) {
      position = 0;
    } else if (position > brickList.size()) {
      position = brickList.size();
    }

    if (brickToBeAdded instanceof ScriptBrick) {

      brickList.add(position, brickToBeAdded);
      position = getNewPositionForScriptBrick(position, brickToBeAdded);
      brickList.remove(brickToBeAdded);
      brickList.add(position, brickToBeAdded);
      scrollToPosition(position);

    } else {

      position = getNewPositionIfEndingBrickIsThere(position, brickToBeAdded);
      position = position <= 0 ? 1 : position;
      position = position > brickList.size() ? brickList.size() : position;
      brickList.add(position, brickToBeAdded);
    }

    this.initInsertedBrick = initInsertedBrick;
    this.positionOfInsertedBrick = position;

    if (scriptCount == 0 && userBrick == null) {
      Script script = new StartScript();
      currentSprite.addScript(script);
      brickList.add(0, script.getScriptBrick());
      ProjectManager.getInstance().setCurrentScript(script);
      clearCheckedItems();
      positionOfInsertedBrick = 1;
    }

    notifyDataSetChanged();
  }
Beispiel #23
0
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript(sprite);
    script.addBrick(new StopAllSoundsBrick(sprite));

    sprite.addScript(script);
    project.addSprite(sprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }
Beispiel #24
0
  @Override
  public void resume() {
    if (!paused) {
      SoundManager.getInstance().resume();
      for (Sprite sprite : sprites) {
        sprite.resume();
      }
    }

    for (Sprite sprite : sprites) {
      sprite.look.refreshTextures();
    }
  }
Beispiel #25
0
  private void cloneLooks(Sprite cloneSprite) {
    List<LookData> cloneLookList = new ArrayList<>();
    for (LookData element : this.lookList) {
      cloneLookList.add(element.clone());
    }
    cloneSprite.lookList = cloneLookList;

    cloneSprite.look = this.look.copyLookForSprite(cloneSprite);
    try {
      cloneSprite.look.setLookData(cloneSprite.getLookDataList().get(0));
    } catch (IndexOutOfBoundsException indexOutOfBoundsException) {
      Log.e(TAG, Log.getStackTraceString(indexOutOfBoundsException));
    }
  }
Beispiel #26
0
    public void refreshSpinnerAfterNewSprite(final Context context, final String newSpriteName) {
      Project project = ProjectManager.getInstance().getCurrentProject();
      for (Sprite sprite : project.getSpriteList()) {
        if (sprite.getName().equals(newSpriteName)) {
          pointedObject = sprite;
        }
      }

      setSpinnerSelection(spinner);

      AlertDialog dialog =
          new CustomAlertDialogBuilder(context)
              .setTitle(R.string.dialog_new_object_switch_title)
              .setMessage(R.string.dialog_new_object_switch_message)
              .setPositiveButton(
                  R.string.yes,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      ProjectManager.getInstance().setCurrentSprite(pointedObject);

                      Intent intent = new Intent(context, ProgramMenuActivity.class);
                      intent.putExtra(
                          ProgramMenuActivity.FORWARD_TO_SCRIPT_ACTIVITY,
                          ScriptActivity.FRAGMENT_SCRIPTS);
                      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                      context.startActivity(intent);

                      dialog.dismiss();
                    }
                  })
              .setNegativeButton(
                  R.string.no,
                  new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                      spinnerAdapter.notifyDataSetChanged();
                      dialog.dismiss();
                    }
                  })
              .create();
      dialog.setCanceledOnTouchOutside(true);
      dialog.show();
    }
  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());
  }
Beispiel #28
0
 private void cloneNfcTags(Sprite cloneSprite) {
   List<NfcTagData> cloneNfcTagList = new ArrayList<>();
   for (NfcTagData element : this.nfcTagList) {
     cloneNfcTagList.add(element.clone());
   }
   cloneSprite.nfcTagList = cloneNfcTagList;
 }
Beispiel #29
0
 private void cloneSounds(Sprite cloneSprite) {
   List<SoundInfo> cloneSoundList = new ArrayList<>();
   for (SoundInfo element : this.soundList) {
     cloneSoundList.add(element.copySoundInfoForSprite(cloneSprite));
   }
   cloneSprite.soundList = cloneSoundList;
 }
  private void createProject() {
    project = new Project(null, UiTestUtils.DEFAULT_TEST_PROJECT_NAME);
    Sprite sprite = new Sprite("cat");
    Script script = new StartScript();

    motorBrick =
        new LegoNxtMotorMoveBrick(LegoNxtMotorMoveBrick.Motor.MOTOR_A, SET_SPEED_INITIALLY);

    script.addBrick(motorBrick);

    sprite.addScript(script);
    project.addSprite(sprite);

    ProjectManager.getInstance().setProject(project);
    ProjectManager.getInstance().setCurrentSprite(sprite);
    ProjectManager.getInstance().setCurrentScript(script);
  }