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:fm.libre.droid.LibreDroid.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem changeStation = menu.add(0, Menu.FIRST, 0, "Change Station").setIcon(R.drawable.back);
    MenuItem quit = menu.add(0, 2, 0, R.string.quit).setIcon(R.drawable.quit);
    changeStation.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            final ViewAnimator view = (ViewAnimator) findViewById(R.id.viewAnimator);
            if (view.getDisplayedChild() == 4) {
                LibreDroid.this.libreServiceConn.service.stop();
                LibreDroid.this.prevPage();
                LibreDroid.this.prevPage();
                LibreDroid.this.prevPage();
                return true;
            } else {
                return false;
            }/*from   www .j  a  v a  2 s .co  m*/
        }
    });

    quit.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            LibreDroid.this.libreServiceConn.service.stop();
            LibreDroid.this.finish();
            return true;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.fragment_events_list, menu);

    MenuItem showArchivedMenuItem = menu.findItem(R.id.fragment_events_list_menu_show_archived);
    showArchivedMenuItem.setChecked(showArchivedEvents);
    showArchivedMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override// w  w w. ja  v  a  2  s .  com
        public boolean onMenuItemClick(MenuItem item) {
            item.setChecked(!item.isChecked());
            showArchivedEvents = item.isChecked();

            downloadData();
            downloadArchivedData();

            return false;
        }
    });
}

From source file:pro.dbro.iburn_2012.OpenStreetMapFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (!FragmentTabsPager.app.embargoClear) {
        MenuItem unlockItem = menu.add(Menu.NONE, R.id.menu_unlock, Menu.NONE, "Unlock");
        MenuItemCompat.setShowAsAction(unlockItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        unlockItem.setIcon(R.drawable.unlock);
        unlockItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @Override/*from   ww  w .  j  a  v a 2s .c om*/
            public boolean onMenuItemClick(MenuItem item) {
                if (!FragmentTabsPager.app.embargoClear) {
                    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

                    alert.setTitle("Enter Unlock Password");

                    // Set an EditText view to get user input 
                    final EditText input = new EditText(getActivity());
                    input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                    alert.setView(input);
                    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            String value = input.getText().toString();
                            if (value.compareTo(FragmentTabsPager.app.unlockPassword) == 0) {
                                FragmentTabsPager.app.setEmbargoClear(true);
                                mLocationOverlay.enableMyLocation();
                                getActivity().findViewById(R.id.map_placeholder).setVisibility(View.GONE);
                                mapView.setVisibility(View.VISIBLE);

                            } else {
                                dialog.cancel();
                                AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
                                alert.setTitle("Invalid Password");
                                alert.show();
                            }
                        }
                    });

                    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                        }
                    });

                    alert.show();
                    //FragmentTabsPager.app.embargoClear = true;
                }
                return false;
            }

        });
    }

}

From source file:org.tigase.mobile.roster.RosterFragment.java

private boolean prepareResources(final SubMenu sm, final long id) {
    final RosterItem rosterItem = getJid(id);
    final Jaxmpp jaxmpp = getMulti().get(rosterItem.getSessionObject());
    Map<String, Presence> all = jaxmpp.getSessionObject().getPresence().getPresences(rosterItem.getJid());

    final CapabilitiesModule capabilitiesModule = jaxmpp.getModule(CapabilitiesModule.class);
    final String nodeName = jaxmpp.getSessionObject().getUserProperty(CapabilitiesModule.NODE_NAME_KEY);

    boolean added = false;

    try {/* w w  w .  j ava2 s  .  c o m*/
        if (all != null)
            for (final Entry<String, Presence> entry : all.entrySet()) {
                if (entry.getValue().getType() != null)
                    continue;
                MenuItem i = sm.add(entry.getKey());

                added = true;
                i.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent();
                        intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
                        intent.putExtra("id", id);
                        intent.putExtra("resource", entry.getKey());

                        getActivity().getApplicationContext().sendBroadcast(intent);

                        return true;
                    }
                });
            }
    } catch (Exception e) {
        Log.e(TAG, "Problem on resources menu", e);
    }

    // if (!added) {
    // Intent intent = new Intent();
    // intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
    // intent.putExtra("id", id);
    //
    // getActivity().getApplicationContext().sendBroadcast(intent);
    // }
    return added;
}

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

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    Log.d(LOG, "onCreateContextMenu, " + menuInfo);

    final AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;
    final int position = adapterContextMenuInfo.position;
    final MyListAdapter.Row row = (MyListAdapter.Row) getListAdapter().getItem(position);

    if (row.dictionaryInfo == null) {
        return;/*from  w ww  .j a  va  2  s.c  o  m*/
    }

    if (position > 0 && row.onDevice) {
        final android.view.MenuItem moveToTopMenuItem = menu.add(R.string.moveToTop);
        moveToTopMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(android.view.MenuItem item) {
                application.moveDictionaryToTop(row.dictionaryInfo);
                setMyListAdapater();
                return true;
            }
        });
    }

    if (row.onDevice) {
        final android.view.MenuItem deleteMenuItem = menu.add(R.string.deleteDictionary);
        deleteMenuItem.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(android.view.MenuItem item) {
                application.deleteDictionary(row.dictionaryInfo);
                setMyListAdapater();
                return true;
            }
        });
    }
}

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

public void onCreateGlobalOptionsMenu(final Context context, final Menu menu) {
    final MenuItem about = menu.add(getString(R.string.about));
    MenuItemCompat.setShowAsAction(about, MenuItem.SHOW_AS_ACTION_NEVER);
    about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(final MenuItem menuItem) {
            final Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
            context.startActivity(intent);
            return false;
        }//ww w .  jav  a2 s  .  co  m
    });

    final MenuItem help = menu.add(getString(R.string.help));
    MenuItemCompat.setShowAsAction(help, MenuItem.SHOW_AS_ACTION_NEVER);
    help.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(final MenuItem menuItem) {
            context.startActivity(HtmlDisplayActivity.getHelpLaunchIntent(getApplicationContext()));
            return false;
        }
    });

    final MenuItem preferences = menu.add(getString(R.string.settings));
    MenuItemCompat.setShowAsAction(preferences, MenuItem.SHOW_AS_ACTION_NEVER);
    preferences.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(final MenuItem menuItem) {
            PreferenceActivity.prefsMightHaveChanged = true;
            final Intent intent = new Intent(getApplicationContext(), PreferenceActivity.class);
            context.startActivity(intent);
            return false;
        }
    });

    final MenuItem reportIssue = menu.add(getString(R.string.reportIssue));
    MenuItemCompat.setShowAsAction(reportIssue, MenuItem.SHOW_AS_ACTION_NEVER);
    reportIssue.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(final MenuItem menuItem) {
            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://github.com/rdoeffinger/Dictionary/issues"));
            context.startActivity(intent);
            return false;
        }
    });
}

From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (getUserVisibleHint()) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getActivity().getMenuInflater().inflate(R.menu.context_menu_epg, menu);
        MenuItem switchItem = menu.findItem(R.id.menuSwitch)
                .setVisible(URLUtil.isValidUrl(ServerConsts.DVBVIEWER_URL));
        switchItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @Override/*from w  w w.j a  v a  2s. c o  m*/
            public boolean onMenuItemClick(MenuItem item) {
                if (getUserVisibleHint()) {
                    String switchRequest = ServerConsts.URL_SWITCH_COMMAND + mCHannel.getPosition();
                    DVBViewerCommand command = new DVBViewerCommand(switchRequest);
                    Thread exexuterTHread = new Thread(command);
                    exexuterTHread.start();
                    return true;
                }
                return false;
            }
        });
        /**
         * Damn Hack for Tablets, onContextItemSelected is not called,
         * But the Dialog appears...
         */
        if (UIUtils.isTablet(getActivity())) {
            menu.findItem(R.id.menuTimer).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (getUserVisibleHint()) {
                        Cursor c = mAdapter.getCursor();
                        c.moveToPosition(selectedPosition);
                        Timer timer = cursorToTimer(c);
                        TimerDetails timerdetails = TimerDetails.newInstance();
                        Bundle args = new Bundle();
                        args.putString(TimerDetails.EXTRA_TITLE, timer.getTitle());
                        args.putString(TimerDetails.EXTRA_CHANNEL_NAME, timer.getChannelName());
                        args.putLong(TimerDetails.EXTRA_CHANNEL_ID, timer.getChannelId());
                        args.putLong(TimerDetails.EXTRA_START, timer.getStart().getTime());
                        args.putLong(TimerDetails.EXTRA_END, timer.getEnd().getTime());
                        timerdetails.setArguments(args);
                        timerdetails.show(getSherlockActivity().getSupportFragmentManager(),
                                TimerDetails.class.getName());
                        return true;
                    }
                    return false;
                }
            });
        }
    }
}

From source file:app.sunstreak.yourpisd.ClassSwipeActivity.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.class_swipe_actions, menu);

    if (termIndex == 0)
        menu.findItem(R.id.previous_six_weeks).setEnabled(false);
    else if (termIndex == 7)
        menu.findItem(R.id.next_six_weeks).setEnabled(false);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == studentIndex)
                item.setEnabled(false);/*from   w  w  w  . ja  v  a  2 s .  c  o m*/

            item.setOnMenuItemClickListener(new StudentSelectListener(i));
            item.setVisible(true);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*from w  ww.j  a  va 2s .c  om*/
    inflater.inflate(R.menu.website_preferences_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (query.equals(mSearch))
                return true;

            mSearch = query;
            getInfoForOrigins();
            return true;
        }
    };
    mSearchView.setOnQueryTextListener(queryTextListener);

    if (mCategory.showProtectedMediaSites()) {
        // Add a menu item to reset protected media identifier device credentials.
        MenuItem resetMenu = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.reset_device_credentials);
        resetMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                ProtectedContentResetCredentialConfirmDialogFragment.newInstance(SingleCategoryPreferences.this)
                        .show(getFragmentManager(), null);
                return true;
            }
        });
    }

    MenuItem help = menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}

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

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    final MenuItem sort = menu.add(getString(R.string.sortDicts));
    MenuItemCompat.setShowAsAction(sort, MenuItem.SHOW_AS_ACTION_NEVER);
    sort.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(final MenuItem menuItem) {
            application.sortDictionaries();
            setMyListAdapater();//from   w  ww  .j av  a  2s . co  m
            return true;
        }
    });

    application.onCreateGlobalOptionsMenu(this, menu);
    return true;
}