/** {@inheritDoc} */ @Override public void onPrepareSubMenu(SubMenu subMenu) { // Clear since the order of items may change. subMenu.clear(); ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); PackageManager packageManager = mContext.getPackageManager(); final int expandedActivityCount = dataModel.getActivityCount(); final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount); // Populate the sub-menu with a sub set of the activities. for (int i = 0; i < collapsedActivityCount; i++) { ResolveInfo activity = dataModel.getActivity(i); subMenu .add(0, i, i, activity.loadLabel(packageManager)) .setIcon(activity.loadIcon(packageManager)) .setOnMenuItemClickListener(mOnMenuItemClickListener); } if (collapsedActivityCount < expandedActivityCount) { // Add a sub-menu for showing all activities as a list item. SubMenu expandedSubMenu = subMenu.addSubMenu( Menu.NONE, collapsedActivityCount, collapsedActivityCount, mContext.getString(R.string.abs__activity_chooser_view_see_all)); for (int i = 0; i < expandedActivityCount; i++) { ResolveInfo activity = dataModel.getActivity(i); expandedSubMenu .add(0, i, i, activity.loadLabel(packageManager)) .setIcon(activity.loadIcon(packageManager)) .setOnMenuItemClickListener(mOnMenuItemClickListener); } } }
@Override public void onPrepareOptionsMenu(Menu menu) { menu.clear(); getSherlockActivity().getSupportMenuInflater().inflate(R.menu.gripmenu, menu); SubMenu submenu = menu.getItem(0).getSubMenu(); submenu.clear(); if (category == null) { category = (getArguments() != null) ? getArguments().getString(SearchFragment.ARG_CATEGORY) : null; } if (getArguments() == null || !getArguments().containsKey(SearchFragment.ARG_LIST) && !getArguments().containsKey(SearchFragment.ARG_QUERY)) { submenu.add(Menu.CATEGORY_SYSTEM, R.id.submenu_search, Menu.NONE, R.string.search_txt); } submenu.add(Menu.CATEGORY_SYSTEM, R.id.map_view, Menu.NONE, R.string.map_view); if (category != null) { String addString = getString( R.string.add_poi_in_cat, getString( CategoryHelper.getCategoryDescriptorByCategoryFiltered( CategoryHelper.CATEGORY_TYPE_POIS, category) .description)); submenu.add(Menu.CATEGORY_SYSTEM, R.id.menu_item_addpoi, Menu.NONE, addString); } // NotificationsSherlockFragmentDT.onPrepareOptionsMenuNotifications(menu); super.onPrepareOptionsMenu(menu); }