DefaultVariableCallback

public class DefaultVariableCallback extends BlocklyController.VariableCallback

Default implementation of BlocklyController.VariableCallback. It uses DeleteVariableDialog and NameVariableDialog by default, but either can be replaced by overriding newDeleteVariableDialog() or newNameVariableDialog(), respectively.

Public Constructor Summary

DefaultVariableCallback(AppCompatActivity activity, BlocklyController controller)

Public Method Summary

void
onAlertCannotDeleteProcedureArgument(String variableName, VariableInfo varInfo)
Sent when a user attempts to delete a variable that is used as a procedure argument.
boolean
onCreateVariable(String variable)
Sent when the user tries to create a new variable.
boolean
onDeleteVariable(String variableName, VariableInfo variableInfo)
Sent when the user tries to remove a variable.
boolean
onRenameVariable(String variable, String newName)
Sent when the user tries to rename a variable.

Protected Method Summary

DeleteVariableDialog
NameVariableDialog

Inherited Method Summary

Public Constructors

public DefaultVariableCallback (AppCompatActivity activity, BlocklyController controller)

Parameters
activity
controller

Public Methods

public void onAlertCannotDeleteProcedureArgument (String variableName, VariableInfo varInfo)

Sent when a user attempts to delete a variable that is used as a procedure argument.

Parameters
variableName The name of the variable.
varInfo The info for this variable.

public boolean onCreateVariable (String variable)

Sent when the user tries to create a new variable. If true is returned a variable will be created with the next available default name. If callers wish to modify and then create a variable they should return false and then call addVariable(String) with the new variable and forced set to true.

Parameters
variable The initial variable name or null if no starting name was specified.
Returns
  • True to create the named variable, false to handle it yourself.

public boolean onDeleteVariable (String variableName, VariableInfo variableInfo)

Sent when the user tries to remove a variable. If true is returned the variable and any blocks referencing it will be deleted.

Parameters
variableName The variable being deleted.
variableInfo
Returns
  • True to allow the delete, false to prevent it.

public boolean onRenameVariable (String variable, String newName)

Sent when the user tries to rename a variable. There is no default handling for variable renaming in the controller, so an application must override this to support renaming variables.

Parameters
variable The variable to rename.
newName The new name for the variable.
Returns
  • True to perform the rename, false to handle it yourself.

Protected Methods

protected DeleteVariableDialog newDeleteVariableDialog ()

protected NameVariableDialog newNameVariableDialog ()