Skip to content

Commit

Permalink
Merge pull request #2932 from Catrobat/hotfix-0.9.38
Browse files Browse the repository at this point in the history
Hotfix 0.9.38
  • Loading branch information
wslany authored Aug 14, 2018
2 parents 26d1234 + 055d64a commit 8e838ba
Show file tree
Hide file tree
Showing 33 changed files with 416 additions and 176 deletions.
4 changes: 2 additions & 2 deletions catroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ android {
targetSdkVersion 22
applicationId appId
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 44
versionCode 45
println "VersionCode is " + versionCode
versionName "0.9.36"
versionName "0.9.38"
println "VersionName is " + versionName
buildConfigField "String", "GIT_DESCRIBE", "\"${versionName}\""
buildConfigField "String", "GIT_CURRENT_BRANCH", "\"${getCurrentGitBranch()}\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.SoundInfo;
import org.catrobat.catroid.content.Scene;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
Expand Down Expand Up @@ -124,16 +125,10 @@ private List<String> getSoundNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
new NewSoundDialogFragment(this,
new NewSoundFromBrickSpinnerDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
ProjectManager.getInstance().getCurrentSprite()) {

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
spinner.setSelection(spinnerSelectionBuffer);
}
}.show(((Activity) v.getContext()).getFragmentManager(), NewSoundDialogFragment.TAG);
ProjectManager.getInstance().getCurrentSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewSoundDialogFragment.TAG);
return false;
}

Expand All @@ -149,7 +144,7 @@ public void addItem(SoundInfo item) {
public View getPrototypeView(Context context) {
View view = super.getPrototypeView(context);
onPrototypeViewCreated(view);
spinner = view.findViewById(R.id.brick_play_sound_spinner);
spinner = (Spinner) view.findViewById(R.id.brick_play_sound_spinner);
spinnerAdapter = new SpinnerAdapterWithNewOption(context, getSoundNames());
spinner.setAdapter(spinnerAdapter);
spinner.setSelection(spinnerAdapter.getPosition(sound != null ? sound.getName() : null));
Expand All @@ -164,4 +159,23 @@ public List<ScriptSequenceAction> addActionToSequence(Sprite sprite, ScriptSeque
sequence.addAction(sprite.getActionFactory().createPlaySoundAction(sprite, sound));
return null;
}

public static class NewSoundFromBrickSpinnerDialogFragment extends NewSoundDialogFragment {

private PlaySoundBrick playSoundBrick;

public NewSoundFromBrickSpinnerDialogFragment() {
}

public NewSoundFromBrickSpinnerDialogFragment(PlaySoundBrick playSoundBrick, Scene dstScene, Sprite dstSprite) {
super(playSoundBrick, dstScene, dstSprite);
this.playSoundBrick = playSoundBrick;
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
playSoundBrick.spinner.setSelection(playSoundBrick.spinnerSelectionBuffer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.content.Scene;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
Expand Down Expand Up @@ -102,14 +103,8 @@ public void onNothingSelected(AdapterView<?> parent) {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
new NewSceneDialogFragment(this, ProjectManager.getInstance().getCurrentProject()) {

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
spinner.setSelection(spinnerSelectionBuffer);
}
}.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject())
.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
return false;
}

Expand Down Expand Up @@ -138,4 +133,24 @@ public List<ScriptSequenceAction> addActionToSequence(Sprite sprite, ScriptSeque
sequence.addAction(sprite.getActionFactory().createSceneStartAction(sceneToStart));
return null;
}

public static class NewSceneFromBrickDialogFragment extends NewSceneDialogFragment {

private SceneStartBrick sceneStartBrick;

public NewSceneFromBrickDialogFragment(SceneStartBrick sceneStartBrick, Project dstProject) {
super(sceneStartBrick, dstProject);
this.sceneStartBrick = sceneStartBrick;
}

public NewSceneFromBrickDialogFragment() {
super();
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
sceneStartBrick.spinner.setSelection(sceneStartBrick.spinnerSelectionBuffer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.content.Scene;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
Expand Down Expand Up @@ -105,14 +106,8 @@ public void onNothingSelected(AdapterView<?> parent) {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
new NewSceneDialogFragment(this, ProjectManager.getInstance().getCurrentProject()) {

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
spinner.setSelection(spinnerSelectionBuffer);
}
}.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject())
.show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG);
return false;
}

Expand Down Expand Up @@ -143,4 +138,24 @@ public List<ScriptSequenceAction> addActionToSequence(Sprite sprite, ScriptSeque
sequence.addAction(sprite.getActionFactory().createSceneTransitionAction(sceneForTransition));
return null;
}

public static class NewSceneFromBrickDialogFragment extends NewSceneDialogFragment {

private SceneTransitionBrick sceneTransitionBrick;

public NewSceneFromBrickDialogFragment() {
super();
}

public NewSceneFromBrickDialogFragment(SceneTransitionBrick sceneTransitionBrick, Project dstProject) {
super(sceneTransitionBrick, dstProject);
this.sceneTransitionBrick = sceneTransitionBrick;
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
sceneTransitionBrick.spinner.setSelection(sceneTransitionBrick.spinnerSelectionBuffer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.LookData;
import org.catrobat.catroid.content.EventWrapper;
import org.catrobat.catroid.content.Scene;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.actions.ScriptSequenceAction;
import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption;
Expand Down Expand Up @@ -133,16 +134,10 @@ private List<String> getLookNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
spinnerSelectionBuffer = spinner.getSelectedItemPosition();
new NewLookDialogFragment(this,
new NewLookFromBrickDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
getSprite()) {

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
spinner.setSelection(spinnerSelectionBuffer);
}
}.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
getSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
return false;
}

Expand Down Expand Up @@ -180,4 +175,23 @@ public List<ScriptSequenceAction> addActionToSequence(Sprite sprite, ScriptSeque
protected Sprite getSprite() {
return ProjectManager.getInstance().getCurrentSprite();
}

public static class NewLookFromBrickDialogFragment extends NewLookDialogFragment {

private SetLookBrick setLookBrick;

public NewLookFromBrickDialogFragment() {
}

public NewLookFromBrickDialogFragment(SetLookBrick setLookBrick, Scene dstScene, Sprite dstSprite) {
super(setLookBrick, dstScene, dstSprite);
this.setLookBrick = setLookBrick;
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
setLookBrick.spinner.setSelection(setLookBrick.spinnerSelectionBuffer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.catrobat.catroid.ProjectManager;
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.LookData;
import org.catrobat.catroid.content.Scene;
import org.catrobat.catroid.content.Script;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.WhenBackgroundChangesScript;
Expand Down Expand Up @@ -139,17 +140,10 @@ private List<String> getLookNames() {
@Override
public boolean onNewOptionInDropDownClicked(View v) {
previouslySelectedLook = getLook();
new NewLookDialogFragment(this,
new NewLookFromBrickDialogFragment(this,
ProjectManager.getInstance().getCurrentlyEditedScene(),
ProjectManager.getInstance().getCurrentSprite()) {

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
setLook(previouslySelectedLook);
spinner.setSelection(spinnerAdapter.getPosition(getLook() != null ? getLook().getName() : null));
}
}.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
ProjectManager.getInstance().getCurrentSprite())
.show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG);
return false;
}

Expand Down Expand Up @@ -177,4 +171,24 @@ public List<ScriptSequenceAction> addActionToSequence(Sprite sprite, ScriptSeque
sequence.addAction(sprite.getActionFactory().createSetLookAction(sprite, getLook()));
return null;
}

public static class NewLookFromBrickDialogFragment extends NewLookDialogFragment {

private WhenBackgroundChangesBrick whenBackgroundChangesBrick;

public NewLookFromBrickDialogFragment() {
}

public NewLookFromBrickDialogFragment(WhenBackgroundChangesBrick whenBackgroundChangesBrick, Scene dstScene, Sprite dstSprite) {
super(whenBackgroundChangesBrick, dstScene, dstSprite);
this.whenBackgroundChangesBrick = whenBackgroundChangesBrick;
}

@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
whenBackgroundChangesBrick.setLook(whenBackgroundChangesBrick.previouslySelectedLook);
whenBackgroundChangesBrick.spinner.setSelection(whenBackgroundChangesBrick.spinnerAdapter.getPosition(whenBackgroundChangesBrick.getLook() != null ? whenBackgroundChangesBrick.getLook().getName() : null));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
package org.catrobat.catroid.io;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -51,7 +43,6 @@
public final class StorageOperations {

private static final String FILE_NAME_APPENDIX = "_#";
private static final String TAG = StorageOperations.class.getSimpleName();

private StorageOperations() {
throw new AssertionError();
Expand Down Expand Up @@ -83,83 +74,6 @@ public static void createSceneDirectory(File sceneDir) throws IOException {
noMediaFile.createNewFile();
}

public static String getPathFromUri(ContentResolver contentResolver, Uri uri) {

if (uri.getScheme().equalsIgnoreCase("file")) {
return uri.getPath();
}

String[] projection = {MediaStore.MediaColumns.DATA};
String[] arguments;
String selection = null;
String[] selectionArgs = null;

if (uri.getScheme().equalsIgnoreCase("content") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

String identifier = DocumentsContract.getDocumentId(uri);

// Downloads
if (uri.getAuthority().equalsIgnoreCase("com.android.providers.downloads.documents")) {
uri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(identifier));
return resolveContent(contentResolver, uri, projection, selection, selectionArgs);
}

arguments = identifier.split(":");

// External Storage
if (uri.getAuthority().equalsIgnoreCase("com.android.externalstorage.documents")) {
return Environment.getExternalStorageDirectory() + "/" + arguments[1];
}

selection = "_id=?";

// Media Documents
if (uri.getAuthority().equalsIgnoreCase("com.android.providers.media.documents")) {
if (arguments[0].equalsIgnoreCase("audio")) {
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
if (arguments[0].equalsIgnoreCase("image")) {
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
}
if (arguments[0].equalsIgnoreCase("video")) {
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
}

selectionArgs = new String[] {arguments[1]};
return resolveContent(contentResolver, uri, projection, selection, selectionArgs);
}

// Google Photos
if (uri.getAuthority().equalsIgnoreCase("com.google.android.apps.photos.content")) {
selectionArgs = new String[] {arguments[1]};
return resolveContent(contentResolver, uri, projection, selection, selectionArgs);
}
}

return "";
}

private static String resolveContent(ContentResolver contentResolver,
Uri uri,
String[] projection,
String selection,
String[] selectionArgs) {

String path = "";
Cursor cursor = contentResolver.query(uri, projection, selection, selectionArgs, null);
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
try {
path = cursor.getString(index);
} catch (CursorIndexOutOfBoundsException e) {
Log.e(TAG, Log.getStackTraceString(e));
} finally {
cursor.close();
}
return path;
}

public static String getSanitizedFileName(File file) {
if (file.isDirectory()) {
return file.getName();
Expand Down Expand Up @@ -230,6 +144,12 @@ public static File copyStreamToDir(InputStream inputStream, File dstDir, String
return transferData(inputStream, dstFile);
}

public static File copyUriToDir(ContentResolver contentResolver, Uri uri, File dstDir, String fileName) throws
IOException {
InputStream inputStream = contentResolver.openInputStream(uri);
return copyStreamToDir(inputStream, dstDir, fileName);
}

public static void transferData(File srcFile, File dstFile) throws IOException {
FileChannel ic = new FileInputStream(srcFile).getChannel();
FileChannel oc = new FileOutputStream(dstFile).getChannel();
Expand Down
Loading

0 comments on commit 8e838ba

Please sign in to comment.