Example usage for android.support.v4.view MenuItemCompat setShowAsAction

List of usage examples for android.support.v4.view MenuItemCompat setShowAsAction

Introduction

In this page you can find the example usage for android.support.v4.view MenuItemCompat setShowAsAction.

Prototype

public static boolean setShowAsAction(MenuItem item, int actionEnum) 

Source Link

Document

Call MenuItem#setShowAsAction(int) MenuItem.setShowAsAction() .

Usage

From source file:net.wequick.small.webkit.WebActivity.java

private void addMenuItem(HashMap<String, String> content, boolean isMore) {
    MenuItem menuItem;// www .  j  a va  2s . c o  m
    do {
        String type = content.get("type");
        // Text without icon
        if (type == null) {
            String title = content.get("title");
            menuItem = mOptionsMenu.add(0, 0, 0, title);
            break;
        }

        Drawable icon = null; // TODO: Export interface to get user defined icon
        if (icon != null) {
            menuItem = mOptionsMenu.add(0, 0, 0, null).setIcon(icon);
            break;
        }

        // Android system icon
        int iconRes = android.R.drawable.ic_menu_info_details;
        if (type.equals("share")) {
            iconRes = android.R.drawable.ic_menu_share;
        } else if (type.equals("add")) {
            iconRes = android.R.drawable.ic_menu_add;
        } else if (type.equals("more")) {
            iconRes = android.R.drawable.ic_menu_more;
        } // TODO: Add more

        menuItem = mOptionsMenu.add(0, 0, 0, null).setIcon(iconRes);
    } while (false);

    int showType = isMore ? MenuItemCompat.SHOW_AS_ACTION_NEVER : MenuItemCompat.SHOW_AS_ACTION_ALWAYS;
    MenuItemCompat.setShowAsAction(menuItem, showType);
    final String onclick = content.get("onclick");
    if (onclick != null) {
        menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (mWebView != null) {
                    mWebView.loadJs(onclick);
                }
                return true;
            }
        });
    }
}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

/*******************************************************************/

@Override/*from  www  .  ja v  a 2  s  .  com*/
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);
    MenuItem item;
    item = menu.add(ContextMenu.NONE, MENU_SEARCH, ContextMenu.NONE, android.R.string.search_go)
            .setIcon(R.drawable.ic_search_24dp).setAlphabeticShortcut(SearchManager.MENU_KEY);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    item = menu.add(ContextMenu.NONE, MENU_PICKER, ContextMenu.NONE, R.string.menu_picker)
            .setIcon(R.drawable.ic_import_24dp);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    item = menu.add(ContextMenu.NONE, MENU_VACUUM, ContextMenu.NONE, R.string.menu_vacuum)
            .setIcon(android.R.drawable.ic_menu_crop);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_NEVER);
    return result;
}

From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem menuItem_Star = menu.add(0, MENU_ITEM_STAR, menu.size(), R.string.description_star);
    MenuItemCompat.setShowAsAction(menuItem_Star, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    if (mIsStarred) {
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star_on);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, checked");
    } else {/*from   w  ww .  j ava 2  s. com*/
        menu.getItem(MENU_ITEM_STAR).setIcon(R.drawable.ic_menu_star);
        menu.getItem(MENU_ITEM_STAR).setTitle("Favorite checkbox, not checked");
    }

    MenuItem menuItem_Refresh = menu.add(1, MENU_ITEM_REFRESH, menu.size(), R.string.description_refresh);
    MenuItemCompat.setShowAsAction(menuItem_Refresh, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    menu.getItem(MENU_ITEM_REFRESH).setIcon(R.drawable.ic_menu_refresh);

    if (mRefreshState) {
        startRefreshAnimation();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:net.potterpcs.recipebook.RecipeEditor.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.editormenu, menu);

    // Set up the action bar for devices that have it
    MenuItemCompat.setShowAsAction(menu.findItem(R.id.editormenusave),
            MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    MenuItemCompat.setShowAsAction(menu.findItem(R.id.editormenuhelp), MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;/*from w  w  w  . j  a va  2 s .co m*/
}

From source file:edu.cmu.cylab.starslinger.view.PickRecipientsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem iAdd = menu.add(0, MENU_CONTACTINVITE, 0, R.string.menu_SelectShareApp)
            .setIcon(R.drawable.ic_action_add_person);

    MenuItemCompat.setShowAsAction(iAdd, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    MenuItem iHelp = menu.add(0, MENU_HELP, 0, R.string.menu_Help).setIcon(R.drawable.ic_action_help);
    MenuItemCompat.setShowAsAction(iHelp, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);

    menu.add(0, MENU_CONTACTINVITE, 0, R.string.menu_SelectShareApp).setIcon(R.drawable.ic_action_add_person);
    menu.add(0, MENU_FEEDBACK, 0, R.string.menu_sendFeedback).setIcon(android.R.drawable.ic_menu_send);

    return true;//from  ww  w.j a v  a2 s.  co  m
}

From source file:website.openeng.anki.Reviewer.java

@SuppressLint("NewApi")
@Override/*w ww  .java 2  s.c  o m*/
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.reviewer, menu);
    Resources res = getResources();
    if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) {
        menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_unmark_note)
                .setIcon(R.drawable.ic_star_white_24dp);
    } else {
        menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_mark_note)
                .setIcon(R.drawable.ic_star_outline_white_24dp);
    }
    if (colIsOpen() && getCol().undoAvailable()) {
        menu.findItem(R.id.action_undo).setEnabled(true).getIcon().setAlpha(Themes.ALPHA_ICON_ENABLED_LIGHT);
    } else {
        menu.findItem(R.id.action_undo).setEnabled(false).getIcon().setAlpha(Themes.ALPHA_ICON_DISABLED_LIGHT);
    }
    if (mPrefWhiteboard) {
        // Don't force showing mark icon when whiteboard enabled
        // TODO: allow user to customize which icons are force-shown
        MenuItemCompat.setShowAsAction(menu.findItem(R.id.action_mark_card),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        // Check if we can forceably squeeze in 3 items into the action bar, if not hide "show whiteboard"
        if (CompatHelper.getSdkVersion() >= 14 && !ViewConfiguration.get(this).hasPermanentMenuKey()) {
            // Android 4.x device with overflow menu in the action bar and small screen can't
            // support forcing 2 extra items into the action bar
            Display display = getWindowManager().getDefaultDisplay();
            DisplayMetrics outMetrics = new DisplayMetrics();
            display.getMetrics(outMetrics);
            float density = getResources().getDisplayMetrics().density;
            float dpWidth = outMetrics.widthPixels / density;
            if (dpWidth < 360) {
                menu.findItem(R.id.action_hide_whiteboard).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }
        }
        // Configure the whiteboard related items in the action bar
        menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.disable_whiteboard);
        menu.findItem(R.id.action_hide_whiteboard).setVisible(true);
        menu.findItem(R.id.action_clear_whiteboard).setVisible(true);

        Drawable whiteboardIcon = getResources().getDrawable(R.drawable.ic_gesture_white_24dp);
        if (mShowWhiteboard) {
            whiteboardIcon.setAlpha(255);
            menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon);
            menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.hide_whiteboard);
        } else {
            whiteboardIcon.setAlpha(77);
            menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon);
            menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.show_whiteboard);
        }
    } else {
        menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.enable_whiteboard);
    }
    if (!CompatHelper.isHoneycomb() && !mDisableClipboard) {
        menu.findItem(R.id.action_search_dictionary).setVisible(true)
                .setEnabled(!(mPrefWhiteboard && mShowWhiteboard))
                .setTitle(clipboardHasText() ? Lookup.getSearchStringTitle()
                        : res.getString(R.string.menu_select));
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:net.potterpcs.recipebook.RecipeFlipbook.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.flippermenu, menu);
    // Show items on the action bar if we have one
    MenuItemCompat.setShowAsAction(menu.findItem(R.id.switchtolist), MenuItem.SHOW_AS_ACTION_IF_ROOM);
    MenuItemCompat.setShowAsAction(menu.findItem(R.id.flipbookhelp), MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;//from   w  w  w  .jav  a2s  .  c  o m
}

From source file:com.ichi2.anki.Reviewer.java

@SuppressLint("NewApi")
@Override//w  w  w.  j a v a  2 s  . co  m
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.reviewer, menu);
    Resources res = getResources();
    if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) {
        menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_unmark_note)
                .setIcon(R.drawable.ic_star_white_24dp);
    } else {
        menu.findItem(R.id.action_mark_card).setTitle(R.string.menu_mark_note)
                .setIcon(R.drawable.ic_star_outline_white_24dp);
    }
    if (colIsOpen() && getCol().undoAvailable()) {
        menu.findItem(R.id.action_undo).setEnabled(true).getIcon().setAlpha(Themes.ALPHA_ICON_ENABLED_LIGHT);
    } else {
        menu.findItem(R.id.action_undo).setEnabled(false).getIcon().setAlpha(Themes.ALPHA_ICON_DISABLED_LIGHT);
    }
    if (mPrefWhiteboard) {
        // Don't force showing mark icon when whiteboard enabled
        // TODO: allow user to customize which icons are force-shown
        MenuItemCompat.setShowAsAction(menu.findItem(R.id.action_mark_card),
                MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        // Check if we can forceably squeeze in 3 items into the action bar, if not hide "show whiteboard"
        if (CompatHelper.getSdkVersion() >= 14 && !ViewConfiguration.get(this).hasPermanentMenuKey()) {
            // Android 4.x device with overflow menu in the action bar and small screen can't
            // support forcing 2 extra items into the action bar
            Display display = getWindowManager().getDefaultDisplay();
            DisplayMetrics outMetrics = new DisplayMetrics();
            display.getMetrics(outMetrics);
            float density = getResources().getDisplayMetrics().density;
            float dpWidth = outMetrics.widthPixels / density;
            if (dpWidth < 360) {
                menu.findItem(R.id.action_hide_whiteboard).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }
        }
        // Configure the whiteboard related items in the action bar
        menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.disable_whiteboard);
        menu.findItem(R.id.action_hide_whiteboard).setVisible(true);
        menu.findItem(R.id.action_clear_whiteboard).setVisible(true);

        Drawable whiteboardIcon = getResources().getDrawable(R.drawable.ic_gesture_white_24dp);
        if (mShowWhiteboard) {
            whiteboardIcon.setAlpha(255);
            menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon);
            menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.hide_whiteboard);
        } else {
            whiteboardIcon.setAlpha(77);
            menu.findItem(R.id.action_hide_whiteboard).setIcon(whiteboardIcon);
            menu.findItem(R.id.action_hide_whiteboard).setTitle(R.string.show_whiteboard);
        }
    } else {
        menu.findItem(R.id.action_enable_whiteboard).setTitle(R.string.enable_whiteboard);
    }
    if (!CompatHelper.isHoneycomb() && !mDisableClipboard) {
        menu.findItem(R.id.action_search_dictionary).setVisible(true)
                .setEnabled(!(mPrefWhiteboard && mShowWhiteboard))
                .setTitle(clipboardHasText() ? Lookup.getSearchStringTitle()
                        : res.getString(R.string.menu_select));
    }
    if (getCol().getDecks().isDyn(getParentDid())) {
        menu.findItem(R.id.action_open_deck_options).setVisible(false);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.jefftharris.passwdsafe.sync.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);

    for (int id : new int[] { R.id.menu_add, R.id.menu_about, R.id.menu_logs }) {
        MenuItem item = menu.findItem(id);
        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    }//w  ww  .j a va 2s  .c  o  m
    return true;
}

From source file:org.mythdroid.activities.MDActivity.java

/**
 * Add a frontend chooser to the options menu (or action bar on >= 3.0)
 * @param menu menu to add to/*  ww  w .j  av  a2 s  .c  o  m*/
 */
protected void addFrontendChooser(Menu menu) {

    final MenuItem item = menu.add(Menu.NONE, MENU_FRONTEND, Menu.NONE, R.string.setCurFe)
            .setIcon(drawable.ic_menu_upload_you_tube);

    if (MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS)) {

        ActionView vi = (ActionView) LayoutInflater.from(this).inflate(R.layout.frontend_indicator, null);

        vi.setFocusable(true);

        vi.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                nextActivity = null;
                showDialog(FRONTEND_CHOOSER);
            }
        });

        frontendIndicator = (TextView) vi.findViewById(R.id.actionItemText);
        updateFrontendIndicator();

        MenuItemCompat.setActionView(item, vi);

    }

}