Example usage for android.widget FrameLayout setEnabled

List of usage examples for android.widget FrameLayout setEnabled

Introduction

In this page you can find the example usage for android.widget FrameLayout setEnabled.

Prototype

@RemotableViewMethod
public void setEnabled(boolean enabled) 

Source Link

Document

Set the enabled state of this view.

Usage

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

/**
 * Prepares and shows the specified menu immediately.
 *
 * @param menu the menu to show/*from  w  w w. j  a v  a  2 s . c  o  m*/
 */
private void showMenu(@NonNull MenuBuilder menu) {
    final LayoutInflater inflater = LayoutInflater.from(mContext);
    final MenuAdapter adapter = new MenuAdapter(menu, inflater, mOverflowOnly);

    // Apply "force show icon" setting. There are 3 cases:
    // (1) This is the top level menu and icon spacing is forced. Add spacing.
    // (2) This is a submenu. Add spacing if any of the visible menu items has an icon.
    // (3) This is the top level menu and icon spacing isn't forced. Do not add spacing.
    if (!isShowing() && mForceShowIcon) {
        // Case 1
        adapter.setForceShowIcon(true);
    } else if (isShowing()) {
        // Case 2
        adapter.setForceShowIcon(MenuPopup.shouldPreserveIconSpacing(menu));
    }
    // Case 3: Else, don't allow spacing for icons (default behavior; do nothing).

    final int menuWidth = measureIndividualMenuWidth(adapter, null, mContext, mMenuMaxWidth);
    final MenuPopupWindow popupWindow = createPopupWindow();
    popupWindow.setAdapter(adapter);
    popupWindow.setWidth(menuWidth);
    popupWindow.setDropDownGravity(mDropDownGravity);

    final CascadingMenuInfo parentInfo;
    final View parentView;
    if (mShowingMenus.size() > 0) {
        parentInfo = mShowingMenus.get(mShowingMenus.size() - 1);
        parentView = findParentViewForSubmenu(parentInfo, menu);
    } else {
        parentInfo = null;
        parentView = null;
    }

    if (parentView != null) {
        // This menu is a cascading submenu anchored to a parent view.
        popupWindow.setTouchModal(false);
        popupWindow.setEnterTransition(null);

        final @HorizPosition int nextMenuPosition = getNextMenuPosition(menuWidth);
        final boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT;
        mLastPosition = nextMenuPosition;

        final int[] tempLocation = new int[2];

        // This popup menu will be positioned relative to the top-left edge
        // of the view representing its parent menu.
        parentView.getLocationInWindow(tempLocation);
        final int parentOffsetLeft = parentInfo.window.getHorizontalOffset() + tempLocation[0];
        final int parentOffsetTop = parentInfo.window.getVerticalOffset() + tempLocation[1];

        // By now, mDropDownGravity is the resolved absolute gravity, so
        // this should work in both LTR and RTL.
        final int x;
        if ((mDropDownGravity & Gravity.RIGHT) == Gravity.RIGHT) {
            if (showOnRight) {
                x = parentOffsetLeft + menuWidth;
            } else {
                x = parentOffsetLeft - parentView.getWidth();
            }
        } else {
            if (showOnRight) {
                x = parentOffsetLeft + parentView.getWidth();
            } else {
                x = parentOffsetLeft - menuWidth;
            }
        }

        popupWindow.setHorizontalOffset(x);

        final int y = parentOffsetTop;
        popupWindow.setVerticalOffset(y);
    } else {
        if (mHasXOffset) {
            popupWindow.setHorizontalOffset(mXOffset);
        }
        if (mHasYOffset) {
            popupWindow.setVerticalOffset(mYOffset);
        }
        final Rect epicenterBounds = getEpicenterBounds();
        popupWindow.setEpicenterBounds(epicenterBounds);
    }

    final CascadingMenuInfo menuInfo = new CascadingMenuInfo(popupWindow, menu, mLastPosition);
    mShowingMenus.add(menuInfo);

    popupWindow.show();

    // If this is the root menu, show the title if requested.
    if (parentInfo == null && mShowTitle && menu.getHeaderTitle() != null) {
        final ListView listView = popupWindow.getListView();
        final FrameLayout titleItemView = (FrameLayout) inflater
                .inflate(R.layout.abc_popup_menu_header_item_layout, listView, false);
        final TextView titleView = (TextView) titleItemView.findViewById(android.R.id.title);
        titleItemView.setEnabled(false);
        titleView.setText(menu.getHeaderTitle());
        listView.addHeaderView(titleItemView, null, false);

        // Show again to update the title.
        popupWindow.show();
    }
}