BlocklyController.Builder

public static class BlocklyController.Builder extends Object

Builder for configuring a new controller and workspace.

Public Constructor Summary

BlocklyController.Builder(Context context)

Public Method Summary

BlocklyController.Builder
addBlockDefinitions(int blockDefinitionsResId)
Add a set of block definitions to load from a resource file.
BlocklyController.Builder
addBlockDefinitionsFromAsset(String assetName)
Add a set of block definitions to load from a JSON asset file.
BlocklyController.Builder
addBlockDefinitionsFromAssets(List<String> assetNames)
Add sets of block definitions to load from multiple JSON asset file.
BlocklyController
build()
Create a new workspace using the configuration in this builder.
BlocklyController.Builder
BlocklyController.Builder
BlocklyController.Builder
setToolboxConfigurationAsset(String assetName)
Sets the asset to load the toolbox configuration from.
BlocklyController.Builder
setToolboxConfigurationResId(int toolboxResId)
Sets the resource to load the toolbox configuration from.
BlocklyController.Builder
setToolboxUi(BlockListUI toolbox, CategorySelectorUI categoryUi)
Sets the ui used for the toolbox, including the flyout with blocks and the category tabs.
BlocklyController.Builder
setTrashIcon(View trashIcon)
Sets a View to use as a drop target and click target for opening/closing the trash.
BlocklyController.Builder
setTrashUi(BlockListUI trash)
Sets the BlockListUI to be used for the trash.
BlocklyController.Builder
BlocklyController.Builder
BlocklyController.Builder

Inherited Method Summary

Public Constructors

public BlocklyController.Builder (Context context)

Parameters
context

Public Methods

public BlocklyController.Builder addBlockDefinitions (int blockDefinitionsResId)

Add a set of block definitions to load from a resource file. These will be added to the set of all known blocks, but will not appear in the user's toolbox unless they are also defined in the toolbox configuration via setToolboxConfigurationResId(int).

The resource must be a json file in the raw directory. If the file contains blocks that were previously defined they will be overridden.

A duplicate block is any block with the same type.

Parameters
blockDefinitionsResId The resource to load blocks from.
Returns
  • this

public BlocklyController.Builder addBlockDefinitionsFromAsset (String assetName)

Add a set of block definitions to load from a JSON asset file. These will be added to the set of all known blocks, but will not appear in the user's toolbox unless they are also defined in the toolbox configuration via setToolboxConfigurationResId(int).

The asset name must be a path to a file in the assets directory. If the file contains blocks that were previously defined, they will be overridden. A duplicate block is any block with the same type.

Parameters
assetName the path of the asset to load from.
Returns
  • this

public BlocklyController.Builder addBlockDefinitionsFromAssets (List<String> assetNames)

Add sets of block definitions to load from multiple JSON asset file. These will be added to the set of all known blocks, but will not appear in the user's toolbox unless they are also defined in the toolbox configuration via setToolboxConfigurationResId(int).

The asset names must be a path to files in the assets directory. If the files contain blocks that were previously defined, they will be overridden. A duplicate block is any block with the same type.

Parameters
assetNames The paths of the assets to load.
Returns
  • this

public BlocklyController build ()

Create a new workspace using the configuration in this builder.

Returns

public BlocklyController.Builder setBlockViewFactory (BlockViewFactory blockViewFactory)

Parameters
blockViewFactory

public BlocklyController.Builder setClipDataHelper (BlockClipDataHelper clipHelper)

Parameters
clipHelper

public BlocklyController.Builder setToolboxConfigurationAsset (String assetName)

Sets the asset to load the toolbox configuration from. The asset name must be a path to a file in the assets directory.

If this is set setToolboxConfigurationResId(int) may not be set.

Parameters
assetName The asset for the toolbox config file.
Returns
  • this

public BlocklyController.Builder setToolboxConfigurationResId (int toolboxResId)

Sets the resource to load the toolbox configuration from. This must be an xml resource in the raw directory.

If this is set, setToolboxConfigurationAsset(String) may not be set.

Parameters
toolboxResId The resource id for the toolbox config file.
Returns
  • this

public BlocklyController.Builder setToolboxUi (BlockListUI toolbox, CategorySelectorUI categoryUi)

Sets the ui used for the toolbox, including the flyout with blocks and the category tabs.

Warning: It is possible this toolbox will be loaded during build(), before the application has a chance to register any Mutators or BlockExtensions. Make sure, if using this convenience Builder method, the referenced blocks do not depend upon such features. Otherwise, set the toolbox later by calling setToolboxUi(BlockListUI, CategorySelectorUI) on the controller, post construction.

Parameters
toolbox The BlockListUI to use to display blocks in the current category.
categoryUi The BlockListUI for displaying the list of categories.
Returns
  • this

public BlocklyController.Builder setTrashIcon (View trashIcon)

Sets a View to use as a drop target and click target for opening/closing the trash. Since the icon may not be inflated yet this can be added after creating the controller with setTrashIcon(View).

Parameters
trashIcon The view to use for opening/closing the trash.
Returns
  • this

public BlocklyController.Builder setTrashUi (BlockListUI trash)

Sets the BlockListUI to be used for the trash. This must be a different ui than the toolbox flyout ui.

Parameters
trash The BlockListUI to use to display blocks in the trash.
Returns
  • this

public BlocklyController.Builder setVariableCallback (BlocklyController.VariableCallback variableCallback)

Parameters
variableCallback

public BlocklyController.Builder setWorkspaceFragment (WorkspaceFragment workspace)

Parameters
workspace

public BlocklyController.Builder setWorkspaceHelper (WorkspaceHelper workspaceHelper)

Parameters
workspaceHelper