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 Sep 15, 2022
1 parent 2e9dd66 commit 7600e90
Show file tree
Hide file tree
Showing 84 changed files with 424 additions and 213 deletions.
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>
88 changes: 88 additions & 0 deletions catroid/src/main/assets/catblocks/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,94 @@ body {
width: 100%;
}

#catroid-catblocks-add-brick-dialog {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 9999;
background-color: white;
}

#catroid-catblocks-add-brick-dialog-header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 50px;
}

#catroid-catblocks-add-brick-dialog-content {
position: absolute;
top: 50px;
bottom: 0;
left: 0;
right: 0;
overflow-x: auto;
}

#catroid-catblocks-bricks-container {
width: 90%;
margin-left: 5%;
margin-right: 5%;
}

.catblocks-svg-brick-container {
width: 100%;
background-color: white;
overflow-y: hidden;
overflow-x: auto;
}

.catblocks-svg-brick-container > svg {
width: 100%;
}

#catroid-catblocks-add-brick-dialog-header-content-container {
position: absolute;
top: 0;
left: 10px;
right: 50px;
height: 50px;

display: flex;
/*justify-content: center;*/
align-items: center;
}

#catroid-catblocks-add-brick-dialog-close-container {
position: absolute;
top: 0;
right: 0;
width: 50px;
height: 50px;

display: flex;
justify-content: center;
align-items: center;
}

#catroid-catblocks-add-brick-dialog-header-text {
margin-bottom: 0;
}

#catroid-catblocks-add-brick-text-container {
vertical-align: middle;
}

#catroid-catblocks-add-brick-back-container {
vertical-align: middle;
}

.catblocks-brick {
margin-bottom: 5px;
}

.catblocks-brick:first-of-type {
margin-top: 5px;
}

/*!
* Bootstrap v4.6.1 (https://getbootstrap.com/)
* Copyright 2011-2021 The Bootstrap Authors
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package org.catrobat.catroid.ui.fragment

import android.content.Context
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
Expand All @@ -34,7 +33,6 @@ import android.widget.AdapterView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.ListFragment
import org.catrobat.catroid.ProjectManager
import org.catrobat.catroid.R
import org.catrobat.catroid.ui.BottomBar.hideBottomBar
import org.catrobat.catroid.ui.BottomBar.showBottomBar
Expand All @@ -44,11 +42,7 @@ import org.catrobat.catroid.ui.ViewSwitchLock
import org.catrobat.catroid.ui.adapter.BrickCategoryAdapter
import org.catrobat.catroid.ui.addTabLayout
import org.catrobat.catroid.ui.removeTabLayout
import org.catrobat.catroid.ui.settingsfragments.AccessibilityProfile
import org.catrobat.catroid.ui.settingsfragments.RaspberryPiSettingsFragment
import org.catrobat.catroid.ui.settingsfragments.SettingsFragment
import org.catrobat.catroid.utils.SnackbarUtil
import java.util.ArrayList
import java.util.concurrent.locks.Lock

class BrickCategoryFragment : ListFragment() {
Expand All @@ -65,8 +59,6 @@ class BrickCategoryFragment : ListFragment() {
scriptFragment = listener
}

private fun onlyBeginnerBricks(): Boolean = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(AccessibilityProfile.BEGINNER_BRICKS, false)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val isRestoringPreviouslyDestroyedActivity = savedInstanceState != null
Expand Down Expand Up @@ -141,55 +133,9 @@ class BrickCategoryFragment : ListFragment() {

@SuppressWarnings("ComplexMethod")
private fun setupBrickCategories() {
val inflater = requireActivity().layoutInflater
val categories: MutableList<View> = ArrayList()

categories.add(inflater.inflate(R.layout.brick_category_recently_used, null))
val brickCategoryFactory = BrickCategoryListBuilder(requireActivity())
val categories = brickCategoryFactory.getBrickCategoryViews()

if (SettingsFragment.isEmroiderySharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_embroidery, null))
}
if (SettingsFragment.isMindstormsNXTSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_lego_nxt, null))
}
if (SettingsFragment.isMindstormsEV3SharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_lego_ev3, null))
}
if (SettingsFragment.isDroneSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_drone, null))
}
if (SettingsFragment.isJSSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_drone_js, null))
}
if (SettingsFragment.isArduinoSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_arduino, null))
}
if (RaspberryPiSettingsFragment.isRaspiSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_raspi, null))
}
if (SettingsFragment.isPhiroSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_phiro, null))
}
if (ProjectManager.getInstance().currentProject.isCastProject) {
categories.add(inflater.inflate(R.layout.brick_category_chromecast, null))
}

categories.add(inflater.inflate(R.layout.brick_category_event, null))
categories.add(inflater.inflate(R.layout.brick_category_control, null))
categories.add(inflater.inflate(R.layout.brick_category_motion, null))
categories.add(inflater.inflate(R.layout.brick_category_sound, null))
categories.add(inflater.inflate(R.layout.brick_category_looks, null))
if (!onlyBeginnerBricks()) {
categories.add(inflater.inflate(R.layout.brick_category_pen, null))
}
categories.add(inflater.inflate(R.layout.brick_category_data, null))
categories.add(inflater.inflate(R.layout.brick_category_device, null))
if (!onlyBeginnerBricks()) {
categories.add(inflater.inflate(R.layout.brick_category_userbrick, null))
}
if (SettingsFragment.isTestSharedPreferenceEnabled(activity)) {
categories.add(inflater.inflate(R.layout.brick_category_assert, null))
}
adapter = BrickCategoryAdapter(categories)
listAdapter = adapter
}
Expand Down
Loading

0 comments on commit 7600e90

Please sign in to comment.