List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
From source file:com.android.music.MusicBrowserActivity.java
/** * M: Create fake menu.//w w w . j a v a 2s .c o m */ private void createFakeMenu() { if (mPermissionReqProcessed == true) { if (mHasMenukey) { MusicLogUtils.d(TAG, "createFakeMenu Quit when there has Menu Key"); return; } if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) { mOverflowMenuButtonId = R.id.overflow_menu; mOverflowMenuButton = findViewById(R.id.overflow_menu); } else { mOverflowMenuButtonId = R.id.overflow_menu_nowplaying; mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying); View parent = (View) mOverflowMenuButton.getParent(); if (parent != null) { parent.setVisibility(View.VISIBLE); } } mOverflowMenuButton.setVisibility(View.VISIBLE); mOverflowMenuButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MusicLogUtils.d(TAG, "createFakeMenu:onClick()"); if (v.getId() == mOverflowMenuButtonId) { final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton); mPopupMenu = popupMenu; final Menu menu = popupMenu.getMenu(); onCreateOptionsMenu(menu); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); popupMenu.setOnDismissListener(new OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopupMenuShowing = false; MusicLogUtils.d(TAG, "createFakeMenu:onDismiss() called"); return; } }); onPrepareOptionsMenu(menu); mPopupMenuShowing = true; if (popupMenu != null) { MusicLogUtils.d(TAG, "createFakeMenu:popupMenu.show()"); 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);/*from www . j a va 2s . 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:com.atlas.mars.weatherradar.MainActivity.java
@Override public void onClick(View v) { final View _v = v; final MainActivity mainActivity = this; switch (v.getId()) { case R.id.buttonReload: /* MyFragment myFragment = (MyFragment)fragmetMap.get(posinion);// (MyFragment)pager.getChildAt(posinion); myFragment.reloadImg();*/ mapFragments.get(posinion).reloadImg(); // reloadImg(); break;//from ww w .j av a 2s .c o m case R.id.buttonMenu: PopupMenu popupMenu = new PopupMenu(this, v); popupMenu.inflate(R.menu.menu_main); popupMenu.show(); popupMenu.setOnMenuItemClickListener(this); break; } }
From source file:com.easemob.chatuidemo.activity.main.MainActivity.java
/** * ?//from www.jav a 2s.c o m */ private void initView() { tvMessage = (TextView) findViewById(R.id.user_message); unreadLabel = (TextView) findViewById(R.id.unread_msg_number); unreadAddressLable = (TextView) findViewById(R.id.unread_msg_number_main); mTabs = new Button[3]; mTabs[0] = (Button) findViewById(R.id.btn_schoolyard); mTabs[1] = (Button) findViewById(R.id.btn_seikatsu); mTabs[2] = (Button) findViewById(R.id.btn_setting); registerForContextMenu(mTabs[1]); tvMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(MainActivity.this, MessageActivity.class); intent.putExtra("invitenum", mInviteNum); intent.putExtra("chatnum", mChatNum); startActivityForResult(intent, 301); } }); tvMemu = (TextView) findViewById(R.id.user_menu); popupMenu = new PopupMenu(this, tvMemu); menu = popupMenu.getMenu(); tvMemu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupMenu.show(); } }); menu.add(Menu.NONE, Menu.FIRST + 0, 0, ""); menu.add(Menu.NONE, Menu.FIRST + 1, 1, ""); menu.add(Menu.NONE, Menu.FIRST + 2, 2, "?"); MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.popupmenu, menu); // ? popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case Menu.FIRST + 0: Intent intent = new Intent(MainActivity.this, UserProfileActivity.class); intent.putExtra("username", EMChatManager.getInstance().getCurrentUser()); intent.putExtra("nick", DemoApplication.getInstance().getNick()); intent.putExtra("setting", true); startActivity(intent); break; case Menu.FIRST + 1: logout(); break; case Menu.FIRST + 2: intent = new Intent(MainActivity.this, RegisterActivity.class); intent.putExtra("action", "update"); startActivity(intent); break; default: break; } return false; } }); }
From source file:com.tlongdev.bktf.util.Utility.java
public static PopupMenu createItemPopupMenu(final Activity activity, View anchor, final Item item) { PopupMenu menu = new PopupMenu(activity, anchor); menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu()); menu.getMenu().findItem(R.id.favorite) .setTitle(isFavorite(activity, item) ? "Remove from favorites" : "Add to favorites"); menu.getMenu().findItem(R.id.calculator).setEnabled(!isInCalculator(activity, item)); menu.setOnMenuItemClickListener(new android.widget.PopupMenu.OnMenuItemClickListener() { @Override/* w w w. j a v a 2 s .c o m*/ public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.history: Intent i = new Intent(activity, PriceHistoryActivity.class); i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item); activity.startActivity(i); break; case R.id.favorite: if (isFavorite(activity, item)) { removeFromFavorites(activity, item); } else { addToFavorites(activity, item); } break; case R.id.calculator: addToCalculator(activity, item); menuItem.setEnabled(false); break; case R.id.backpack_tf: CustomTabActivityHelper.openCustomTab(activity, new CustomTabsIntent.Builder().build(), Uri.parse(item.getBackpackTfUrl()), new WebViewFallback()); break; case R.id.wiki: CustomTabActivityHelper.openCustomTab(activity, new CustomTabsIntent.Builder().build(), Uri.parse(item.getTf2WikiUrl()), new WebViewFallback()); break; } return true; } }); return menu; }
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 . j a v a2 s . c om 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.example.javier.MaterialDesignApp.PlayerActivity.java
public void showVideoPopup(View v) { PopupMenu popup = new PopupMenu(this, v); configurePopupWithTracks(popup, null, DemoPlayer.TYPE_VIDEO); popup.show();//from w w w . j a va2s . co m }
From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java
public void showAudioPopup(View v) { PopupMenu popup = new PopupMenu(this, v); Menu menu = popup.getMenu();/* w ww. j a va2 s . c om*/ menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio); final MenuItem backgroundAudioItem = menu.findItem(0); backgroundAudioItem.setCheckable(true); backgroundAudioItem.setChecked(enableBackgroundAudio); OnMenuItemClickListener clickListener = new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item == backgroundAudioItem) { enableBackgroundAudio = !item.isChecked(); return true; } return false; } }; configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO); popup.show(); }
From source file:com.tct.mail.browse.MessageAttachmentBar.java
private boolean onClick(final int res, final View v) { if (res == R.id.preview_attachment) { previewAttachment();/*w w w . ja va 2s . co m*/ } else if (res == R.id.save_attachment) { if (mAttachment.canSave()) { //TS: jian.xu 2016-01-20 EMAIL FEATURE-1477377 MOD_S //Note: provide an activity for user to select the location to save attachment. /* // TS: zhaotianyong 2015-01-29 EMAIL BUGFIX-916938 MOD_S // TS: Gantao 2015-06-24 EMAIL BUGFIX-1029228 MOD_S String emlAttAuth = mContext.getResources().getString(R.string.eml_attachment_provider); if (mAttachment.contentUri!=null && mAttachment.contentUri.getAuthority().equals(emlAttAuth)) { if (PermissionUtil.checkAndRequestStoragePermission(mContext)) { mActionHandler.startDownloadingAttachment(AttachmentDestination.EXTERNAL); mSaveClicked = true; } else { //TS: jian.xu 2015-12-29 EMAIL BUGFIX-1240340 ADD_S if (mContext instanceof BaseActivity){ ((BaseActivity) mContext).registerPermissionResultListener(this); } } //TS: jian.xu 2015-12-29 EMAIL BUGFIX-1240340 ADD_E } else { if (PermissionUtil.checkAndRequestStoragePermission(mContext)) { mActionHandler.startDownloadingAttachment(AttachmentDestination.CACHE); mSaveClicked = true; } else { //TS: jian.xu 2015-12-29 EMAIL BUGFIX-1240340 ADD_S if (mContext instanceof BaseActivity){ ((BaseActivity) mContext).registerPermissionResultListener(this); } } //TS: jian.xu 2015-12-29 EMAIL BUGFIX-1240340 ADD_E } // TS: Gantao 2015-06-24 EMAIL BUGFIX-1029228 MOD_E // TS: zhaotianyong 2015-01-29 EMAIL BUGFIX-916938 MOD_E */ boolean saveWay = PLFUtils.getBoolean(getContext(), "feature_email_saveAttachmentLocationSelectable_on"); if (saveWay) { saveAttachmentWithLocationSelectable(); } else { saveAttachmentAutomatic(); } //TS: jian.xu 2016-01-20 EMAIL FEATURE-1477377 MOD_E Analytics.getInstance().sendEvent("save_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } } else if (res == R.id.download_again) { if (mAttachment.isPresentLocally()) { //Don't show the dialog for the feature <Horizontal attachment>. // mActionHandler.showDownloadingDialog(); //TS:zhangchao 2015-11-13 EMAIL BUGFIX_1103647 ADD_S if (!AttachmentUtils.canDownloadAttachment(getContext(), mAttachment)) { UiUtilities.showConnectionAlertDialog(mFragmentManager); return true; } //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_S if (mAttachment != null && mAttachment.destination == AttachmentDestination.EXTERNAL) { if (!PermissionUtil.checkAndRequestPermissionForResult(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE, PermissionUtil.REQ_CODE_PERMISSION_REDOWNLOAD_ATTACHMENT)) { if (mContext instanceof BaseActivity) { ((BaseActivity) mContext).registerPermissionResultListener(this); } return true; } } //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_E //TS:zhangchao 2015-11-13 EMAIL BUGFIX_1103647 ADD_E mActionHandler.startRedownloadingAttachment(mAttachment); Analytics.getInstance().sendEvent("redownload_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } } else if (res == R.id.cancel_attachment) { mActionHandler.cancelAttachment(); mSaveClicked = false; Analytics.getInstance().sendEvent("cancel_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } else if (res == R.id.attachment_extra_option1) { mActionHandler.handleOption1(); } else if (res == R.id.overflow) { // If no overflow items are visible, just bail out. // We shouldn't be able to get here anyhow since the overflow // button should be hidden. if (shouldShowOverflow()) { if (mPopup == null) { mPopup = new PopupMenu(getContext(), v); mPopup.getMenuInflater().inflate(R.menu.message_footer_overflow_menu, mPopup.getMenu()); mPopup.setOnMenuItemClickListener(this); } final Menu menu = mPopup.getMenu(); //TS: junwei-xu 2016-04-07 EMAIL BUGFIX-1863570 ADD_S //Note: should change the title for save attachment menu dynamically. boolean saveTo = PLFUtils.getBoolean(getContext(), "feature_email_saveAttachmentLocationSelectable_on"); if (saveTo) { menu.findItem(R.id.save_attachment).setTitle(R.string.save_to_attachment); } else { menu.findItem(R.id.save_attachment).setTitle(R.string.save_attachment); } //TS: junwei-xu 2016-04-07 EMAIL BUGFIX-1863570 ADD_E menu.findItem(R.id.preview_attachment).setVisible(shouldShowPreview()); menu.findItem(R.id.save_attachment).setVisible(shouldShowSave()); menu.findItem(R.id.download_again).setVisible(shouldShowDownloadAgain()); menu.findItem(R.id.attachment_extra_option1).setVisible(shouldShowExtraOption1()); mPopup.show(); } } else { // Handles clicking the attachment // in any area that is not the overflow // button or cancel button or one of the // overflow items. final String mime = Utils.normalizeMimeType(mAttachment.getContentType()); final String action; if ((mAttachment.flags & Attachment.FLAG_DUMMY_ATTACHMENT) != 0) { // This is a dummy. We need to download it, but not attempt to open or preview. //Don't show the dialog for the feature <Horizontal attachment>. // mActionHandler.showDownloadingDialog(); mActionHandler.setViewOnFinish(false); mActionHandler.startDownloadingAttachment(AttachmentDestination.CACHE); action = null; } // If we can install, install. else if (MimeType.isInstallable(mAttachment.getContentType())) { // Save to external because the package manager only handles // file:// uris not content:// uris. We do the same // workaround in // UiProvider#getUiAttachmentsCursorForUIAttachments() //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_S if (!(mAttachment.isPresentLocally() && mAttachment.destination == AttachmentDestination.EXTERNAL) && !PermissionUtil.checkAndRequestPermissionForResult(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE, PermissionUtil.REQ_CODE_PERMISSION_VIEW_ATTACHMENT)) { if (mContext instanceof BaseActivity) { ((BaseActivity) mContext).registerPermissionResultListener(this); } return true; } //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD_E mActionHandler.showAttachment(AttachmentDestination.EXTERNAL); action = "attachment_bar_install"; } // If we can view or play with an on-device app, // view or play. else if (MimeType.isViewable(getContext(), mAttachment.contentUri, mAttachment.getContentType())) { mActionHandler.showAttachment(AttachmentDestination.CACHE); action = "attachment_bar"; } // TS: zhaotianyong 2015-05-19 EMAIL BUGFIX-1006010 DEL // If we can only preview the attachment, preview. else if (mAttachment.canPreview()) { previewAttachment(); action = null; } // TS: zhaotianyong 2015-05-19 EMAIL BUGFIX-1006010 ADD_S // New requirement:even if there is no app can open the attachement, // we can also download it. else if (!mAttachment.isPresentLocally()) { //Don't show the dialog for the feature <Horizontal attachment>. // mActionHandler.showDownloadingDialog(); //TS:zhangchao 2015-11-13 EMAIL BUGFIX_1103647 ADD_S if (!AttachmentUtils.canDownloadAttachment(getContext(), mAttachment)) { UiUtilities.showConnectionAlertDialog(mFragmentManager); return true; } //TS:zhangchao 2015-11-13 EMAIL BUGFIX_1103647 ADD_E mActionHandler.startDownloadingAttachment(AttachmentDestination.CACHE); action = "attachment_bar"; } // TS: zhaotianyong 2015-05-19 EMAIL BUGFIX-1006010 DEL_E // Otherwise, if we cannot do anything, show the info dialog. else { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); int dialogMessage = R.string.no_application_found; builder.setTitle(R.string.more_info_attachment).setMessage(dialogMessage).show(); action = "attachment_bar_no_viewer"; } if (action != null) { Analytics.getInstance().sendEvent("view_attachment", mime, action, mAttachment.size); } } return true; }