Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

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

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #add(int,int,int,CharSequence) that takes a string resource identifier instead of the string itself.

Usage

From source file:system.info.reader.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, 0, 0, getString(R.string.refresh));//.setVisible(false);
    menu.add(0, 1, 0, getString(R.string.upload));
    menu.add(0, 2, 0, getString(R.string.about));
    menu.add(0, 3, 0, getString(R.string.exit)).setVisible(false);
    return true;// w  w w  . j  a v  a 2  s.  c  o m
}

From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java

public void UpdateCurrentGroupMenu() {
    StartActivity rootactivity = (StartActivity) getActivity();
    Menu menu = rootactivity.getActionMenu();
    if (menu != null) {
        MenuItem automation = menu.findItem(R.id.menu_automation);
        if (automation != null) {
            automation.setEnabled(false);
            Menu submenu = automation.getSubMenu();
            if (submenu == null)
                return;
            ///*from   ww  w  .j a  v  a  2  s  . c  om*/
            submenu.removeGroup(Menu.NONE);
            if (mGroupPrograms.size() > 0) {
                for (Module program : mGroupPrograms) {
                    MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName());
                    prg.setIcon(R.drawable.ic_action_flash_on);
                    MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                    final String paddress = program.Address;
                    String groupname = "";
                    try {
                        groupname = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8");
                    } catch (Exception e) {
                    }
                    final String gname = groupname;
                    prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            String apicall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + paddress
                                    + "/" + gname + "/" + new Date().getTime();
                            Control.callServiceApi(apicall, null);
                            return true;
                        }
                    });
                }
                automation.setEnabled(true);
            }
        }
        //
        //            MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro");
        //            recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        //                @Override
        //                public boolean onMenuItemClick(MenuItem menuItem) {
        //                    StartActivity sa = (StartActivity)getActivity();
        //                    sa.openMacroRecordMenu();
        //                    return true;
        //                }
        //            });
        //            rootactivity.supportInvalidateOptionsMenu();
    }
}

From source file:com.example.shyam.popi.LearnEmotions.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    getMenuInflater().inflate(R.menu.activity_screen_slide, menu);

    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

    // Add either a "next" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
            (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) ? R.string.action_finish
                    : R.string.action_next);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;//from   w  ww  .j  a v a 2  s. c o m
}

From source file:com.velli.passwordmanager.ActivityMain.java

public void setupDrawerGroups() {
    PasswordDatabaseHandler.getInstance().getLastLoginDate(new OnGetLastLoginDateListener() {
        @Override/*from  w  w  w.  j av  a2 s.com*/
        public void onLastLoginDate(long millis) {
            if (mNavigationDrawerFragment != null && mNavigationDrawerFragment.getHeaderView(0) != null) {
                RobotoTextView text = (RobotoTextView) mNavigationDrawerFragment.getHeaderView(0)
                        .findViewById(R.id.navigation_drawer_header_last_login);
                if (text != null) {
                    text.setText(Utils.getDateTimeString(millis));
                }
            }
        }
    });
    PasswordDatabaseHandler.getInstance().getGroups(new OnGetGroupsListener() {
        @Override
        public void onGetValues(ArrayList<String> list) {
            if (mNavigationDrawerFragment != null && mNavigationDrawerFragment.getMenu() != null
                    && list != null) {
                Menu menu = mNavigationDrawerFragment.getMenu().findItem(R.id.navigation_item_custom_group)
                        .getSubMenu();
                int i = 0;
                MenuItem item;
                for (String group : list) {
                    item = menu.add(R.id.navigation_group_groups, R.id.navigation_item_custom_group, i, group);
                    item.setIcon(R.drawable.ic_type_group);
                    i++;
                }
            }
        }
    });

}

From source file:com.silentcircle.contacts.editor.RawContactEditorView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void showAddInformationPopupWindow() {
    final ArrayList<KindSectionView> fields = getSectionViewsWithoutFields();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        showAddInformationPopupWindow(fields);
    } else {//  w  w w  . j  ava 2s.c  o m
        final PopupMenu popupMenu = new PopupMenu(getContext(), mAddFieldButton);
        final Menu menu = popupMenu.getMenu();
        for (int i = 0; i < fields.size(); i++) {
            menu.add(Menu.NONE, i, Menu.NONE, fields.get(i).getTitle());
        }

        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                final KindSectionView view = fields.get(item.getItemId());
                if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(view.getKind().mimeType)) {
                    mPhoneticNameAdded = true;
                    updatePhoneticNameVisibility();
                } else {
                    view.addItem();
                }

                // If this was the last section without an entry, we just added one, and therefore
                // there's no reason to show the button.
                if (fields.size() == 1) {
                    mAddFieldButton.setVisibility(GONE);
                }

                return true;
            }
        });
        popupMenu.show();
    }
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.clear();//w w w . j  a v a  2  s  .  com
    if (BuildConfig.DONATE && donateView.getVisibility() == View.GONE) {
        menu.add(Menu.NONE, R.string.donate, Menu.NONE, R.string.donate);
    }
    menu.add(Menu.NONE, R.string.version, Menu.NONE, R.string.version);
    if (BuildConfig.DONATE) {
        menu.add(Menu.NONE, R.string.feedback, Menu.NONE, R.string.feedback);
        if (TextUtils.isEmpty(LicenseUtils.getLicense(this))) {
            menu.add(Menu.NONE, R.string.request_license, Menu.NONE, R.string.request_license);
        }
    }
    menu.add(Menu.NONE, R.string.advanced_settings, Menu.NONE, R.string.advanced_settings);
    return super.onCreateOptionsMenu(menu);
}

From source file:edu.cnu.PowerTutor.ui.PowerViewer.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_OPTIONS, 0, "Options");
    menu.add(0, MENU_TOGGLE_COLLECTING, 0, "");
    menu.add(0, MENU_APP_RATING, 0, "App Rating");
    return true;//w  ww  . j a v a  2s.  c  o  m
}

From source file:br.com.GUI.perfil.BuscarUsuario.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.buscar_usuario, menu);

    final SearchView searchView = new SearchView(this.getActionBar().getThemedContext());
    searchView.setQueryHint("Search");

    menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search)
            .setActionView(searchView)// w  w w. ja  v  a 2s.  c  o m
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            /* if (newText.length() > 0) {
                if(pref.getString("tipo", null).equals("personal")){
                   pesquisarAluno(newText.toString());
                }else if(pref.getString("tipo", null).equals("aluno")){
                   pesquisarPersonal(newText.toString());
                }
                    
             } else {
                if(pref.getString("tipo", null).equals("personal")){
                   pesquisarAluno("");
                }else if(pref.getString("tipo", null).equals("aluno")){
                   pesquisarPersonal("");
                }
                        
            }*/
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String arg0) {
            if (pref.getString("tipo", null).equals("personal")) {
                pesquisarAluno(arg0);
            } else if (pref.getString("tipo", null).equals("aluno")) {
                pesquisarPersonal(arg0);
            }

            return false;
        }
    });
    return true;
}

From source file:com.android.mms.ui.MailBoxMessageContent.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();/*  w w w . j ava2s  .  co  m*/

    if (MessageUtils.hasIccCard()) {
        menu.add(0, MENU_CALL_RECIPIENT, 0, R.string.menu_call).setIcon(R.drawable.ic_menu_call)
                .setTitle(R.string.menu_call).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }

    if (mMsgType == Sms.MESSAGE_TYPE_INBOX) {
        menu.add(0, MENU_REPLY, 0, R.string.menu_reply);
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
        menu.add(0, MENU_DELETE, 0, R.string.delete);
    } else if (mMsgType == Sms.MESSAGE_TYPE_FAILED || mMsgType == Sms.MESSAGE_TYPE_OUTBOX) {
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
        menu.add(0, MENU_RESEND, 0, R.string.menu_resend);
        menu.add(0, MENU_DELETE, 0, R.string.delete);
    } else if (mMsgType == Sms.MESSAGE_TYPE_SENT) {
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
        menu.add(0, MENU_RESEND, 0, R.string.menu_resend);
        menu.add(0, MENU_DELETE, 0, R.string.delete);
    } else if (mMsgType == Sms.MESSAGE_TYPE_QUEUED) {
        menu.add(0, MENU_FORWARD, 0, R.string.menu_forward);
        menu.add(0, MENU_DELETE, 0, R.string.delete);
    }

    if (isLockMessage()) {
        menu.add(0, MENU_LOCK, 0, R.string.menu_unlock);
    } else {
        menu.add(0, MENU_LOCK, 0, R.string.menu_lock);
    }

    if (!Contact.get(mMsgFrom, false).existsInDatabase()) {
        menu.add(0, MENU_SAVE_TO_CONTACT, 0, R.string.menu_add_to_contacts_cm);
    }

    return true;
}

From source file:com.battlelancer.seriesguide.ui.ActivityFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) {
    PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
    Menu menu = popupMenu.getMenu();

    Cursor episode = (Cursor) mAdapter.getItem(position);
    if (episode == null) {
        return false;
    }/*from  w  w w  .j  a v a2s  . c  om*/

    // only display the action appropriate for the items current state
    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    if (EpisodeTools.isWatched(episode.getInt(ActivityQuery.WATCHED))) {
        menu.add(0, CONTEXT_FLAG_UNWATCHED_ID, 1, R.string.action_unwatched);
    } else {
        menu.add(0, CONTEXT_FLAG_WATCHED_ID, 1, R.string.action_watched);
    }
    if (EpisodeTools.isCollected(episode.getInt(ActivityQuery.COLLECTED))) {
        menu.add(0, CONTEXT_COLLECTION_REMOVE_ID, 2, R.string.action_collection_remove);
    } else {
        menu.add(0, CONTEXT_COLLECTION_ADD_ID, 2, R.string.action_collection_add);
    }

    final int showTvdbId = episode.getInt(ActivityQuery.SHOW_ID);
    final int episodeTvdbId = episode.getInt(ActivityQuery._ID);
    final int seasonNumber = episode.getInt(ActivityQuery.SEASON);
    final int episodeNumber = episode.getInt(ActivityQuery.NUMBER);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case CONTEXT_CHECKIN_ID: {
                checkInEpisode((int) id);
                return true;
            }
            case CONTEXT_FLAG_WATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_FLAG_UNWATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            case CONTEXT_COLLECTION_ADD_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_COLLECTION_REMOVE_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            }
            return false;
        }
    });

    popupMenu.show();

    return true;
}