Example usage for android.view Menu getItem

List of usage examples for android.view Menu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:com.pdftron.pdf.controls.UserBookmarkDialogFragment.java

public void onShowPopupMenu(final int position, View anchor) {
    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    Menu menu = popupMenu.getMenu();

    final UserBookmarkItem bItem = mBookmarkViewAdapter.getItem(position);
    String[] menuItems = getResources().getStringArray(R.array.user_bookmark_dialog_context_menu);
    menu.add(Menu.NONE, CONTEXT_MENU_EDIT_ITEM, CONTEXT_MENU_EDIT_ITEM, menuItems[CONTEXT_MENU_EDIT_ITEM]);
    menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM,
            menuItems[CONTEXT_MENU_DELETE_ITEM]);
    menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL, menuItems[CONTEXT_MENU_DELETE_ALL]);
    MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
        @Override/*  w  ww  . j  a va 2s.c om*/
        public boolean onMenuItemClick(MenuItem item) {
            onPopupItemSelected(item, position);
            return true;
        }
    };
    menu.getItem(CONTEXT_MENU_EDIT_ITEM).setOnMenuItemClickListener(listener);
    menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener);
    menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener);
    popupMenu.show();
}

From source file:com.mplayer_remote.ServerList.java

/**
 * Metoda wywoywana przez system Android w reakcji na kade wybranie przycisku menu urzdzenia. 
 * Suy do dynamicznego wprowadzania zmian w menu aktywnoci, tu za wyczenie pozycji odpowiedzialnych za edycje i usuwanie danych serwera w przypadku gdy w pamici urzdzenia nie s zapisane, adne informacje o serwerach SSH.   
 * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu)
 *//*  w ww . ja v  a 2s.  co m*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (serverListArrayList.size() > 0) {
        menu.getItem(2).setEnabled(true);
        menu.getItem(3).setEnabled(true);
    }

    return true;
}

From source file:com.klinker.android.twitter.activities.profile_viewer.ProfilePager.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    final int MENU_TWEET = 0;
    final int MENU_FOLLOW = 1;
    final int MENU_UNFOLLOW = 2;
    final int MENU_FAVORITE = 3;
    final int MENU_UNFAVORITE = 4;
    final int MENU_BLOCK = 5;
    final int MENU_UNBLOCK = 6;
    final int MENU_ADD_LIST = 7;
    final int MENU_DM = 8;
    final int MENU_CHANGE_PICTURE = 9;
    final int MENU_CHANGE_BANNER = 10;
    final int MENU_CHANGE_BIO = 11;
    final int MENU_MUTE = 12;
    final int MENU_UNMUTE = 13;
    final int MENU_MUTE_RT = 14;
    final int MENU_UNMUTE_RT = 15;

    if (isMyProfile) {
        menu.getItem(MENU_TWEET).setVisible(false);
        menu.getItem(MENU_FOLLOW).setVisible(false);
        menu.getItem(MENU_UNFOLLOW).setVisible(false);
        menu.getItem(MENU_BLOCK).setVisible(false);
        menu.getItem(MENU_UNBLOCK).setVisible(false);
        menu.getItem(MENU_ADD_LIST).setVisible(false);
        menu.getItem(MENU_DM).setVisible(false);
        menu.getItem(MENU_FAVORITE).setVisible(false);
        menu.getItem(MENU_UNFAVORITE).setVisible(false);
        menu.getItem(MENU_MUTE).setVisible(false);
        menu.getItem(MENU_UNMUTE).setVisible(false);
        menu.getItem(MENU_MUTE_RT).setVisible(false);
        menu.getItem(MENU_UNMUTE_RT).setVisible(false);
    } else {//from  w ww  .j a  v a  2  s .  c om
        if (isFollowingSet) {
            if (isFollowing) {
                menu.getItem(MENU_FOLLOW).setVisible(false);
            } else {
                menu.getItem(MENU_UNFOLLOW).setVisible(false);
            }

            if (isBlocking) {
                menu.getItem(MENU_BLOCK).setVisible(false);
            } else {
                menu.getItem(MENU_UNBLOCK).setVisible(false);
            }

            if (isFavorite) {
                menu.getItem(MENU_FAVORITE).setVisible(false);
            } else {
                menu.getItem(MENU_UNFAVORITE).setVisible(false);
            }

            if (isMuted) {
                menu.getItem(MENU_MUTE).setVisible(false);
            } else {
                menu.getItem(MENU_UNMUTE).setVisible(false);
            }

            if (isRTMuted) {
                menu.getItem(MENU_MUTE_RT).setVisible(false);
            } else {
                menu.getItem(MENU_UNMUTE_RT).setVisible(false);
            }
        } else {
            menu.getItem(MENU_FOLLOW).setVisible(false);
            menu.getItem(MENU_UNFOLLOW).setVisible(false);
            menu.getItem(MENU_FAVORITE).setVisible(false);
            menu.getItem(MENU_UNFAVORITE).setVisible(false);
            menu.getItem(MENU_BLOCK).setVisible(false);
            menu.getItem(MENU_UNBLOCK).setVisible(false);
            menu.getItem(MENU_MUTE).setVisible(false);
            menu.getItem(MENU_UNMUTE).setVisible(false);
            menu.getItem(MENU_MUTE_RT).setVisible(false);
            menu.getItem(MENU_UNMUTE_RT).setVisible(false);
        }

        menu.getItem(MENU_CHANGE_BIO).setVisible(false);
        menu.getItem(MENU_CHANGE_BANNER).setVisible(false);
        menu.getItem(MENU_CHANGE_PICTURE).setVisible(false);
    }

    return true;
}

From source file:com.hijacker.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MainActivity.menu = menu;//from   w ww. ja v  a2  s . c o  m
    getMenuInflater().inflate(R.menu.toolbar, menu);
    if (airOnStartup) {
        menu.getItem(1).setIcon(R.drawable.stop_drawable);
        menu.getItem(1).setTitle(R.string.stop);
    }
    menu.getItem(3).setEnabled(false);
    return true;
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

private void StyleMenuButtons(Menu m) {
    // Find each menu item and set its text colour
    for (int i = 0; i < m.size(); i++) {
        m.getItem(i).setTitle(createMenuItem(m.getItem(i).getTitle().toString()));
    }//from   ww w. j a  v  a 2s. c o m
}

From source file:com.jins_meme.bridge.MainActivity.java

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

    //debug Log.d("DEBUG", "onPrepareOptionsMenu");

    String barTitle;//w w  w . j a  v a 2 s . c om
    if (getSupportActionBar() != null && getSupportActionBar().getTitle() != null) {
        barTitle = getSupportActionBar().getTitle().toString();

        Log.d("DEBUG", "Title = " + barTitle);

        if (barTitle.length() > 1) {
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                String title = item.getTitle().toString();

                if (title.contains(" (for Eye VDJ)")) {
                    title = title.substring(0, title.indexOf(" (for Eye VDJ)"));
                }

                if (barTitle.contains(title)) {
                    item.setVisible(false);
                } else {
                    item.setVisible(true);
                }
            }
        } else {
            for (int i = 0; i < menu.size(); i++) {
                menu.getItem(i).setVisible(true);
            }
        }
    }

    return true;
}

From source file:cz.urbangaming.galgs.GAlg.java

public boolean onCreateOptionsMenu(Menu menu) {
    //TODO: OMG, put this in a separate, non blocking task!!!
    Log.d(DEBUG_TAG, "CALLED onCreateOptionsMenu!");
    try {//from w  w w. j ava 2  s.  c  om
        File rbClassFile = new File(galgsRubyClassesDirectory, GALGS_CLASS_FILE);
        Log.d(DEBUG_TAG, "rbClassFile.getAbsolutePath() " + rbClassFile.getAbsolutePath());
        Log.d(DEBUG_TAG, "rbClassFile.exists() " + rbClassFile.exists());
        Log.d(DEBUG_TAG, "rbClassFile.length() " + rbClassFile.length());
        Log.d(DEBUG_TAG, "rbClassFile.canRead() " + rbClassFile.canRead());
        Log.d(DEBUG_TAG, "rbClassFile.canWrite() " + rbClassFile.canWrite());
        FileReader rbClassFileReader = new FileReader(rbClassFile);
        Log.d(DEBUG_TAG, "rbClassFile " + rbClassFileReader.getEncoding());

        loadRubyMethodsToMenu(new BufferedReader(rbClassFileReader));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //JavaAlgs Action provider
    javaAlgsActionProvider = new JavaAlgsActionProvider(this);
    //RubyAlgs Action provider
    Log.d(DEBUG_TAG, "Ruby methods just before creatingProvider:" + rubyMethods);

    rubyAlgsActionProvider = new RubyAlgsActionProvider(this, rubyMethods);

    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.galg, menu);
    menu.getItem(0).setActionProvider(javaAlgsActionProvider);
    menu.getItem(1).setActionProvider(rubyAlgsActionProvider);

    return super.onCreateOptionsMenu(menu);

}

From source file:com.tweetlanes.android.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {/* w w  w. ja  va  2  s. c o  m*/
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        switch (subMenuItem.getItemId()) {
                        case R.id.action_replies_visibility:

                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));
                            break;

                        case R.id.action_retweets_visibility:
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));
                            break;

                        default:
                            break;
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}

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. ja  v a2 s.com*/
        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:github.daneren2005.dsub.fragments.SubsonicFragment.java

protected void recreateContextMenu(Menu menu) {
    List<MenuItem> menuItems = new ArrayList<MenuItem>();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isVisible()) {
            menuItems.add(item);/* www .j ava 2s .c  om*/
        }
    }
    menu.clear();
    for (int i = 0; i < menuItems.size(); i++) {
        MenuItem item = menuItems.get(i);
        menu.add(tag, item.getItemId(), Menu.NONE, item.getTitle());
    }
}