Example usage for android.view MenuItem setOnMenuItemClickListener

List of usage examples for android.view MenuItem setOnMenuItemClickListener

Introduction

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

Prototype

public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener);

Source Link

Document

Set a custom listener for invocation of this menu item.

Usage

From source file:com.hughes.android.dictionary.DictionaryActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {

    if (PreferenceManager.getDefaultSharedPreferences(this)
            .getBoolean(getString(R.string.showPrevNextButtonsKey), true)) {
        // Next word.
        nextWordMenuItem = menu.add(getString(R.string.nextWord)).setIcon(R.drawable.arrow_down_float);
        MenuItemCompat.setShowAsAction(nextWordMenuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        nextWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override//w  w w  .ja v  a 2 s . co  m
            public boolean onMenuItemClick(MenuItem item) {
                onUpDownButton(false);
                return true;
            }
        });

        // Previous word.
        previousWordMenuItem = menu.add(getString(R.string.previousWord)).setIcon(R.drawable.arrow_up_float);
        MenuItemCompat.setShowAsAction(previousWordMenuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
        previousWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                onUpDownButton(true);
                return true;
            }
        });
    }

    randomWordMenuItem = menu.add(getString(R.string.randomWord));
    randomWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            onRandomWordButton();
            return true;
        }
    });

    application.onCreateGlobalOptionsMenu(this, menu);

    {
        final MenuItem dictionaryManager = menu.add(getString(R.string.dictionaryManager));
        MenuItemCompat.setShowAsAction(dictionaryManager, MenuItem.SHOW_AS_ACTION_NEVER);
        dictionaryManager.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(final MenuItem menuItem) {
                startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
                finish();
                return false;
            }
        });
    }

    {
        final MenuItem aboutDictionary = menu.add(getString(R.string.aboutDictionary));
        MenuItemCompat.setShowAsAction(aboutDictionary, MenuItem.SHOW_AS_ACTION_NEVER);
        aboutDictionary.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(final MenuItem menuItem) {
                final Context context = getListView().getContext();
                final Dialog dialog = new Dialog(context);
                dialog.setContentView(R.layout.about_dictionary_dialog);
                final TextView textView = (TextView) dialog.findViewById(R.id.text);

                final String name = application.getDictionaryName(dictFile.getName());
                dialog.setTitle(name);

                final StringBuilder builder = new StringBuilder();
                final DictionaryInfo dictionaryInfo = dictionary.getDictionaryInfo();
                dictionaryInfo.uncompressedBytes = dictFile.length();
                if (dictionaryInfo != null) {
                    builder.append(dictionaryInfo.dictInfo).append("\n\n");
                    builder.append(getString(R.string.dictionaryPath, dictFile.getPath())).append("\n");
                    builder.append(getString(R.string.dictionarySize, dictionaryInfo.uncompressedBytes))
                            .append("\n");
                    builder.append(getString(R.string.dictionaryCreationTime, dictionaryInfo.creationMillis))
                            .append("\n");
                    for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {
                        builder.append("\n");
                        builder.append(getString(R.string.indexName, indexInfo.shortName)).append("\n");
                        builder.append(getString(R.string.mainTokenCount, indexInfo.mainTokenCount))
                                .append("\n");
                    }
                    builder.append("\n");
                    builder.append(getString(R.string.sources)).append("\n");
                    for (final EntrySource source : dictionary.sources) {
                        builder.append(getString(R.string.sourceInfo, source.getName(), source.getNumEntries()))
                                .append("\n");
                    }
                }
                textView.setText(builder.toString());

                dialog.show();
                final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
                layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(layoutParams);
                return false;
            }
        });
    }

    return true;
}

From source file:com.kaliturin.blacklist.fragments.ContactsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);

    // tune menu options
    MenuItem itemSearch = menu.findItem(R.id.action_search);
    Utils.setMenuIconTint(getContext(), itemSearch, R.attr.colorAccent);
    itemSearch.setVisible(true);//from  w w  w.  ja v  a2s.c o m
    MenuItem itemAdd = menu.findItem(R.id.action_add);
    Utils.setMenuIconTint(getContext(), itemAdd, R.attr.colorAccent);
    itemAdd.setVisible(true);

    // get the view from search menu item
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(itemSearch);
    searchView.setQueryHint(getString(R.string.Search_action));
    // set on text change listener
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

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

    // on search cancelling
    // SearchView.OnCloseListener is not calling so use other way...
    MenuItemCompat.setOnActionExpandListener(itemSearch, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            reloadItems(null);
            return true;
        }
    });

    // item's 'add contact' on click listener
    itemAdd.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // show menu dialog
            showAddContactsMenuDialog();

            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

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

private void initAllMenuItems() {
    try {/*w ww  .  j av  a 2 s  .c o m*/
        menu.findItem(R.id.menu_bookmarks).setVisible(true);
        menu.findItem(R.id.menu_fullscreen).setVisible(true);
        menu.findItem(R.id.menu_home).setVisible(true);
        menu.findItem(R.id.menu_randomarticle).setVisible(true);
        menu.findItem(R.id.menu_searchintext).setVisible(true);

        MenuItem searchItem = menu.findItem(R.id.menu_search);
        searchItem.setVisible(true);
        final String zimFile = ZimContentProvider.getZimFile();
        searchItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
                i.putExtra("zimFile", zimFile);
                startActivityForResult(i, REQUEST_FILE_SEARCH);
                overridePendingTransition(0, 0);
                return true;
            }
        });

        toolbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
                i.putExtra("zimFile", zimFile);
                startActivityForResult(i, REQUEST_FILE_SEARCH);
                overridePendingTransition(0, 0);
            }
        });
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
                    drawerLayout.closeDrawer(GravityCompat.END);
                } else if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
                    drawerLayout.closeDrawer(GravityCompat.START);
                } else {
                    drawerLayout.openDrawer(GravityCompat.START);
                }
            }
        });

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                ActionMenuItemView m = (ActionMenuItemView) findViewById(R.id.menu_bookmarks);
                if (m == null) {
                    return;
                }
                findViewById(R.id.menu_bookmarks).setOnLongClickListener(view -> {
                    goToBookmarks();
                    return false;
                });
            }
        });

        if (tts.isInitialized()) {
            menu.findItem(R.id.menu_read_aloud).setVisible(true);
            if (isSpeaking) {
                menu.findItem(R.id.menu_read_aloud)
                        .setTitle(createMenuItem(getResources().getString(R.string.menu_read_aloud_stop)));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {

    SubMenu subMenuBlueTooth = menu.addSubMenu(this.getString(R.string.lblBluetoothItem));
    com.actionbarsherlock.view.MenuItem miBluetooth = subMenuBlueTooth.getItem();
    miBluetooth.setIcon(R.drawable.stat_sys_data_bluetooth);
    miBluetooth.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    com.actionbarsherlock.view.MenuItem miBlueToothDiscover = subMenuBlueTooth
            .add(R.string.lblBluetoothDiscover).setIcon(R.drawable.ic_menu_allfriends);
    com.actionbarsherlock.view.MenuItem miBlueToothGetDiscoverable = subMenuBlueTooth
            .add(R.string.lblBluetoothGetDiscoverable).setIcon(android.R.drawable.ic_menu_myplaces);
    com.actionbarsherlock.view.MenuItem miBlueToothReceive = subMenuBlueTooth.add(R.string.lblBluetoothReceive)
            .setIcon(R.drawable.ic_menu_download);
    com.actionbarsherlock.view.MenuItem miBlueToothHelp = subMenuBlueTooth.add(R.string.lblBluetoothHelp)
            .setIcon(android.R.drawable.ic_menu_info_details);

    miBlueToothDiscover.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*from ww w  .  jav a2s  .  c o m*/
        public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            if (isBluetoothActivated()) {
                GameSetHistoryActivity.this.bluetoothHelper.startDiscovery();
                AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothDiscoverDevices);
            }
            return true;
        }
    });

    miBlueToothGetDiscoverable.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            if (isBluetoothActivated()) {
                GameSetHistoryActivity.this.bluetoothHelper.setBluetoothDeviceDiscoverable();
                AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothSetDiscoverable);
            }
            return true;
        }
    });

    miBlueToothReceive.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            if (isBluetoothActivated()) {
                // retrieve game count
                int gameSetCount;
                try {
                    gameSetCount = AppContext.getApplication().getDalService().getGameSetCount();
                } catch (DalException de) {
                    gameSetCount = 0;
                }

                // prevent user from downloading if game set count > 5 and
                // limited version
                if (AppContext.getApplication().isAppLimited() && gameSetCount >= 5) {
                    Toast.makeText(GameSetHistoryActivity.this,
                            AppContext.getApplication().getResources()
                                    .getString(R.string.msgLimitedVersionInformation),
                            Toast.LENGTH_SHORT).show();
                }

                // ok for download
                else {
                    try {
                        GameSetHistoryActivity.this.receiveGameSetTask = new ReceiveGameSetTask(
                                GameSetHistoryActivity.this, GameSetHistoryActivity.this.progressDialog,
                                GameSetHistoryActivity.this.bluetoothHelper.getBluetoothAdapter());
                        GameSetHistoryActivity.this.receiveGameSetTask.setCallback(refreshCallback);
                        GameSetHistoryActivity.this.receiveGameSetTask.execute();
                        AuditHelper.auditEvent(AuditHelper.EventTypes.actionBluetoothReceiveGameSet);
                    } catch (IOException ioe) {
                        Log.v(AppContext.getApplication().getAppLogTag(),
                                "TarotDroid Exception in " + this.getClass().toString(), ioe);
                        Toast.makeText(GameSetHistoryActivity.this, AppContext.getApplication().getResources()
                                .getString(R.string.msgBluetoothError, ioe), Toast.LENGTH_SHORT).show();
                    }
                }
            }
            return true;
        }
    });

    miBlueToothHelp.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            UIHelper.showSimpleRichTextDialog(GameSetHistoryActivity.this,
                    AppContext.getApplication().getResources().getText(R.string.msgHelpBluetooth).toString(),
                    AppContext.getApplication().getResources().getString(R.string.titleHelpBluetooth));
            return true;
        }
    });

    // TODO Improve Massive excel export
    // if (!AppContext.getApplication().isAppLimited()) {
    // com.actionbarsherlock.view.MenuItem miGlobalExport =
    // menu.add(this.getString(R.string.lblExcelExport)).setIcon(R.drawable.ic_excel);
    // miGlobalExport.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER);
    // //miGlobalExport.setIcon(R.drawable.ic_excel);
    //
    // miGlobalExport.setOnMenuItemClickListener(new
    // OnMenuItemClickListener() {
    // @Override
    // public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem
    // item) {
    // ExportToExcelTask task = new
    // ExportToExcelTask(GameSetHistoryActivity.this, progressDialog);
    // task.execute();
    // return true;
    // }
    // });
    // }

    com.actionbarsherlock.view.MenuItem miBin = menu.add(this.getString(R.string.lblInitDalItem));
    miBin.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_NEVER);
    miBin.setIcon(R.drawable.gd_action_bar_trashcan);

    miBin.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(GameSetHistoryActivity.this);
            builder.setTitle(GameSetHistoryActivity.this.getString(R.string.titleReinitDalYesNo));
            builder.setMessage(
                    Html.fromHtml(GameSetHistoryActivity.this.getText(R.string.msgReinitDalYesNo).toString()));
            builder.setPositiveButton(GameSetHistoryActivity.this.getString(R.string.btnOk),
                    GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener);
            builder.setNegativeButton(GameSetHistoryActivity.this.getString(R.string.btnCancel),
                    GameSetHistoryActivity.this.removeAllGameSetsDialogClickListener).show();
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            return true;
        }
    });

    return true;
}

From source file:saphion.fragments.alarm.AlarmFragment.java

/**
 * Installs click and touch listeners on a fake overflow menu button.
 * /*from  ww  w  .j  a va2s .  c om*/
 * @param menuButton
 *            the fragment's fake overflow menu button
 */
public void setupFakeOverflowMenuButton(View menuButton) {
    final PopupMenu fakeOverflow = new PopupMenu(menuButton.getContext(), menuButton) {
        @Override
        public void show() {
            getActivity().onPrepareOptionsMenu(getMenu());
            super.show();
        }
    };
    Menu menu = fakeOverflow.getMenu();// .inflate(R.menu.bmenu);
    MenuItem noti = menu.add("Notification Settings");
    noti.setIcon(R.drawable.noti);
    noti.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().startActivity(new Intent(getBaseContext(), Controller.class));
            getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return true;
        }
    });

    MenuItem prefs = menu.add("Preferences");
    prefs.setIcon(R.drawable.prefs);
    prefs.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(getBaseContext(), MainPreference.class));
            getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return true;
        }
    });

    MenuItem share = menu.add("Share");
    share.setIcon(R.drawable.share);
    share.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().startActivity(createShareIntent());
            return true;
        }
    });

    MenuItem more = menu.add("More By Developer");
    more.setIcon(R.drawable.morebydev);
    more.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/developer?id=sachin+shinde")));
            return true;
        }
    });

    MenuItem about = menu.add("About");
    about.setIcon(R.drawable.about);
    about.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(getBaseContext(), AboutClass.class));
            getActivity().overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            return true;
        }
    });

    fakeOverflow.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return getActivity().onOptionsItemSelected(item);
        }
    });

    menuButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fakeOverflow.show();
        }
    });
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupActionModeCallback() {
    mActionModeCallbackV7 = new Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override//from  w  w w  . java  2 s .co m
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onCreateActionMode");
            }

            if (mode == null && torrentListAdapter.getCheckedItemCount() == 0
                    && torrentListAdapter.getSelectedPosition() < 0) {
                return false;
            }

            Menu origMenu = menu;
            if (tb != null) {
                menu = tb.getMenu();
            }
            if (mode != null) {
                mActionMode = (mode instanceof ActionModeWrapperV7) ? mode
                        : new ActionModeWrapperV7(mode, tb, getActivity());

                mActionMode.setTitle(R.string.context_torrent_title);
            }
            ActionBarToolbarSplitter.buildActionBar(getActivity(), this, R.menu.menu_context_torrent_details,
                    menu, tb);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onCreateActionMode(mode, menu);
            }

            if (sideListArea == null) {
                SubMenu subMenu = origMenu.addSubMenu(R.string.menu_global_actions);
                subMenu.setIcon(R.drawable.ic_menu_white_24dp);
                MenuItemCompat.setShowAsAction(subMenu.getItem(), MenuItemCompat.SHOW_AS_ACTION_NEVER);

                try {
                    // Place "Global" actions on top bar in collapsed menu
                    MenuInflater mi = mode == null ? getActivity().getMenuInflater() : mode.getMenuInflater();
                    mi.inflate(R.menu.menu_torrent_list, subMenu);
                    onPrepareOptionsMenu(subMenu);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG, e.getMessage());
                    menu.removeItem(subMenu.getItem().getItemId());
                }
            }

            if (AndroidUtils.usesNavigationControl()) {
                MenuItem add = origMenu.add(R.string.select_multiple_items);
                add.setCheckable(true);
                add.setChecked(torrentListAdapter.isMultiCheckMode());
                add.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        boolean turnOn = !torrentListAdapter.isMultiCheckModeAllowed();

                        torrentListAdapter.setMultiCheckModeAllowed(turnOn);
                        if (turnOn) {
                            torrentListAdapter.setMultiCheckMode(turnOn);
                            torrentListAdapter.setItemChecked(torrentListAdapter.getSelectedPosition(), true);
                        }
                        return true;
                    }
                });
            }

            return true;
        }

        // Called each time the action mode is shown. Always called after
        // onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "MULTI:onPrepareActionMode " + mode);
            }
            if (tb != null) {
                menu = tb.getMenu();
            }

            // Must be called first, because our drawer sets all menu items
            // visible.. :(
            getActivity().onPrepareOptionsMenu(menu);

            prepareContextMenu(menu);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onPrepareActionMode(mode, menu);
            }

            AndroidUtils.fixupMenuAlpha(menu);

            return true;
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onActionItemClicked " + item.getTitle());
            }

            if (TorrentListFragment.this.handleFragmentMenuItems(item.getItemId())) {
                return true;
            }
            if (getActivity().onOptionsItemSelected(item)) {
                return true;
            }
            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                if (frag.onActionItemClicked(mode, item)) {
                    return true;
                }
            }
            return false;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onDestroyActionMode. BeingReplaced?" + actionModeBeingReplaced);
            }

            mActionMode = null;

            if (!actionModeBeingReplaced) {
                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        torrentListAdapter.setMultiCheckMode(false);
                        torrentListAdapter.clearChecked();
                        updateCheckedIDs();
                    }
                });

                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.actionModeBeingReplacedDone();
                        }
                    }
                });

                listview.setLongClickable(true);
                listview.requestLayout();
                AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
            }
        }
    };
}

From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java

/** Show the context menu on a history item. */
@Override/*from   ww w .  j a  v  a 2 s.c o  m*/
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

    ChatView chatView = getCurrentChatView();

    if (chatView != null) {
        AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        mMessageContextMenuHandler.mPosition = info.position;
        Cursor cursor = chatView.getMessageAtPosition(info.position);
        int type = cursor.getInt(cursor.getColumnIndexOrThrow(Imps.Messages.TYPE));
        if (type == Imps.MessageType.OUTGOING) {
            android.view.MenuItem mi = menu.add(0, MENU_RESEND, 0, R.string.menu_resend);

            mi.setOnMenuItemClickListener(mMessageContextMenuHandler);

        }

    }
}

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

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem starredMenuItem = menu.findItem(R.id.menu_star);
    /*/* w w  w.j a v  a 2 s  .c o m*/
     * Bug Fix by Mediatek Begin.
     *   Original Android's code:
            
    starredMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
        // Toggle "starred" state
        // Make sure there is a contact
        if (mLookupUri != null) {
            // Read the current starred value from the UI instead of using the last
            // loaded state. This allows rapid tapping without writing the same
            // value several times
            final boolean isStarred = starredMenuItem.isChecked();
            
            // To improve responsiveness, swap out the picture (and tag) in the UI already
            ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
                    mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
                    !isStarred);
            
            // Now perform the real save
            Intent intent = ContactSaveService.createSetStarredIntent(
                    ContactDetailActivity.this, mLookupUri, !isStarred);
            ContactDetailActivity.this.startService(intent);
        }
        return true;
    }
    });
    // If there is contact data, update the starred state
    if (mContactData != null) {
    ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
            mContactData.isDirectoryEntry(), mContactData.isUserProfile(),
            mContactData.getStarred());
    }
     *   CR ID: ALPS00115684
     */
    if (this.mContactData != null && this.mContactData.getIndicate() < 0) {

        starredMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // Toggle "starred" state
                // Make sure there is a contact
                if (mLookupUri != null) {
                    // Read the current starred value from the UI instead of using the last
                    // loaded state. This allows rapid tapping without writing the same
                    // value several times
                    final boolean isStarred = starredMenuItem.isChecked();

                    // To improve responsiveness, swap out the picture (and tag) in the UI already
                    ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem,
                            mContactData.isDirectoryEntry(), mContactData.isUserProfile(), !isStarred);

                    // Now perform the real save
                    Intent intent = ContactSaveService.createSetStarredIntent(ContactDetailActivity.this,
                            mLookupUri, !isStarred);
                    ContactDetailActivity.this.startService(intent);
                }
                return true;
            }
        });
        ContactDetailDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(),
                mContactData.isUserProfile(), mContactData.getStarred());
    } else {
        Log.i(TAG, "it is sim contact");
        starredMenuItem.setVisible(false);
    }
    /*
     * Bug Fix by Mediatek End.
     */

    /*
     * New Feature by Mediatek Begin. set this if show new association menu
     */
    setAssociationMenu(menu, true);
    /*
     * New Feature by Mediatek End.
     */

    return true;
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onSupportActionModeStarted(final ActionMode mode) {
    if (mSelectionModeActive && selectedTextView != null) {
        mSelectionModeActive = false;/* w  w w .j  ava2s  .  c o m*/
        mActionMode = mode;
        final Menu menu = mode.getMenu();
        mode.getMenuInflater().inflate(R.menu.details_context, menu);
        menu.findItem(R.id.menu_copy).setVisible(false);
        menu.findItem(R.id.menu_cache_share_field).setOnMenuItemClickListener(new TextMenuItemClickListener());
        menu.findItem(R.id.menu_translate_to_sys_lang)
                .setOnMenuItemClickListener(new TextMenuItemClickListener());
        menu.findItem(R.id.menu_translate_to_english)
                .setOnMenuItemClickListener(new TextMenuItemClickListener());
        final MenuItem extWpts = menu.findItem(R.id.menu_extract_waypoints);
        extWpts.setVisible(true);
        extWpts.setOnMenuItemClickListener(new TextMenuItemClickListener());
        buildDetailsContextMenu(mode, menu, res.getString(R.string.cache_description), false);
        selectedTextView.setWindowFocusWait(true);
    }
    super.onSupportActionModeStarted(mode);
}

From source file:org.de.jmg.learn.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    try {//  w w w  . j  a v a2  s .  co  m
        getMenuInflater().inflate(R.menu.main, menu);
        //findViewById(R.menu.main).setBackgroundColor(Color.BLACK);
        //.setBackgroundColor(Color.BLACK);
        //resize();
        OptionsMenu = menu;
        if (OptionsMenu != null) {
            mnuAddNew = menu.findItem(R.id.mnuAddWord);
            mnuUploadToQuizlet = menu.findItem(R.id.mnuUploadToQuizlet);
            Resources resources = context.getResources();
            DisplayMetrics metrics = resources.getDisplayMetrics();
            int height = metrics.heightPixels;
            int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop();
            height = height - viewTop;
            double scale = (double) height / (double) 950;
            if (scale < .5f) {
                isSmallDevice = true;
            }
            if (Build.VERSION.SDK_INT < 11) {
                menu.findItem(R.id.mnuOpenQuizlet).setVisible(false);
                menu.findItem(R.id.mnuUploadToQuizlet).setVisible(false);
            }
            /*
            if (isSmallDevice)
            {
            MenuItemCompat.setShowAsAction(menu.findItem(R.id.mnuSaveAs), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            }
            */
            MenuItem mnuQuizlet = menu.findItem(R.id.mnuLoginQuizlet);
            mnuQuizlet.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    //throw new RuntimeException("Test");
                    return false;
                }
            });
            if (BuildConfig.DEBUG) {
                mnuQuizlet.setVisible(true);
            } else {
                mnuQuizlet.setVisible(false);
            }
            MenuItem mnuAskReverse = OptionsMenu.findItem(R.id.mnuAskReverse);
            mnuAskReverse.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    item.setChecked(!item.isChecked());
                    vok.reverse = item.isChecked();
                    setMnuReverse();
                    return true;
                }
            });
            setMnuReverse();
            /*
            if (isSmallDevice)
            {
            MenuItem m = menu.findItem(R.id.mnuHome);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuFileOpen);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuSaveAs);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuAddWord);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            //lib.ShowToast(this,"Menus set to IF_ROOM!");
            }
            */
            mainView.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                        @Override
                        public void onGlobalLayout() {
                            // Ensure you call it only once :
                            lib.removeLayoutListener(mainView.getViewTreeObserver(), this);
                            //MainActivity.this.SetShowAsAction(mnuUploadToQuizlet);
                        }
                    });

            return true;
        }
        throw new RuntimeException("menu is null!");
    } catch (Exception ex) {
        lib.ShowException(this, ex);
    }

    return false;
}