1. how do you specify blocks to appear on the workspace by default (ie forced blocks like 'Start') and mark them as un-deletable?
2. I find that javascript code passed to onFinishCodeGeneration() is not organized with functions at the top and that blocks that are not encapsulated by start blocks appear - can I control the filtering of this? I would like to strip out all the blocks that are not within start blocks.
3. how is it suggested that we can 'execute' the javascript code within Android? The examples all use WebView's which make sense to execute javascript in, but in my case I'm using the code to drive a physical robot around. So far I found that using the open-source AndroidJSContext works, but I'm not sure if that's the easiest or even necessary. It seems like android-blockly is using javascript for code-generation so they must be interpreting it?
4. how do I enable functions in the toolbox?
Hey Tim,Thanks for trying out Blockly for Android. Let's see if I can help:1. how do you specify blocks to appear on the workspace by default (ie forced blocks like 'Start') and mark them as un-deletable?I would suggest constructing a XML for your initial workspace, and loading that file inside your activity's onLoadInitialWorkspace() or onInitBlankWorkspace().Within that XML, you can specify deletable="false" on a block, but we haven't actually implemented this (#305). This should be a quick fix, if you have the time (and I don't get to it first). However, movable="false" is implemented, and will prevent users from dragging the block, including dragging it to the trash. A mild but effective hack.
2. I find that javascript code passed to onFinishCodeGeneration() is not organized with functions at the top and that blocks that are not encapsulated by start blocks appear - can I control the filtering of this? I would like to strip out all the blocks that are not within start blocks.In web blockly, the easiest way prevent the generation of code unconnected to event trigger blocks is to set Blockly.Events.disableOrphans=true. Unfortunately, this is another case where Blockly for Android doesn't support this yet (#333). This should be feasible once all the basic event code is implement (my current project).
Both problems (ordering and skipping code generation) are solvable by modifying the JavaScript generator to your needs. You can find the source of the JavaScript generator (and others), here, on the main Blockly repo. Blockly for Android is compatible with all of them. Replace references to javascript_compressed.js with the file name of your own generator code (#99, add an API for this).
3. how is it suggested that we can 'execute' the javascript code within Android? The examples all use WebView's which make sense to execute javascript in, but in my case I'm using the code to drive a physical robot around. So far I found that using the open-source AndroidJSContext works, but I'm not sure if that's the easiest or even necessary. It seems like android-blockly is using javascript for code-generation so they must be interpreting it?Blockly does use a limited amount of off-screen WebViews to execute generator JavaScript, but we are agnostic regarding how apps should run their code.
In our own robots (such as those seen at Google IO), we upload the generated code into the robot and run it there. We like this strategy, because it means the robot can run independent of the tablet and the wifi connection. In that case, depending on your robot, JavaScript might not be the right language, but it is pretty easy to use your own language generator.4. how do I enable functions in the toolbox?Blockly for Android does not support functions yet. We still exploring appropriate touch/mobile UIs equivalents for the "mutator" window used in function argument configuration and other blocks.It's great to hear your needs, and hopefully we can prioritize a few of these small ones.
On Monday, August 29, 2016 at 3:23:21 PM UTC-7, Andrew n marshall wrote:2. I find that javascript code passed to onFinishCodeGeneration() is not organized with functions at the top and that blocks that are not encapsulated by start blocks appear - can I control the filtering of this? I would like to strip out all the blocks that are not within start blocks.In web blockly, the easiest way prevent the generation of code unconnected to event trigger blocks is to set Blockly.Events.disableOrphans=true. Unfortunately, this is another case where Blockly for Android doesn't support this yet (#333). This should be feasible once all the basic event code is implement (my current project).What is your best guess at timeframe on getting to that?
Both problems (ordering and skipping code generation) are solvable by modifying the JavaScript generator to your needs. You can find the source of the JavaScript generator (and others), here, on the main Blockly repo. Blockly for Android is compatible with all of them. Replace references to javascript_compressed.js with the file name of your own generator code (#99, add an API for this).I haven't yet dug into the android-blockly code. Are you saying it is referencing the main blockly repo and using those code generators or are you saying I could use those to override what is built into android-blockly at the moment?
3. how is it suggested that we can 'execute' the javascript code within Android? The examples all use WebView's which make sense to execute javascript in, but in my case I'm using the code to drive a physical robot around. So far I found that using the open-source AndroidJSContext works, but I'm not sure if that's the easiest or even necessary. It seems like android-blockly is using javascript for code-generation so they must be interpreting it?Blockly does use a limited amount of off-screen WebViews to execute generator JavaScript, but we are agnostic regarding how apps should run their code.Do you have an example of using an offscreen WebView you can point me to? I have to admit I'm very new to Android programming and even my Java is about 10 years rusty. It sounds like using an off-screen WebView may eliminate the need for AndroidJSContext but I would need to understand how to bind javascript functions back to Java.I should be able to create event handlers by using AndroidJSContext to invoke javascript bindings on events, I just haven't quite figured out how to do that yet. My first use case is to have a voiceCommand background service capturing simple voice commands and issuing callbacks for those. I haven't yet figured out what the best course of action for this is.
context.evaluateScript("var f = factorial(10);")
It would probably help to explain more about what i'm doing. In my use case the robot's are simple home-made robots using 4 servo's controlled by an Arduino. An Android phone acts as the robot head and currently is where the Blockly code is designed and executed. Thus I need to hook the javascript functions (or objects) that my blocks call out to interpret them into simple strings sent to the Arduino over bluetooth. My goal is to eventually allow the user to code in javascript directly as well and eventually allow syncing with javascript created by a web-based blockly/javascript editor (kind of like MIT's App Inventor uses a companion app to keep data in sync with their web based IDE).This is for a grade school robotics class - See http://github.com/tharvey/BlocklyBot and http://robotstem.wordpress.com for details.Thanks for the great suggestions!
--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/cMaqarnW3kw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hey Tim,Thanks for trying out Blockly for Android. Let's see if I can help:1. how do you specify blocks to appear on the workspace by default (ie forced blocks like 'Start') and mark them as un-deletable?I would suggest constructing a XML for your initial workspace, and loading that file inside your activity's onLoadInitialWorkspace() or onInitBlankWorkspace().Within that XML, you can specify deletable="false" on a block, but we haven't actually implemented this (#305). This should be a quick fix, if you have the time (and I don't get to it first). However, movable="false" is implemented, and will prevent users from dragging the block, including dragging it to the trash. A mild but effective hack.
2. I find that javascript code passed to onFinishCodeGeneration() is not organized with functions at the top and that blocks that are not encapsulated by start blocks appear - can I control the filtering of this? I would like to strip out all the blocks that are not within start blocks.In web blockly, the easiest way prevent the generation of code unconnected to event trigger blocks is to set Blockly.Events.disableOrphans=true. Unfortunately, this is another case where Blockly for Android doesn't support this yet (#333). This should be feasible once all the basic event code is implement (my current project).Both problems (ordering and skipping code generation) are solvable by modifying the JavaScript generator to your needs. You can find the source of the JavaScript generator (and others), here, on the main Blockly repo. Blockly for Android is compatible with all of them. Replace references to javascript_compressed.js with the file name of your own generator code (#99, add an API for this).
3. how is it suggested that we can 'execute' the javascript code within Android? The examples all use WebView's which make sense to execute javascript in, but in my case I'm using the code to drive a physical robot around. So far I found that using the open-source AndroidJSContext works, but I'm not sure if that's the easiest or even necessary. It seems like android-blockly is using javascript for code-generation so they must be interpreting it?Blockly does use a limited amount of off-screen WebViews to execute generator JavaScript, but we are agnostic regarding how apps should run their code.In our own robots (such as those seen at Google IO), we upload the generated code into the robot and run it there. We like this strategy, because it means the robot can run independent of the tablet and the wifi connection. In that case, depending on your robot, JavaScript might not be the right language, but it is pretty easy to use your own language generator.
4. how do I enable functions in the toolbox?Blockly for Android does not support functions yet. We still exploring appropriate touch/mobile UIs equivalents for the "mutator" window used in function argument configuration and other blocks.It's great to hear your needs, and hopefully we can prioritize a few of these small ones.
It looks like all the code is in place for get/setDeletable - it just isn't checking this when deleting a block. The following seems to work fine for me: https://github.com/tharvey/BlocklyBot/commit/c8569e074971f6c21e83b1affd1c95f3313afa2a
I like this strategy as well, but I'm not aware of a javascript interpreter in android that you can 'hook' into. I'm currently using AndroidJSCore as an interpreter and its working well. I'm able to hook the function calls that my blocks create.
I added some 'Listen' blocks that use voice recognition (I found Android's VoiceRecognizer to not be fast enough (which may be me not tuning it proplery) and thus am using CMU's PocketSphinx which is working well for recognizing phrases. This way I can have a 'Listen' block with a text field where the user selects the phrase they want to trigger off of and I have an event handler that calls the function that is comprised of the function input to the block. Once I had 'listen' blocks working as event handlers it made sense to add a 'start' block and filter out orphaned root blocks.