示例#1
0
  public void loadLegoNXTSettingsFromProject(Context context) {

    if (context == null) {
      return;
    }

    for (Setting setting : settings) {
      if (setting instanceof LegoNXTSetting) {
        SettingsActivity.enableLegoMindstormsNXTBricks(context);
        SettingsActivity.setLegoMindstormsNXTSensorMapping(
            context, ((LegoNXTSetting) setting).getSensorMapping());
        return;
      }
    }
  }
示例#2
0
  public void saveLegoNXTSettingsToProject(Context context) {
    if (context == null) {
      return;
    }

    if ((getRequiredResources() & Brick.BLUETOOTH_LEGO_NXT) == 0) {
      for (Object setting : settings.toArray()) {
        if (setting instanceof LegoNXTSetting) {
          settings.remove(setting);
          return;
        }
      }
      return;
    }

    NXTSensor.Sensor[] sensorMapping = SettingsActivity.getLegoMindstormsNXTSensorMapping(context);
    for (Setting setting : settings) {
      if (setting instanceof LegoNXTSetting) {
        ((LegoNXTSetting) setting).updateMapping(sensorMapping);
        return;
      }
    }

    Setting mapping = new LegoNXTSetting(sensorMapping);
    settings.add(mapping);
  }
示例#3
0
  private List<Brick> setupLooksCategoryList(Context context) {
    List<Brick> looksBrickList = new ArrayList<Brick>();

    looksBrickList.add(new SetLookBrick());
    looksBrickList.add(new NextLookBrick());
    looksBrickList.add(new SetSizeToBrick(BrickValues.SET_SIZE_TO));
    looksBrickList.add(new ChangeSizeByNBrick(BrickValues.CHANGE_SIZE_BY));
    looksBrickList.add(new HideBrick());
    looksBrickList.add(new ShowBrick());
    looksBrickList.add(new SetTransparencyBrick(BrickValues.SET_TRANSPARENCY));
    looksBrickList.add(new ChangeTransparencyByNBrick(BrickValues.CHANGE_GHOST_EFFECT));
    looksBrickList.add(new SetBrightnessBrick(BrickValues.SET_BRIGHTNESS_TO));
    looksBrickList.add(new ChangeBrightnessByNBrick(BrickValues.CHANGE_BRITHNESS_BY));
    looksBrickList.add(new ClearGraphicEffectBrick());
    if (BuildConfig.FEATURE_LED_BRICK_ENABLED) {
      looksBrickList.add(new LedOffBrick());
      looksBrickList.add(new LedOnBrick());
    }

    if (SettingsActivity.isPhiroSharedPreferenceEnabled(context)) {
      looksBrickList.add(
          new PhiroRGBLightBrick(
              PhiroRGBLightBrick.Eye.BOTH,
              BrickValues.PHIRO_VALUE_RED,
              BrickValues.PHIRO_VALUE_GREEN,
              BrickValues.PHIRO_VALUE_BLUE));
    }

    return looksBrickList;
  }
示例#4
0
  private List<Brick> setupSoundCategoryList(Context context) {
    List<Brick> soundBrickList = new ArrayList<Brick>();
    soundBrickList.add(new PlaySoundBrick());
    soundBrickList.add(new StopAllSoundsBrick());
    soundBrickList.add(new SetVolumeToBrick(BrickValues.SET_VOLUME_TO));

    // workaround to set a negative default value for a Brick
    float positiveDefaultValueChangeVolumeBy = Math.abs(BrickValues.CHANGE_VOLUME_BY);
    FormulaElement defaultValueChangeVolumeBy =
        new FormulaElement(
            ElementType.OPERATOR,
            Operators.MINUS.name(),
            null,
            null,
            new FormulaElement(
                ElementType.NUMBER, String.valueOf(positiveDefaultValueChangeVolumeBy), null));
    soundBrickList.add(new ChangeVolumeByNBrick(new Formula(defaultValueChangeVolumeBy)));

    soundBrickList.add(new SpeakBrick(BrickValues.SPEAK));

    if (SettingsActivity.isPhiroSharedPreferenceEnabled(context)) {
      soundBrickList.add(
          new PhiroPlayToneBrick(PhiroPlayToneBrick.Tone.DO, BrickValues.PHIRO_DURATION));
    }

    return soundBrickList;
  }
示例#5
0
  private List<Brick> setupMotionCategoryList(Sprite sprite, Context context) {
    List<Brick> motionBrickList = new ArrayList<Brick>();
    motionBrickList.add(new PlaceAtBrick(BrickValues.X_POSITION, BrickValues.Y_POSITION));
    motionBrickList.add(new SetXBrick(BrickValues.X_POSITION));
    motionBrickList.add(new SetYBrick(BrickValues.Y_POSITION));
    motionBrickList.add(new ChangeXByNBrick(BrickValues.CHANGE_X_BY));
    motionBrickList.add(new ChangeYByNBrick(BrickValues.CHANGE_Y_BY));

    if (!isBackground(sprite)) {
      motionBrickList.add(new IfOnEdgeBounceBrick());
    }

    motionBrickList.add(new MoveNStepsBrick(BrickValues.MOVE_STEPS));
    motionBrickList.add(new TurnLeftBrick(BrickValues.TURN_DEGREES));
    motionBrickList.add(new TurnRightBrick(BrickValues.TURN_DEGREES));
    motionBrickList.add(new PointInDirectionBrick(Direction.RIGHT));
    motionBrickList.add(new PointToBrick(null));
    motionBrickList.add(
        new GlideToBrick(
            BrickValues.X_POSITION, BrickValues.Y_POSITION, BrickValues.GLIDE_SECONDS));

    if (!isBackground(sprite)) {
      motionBrickList.add(new GoNStepsBackBrick(BrickValues.GO_BACK));
      motionBrickList.add(new ComeToFrontBrick());
    }
    if (BuildConfig.FEATURE_VIBRATION_BRICK_ENABLED) {
      motionBrickList.add(new VibrationBrick(BrickValues.VIBRATE_MILLISECONDS));
    }

    if (SettingsActivity.isPhiroSharedPreferenceEnabled(context)) {
      motionBrickList.add(
          new PhiroMotorMoveForwardBrick(
              PhiroMotorMoveForwardBrick.Motor.MOTOR_LEFT, BrickValues.PHIRO_SPEED));
      motionBrickList.add(
          new PhiroMotorMoveBackwardBrick(
              PhiroMotorMoveBackwardBrick.Motor.MOTOR_LEFT, BrickValues.PHIRO_SPEED));
      motionBrickList.add(new PhiroMotorStopBrick(PhiroMotorStopBrick.Motor.MOTOR_BOTH));
    }

    return motionBrickList;
  }
示例#6
0
  private List<Brick> setupControlCategoryList(Context context) {
    List<Brick> controlBrickList = new ArrayList<Brick>();
    controlBrickList.add(new WhenStartedBrick(null));
    controlBrickList.add(new WhenBrick(null));
    controlBrickList.add(new WaitBrick(BrickValues.WAIT));

    final String broadcastMessage = MessageContainer.getFirst(context);
    controlBrickList.add(new BroadcastReceiverBrick(broadcastMessage));
    controlBrickList.add(new BroadcastBrick(broadcastMessage));
    controlBrickList.add(new BroadcastWaitBrick(broadcastMessage));

    controlBrickList.add(new NoteBrick(context.getString(R.string.brick_note_default_value)));
    controlBrickList.add(new ForeverBrick());
    controlBrickList.add(new IfLogicBeginBrick(0));
    controlBrickList.add(new RepeatBrick(BrickValues.REPEAT));

    if (SettingsActivity.isPhiroSharedPreferenceEnabled(context)) {
      controlBrickList.add(new PhiroIfLogicBeginBrick());
    }

    return controlBrickList;
  }
  public void testSerializeSettings()
      throws CompatibilityProjectException, OutdatedVersionProjectException,
          LoadingProjectException {

    NXTSensor.Sensor[] sensorMapping =
        new NXTSensor.Sensor[] {
          NXTSensor.Sensor.TOUCH, NXTSensor.Sensor.SOUND,
          NXTSensor.Sensor.LIGHT_INACTIVE, NXTSensor.Sensor.ULTRASONIC
        };

    Reflection.setPrivateField(ProjectManager.getInstance(), "asynchronousTask", false);

    Project project = generateMultiplePermissionsProject();
    ProjectManager.getInstance().setProject(project);

    String projectName = project.getName();
    SettingsActivity.setLegoMindstormsNXTSensorMapping(
        getInstrumentation().getTargetContext(), sensorMapping);

    ProjectManager.getInstance().saveProject(getInstrumentation().getTargetContext());
    Setting setting = project.getSettings().get(0);

    assertTrue("Wrong setting type, LegoNXT setting expected", setting instanceof LegoNXTSetting);

    LegoNXTSetting nxtSetting = (LegoNXTSetting) setting;
    NXTSensor.Sensor[] actualSensorMapping = nxtSetting.getSensorMapping();

    assertEquals("Wrong numer of sensors", 4, actualSensorMapping.length);

    assertEquals("Wrong sensor mapping for touch sensor", sensorMapping[0], actualSensorMapping[0]);
    assertEquals("Wrong sensor mapping for sound sensor", sensorMapping[1], actualSensorMapping[1]);
    assertEquals("Wrong sensor mapping for light sensor", sensorMapping[2], actualSensorMapping[2]);
    assertEquals(
        "Wrong sensor mapping for ultrasonic sensor", sensorMapping[3], actualSensorMapping[3]);

    NXTSensor.Sensor[] changedSensorMapping = sensorMapping.clone();
    changedSensorMapping[0] = NXTSensor.Sensor.LIGHT_ACTIVE;

    SettingsActivity.setLegoMindstormsNXTSensorMapping(
        getInstrumentation().getTargetContext(), changedSensorMapping);

    ProjectManager.getInstance().setProject(null);
    ProjectManager.getInstance().loadProject(projectName, getInstrumentation().getTargetContext());

    actualSensorMapping =
        SettingsActivity.getLegoMindstormsNXTSensorMapping(getInstrumentation().getTargetContext());

    assertEquals("Wrong numer of sensors", 4, actualSensorMapping.length);

    assertEquals(
        "Wrong sensor mapping for touch sensor, settings not correctly loaded from project",
        sensorMapping[0],
        actualSensorMapping[0]);
    assertEquals("Wrong sensor mapping for sound sensor", sensorMapping[1], actualSensorMapping[1]);
    assertEquals("Wrong sensor mapping for light sensor", sensorMapping[2], actualSensorMapping[2]);
    assertEquals(
        "Wrong sensor mapping for ultrasonic sensor", sensorMapping[3], actualSensorMapping[3]);

    project = ProjectManager.getInstance().getCurrentProject();

    setting = project.getSettings().get(0);
    nxtSetting = (LegoNXTSetting) setting;

    assertTrue("Wrong setting type, LegoNXT setting expected", setting instanceof LegoNXTSetting);

    actualSensorMapping = nxtSetting.getSensorMapping();

    assertEquals("Wrong numer of sensors", 4, actualSensorMapping.length);

    assertEquals("Wrong sensor mapping for touch sensor", sensorMapping[0], actualSensorMapping[0]);
    assertEquals("Wrong sensor mapping for sound sensor", sensorMapping[1], actualSensorMapping[1]);
    assertEquals("Wrong sensor mapping for light sensor", sensorMapping[2], actualSensorMapping[2]);
    assertEquals(
        "Wrong sensor mapping for ultrasonic sensor", sensorMapping[3], actualSensorMapping[3]);
  }