BlocklyCategory

public class BlocklyCategory extends Object

A category of a toolbox, which holds zero or more blocks or zero or more subcategories. Not both. FlyoutFragment is responsible for displaying this.

Nested Class Summary

class BlocklyCategory.BlockItem Flyout item that contains a stack blocks. 
class BlocklyCategory.ButtonItem Flyout item representing a clickable button, such as "Add Variable". 
class BlocklyCategory.Callback Callback class for listening to changes to this category. 
class BlocklyCategory.CategoryItem Wraps items that can be displayed as part of a BlocklyCategory
class BlocklyCategory.LabelItem Flyout item representing a label between groups of blocks. 

Field Summary

public static final CUSTOM_CATEGORIES
protected final List<BlocklyCategory.CategoryItem> mItems
protected final List<BlocklyCategory> mSubcategories

Public Constructor Summary

Public Method Summary

void
addItem(BlocklyCategory.CategoryItem item)
Add a Block to the blocks displayed in this category.
void
addItem(int index, BlocklyCategory.CategoryItem item)
Add a Block to the blocks displayed in this category at the specified index.
void
void
clear()
Clear the contents of this category and all subcategories; remove subcategories.
static BlocklyCategory
fromXml(XmlPullParser parser, BlockFactory factory, String workspaceId)
Read the full definition of the category's contents in from XML.
void
getAllBlocksRecursive(List<Block> blocks)
Fill the given list with of the Block instances in this category and its subcategories.
String
Integer
String
List<BlocklyCategory.CategoryItem>
getItems()
Gets the list of blocks in this category.
List<BlocklyCategory>
int
int
indexOf(Block rootBlock)
boolean
boolean
removeBlock(Block block)
Convenience method for removing a BlocklyCategory.BlockItem from this category by its block.
boolean
removeItem(int index)
Removes an item from this category.
boolean
removeItem(BlocklyCategory.CategoryItem item)
Removes an item from this category.
void

Inherited Method Summary

Fields

public static final CUSTOM_CATEGORIES

protected final List<BlocklyCategory.CategoryItem> mItems

protected final List<BlocklyCategory> mSubcategories

Public Constructors

public BlocklyCategory ()

Public Methods

public void addItem (BlocklyCategory.CategoryItem item)

Add a Block to the blocks displayed in this category.

Parameters
item The Block to add.

public void addItem (int index, BlocklyCategory.CategoryItem item)

Add a Block to the blocks displayed in this category at the specified index.

Parameters
index The index to insert the block at.
item The Block to add.

public void addSubcategory (BlocklyCategory subcategory)

Parameters
subcategory The category to add under this category.

public void clear ()

Clear the contents of this category and all subcategories; remove subcategories.

public static BlocklyCategory fromXml (XmlPullParser parser, BlockFactory factory, String workspaceId)

Read the full definition of the category's contents in from XML.

Parameters
parser The XmlPullParser to read from.
factory The BlockFactory to use to generate blocks from their names.
workspaceId The workspaceId to set on all blocks attached to this Category.
Returns
Throws
BlockLoadingException If any error occurs with the input. It may wrap an IOException or XmlPullParserException as a root cause.

public void getAllBlocksRecursive (List<Block> blocks)

Fill the given list with of the Block instances in this category and its subcategories.

Parameters
blocks The list to add to, which is not cleared before adding blocks.

public String getCategoryName ()

Returns
  • The user visible name of this category.

public Integer getColor ()

public String getCustomType ()

Returns
  • The custom type of this category.

public List<BlocklyCategory.CategoryItem> getItems ()

Gets the list of blocks in this category. The list should not be modified directly, instead addItem(CategoryItem) and removeItem(CategoryItem) should be used.

Returns
  • The list of blocks in this category.

public List<BlocklyCategory> getSubcategories ()

public int indexOf (BlocklyCategory.CategoryItem item)

Parameters
item
Returns
  • The index of the given item or -1 if it's not in this category.

public int indexOf (Block rootBlock)

Parameters
rootBlock
Returns
  • The index of the item containing the given block or -1 if it's not in this category.

public boolean isEmpty ()

Returns
  • True if this category contains no blocks or subcategories, false otherwise.

public boolean removeBlock (Block block)

Convenience method for removing a BlocklyCategory.BlockItem from this category by its block.

Parameters
block The block to locate and remove.
Returns
  • true if an item with that block was found and removed, false otherwise.

public boolean removeItem (int index)

Removes an item from this category.

Parameters
index The position of the item to remove.
Returns
  • true if the item was removed, otherwise an OOBE will be thrown.

public boolean removeItem (BlocklyCategory.CategoryItem item)

Removes an item from this category.

Parameters
item The item to remove.
Returns
  • true if the item was found and removed, false otherwise.

public void setCallback (BlocklyCategory.Callback callback)

Parameters
callback