Java Code Examples for com.google.android.flexbox.FlexboxLayout#getFlexItemCount()
The following examples show how to use
com.google.android.flexbox.FlexboxLayout#getFlexItemCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OverlayController.java From talkback with Apache License 2.0 | 6 votes |
@VisibleForTesting void updateMenuContent(List<MenuItem> newMenuItems) { menuItems = newMenuItems; firstMenuItemIndex = 0; FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons); int maxItemsPerPage = menuButtonsLayout.getFlexItemCount(); View nextArrow = menuOverlay.findViewById(R.id.next_arrow_button); if (maxItemsPerPage < menuItems.size()) { nextArrow.setVisibility(View.VISIBLE); lastMenuItemIndex = maxItemsPerPage; } else { nextArrow.setVisibility(View.INVISIBLE); lastMenuItemIndex = menuItems.size(); } menuOverlay.findViewById(R.id.previous_arrow_button).setVisibility(View.INVISIBLE); updateVisibleMenuButtons(); }
Example 2
Source File: OverlayController.java From talkback with Apache License 2.0 | 6 votes |
/** * Adds extra empty items to the bottom row of the menu overlay so spacing works. We want the * FlexboxLayout to justify items (i.e. center all rows that have the maximum number of items and * left-align the last row if it has fewer than the maximum number of items), but the closest * option is to center-align, so we artificially left-align the bottom row. */ @VisibleForTesting void fillRemainingSpaceForMenuOverlay() { FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons); int numActiveButtons = menuButtonsLayout.getFlexItemCount(); int numRows = menuButtonsLayout.getFlexLines().size(); if (numRows > 1) { int maxItemsPerRow = menuButtonsLayout.getFlexLines().get(0).getItemCountNotGone(); int numButtonsInLastRow = numActiveButtons % maxItemsPerRow; if (numButtonsInLastRow > 0) { for (int i = numButtonsInLastRow; i < maxItemsPerRow; i++) { menuButtonsLayout.addView(new MenuButton(menuOverlay.getContext())); } } } else if (numRows == 1) { // TODO: Investigate if we can resize the menu horizontally when there's only one // row. // Hide the view until the spacing is figured out. menuOverlay.getRootView().setVisibility(View.INVISIBLE); fillOutSingleRow(menuOverlay, menuButtonsLayout); } }
Example 3
Source File: OverlayController.java From talkback with Apache License 2.0 | 6 votes |
private void updateVisibleMenuButtons() { FlexboxLayout menuButtonsLayout = (FlexboxLayout) menuOverlay.findViewById(R.id.menu_buttons); int numNewMenuItems = lastMenuItemIndex - firstMenuItemIndex; int numMenuButtons = menuButtonsLayout.getFlexItemCount(); for (int i = 0; i < numMenuButtons; i++) { MenuButton button = (MenuButton) menuButtonsLayout.getFlexItemAt(i); if (i < numNewMenuItems) { // Replace existing menu buttons with new ones. MenuItem newMenuItem = menuItems.get(firstMenuItemIndex + i); setIconTextAndOnClickListenerForMenuButton(button, newMenuItem); } else if (button != null) { // Clear now-unused buttons. button.clearButton(); } } }