예제 #1
0
  public void testNXTMotorActionBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_brick_motor_move)));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.nxt_motor_speed_to)));

    UiTestUtils.testBrickWithFormulaEditor(
        solo,
        ProjectManager.getInstance().getCurrentSprite(),
        R.id.motor_action_speed_edit_text,
        SET_SPEED,
        Brick.BrickField.LEGO_NXT_SPEED,
        motorBrick);

    String[] motors = getActivity().getResources().getStringArray(R.array.nxt_motor_chooser);
    assertTrue("Spinner items list too short!", motors.length == 4);

    int legoSpinnerIndex = 0;

    Spinner currentSpinner = solo.getCurrentViews(Spinner.class).get(legoSpinnerIndex);
    solo.pressSpinnerItem(legoSpinnerIndex, 0);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[0], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[1], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[2], currentSpinner.getSelectedItem());
    solo.pressSpinnerItem(legoSpinnerIndex, 1);
    solo.waitForActivity(ScriptActivity.class.getSimpleName());
    assertEquals("Wrong item in spinner!", motors[3], currentSpinner.getSelectedItem());
  }
예제 #2
0
  public void testHideBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull("TextView does not exist.", solo.getText(solo.getString(R.string.brick_hide)));
  }
예제 #3
0
  public void testChangeYByNBrick() {
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) dragDropListView.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals("Incorrect number of bricks.", 2, dragDropListView.getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull(
        "TextView does not exist.", solo.getText(solo.getString(R.string.brick_change_y_by)));

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, Y_TO_CHANGE, "yMovement", changeYByNBrick);
  }
예제 #4
0
  @Smoke
  public void testIfBrick() {
    ListView view = UiTestUtils.getScriptListView(solo);
    ListView dragDropListView = UiTestUtils.getScriptListView(solo);
    BrickAdapter adapter = (BrickAdapter) view.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();

    UiTestUtils.testBrickWithFormulaEditor(solo, 0, 1, 5, "ifCondition", ifBrick);

    assertEquals(
        "Incorrect number of bricks.",
        6,
        dragDropListView.getChildCount()); // don't forget the footer
    assertEquals("Incorrect number of bricks.", 0, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 4, projectBrickList.size());

    assertTrue("Wrong Brick instance.", projectBrickList.get(0) instanceof IfLogicBeginBrick);
    assertNotNull(
        "TextView does not exist", solo.getText(getActivity().getString(R.string.brick_if_begin)));
  }
예제 #5
0
  public void testGoNStepsBackBrick() {
    ScriptActivity activity = (ScriptActivity) solo.getCurrentActivity();
    ScriptFragment fragment =
        (ScriptFragment) activity.getFragment(ScriptActivity.FRAGMENT_SCRIPTS);
    BrickAdapter adapter = fragment.getAdapter();

    int childrenCount = adapter.getChildCountFromLastGroup();
    int groupCount = adapter.getScriptCount();

    assertEquals(
        "Incorrect number of bricks.",
        2,
        solo.getCurrentViews(ListView.class).get(0).getChildCount());
    assertEquals("Incorrect number of bricks.", 1, childrenCount);

    ArrayList<Brick> projectBrickList = project.getSpriteList().get(0).getScript(0).getBrickList();
    assertEquals("Incorrect number of bricks.", 1, projectBrickList.size());

    assertEquals(
        "Wrong Brick instance.", projectBrickList.get(0), adapter.getChild(groupCount - 1, 0));
    assertNotNull("TextView does not exist.", solo.getText(solo.getString(R.string.brick_move)));

    UiTestUtils.testBrickWithFormulaEditor(
        solo,
        ProjectManager.getInstance().getCurrentSprite(),
        R.id.brick_move_n_steps_edit_text,
        STEPS_TO_MOVE,
        Brick.BrickField.STEPS,
        moveNStepsBrick);

    UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, STEPS_TO_MOVE);

    try {
      assertEquals(
          "Wrong text in field.",
          STEPS_TO_MOVE,
          (moveNStepsBrick.getFormulaWithBrickField(Brick.BrickField.STEPS)).interpretDouble(null));
    } catch (InterpretationException interpretationException) {
      fail("Wrong text in field.");
    }

    assertEquals(
        "Value in Brick is not updated.",
        STEPS_TO_MOVE,
        Double.valueOf(
            ((TextView) solo.getView(R.id.brick_move_n_steps_edit_text))
                .getText()
                .toString()
                .replace(',', '.')));

    UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, 1);
    TextView stepTextView = (TextView) solo.getView(R.id.brick_move_n_steps_step_text_view);
    assertTrue(
        "Specifier hasn't changed from plural to singular",
        stepTextView
            .getText()
            .equals(
                stepTextView
                    .getResources()
                    .getQuantityString(R.plurals.brick_move_n_step_plural, 1)));

    UiTestUtils.insertValueViaFormulaEditor(solo, R.id.brick_move_n_steps_edit_text, 1.4);
    stepTextView = (TextView) solo.getView(R.id.brick_move_n_steps_step_text_view);
    assertTrue(
        "Specifier hasn't changed from singular to plural",
        stepTextView
            .getText()
            .equals(
                stepTextView
                    .getResources()
                    .getQuantityString(
                        R.plurals.brick_move_n_step_plural,
                        Utils.convertDoubleToPluralInteger(1.4))));
  }
예제 #6
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    FragmentManager fragmentManager = getSupportFragmentManager();

    for (String tag : FormulaEditorListFragment.TAGS) {
      FormulaEditorListFragment fragment =
          (FormulaEditorListFragment) fragmentManager.findFragmentByTag(tag);
      if (fragment != null && fragment.isVisible()) {
        return fragment.onKey(null, keyCode, event);
      }
    }

    FormulaEditorVariableListFragment formulaEditorVariableListFragment =
        (FormulaEditorVariableListFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG);

    if (formulaEditorVariableListFragment != null
        && formulaEditorVariableListFragment.isVisible()) {
      return formulaEditorVariableListFragment.onKey(null, keyCode, event);
    }

    FormulaEditorFragment formulaEditor =
        (FormulaEditorFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);

    if (formulaEditor != null && formulaEditor.isVisible()) {
      scriptFragment.getAdapter().updateProjectBrickList();
      return formulaEditor.onKey(null, keyCode, event);
    }

    if (soundFragment != null
        && soundFragment.isVisible()
        && soundFragment.onKey(null, keyCode, event)) {
      return true;
    }

    if (lookFragment != null
        && lookFragment.isVisible()
        && lookFragment.onKey(null, keyCode, event)) {
      return true;
    }

    int backStackEntryCount = fragmentManager.getBackStackEntryCount();
    for (int i = backStackEntryCount; i > 0; --i) {
      String backStackEntryName = fragmentManager.getBackStackEntryAt(i - 1).getName();
      if (backStackEntryName != null
          && (backStackEntryName.equals(LookFragment.TAG)
              || backStackEntryName.equals(SoundFragment.TAG))) {
        fragmentManager.popBackStack();
      } else {
        break;
      }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK && currentFragmentPosition == FRAGMENT_SCRIPTS) {
      DragAndDropListView listView = scriptFragment.getListView();
      if (listView.isCurrentlyDragging()) {
        listView.resetDraggingScreen();

        BrickAdapter adapter = scriptFragment.getAdapter();
        adapter.removeDraggedBrick();
        return true;
      }
    }

    return super.onKeyDown(keyCode, event);
  }