AbstractBlockView

public abstract class AbstractBlockView extends NonPropagatingViewGroup
implements BlockView
Known Direct Subclasses

An optional base class for BlockView. AbstractBlockView assumes InputViews are direct children, and handles most UI events and view hierarchy coordination. The measurement, placement and drawing are left to the subclass to implement.

Inherited Constant Summary

Field Summary

protected final Block mBlock
protected final ViewPoint mBlockViewSize
protected final ConnectionManager mConnectionManager
protected final BlockViewFactory mFactory
protected boolean mHasValueInput
protected final WorkspaceHelper mHelper
protected Connection mHighlightedConnection
protected View mIconsView
protected final ArrayList<ViewPoint> mInputConnectorOffsets
protected int mInputCount
protected final ArrayList<ViewPoint> mInputLayoutOrigins
protected final ArrayList<InputView extends InputView> mInputViews
protected final ViewPoint mNextConnectorOffset
protected final ViewPoint mOutputConnectorOffset
protected final ViewPoint mPreviousConnectorOffset
protected final ViewPoint mTempConnectionPosition
protected final WorkspacePoint mTempWorkspacePoint
protected BlockTouchHandler mTouchHandler
protected WorkspaceView mWorkspaceView

Inherited Field Summary

Protected Constructor Summary

AbstractBlockView(Context context, WorkspaceHelper helper, BlockViewFactory factory, Block block, List<InputView> inputViews, ConnectionManager connectionManager, BlockTouchHandler touchHandler)
Creates a BlockView for the given Block.

Public Method Summary

Block
ConnectionManager
InputView
getInputView(int index)
int
BlockGroup
BlockTouchHandler
void
getTouchLocationOnScreen(MotionEvent event, int[] locationOut)
Gets the screen location of a touch, assuming that the view transforms will be in the WorkspaceView that contains this view.
WorkspaceView
boolean
onInterceptTouchEvent(MotionEvent event)
Processes intercepted touch events by calling onInterceptTouchEvent(BlockView, MotionEvent) when hitTest(MotionEvent) passes.
boolean
onTouchEvent(MotionEvent event)
Test whether event hits visible parts of this block and notify WorkspaceView if it does.
void
setHighlightedConnection(Connection connection)
Select a connection for highlighted drawing.
void
setIconsView(View iconsView)
Sets a view containing one or more icons for the block, such as the mutate or warning icons.
void
setTouchHandler(BlockTouchHandler touchHandler)
Sets the touch handler used on this block and all contained blocks.
void
unlinkModel()
Recursively disconnects the view from the model, and removes all views.
void
updateConnectorLocations()
Updates the locations of the connections based on their offsets within the BlockView, based upon the view's position within the WorkspaceView.

Protected Method Summary

void
addInputViewsToViewHierarchy()
Adds the InputViews in mInputViews to the view hierarchy.
abstract boolean
coordinatesAreOnBlock(int x, int y)
Checks if the coordinates (relative to this view) exist on a visible part of this view.
void
drawConnectorCenters(Canvas c)
This is a developer testing function subclasses can call to draw dots at the model's location of all connections on this block.
boolean
hitTest(MotionEvent event)
Test whether a MotionEvent event that has happened on this view is (approximately) hitting a visible part of this view.
boolean
isEntireBlockHighlighted()
Check if border highlight is rendered.
void
onAttachedToWindow()
Stores a reference to the WorkspaceView containing this BlockView.
abstract void
onBlockUpdated(int updateMask)
Called when the underlying block has been updated.
void
onDetachedFromWindow()
Clears the reference to any WorkspaceView.

Inherited Method Summary

Fields

protected final Block mBlock

protected final ViewPoint mBlockViewSize

protected final ConnectionManager mConnectionManager

protected final BlockViewFactory mFactory

protected boolean mHasValueInput

protected final WorkspaceHelper mHelper

protected Connection mHighlightedConnection

protected View mIconsView

protected final ArrayList<ViewPoint> mInputConnectorOffsets

protected int mInputCount

protected final ArrayList<ViewPoint> mInputLayoutOrigins

protected final ArrayList<InputView extends InputView> mInputViews

protected final ViewPoint mNextConnectorOffset

protected final ViewPoint mOutputConnectorOffset

protected final ViewPoint mPreviousConnectorOffset

protected final ViewPoint mTempConnectionPosition

protected final WorkspacePoint mTempWorkspacePoint

protected BlockTouchHandler mTouchHandler

protected WorkspaceView mWorkspaceView

Protected Constructors

protected AbstractBlockView (Context context, WorkspaceHelper helper, BlockViewFactory factory, Block block, List<InputView> inputViews, ConnectionManager connectionManager, BlockTouchHandler touchHandler)

Creates a BlockView for the given Block.

Parameters
context The context for creating this view.
helper The WorkspaceHelper for this app.
factory The helper for loading workspace configs and doing calculations.
block The Block represented by this view.
inputViews The InputView children in the new BlockView.
connectionManager The ConnectionManager to update when moving connections.
touchHandler The optional handler for forwarding touch events on this block to the Dragger.

Public Methods

public Block getBlock ()

Returns
  • The block for this view.

public ConnectionManager getConnectionManager ()

Returns
  • The ConnectionManager managing the connections of this view.

public InputView getInputView (int index)

Parameters
index
Returns

public int getInputViewCount ()

Returns
  • The number of InputView instances inside this view.

public BlockGroup getParentBlockGroup ()

Returns
  • The closest view tree ancestor that is a BlockGroup.

public BlockTouchHandler getTouchHandler ()

Returns
  • The touch handler for handling the touch and drag events for this view.

public void getTouchLocationOnScreen (MotionEvent event, int[] locationOut)

Gets the screen location of a touch, assuming that the view transforms will be in the WorkspaceView that contains this view.

Parameters
event The touch event in question
locationOut The array to store the results.

public WorkspaceView getWorkspaceView ()

Returns

public boolean onInterceptTouchEvent (MotionEvent event)

Processes intercepted touch events by calling onInterceptTouchEvent(BlockView, MotionEvent) when hitTest(MotionEvent) passes.

Parameters
event The touch event in progress.
Returns

public boolean onTouchEvent (MotionEvent event)

Test whether event hits visible parts of this block and notify WorkspaceView if it does.

Parameters
event The MotionEvent to handle.
Returns
  • False if the touch was on the view but not on a visible part of the block; otherwise returns whether the WorkspaceView says that the event is being handled properly.

public void setHighlightedConnection (Connection connection)

Select a connection for highlighted drawing.

Parameters
connection The connection whose port to highlight. This must be a connection associated with the Block represented by this AbstractBlockView instance. Disables all connection highlights if connection is null.

public void setIconsView (View iconsView)

Sets a view containing one or more icons for the block, such as the mutate or warning icons. The view will be added to the view hierarchy, though the concrete BlockView implementation is responsible for deciding how the icons are laid out and drawn.

Parameters
iconsView The view containing any icons that are part of this block or null.

public void setTouchHandler (BlockTouchHandler touchHandler)

Sets the touch handler used on this block and all contained blocks.

Parameters
touchHandler The BlockTouchHandler to use.

public void unlinkModel ()

Recursively disconnects the view from the model, and removes all views.

public void updateConnectorLocations ()

Updates the locations of the connections based on their offsets within the BlockView, based upon the view's position within the WorkspaceView. Often used when the block has moved but not changed shape, such as after a drag.

Protected Methods

protected void addInputViewsToViewHierarchy ()

Adds the InputViews in mInputViews to the view hierarchy. The default implementation adds the views directly to this view, in order.

protected abstract boolean coordinatesAreOnBlock (int x, int y)

Checks if the coordinates (relative to this view) exist on a visible part of this view.

Parameters
x the x coordinate relative to this view.
y the y coordinate relative to this view.
Returns
  • true if the coordinates are on a visible part of this view.

protected void drawConnectorCenters (Canvas c)

This is a developer testing function subclasses can call to draw dots at the model's location of all connections on this block. Never called by default.

Parameters
c The canvas to draw on.

protected boolean hitTest (MotionEvent event)

Test whether a MotionEvent event that has happened on this view is (approximately) hitting a visible part of this view.

This is used to determine whether the event should be handled by this view, e.g., to activate dragging or to open a context menu. Since the actual block interactions are implemented at the WorkspaceView level, there is no need to store the event data in this class.

Parameters
event The MotionEvent to check.
Returns
  • True if the coordinate of the motion event is on the visible, non-transparent part of this view; false otherwise.

protected boolean isEntireBlockHighlighted ()

Check if border highlight is rendered.

protected void onAttachedToWindow ()

Stores a reference to the WorkspaceView containing this BlockView.

protected abstract void onBlockUpdated (int updateMask)

Called when the underlying block has been updated. The view implementation should override this method to appropriately update the view to reflect the new state.

Parameters
updateMask A bit mask denoting Block.UpdateState changes.

protected void onDetachedFromWindow ()

Clears the reference to any WorkspaceView.