List of usage examples for android.widget PopupMenu getMenuInflater
public MenuInflater getMenuInflater()
From source file:free.yhc.feeder.ChannelListActivity.java
private void onOpt_addChannel(final View anchor) { if (0 == mAb.getNavigationItemCount()) { eAssert(false);//ww w. ja v a 2 s. c om return; } if (0 > mAb.getSelectedNavigationIndex()) { UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_select_category_to_add); return; } if (!Utils.isNetworkAvailable()) { // TODO Handling error UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_network_unavailable); return; } PopupMenu popup = new PopupMenu(this, anchor); popup.getMenuInflater().inflate(R.menu.popup_addchannel, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.predefined: onOpt_addChannel_predefined(anchor); break; case R.id.url: onOpt_addChannel_url(anchor); break; case R.id.youtube: onOpt_addChannel_youtube(anchor); break; default: eAssert(false); } return true; } }); popup.show(); }
From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceTile.java
public WirelessIfaceTile(@NotNull String iface, @Nullable String parentIface, @NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) { super(parentFragment, arguments, router, R.layout.tile_status_wireless_iface, R.id.tile_status_wireless_iface_togglebutton); this.iface = iface; this.parentIface = parentIface; ((TextView) this.layout.findViewById(R.id.tile_status_wireless_iface_title)).setText(this.iface); //Create Options Menu final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_status_wireless_iface_menu); final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid()); if (!isThemeLight) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); }//w ww .j a v a 2s . co m tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(WirelessIfaceTile.this); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_wireless_iface_options, menu); if (wifiEncryptionType == null || (isNullOrEmpty(wifiSsid) && isNullOrEmpty(wifiPassword))) { menu.findItem(R.id.tile_status_wireless_iface_qrcode).setEnabled(false); } popup.show(); } }); }
From source file:me.albertonicoletti.latex.activities.EditorActivity.java
/** * Initializes the symbols shortcut bar. *//* ww w.j a v a 2 s.c o m*/ private void initSymbols() { // It actually only initializes the "+" button, creating a popup menu final Button button = (Button) findViewById(R.id.maths_button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Shows a popup menu PopupMenu popup = new PopupMenu(EditorActivity.this, button); popup.getMenuInflater().inflate(R.menu.menu_maths, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { // On symbol click insertSymbol(menuItem.getTitle().toString()); return false; } }); popup.show(); } }); }
From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java
private void handleLongPress(final TaskDescription ad, View view) { final PopupMenu popup = new PopupMenu(mContext, view); mPopup = popup;/*from w w w. j av a2 s.c om*/ popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.recent_remove_item) { mRecentsManager.killTask(ad); } else if (item.getItemId() == R.id.recent_inspect_item) { startApplicationDetailsActivity(ad.getPackageName()); } else { return false; } return true; } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopup = null; } }); popup.show(); }
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 w ww .ja v a 2 s .co m }
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
private PopupMenu initializeHeaderOverflowPopup(final View headerOverflowMenu) { final PopupMenu resultPopupMenu; if (headerOverflowMenu == null) { resultPopupMenu = null;//from w ww . j a v a 2s .c om } else { final PopupMenu popupMenu = new PopupMenu(this, headerOverflowMenu); popupMenu.getMenuInflater().inflate(R.menu.mpd_mainmenu, popupMenu.getMenu()); popupMenu.getMenuInflater().inflate(R.menu.mpd_playlistmenu, popupMenu.getMenu()); popupMenu.getMenu().removeItem(R.id.PLM_EditPL); popupMenu.setOnMenuItemClickListener(this); headerOverflowMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popupMenu)); headerOverflowMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mSlidingLayout != null && mSlidingLayout.isPanelExpanded()) { prepareNowPlayingMenu(popupMenu.getMenu()); popupMenu.show(); } } }); resultPopupMenu = popupMenu; } return resultPopupMenu; }
From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java
public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) {/* w ww . j ava 2 s .co m*/ 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.pranavpandey.smallapp.sample.SmallAppSample.java
private void setupOptionMenu() { View header = LayoutInflater.from(this).inflate(R.layout.header, new LinearLayout(this), false); final View optionMenu = header.findViewById(R.id.option_menu); optionMenu.setOnLongClickListener(new View.OnLongClickListener() { @Override/*from w ww. j av a 2s . co m*/ public boolean onLongClick(View v) { SmallTheme.getInstance().showHeaderHint(v, R.string.sas_options); return false; } }); optionMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(getContext(), optionMenu); 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) { e.printStackTrace(); } popup.getMenuInflater().inflate(R.menu.main, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_settings: showSettings(); break; case R.id.menu_about: new AboutDialog(SmallAppSample.this, R.mipmap.ic_launcher, R.string.app_name, Type.LIST) .show(getRootView()); break; case R.id.menu_sources: SmallUtils.openLink(SmallAppSample.this, getRootView(), SOURCES_LINK, null, Type.GRID); break; } return true; } }); popup.show(); } }); getWindow().setHeaderView(header); }
From source file:com.javielinux.fragments.MyActivityFragment.java
private void showMenuMoreActions(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.my_activity_more_actions, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// w ww . j a v a2 s.c om public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.popupmenu_more_actions_saved_tweet) { openSavedTweetColumn(); } else if (item.getItemId() == R.id.popupmenu_more_actions_trending_topics) { newTrending(); } return true; } }); popupMenu.show(); } else { AlertDialogFragment frag = new AlertDialogFragment(); Bundle args = new Bundle(); args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions); args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false); args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false); args.putInt(AlertDialogFragment.KEY_ALERT_ARRAY_ITEMS, R.array.popupmenu_my_activity_more_actions); frag.setArguments(args); frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() { @Override public void OnAlertButtonOk() { } @Override public void OnAlertButtonCancel() { } @Override public void OnAlertButtonNeutral() { } @Override public void OnAlertItems(int which) { if (which == 0) { openSavedTweetColumn(); } else if (which == 1) { newTrending(); } } }); frag.show(getFragmentManager(), "dialog"); } }
From source file:com.javielinux.fragments.MyActivityFragment.java
private void showMenuOptions(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.my_activity_more_options, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from w w w. j a va 2 s . co m*/ public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.popupmenu_more_options_size) { showSizeText(); } else if (item.getItemId() == R.id.popupmenu_more_options_theme) { showThemeDialog(); } else if (item.getItemId() == R.id.popupmenu_more_options_preferences) { Intent i = new Intent(getActivity(), Preferences.class); startActivity(i); } else if (item.getItemId() == R.id.popupmenu_more_options_exit) { showDialogExit(); } return true; } }); popupMenu.show(); } else { AlertDialogFragment frag = new AlertDialogFragment(); Bundle args = new Bundle(); args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions); args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false); args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false); args.putInt(AlertDialogFragment.KEY_ALERT_ARRAY_ITEMS, R.array.popupmenu_my_activity_more_options); frag.setArguments(args); frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() { @Override public void OnAlertButtonOk() { } @Override public void OnAlertButtonCancel() { } @Override public void OnAlertButtonNeutral() { } @Override public void OnAlertItems(int which) { if (which == 0) { showSizeText(); } else if (which == 1) { Intent i = new Intent(getActivity(), Preferences.class); startActivity(i); } else if (which == 2) { showThemeDialog(); } else if (which == 3) { showDialogExit(); } } }); frag.show(getFragmentManager(), "dialog"); } }