I am currently playing with some ideas for expanding Canvas component, so I decided to just clone it, and then toy with its code.
TL;DR of what I have done (it might serve as reference to others):
-
Copy Canvas.java to CanvasClone.java, I’ve renamed class to CanvasClone
-
In YaVersion.java:
2.1 increase YOUNG_ANDROID_VERSION = 198 (+1 from 197)
2.2 add CANVASCLONE_COMPONENT_VERSION = 1
-
In CanvasClone.java (the new component, exact clone of Canvas.java), update code to use version=YaVersion.CANVASCLONE_COMPONENT_VERSION
-
Copy MockCanvas.java to MockCanvasClone.java, rename class name to MockCanvasClone.java
-
In SimpleComponentDescriptor.java:
5.1 add “import com.google.appinventor.client.editor.simple.components.MockCanvasClone”
5.2 update function public static MockComponent createMockComponent() to identify MockCanvasClone
Source file references:
Canvas.java in com.google.appinventor.components.runtime
CanvasClone.java in com.google.appinventor.components.runtime
YaVersion.java in com.google.appinventor.components.common
MockCanvas.java in com.google.appinventor.client.editor.simple.components
MockCanvasClone.java in com.google.appinventor.client.editor.simple.components
SimpleComponentDescriptor.java in com.google.appinventor.client.editor.simple.palette
Basically, I’ve done the same as Topo wrote in 2014 I believe, his post can be found on GoogleGroups, now obsolete gathering point for MIT App Inventor2.
It compiled flawlessly, but when I tried to create a new project and check, this is mistake I got:
faultData = java.lang.UnsupportedOperationException: unknown component: CanvasClone
More verbosely:
notes = Browser: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0
foundIn = v181-36-g27fec76c-dirty
faultData = java.lang.UnsupportedOperationException: unknown component: CanvasClone
projectId = -1
After I reread how to add component/ property to component from documentation site here:
https://mit-cml.github.io/appinventor-sources/ I’ve found out that from September 19th 2019, one has to (semi)manually change corresponding Documentation.html, actually found here:
… appinventor/docs/html/reference/components/animation.html (component-doc.html)
It didn’t help, same mistake showed after trying to create a new project with the new component included.
I’ve then checked ComponentsTranslation.java, and CanvasClone is there. I’ve also checked following files too: simple_components.json
simple_components.txt
simple_components_permissions.json
ya_lang_def.xml
Everything was all right as I was able to discern.
Just in case, I did the same with WebViewer component, (I’ve made WebViewerClone.java etc.), in case there is something special with Canvas. Same thing happened.
Please note, if one intends to do so with WebViewer. java component, one is advised to create a new helper method setupWebViewGeoLoc in EclairUtil.java in com.google.appinvnetor.components.runtime.util where WebViewerClone is the caller.
Same mistake appeared when I was checking, trying to make a new project with a new/cloned component:
notes = Browser: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0
foundIn = v181-48-gb4bbaa77-dirty
faultData = java.lang.UnsupportedOperationException: unknown component: WebViewerClone
projectId = -1
For completeness sake, I should mention that both time I was working on a new, local branch based on a newest master at the time of the writing. In case someone is wondering, I am interested to found out how feasible is to have a possibility to add new sprites from designer. I know it is dumb, considering all the hardware/software limitations, but I ,for one reason or another, just want to find out how far they go ;).
I am sure I am missing something obvious, but clearly, atm I do not know what :). Perhaps it is Blockly related, since it compiles?
Thank you all in advance, and greetings to you all, it has been awhile since I had time for MIT App Inventor 2, I am really glad that community has grown so much.