List of usage examples for android.widget PopupMenu setOnMenuItemClickListener
public void setOnMenuItemClickListener(OnMenuItemClickListener listener)
From source file:com.owncloud.android.ui.fragment.FileDetailSharingFragment.java
@OnClick(R.id.overflow_menu_share_link) public void showLinkOverflowMenu() { Context context = getContext(); if (context != null && ThemeUtils.themingEnabled(context)) { // use grey as fallback for elements where custom theming is not available context.getTheme().applyStyle(R.style.FallbackThemingTheme, true); } else {// ww w . j av a 2 s . co m context = getActivity(); } PopupMenu popup = new PopupMenu(context, overflowMenuShareLink); popup.inflate(R.menu.file_detail_sharing_link_menu); prepareOptionsMenu(popup.getMenu()); popup.setOnMenuItemClickListener(this::optionsItemSelected); popup.show(); }
From source file:net.nakama.duckdroid.ui.Duckdroid.java
public void btnshowPopupBang(View view) { PopupMenu p = new PopupMenu(this, view); MenuInflater inflater = p.getMenuInflater(); p.setOnMenuItemClickListener(bangListener); inflater.inflate(this.prefBangMenuId, p.getMenu()); p.show();/*from w w w. j a v a2 s.co m*/ }
From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessClientsTile.java
/** * Called when a previously created loader has finished its load. Note * that normally an application is <em>not</em> allowed to commit fragment * transactions while in this call, since it can happen after an * activity's state is saved. See {@link android.support.v4.app.FragmentManager#beginTransaction() * FragmentManager.openTransaction()} for further discussion on this. * <p/>//w ww.j av a2 s . c o m * <p>This function is guaranteed to be called prior to the release of * the last data that was supplied for this Loader. At this point * you should remove all use of the old data (since it will be released * soon), but should not do your own release of the data since its Loader * owns it and will take care of that. The Loader will take care of * management of its data so you don't have to. In particular: * <p/> * <ul> * <li> <p>The Loader will monitor for changes to the data, and report * them to you through new calls here. You should not monitor the * data yourself. For example, if the data is a {@link android.database.Cursor} * and you place it in a {@link android.widget.CursorAdapter}, use * the {@link android.widget.CursorAdapter#CursorAdapter(android.content.Context, * android.database.Cursor, int)} constructor <em>without</em> passing * in either {@link android.widget.CursorAdapter#FLAG_AUTO_REQUERY} * or {@link android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER} * (that is, use 0 for the flags argument). This prevents the CursorAdapter * from doing its own observing of the Cursor, which is not needed since * when a change happens you will get a new Cursor throw another call * here. * <li> The Loader will release the data once it knows the application * is no longer using it. For example, if the data is * a {@link android.database.Cursor} from a {@link android.content.CursorLoader}, * you should not call close() on it yourself. If the Cursor is being placed in a * {@link android.widget.CursorAdapter}, you should use the * {@link android.widget.CursorAdapter#swapCursor(android.database.Cursor)} * method so that the old Cursor is not closed. * </ul> * * @param loader The Loader that has finished. * @param data The data generated by the Loader. */ @Override public void onLoadFinished(Loader<ClientDevices> loader, ClientDevices data) { Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data); layout.findViewById(R.id.tile_status_wireless_clients_loading_view).setVisibility(View.GONE); layout.findViewById(R.id.tile_status_wireless_clients_layout_list_container).setVisibility(View.VISIBLE); layout.findViewById(R.id.tile_status_wireless_clients_togglebutton_container).setVisibility(View.VISIBLE); if (data == null || (data.getDevices().isEmpty() && !(data.getException() instanceof DDWRTTileAutoRefreshNotAllowedException))) { data = new ClientDevices().setException(new DDWRTNoDataException("No Data!")); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_wireless_clients_error); @Nullable final Exception exception = data.getException(); if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); } final GridLayout clientsContainer = (GridLayout) this.layout .findViewById(R.id.tile_status_wireless_clients_layout_list_container); clientsContainer.removeAllViews(); clientsContainer.setBackgroundColor( mParentFragmentActivity.getResources().getColor(android.R.color.transparent)); final Set<Device> devices = data.getDevices(MAX_CLIENTS_TO_SHOW_IN_TILE); final int themeBackgroundColor = getThemeBackgroundColor(mParentFragmentActivity, mRouter.getUuid()); final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid()); for (final Device device : devices) { final CardView cardView = (CardView) mParentFragmentActivity.getLayoutInflater() .inflate(R.layout.tile_status_wireless_client, null); //Create Options Menu final ImageButton tileMenu = (ImageButton) cardView .findViewById(R.id.tile_status_wireless_client_device_menu); if (!isThemeLight) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); } cardView.setCardBackgroundColor(themeBackgroundColor); //Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners. cardView.setPreventCornerOverlap(true); //Add padding in API v21+ as well to have the same measurements with previous versions. cardView.setUseCompatPadding(true); final TextView deviceName = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_name); final String name = device.getName(); deviceName.setText(name); final TextView deviceMac = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_mac); final String macAddress = device.getMacAddress(); deviceMac.setText(macAddress); final TextView deviceIp = (TextView) cardView .findViewById(R.id.tile_status_wireless_client_device_ip); final String ipAddress = device.getIpAddress(); final boolean isThisDevice = (ipAddress != null && ipAddress.equals(mCurrentIpAddress)); deviceIp.setText(ipAddress); if (isThisDevice) { final View thisDevice = cardView.findViewById(R.id.tile_status_wireless_client_device_this); if (isThemeLight) { //Set text color to blue ((TextView) thisDevice) .setTextColor(mParentFragmentActivity.getResources().getColor(R.color.blue)); } thisDevice.setVisibility(View.VISIBLE); } cardView.setOnClickListener(new DeviceOnClickListener(device)); clientsContainer.addView(cardView); tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(new DeviceOnMenuItemClickListener(device)); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_status_wireless_client_options, menu); if (isThisDevice) { //WOL not needed as this is the current device menu.findItem(R.id.tile_status_wireless_client_wol).setEnabled(false); } popup.show(); } }); } final Button showMore = (Button) this.layout.findViewById(R.id.tile_status_wireless_clients_show_more); //Whether to display 'Show more' button if (data.getDevicesCount() > MAX_CLIENTS_TO_SHOW_IN_TILE) { showMore.setVisibility(View.VISIBLE); showMore.setOnClickListener(this); } else { showMore.setVisibility(View.GONE); } } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); } doneWithLoaderInstance(this, loader, R.id.tile_status_wireless_clients_togglebutton_title, R.id.tile_status_wireless_clients_togglebutton_separator); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:com.giltesa.taskcalendar.activity.Main.java
/** * Desde el metodo onOptionsItemSelected(), se tratan los eventos que produzcan los diferentes Items de los Menus. * Se tratan tanto los eventos del menu del boton fisico como los producidos por el boton del ActionBar. *///from www . j a v a 2 s . c om @SuppressLint("NewApi") public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Se trata el evento del boton Menu, y de sus SubMenus metidos en un PopupMenu: case R.id.main_actionbar_menu: PopupMenu popup = new PopupMenu(this, findViewById(R.id.main_actionbar_menu)); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.main_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.main_menu_newtask: // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity: Intent intent = new Intent(context, NewTask.class); Bundle bundle = new Bundle(); bundle.putBoolean("isNewTask", true); bundle.putInt("positionSlider", mViewPager.getCurrentItem()); intent.putExtra("dataActivity", bundle); startActivityForResult(intent, Main.NEWTASK); return true; case R.id.main_menu_settings: startActivity(new Intent(Main.this, Settings.class)); return true; case R.id.main_menu_exit: finish(); return true; default: return false; } } }); popup.show(); return true; case R.id.main_actionbar_search: return true; case R.id.main_menu_newtask: // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity: Intent intent = new Intent(context, NewTask.class); Bundle bundle = new Bundle(); bundle.putBoolean("isNewTask", true); bundle.putInt("positionSlider", mViewPager.getCurrentItem()); intent.putExtra("dataActivity", bundle); startActivityForResult(intent, Main.NEWTASK); return true; case R.id.main_menu_settings: startActivity(new Intent(Main.this, Settings.class)); return true; case R.id.main_menu_exit: finish(); return true; default: return false; } }
From source file:net.nakama.duckdroid.ui.Duckdroid.java
public void btnshowPopupSetting(View view) { PopupMenu popup = new PopupMenu(this, view); MenuInflater inflater = popup.getMenuInflater(); popup.setOnMenuItemClickListener(this); inflater.inflate(R.menu.activity_duckdroid, popup.getMenu()); popup.show();//from ww w .j av a 2s. c om }
From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { currentFolder = PreferenceHelper.defaultFolder(this); ThemeUtils.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_file); Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar);/*w w w.ja va2s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); //final Actions action = (Actions) getIntent().getExtras().getSerializable("action"); wantAFile = true; //action == Actions.SelectFile; mfabOkMode = false; folderOpenMode = getIntent().getBooleanExtra("foldermode", false); if (folderOpenMode) setTitle("Open Folder"); listView = (ListView) findViewById(android.R.id.list); listView.setOnItemClickListener(this); listView.setTextFilterEnabled(true); mFab = (FloatingActionButton) findViewById(R.id.fabbutton); mFab.setColor(getResources().getColor(R.color.fab_light)); mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add)); mFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mfabOkMode) { PopupMenu popup = new PopupMenu(SelectFileActivity.this, v); popup.getMenuInflater().inflate(R.menu.popup_new_file, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.im_new_file) { EditTextDialog.newInstance(EditTextDialog.Actions.NewFile) .show(getFragmentManager().beginTransaction(), "dialog"); return true; } else if (i == R.id.im_new_folder) { EditTextDialog.newInstance(EditTextDialog.Actions.NewFolder) .show(getFragmentManager().beginTransaction(), "dialog"); return true; } else { return false; } } }); popup.show(); } if (mfabOkMode) { finishWithResult(selectedFile); } } }); mFab.listenTo(listView); String lastNavigatedPath = PreferenceHelper.getWorkingFolder(this); File file = new File(lastNavigatedPath); if (!file.exists()) { PreferenceHelper.setWorkingFolder(this, PreferenceHelper.defaultFolder(this)); file = new File(PreferenceHelper.defaultFolder(this)); } new UpdateList().execute(file.getAbsolutePath()); }
From source file:org.akop.crosswords.fragment.CrosswordFragment.java
@Override public void onCellLongPressed(CrosswordView view, Crossword.Word word, int cell) { // Get the highlighted cell's rectangle Rect rect = view.getCellRect(word, cell); // Offset the placeholder to the same position as the cell FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(rect.width(), rect.height()); lp.setMargins(rect.left, rect.top, 0, 0); mMenuPlaceholder.setLayoutParams(lp); // Save the word/cell associated with the popup mPopupWord = word;/*from ww w . jav a2s . co m*/ mPopupCell = cell; // Initialize and show the popup menu PopupMenu popup = new PopupMenu(getActivity(), mMenuPlaceholder); popup.setOnMenuItemClickListener(mCellPopupListener); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.fragment_crossword_popup_cell, popup.getMenu()); popup.show(); }
From source file:com.google.reviewit.PagedChangeDetailsFragment.java
private void init() { final Change change = getApp().getQueryHandler().getCurrentChange(); checkArgument(change != null, "No change to display"); ChangeEntry changeEntry = new ChangeEntry(getContext()); changeEntry.init(getApp(), change);/*from w w w . j ava 2s .c om*/ vg(R.id.changeHeader).addView(changeEntry); final List<PageFragment> fragments = new ArrayList<>(); CommitMessageFragment commitMessageFragment = new CommitMessageFragment(); commitMessageFragment.setChange(change); fragments.add(commitMessageFragment); FileListFragment fileListFragment = new FileListFragment(); fileListFragment.setChange(change); fragments.add(fileListFragment); ApprovalsFragment approvalsFragment = new ApprovalsFragment(); approvalsFragment.setChange(change); fragments.add(approvalsFragment); ReplyFragment replyFragment = new ReplyFragment(); replyFragment.setChange(change); fragments.add(replyFragment); // TODO add more tabs, e.g. for change messages ViewPager pager = ((ViewPager) v(R.id.pager)); pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) { @Override public Fragment getItem(int position) { return fragments.get(position); } @Override public int getCount() { return fragments.size(); } @Override public CharSequence getPageTitle(int position) { return getString(fragments.get(position).getTitle()); } }); SlidingTabLayout tabs = ((SlidingTabLayout) v(R.id.tabs)); tabs.setTextColor(widgetUtil.color(R.color.tab)); tabs.setSelectedIndicatorColors(widgetUtil.color(R.color.tab)); tabs.setBorderColor(widgetUtil.color(R.color.tab)); tabs.setDividerColors(widgetUtil.color(R.color.tabDivider)); tabs.setBottomBorderThickness(widgetUtil.dpToPx(1)); tabs.setSelectedIndicatorThickness(widgetUtil.dpToPx(5)); tabs.setViewPager(pager); final View more = v(R.id.more); more.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), more); popup.getMenuInflater().inflate(R.menu.menu_paged_change_details, popup.getMenu()); popup.getMenu().findItem(R.id.action_abandon).setVisible( change.info.status == ChangeStatus.NEW || change.info.status == ChangeStatus.SUBMITTED); popup.getMenu().findItem(R.id.action_restore) .setVisible(change.info.status == ChangeStatus.ABANDONED); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_abandon: display(AbandonFragment.create(PagedChangeDetailsFragment.class)); return true; case R.id.action_restore: display(RestoreFragment.create(PagedChangeDetailsFragment.class)); return true; default: return true; } } }); popup.show(); } }); }
From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java
@Override public void onPopupMenuClick(View v, final int seasonTvdbId, final int seasonNumber) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.inflate(R.menu.seasons_popup_menu); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override//from w w w . j a va 2s.c o m public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_seasons_watched_all: { onFlagSeasonWatched(seasonTvdbId, seasonNumber, true); fireTrackerEventContextMenu("Flag all watched"); return true; } case R.id.menu_action_seasons_watched_none: { onFlagSeasonWatched(seasonTvdbId, seasonNumber, false); fireTrackerEventContextMenu("Flag all unwatched"); return true; } case R.id.menu_action_seasons_collection_add: { onFlagSeasonCollected(seasonTvdbId, seasonNumber, true); fireTrackerEventContextMenu("Flag all collected"); return true; } case R.id.menu_action_seasons_collection_remove: { onFlagSeasonCollected(seasonTvdbId, seasonNumber, false); fireTrackerEventContextMenu("Flag all uncollected"); return true; } case R.id.menu_action_seasons_skip: { onFlagSeasonSkipped(seasonTvdbId, seasonNumber); fireTrackerEventContextMenu("Flag all skipped"); return true; } case R.id.menu_action_seasons_manage_lists: { ManageListsDialogFragment.showListsDialog(seasonTvdbId, ListItemTypes.SEASON, getFragmentManager()); fireTrackerEventContextMenu("Manage lists"); return true; } } return false; } }); popupMenu.show(); }
From source file:com.jwetherell.quick_response_code.EncoderActivity.java
@SuppressLint("NewApi") public OnClickListener onclickPopUpMenu(MenuItem item) { //Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(EncoderActivity.this, item.getActionView()); //Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.menu_contextual_wps, popup.getMenu()); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Toast.makeText(EncoderActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show(); return true; }/* w w w .j a v a 2 s. c o m*/ }); popup.show(); //showing popup menu return null; }