List of usage examples for android.view MenuItem setOnMenuItemClickListener
public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener);
From source file:com.koushikdutta.superuser.FragmentMain.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MenuItem mode = menu.add(Menu.NONE, Menu.NONE, 100, R.string.list_mode); mode.setTitle(pref.getBoolean("grid_mode", true) ? R.string.list_mode : R.string.grid_mode); mode.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); mode.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override/* w w w . jav a2s. c o m*/ public boolean onMenuItemClick(MenuItem menuItem) { if (pref.edit().putBoolean("grid_mode", !pref.getBoolean("grid_mode", true)).commit()) getActivity().recreate(); return true; } }); if (!gridMode) return; MenuItem gridSize = menu.add(Menu.NONE, Menu.NONE, 101, R.string.grid_size); gridSize.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); gridSize.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int sizePort = pref.getInt("grid_size_port", 3); int sizeLand = pref.getInt("grid_size_land", 4); final AlertDialog.Builder builder = new AlertDialog.Builder(context); View parent = LayoutInflater.from(context).inflate(R.layout.dialog_settings_grid_size, null); final AppCompatSeekBar seekPort = (AppCompatSeekBar) parent.findViewById(R.id.seek_port); seekPort.setProgress(sizePort - 3); final AppCompatSeekBar seekLand = (AppCompatSeekBar) parent.findViewById(R.id.seek_land); seekLand.setProgress(sizeLand - 3); builder.setView(parent); builder.setPositiveButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { SharedPreferences.Editor editor = pref.edit(); editor.putInt("grid_size_port", seekPort.getProgress() + 3); editor.putInt("grid_size_land", seekLand.getProgress() + 3).apply(); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { int val = seekPort.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } else if (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { int val = seekLand.getProgress() + 3; layoutManager.setSpanCount(val); callback.onGridSpanChanged(type, val); } } }); builder.show(); return true; } }); }
From source file:org.openremote.android.console.GroupActivity.java
/** * If there have global or local tabbar, create and update menu before the menu is shown. * /*w w w. ja va 2 s.c o m*/ * @see android.app.Activity#onPrepareOptionsMenu(android.view.Menu) */ @Override public boolean onPrepareOptionsMenu(Menu menu) { if (currentGroupView == null || currentGroupView.getGroup() == null) { return true; } TabBar tabBar = currentGroupView.getGroup().getTabBar(); if (tabBar == null) { tabBar = XMLEntityDataBase.globalTabBar; } if (tabBar != null && tabBar.getTabBarItems().size() > 0) { menu.clear(); ArrayList<TabBarItem> items = tabBar.getTabBarItems(); int itemSize = items.size(); for (int i = 0; i < itemSize; i++) { MenuItem menuItem = menu.add(0, i, i, items.get(i).getName()); if (items.get(i).getImage() != null) { menuItem.setIcon(ImageUtil .createFromPathQuietly(Constants.FILE_FOLDER_PATH + items.get(i).getImage().getSrc())); } final Navigate navigate = items.get(i).getNavigate(); if (navigate != null) { menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { handleNavigate(navigate); return true; } }); } } } return true; }
From source file:org.readium.sdk.android.biblemesh.WebViewActivity.java
@Override public void onActionModeStarted(ActionMode mode) { if (mActionMode == null) { mActionMode = mode;/*from w ww. ja v a 2s.c o m*/ Menu menu = mode.getMenu(); // Remove the default menu items (select all, copy, paste, search) menu.clear(); // If you want to keep any of the defaults, // remove the items you don't want individually: // menu.removeItem(android.R.id.[id_of_item_to_remove]) // Inflate your own menu items mode.getMenuInflater().inflate(R.menu.context_menu, menu); MenuItem item = menu.findItem(R.id.highlight_item); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { mReadiumJSApi.highlightSelection(); return true; } }); } super.onActionModeStarted(mode); }
From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // This is a hack to give the longclick handler time // to find the word the user long clicked on. if (this.selectedWord != null) { final CharSequence word = this.selectedWord; String header = String.format(getString(R.string.word_select), selectedWord); menu.setHeaderTitle(header);/*w w w . j a v a2s. c om*/ final Intent intent = new Intent(PICK_RESULT_ACTION); intent.putExtra(EXTRA_QUERY, word.toString()); // Search Query intent.putExtra(EXTRA_FULLSCREEN, false); // intent.putExtra(EXTRA_HEIGHT, 400); // 400pixel, if you don't // specify, fill_parent" intent.putExtra(EXTRA_GRAVITY, Gravity.BOTTOM); intent.putExtra(EXTRA_MARGIN_LEFT, 100); if (isIntentAvailable(this, intent)) { MenuItem item = menu.add(getString(R.string.dictionary_lookup)); item.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { startActivityForResult(intent, 5); return true; } }); } MenuItem newItem = menu.add(getString(R.string.wikipedia_lookup)); newItem.setOnMenuItemClickListener(new BrowserSearchMenuItem( "http://en.wikipedia.org/wiki/Special:Search?search=" + URLEncoder.encode(word.toString()))); MenuItem newItem2 = menu.add(getString(R.string.google_lookup)); newItem2.setOnMenuItemClickListener(new BrowserSearchMenuItem( "http://www.google.com/search?q=" + URLEncoder.encode(word.toString()))); this.selectedWord = null; } }
From source file:com.android.contacts.activities.DialtactsActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.dialtacts_options, menu); // set up intents and onClick listeners final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings); final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar); final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option); final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact); callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent()); searchMenuItem.setOnMenuItemClickListener(mSearchMenuItemClickListener); filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener); addContactOptionMenuItem.setIntent(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); return true;/* ww w .j a v a2s . co m*/ }
From source file:net.wequick.small.webkit.WebActivity.java
private void addMenuItem(HashMap<String, String> content, boolean isMore) { MenuItem menuItem; do {//from w ww.j a va 2 s .co m String type = content.get("type"); // Text without icon if (type == null) { String title = content.get("title"); menuItem = mOptionsMenu.add(0, 0, 0, title); break; } Drawable icon = null; // TODO: Export interface to get user defined icon if (icon != null) { menuItem = mOptionsMenu.add(0, 0, 0, null).setIcon(icon); break; } // Android system icon int iconRes = android.R.drawable.ic_menu_info_details; if (type.equals("share")) { iconRes = android.R.drawable.ic_menu_share; } else if (type.equals("add")) { iconRes = android.R.drawable.ic_menu_add; } else if (type.equals("more")) { iconRes = android.R.drawable.ic_menu_more; } // TODO: Add more menuItem = mOptionsMenu.add(0, 0, 0, null).setIcon(iconRes); } while (false); int showType = isMore ? MenuItemCompat.SHOW_AS_ACTION_NEVER : MenuItemCompat.SHOW_AS_ACTION_ALWAYS; MenuItemCompat.setShowAsAction(menuItem, showType); final String onclick = content.get("onclick"); if (onclick != null) { menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (mWebView != null) { mWebView.loadJs(onclick); } return true; } }); } }
From source file:app.sunstreak.yourpisd.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.main_activity, menu); // 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 == session.studentIndex) item.setEnabled(false);// w ww.ja va 2 s .co m item.setOnMenuItemClickListener(new StudentChooserListener(i)); item.setVisible(true); } } return super.onCreateOptionsMenu(menu); }
From source file:org.woltage.irssiconnectbot.ConsoleActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); View view = findCurrentView(R.id.console_flip); final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); final boolean activeTerminal = (view instanceof TerminalView); boolean sessionOpen = false; boolean disconnected = false; boolean canForwardPorts = false; if (activeTerminal) { TerminalBridge bridge = ((TerminalView) view).bridge; sessionOpen = bridge.isSessionOpen(); disconnected = bridge.isDisconnected(); canForwardPorts = bridge.canFowardPorts(); }/*from ww w.j ava2 s. c o m*/ menu.setQwertyMode(true); disconnect = menu.add(R.string.list_host_disconnect); if (hardKeyboard) disconnect.setAlphabeticShortcut('w'); if (!sessionOpen && disconnected) disconnect.setTitle(R.string.console_menu_close); disconnect.setEnabled(activeTerminal); disconnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel); disconnect.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // disconnect or close the currently visible session TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; bridge.dispatchDisconnect(true); if (bound != null && prefs.getBoolean("unloadKeysOnDisconnect", true)) { bound.lockUnusedKeys(); } return true; } }); copy = menu.add(R.string.console_menu_copy); if (hardKeyboard) copy.setAlphabeticShortcut('c'); copy.setIcon(android.R.drawable.ic_menu_set_as); copy.setEnabled(activeTerminal); copy.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // mark as copying and reset any previous bounds TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); copySource = terminalView.bridge; SelectionArea area = copySource.getSelectionArea(); area.reset(); area.setBounds(copySource.buffer.getColumns(), copySource.buffer.getRows()); area.setRow(copySource.buffer.getCursorRow()); area.setColumn(copySource.buffer.getCursorColumn()); copySource.setSelectingForCopy(true); // Make sure we show the initial selection copySource.redraw(); Toast.makeText(ConsoleActivity.this, getString(R.string.console_copy_start), Toast.LENGTH_LONG) .show(); return true; } }); paste = menu.add(R.string.console_menu_paste); if (hardKeyboard) paste.setAlphabeticShortcut('v'); paste.setIcon(android.R.drawable.ic_menu_edit); paste.setEnabled(clipboard.hasText() && sessionOpen); paste.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // force insert of clipboard text into current console TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; // pull string from clipboard and generate all events to force // down String clip = clipboard.getText().toString(); bridge.injectString(clip); return true; } }); portForward = menu.add(R.string.console_menu_portforwards); if (hardKeyboard) portForward.setAlphabeticShortcut('f'); portForward.setIcon(android.R.drawable.ic_menu_manage); portForward.setEnabled(sessionOpen && canForwardPorts); portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); TerminalBridge bridge = terminalView.bridge; Intent intent = new Intent(ConsoleActivity.this, PortForwardListActivity.class); intent.putExtra(Intent.EXTRA_TITLE, bridge.host.getId()); ConsoleActivity.this.startActivityForResult(intent, REQUEST_EDIT); return true; } }); urlscan = menu.add(R.string.console_menu_urlscan); if (hardKeyboard) urlscan.setAlphabeticShortcut('u'); urlscan.setIcon(android.R.drawable.ic_menu_search); urlscan.setEnabled(activeTerminal); urlscan.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminal = (TerminalView) findCurrentView(R.id.console_flip); TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.urlScan(terminal); return true; } }); resize = menu.add(R.string.console_menu_resize); if (hardKeyboard) resize.setAlphabeticShortcut('s'); resize.setIcon(android.R.drawable.ic_menu_crop); resize.setEnabled(sessionOpen); resize.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminalView = (TerminalView) findCurrentView(R.id.console_flip); final View resizeView = inflater.inflate(R.layout.dia_resize, null, false); ((EditText) resizeView.findViewById(R.id.width)) .setText(prefs.getString("default_fsize_width", "80")); ((EditText) resizeView.findViewById(R.id.height)) .setText(prefs.getString("default_fsize_height", "25")); new AlertDialog.Builder(ConsoleActivity.this).setView(resizeView) .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int width, height; try { width = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.width)).getText().toString()); height = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.height)).getText().toString()); } catch (NumberFormatException nfe) { // TODO change this to a real dialog where we can // make the input boxes turn red to indicate an error. return; } if (width > 0 && height > 0) { terminalView.forceSize(width, height); terminalView.bridge.parentChanged(terminalView); } else { new AlertDialog.Builder(ConsoleActivity.this) .setMessage("Width and height must be higher than zero.") .setTitle("Error").show(); } } }).setNegativeButton(android.R.string.cancel, null).create().show(); return true; } }); MenuItem ctrlKey = menu.add("Ctrl"); ctrlKey.setEnabled(activeTerminal); ctrlKey.setIcon(R.drawable.button_ctrl); MenuItemCompat.setShowAsAction(ctrlKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); ctrlKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.metaPress(TerminalKeyListener.META_CTRL_ON); terminal.bridge.tryKeyVibrate(); return true; } }); MenuItem escKey = menu.add("Esc"); escKey.setEnabled(activeTerminal); escKey.setIcon(R.drawable.button_esc); MenuItemCompat.setShowAsAction(escKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); escKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.sendEscape(); terminal.bridge.tryKeyVibrate(); return true; } }); MenuItem symKey = menu.add("SYM"); symKey.setEnabled(activeTerminal); symKey.setIcon(R.drawable.button_sym); MenuItemCompat.setShowAsAction(symKey, MenuItem.SHOW_AS_ACTION_IF_ROOM); symKey.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; TerminalView terminal = (TerminalView) flip; TerminalKeyListener handler = terminal.bridge.getKeyHandler(); handler.showCharPickerDialog(terminal); return true; } }); MenuItem inputButton = menu.add("Input"); inputButton.setEnabled(activeTerminal); inputButton.setIcon(R.drawable.button_input); MenuItemCompat.setShowAsAction(inputButton, MenuItem.SHOW_AS_ACTION_IF_ROOM); inputButton.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; final TerminalView terminal = (TerminalView) flip; Thread promptThread = new Thread(new Runnable() { public void run() { String inj = getCurrentPromptHelper().requestStringPrompt(null, ""); terminal.bridge.injectString(inj); } }); promptThread.setName("Prompt"); promptThread.setDaemon(true); promptThread.start(); return true; } }); MenuItem keyboard = menu.add("Show Keyboard"); keyboard.setEnabled(activeTerminal); keyboard.setIcon(R.drawable.button_keyboard); MenuItemCompat.setShowAsAction(keyboard, MenuItem.SHOW_AS_ACTION_IF_ROOM); keyboard.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { View flip = findCurrentView(R.id.console_flip); if (flip == null) return false; inputManager.showSoftInput(flip, InputMethodManager.SHOW_FORCED); return true; } }); MenuItem keys = menu.add(R.string.console_menu_pubkeys); keys.setIcon(android.R.drawable.ic_lock_lock); keys.setIntent(new Intent(this, PubkeyListActivity.class)); keys.setEnabled(activeTerminal); keys.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(ConsoleActivity.this, PubkeyListActivity.class); intent.putExtra(PubkeyListActivity.PICK_MODE, true); ConsoleActivity.this.startActivityForResult(intent, REQUEST_SELECT); return true; } }); return true; }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo; final RowBase row = (RowBase) getListAdapter().getItem(adapterContextMenuInfo.position); final android.view.MenuItem addToWordlist = menu.add(getString(R.string.addToWordList, wordList.getName())); addToWordlist.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(android.view.MenuItem item) { onAppendToWordList(row);//from w w w . j ava 2 s. com return false; } }); final android.view.MenuItem share = menu.add("Share"); share.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(android.view.MenuItem item) { Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, row.getTokenRow(true).getToken()); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, row.getRawText(saveOnlyFirstSubentry)); startActivity(shareIntent); return false; } }); final android.view.MenuItem copy = menu.add(android.R.string.copy); copy.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(android.view.MenuItem item) { onCopy(row); return false; } }); if (selectedSpannableText != null) { final String selectedText = selectedSpannableText; final android.view.MenuItem searchForSelection = menu .add(getString(R.string.searchForSelection, selectedSpannableText)); searchForSelection.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(android.view.MenuItem item) { jumpToTextFromHyperLink(selectedText, selectedSpannableIndex); return false; } }); // Rats, this won't be shown: //searchForSelection.setIcon(R.drawable.abs__ic_search); } if ((row instanceof TokenRow || selectedSpannableText != null) && ttsReady) { final android.view.MenuItem speak = menu.add(R.string.speak); final String textToSpeak = row instanceof TokenRow ? ((TokenRow) row).getToken() : selectedSpannableText; updateTTSLanguage(row instanceof TokenRow ? indexIndex : selectedSpannableIndex); speak.setOnMenuItemClickListener(new android.view.MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(android.view.MenuItem item) { textToSpeech.speak(textToSpeak, TextToSpeech.QUEUE_FLUSH, new HashMap<String, String>()); return false; } }); } }
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { this.getMenuInflater().inflate(R.menu.toolbar_menu, menu); //clear button MenuItem item = menu.findItem(R.id.clear_btn); if (item != null) { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override/*from w w w.ja v a 2s. c om*/ public boolean onMenuItemClick(MenuItem item) { clearAdapter(); return true; } }); } //bluetoooth scan button item = menu.findItem(R.id.scan_btn); if (item != null) { item.setIcon(R.drawable.ic_action_scanning); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleScan(item); return true; } }); } //bluetooth state button item = menu.findItem(R.id.state_bt_btn); if (item != null) { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { toggleBtState(); return true; } }); if (mBluetoothAdapter.isEnabled()) { item.setIcon(R.drawable.ic_bluetooth); } else { item.setIcon(R.drawable.ic_bluetooth_disabled); } } //reset snoop file button if (Build.VERSION.SDK_INT <= 22) { item = menu.findItem(R.id.reset_snoop_file); item.setVisible(true); if (item != null) { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { resetSnoopFile(); refresh(); return true; } }); } } //filter button item = menu.findItem(R.id.filter_btn); if (item != null) { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { filter(); return true; } }); } //refresh button item = menu.findItem(R.id.refresh); if (item != null) { if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT) { item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { refresh(); return true; } }); } else { item.setVisible(false); } } item = menu.findItem(R.id.share); if (item != null) { // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item); setSharedIntent(); } return super.onCreateOptionsMenu(menu); }