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.odoo.core.utils.OAppBarUtils.java

public static void bindShopMenu(final AppCompatActivity activity, int[] hideMenuIds, Menu menu) {
    final ShopCart shopCart = new ShopCart(activity);
    MenuItem cart = menu.findItem(R.id.menu_show_cart);
    for (int menuId : hideMenuIds) {
        Log.v("", "Hiding menu " + menu.findItem(menuId).getTitle());
        menu.findItem(menuId).setVisible(false);
    }/* w w  w  . j  av a 2s.  com*/
    //        menu.findItem(R.id.menu_search_product).setVisible(!isHome);
    // Binding cart and its badge
    final RelativeLayout cartBadge = (RelativeLayout) cart.getActionView();
    int counter = shopCart.counter();
    setCounter(counter, cartBadge);
    cart.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            OAppBarUtils.onShopMenuItemClick(activity, null, item);
            return true;
        }
    });
    cartBadge.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            OFragmentUtils.get(activity, null).startFragment(new CartFragment(), true, null);
        }
    });
}

From source file:com.google.android.marvin.talkback.menurules.RuleUnlabeledImage.java

@Override
public List<RadialMenuItem> getMenuItemsForNode(TalkBackService service, AccessibilityNodeInfoCompat node) {
    final AccessibilityNodeInfoCompat nodeCopy = AccessibilityNodeInfoCompat.obtain(node);
    // TODO(caseyburkhardt): Undo when the support library is fixed.
    final AccessibilityNodeInfo unwrappedCopy = (AccessibilityNodeInfo) nodeCopy.getInfo();
    final CustomLabelManager labelManager = service.getLabelManager();
    final List<RadialMenuItem> items = new LinkedList<RadialMenuItem>();

    final Label viewLabel = labelManager.getLabelForViewIdFromCache(unwrappedCopy.getViewIdResourceName());
    if (viewLabel == null) {
        final RadialMenuItem addLabel = new RadialMenuItem(service, RadialMenu.NONE,
                R.id.labeling_breakout_add_label, RadialMenu.NONE,
                service.getString(R.string.label_dialog_title_add));
        items.add(addLabel);//from   w  ww.  ja  va  2  s . c o  m
    } else {
        final RadialMenuItem editLabel = new RadialMenuItem(service, RadialMenu.NONE,
                R.id.labeling_breakout_edit_label, RadialMenu.NONE,
                service.getString(R.string.label_dialog_title_edit));
        final RadialMenuItem removeLabel = new RadialMenuItem(service, RadialMenu.NONE,
                R.id.labeling_breakout_remove_label, RadialMenu.NONE,
                service.getString(R.string.label_dialog_title_remove));
        items.add(editLabel);
        items.add(removeLabel);
    }

    for (MenuItem item : items) {
        item.setOnMenuItemClickListener(
                new UnlabeledImageMenuItemClickListener(service, unwrappedCopy, viewLabel));
    }

    return items;
}

From source file:org.samcrow.ridgesurvey.DataEntryActivity.java

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

    final MenuItem saveItem = menu.findItem(R.id.save_item);
    saveItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*from  w  ww. j  a  v  a  2 s  .  c  o m*/
        public boolean onMenuItemClick(MenuItem item) {
            submit();
            return true;
        }
    });

    return true;
}

From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java

protected void setupStandardMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.standard_analysis_actions, menu);

    final MenuItem doneItem = menu.findItem(R.id.action_done);
    assert doneItem != null;
    doneItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*from   w  ww  .  j a  v a  2 s.co  m*/
        public boolean onMenuItemClick(MenuItem menuItem) {
            Activity activity = getActivity();
            activity.setResult(Activity.RESULT_OK);
            activity.finish();
            return true;
        }
    });

    // data menu item
    ExperimentAnalysisActivity experimentActivity = (ExperimentAnalysisActivity) getActivity();
    final ExperimentAnalysis experimentAnalysis = experimentActivity.getExperimentAnalysis();
    final MenuItem dataItem = menu.findItem(R.id.action_data);
    assert dataItem != null;
    dataItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            showDataMenu(experimentAnalysis);
            return true;
        }
    });
    // hide item if there is no more than one data
    if (experimentAnalysis.getAnalysisRunAt(analysisRef.runId).analysisList.size() == 1)
        dataItem.setVisible(false);
}

From source file:org.cook_e.cook_e.BugReportActivity.java

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

    final MenuItem sendItem = menu.findItem(R.id.item_send_report);
    sendItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//w w w. j  a  va2 s  .  c o  m
        public boolean onMenuItemClick(MenuItem item) {
            sendReport();
            return true;
        }
    });

    return true;
}

From source file:org.tunesremote.PlaylistsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    try {/* www.j  a v a  2 s . co  m*/
        // create context menu to play entire artist
        final Playlist ply = (Playlist) adapter.getItem(info.position);
        menu.setHeaderTitle(ply.getName());
        final String playlistid = Long.toString(ply.getID());

        final MenuItem browse = menu.add(R.string.albums_menu_browse);
        browse.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                Intent intent = new Intent(host, TracksActivity.class);
                intent.putExtra(Intent.EXTRA_TITLE, "");
                intent.putExtra("Playlist", playlistid);
                intent.putExtra("PlaylistPersistentId", ply.getPersistentId());
                intent.putExtra("AllAlbums", false);
                host.startActivityForResult(intent, 1);

                return true;
            }

        });

        final MenuItem play = menu.add(R.string.playlists_menu_play);
        play.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                host.session.controlPlayPlaylist(ply.getPersistentId(), "0");
                host.finish();
                return true;
            }

        });
    } catch (Exception e) {
        Log.w(TAG, "onCreateContextMenu:" + e.getMessage());
    }

}

From source file:com.koushikdutta.superuser.PolicyFragmentInternal.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuInflater mi = new MenuInflater(getActivity());
    mi.inflate(R.menu.main, menu);/* w  w w .  j ava  2 s  .c o m*/
    MenuItem log = menu.findItem(R.id.logs);
    log.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            showAllLogs();
            return true;
        }
    });

    MenuItem settings = menu.findItem(R.id.settings);
    settings.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        void openSettingsNative(final MenuItem item) {
            setContent(createSettingsNativeFragment(), true, getString(R.string.settings));
        }

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            if (getActivity() instanceof FragmentActivity) {
                setContent(new SettingsFragment(), true, getString(R.string.settings));
            } else {
                openSettingsNative(item);
            }
            return true;
        }
    });
}

From source file:org.cook_e.cook_e.HomeActivity.java

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

    getMenuInflater().inflate(R.menu.topright_menu, menu);

    final MenuItem tutorialItem = menu.findItem(R.id.menu_tutorial);
    tutorialItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from   ww  w  .  j ava  2 s. co m
        public boolean onMenuItemClick(MenuItem item) {
            final Intent intent = new Intent(HomeActivity.this, TutorialActivity.class);
            startActivity(intent);
            return true;
        }
    });

    final MenuItem aboutItem = menu.findItem(R.id.menu_about);
    aboutItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // Open the about activity
            final Intent intent = new Intent(HomeActivity.this, AboutActivity.class);
            startActivity(intent);
            return true;
        }
    });

    final MenuItem reportProblemItem = menu.findItem(R.id.menu_report_problem);
    reportProblemItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Intent intent = new Intent(HomeActivity.this, BugReportActivity.class);
            startActivity(intent);
            return true;
        }
    });

    final MenuItem settingsItem = menu.findItem(R.id.menu_settings);
    settingsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(HomeActivity.this, SettingsActivity.class));
            return true;
        }
    });

    return true;
}

From source file:com.google.android.marvin.mytalkback.menurules.RuleEditText.java

@Override
public List<RadialMenuItem> getMenuItemsForNode(TalkBackService service, AccessibilityNodeInfoCompat node) {
    final AccessibilityNodeInfoCompat nodeCopy = AccessibilityNodeInfoCompat.obtain(node);
    final CursorController cursorController = service.getCursorController();
    final List<RadialMenuItem> items = new LinkedList<RadialMenuItem>();

    // This action has inconsistencies with EditText nodes that have
    // contentDescription attributes.
    if (TextUtils.isEmpty(nodeCopy.getContentDescription())) {
        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy,
                AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY)) {
            final RadialMenuItem moveToBeginning = new RadialMenuItem(service, RadialMenu.NONE,
                    R.id.edittext_breakout_move_to_beginning, RadialMenu.NONE,
                    service.getString(R.string.title_edittext_breakout_move_to_beginning));
            items.add(moveToBeginning);/*w  w  w  .  ja v  a2  s . co m*/
        }

        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy,
                AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY)) {
            final RadialMenuItem moveToEnd = new RadialMenuItem(service, RadialMenu.NONE,
                    R.id.edittext_breakout_move_to_end, RadialMenu.NONE,
                    service.getString(R.string.title_edittext_breakout_move_to_end));
            items.add(moveToEnd);
        }

        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy, AccessibilityNodeInfoCompat.ACTION_CUT)) {
            final RadialMenuItem cut = new RadialMenuItem(service, RadialMenu.NONE, R.id.edittext_breakout_cut,
                    RadialMenu.NONE, service.getString(R.string.title_edittext_breakout_cut));
            items.add(cut);
        }

        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy, AccessibilityNodeInfoCompat.ACTION_COPY)) {
            final RadialMenuItem copy = new RadialMenuItem(service, RadialMenu.NONE,
                    R.id.edittext_breakout_copy, RadialMenu.NONE,
                    service.getString(R.string.title_edittext_breakout_copy));
            items.add(copy);
        }

        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy, AccessibilityNodeInfoCompat.ACTION_PASTE)) {
            final RadialMenuItem paste = new RadialMenuItem(service, RadialMenu.NONE,
                    R.id.edittext_breakout_paste, RadialMenu.NONE,
                    service.getString(R.string.title_edittext_breakout_paste));
            items.add(paste);
        }

        if (AccessibilityNodeInfoUtils.supportsAnyAction(nodeCopy,
                AccessibilityNodeInfoCompat.ACTION_SET_SELECTION)) {
            final RadialMenuItem select = new RadialMenuItem(service, RadialMenu.NONE,
                    R.id.edittext_breakout_select_all, RadialMenu.NONE,
                    service.getString(R.string.title_edittext_breakout_select_all));
            items.add(select);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            // Text selection APIs are available in API 18+
            // TODO(caseyburkhardt) Use a checkable menu item once supported.
            final RadialMenuItem selectionMode;
            if (cursorController.isSelectionModeActive()) {
                selectionMode = new RadialMenuItem(service, RadialMenu.NONE,
                        R.id.edittext_breakout_end_selection_mode, RadialMenu.NONE,
                        service.getString(R.string.title_edittext_breakout_end_selection_mode));
            } else {
                selectionMode = new RadialMenuItem(service, RadialMenu.NONE,
                        R.id.edittext_breakout_start_selection_mode, RadialMenu.NONE,
                        service.getString(R.string.title_edittext_breakout_start_selection_mode));
            }

            items.add(selectionMode);
        }
    }

    for (MenuItem item : items) {
        item.setOnMenuItemClickListener(new EditTextMenuItemClickListener(service, nodeCopy));
    }

    return items;
}

From source file:org.whisperim.android.ui.ChatWindow.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    MenuItem sendKey = menu.add(0, SEND_KEY, 0, "Send Key");
    sendKey.setOnMenuItemClickListener(this);
    encryption_ = menu.add(0, ENCRYPTION, 0, "Encryption");
    encryption_.setOnMenuItemClickListener(this);
    encryption_.setCheckable(true);//  w  w w  .  j  a v  a  2  s.co m
    if (!parent_.haveKey(buddy_)) {
        encryption_.setEnabled(false);
    }

}