@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { MenuItem item = menu.add(Menu.NONE, MENU_DISCARD, MENU_DISCARD, R.string.rate_offline_discard); item.setIcon(R.drawable.ic_action_discard); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); super.onCreateOptionsMenu(menu, inflater); }
protected void addMenuItem(Menu menu, int title, int imageRes, int id, boolean showAsAction) { AstridActivity activity = (AstridActivity) getActivity(); if ((activity.getFragmentLayout() != AstridActivity.LAYOUT_SINGLE && showAsAction) || !(activity instanceof TaskListActivity)) { MenuItem item = menu.add(Menu.NONE, id, Menu.NONE, title); item.setIcon(imageRes); if (activity instanceof TaskListActivity) item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); } else { ((TaskListActivity) activity).getMainMenuPopover().addMenuItem(title, imageRes, id); } }
protected void addMenuItem( Menu menu, CharSequence title, Drawable image, Intent customIntent, int id) { Activity activity = getActivity(); if (activity instanceof TaskListActivity) { ((TaskListActivity) activity) .getMainMenuPopover() .addMenuItem(title, image, customIntent, id); } else { MenuItem item = menu.add(Menu.NONE, id, Menu.NONE, title); item.setIcon(image); item.setIntent(customIntent); } }
// Menu stuff @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(R.string.add_account) .setIcon(android.R.drawable.ic_menu_add) .setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { startActivityForResult( new Intent(getActivity(), WizardChooser.class), CHOOSE_WIZARD); return true; } }) .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menu.add(R.string.reorder) .setIcon(android.R.drawable.ic_menu_sort_by_size) .setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { AccountsEditListAdapter ad = (AccountsEditListAdapter) getListAdapter(); ad.toggleDraggable(); return true; } }) .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); menu.add(R.string.backup_restore) .setIcon(android.R.drawable.ic_menu_save) .setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // Populate choice list List<String> items = new ArrayList<String>(); items.add(getResources().getString(R.string.backup)); final File backupDir = PreferencesWrapper.getConfigFolder(getActivity()); if (backupDir != null) { String[] filesNames = backupDir.list(); for (String fileName : filesNames) { items.add(fileName); } } final String[] fItems = (String[]) items.toArray(new String[0]); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.backup_restore); builder.setItems( fItems, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { SipProfileJson.saveSipConfiguration(getActivity()); } else { File fileToRestore = new File(backupDir + File.separator + fItems[item]); SipProfileJson.restoreSipConfiguration(getActivity(), fileToRestore); } } }); builder.setCancelable(true); AlertDialog backupDialog = builder.create(); backupDialog.show(); return true; } }); super.onCreateOptionsMenu(menu, inflater); }