Java Code Examples for android.support.v7.view.menu.MenuPresenter

The following are top voted examples for showing how to use android.support.v7.view.menu.MenuPresenter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NightOwl   File: ToolbarHandler.java   View source code 6 votes vote down vote up
@Override
public void draw(@NonNull View view, @NonNull Object value) {
    Toolbar toolbar = (Toolbar) view;
    int themeId = (int) value;
    try {
        ActionMenuView actionMenuView = (ActionMenuView) sActionMenuViewField.get(toolbar);
        if ( actionMenuView == null ){
            toolbar.getContext().setTheme(themeId);
        } else {
            MenuPresenter presenter = (MenuPresenter) sPresenterField.get(actionMenuView);
            Context context = (Context) sContextField.get(presenter);
            context.setTheme(themeId);
        }

    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    toolbar.setPopupTheme((Integer) value);
}
 
Example 2
Project: boohee_v5.6   File: AppCompatDelegateImplV7.java   View source code 5 votes vote down vote up
MenuView getListMenuView(MenuPresenter.Callback cb) {
    if (this.menu == null) {
        return null;
    }
    if (this.listMenuPresenter == null) {
        this.listMenuPresenter = new ListMenuPresenter(this.listPresenterContext, R.layout.abc_list_menu_item_layout);
        this.listMenuPresenter.setCallback(cb);
        this.menu.addMenuPresenter(this.listMenuPresenter);
    }
    return this.listMenuPresenter.getMenuView(this.decorView);
}
 
Example 3
Project: boohee_v5.6   File: ToolbarWidgetWrapper.java   View source code 5 votes vote down vote up
public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    if (this.mActionMenuPresenter == null) {
        this.mActionMenuPresenter = new ActionMenuPresenter(this.mToolbar.getContext());
        this.mActionMenuPresenter.setId(R.id.action_menu_presenter);
    }
    this.mActionMenuPresenter.setCallback(cb);
    this.mToolbar.setMenu((MenuBuilder) menu, this.mActionMenuPresenter);
}
 
Example 4
Project: Carbon   File: Menu.java   View source code 5 votes vote down vote up
public boolean performItemAction(android.view.MenuItem item, MenuPresenter preferredPresenter, int flags) {
    MenuItem itemImpl = (MenuItem) item;

    if (itemImpl == null || !itemImpl.isEnabled()) {
        return false;
    }

    itemImpl.performAction();

    return true;
}
 
Example 5
Project: boohee_v5.6   File: ActionBarOverlayLayout.java   View source code 4 votes vote down vote up
public void setMenu(Menu menu, MenuPresenter.Callback cb) {
    pullChildren();
    this.mDecorToolbar.setMenu(menu, cb);
}
 
Example 6
Project: boohee_v5.6   File: ToolbarWidgetWrapper.java   View source code 4 votes vote down vote up
public void setMenuCallbacks(MenuPresenter.Callback actionMenuPresenterCallback, MenuBuilder.Callback menuBuilderCallback) {
    this.mToolbar.setMenuCallbacks(actionMenuPresenterCallback, menuBuilderCallback);
}
 
Example 7
Project: app-theme-engine-master   File: ATEMenuPresenterCallback.java   View source code 4 votes vote down vote up
public ATEMenuPresenterCallback(Activity context, String key, MenuPresenter.Callback parentCb, Toolbar toolbar) {
    mContext = context;
    mKey = key;
    mParentCb = parentCb;
    mToolbar = toolbar;
}
 
Example 8
Project: Superuser-UI   File: ToolbarContentTintHelper.java   View source code 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar, @Nullable Menu menu, final @ColorInt int toolbarContentColor, final @ColorInt int titleTextColor, final @ColorInt int subtitleTextColor, final @ColorInt int menuWidgetColor) {
    if (toolbar == null) return;

    if (menu == null) {
        menu = toolbar.getMenu();
    }

    toolbar.setTitleTextColor(titleTextColor);
    toolbar.setSubtitleTextColor(subtitleTextColor);

    if (toolbar.getNavigationIcon() != null) {
        // Tint the toolbar navigation icon (e.g. back, drawer, etc.)
        toolbar.setNavigationIcon(TintHelper.createTintedDrawable(toolbar.getNavigationIcon(), toolbarContentColor));
    }

    InternalToolbarContentTintUtil.tintMenu(toolbar, menu, toolbarContentColor);
    InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor);

    if (context instanceof Activity) {
        InternalToolbarContentTintUtil.setOverflowButtonColor((Activity) context, toolbarContentColor);
    }

    try {
        // Tint immediate overflow menu items
        final Field menuField = Toolbar.class.getDeclaredField("mMenuBuilderCallback");
        menuField.setAccessible(true);
        final Field presenterField = Toolbar.class.getDeclaredField("mActionMenuPresenterCallback");
        presenterField.setAccessible(true);
        final Field menuViewField = Toolbar.class.getDeclaredField("mMenuView");
        menuViewField.setAccessible(true);

        final MenuPresenter.Callback currentPresenterCb = (MenuPresenter.Callback) presenterField.get(toolbar);
        if (!(currentPresenterCb instanceof ATHMenuPresenterCallback)) {
            final ATHMenuPresenterCallback newPresenterCb = new ATHMenuPresenterCallback(context, menuWidgetColor, currentPresenterCb, toolbar);
            final MenuBuilder.Callback currentMenuCb = (MenuBuilder.Callback) menuField.get(toolbar);
            toolbar.setMenuCallbacks(newPresenterCb, currentMenuCb);
            ActionMenuView menuView = (ActionMenuView) menuViewField.get(toolbar);
            if (menuView != null)
                menuView.setMenuCallbacks(newPresenterCb, currentMenuCb);
        }

        // OnMenuItemClickListener to tint submenu items
        final Field menuItemClickListener = Toolbar.class.getDeclaredField("mOnMenuItemClickListener");
        menuItemClickListener.setAccessible(true);
        Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener.get(toolbar);
        if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) {
            final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context, menuWidgetColor, currentClickListener, toolbar);
            toolbar.setOnMenuItemClickListener(newClickListener);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 9
Project: Superuser-UI   File: ToolbarContentTintHelper.java   View source code 4 votes vote down vote up
public ATHMenuPresenterCallback(Context context, final @ColorInt int color, MenuPresenter.Callback parentCb, Toolbar toolbar) {
    mContext = context;
    mColor = color;
    mParentCb = parentCb;
    mToolbar = toolbar;
}