Example usage for android.view MenuItem SHOW_AS_ACTION_IF_ROOM

List of usage examples for android.view MenuItem SHOW_AS_ACTION_IF_ROOM

Introduction

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

Prototype

int SHOW_AS_ACTION_IF_ROOM

To view the source code for android.view MenuItem SHOW_AS_ACTION_IF_ROOM.

Click Source Link

Document

Show this item as a button in an Action Bar if the system decides there is room for it.

Usage

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    /*/*  w ww . j a  va  2s.c  o  m*/
     * int MENU_ACTION_WITH_TEXT=0;
     * 
     * //Temp- for backward compatibility with OS 3 features
     * 
     * if(!usingListSpinner()){ try{ //setting the value equivalent to
     * desired expression
     * //MenuItem.SHOW_AS_ACTION_IF_ROOM|MenuItem.SHOW_AS_ACTION_WITH_TEXT
     * java.lang.reflect.Field
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_IF_ROOM");
     * MENU_ACTION_WITH_TEXT=field.getInt(MenuItem.class);
     * field=MenuItem.class.getDeclaredField("SHOW_AS_ACTION_WITH_TEXT");
     * MENU_ACTION_WITH_TEXT|=field.getInt(MenuItem.class); }catch(Exception
     * e){ //reset value irrespective of cause MENU_ACTION_WITH_TEXT=0; }
     * 
     * }
     */

    // Add menu option for auto adding items from string array in intent
    // extra if they exist
    if (mExtraItems != null) {
        menu.add(0, MENU_INSERT_FROM_EXTRAS, 0, R.string.menu_auto_add)
                .setIcon(android.R.drawable.ic_menu_upload);
    }

    MenuItem item = null;

    View searchView = mItemsView.getSearchView();
    if (searchView != null) {
        item = menu.add(0, MENU_SEARCH_ADD, 0, R.string.menu_search_add);
        MenuItemCompat.setActionView(item, searchView);
        MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    mAddPanel.setVisibility(searchView == null ? View.VISIBLE : View.GONE);

    item = menu.add(0, MENU_SORT_LIST, 0, R.string.menu_sort_list)
            .setIcon(android.R.drawable.ic_menu_sort_alphabetically);
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    if (mListSortActionProvider == null) {
        mListSortActionProvider = new ListSortActionProvider(this);
    }
    MenuItemCompat.setActionProvider(item, mListSortActionProvider);

    // Standard menu

    // tentatively moved "new list" to drawer
    //item = menu.add(0, MENU_NEW_LIST, 0, R.string.new_list)
    //      .setIcon(R.drawable.ic_menu_add_list).setShortcut('0', 'n');
    // MenuCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    item = menu.add(0, MENU_CLEAN_UP_LIST, 0, R.string.clean_up_list).setIcon(R.drawable.ic_menu_cleanup)
            .setShortcut('1', 'c');
    MenuItemCompat.setShowAsAction(item, MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(0, MENU_PICK_ITEMS, 0, R.string.menu_pick_items).setIcon(android.R.drawable.ic_menu_add)
            .setShortcut('2', 'p').
            // tentatively replaced by buttons in drawer.
            setVisible(false);

    /*
     * menu.add(0, MENU_SHARE, 0, R.string.share)
     * .setIcon(R.drawable.contact_share001a) .setShortcut('4', 's');
     */

    menu.add(0, MENU_THEME, 0, R.string.theme).setIcon(android.R.drawable.ic_menu_manage).setShortcut('3', 't');

    menu.add(0, MENU_PREFERENCES, 0, R.string.preferences).setIcon(android.R.drawable.ic_menu_preferences)
            .setShortcut('4', 'p');

    menu.add(0, MENU_RENAME_LIST, 0, R.string.rename_list).setIcon(android.R.drawable.ic_menu_edit)
            .setShortcut('5', 'r');

    menu.add(0, MENU_DELETE_LIST, 0, R.string.delete_list).setIcon(android.R.drawable.ic_menu_delete);

    menu.add(0, MENU_SEND, 0, R.string.send).setIcon(android.R.drawable.ic_menu_send).setShortcut('7', 's');

    if (addLocationAlertPossible()) {
        menu.add(0, MENU_ADD_LOCATION_ALERT, 0, R.string.shopping_add_alert)
                .setIcon(android.R.drawable.ic_menu_mylocation).setShortcut('8', 'l');
    }

    menu.add(0, MENU_MARK_ALL_ITEMS, 0, R.string.mark_all_items).setIcon(android.R.drawable.ic_menu_agenda)
            .setShortcut('9', 'm');

    menu.add(0, MENU_UNMARK_ALL_ITEMS, 0, R.string.unmark_all_items);

    menu.add(0, MENU_SYNC_WEAR, 0, R.string.sync_wear);

    // Add distribution menu items last.
    mDistribution.onCreateOptionsMenu(menu);

    // NOTE:
    // Dynamically added menu items are included in onPrepareOptionsMenu()
    // instead of here!
    // (Explanation see there.)

    return true;
}

From source file:com.android.gallery3d.app.PhotoPage.java

private void updatePanoramaUI(boolean isPanorama360) {
    Menu menu = mActionBar.getMenu();

    // it could be null if onCreateActionBar has not been called yet
    if (menu == null) {
        return;//from   w ww . j  a  v  a  2s .c o m
    }

    MenuExecutor.updateMenuForPanorama(menu, isPanorama360, isPanorama360);

    if (isPanorama360) {
        MenuItem item = menu.findItem(R.id.action_share);
        if (item != null) {
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
            item.setTitle(mActivity.getResources().getString(R.string.share_as_photo));
        }
    } else if ((mCurrentPhoto.getSupportedOperations() & MediaObject.SUPPORT_SHARE) != 0) {
        MenuItem item = menu.findItem(R.id.action_share);
        if (item != null) {
            item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            item.setTitle(mActivity.getResources().getString(R.string.share));
        }
    }
}

From source file:knayi.delevadriver.AvaliableJobDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem item = menu.add("Icon");
    item.setIcon(R.drawable.deleva_dispatcher_white_noeffects_04);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return super.onCreateOptionsMenu(menu);
}