List of usage examples for android.widget PopupMenu setOnMenuItemClickListener
public void setOnMenuItemClickListener(OnMenuItemClickListener listener)
From source file:im.vector.fragments.GroupsFragment.java
@SuppressLint("NewApi") private void displayGroupPopupMenu(final Group group, final View actionView) { final Context context = getActivity(); final PopupMenu popup; if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { popup = new PopupMenu(context, actionView, Gravity.END); } else {//from w ww . j a v a2s . co m popup = new PopupMenu(context, actionView); } popup.getMenuInflater().inflate(R.menu.vector_home_group_settings, popup.getMenu()); CommonActivityUtils.tintMenuIcons(popup.getMenu(), ThemeUtils.getColor(context, R.attr.settings_icon_tint_color)); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { switch (item.getItemId()) { case R.id.ic_action_select_remove_group: { leaveOrReject(group.getGroupId()); break; } } return false; } }); // force to display the icon try { Field[] fields = popup.getClass().getDeclaredFields(); for (Field field : fields) { if ("mPopup".equals(field.getName())) { field.setAccessible(true); Object menuPopupHelper = field.get(popup); Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName()); Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class); setForceIcons.invoke(menuPopupHelper, true); break; } } } catch (Exception e) { Log.e(LOG_TAG, "## displayGroupPopupMenu() : failed " + e.getMessage()); } popup.show(); }
From source file:org.alfresco.mobile.android.application.fragments.person.PersonProfileFragment.java
private void display() { TextView tv = null;/* w ww . j av a 2 s . co m*/ ImageView bIm = null; // HEADER tv = (TextView) vRoot.findViewById(R.id.name); tv.setText(person.getFullName()); // JOB TITLE tv = (TextView) vRoot.findViewById(R.id.jobTitle); if (person.getJobTitle() != null && !person.getJobTitle().isEmpty() && person.getCompany() != null && person.getCompany().getName() != null && !person.getCompany().getName().isEmpty()) { tv.setText(String.format(getString(R.string.work_at), person.getJobTitle(), person.getCompany().getName())); } else if (person.getJobTitle() != null) { tv.setText(person.getJobTitle()); } else { tv.setText(person.getCompany().getName()); } // Location tv = (TextView) vRoot.findViewById(R.id.location); tv.setText(person.getLocation()); // Summary displayOrHide(R.id.description, person.getSummary(), R.id.summary_group); // Email displayOrHide(R.id.email_value, person.getEmail(), R.id.email_group); // Telephone displayOrHide(R.id.telephone_value, person.getTelephoneNumber(), R.id.telephone_group); // Mobile displayOrHide(R.id.mobile_value, person.getMobileNumber(), R.id.mobile_group); if (person.getTelephoneNumber() != null || person.getMobileNumber() != null || person.getCompany().getTelephoneNumber() != null) { bIm = (ImageView) vRoot.findViewById(R.id.action_call); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_CALL); popup.setOnMenuItemClickListener(PersonProfileFragment.this); popup.show(); } }); } else { vRoot.findViewById(R.id.action_call).setVisibility(View.GONE); } // SKype if (person.getSkypeId() != null && !person.getSkypeId().isEmpty()) { displayGroup(); tv = (TextView) vRoot.findViewById(R.id.skypeId_value); tv.setText(person.getSkypeId()); bIm = (ImageView) vRoot.findViewById(R.id.action_skype); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_SKYPE); popup.setOnMenuItemClickListener(PersonProfileFragment.this); popup.show(); } }); } else { vRoot.findViewById(R.id.action_skype).setVisibility(View.GONE); vRoot.findViewById(R.id.skypeId_group).setVisibility(View.GONE); } // IM if (person.getInstantMessageId() != null && !person.getInstantMessageId().isEmpty()) { displayGroup(); tv = (TextView) vRoot.findViewById(R.id.instantMessagingId_value); tv.setText(person.getInstantMessageId()); } else { vRoot.findViewById(R.id.instantMessagingId_group).setVisibility(View.GONE); } // Google if (person.getGoogleId() != null && !person.getGoogleId().isEmpty()) { displayGroup(); tv = (TextView) vRoot.findViewById(R.id.googleId_value); tv.setText(person.getGoogleId()); bIm = (ImageView) vRoot.findViewById(R.id.action_im); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionStartIm(getActivity(), person.getGoogleId()); } }); } else { vRoot.findViewById(R.id.action_im).setVisibility(View.GONE); vRoot.findViewById(R.id.googleId_group).setVisibility(View.GONE); } if (!displayContactDetails) { vRoot.findViewById(R.id.contactInfo_group).setVisibility(View.GONE); displayContactDetails = false; } // Company Company cp = person.getCompany(); displayCompanyOrHide(R.id.companyName_value, cp.getName(), R.id.companyName_group); displayCompanyOrHide(R.id.companyAdress1_value, cp.getAddress1(), R.id.companyAdress1_group); displayCompanyOrHide(R.id.companyAdress2_value, cp.getAddress2(), R.id.companyAdress2_group); displayCompanyOrHide(R.id.companyAdress3_value, cp.getAddress3(), R.id.companyAdress3_group); displayCompanyOrHide(R.id.companyPostcode_value, cp.getPostCode(), R.id.companyPostcode_group); displayCompanyOrHide(R.id.companyTelephone_value, cp.getTelephoneNumber(), R.id.companyTelephone_group); displayCompanyOrHide(R.id.companyFax_value, cp.getFaxNumber(), R.id.companyFax_group); displayCompanyOrHide(R.id.companyEmail_value, cp.getEmail(), R.id.companyEmail_group); // Add Contact bIm = (ImageView) vRoot.findViewById(R.id.action_addcontact); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionAddContact(getActivity(), person); } }); // Add Contact if (person.getEmail() != null || person.getCompany().getEmail() != null) { bIm = (ImageView) vRoot.findViewById(R.id.action_email); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); getMenu(popup.getMenu(), MODE_EMAIL); popup.setOnMenuItemClickListener(PersonProfileFragment.this); popup.show(); } }); } else { vRoot.findViewById(R.id.action_email).setVisibility(View.GONE); } // Geolocalisation if (person.getCompany().getFullAddress() != null) { displayGroup(); bIm = (ImageView) vRoot.findViewById(R.id.action_geolocation); bIm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { actionGeolocalisation(getActivity(), person.getCompany().getFullAddress(), person.getCompany().getName()); } }); } else { vRoot.findViewById(R.id.action_geolocation).setVisibility(View.GONE); } if (!displayCompanyDetails) { vRoot.findViewById(R.id.company_group).setVisibility(View.GONE); } }
From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java
private void showArtistOverflow(final Context context, View parent, final Artist artist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.search_res_artist); popupMenu.show();/* w w w . ja va2 s. c o m*/ popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_play_now: List<Song> radio = Suggestor.getInstance().buildArtistRadio(artist); PlaybackProxy.clearQueue(); for (Song song : radio) { PlaybackProxy.queueSong(song, false); } PlaybackProxy.playAtIndex(0); break; default: return false; } return true; } }); }
From source file:com.cecs492a_group4.sp.SingleEvent.java
public void showPopup(View v) { PopupMenu popup = new PopupMenu(this, v); popup.setOnMenuItemClickListener(this); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.menu, popup.getMenu()); popup.show();//from www .j a v a 2 s . c o m }
From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java
private void showPlaylistOverflow(final Context context, View parent, final Playlist playlist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.search_res_playlist); popupMenu.show();//from ww w . j av a 2 s. co m popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playPlaylist(playlist); break; case R.id.menu_add_to_queue: PlaybackProxy.queuePlaylist(playlist, false); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(playlist); fragment.show(((FragmentActivity) context).getSupportFragmentManager(), playlist.getRef()); break; default: return false; } return true; } }); }
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 .jav a 2s . 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:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java
public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) {/*from w ww . jav a 2 s.c om*/ super(parentFragment, arguments, router, R.layout.tile_admin_nvram, R.id.tile_admin_nvram_togglebutton); sortIds.put(R.id.tile_admin_nvram_sort_default, 11); sortIds.put(R.id.tile_admin_nvram_sort_asc, 12); sortIds.put(R.id.tile_admin_nvram_sort_desc, 13); this.mNvramInfoDefaultSorting = new NVRAMInfo(); mRecyclerView = (RecyclerView) layout.findViewById(R.id.tile_admin_nvram_ListView); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView // allows for optimizations if all items are of the same size: mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(mParentFragmentActivity); mLayoutManager.scrollToPosition(0); mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new NVRAMDataRecyclerViewAdapter(mParentFragmentActivity, router, mNvramInfoDefaultSorting); mRecyclerView.setAdapter(mAdapter); //Create Options Menu final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_admin_nvram_menu); if (!isThemeLight(mParentFragmentActivity, mRouter.getUuid())) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); } tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(AdminNVRAMTile.this); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_admin_nvram_options, menu); //Disable menu item from preference Integer currentSort = null; if (mParentFragmentPreferences != null) { currentSort = sortIds.inverse().get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), sortIds.get(R.id.tile_admin_nvram_sort_default))); } if (currentSort == null) { currentSort = R.id.tile_admin_nvram_sort_default; } final MenuItem currentSortMenuItem = menu.findItem(currentSort); if (currentSortMenuItem != null) { currentSortMenuItem.setEnabled(false); } // Locate MenuItem with ShareActionProvider final MenuItem shareMenuItem = menu.findItem(R.id.tile_admin_nvram_share); // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider(); popup.show(); } }); //Handle for Search EditText final EditText filterEditText = (EditText) this.layout.findViewById(R.id.tile_admin_nvram_filter); //Initialize with existing search data filterEditText.setText(mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING) : EMPTY_STRING); filterEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (filterEditText.getRight() - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { //'Clear' button - clear data, and reset everything out //Reset everything filterEditText.setText(EMPTY_STRING); final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplay = new HashMap<>(); break; } mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData); } } else { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplay); mAdapter.notifyDataSetChanged(); if (mParentFragmentPreferences != null) { final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING); editor.apply(); } return true; } } return false; } }); filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { final String textToFind = filterEditText.getText().toString(); if (isNullOrEmpty(textToFind)) { //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present return true; } final String existingSearch = mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (mParentFragmentPreferences != null) { if (textToFind.equalsIgnoreCase(existingSearch)) { //No need to go further as this is already the string we are looking for return true; } final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind); editor.apply(); } //Filter out (and sort by user-preference) final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences final Map<Object, Object> mNvramInfoToDisplayCopy; if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplayCopy = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplayCopy = new HashMap<>(); break; } //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } } else { mNvramInfoToDisplayCopy = new HashMap<>(); //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy); mAdapter.notifyDataSetChanged(); return true; } return false; } }); }
From source file:com.jrummyapps.busybox.fragments.ScriptsFragment.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ShellScript script = adapter.getItem(position); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // hack to get the popupmenu color working on Android 6.0+ for custom color schemes ContextCompat.getDrawable(getActivity(), R.drawable.bg_popup_dark); ContextCompat.getDrawable(getActivity(), R.drawable.bg_popup_light); }// www . j av a 2s . c o m PopupMenu popupMenu = new PopupMenu(getActivity(), view); popupMenu.getMenu().add(0, 1, 0, R.string.run).setIcon(R.drawable.ic_play_white_24dp); popupMenu.getMenu().add(0, 2, 0, R.string.edit).setIcon(R.drawable.ic_edit_white_24dp); popupMenu.getMenu().add(0, 3, 0, R.string.info).setIcon(R.drawable.ic_information_white_24dp); popupMenu.getMenu().add(0, 4, 0, R.string.delete).setIcon(R.drawable.ic_delete_white_24dp); getRadiant().tint(popupMenu.getMenu()).forceIcons().apply(getActivity()); Analytics.newEvent("clicked script").put("script_name", script.name).put("script_file", script.path).log(); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case 1: { // run Intent intent = new Intent(getActivity(), ScriptExecutorActivity.class); intent.putExtra(FileIntents.INTENT_EXTRA_PATH, script.path); startActivity(intent); return true; } case 2: { // edit Intent intent = new Intent(getActivity(), TextEditorActivity.class); intent.putExtra(FileIntents.INTENT_EXTRA_PATH, script.path); startActivity(intent); return true; } case 3: { // info Intent intent = new Intent(getActivity(), FilePropertiesActivity.class); intent.putExtra(FileIntents.INTENT_EXTRA_FILE, new File(script.path)); intent.putExtra(FilePropertiesActivity.EXTRA_DESCRIPTION, script.info); startActivity(intent); return true; } case 4: { // delete ShellScriptTable table = Database.getInstance().getTable(ShellScriptTable.NAME); boolean deleted = table.delete(script) != 0; if (deleted) { adapter.scripts.remove(script); adapter.notifyDataSetChanged(); new File(script.path).delete(); } return true; } default: return false; } } }); popupMenu.show(); }
From source file:com.jwetherell.quick_response_code.EncoderActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.btnshare: OnClickShare(null);/*from w w w . j a v a2 s. co m*/ return true; case android.R.id.home: onBackPressed(); return true; case R.id.empty: Statistics.getInstance(EncoderActivity.this).click(); View menuItemView = findViewById(R.id.empty); PopupMenu popupMenu = new PopupMenu(this, menuItemView); popupMenu.inflate(R.menu.menu_contextual_wps); for (int i = 0; i < popupMenu.getMenu().size(); i++) { MenuItem itemMenu = popupMenu.getMenu().getItem(i); SpannableString spanString = new SpannableString( popupMenu.getMenu().getItem(i).getTitle().toString()); spanString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, spanString.length(), 0); itemMenu.setTitle(spanString); } popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Statistics.getInstance(EncoderActivity.this).click(); // TODO Auto-generated method stub switch (item.getItemId()) { case R.id.wps: Statistics.getInstance(EncoderActivity.this).sendStatistics(TAGS.TAG_31); Intent mIntent = new Intent(EncoderActivity.this, AVActivateWpsActivity.class); mIntent.putExtra("is_5ghz", getIntent().getBooleanExtra("is_5ghz", false)); startActivity(mIntent); break; default: break; } return false; } }); popupMenu.show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.studyjams.mdvideo.PlayerModule.PlayerActivity.java
private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener, final int trackType) { if (player == null) { return;/*from w w w . j a v a2s. c o m*/ } int trackCount = player.getTrackCount(trackType); if (trackCount == 0) { return; } popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item)) || onTrackItemClick(item, trackType); } }); Menu menu = popup.getMenu(); // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0). menu.add(MENU_GROUP_TRACKS, DemoPlayer.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off); for (int i = 0; i < trackCount; i++) { menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, buildTrackName(player.getTrackFormat(trackType, i))); } menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true); menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true); }