List of usage examples for android.view SubMenu removeItem
public void removeItem(int id);
From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java
private void updateAccounts() { final Menu menu = binding.navigation.getMenu(); final MenuItem libraries = menu.findItem(R.id.nav_libraries); final SubMenu subMenu = libraries.getSubMenu(); while (subMenu.size() > 0) { subMenu.removeItem(subMenu.getItem(0).getItemId()); }/* ww w.ja va2 s . com*/ final List<Account> accounts = getServer().getAccounts(); for (int index = 0; index < accounts.size(); index++) { final Account account = accounts.get(index); final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName()); if (account.getId().equals("local")) { menuItem.setIcon(R.drawable.ic_folder_24dp); } else { menuItem.setIcon(R.drawable.ic_cloud_24dp); } menuItem.setCheckable(true); } final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE, R.string.nav_addaccount); menuItem.setIcon(R.drawable.ic_add_24dp); for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) { final View child = binding.navigation.getChildAt(i); if (child != null && child instanceof ListView) { final ListView menuView = (ListView) child; final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter(); final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter(); wrapped.notifyDataSetChanged(); } } getServer().loadRecent(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem recent = menu.findItem(R.id.nav_recent); if (recent != null) { recent.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); getServer().loadStarred(new LoadCallback<List<String>>() { @Override public void loaded(List<String> item) { final MenuItem starred = menu.findItem(R.id.nav_starred); if (starred != null) { starred.setVisible(!item.isEmpty()); } } @Override public void error(Throwable e) { GoogleAnalytics.trackException(e); } }); }
From source file:org.akvo.flow.activity.SurveyActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.survey_activity, menu); SubMenu subMenu = menu.findItem(R.id.more_submenu).getSubMenu(); if (isReadOnly()) { subMenu.removeItem(R.id.clear); } else if (mSurveyGroup.isMonitored()) { // Add 'pre-fill' option, if applies if (mDatabase.getLastSurveyInstance(mRecordId, mSurvey.getId()) != null) { subMenu.add(Menu.NONE, MENU_PREFILL, Menu.NONE, R.string.prefill_title); }//from w ww .j a v a 2 s . c o m } return super.onCreateOptionsMenu(menu); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private synchronized void updateFromFilterEdit() { final SubMenu filters = mFilterItem.getSubMenu(); for (int i = 0; i < FILTER_MAX_ID; i++) { filters.removeItem(i); }//from w w w . j av a2s . co m ArrayList<ChannelFilterValues> channelFilterList = new ArrayList<ChannelFilterValues>(); SharedPreferences filterPreferences = PrefUtils.getSharedPreferences(PrefUtils.TYPE_PREFERENCES_FILTERS, TvBrowser.this); Map<String, ?> filterValues = filterPreferences.getAll(); for (String key : filterValues.keySet()) { Object values = filterValues.get(key); if (key.startsWith("filter.") && values instanceof String && values != null) { channelFilterList.add(new ChannelFilterValues(key, (String) values)); } } Collections.sort(channelFilterList, ChannelFilterValues.CHANNEL_FILTER_VALUES_COMPARATOR); int groupId = 3; int id = 1; mAllFilter = new ChannelFilterValues(SettingConstants.ALL_FILTER_ID, getString(R.string.activity_edit_filter_list_text_all), ""); MenuItem all = filters.add(groupId, id++, groupId, mAllFilter.toString()); all.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { updateChannelFilter(mAllFilter, R.drawable.ic_filter_default); item.setChecked(true); return true; } }); if (mCurrentChannelFilterId == null || mAllFilter.getId().endsWith(mCurrentChannelFilterId)) { all.setChecked(true); } for (final ChannelFilterValues filter : channelFilterList) { MenuItem item = filters.add(groupId, id++, groupId, filter.toString()); if (mCurrentChannelFilterId != null && filter.getId().endsWith(mCurrentChannelFilterId)) { mFilterItem.setIcon(R.drawable.ic_filter_on); item.setChecked(true); } item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { updateChannelFilter(filter, R.drawable.ic_filter_on); item.setChecked(true); return true; } }); } FILTER_MAX_ID = id; filters.setGroupCheckable(groupId, true, true); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void updateScrollMenu() { if (mScrollTimeItem != null) { SubMenu subMenu = mScrollTimeItem.getSubMenu(); for (int i = 0; i < SCROLL_IDS.length; i++) { subMenu.removeItem(SCROLL_IDS[i]); }//from ww w . j a va 2 s . co m SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this); ArrayList<Integer> values = new ArrayList<Integer>(); int[] defaultValues = getResources().getIntArray(R.array.time_button_defaults); int timeButtonCount = pref.getInt(getString(R.string.TIME_BUTTON_COUNT), getResources().getInteger(R.integer.time_button_count_default)); for (int i = 1; i <= Math.min(timeButtonCount, getResources().getInteger(R.integer.time_button_count_default)); i++) { try { Class<?> string = R.string.class; Field setting = string.getDeclaredField("TIME_BUTTON_" + i); Integer value = Integer.valueOf(pref .getInt(getResources().getString((Integer) setting.get(string)), defaultValues[i - 1])); if (value >= -1 && !values.contains(value)) { values.add(value); } } catch (Exception e) { } } for (int i = 7; i <= timeButtonCount; i++) { Integer value = Integer.valueOf(pref.getInt("TIME_BUTTON_" + i, 0)); if (value >= -1 && !values.contains(value)) { values.add(value); } } if (PrefUtils.getBooleanValue(R.string.SORT_RUNNING_TIMES, R.bool.sort_running_times_default)) { Collections.sort(values); } SCROLL_TIMES = new int[values.size()]; SCROLL_IDS = new int[values.size()]; for (int i = 0; i < values.size(); i++) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, values.get(i) / 60); cal.set(Calendar.MINUTE, values.get(i) % 60); SCROLL_TIMES[i] = values.get(i).intValue(); SCROLL_IDS[i] = -(i + 1); subMenu.add(100, SCROLL_IDS[i], i + 1, DateFormat.getTimeFormat(TvBrowser.this).format(cal.getTime())); } } }