Example usage for android.view MenuItem setShowAsAction

List of usage examples for android.view MenuItem setShowAsAction

Introduction

In this page you can find the example usage for android.view MenuItem setShowAsAction.

Prototype

public void setShowAsAction(int actionEnum);

Source Link

Document

Sets how this item should display in the presence of an Action Bar.

Usage

From source file:tkj.android.homecontrol.mythmote.MythMote.java

/**
 * Called to create the options menu once.
 *///from   ww w . j  ava 2s.com
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);

    // create reconnect menu item
    MenuItem menuItem = menu.add(0, RECONNECT_ID, 0, R.string.reconnect_str)
            .setIcon(R.drawable.ic_menu_refresh);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }

    // create settings menu item
    menuItem = menu.add(0, SETTINGS_ID, 0, R.string.settings_menu_str)
            .setIcon(android.R.drawable.ic_menu_preferences);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    // create keyboard input menu item
    menuItem = menu.add(0, KEYBOARD_INPUT_ID, 0, R.string.keyboard_input_str)
            .setIcon(R.drawable.ic_notification_ime_default);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    // create select location menu item
    menuItem = menu.add(0, SELECTLOCATION_ID, 0, R.string.selected_location_str)
            .setIcon(R.drawable.ic_menu_home);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    //create wake on lan menu item
    menuItem = menu.add(0, SENDWOL_ID, 0, R.string.send_wol_str).setIcon(R.drawable.ic_menu_sun);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    }
    //menu.add(0, SENDWOL_RE_ID, 0, R.string.send_wol_re_str);
    //menu.add(0, SENDWOL_PJ_ID, 0, R.string.send_wol_pj_str);

    //add donate button if enabled
    if (sShowDonateMenuItem) {

    }

    // return results
    return result;
}

From source file:com.concentricsky.android.khanacademy.app.VideoListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mainMenu = menu;//from www  .j  a v a2s .com
    mainMenuDelegate.onCreateOptionsMenu(menu);

    MenuItem downloadItem = mainMenu.add(0, DOWNLOAD_ITEM_ID, mainMenu.size(), R.string.menu_item_download_all);
    downloadItem.setIcon(R.drawable.av_download);
    downloadItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}

From source file:org.alfresco.mobile.android.application.fragments.node.details.NodeDetailsActionMode.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    if (selectedItems.isEmpty() || selectedItems.size() > 1) {
        return;/*from  w  ww  .j  a  v  a 2  s  .c  o  m*/
    }

    MenuItem mi;
    Node node = getCurrentItem();
    if (node == null) {
        return;
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict && ConfigurableActionHelper
                .isVisible(getActivity(), getAccount(), ConfigurableActionHelper.ACTION_NODE_DOWNLOAD)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_download, Menu.FIRST, R.string.download);
            mi.setIcon(R.drawable.ic_download_light);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion() && ConfigurableActionHelper.isVisible(getActivity(),
                getAccount(), getSession(), node, ConfigurableActionHelper.ACTION_NODE_UPDATE)) {
            mi = menu.add(Menu.NONE, R.id.menu_action_update, Menu.FIRST + 130, R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(SessionUtils.getSession(activity) instanceof CloudSession) && ConfigurableActionHelper
                .isVisible(getActivity(), getAccount(), ConfigurableActionHelper.ACTION_NODE_REVIEW)) {
            mi = menu.add(Menu.NONE, R.id.menu_workflow_add, Menu.FIRST + 500, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_EDIT)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_edit, Menu.FIRST + 50, R.string.edit);
        mi.setIcon(R.drawable.ic_properties);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (ConfigurableActionHelper.isVisible(getActivity(), getAccount(), getSession(), node,
            ConfigurableActionHelper.ACTION_NODE_DELETE)) {
        mi = menu.add(Menu.NONE, R.id.menu_action_delete, Menu.FIRST + 1000, R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    if (notificationsFragment != null && menu.findItem(R.id.menu_notifications) == null) {
        final MenuItem notificationItem = menu.add(Menu.NONE, R.id.menu_notifications, 2,
                R.string.menu_notifications);
        notificationItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        notificationItem.setActionView(R.layout.actionbar_item_notifications);

        final TextView notificationTextView = (TextView) notificationItem.getActionView()
                .findViewById(R.id.textView);

        int count = notificationsFragment.getUnreadCount();

        notificationTextView.setText(String.valueOf(count));

        if (count > 0) {
            notificationTextView/*from  w w  w  .j  a  v  a2  s .  c  o  m*/
                    .setBackgroundResource(AttrUtil.getResourceId(this, R.attr.notificationsItemBackground));
        } else {
            notificationTextView.setBackgroundResource(R.drawable.notifications_read_background);

        }

        notificationItem.getActionView().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onOptionsItemSelected(notificationItem);
            }
        });
    }

    if (!KlyphFlags.IS_PRO_VERSION && menu.findItem(R.id.menu_buy_pro) == null) {
        menu.add(Menu.NONE, R.id.menu_buy_pro, 2, R.string.menu_buy_pro)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (menu.findItem(R.id.menu_faq) == null) {
        menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.alfresco.mobile.android.application.accounts.fragment.AccountDetailsFragment.java

public void getMenu(Menu menu) {
    MenuItem mi;

    if (acc.getActivation() == null) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_EDIT,
                Menu.FIRST + MenuActionItem.MENU_ACCOUNT_EDIT,
                String.format(getString(R.string.account_edit_hint), acc.getDescription()));
        mi.setIcon(R.drawable.ic_edit);/*  w  w w.j  a  v a  2 s .com*/
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_DELETE,
            Menu.FIRST + MenuActionItem.MENU_ACCOUNT_DELETE,
            String.format(getString(R.string.account_delete_hint), acc.getDescription()));
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

From source file:com.cyeam.cInterphone.ui.CInterphone.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*w ww  .  j  a  v  a 2s . c o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);

    MenuItem m;
    // m = menu.add(0, TEST1, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_call);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);
    //
    // m = menu.add(0, TEST2, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_gallery);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, CONFIGURE_MENU_ITEM, 0, R.string.menu_settings);
    m.setIcon(android.R.drawable.ic_menu_preferences);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, ABOUT_MENU_ITEM, 0, R.string.menu_about);
    m.setIcon(android.R.drawable.ic_menu_info_details);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, EXIT_MENU_ITEM, 0, R.string.menu_exit);
    m.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    return result;
}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

private void initToolbar() {

    Resources res = getResources();

    mToolbar.setNavigationIcon(R.drawable.ic_drawer_raw);
    mToolbar.setNavigationContentDescription(R.string.tab);

    Menu menu = mToolbar.getMenu();
    List<MenuItemInfo> menuItemInfos = MenuFactory.getInstance(this).getToolbarIcon();
    for (MenuItemInfo item : menuItemInfos) {
        MenuItem menuItem = menu.add(MenuDef.GROUP_TOOLBAR, item.getItemId(), Menu.NONE, item.getTitleResId());
        menuItem.setIcon(MenuManager.makeToolbarNormalIcon(res, item.getIconResId()));

        //menuItem.setShortcut()
        menuItem.setOnMenuItemClickListener(this);
        menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }//from  w  ww  . j a  va 2  s  . co  m
    MenuItem menuItem = menu.add(MenuDef.GROUP_TOOLBAR, R.id.m_menu, Menu.NONE, getString(R.string.more_menu));
    menuItem.setIcon(R.drawable.ic_right_menu);
    menuItem.setOnMenuItemClickListener(this);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    tabManager = new TabManager(this);
}

From source file:org.alfresco.mobile.android.application.fragments.properties.DetailsFragment.java

public static void getMenu(AlfrescoSession session, Activity activity, Menu menu, Node node,
        boolean actionMode) {
    MenuItem mi;

    if (node == null) {
        return;//from www .ja  v  a  2 s . com
    }
    if (node instanceof NodeSyncPlaceHolder) {
        return;
    }

    boolean isRestrict = node.hasAspect(ContentModel.ASPECT_RESTRICTABLE);

    if (node.isDocument()) {
        if (((Document) node).getContentStreamLength() > 0 && !isRestrict) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_DOWNLOAD, Menu.FIRST + MenuActionItem.MENU_DOWNLOAD,
                    R.string.download);
            mi.setIcon(R.drawable.ic_download_dark);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (((Document) node).isLatestVersion()
                && ((DocumentImpl) node).hasAllowableAction(Action.CAN_SET_CONTENT_STREAM.value())) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_UPDATE, Menu.FIRST + MenuActionItem.MENU_UPDATE,
                    R.string.update);
            mi.setIcon(R.drawable.ic_upload);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        if (!(session instanceof CloudSession)) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_WORKFLOW_ADD,
                    Menu.FIRST + MenuActionItem.MENU_WORKFLOW_ADD, R.string.process_start_review);
            mi.setIcon(R.drawable.ic_start_review);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }

    if (session.getServiceRegistry().getDocumentFolderService().getPermissions(node).canEdit()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT,
                R.string.edit);
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (session.getServiceRegistry().getDocumentFolderService().getPermissions(node).canDelete()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DELETE, 1000 + MenuActionItem.MENU_DELETE,
                R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!DisplayUtils.hasCentralPane(activity)) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_COMMENT, Menu.FIRST + MenuActionItem.MENU_COMMENT,
                R.string.comments);
        mi.setIcon(R.drawable.ic_comment);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        if (node.isDocument()) {
            mi = menu.add(Menu.NONE, MenuActionItem.MENU_VERSION_HISTORY,
                    Menu.FIRST + MenuActionItem.MENU_VERSION_HISTORY, R.string.version_history);
            mi.setIcon(R.drawable.ic_menu_recent_history);
            mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }

        mi = menu.add(Menu.NONE, MenuActionItem.MENU_TAGS, Menu.FIRST + MenuActionItem.MENU_TAGS,
                R.string.tags);
        mi.setIcon(R.drawable.mime_tags);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.workflow.task.TaskDetailsFragment.java

public void getMenu(Menu menu) {
    MenuItem mi;

    String processDefinitionKey = WorkflowUtils.getKeyFromProcessDefinitionId(processDefinitionId);

    if (endedAt == null && processDefinitionKey.startsWith(WorkflowModel.KEY_PREFIX_ACTIVITI)) {
        mi = menu.add(Menu.NONE, R.id.menu_process_details, Menu.FIRST, R.string.process_diagram);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }/*from  www.ja  v  a2 s  .  c o  m*/

    mi = menu.add(Menu.NONE, R.id.menu_process_history, Menu.FIRST + 1, R.string.tasks_history);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    if (currentTask == null || endedAt != null) {
        return;
    }

    // unclaim : I unassign myself (generally created by a pooled process)
    if (currentTask.getAssigneeIdentifier() != null
            && WorkflowModel.FAMILY_PROCESS_POOLED_REVIEW.contains(processDefinitionKey)) {
        mi = menu.add(Menu.NONE, R.id.menu_task_unclaim, Menu.FIRST + 2, R.string.task_unclaim);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }
    // reassign : I have a task and I decide I dont want to be responsible
    // anymore of this task so I reassign to a specific person
    else if (currentTask.getAssigneeIdentifier() != null) {
        mi = menu.add(Menu.NONE, R.id.menu_task_reassign, Menu.FIRST + 3, R.string.task_reassign);
        mi.setIcon(R.drawable.ic_reassign);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
    // claim : I assign to me an unassigned task (created by a pooled
    // process)
    else if ((currentTask.getAssigneeIdentifier() == null
            && WorkflowModel.FAMILY_PROCESS_POOLED_REVIEW.contains(processDefinitionKey))
            || "unclaimed".equals(state)) {
        mi = menu.add(Menu.NONE, R.id.menu_task_claim, Menu.FIRST + 4, R.string.task_claim);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    }
}

From source file:org.alfresco.mobile.android.application.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (sessionState == SESSION_ERROR && getCurrentSession() == null) {
        MenuItem mi = menu.add(Menu.NONE, R.id.menu_account_reload, Menu.FIRST, R.string.retry_account_loading);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT | MenuItem.SHOW_AS_ACTION_ALWAYS);
    }//from  ww  w .j ava 2s  .  c  o m

    return super.onCreateOptionsMenu(menu);
}