Known Direct Subclasses |
Known Indirect Subclasses |
Interface for mutators, platform specific hooks into blocks that manage the <mutation>
serialized state and any related block updates.
"mutator"
attribute in JSON block
definition. With this, the block constructor will call
applyMutator(String, Block)
.
See guide on
extensions and mutators.
Nested Class Summary
interface | Mutator.Factory<T extends Mutator> | The factory class for this type of mutator. |
Constant Summary
String | TAG_MUTATION | The tag name for the XML element when serializing and updating Mutators. |
Field Summary
protected Block | mBlock |
Protected Constructor Summary
Public Method Summary
final void | |
final void |
detachFromBlock()
This is called when a mutator is detached from a block.
|
Block |
getBlock()
|
final String | |
abstract void |
serialize(XmlSerializer serializer)
Serializes the Mutator's state to an XML
<mutation> element. |
abstract void |
update(XmlPullParser parser)
Updates the mutator state from the provided
<mutation> XML. |
Protected Method Summary
void | |
void |
onDetached(Block block)
Called immediately after the mutator is detached from a block, usually as a result of
destroying the block.
|
Inherited Method Summary
Constants
public static final String TAG_MUTATION
The tag name for the XML element when serializing and updating Mutators.
Fields
Protected Constructors
protected Mutator (Factory factory)
Mutators are required to be initialized with the factory used to create them.
Parameters
factory |
---|
Public Methods
public final void attachToBlock (Block block)
This is called when a mutator is attached to a block. Developers wishing to perform
setup on the block should override onAttached(Block)
.
Parameters
block | The block this mutator is attached to. |
---|
public final void detachFromBlock ()
This is called when a mutator is detached from a block. Developers wishing to perform
teardown on the block should override onDetached(Block)
.
public final String getMutatorId ()
Returns
- The id that was used to register this mutator's factory.
public abstract void serialize (XmlSerializer serializer)
Serializes the Mutator's state to an XML <mutation>
element.
Compare with block.mutationToDom()
on web Blockly (added by extensions or mixins),
or Mutator.toXMLElement()
on blockly-ios.
Throws
IOException |
---|
public abstract void update (XmlPullParser parser)
Updates the mutator state from the provided <mutation>
XML. The parser state is such
that parser.next()
will return START_TAG
, the beginning of the
<mutation>
element.
Compare with block.domToMutation()
on web Blockly (added by extensions or mixins),
or Mutator.update()
on blockly-ios.
Parameters
parser | The parser with the <mutation> element. |
---|
Throws
IOException | If the parser cannot read its source. |
---|---|
XmlPullParserException | If the parser cannot parse into XML. |
BlockLoadingException | If the XML is not what the mutator expected. |
Protected Methods
protected void onAttached (Block block)
Called immediately after the mutator is attached to the block. Can be used to perform additional block initialization related to this mutator.
Parameters
block |
---|
protected void onDetached (Block block)
Called immediately after the mutator is detached from a block, usually as a result of destroying the block.
Parameters
block |
---|