Skip to content

Commit

Permalink
CATROID-1202 implement add brick functionality in Catblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bprattes committed Oct 23, 2022
1 parent 8a3022e commit 55a1d25
Show file tree
Hide file tree
Showing 86 changed files with 540 additions and 339 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* 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 <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.uiespresso.content.brick.app

import android.view.View
import android.webkit.WebView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import org.catrobat.catroid.R
import org.catrobat.catroid.UiTestCatroidApplication.Companion.projectManager
import org.catrobat.catroid.content.Project
import org.catrobat.catroid.content.Sprite
import org.catrobat.catroid.content.StartScript
import org.catrobat.catroid.ui.SpriteActivity
import org.catrobat.catroid.ui.recyclerview.fragment.CatblocksScriptFragment
import org.catrobat.catroid.ui.settingsfragments.SettingsFragment
import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class AddBrickCatblocksTest {

companion object {
private const val TIMEOUT: Long = (5 * 1000).toLong()
}

@get:Rule
var baseActivityTestRule = FragmentActivityTestRule(
SpriteActivity::class.java, SpriteActivity.EXTRA_FRAGMENT_POSITION,
SpriteActivity.FRAGMENT_SCRIPTS
)

@Before
fun setUp() {
SettingsFragment.setUseCatBlocks(ApplicationProvider.getApplicationContext(), true)
createProject()
baseActivityTestRule.launchActivity()
}

@After
fun tearDown() {
SettingsFragment.setUseCatBlocks(ApplicationProvider.getApplicationContext(), false)
baseActivityTestRule.finishActivity()
}

@Test
fun addBricksFromCatblocksView() {
val uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
uiDevice.wait(Until.findObject(By.clazz(WebView::class.java)), TIMEOUT)
val catblocksView = baseActivityTestRule.activity.findViewById<View>(R.id.catblocksWebView)
val catblocksFragment = FragmentManager.findFragment<Fragment>(catblocksView) as CatblocksScriptFragment
catblocksFragment.activity?.runOnUiThread(Runnable {
catblocksFragment.handleAddButton()
})
val categoryEvent = uiDevice.findObject(
UiSelector().resourceId("categoryEVENT")
)
Assert.assertTrue(categoryEvent.waitForExists(TIMEOUT))
categoryEvent.click()
val brickStartScript = uiDevice.findObject(
UiSelector().resourceId("brickStartScript")
)
Assert.assertTrue(brickStartScript.waitForExists(TIMEOUT))
Assert.assertTrue(brickStartScript.exists())
Assert.assertTrue(brickStartScript.click())
Assert.assertTrue(brickStartScript.waitUntilGone(TIMEOUT))
Assert.assertEquals(projectManager.currentSprite.scriptList.count(), 1)
val addedScript = projectManager.currentSprite.scriptList.first()
Assert.assertNotNull(addedScript)
Assert.assertTrue(addedScript is StartScript)
}


private fun createProject() {
val projectName = javaClass.simpleName
val project = Project(ApplicationProvider.getApplicationContext(), projectName)
val sprite = Sprite("testSprite")
project.defaultScene.addSprite(sprite)
projectManager.currentProject = project
projectManager.currentSprite = sprite
}
}
2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/CatBlocks.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/af.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/az.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/bg.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/bn.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/bs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ca.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/chr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/cs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/da.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/de.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/el.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/en.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/en_AU.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/en_CA.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/en_GB.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/es.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/eu_ES.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/fa.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/fa_IR.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/fi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/fr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/gl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/gu.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ha.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/hi.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/hr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/hu.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ig.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/in.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/it.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/iw.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ja.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ka.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/kab.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/kk.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/kn.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ko.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/lt.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/mk.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ml.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ml_IN.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ms.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/nl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/no.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/pa_IN.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/pl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ps.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/pt.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/pt_BR.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ro.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ru.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sd.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/si.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sk.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sq.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sr_CS.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sr_SP.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sv.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/sw.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ta.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/te.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/th.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/tl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/tr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/tw.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/uk.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/ur.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/uz.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/vi.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions catroid/src/main/assets/catblocks/i18n/yo_NG.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/zh_CN.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion catroid/src/main/assets/catblocks/i18n/zh_TW.json

Large diffs are not rendered by default.

77 changes: 61 additions & 16 deletions catroid/src/main/assets/catblocks/index.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Catblocks 2D view</title>
<link href="main.css" rel="stylesheet">
</head>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Android Release</title>

<body>
<div id="catroid-catblocks-container"></div>
<script type="text/javascript"
src="https://appassets.androidplatform.net/assets/catblocks/CatBlocks.js"></script>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" />

<script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.15.0/css/mdb.min.css" rel="stylesheet" />
<link href="main.css?a54aa1ae5714dedd3117" rel="stylesheet"></head>

<body>
<div id="catroid-catblocks-container"></div>

<div id="catroid-catblocks-hidden-container" style="display:none;"></div>

<div id="catroid-catblocks-add-brick-dialog" style="display:none;">
<div id="catroid-catblocks-add-brick-dialog-header">
<div id="catroid-catblocks-add-brick-dialog-header-content-container">
<div id="catroid-catblocks-add-brick-back-container">
<img
src="https://appassets.androidplatform.net/assets/catblocks/media/arrow_back_ios_black_36dp.svg" />
</div>
<div id="catroid-catblocks-add-brick-text-container">
<h3 id="catroid-catblocks-add-brick-dialog-header-text"></h3>
</div>
</div>
<div id="catroid-catblocks-add-brick-dialog-close-container">
<img
src="https://appassets.androidplatform.net/assets/catblocks/media/close_black_36dp.svg" />
</div>
</div>
<div id="catroid-catblocks-add-brick-dialog-content">
<div id="catroid-catblocks-brick-category-container" class="list-group" style="display:none;"></div>
<div id="catroid-catblocks-bricks-container" style="display:none;"></div>
</div>
</div>

<script>
window.onload = function () {
CatBlocks.init({
container: 'catroid-catblocks-container',
Expand All @@ -28,13 +59,27 @@
readOnly: false
}).then(() => {
const programXML = Android.getCurrentProject();

const scene = Android.getSceneNameToDisplay();
const object = Android.getSpriteNameToDisplay();
const brickIDToFocus = Android.getBrickIDToFocus();
CatBlocks.render(programXML, scene, object, brickIDToFocus);
CatBlocks.render(programXML, scene, object);
});
};
</script>
</body>
</html>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"
></script>
<script type="text/javascript"
src="https://appassets.androidplatform.net/assets/catblocks/CatBlocks.js?a54aa1ae5714dedd3117"></script></body>
</html>
Loading

0 comments on commit 55a1d25

Please sign in to comment.