public boolean containsLookData(LookData lookData) { for (LookData lookOfSprite : lookList) { if (lookOfSprite.equals(lookData)) { return true; } } return false; }
public boolean existLookDataByFileName(LookData look) { for (LookData lookdata : lookList) { if (lookdata.getLookFileName().equals(look.getLookFileName())) { return true; } } return false; }
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()); }
private LookData createWhiteBackgroundLookData() { LookData whiteBackground = new LookData(); Pixmap whiteBackgroundPixmap = new Pixmap((int) virtualWidth, (int) virtualHeight, Format.RGBA8888); whiteBackgroundPixmap.setColor(Color.WHITE); whiteBackgroundPixmap.fill(); whiteBackground.setPixmap(whiteBackgroundPixmap); whiteBackground.setTextureRegion(); return whiteBackground; }
private Object interpretObjectSensor(Sensors sensor, Sprite sprite) { Object returnValue = 0d; LookData lookData = sprite.look.getLookData(); List<LookData> lookDataList = sprite.getLookDataList(); if (lookData == null && lookDataList.size() > 0) { lookData = lookDataList.get(0); } switch (sensor) { case OBJECT_BRIGHTNESS: returnValue = (double) sprite.look.getBrightnessInUserInterfaceDimensionUnit(); break; case OBJECT_COLOR: returnValue = (double) sprite.look.getColorInUserInterfaceDimensionUnit(); break; case OBJECT_TRANSPARENCY: returnValue = (double) sprite.look.getTransparencyInUserInterfaceDimensionUnit(); break; case OBJECT_LAYER: returnValue = (double) sprite.look.getZIndex(); break; case OBJECT_ROTATION: returnValue = (double) sprite.look.getDirectionInUserInterfaceDimensionUnit(); break; case OBJECT_SIZE: returnValue = (double) sprite.look.getSizeInUserInterfaceDimensionUnit(); break; case OBJECT_X: returnValue = (double) sprite.look.getXInUserInterfaceDimensionUnit(); break; case OBJECT_Y: returnValue = (double) sprite.look.getYInUserInterfaceDimensionUnit(); break; case OBJECT_ANGULAR_VELOCITY: returnValue = (double) sprite.look.getAngularVelocityInUserInterfaceDimensionUnit(); break; case OBJECT_X_VELOCITY: returnValue = (double) sprite.look.getXVelocityInUserInterfaceDimensionUnit(); break; case OBJECT_Y_VELOCITY: returnValue = (double) sprite.look.getYVelocityInUserInterfaceDimensionUnit(); break; case OBJECT_LOOK_NUMBER: case OBJECT_BACKGROUND_NUMBER: returnValue = 1.0d + ((lookData != null) ? lookDataList.indexOf(lookData) : 0); break; case OBJECT_LOOK_NAME: case OBJECT_BACKGROUND_NAME: returnValue = (lookData != null) ? lookData.getLookName() : ""; break; case OBJECT_DISTANCE_TO: returnValue = (double) sprite.look.getDistanceToTouchPositionInUserInterfaceDimensions(); } return returnValue; }
public void resetSprite() { if ((getRequiredResources() & Brick.PHYSICS) > 0) { PhysicsWorld physicsWorld = ProjectManager.getInstance().getCurrentProject().getPhysicsWorld(); look = new PhysicsLook(this, physicsWorld); } else { look = new Look(this); } for (LookData lookData : lookList) { lookData.resetLookData(); } }
private Object readResolve() { // filling FileChecksumContainer: if (ProjectManager.getInstance().getCurrentProject() != null) { FileChecksumContainer container = ProjectManager.getInstance().getFileChecksumContainer(); for (SoundInfo soundInfo : soundList) { container.addChecksum(soundInfo.getChecksum(), soundInfo.getAbsolutePath()); } for (LookData lookData : lookList) { container.addChecksum(lookData.getChecksum(), lookData.getAbsolutePath()); } } return this; }
public int getRequiredResources() { int resources = Brick.NO_RESOURCES; for (Script script : scriptList) { resources |= script.getRequiredResources(); } for (LookData lookData : getLookDataList()) { resources |= lookData.getRequiredResources(); } return resources; }
private void disposeTextures() { List<Sprite> sprites = project.getSpriteList(); int spriteSize = sprites.size(); for (int i = 0; i > spriteSize; i++) { List<LookData> data = sprites.get(i).getLookDataList(); int dataSize = data.size(); for (int j = 0; j < dataSize; j++) { LookData lookData = data.get(j); lookData.getPixmap().dispose(); lookData.getTextureRegion().getTexture().dispose(); } } }
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)); } }
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 copyLook(int position) { LookData lookData = lookDataList.get(position); try { String projectName = ProjectManager.getInstance().getCurrentProject().getName(); StorageHandler.getInstance().copyImage(projectName, lookData.getAbsolutePath(), null); String imageName = lookData.getLookName() + "_" + getString(R.string.copy_look_addition); String imageFileName = lookData.getLookFileName(); updateLookAdapter(imageName, imageFileName); } catch (IOException e) { Utils.showErrorDialog(getActivity(), getString(R.string.error_load_image)); e.printStackTrace(); } getActivity().sendBroadcast(new Intent(ScriptActivity.ACTION_BRICK_LIST_CHANGED)); }
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); selectedLookData = adapter.getItem(selectedLookPosition); menu.setHeaderTitle(selectedLookData.getLookName()); getSherlockActivity().getMenuInflater().inflate(R.menu.context_menu_default, menu); menu.findItem(R.id.context_edit_in_pocket_paint).setVisible(true); }
private void loadPocketPaintImageIntoCatroid(Intent intent) { Bundle bundle = intent.getExtras(); String pathOfPocketPaintImage = bundle.getString(Constants.EXTRA_PICTURE_PATH_POCKET_PAINT); int[] imageDimensions = ImageEditing.getImageDimensions(pathOfPocketPaintImage); if (imageDimensions[0] < 0 || imageDimensions[1] < 0) { Utils.showErrorDialog(getActivity(), this.getString(R.string.error_load_image)); return; } String actualChecksum = Utils.md5Checksum(new File(pathOfPocketPaintImage)); // If look changed --> saving new image with new checksum and changing lookData if (!selectedLookData.getChecksum().equalsIgnoreCase(actualChecksum)) { String oldFileName = selectedLookData.getLookFileName(); String newFileName = oldFileName.substring(oldFileName.indexOf('_') + 1); // HACK for https://github.com/Catrobat/Catroid/issues/81 if (!newFileName.endsWith(".png")) { newFileName = newFileName + ".png"; } String projectName = ProjectManager.getInstance().getCurrentProject().getName(); try { File newLookFile = StorageHandler.getInstance() .copyImage(projectName, pathOfPocketPaintImage, newFileName); File temporaryPictureFileInPocketPaint = new File(pathOfPocketPaintImage); temporaryPictureFileInPocketPaint.delete(); // delete temp file in paintroid StorageHandler.getInstance() .deleteFile( selectedLookData.getAbsolutePath()); // reduce usage in container or delete it selectedLookData.setLookFilename(newLookFile.getName()); selectedLookData.resetThumbnailBitmap(); } catch (IOException e) { e.printStackTrace(); } } }
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); } }); }
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; }
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); }
@Override protected void showRenameDialog() { RenameLookDialog renameLookDialog = RenameLookDialog.newInstance(selectedLookData.getLookName()); renameLookDialog.show(getFragmentManager(), RenameLookDialog.DIALOG_FRAGMENT_TAG); }