FlyoutFragment

public class FlyoutFragment extends Fragment
implements BlockListUI

A drawer UI to show a set of Blocks one can drag into the workspace. The available blocks are provided by a BlocklyCategory, with this fragment displaying a single set of blocks. Set the blocks currently being shown by using setCurrentCategory(BlocklyCategory).

This Fragment is often used with CategorySelectorFragment which displays a list of tabs built from a root category. The fragments don't interact directly, but the FlyoutController can be used to handle the interaction between these components.

The behavior of the FlyoutFragment is configurable in xml. closeable and scrollOrientation attributes may be set to affect the display and behavior of this fragment.

For example:

 <fragment
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:blockly="http://schemas.android.com/apk/res-auto"
     android:name="com.google.blockly.FlyoutFragment"
     android:id="@+id/blockly_toolbox"
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
     blockly:closeable="false"
     blockly:scrollOrientation="vertical"
     />
 

When blockly:closeable is true, the drawer of blocks will hide in the closed state. The tabs will remain visible, providing the user a way to open the drawers.

blockly:scrollOrientation can be either horizontal or vertical, and affects only the block list. The tab scroll orientation is determined by the tabEdge.

Developers can further customize the flyout by providing their own FlyoutView in onCreateView(LayoutInflater, ViewGroup, Bundle).

Constant Summary

String ARG_CLOSEABLE
String ARG_SCROLL_ORIENTATION
float BLOCKS_BACKGROUND_LIGHTNESS
int DEFAULT_BLOCKS_BACKGROUND_ALPHA
int DEFAULT_BLOCKS_BACKGROUND_COLOR

Field Summary

protected int mBgAlpha
protected int mBgColor
protected final ColorDrawable mBgDrawable
protected boolean mCloseable
protected BlocklyController mController
protected View mFlyoutView
protected WorkspaceHelper mHelper
protected BlockRecyclerViewHelper mRecyclerHelper
protected int mScrollOrientation
protected FlyoutCallback mViewCallback

Public Constructor Summary

Public Method Summary

boolean
closeUi()
Attempts to close the blocks drawer.
BlocklyCategory
void
init(BlocklyController controller, FlyoutCallback callback)
Connects the FlyoutFragment to the application's drag and click handling.
boolean
boolean
isOpen()
View
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
void
onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState)
void
onSaveInstanceState(Bundle outState)
Saves closeable and scroll orientation state.
void
setCloseable(boolean closeable)
Sets whether this flyout should be allowed to close.
void
setCurrentCategory(BlocklyCategory category)
Sets the Flyout's current BlocklyCategory, including opening or closing the drawer.

Protected Method Summary

int
getBackgroundColor(int categoryColor)
Adjusts a color to make it appropriate for a background behind blocks of that color.
void
readArgumentsFromBundle(Bundle bundle)
Reads ARG_CLOSEABLE and ARG_SCROLL_ORIENTATION from the bundle.
void
updateCategoryColors(BlocklyCategory curCategory)
Sets the background color for the flyout's view based on the category.

Inherited Method Summary

Constants

protected static final String ARG_CLOSEABLE

Constant Value: "BlockDrawerFragment_closeable"

protected static final String ARG_SCROLL_ORIENTATION

Constant Value: "BlockDrawerFragment_scrollOrientation"

protected static final float BLOCKS_BACKGROUND_LIGHTNESS

Constant Value: 0.75

public static final int DEFAULT_BLOCKS_BACKGROUND_ALPHA

Constant Value: 187

public static final int DEFAULT_BLOCKS_BACKGROUND_COLOR

Constant Value: -3355444

Fields

protected int mBgAlpha

protected int mBgColor

protected final ColorDrawable mBgDrawable

protected boolean mCloseable

protected BlocklyController mController

protected View mFlyoutView

protected WorkspaceHelper mHelper

protected BlockRecyclerViewHelper mRecyclerHelper

protected int mScrollOrientation

protected FlyoutCallback mViewCallback

Public Constructors

public FlyoutFragment ()

Public Methods

public boolean closeUi ()

Attempts to close the blocks drawer.

Returns
  • True if an action was taken (the drawer is closeable and was previously open).

public BlocklyCategory getCurrentCategory ()

Returns
  • The currently set category.

public void init (BlocklyController controller, FlyoutCallback callback)

Connects the FlyoutFragment to the application's drag and click handling. It is called by setToolboxUi(BlockListUI, CategorySelectorUI) and should not be called by the application developer.

Parameters
controller
callback The callback that will handle user actions in the flyout.

public boolean isCloseable ()

Returns
  • True if this flyout is allowed to close, false otherwise.

public boolean isOpen ()

Returns
  • True if this fragment is currently visible, false otherwise.

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Parameters
inflater
container
savedInstanceState

public void onInflate (Context context, AttributeSet attrs, Bundle savedInstanceState)

Parameters
context
attrs
savedInstanceState

public void onSaveInstanceState (Bundle outState)

Saves closeable and scroll orientation state.

Parameters
outState Bundle to write.

public void setCloseable (boolean closeable)

Sets whether this flyout should be allowed to close.

Parameters
closeable True to allow it to close, false otherwise.

public void setCurrentCategory (BlocklyCategory category)

Sets the Flyout's current BlocklyCategory, including opening or closing the drawer. In closeable toolboxes, null category is equivalent to closing the drawer. Otherwise, the drawer will be rendered empty.

Parameters
category The BlocklyCategory with blocks to display.

Protected Methods

protected int getBackgroundColor (int categoryColor)

Adjusts a color to make it appropriate for a background behind blocks of that color.

Parameters
categoryColor The color to adjust for the background.
Returns
  • A color appropriate for the background behind blocks.

protected void readArgumentsFromBundle (Bundle bundle)

Reads ARG_CLOSEABLE and ARG_SCROLL_ORIENTATION from the bundle.

Parameters
bundle The Bundle to read from.

protected void updateCategoryColors (BlocklyCategory curCategory)

Sets the background color for the flyout's view based on the category.

Parameters
curCategory The category to set the color from or null.