List of usage examples for android.widget PopupMenu getMenuInflater
public MenuInflater getMenuInflater()
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//ww w .j av a2s. com 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.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);/*www . jav a2 s. 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.siva.animation_sample.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); //getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); getActionBar().setDisplayShowCustomEnabled(true); getActionBar().setCustomView(R.layout.custom_action_bar_layout); custom_action_view = getActionBar().getCustomView(); ImageView more_icon = (ImageView) custom_action_view.findViewById(R.id.moreimage); more_icon.setOnClickListener(new View.OnClickListener() { @Override// w w w . j av a2 s . c o m public void onClick(View v) { // TODO Auto-generated method stub PopupMenu popup = new PopupMenu(HomeActivity.this, v); MenuInflater inflate = popup.getMenuInflater(); inflate.inflate(R.menu.home, popup.getMenu()); popup.show(); popup.setOnMenuItemClickListener(HomeActivity.this); } }); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); Create_alert_box(); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)), FragmentTab1.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)), FragmentTab2.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab3").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)), FragmentTab3.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab4").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)), FragmentTab4.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab5").setIndicator(null, getResources().getDrawable(R.drawable.ic_launcher)), FragmentTab5.class, null); mTabHost.setCurrentTab(2); }
From source file:at.ac.uniklu.mobile.sportal.DashboardActivity.java
@TargetApi(11) @Override//from w w w .j av a 2s . c o m public void openOptionsMenu() { // Honeycomb and ICS tablet menu workaround if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { /* Android >= 3 with holo theme doesn't support the options menu, so * display a popup menu below the overflow action button. */ PopupMenu m = new PopupMenu(this, findViewById(R.id.actionbar_overflow)); m.getMenuInflater().inflate(R.menu.dashboard_menu, m.getMenu()); m.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); m.show(); } else { // show default options menu on Android 2.x super.openOptionsMenu(); } }
From source file:org.hawkular.client.android.fragment.FavTriggersFragment.java
private void showTriggerMenu(final View triggerView, final int triggerPosition) { PopupMenu triggerMenu = new PopupMenu(getActivity(), triggerView); triggerMenu.getMenuInflater().inflate(R.menu.popup_delete, triggerMenu.getMenu()); triggerMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// ww w .j a va 2 s. co m public boolean onMenuItemClick(MenuItem menuItem) { Trigger trigger = getTriggersAdapter().getItem(triggerPosition); switch (menuItem.getItemId()) { case R.id.menu_delete: Context context = getActivity(); SQLStore<Trigger> store = openStore(context); store.openSync(); store.remove(trigger.getId()); onRefresh(); return true; default: return false; } } }); triggerMenu.show(); }
From source file:net.sf.golly.SettingsActivity.java
public void doPasteMode(View view) { // display pop-up menu with these items: AND, COPY, OR, XOR PopupMenu popup = new PopupMenu(this, view); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.pastemode_menu, popup.getMenu()); popup.show();//from ww w.java 2 s . co m }
From source file:org.hawkular.client.android.fragment.FavMetricsFragment.java
private void showMetricMenu(final View metricView, final int metricPosition) { PopupMenu metricMenu = new PopupMenu(getActivity(), metricView); metricMenu.getMenuInflater().inflate(R.menu.popup_delete, metricMenu.getMenu()); metricMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/* w w w . j a va 2s . com*/ public boolean onMenuItemClick(MenuItem menuItem) { Metric metric = getFavMetricsAdapter().getItem(metricPosition); switch (menuItem.getItemId()) { case R.id.menu_delete: Context context = getActivity(); SQLStore<Metric> store = openStore(context); store.openSync(); store.remove(metric.getId()); onRefresh(); return true; default: return false; } } }); metricMenu.show(); }
From source file:com.tlongdev.bktf.ui.fragment.FavoritesFragment.java
@Override public void onMoreClicked(View view, final Item item) { PopupMenu menu = new PopupMenu(getActivity(), view); menu.getMenuInflater().inflate(R.menu.popup_item, menu.getMenu()); menu.getMenu().findItem(R.id.favorite).setTitle("Remove from favorites"); menu.getMenu().findItem(R.id.calculator).setEnabled(!Utility.isInCalculator(getActivity(), item)); menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// w w w. j a v a 2s.c o m public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.history: Intent i = new Intent(getActivity(), PriceHistoryActivity.class); i.putExtra(PriceHistoryActivity.EXTRA_ITEM, item); startActivity(i); break; case R.id.favorite: Utility.removeFromFavorites(getActivity(), item); mAdapter.removeItem(item); break; case R.id.calculator: Utility.addToCalculator(getActivity(), item); menuItem.setEnabled(false); break; case R.id.backpack_tf: CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(), Uri.parse(item.getBackpackTfUrl()), new WebViewFallback()); break; case R.id.wiki: CustomTabActivityHelper.openCustomTab(getActivity(), new CustomTabsIntent.Builder().build(), Uri.parse(item.getTf2WikiUrl()), new WebViewFallback()); break; } return true; } }); menu.show(); }
From source file:org.hawkular.client.android.fragment.TriggersFragment.java
private void showTriggerMenu(final View triggerView, final int triggerPosition) { PopupMenu triggerMenu = new PopupMenu(getActivity(), triggerView); triggerMenu.getMenuInflater().inflate(R.menu.popup_add, triggerMenu.getMenu()); triggerMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override/*from ww w.jav a2s . c o m*/ public boolean onMenuItemClick(MenuItem menuItem) { Trigger trigger = getTriggersAdapter().getItem(triggerPosition); switch (menuItem.getItemId()) { case R.id.menu_add: Context context = getActivity(); SQLStore<Trigger> store = openStore(context); store.openSync(); store.save(trigger); onRefresh(); return true; default: return false; } } }); triggerMenu.show(); }
From source file:org.xbmc.kore.ui.SongsListFragment.java
private void showPopupMenu(View v) { ViewHolder viewHolder = (ViewHolder) v.getTag(); final PlaylistType.Item playListItem = new PlaylistType.Item(); playListItem.songid = viewHolder.songId; final PopupMenu popupMenu = new PopupMenu(getActivity(), v); popupMenu.getMenuInflater().inflate(R.menu.musiclist_item, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override// w ww.j a v a 2s . c om public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_play: MediaPlayerUtils.play(SongsListFragment.this, playListItem); return true; case R.id.action_queue: MediaPlayerUtils.queue(SongsListFragment.this, playListItem, PlaylistType.GetPlaylistsReturnType.AUDIO); return true; } return false; } }); popupMenu.show(); }