Search in sources :

Example 1 with ActionProvider

use of androidx.core.view.ActionProvider in project GreenHouse by utsanjan.

the class ActivityChooserView method showPopupUnchecked.

void showPopupUnchecked(int maxActivityCount) {
    if (this.mAdapter.getDataModel() != null) {
        getViewTreeObserver().addOnGlobalLayoutListener(this.mOnGlobalLayoutListener);
        boolean defaultActivityButtonShown = this.mDefaultActivityButton.getVisibility() == 0;
        int activityCount = this.mAdapter.getActivityCount();
        int maxActivityCountOffset = defaultActivityButtonShown ? 1 : 0;
        if (maxActivityCount == Integer.MAX_VALUE || activityCount <= maxActivityCount + maxActivityCountOffset) {
            this.mAdapter.setShowFooterView(false);
            this.mAdapter.setMaxActivityCount(maxActivityCount);
        } else {
            this.mAdapter.setShowFooterView(true);
            this.mAdapter.setMaxActivityCount(maxActivityCount - 1);
        }
        ListPopupWindow popupWindow = getListPopupWindow();
        if (!popupWindow.isShowing()) {
            if (this.mIsSelectingDefaultActivity || !defaultActivityButtonShown) {
                this.mAdapter.setShowDefaultActivity(true, defaultActivityButtonShown);
            } else {
                this.mAdapter.setShowDefaultActivity(false, false);
            }
            int contentWidth = Math.min(this.mAdapter.measureContentWidth(), this.mListPopupMaxWidth);
            popupWindow.setContentWidth(contentWidth);
            popupWindow.show();
            ActionProvider actionProvider = this.mProvider;
            if (actionProvider != null) {
                actionProvider.subUiVisibilityChanged(true);
            }
            popupWindow.getListView().setContentDescription(getContext().getString(R.string.abc_activitychooserview_choose_application));
            popupWindow.getListView().setSelector(new ColorDrawable(0));
            return;
        }
        return;
    }
    throw new IllegalStateException("No data model. Did you call #setDataModel?");
}
Also used : ActionProvider(androidx.core.view.ActionProvider) ColorDrawable(android.graphics.drawable.ColorDrawable)

Example 2 with ActionProvider

use of androidx.core.view.ActionProvider in project GreenHouse by utsanjan.

the class MenuItemImpl method invoke.

public boolean invoke() {
    MenuItem.OnMenuItemClickListener onMenuItemClickListener = this.mClickListener;
    if (onMenuItemClickListener != null && onMenuItemClickListener.onMenuItemClick(this)) {
        return true;
    }
    MenuBuilder menuBuilder = this.mMenu;
    if (menuBuilder.dispatchMenuItemSelected(menuBuilder, this)) {
        return true;
    }
    Runnable runnable = this.mItemCallback;
    if (runnable != null) {
        runnable.run();
        return true;
    }
    if (this.mIntent != null) {
        try {
            this.mMenu.getContext().startActivity(this.mIntent);
            return true;
        } catch (ActivityNotFoundException e) {
            Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
        }
    }
    ActionProvider actionProvider = this.mActionProvider;
    return actionProvider != null && actionProvider.onPerformDefaultAction();
}
Also used : ActionProvider(androidx.core.view.ActionProvider) ActivityNotFoundException(android.content.ActivityNotFoundException) SupportMenuItem(androidx.core.internal.view.SupportMenuItem) MenuItem(android.view.MenuItem)

Example 3 with ActionProvider

use of androidx.core.view.ActionProvider in project sesl-appcompat by OneUIProject.

the class ActionMenuPresenter method updateMenuView.

@Override
public void updateMenuView(boolean cleared) {
    super.updateMenuView(cleared);
    if (mMenuView != null) {
        ((View) mMenuView).requestLayout();
    }
    if (mMenu != null) {
        final ArrayList<MenuItemImpl> actionItems = mMenu.getActionItems();
        final int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            final ActionProvider provider = actionItems.get(i).getSupportActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }
    final ArrayList<MenuItemImpl> nonActionItems = mMenu != null ? mMenu.getNonActionItems() : null;
    boolean hasOverflow = false;
    if (mReserveOverflow && nonActionItems != null) {
        final int count = nonActionItems.size();
        if (count == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else {
            hasOverflow = count > 0;
        }
    }
    if (hasOverflow) {
        if (mOverflowButton == null) {
            mOverflowButton = new OverflowMenuButton(mSystemContext);
            mOverflowButton.setId(R.id.sesl_action_bar_overflow_button);
        }
        ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
        if (parent != mMenuView) {
            if (parent != null) {
                parent.removeView(mOverflowButton);
            }
            ActionMenuView menuView = (ActionMenuView) mMenuView;
            if (menuView != null) {
                menuView.addView(mOverflowButton, menuView.generateOverflowButtonLayoutParams());
            }
        }
    } else if (mOverflowButton != null && mOverflowButton.getParent() == mMenuView) {
        if (mMenuView != null) {
            ((ViewGroup) mMenuView).removeView(mOverflowButton);
        }
        if (isOverflowMenuShowing()) {
            hideOverflowMenu();
        }
    }
    if (mOverflowButton != null && mMenuView != null) {
        mOverflowButton.setBadgeText(((ActionMenuView) mMenuView).getOverflowBadgeText(), ((ActionMenuView) mMenuView).getSumOfDigitsInBadges());
    }
    if ((mOverflowButton == null || mOverflowButton.getVisibility() != View.GONE) && isOverflowMenuShowing()) {
        hideOverflowMenu();
    }
    if (mMenuView != null) {
        ((ActionMenuView) mMenuView).setOverflowReserved(mReserveOverflow);
    }
}
Also used : MenuItemImpl(androidx.appcompat.view.menu.MenuItemImpl) ActionProvider(androidx.core.view.ActionProvider) ViewGroup(android.view.ViewGroup) MenuView(androidx.appcompat.view.menu.MenuView) View(android.view.View) TextView(android.widget.TextView) ActionMenuItemView(androidx.appcompat.view.menu.ActionMenuItemView) SuppressLint(android.annotation.SuppressLint)

Example 4 with ActionProvider

use of androidx.core.view.ActionProvider in project GreenHouse by utsanjan.

the class ActionMenuPresenter method updateMenuView.

// androidx.appcompat.view.menu.BaseMenuPresenter, androidx.appcompat.view.menu.MenuPresenter
@Override
public void updateMenuView(boolean cleared) {
    super.updateMenuView(cleared);
    ((View) this.mMenuView).requestLayout();
    if (this.mMenu != null) {
        ArrayList<MenuItemImpl> actionItems = this.mMenu.getActionItems();
        int count = actionItems.size();
        for (int i = 0; i < count; i++) {
            ActionProvider provider = actionItems.get(i).getSupportActionProvider();
            if (provider != null) {
                provider.setSubUiVisibilityListener(this);
            }
        }
    }
    ArrayList<MenuItemImpl> nonActionItems = this.mMenu != null ? this.mMenu.getNonActionItems() : null;
    boolean hasOverflow = false;
    if (this.mReserveOverflow && nonActionItems != null) {
        int count2 = nonActionItems.size();
        hasOverflow = false;
        if (count2 == 1) {
            hasOverflow = !nonActionItems.get(0).isActionViewExpanded();
        } else if (count2 > 0) {
            hasOverflow = true;
        }
    }
    if (hasOverflow) {
        if (this.mOverflowButton == null) {
            this.mOverflowButton = new OverflowMenuButton(this.mSystemContext);
        }
        ViewGroup parent = (ViewGroup) this.mOverflowButton.getParent();
        if (parent != this.mMenuView) {
            if (parent != null) {
                parent.removeView(this.mOverflowButton);
            }
            ActionMenuView menuView = (ActionMenuView) this.mMenuView;
            menuView.addView(this.mOverflowButton, menuView.generateOverflowButtonLayoutParams());
        }
    } else {
        OverflowMenuButton overflowMenuButton = this.mOverflowButton;
        if (overflowMenuButton != null && overflowMenuButton.getParent() == this.mMenuView) {
            ((ViewGroup) this.mMenuView).removeView(this.mOverflowButton);
        }
    }
    ((ActionMenuView) this.mMenuView).setOverflowReserved(this.mReserveOverflow);
}
Also used : MenuItemImpl(androidx.appcompat.view.menu.MenuItemImpl) ActionProvider(androidx.core.view.ActionProvider) ViewGroup(android.view.ViewGroup) ActionMenuView(androidx.appcompat.widget.ActionMenuView) MenuView(androidx.appcompat.view.menu.MenuView) ActionMenuView(androidx.appcompat.widget.ActionMenuView) View(android.view.View) ActionMenuItemView(androidx.appcompat.view.menu.ActionMenuItemView)

Example 5 with ActionProvider

use of androidx.core.view.ActionProvider in project GreenHouse by utsanjan.

the class MenuBuilder method performItemAction.

public boolean performItemAction(MenuItem item, MenuPresenter preferredPresenter, int flags) {
    MenuItemImpl itemImpl = (MenuItemImpl) item;
    if (itemImpl == null || !itemImpl.isEnabled()) {
        return false;
    }
    boolean invoked = itemImpl.invoke();
    ActionProvider provider = itemImpl.getSupportActionProvider();
    boolean providerHasSubMenu = provider != null && provider.hasSubMenu();
    if (itemImpl.hasCollapsibleActionView()) {
        invoked |= itemImpl.expandActionView();
        if (invoked) {
            close(true);
        }
    } else if (itemImpl.hasSubMenu() || providerHasSubMenu) {
        if ((flags & 4) == 0) {
            close(false);
        }
        if (!itemImpl.hasSubMenu()) {
            itemImpl.setSubMenu(new SubMenuBuilder(getContext(), this, itemImpl));
        }
        SubMenuBuilder subMenu = (SubMenuBuilder) itemImpl.getSubMenu();
        if (providerHasSubMenu) {
            provider.onPrepareSubMenu(subMenu);
        }
        invoked |= dispatchSubMenuSelected(subMenu, preferredPresenter);
        if (!invoked) {
            close(true);
        }
    } else if ((flags & 1) == 0) {
        close(true);
    }
    return invoked;
}
Also used : ActionProvider(androidx.core.view.ActionProvider)

Aggregations

ActionProvider (androidx.core.view.ActionProvider)10 View (android.view.View)4 MenuView (androidx.appcompat.view.menu.MenuView)4 ViewGroup (android.view.ViewGroup)3 ActionMenuItemView (androidx.appcompat.view.menu.ActionMenuItemView)3 MenuItemImpl (androidx.appcompat.view.menu.MenuItemImpl)3 SuppressLint (android.annotation.SuppressLint)2 TextView (android.widget.TextView)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MenuItem (android.view.MenuItem)1 ActionMenuView (androidx.appcompat.widget.ActionMenuView)1 SupportMenuItem (androidx.core.internal.view.SupportMenuItem)1