diff --git a/catroid/build.gradle b/catroid/build.gradle index 18f08907a6d..259b43ba0fc 100644 --- a/catroid/build.gradle +++ b/catroid/build.gradle @@ -279,9 +279,9 @@ android { targetSdkVersion 22 applicationId appId testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' - versionCode 45 + versionCode 46 println "VersionCode is " + versionCode - versionName "0.9.38" + versionName "0.9.40" println "VersionName is " + versionName buildConfigField "String", "GIT_DESCRIBE", "\"${versionName}\"" buildConfigField "String", "GIT_CURRENT_BRANCH", "\"${getCurrentGitBranch()}\"" diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/app/API19SpinnerAndFormulaFieldCrashesRegressionTest.java b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/app/API19SpinnerAndFormulaFieldCrashesRegressionTest.java new file mode 100644 index 00000000000..787f0dd158a --- /dev/null +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/content/brick/app/API19SpinnerAndFormulaFieldCrashesRegressionTest.java @@ -0,0 +1,162 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.catrobat.catroid.uiespresso.content.brick.app; + +import android.support.test.runner.AndroidJUnit4; + +import org.catrobat.catroid.R; +import org.catrobat.catroid.content.bricks.ChangeSizeByNBrick; +import org.catrobat.catroid.content.bricks.PlaySoundBrick; +import org.catrobat.catroid.content.bricks.PointToBrick; +import org.catrobat.catroid.content.bricks.SceneStartBrick; +import org.catrobat.catroid.content.bricks.SceneTransitionBrick; +import org.catrobat.catroid.content.bricks.SetLookBrick; +import org.catrobat.catroid.content.bricks.WhenBackgroundChangesBrick; +import org.catrobat.catroid.ui.SpriteActivity; +import org.catrobat.catroid.uiespresso.content.brick.utils.BrickTestUtils; +import org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper; +import org.catrobat.catroid.uiespresso.testsuites.Cat; +import org.catrobat.catroid.uiespresso.testsuites.Level; +import org.catrobat.catroid.uiespresso.util.rules.BaseActivityInstrumentationRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.runner.RunWith; + +import static android.support.test.espresso.Espresso.onView; +import static android.support.test.espresso.action.ViewActions.click; +import static android.support.test.espresso.assertion.ViewAssertions.matches; +import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; +import static android.support.test.espresso.matcher.ViewMatchers.withText; + +import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition; + +@RunWith(AndroidJUnit4.class) +public class API19SpinnerAndFormulaFieldCrashesRegressionTest { + + @Rule + public BaseActivityInstrumentationRule baseActivityTestRule = new + BaseActivityInstrumentationRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION, SpriteActivity.FRAGMENT_SCRIPTS); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() { + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testFormulaFieldBrickRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("ChangeSizeByNBrick") + .addBrick(new ChangeSizeByNBrick()); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onFormulaTextField(R.id.brick_change_size_by_edit_text) + .perform(click()); + onView(FormulaEditorWrapper.FORMULA_EDITOR_KEYBOARD_MATCHER) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testPlaySoundBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("PlaySoundBrick") + .addBrick(new PlaySoundBrick()); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_play_sound_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_sound_dialog_title)) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testPointToBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("PointToBrick") + .addBrick(new PointToBrick()); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_point_to_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_look_dialog_title)) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testSceneStartBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("SceneStartBrick") + .addBrick(new SceneStartBrick("Scene 1")); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_scene_start_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_scene_dialog)) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testSceneTransitionBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("SceneTransitionBrick") + .addBrick(new SceneTransitionBrick("Scene 1")); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_scene_transition_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_scene_dialog)) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testSetLookBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("SetLookBrick") + .addBrick(new SetLookBrick()); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_set_look_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_look_dialog_title)) + .check(matches(isDisplayed())); + } + + @Category({Cat.AppUi.class, Cat.ApiLevel19Regression.class, Level.Smoke.class}) + @Test + public void testWhenBackgroundChangesBrickSpinnerRegressionTest() { + BrickTestUtils.createProjectAndGetStartScript("WhenBackgroundChangesBrick") + .addBrick(new WhenBackgroundChangesBrick()); + baseActivityTestRule.launchActivity(); + onBrickAtPosition(1) + .onSpinner(R.id.brick_when_background_spinner) + .performSelect(R.string.new_broadcast_message); + onView(withText(R.string.new_look_dialog_title)) + .check(matches(isDisplayed())); + } +} diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/ApiLevel19RegressionTestsSuite.java b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/ApiLevel19RegressionTestsSuite.java new file mode 100644 index 00000000000..b1145e62bdc --- /dev/null +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/ApiLevel19RegressionTestsSuite.java @@ -0,0 +1,34 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.catrobat.catroid.uiespresso.testsuites; + +import org.junit.experimental.categories.Categories; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Categories.class) +@Categories.IncludeCategory({Cat.ApiLevel19Regression.class}) +@Suite.SuiteClasses(AllEspressoTestsSuite.class) +public class ApiLevel19RegressionTestsSuite { +} diff --git a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/Cat.java b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/Cat.java index a0c230f2042..693cc35f914 100644 --- a/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/Cat.java +++ b/catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/testsuites/Cat.java @@ -54,6 +54,10 @@ interface Network { interface SensorBox { } + //Regression tests for Api 19, stuff that just works on higher Apis, but needs special treatment on 19 + interface ApiLevel19Regression { + } + //Educational tests that are in place to demonstrate how to test something interface Educational { } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/PlaySoundBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/PlaySoundBrick.java index b54147d4ffc..665d33c980f 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/PlaySoundBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/PlaySoundBrick.java @@ -36,6 +36,7 @@ import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewSoundDialogFragment; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -125,10 +126,15 @@ private List getSoundNames() { @Override public boolean onNewOptionInDropDownClicked(View v) { spinnerSelectionBuffer = spinner.getSelectedItemPosition(); + Activity activity = UiUtils.getActivityFromView(v); + if (activity == null) { + return false; + } + new NewSoundFromBrickSpinnerDialogFragment(this, ProjectManager.getInstance().getCurrentlyEditedScene(), ProjectManager.getInstance().getCurrentSprite()) - .show(((Activity) v.getContext()).getFragmentManager(), NewSoundDialogFragment.TAG); + .show(activity.getFragmentManager(), NewSoundDialogFragment.TAG); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/PointToBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/PointToBrick.java index eb9e58e0795..ff5e8d046ad 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/PointToBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/PointToBrick.java @@ -33,6 +33,7 @@ import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewSpriteDialogWrapper; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -104,6 +105,11 @@ private List getSpriteNames() { @Override public boolean onNewOptionInDropDownClicked(View v) { spinnerSelectionBuffer = spinner.getSelectedItemPosition(); + Activity activity = UiUtils.getActivityFromView(v); + if (activity == null) { + return false; + } + new NewSpriteDialogWrapper(this, ProjectManager.getInstance().getCurrentlyEditedScene()) { @Override @@ -111,7 +117,7 @@ public void onWorkflowCanceled() { super.onWorkflowCanceled(); spinner.setSelection(spinnerSelectionBuffer); } - }.showDialog(((Activity) v.getContext()).getFragmentManager()); + }.showDialog(activity.getFragmentManager()); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneStartBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneStartBrick.java index 441224b86d5..0d45218a04f 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneStartBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneStartBrick.java @@ -36,6 +36,7 @@ import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewSceneDialogFragment; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -103,8 +104,13 @@ public void onNothingSelected(AdapterView parent) { @Override public boolean onNewOptionInDropDownClicked(View v) { spinnerSelectionBuffer = spinner.getSelectedItemPosition(); + Activity activity = UiUtils.getActivityFromView(v); + if (activity == null) { + return false; + } + new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject()) - .show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG); + .show(activity.getFragmentManager(), NewSceneDialogFragment.TAG); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneTransitionBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneTransitionBrick.java index 7ff85672a1e..d30424a66dc 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneTransitionBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SceneTransitionBrick.java @@ -36,6 +36,7 @@ import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewSceneDialogFragment; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -106,8 +107,13 @@ public void onNothingSelected(AdapterView parent) { @Override public boolean onNewOptionInDropDownClicked(View v) { spinnerSelectionBuffer = spinner.getSelectedItemPosition(); + Activity activity = UiUtils.getActivityFromView(v); + if (activity == null) { + return false; + } + new NewSceneFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentProject()) - .show(((Activity) v.getContext()).getFragmentManager(), NewSceneDialogFragment.TAG); + .show(activity.getFragmentManager(), NewSceneDialogFragment.TAG); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetLookBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetLookBrick.java index 4f571400613..6d471417868 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetLookBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/SetLookBrick.java @@ -38,6 +38,7 @@ import org.catrobat.catroid.content.Sprite; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewLookDialogFragment; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -134,10 +135,15 @@ private List getLookNames() { @Override public boolean onNewOptionInDropDownClicked(View v) { spinnerSelectionBuffer = spinner.getSelectedItemPosition(); + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return false; + } + new NewLookFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentlyEditedScene(), getSprite()) - .show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG); + .show(activity.getFragmentManager(), NewLookDialogFragment.TAG); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/content/bricks/WhenBackgroundChangesBrick.java b/catroid/src/main/java/org/catrobat/catroid/content/bricks/WhenBackgroundChangesBrick.java index ac45f543fd9..7062aa454e2 100644 --- a/catroid/src/main/java/org/catrobat/catroid/content/bricks/WhenBackgroundChangesBrick.java +++ b/catroid/src/main/java/org/catrobat/catroid/content/bricks/WhenBackgroundChangesBrick.java @@ -38,6 +38,7 @@ import org.catrobat.catroid.content.WhenBackgroundChangesScript; import org.catrobat.catroid.content.actions.ScriptSequenceAction; import org.catrobat.catroid.content.bricks.brickspinner.SpinnerAdapterWithNewOption; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.recyclerview.dialog.NewLookDialogFragment; import org.catrobat.catroid.ui.recyclerview.dialog.dialoginterface.NewItemInterface; @@ -140,10 +141,15 @@ private List getLookNames() { @Override public boolean onNewOptionInDropDownClicked(View v) { previouslySelectedLook = getLook(); + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return false; + } + new NewLookFromBrickDialogFragment(this, ProjectManager.getInstance().getCurrentlyEditedScene(), ProjectManager.getInstance().getCurrentSprite()) - .show(((Activity) v.getContext()).getFragmentManager(), NewLookDialogFragment.TAG); + .show(activity.getFragmentManager(), NewLookDialogFragment.TAG); return false; } diff --git a/catroid/src/main/java/org/catrobat/catroid/io/ProjectAndSceneScreenshotLoader.java b/catroid/src/main/java/org/catrobat/catroid/io/ProjectAndSceneScreenshotLoader.java index 085959e6169..576dbcecfb4 100644 --- a/catroid/src/main/java/org/catrobat/catroid/io/ProjectAndSceneScreenshotLoader.java +++ b/catroid/src/main/java/org/catrobat/catroid/io/ProjectAndSceneScreenshotLoader.java @@ -29,6 +29,7 @@ import org.catrobat.catroid.R; import org.catrobat.catroid.stage.StageListener; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.utils.ImageEditing; import org.catrobat.catroid.utils.PathBuilder; @@ -126,8 +127,6 @@ public void run() { return; } - Activity uiActivity = (Activity) projectAndSceneScreenshotData.imageView.getContext(); - File projectAndSceneImageFile = getScreenshotFile(); String pathOfScreenshot = projectAndSceneImageFile.getAbsolutePath(); @@ -155,19 +154,23 @@ public void run() { return; } - uiActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (imageViewReused(projectAndSceneScreenshotData)) { - return; - } - if (projectAndSceneImage != null) { - projectAndSceneScreenshotData.imageView.setImageBitmap(projectAndSceneImage); - } else { - projectAndSceneScreenshotData.imageView.setImageBitmap(null); + Activity uiActivity = UiUtils.getActivityFromView(projectAndSceneScreenshotData.imageView); + + if (uiActivity != null) { + uiActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (imageViewReused(projectAndSceneScreenshotData)) { + return; + } + if (projectAndSceneImage != null) { + projectAndSceneScreenshotData.imageView.setImageBitmap(projectAndSceneImage); + } else { + projectAndSceneScreenshotData.imageView.setImageBitmap(null); + } } - } - }); + }); + } } File getScreenshotFile() { diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/UiUtils.java b/catroid/src/main/java/org/catrobat/catroid/ui/UiUtils.java new file mode 100644 index 00000000000..b08ce7857d8 --- /dev/null +++ b/catroid/src/main/java/org/catrobat/catroid/ui/UiUtils.java @@ -0,0 +1,49 @@ +/* + * Catroid: An on-device visual programming system for Android devices + * Copyright (C) 2010-2018 The Catrobat Team + * () + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * An additional term exception under section 7 of the GNU Affero + * General Public License, version 3, is available at + * http://developer.catrobat.org/license_additional_term + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.catrobat.catroid.ui; + +import android.app.Activity; +import android.content.Context; +import android.content.ContextWrapper; +import android.view.View; + +public final class UiUtils { + private UiUtils() { + } + + public static Activity getActivityFromView(View view) { + Context context = view.getContext(); + while (context instanceof ContextWrapper) { + if (context instanceof Activity) { + break; + } + context = ((ContextWrapper) context).getBaseContext(); + } + + if (context instanceof Activity) { + return (Activity) context; + } + return null; + } +} diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/FormulaEditorFragment.java b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/FormulaEditorFragment.java index c42975d34ee..ff0514dfd56 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/FormulaEditorFragment.java +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/FormulaEditorFragment.java @@ -68,6 +68,7 @@ import org.catrobat.catroid.formulaeditor.UserList; import org.catrobat.catroid.formulaeditor.UserVariable; import org.catrobat.catroid.ui.BottomBar; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.dialogs.FormulaEditorComputeDialog; import org.catrobat.catroid.ui.dialogs.FormulaEditorIntroDialog; import org.catrobat.catroid.ui.recyclerview.dialog.NewStringDialogFragment; @@ -158,7 +159,11 @@ private void cloneFormulaBrick(FormulaBrick formulaBrick) { } private static void showFragment(View view, FormulaBrick formulaBrick, Brick.BrickField brickField, boolean showCustomView) { - Activity activity = (Activity) view.getContext(); + + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return; + } FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) activity.getFragmentManager() .findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG); @@ -236,7 +241,10 @@ public static void showCustomFragment(View view, FormulaBrick formulaBrick, Bric public static void overwriteFormula(View view, Formula newFormula) { - Activity activity = (Activity) view.getContext(); + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return; + } FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) activity.getFragmentManager() .findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG); @@ -250,7 +258,10 @@ public static void overwriteFormula(View view, Formula newFormula) { public static void changeInputField(View view, Brick.BrickField brickField) { - Activity activity = (Activity) view.getContext(); + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return; + } FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) activity.getFragmentManager() .findFragmentByTag(FORMULA_EDITOR_FRAGMENT_TAG); diff --git a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/UserBrickElementEditorFragment.java b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/UserBrickElementEditorFragment.java index 4d11c6a3c22..086d3e8d8f1 100644 --- a/catroid/src/main/java/org/catrobat/catroid/ui/fragment/UserBrickElementEditorFragment.java +++ b/catroid/src/main/java/org/catrobat/catroid/ui/fragment/UserBrickElementEditorFragment.java @@ -55,6 +55,7 @@ import org.catrobat.catroid.ui.DragAndDropBrickLayoutListener; import org.catrobat.catroid.ui.DragNDropBrickLayout; import org.catrobat.catroid.ui.LineBreakListener; +import org.catrobat.catroid.ui.UiUtils; import org.catrobat.catroid.ui.dialogs.UserBrickEditElementDialog; import java.util.ArrayList; @@ -86,7 +87,10 @@ public void onCreate(Bundle savedInstanceState) { } public static void showFragment(View view, UserScriptDefinitionBrick brick) { - Activity activity = (Activity) view.getContext(); + Activity activity = UiUtils.getActivityFromView(view); + if (activity == null) { + return; + } UserBrickElementEditorFragment dataEditorFragment = (UserBrickElementEditorFragment) activity .getFragmentManager().findFragmentByTag(BRICK_DATA_EDITOR_FRAGMENT_TAG);