List of usage examples for android.view SubMenu add
public MenuItem add(int groupId, int itemId, int order, CharSequence title);
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);// w w w . j a v a 2 s . c o 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 w w w. j a v a 2s .c om 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())); } } }