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

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

    // set up intents and onClick listeners
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    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);

    callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent());
    searchMenuItem.setOnMenuItemClickListener(mSearchMenuItemClickListener);
    filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener);
    addContactOptionMenuItem.setIntent(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));

    return true;//from w  w w  .j a v a2  s.com
}

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

private void makeMenuItemVisible(Menu menu, int itemId, boolean visible) {
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        item.setVisible(visible);//from   w  w  w  .  j  ava  2  s  .  co m
    }
}

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

private void makeMenuItemEnabled(Menu menu, int itemId, boolean visible) {
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        item.setEnabled(visible);//from   w  ww .  jav a  2s .c o m
    }
}

From source file:com.paramonod.kikos.MainActivity.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.menu_main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_settings));
    System.out.println(searchView);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//  ww w  .j  a va  2s  . co  m
        public boolean onQueryTextSubmit(String query) {
            Menu menu = bottomNavigationView.getMenu();
            Menu mm = navigationView.getMenu();
            FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            Fragment f = null;
            System.out.println(fragments);
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment != null && fragment.isVisible())
                        f = fragment;
                    System.out.println(f);
                }
            }
            if (f instanceof CardContentFragment) {
                main.searchListener(query, 2);

            }
            if (f instanceof CategoryContentFragment) {
                main.searchListener(query, 1);

            }
            if (f instanceof MapViewFragment) {
                main.searchListener(query, 0);

            }
            if (f instanceof ListContentFragment) {
                main.searchListener(query, 3);
            }
            if (mm.getItem(1).isChecked()) {
                main.searchListener(query, 3);
            } else
                for (int i = 0; i < bottomNavigationView.getMenu().size(); i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (menuItem.isChecked()) {
                        main.searchListener(query, i);
                    }
                }

            return false;
        }

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

    return super.onCreateOptionsMenu(menu);
}

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

private void prepareOptionsMenuForDialerTab(Menu menu) {
    if (DEBUG) {/* ww  w.  j ava  2 s.c  o  m*/
        Log.d(TAG,
                "onPrepareOptionsMenu(dialer). swipe: " + mDuringSwipe + ", user tab click: " + mUserTabClick);
    }

    // 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
    filterOptionMenuItem.setVisible(false);
    addContactOptionMenuItem.setVisible(false);
    if (mDuringSwipe || mUserTabClick) {
        // During horizontal movement, the real ActionBar menu items are shown
        searchMenuItem.setVisible(true);
        callSettingsMenuItem.setVisible(true);
        // When there is a permanent menu key, there is no overflow icon on the right of
        // the action bar which would force the search menu item (if it is visible) to the
        // left.  This is the purpose of showing the emptyRightMenuItem.
        emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
    } else {
        // This is when the user is looking at the dialer pad.  In this case, the real
        // ActionBar is hidden and fake menu items are shown.
        // Except in landscape, in which case the real search menu item is shown.
        searchMenuItem.setVisible(ContactsUtils.isLandscape(this));
        // If a permanent menu key is available, then we need to show the call settings item
        // so that the call settings item can be invoked by the permanent menu key.
        callSettingsMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
        emptyRightMenuItem.setVisible(false);
    }
}

From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.findItem(R.id.action_save).setVisible(true);
    menu.findItem(R.id.action_reset).setVisible(true);
    menu.findItem(R.id.action_about).setVisible(true);
    return true;/*  w  ww.  j a  va2  s . c  o m*/
}

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu2, menu);

    //Select search item
    // final MenuItem menuItem = menu.findItem(R.id.menu_search);
    // menuItem.setVisible(true);

    // SearchView searchView = (SearchView) menuItem.getActionView();
    //  searchView.setQueryHint(this.getString(R.string.search));

    //((EditText) searchView.findViewById(R.id.search_src_text))
    //        .setHintTextColor(getResources().getColor(R.color.nliveo_white));
    //  searchView.setOnQueryTextListener(onQuerySearchView);

    menu.findItem(R.id.menu_add).setVisible(true);

    //mSearchCheck = false;
}

From source file:in.shick.diode.user.ProfileActivity.java

/**
 * Hide or show specific menu items as necessary in a user's profile.
 *///from   ww w  . ja va 2 s . c o  m
private void hideShowMenuItems(Menu theMenu) {
    // Only show the 'View saved posts' menu item when the user is logged in AND we're currently viewing their
    // profile.
    MenuItem savedMenuItem = theMenu.findItem(R.id.saved_menu_id);
    if (savedMenuItem != null) {
        if (mSettings.isLoggedIn() && mSettings.getUsername().equalsIgnoreCase(mUsername)) {
            savedMenuItem.setVisible(true);
        } else {
            savedMenuItem.setVisible(false);
        }
    }
}

From source file:pl.bcichecki.rms.client.android.fragments.OutboxMessagesListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override/*from  w  w w . j  av  a 2  s . co  m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return performAction(mode, item);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.fragment_outbox_messages_list_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                verifyMenuItems(mode.getMenu());
                for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) {
                    if (i != position) {
                        getListView().setItemChecked(i, false);
                    }
                }
            }
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        private void verifyMenuItems(Menu menu) {
            Message checkedMessage = getFirstCheckedItem();
            menu.findItem(R.id.fragment_outbox_messages_list_context_menu_archive)
                    .setVisible(!checkedMessage.isArchivedBySender());
        }
    });
}

From source file:pl.bcichecki.rms.client.android.fragments.InboxMessagesListFragment.java

private void setUpActionModeOnListItems() {
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override/*from   ww  w .java 2  s . co  m*/
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return performAction(mode, item);
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.fragment_inbox_messages_list_context, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            if (checked) {
                verifyMenuItems(mode.getMenu());
                for (int i = 0; i < getListView().getCheckedItemPositions().size(); i++) {
                    if (i != position) {
                        getListView().setItemChecked(i, false);
                    }
                }
            }
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        private void verifyMenuItems(Menu menu) {
            Message checkedMessage = getFirstCheckedItem();
            menu.findItem(R.id.fragment_inbox_messages_list_context_menu_archive)
                    .setVisible(!checkedMessage.isArchivedBySender());
        }
    });
}