Example usage for android.view Menu findItem

List of usage examples for android.view Menu findItem

Introduction

In this page you can find the example usage for android.view Menu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:com.android.contacts.activities.DialtactsActivity.java

private void prepareOptionsMenuInSearchMode(Menu menu) {
    // get references to menu items
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);

    // prepare the menu items
    searchMenuItem.setVisible(false);//from  w w  w . j a  v a  2 s  . com
    filterOptionMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
    addContactOptionMenuItem.setVisible(false);
    callSettingsMenuItem.setVisible(false);
    emptyRightMenuItem.setVisible(false);
}

From source file:com.android.contacts.activities.DialtactsActivity.java

private void prepareOptionsMenuForCallLogTab(Menu menu) {
    // get references to menu items
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);

    // prepare the menu items
    searchMenuItem.setVisible(true);// ww  w.j  a va 2 s.  c  om
    filterOptionMenuItem.setVisible(false);
    addContactOptionMenuItem.setVisible(false);
    callSettingsMenuItem.setVisible(true);
    emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
}

From source file:com.android.contacts.activities.DialtactsActivity.java

private void prepareOptionsMenuForFavoritesTab(Menu menu) {
    // get references to menu items
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);

    // prepare the menu items
    searchMenuItem.setVisible(true);/*from ww w.  j  a  va2  s.  c  om*/
    filterOptionMenuItem.setVisible(true);
    addContactOptionMenuItem.setVisible(true);
    callSettingsMenuItem.setVisible(true);
    emptyRightMenuItem.setVisible(false);
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

void prepareNowPlayingMenu(final Menu menu) {
    final boolean isStreaming = mApp.isStreamActive();
    final MPD mpd = mApp.oMPDAsyncHelper.oMPD;
    final MPDStatus mpdStatus = mpd.getStatus();

    // Reminder : never disable buttons that are shown as actionbar actions here
    if (mpd.isConnected()) {
        if (menu.findItem(CONNECT) != null) {
            menu.removeItem(CONNECT);//from w  w  w . j  a v  a 2  s.com
        }
    } else {
        if (menu.findItem(CONNECT) == null) {
            menu.add(0, CONNECT, 0, R.string.connect);
        }
    }

    final MenuItem saveItem = menu.findItem(R.id.PLM_Save);
    final MenuItem clearItem = menu.findItem(R.id.PLM_Clear);
    if (!mIsDualPaneMode && mNowPlayingPager != null && mNowPlayingPager.getCurrentItem() == 0) {
        saveItem.setVisible(false);
        clearItem.setVisible(false);
    } else {
        saveItem.setVisible(true);
        clearItem.setVisible(true);
    }

    /** If in streamingMode or persistentNotification don't allow a checkbox in the menu. */
    final MenuItem notificationItem = menu.findItem(R.id.GMM_ShowNotification);
    if (notificationItem != null) {
        if (isStreaming || mApp.isNotificationPersistent()) {
            notificationItem.setVisible(false);
        } else {
            notificationItem.setVisible(true);
        }

        setMenuChecked(notificationItem, mApp.isNotificationActive());
    }

    setMenuChecked(menu.findItem(R.id.GMM_Stream), isStreaming);
    setMenuChecked(menu.findItem(R.id.GMM_Single), mpdStatus.isSingle());
    setMenuChecked(menu.findItem(R.id.GMM_Consume), mpdStatus.isConsume());
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.card_browser, menu);
    mSaveSearchItem = menu.findItem(R.id.action_save_search);
    mSaveSearchItem.setVisible(false); //the searchview's query always starts empty.
    mMySearchesItem = menu.findItem(R.id.action_list_my_searches);
    JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
    mMySearchesItem.setVisible(savedFiltersObj != null && savedFiltersObj.length() > 0);
    mSearchItem = menu.findItem(R.id.action_search);
    MenuItemCompat.setOnActionExpandListener(mSearchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override//w w  w . j  a  v a 2 s . co  m
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // SearchView doesn't support empty queries so we always reset the search when collapsing
            mSearchTerms = "";
            mSearchView.setQuery(mSearchTerms, false);
            searchCards();
            return true;
        }
    });
    mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            mSaveSearchItem.setVisible(!TextUtils.isEmpty(newText));
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            onSearch();
            mSearchView.clearFocus();
            return true;
        }
    });
    mSearchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Provide SearchView with the previous search terms
            mSearchView.setQuery(mSearchTerms, false);
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:com.openerp.addons.messages.Message.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_fragment_message, menu);
    // Associate searchable configuration with the SearchView
    searchView = (SearchView) menu.findItem(R.id.menu_message_search).getActionView();
    Bundle bundle = getArguments();/*from   w w w .ja v a  2 s  .  c o  m*/
    if (bundle != null && bundle.containsKey("group_id")) {
        MenuItem compose = menu.findItem(R.id.menu_message_compose);
        compose.setVisible(false);
    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {

    super.onPrepareOptionsMenu(menu);

    if (!application.isLoaded())
        return false; // Wallet not loaded just yet

    final Resources res = getResources();
    final String externalStorageState = Environment.getExternalStorageState();

    boolean writable = Environment.MEDIA_MOUNTED.equals(externalStorageState);
    boolean readOnly = Environment.MEDIA_MOUNTED_READ_ONLY.equals(externalStorageState);

    menu.findItem(R.id.wallet_options_exchange_rates)
            .setVisible(res.getBoolean(R.bool.show_exchange_rates_option));
    menu.findItem(R.id.wallet_options_restore_wallet).setEnabled(writable || readOnly);
    menu.findItem(R.id.wallet_options_backup_wallet).setEnabled(writable);
    menu.findItem(R.id.wallet_options_export)
            .setEnabled(writable && txListAdapter != null && !txListAdapter.transactions.isEmpty());

    menu.findItem(R.id.wallet_options_encrypt_keys)
            .setTitle(application.getWallet().isEncrypted() ? R.string.wallet_options_encrypt_keys_change
                    : R.string.wallet_options_encrypt_keys_set);

    return true;/*www .  ja v a  2s .  c o  m*/

}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener,
        final int trackType) {
    if (player == null) {
        return;//from www  .j a  va 2  s . co  m
    }
    String[] tracks = player.getTracks(trackType);
    if (tracks == null) {
        return;
    }
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item))
                    || onTrackItemClick(item, trackType);
        }
    });
    Menu menu = popup.getMenu();
    // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0)
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.DISABLED_TRACK + ID_OFFSET, Menu.NONE, R.string.off);
    if (tracks.length == 1 && TextUtils.isEmpty(tracks[0])) {
        menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on);
    } else {
        for (int i = 0; i < tracks.length; i++) {
            menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, tracks[i]);
        }
    }
    menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
    menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true);
}

From source file:com.irccloud.android.activity.ImageViewerActivity.java

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

    if (getIntent() != null && getIntent().getDataString() != null) {
        Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http")));
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,
                getIntent().getDataString().replace(getResources().getString(R.string.IMAGE_SCHEME), "http"));
        intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
        intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

        MenuItem shareItem = menu.findItem(R.id.action_share);
        ShareActionProviderHax share = (ShareActionProviderHax) MenuItemCompat.getActionProvider(shareItem);
        share.onShareActionProviderSubVisibilityChangedListener = this;
        share.setShareIntent(intent);//w  w w .j  a va 2 s . co m
    }
    return true;
}