Example usage for android.view MenuItem SHOW_AS_ACTION_ALWAYS

List of usage examples for android.view MenuItem SHOW_AS_ACTION_ALWAYS

Introduction

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

Prototype

int SHOW_AS_ACTION_ALWAYS

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

Click Source Link

Document

Always show this item as a button in an Action Bar.

Usage

From source file:com.quarterfull.newsAndroid.NewsDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.news_detail, menu);

    menuItem_Starred = menu.findItem(R.id.action_starred);
    menuItem_Read = menu.findItem(R.id.action_read);
    menuItem_PlayPodcast = menu.findItem(R.id.action_playPodcast);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    Set<String> selections = preferences.getStringSet("sp_news_detail_actionbar_icons", new HashSet<String>());
    String[] selected = selections.toArray(new String[] {});
    for (String selection : selected) {
        switch (selection) {
        case "open_in_browser":
            menu.findItem(R.id.action_openInBrowser).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            break;
        case "share":
            menu.findItem(R.id.action_ShareItem).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            break;
        case "podcast":
            menu.findItem(R.id.action_playPodcast).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            break;
        //case "tts":
        //    menu.findItem(R.id.action_tts).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        //    break;
        }/*from   ww  w. ja v  a2 s.c  o m*/
    }

    UpdateActionBarIcons();

    return true;
}

From source file:com.berniesanders.fieldthebern.MainActivity.java

private void handleOptionsMenu(Menu menu) {
    if (actionBarMenuAction != null) {

        if (actionBarMenuAction.isSearch()) {
            setupSearchMenu(menu);/*from   w w w. java 2s  .c  o m*/
        } else {
            menu.add(actionBarMenuAction.label()).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS)
                    .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            actionBarMenuAction.action().call();
                            return true;
                        }
                    });
        }
        //        // Inflate the options menu from XML
        //        MenuInflater inflater = getMenuInflater();
        //        inflater.inflate(R.menu.menu_cancel, menu);
    }
}

From source file:maimeng.yodian.app.client.android.chat.activity.ChatActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_chat_menu, menu);
    if ("hx_admin".equals(chatUser.getChatName())) {
        MENU_ID_CONTACT = 1001;/*w w w . j a v a  2s .  c o  m*/
        menu.add(0, MENU_ID_CONTACT, 0, "").setIcon(R.mipmap.ic_contact_path)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.mishiranu.dashchan.ui.navigator.page.PostsPage.java

@Override
public void onCreateOptionsMenu(Menu menu) {
    menu.add(0, OPTIONS_MENU_ADD_POST, 0, R.string.action_add_post).setIcon(obtainIcon(R.attr.actionAddPost))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, OPTIONS_MENU_SEARCH, 0, R.string.action_search);
    menu.add(0, OPTIONS_MENU_GALLERY, 0, R.string.action_gallery);
    menu.add(0, OPTIONS_MENU_SELECT, 0, R.string.action_select);
    menu.add(0, OPTIONS_MENU_REFRESH, 0, R.string.action_refresh).setIcon(obtainIcon(R.attr.actionRefresh))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.addSubMenu(0, OPTIONS_MENU_APPEARANCE, 0, R.string.action_appearance);
    SubMenu threadOptions = menu.addSubMenu(0, OPTIONS_MENU_THREAD_OPTIONS, 0, R.string.action_thread_options);
    menu.add(0, OPTIONS_MENU_ADD_TO_FAVORITES_TEXT, 0, R.string.action_add_to_favorites);
    menu.add(0, OPTIONS_MENU_REMOVE_FROM_FAVORITES_TEXT, 0, R.string.action_remove_from_favorites);
    menu.add(0, OPTIONS_MENU_ADD_TO_FAVORITES_ICON, 0, R.string.action_add_to_favorites)
            .setIcon(obtainIcon(R.attr.actionAddToFavorites)).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add(0, OPTIONS_MENU_REMOVE_FROM_FAVORITES_ICON, 0, R.string.action_remove_from_favorites)
            .setIcon(obtainIcon(R.attr.actionRemoveFromFavorites))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add(0, OPTIONS_MENU_OPEN_ORIGINAL_THREAD, 0, R.string.action_open_the_original);
    menu.add(0, OPTIONS_MENU_ARCHIVE, 0, R.string.action_archive_add);

    threadOptions.add(0, THREAD_OPTIONS_MENU_RELOAD, 0, R.string.action_reload);
    threadOptions.add(0, THREAD_OPTIONS_MENU_AUTO_REFRESH, 0, R.string.action_auto_refresh).setCheckable(true);
    threadOptions.add(0, THREAD_OPTIONS_MENU_HIDDEN_POSTS, 0, R.string.action_hidden_posts);
    threadOptions.add(0, THREAD_OPTIONS_MENU_CLEAR_DELETED, 0, R.string.action_clear_deleted);
    threadOptions.add(0, THREAD_OPTIONS_MENU_SUMMARY, 0, R.string.action_summary);
}

From source file:ren.qinc.markdowneditors.view.FolderManagerFragment.java

/**
 * ?ActionModeCallBack//w  w  w.j  av  a 2 s.  c om
 * Init action mode.
 */

private void initActionMode() {
    pasteModeCallback = new ActionModeCallback(getActivity(), R.color.colorPrimary) {
        @Override
        public void onDestroyActionModeCustom(ActionMode mode) {
            mActionMode = null;
        }

        @Override
        public boolean onCreateActionModeCustom(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            mode.setTitle("1");
            inflater.inflate(R.menu.menu_action_paste, menu);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            boolean flag = false;
            switch (item.getItemId()) {
            case R.id.action_paste:
                mPresenter.paste();
                flag = true;
                break;
            case R.id.action_create_folder:
                createFolder();
                flag = true;
                break;
            }
            return flag;
        }

    };
    editModeCallback = new ActionModeCallback(getActivity(), R.color.colorPrimary) {
        @Override
        public void onDestroyActionModeCustom(ActionMode mode) {
            mPresenter.closeEditMode();
            mActionMode = null;
        }

        @Override
        public boolean onCreateActionModeCustom(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            //                mode.setTitle("1");
            inflater.inflate(R.menu.menu_action_folder, menu);
            menu.findItem(R.id.action_edit).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_delete).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_copy).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.action_cut).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            boolean ret = false;
            switch (item.getItemId()) {
            case R.id.action_edit:
                rename();
                break;
            case R.id.action_delete:
                deleteFiles();
                break;
            case R.id.action_copy:
                coptFiles();
                break;
            case R.id.action_cut:
                cutFiles();
                break;
            }
            return ret;
        }

    };
}

From source file:com.freeme.filemanager.FileExplorerTabActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mViewPager.getCurrentItem() != 1) {
        menu.add(0, GlobalConsts.MENU_SEARCH, 1, getResources().getString(R.string.menu_item_search))
                .setIcon(R.drawable.ic_menu_searchs).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }//  w  w w . j a v  a 2 s  .co m
    if (!FeatureOption.CLEAN_BUTTON_SUPPORT) {
        menu.add(0, OPERATION_MENU_CLEAN, 1, getResources().getString(R.string.garbage_clean_title))
                .setIcon(R.drawable.ic_menu_clean).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Sets up the options menu when the menu button is pushed, dynamic
 * population of the station select menu
 *//*  w ww  .j a  va2  s  .  c o m*/
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    boolean result = super.onCreateOptionsMenu(menu);

    // Create and populate the band selection menu
    SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE, R.string.band_select);
    subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
    subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us);
    subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu);
    subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja);
    subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch);
    subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true);
    subMenu.getItem(mSelectedBand).setChecked(true);

    // Create and populate the speaker/headset selection menu if speaker supported
    if (context.getResources().getBoolean(R.bool.speaker_supported)) {
        subMenu = menu.addSubMenu(BASE_OPTION_MENU, OUTPUT_SOUND, Menu.NONE, R.string.output_select);
        subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_HEADSET, Menu.NONE, R.string.output_select_default);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_SPEAKER, Menu.NONE, R.string.output_select_loudspeaker);
        subMenu.setGroupCheckable(LOUDSPEAKER_SELECTION_MENU, true, true);
        subMenu.getItem(mSelectedOutput).setChecked(true);
    }

    // Create the station select menu
    subMenu = menu.addSubMenu(BASE_OPTION_MENU, STATION_SELECT, Menu.NONE, R.string.station_select);
    subMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // Dynamically populate the station select menu
    if (mMenuAdapter.isEmpty()) {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, false);
    } else {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, true);
        for (int i = 0; i < mMenuAdapter.getCount(); i++) {
            subMenu.add(STATION_SELECTION_MENU, STATION_SELECT_MENU_ITEMS + i, Menu.NONE,
                    mMenuAdapter.getItem(i).toString());
        }
    }
    return result;
}

From source file:de.kaidev.vertretungsplanapp.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem info = menu.add(0, 99, 0, "Info").setIcon(R.drawable.ic_info_outline_white_48dp);
    info.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    int i = mPager != null ? mPager.getCurrentItem() : 0;
    String s = i == 0 ? heute.getInfo() : morgen.getInfo();

    if (!s.isEmpty()) {
        for (String t : s.split("\n")) {
            if (!t.startsWith("Abwesende") && !t.startsWith("Blockierte")) {
                info.setIcon(R.drawable.ic_info_white_48dp);
                break;
            }//from  w w  w .j  a v a 2s. com
        }
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

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

    // Actions are always visible when showing as dialog
    if (mShowAsDialog) {
        for (int i = 0; i < menu.size(); i++) {
            menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }/*from  w ww.j a  v a  2 s . co m*/
    }

    final MenuItem searchMenu = menu.findItem(R.id.menu_search);
    mSearchView = (SearchView) searchMenu.getActionView();
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mState.currentSearch = query;
            mSearchView.clearFocus();
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    searchMenu.setOnActionExpandListener(new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            if (mIgnoreNextCollapse) {
                mIgnoreNextCollapse = false;
                return true;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }
    });

    mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (mIgnoreNextClose) {
                mIgnoreNextClose = false;
                return false;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return false;
        }
    });

    return true;
}

From source file:com.miz.mizuu.fragments.TmdbMovieDetailsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mMovie != null) {
        inflater.inflate(R.menu.tmdb_details, menu);

        if (MizLib.isTablet(mContext)) {
            menu.findItem(R.id.share).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            menu.findItem(R.id.checkIn).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }/*from ww w .j av  a 2 s.c  o  m*/

        if (!Trakt.hasTraktAccount(mContext))
            menu.findItem(R.id.checkIn).setVisible(false);
    }
}