List of usage examples for android.widget PopupMenu getMenu
public Menu getMenu()
From source file:com.silentcircle.contacts.editor.RawContactEditorView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void showAddInformationPopupWindow() { final ArrayList<KindSectionView> fields = getSectionViewsWithoutFields(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { showAddInformationPopupWindow(fields); } else {/*w w w.ja v a 2s. com*/ final PopupMenu popupMenu = new PopupMenu(getContext(), mAddFieldButton); final Menu menu = popupMenu.getMenu(); for (int i = 0; i < fields.size(); i++) { menu.add(Menu.NONE, i, Menu.NONE, fields.get(i).getTitle()); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { final KindSectionView view = fields.get(item.getItemId()); if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(view.getKind().mimeType)) { mPhoneticNameAdded = true; updatePhoneticNameVisibility(); } else { view.addItem(); } // If this was the last section without an entry, we just added one, and therefore // there's no reason to show the button. if (fields.size() == 1) { mAddFieldButton.setVisibility(GONE); } return true; } }); popupMenu.show(); } }
From source file:com.zigvine.zagriculture.UIActivity.java
@TargetApi(11) private void showPopupMenu() { final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton); final Menu menu = popupMenu.getMenu(); // popupMenu.inflate(R.menu.main_menu); popupMenu.getMenuInflater().inflate(R.menu.main_menu, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* w w w . j ava2s . c om*/ public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); onPrepareOptionsMenu(menu); if (popupMenu != null) { popupMenu.show(); } }
From source file:com.untappedkegg.rally.home.ActivityMain.java
public void onScheduleMenuClick(View v) { menuView = ((View) v.getParent().getParent()); final boolean isFinished = DbSchedule .isEventFinished(((TextView) menuView.findViewById(R.id.sched_id)).getText().toString()); final String date = ((TextView) menuView.findViewById(R.id.sched_date)).getText().toString(); PopupMenu popup = new PopupMenu(this, v); popup.inflate(R.menu.schedule);/* ww w . j ava 2 s. com*/ if (AppState.isNullOrEmpty(((TextView) menuView.findViewById(R.id.sched_website)).getText().toString())) { popup.getMenu().removeItem(R.id.menu_schedule_website); } if (!isFinished) { popup.getMenu().removeItem(R.id.menu_schedule_photos); } if (isFinished || "TBD".equalsIgnoreCase(date) || "CANCELLED".equalsIgnoreCase(date)) { popup.getMenu().removeItem(R.id.menu_schedule_add_to_cal); } popup.setOnMenuItemClickListener(this); popup.show(); }
From source file:org.apache.cordova.navigationmenu.NavigationMenu.java
/** * Displays popup menu.// w w w . j av a 2s .c o m * * @param items The array of objects which describes menu items. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void showPopup(JSONArray items) { final PopupMenu popup = new PopupMenu(this.webView.getContext(), this.webView); PopupMenu.OnMenuItemClickListener handler = new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { int itemId = item.getItemId(); webView.sendJavascript("menu.popupItemClick && menu.popupItemClick(" + itemId + ");"); return false; } }; popup.setOnMenuItemClickListener(handler); Menu popupMenu = popup.getMenu(); for (int i = 0; i < items.length(); i++) { JSONObject menuItem = items.optJSONObject(i); if (menuItem != null) { appendItem(popupMenu, menuItem); } } this.cordova.getActivity().runOnUiThread(new Runnable() { public void run() { popup.show(); } }); }
From source file:org.alfresco.mobile.android.application.fragments.node.browser.ProgressNodeAdapter.java
@Override protected void updateIcon(TwoLinesProgressViewHolder vh, Node item) { if (item instanceof NodePlaceHolder) { UIUtils.setBackground(vh.icon, null); vh.icon.setImageResource(MimeTypeManager.getInstance(getActivity()).getIcon(item.getName())); vh.choose.setVisibility(View.GONE); return;//from w w w .j av a 2 s . c om } else { super.updateIcon(vh, item); } if ((selectedItems != null && selectedItems.contains(item)) || (selectedMapItems != null && selectedMapItems.containsKey(item.getIdentifier()))) { if (getFragment() != null && getFragment() instanceof DocumentFolderBrowserFragment && ((DocumentFolderBrowserFragment) getFragment()).hasActionMode()) { vh.choose.setVisibility(View.VISIBLE); vh.choose.setImageResource(R.drawable.ic_done_single_white); int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); UIUtils.setBackground(vh.choose, null); vh.choose.setOnClickListener(null); } } else if (item.isFolder()) { vh.icon.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.mime_256_folder)); if (mode == ListingModeFragment.MODE_IMPORT) { return; } if (mode == ListingModeFragment.MODE_PICK) { return; } vh.choose.setImageResource(R.drawable.ic_more_options); vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light); int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16); vh.choose.setPadding(d_16, d_16, d_16, d_16); vh.choose.setVisibility(View.VISIBLE); AccessibilityUtils.addContentDescription(vh.choose, String.format(getActivity().getString(R.string.more_options_folder), item.getName())); vh.choose.setTag(R.id.node_action, item); vh.choose.setOnClickListener(new OnClickListener() { @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public void onClick(View v) { Node item = (Node) v.getTag(R.id.node_action); if (item == null) { return; } selectedOptionItems.add(item); PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), item); popup.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { selectedOptionItems.clear(); } }); popup.setOnMenuItemClickListener(ProgressNodeAdapter.this); popup.show(); } }); } else { UIUtils.setBackground(vh.choose, null); vh.choose.setPadding(0, 0, 0, 0); vh.choose.setVisibility(View.GONE); } }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
private void setWatchedToggleState(int unwatchedEpisodes) { mWatchedAllEpisodes = unwatchedEpisodes == 0; mButtonWatchedAll.setImageResource(mWatchedAllEpisodes ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchedAll) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchAll)); // set onClick listener not before here to avoid unexpected actions mButtonWatchedAll.setOnClickListener(new OnClickListener() { @Override// w ww. j a va 2 s . c o m public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); if (mWatchedAllEpisodes) { popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_NONE_ID, 0, R.string.unmark_all); } else { popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_ALL_ID, 0, R.string.mark_all); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_WATCHED_SHOW_ALL_ID: { onFlagShowWatched(true); fireTrackerEvent("Flag all watched (inline)"); return true; } case CONTEXT_WATCHED_SHOW_NONE_ID: { onFlagShowWatched(false); fireTrackerEvent("Flag all unwatched (inline)"); return true; } } return false; } }); popupMenu.show(); } }); CheatSheet.setup(mButtonWatchedAll, mWatchedAllEpisodes ? R.string.unmark_all : R.string.mark_all); }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
private void setCollectedToggleState(int uncollectedEpisodes) { mCollectedAllEpisodes = uncollectedEpisodes == 0; mButtonCollectedAll.setImageResource(mCollectedAllEpisodes ? R.drawable.ic_collected_all : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollectAll)); // set onClick listener not before here to avoid unexpected actions mButtonCollectedAll.setOnClickListener(new OnClickListener() { @Override//from w w w. j a v a 2 s . com public void onClick(View v) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); if (mCollectedAllEpisodes) { popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_NONE_ID, 0, R.string.uncollect_all); } else { popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_ALL_ID, 0, R.string.collect_all); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_COLLECTED_SHOW_ALL_ID: { onFlagShowCollected(true); fireTrackerEvent("Flag all collected (inline)"); return true; } case CONTEXT_COLLECTED_SHOW_NONE_ID: { onFlagShowCollected(false); fireTrackerEvent("Flag all uncollected (inline)"); return true; } } return false; } }); popupMenu.show(); } }); CheatSheet.setup(mButtonCollectedAll, mCollectedAllEpisodes ? R.string.uncollect_all : R.string.collect_all); }
From source file:org.catnut.adapter.TweetAdapter.java
private void showPopupMenu(View view) { final Bean bean = (Bean) view.getTag(); PopupMenu popup = new PopupMenu(mContext, view); Menu menu = popup.getMenu(); popup.getMenuInflater().inflate(R.menu.tweet_overflow, menu); MenuItem item = menu.findItem(R.id.action_favorite); item.setTitle(bean.favorited ? R.string.cancle_favorite : R.string.favorite); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// w w w.j a va 2 s .co m public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_favorite: mRequestQueue.add(new CatnutRequest(mContext, bean.favorited ? FavoritesAPI.destroy(bean.id) : FavoritesAPI.create(bean.id), new StatusProcessor.FavoriteTweetProcessor(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Toast.makeText(mContext, bean.favorited ? R.string.cancle_favorite_success : R.string.favorite_success, Toast.LENGTH_SHORT).show(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error); Toast.makeText(mContext, weiboAPIError.error, Toast.LENGTH_LONG).show(); } })); break; case R.id.action_like: Toast.makeText(mContext, "sina not provide this option...", Toast.LENGTH_SHORT).show(); break; case android.R.id.copy: CatnutUtils.copy2ClipBoard(mContext, mContext.getString(R.string.tweet), bean.text, mContext.getString(R.string.tweet_text_copied)); break; default: break; } return false; } }); popup.show(); }
From source file:com.inde.shiningdays.MainActivity.java
private void showPopupMenu() { final View menuItemView = findViewById(R.id.action_menumore); // SAME ID AS MENU ID PopupMenu popupMenu = new PopupMenu(this, menuItemView); popupMenu.inflate(R.menu.more_popup_menu); String currentSortRule = getCurrentSortRule(); if (CountDown.SORT_END_DATE_ASC.equals(currentSortRule)) { popupMenu.getMenu().findItem(R.id.sort_end_date_asc).setChecked(true); } else if (CountDown.DEFAULT_SORT_ORDER.equals(currentSortRule)) { popupMenu.getMenu().findItem(R.id.sort_update_date_desc).setChecked(true); }/*w w w. j a v a2s.com*/ popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { String rule = ""; switch (item.getItemId()) { case R.id.sort_end_date_asc: rule = CountDown.SORT_END_DATE_ASC; updateCurrentSortRule(rule); selectItem(currentTypePosition, rule); return true; case R.id.sort_update_date_desc: rule = CountDown.DEFAULT_SORT_ORDER; updateCurrentSortRule(rule); selectItem(currentTypePosition, rule); return true; case R.id.action_setting: Intent intent = new Intent(menuItemView.getContext(), MenuMore.class); startActivity(intent); default: return true; } } }); popupMenu.show(); }
From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java
@Override public void onTransactionMenuClick(final View view, final Transaction tx) { final boolean txSent = tx.getValue(wallet).signum() < 0; final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet); final byte[] txSerialized = tx.unsafeBitcoinSerialize(); final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION; final PopupMenu popupMenu = new PopupMenu(activity, view); popupMenu.inflate(R.menu.wallet_transactions_context); final MenuItem editAddressMenuItem = popupMenu.getMenu() .findItem(R.id.wallet_transactions_context_edit_address); if (!txRotation && txAddress != null) { editAddressMenuItem.setVisible(true); final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toString()) == null; final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160()); if (isOwn) editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive); else//ww w . j av a 2 s.c o m editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit); } else { editAddressMenuItem.setVisible(false); } popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr) .setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES); popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee) .setVisible(RaiseFeeDialogFragment.feeCanBeRaised(wallet, tx)); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); return true; case R.id.wallet_transactions_context_browse: if (!txRotation) startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(config.getBlockExplorer(), "tx/" + tx.getHashAsString()))); else startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI)); return true; case R.id.wallet_transactions_context_raise_fee: RaiseFeeDialogFragment.show(getFragmentManager(), tx); return true; } return false; } private void handleEditAddress(final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress); } private void handleShowQr() { final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); popupMenu.show(); }