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 | |
void |
addItem(int index, BlocklyCategory.CategoryItem item)
Add a
Block to the blocks displayed in this category at the specified index. |
void |
addSubcategory(BlocklyCategory subcategory)
|
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 |
getColor()
|
String | |
List<BlocklyCategory.CategoryItem> |
getItems()
Gets the list of blocks in this category.
|
List<BlocklyCategory> | |
int | |
int | |
boolean |
isEmpty()
|
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 | |
void |
setCallback(BlocklyCategory.Callback callback)
|
Inherited Method Summary
Fields
public
static
final
CUSTOM_CATEGORIES
Public Constructors
public BlocklyCategory ()
Public Methods
public void addItem (BlocklyCategory.CategoryItem item)
public void addItem (int index, BlocklyCategory.CategoryItem item)
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
- A new
BlocklyCategory
with the contents given by the XML.
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 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.