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); }
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]); }