Example usage for android.view SubMenu findItem

List of usage examples for android.view SubMenu findItem

Introduction

In this page you can find the example usage for android.view SubMenu findItem.

Prototype

public MenuItem findItem(int id);

Source Link

Document

Return the menu item with a particular identifier.

Usage

From source file:org.jboss.demo.loanmanagement.StatusesScreen.java

/**
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 *//*  www .j  a va 2 s.c  o  m*/
@Override
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
    getMenuInflater().inflate(R.menu.statuses_screen_menu, optionsMenu);

    final MenuItem sortItem = optionsMenu.findItem(R.id.menu_sort);
    final SubMenu sortMenu = sortItem.getSubMenu();

    // find out which sort to turn on
    final String sorterId = this.adapter.getSorterId();

    if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_name);
        item.setChecked(true);
    } else if (Prefs.SORT_BY_SSN.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_ssn);
        item.setChecked(true);
    } else if (Prefs.SORT_BY_RATE.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_rate);
        item.setChecked(true);
    } else {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_status);
        item.setChecked(true);
    }

    return true; // show menu and action bar items
}

From source file:org.jboss.demo.loanmanagement.EvaluationsScreen.java

/**
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 *//*w w  w .java2  s  . c  om*/
@Override
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
    getMenuInflater().inflate(R.menu.evaluations_screen_menu, optionsMenu);

    final MenuItem sortItem = optionsMenu.findItem(R.id.menu_sort);
    final SubMenu sortMenu = sortItem.getSubMenu();

    // find out which sort to turn on
    final String sorterId = this.adapter.getSorterId();

    if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem sortByNameItem = sortMenu.findItem(R.id.action_sort_by_name);
        sortByNameItem.setChecked(true);
    } else if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem sortBySsnItem = sortMenu.findItem(R.id.action_sort_by_ssn);
        sortBySsnItem.setChecked(true);
    } else {
        final MenuItem sortByDateItem = sortMenu.findItem(R.id.action_sort_by_date);
        sortByDateItem.setChecked(true);
    }

    return true; // show menu and action bar items
}

From source file:com.github.pockethub.android.ui.MainActivity.java

private void setUpNavigationMenu() {
    MenuItem organizationContainer = navigationView.getMenu().findItem(R.id.navigation_organizations);
    if (organizationContainer.hasSubMenu()) {
        SubMenu organizationsMenu = organizationContainer.getSubMenu();
        for (int i = 1; i < orgs.size(); i++) {
            User organization = orgs.get(i);
            if (organizationsMenu.findItem(organization.id()) == null) {
                MenuItem organizationMenuItem = organizationsMenu.add(Menu.NONE, organization.id(), Menu.NONE,
                        organization.name() != null ? organization.name() : organization.login());
                organizationMenuItem.setIcon(R.drawable.ic_github_organization_black_24dp);
                //Because of tinting the real image would became a grey block
                //avatars.bind(organizationMenuItem, organization);
                menuItemOrganizationMap.put(organizationMenuItem, organization);
            }//www .  jav a  2  s. c o m
        }
    } else {
        throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu");
    }
}

From source file:org.totschnig.myexpenses.fragment.TemplatesList.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.sort, menu);
    SubMenu subMenu = menu.findItem(R.id.SORT_COMMAND).getSubMenu();
    subMenu.findItem(R.id.SORT_AMOUNT_COMMAND).setVisible(true);
    subMenu.findItem(R.id.SORT_NEXT_INSTANCE_COMMAND).setVisible(true);
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static void configureGroupingMenu(SubMenu groupingMenu, Grouping currentGrouping) {
    MenuItem activeItem;//from   w  ww  . ja v a  2  s.  c om
    switch (currentGrouping) {
    case DAY:
        activeItem = groupingMenu.findItem(R.id.GROUPING_DAY_COMMAND);
        break;
    case WEEK:
        activeItem = groupingMenu.findItem(R.id.GROUPING_WEEK_COMMAND);
        break;
    case MONTH:
        activeItem = groupingMenu.findItem(R.id.GROUPING_MONTH_COMMAND);
        break;
    case YEAR:
        activeItem = groupingMenu.findItem(R.id.GROUPING_YEAR_COMMAND);
        break;
    default:
        activeItem = groupingMenu.findItem(R.id.GROUPING_NONE_COMMAND);
        break;
    }
    activeItem.setChecked(true);
}

From source file:org.totschnig.myexpenses.util.Utils.java

public static void configureSortMenu(SubMenu sortMenu, String currentSortOrder) {
    MenuItem activeItem;/* w ww. java2s.  c  o  m*/
    switch (currentSortOrder) {
    case ProtectedFragmentActivity.SORT_ORDER_USAGES:
        activeItem = sortMenu.findItem(R.id.SORT_USAGES_COMMAND);
        break;
    case ProtectedFragmentActivity.SORT_ORDER_LAST_USED:
        activeItem = sortMenu.findItem(R.id.SORT_LAST_USED_COMMAND);
        break;
    case ProtectedFragmentActivity.SORT_ORDER_AMOUNT:
        activeItem = sortMenu.findItem(R.id.SORT_AMOUNT_COMMAND);
        break;
    case ProtectedFragmentActivity.SORT_ORDER_CUSTOM:
        activeItem = sortMenu.findItem(R.id.SORT_CUSTOM_COMMAND);
        break;
    case ProtectedFragmentActivity.SORT_ORDER_NEXT_INSTANCE:
        activeItem = sortMenu.findItem(R.id.SORT_NEXT_INSTANCE_COMMAND);
        break;
    default:
        activeItem = sortMenu.findItem(R.id.SORT_TITLE_COMMAND);
    }
    activeItem.setChecked(true);
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

private void selectCurrentPeriod(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_period);
    if (item == null)
        return;//from  w w w .  j  a  va 2s.  c  o m

    SubMenu subMenu = item.getSubMenu();

    // on init, mark the default item as checked
    AppSettings settings = new AppSettings(getActivity());
    DefinedDateRangeName rangeName = settings.getLookAndFeelSettings().getShowTransactions();
    if (rangeName == null)
        return;

    DefinedDateRanges ranges = new DefinedDateRanges(getActivity());
    DefinedDateRange range = ranges.get(rangeName);
    if (range == null)
        return;
    int id = range.menuResourceId;

    MenuItem itemToMark = subMenu.findItem(id);
    if (itemToMark == null)
        return;

    itemToMark.setChecked(true);
}

From source file:com.dycody.android.idealnote.ListFragment.java

private void initSortingSubmenu() {
    final String[] arrayDb = getResources().getStringArray(R.array.sortable_columns);
    final String[] arrayDialog = getResources().getStringArray(R.array.sortable_columns_human_readable);
    int selected = Arrays.asList(arrayDb).indexOf(prefs.getString(Constants.PREF_SORTING_COLUMN, arrayDb[0]));

    SubMenu sortMenu = this.menu.findItem(R.id.menu_sort).getSubMenu();
    for (int i = 0; i < arrayDialog.length; i++) {
        if (sortMenu.findItem(i) == null) {
            sortMenu.add(Constants.MENU_SORT_GROUP_ID, i, i, arrayDialog[i]);
        }/*from   w w w.  jav a 2 s. co  m*/
        if (i == selected)
            sortMenu.getItem(i).setChecked(true);
    }
    sortMenu.setGroupCheckable(Constants.MENU_SORT_GROUP_ID, true, true);
}

From source file:org.totschnig.myexpenses.activity.MyExpenses.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(MyApplication.getThemeId());
    Resources.Theme theme = getTheme();
    TypedValue value = new TypedValue();
    theme.resolveAttribute(R.attr.colorAggregate, value, true);
    colorAggregate = value.data;//w w w.j av  a 2 s. c  o m
    int prev_version = PrefKey.CURRENT_VERSION.getInt(-1);
    if (prev_version == -1) {
        //prevent preference change listener from firing when preference file is created
        if (MyApplication.getInstance().isInstrumentationTest()) {
            PreferenceManager.setDefaultValues(this, MyApplication.getTestId(), Context.MODE_PRIVATE,
                    R.xml.preferences, true);
        } else {
            PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
        }
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    adHandler = new AdHandler(this);
    adHandler.init();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (StickyListHeadersListView) findViewById(R.id.left_drawer);
    mToolbar = setupToolbar(false);
    mToolbar.addView(getLayoutInflater().inflate(R.layout.custom_title, mToolbar, false));
    if (mDrawerLayout != null) {
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
                R.string.drawer_close) {

            /**
             * Called when a drawer has settled in a completely closed state.
             */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                TransactionList tl = getCurrentFragment();
                if (tl != null)
                    tl.onDrawerClosed();
                //ActivityCompat.invalidateOptionsMenu(MyExpenses.this); // creates call to onPrepareOptionsMenu()
            }

            /**
             * Called when a drawer has settled in a completely open state.
             */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                TransactionList tl = getCurrentFragment();
                if (tl != null)
                    tl.onDrawerOpened();
                //ActivityCompat.invalidateOptionsMenu(MyExpenses.this); // creates call to onPrepareOptionsMenu()
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, 0); // this disables the animation
            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.addDrawerListener(mDrawerToggle);
    }
    String[] from = new String[] { KEY_DESCRIPTION, KEY_LABEL, KEY_OPENING_BALANCE, KEY_SUM_INCOME,
            KEY_SUM_EXPENSES, KEY_SUM_TRANSFERS, KEY_CURRENT_BALANCE, KEY_TOTAL, KEY_CLEARED_TOTAL,
            KEY_RECONCILED_TOTAL };
    // and an array of the fields we want to bind those fields to
    int[] to = new int[] { R.id.description, R.id.label, R.id.opening_balance, R.id.sum_income,
            R.id.sum_expenses, R.id.sum_transfer, R.id.current_balance, R.id.total, R.id.cleared_total,
            R.id.reconciled_total };
    mDrawerListAdapter = new MyGroupedAdapter(this, R.layout.account_row, null, from, to, 0);

    Toolbar accountsMenu = (Toolbar) findViewById(R.id.accounts_menu);
    accountsMenu.setTitle(R.string.pref_manage_accounts_title);
    accountsMenu.inflateMenu(R.menu.accounts);
    accountsMenu.inflateMenu(R.menu.sort);

    //Sort submenu
    MenuItem menuItem = accountsMenu.getMenu().findItem(R.id.SORT_COMMAND);
    MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    sortMenu = menuItem.getSubMenu();
    sortMenu.findItem(R.id.SORT_CUSTOM_COMMAND).setVisible(true);

    //Grouping submenu
    SubMenu groupingMenu = accountsMenu.getMenu().findItem(R.id.GROUPING_ACCOUNTS_COMMAND).getSubMenu();
    AccountGrouping accountGrouping;
    try {
        accountGrouping = AccountGrouping.valueOf(PrefKey.ACCOUNT_GROUPING.getString("TYPE"));
    } catch (IllegalArgumentException e) {
        accountGrouping = AccountGrouping.TYPE;
    }
    MenuItem activeItem;
    switch (accountGrouping) {
    case CURRENCY:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_CURRENCY_COMMAND);
        break;
    case NONE:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_NONE_COMMAND);
        break;
    default:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_TYPE_COMMAND);
        break;
    }
    activeItem.setChecked(true);

    accountsMenu.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleSortOption(item) || handleAccountsGrouping(item)
                    || dispatchCommand(item.getItemId(), null);
        }
    });

    mDrawerList.setAdapter(mDrawerListAdapter);
    mDrawerList.setAreHeadersSticky(false);
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mAccountId != id) {
                moveToPosition(position);
                ((SimpleCursorAdapter) mDrawerListAdapter).notifyDataSetChanged();
                closeDrawer();
            }
        }
    });

    requireFloatingActionButtonWithContentDescription(Utils.concatResStrings(this, ". ",
            R.string.menu_create_transaction, R.string.menu_create_transfer, R.string.menu_create_split));
    if (prev_version == -1) {
        getSupportActionBar().hide();
        initialSetup();
        return;
    }
    if (savedInstanceState != null) {
        mExportFormat = savedInstanceState.getString("exportFormat");
        mAccountId = savedInstanceState.getLong(KEY_ACCOUNTID, 0L);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            mAccountId = Utils.getFromExtra(extras, KEY_ROWID, 0);
            idFromNotification = extras.getLong(KEY_TRANSACTIONID, 0);
            //detail fragment from notification should only be shown upon first instantiation from notification
            if (idFromNotification != 0) {
                FragmentManager fm = getSupportFragmentManager();
                if (fm.findFragmentByTag(TransactionDetailFragment.class.getName()) == null) {
                    TransactionDetailFragment.newInstance(idFromNotification).show(fm,
                            TransactionDetailFragment.class.getName());
                    getIntent().removeExtra(KEY_TRANSACTIONID);
                }
            }
        }
    }
    if (mAccountId == 0)
        mAccountId = PrefKey.CURRENT_ACCOUNT.getLong(0L);
    setup();
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

public void updateFavoritesMenu(boolean editDeleteEnabled) {
    if (mCreateFavorite != null) {
        SubMenu menu = mCreateFavorite.getSubMenu();

        menu.findItem(R.id.menu_tvbrowser_action_favorite_edit).setEnabled(editDeleteEnabled);
        menu.findItem(R.id.menu_tvbrowser_action_favorite_delete).setEnabled(editDeleteEnabled);
    }/*from   w  w  w  . j a v  a 2  s  .c  o m*/
}