Java Code Examples for android.view.Menu#removeGroup()

The following examples show how to use android.view.Menu#removeGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessagesActivity.java    From android with MIT License 6 votes vote down vote up
protected void onUpdateApps(List<Application> applications) {
    Menu menu = navigationView.getMenu();
    menu.removeGroup(R.id.apps);
    targetReferences.clear();
    updateMessagesAndStopLoading(messages.get(appId));
    for (Application app : applications) {
        MenuItem item = menu.add(R.id.apps, app.getId(), APPLICATION_ORDER, app.getName());
        item.setCheckable(true);
        Target t = Utils.toDrawable(getResources(), item::setIcon);
        targetReferences.add(t);
        picassoHandler
                .get()
                .load(Utils.resolveAbsoluteUrl(settings.url() + "/", app.getImage()))
                .error(R.drawable.ic_alarm)
                .placeholder(R.drawable.ic_placeholder)
                .resize(100, 100)
                .into(t);
    }
}
 
Example 2
Source File: WalletActivity.java    From xmrwallet with Apache License 2.0 6 votes vote down vote up
void updateAccountsList() {
    final Wallet wallet = getWallet();
    Menu menu = accountsView.getMenu();
    menu.removeGroup(R.id.accounts_list);
    final int n = wallet.getNumAccounts();
    final boolean showBalances = (n > 1) && !isStreetMode();
    for (int i = 0; i < n; i++) {
        final String label = (showBalances ?
                getString(R.string.label_account, wallet.getAccountLabel(i), Helper.getDisplayAmount(wallet.getBalance(i), 2))
                : wallet.getAccountLabel(i));
        final MenuItem item = menu.add(R.id.accounts_list, getAccountId(i), 2 * i, label);
        item.setIcon(R.drawable.ic_account_balance_wallet_black_24dp);
        if (i == wallet.getAccountIndex())
            item.setChecked(true);
    }
    menu.setGroupCheckable(R.id.accounts_list, true, true);
}
 
Example 3
Source File: BrowserActivity.java    From TLint with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.removeGroup(R.id.browser);
    getMenuInflater().inflate(R.menu.menu_browser, menu);

    String shareContent = String.format("%s %s ", getTitle() + "", url + "");
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, shareContent);

    MenuItem shareItem = menu.findItem(R.id.share);
    ShareActionProvider shareProvider =
            (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
    shareProvider.setShareHistoryFileName("channe_share.xml");
    shareProvider.setShareIntent(shareIntent);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 4
Source File: DrawerAccountsService.java    From kolabnotes-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Set<AccountIdentifier> overrideAccounts(OnAccountSwitchedFromNavListener list, Account[] accounts, AccountManager accountManager, DrawerLayout layout){
    Set<AccountIdentifier> createdAccounts = new LinkedHashSet<>();
    final Menu menu = nav.getMenu();
    final Context context = nav.getContext();

    menu.removeGroup(R.id.drawer_accounts);

    createMenuItem(list, menu, context, 0, "local", context.getString(R.string.drawer_account_local), "Notes", "local", layout);

    for(int i=0;i<accounts.length;i++) {
        String email = accountManager.getUserData(accounts[i], AuthenticatorActivity.KEY_EMAIL);
        String name = accountManager.getUserData(accounts[i],AuthenticatorActivity.KEY_ACCOUNT_NAME);
        String rootFolder = accountManager.getUserData(accounts[i],AuthenticatorActivity.KEY_ROOT_FOLDER);
        String accountType = accountManager.getUserData(accounts[i], AuthenticatorActivity.KEY_ACCOUNT_TYPE);
        final AccountIdentifier accountIdentifier = createMenuItem(list, menu, context, i+1, email, name, rootFolder, accountType, layout);

        createdAccounts.remove(accountIdentifier);
    }
    return createdAccounts;
}
 
Example 5
Source File: WaypointList.java    From Androzic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPrepareOptionsMenu(final Menu menu)
{
	Androzic application = Androzic.getApplication();
	
	MenuItem sortItem = menu.findItem(mSortMode == 0 ? R.id.action_sort_alpha : R.id.action_sort_size);
	sortItem.setChecked(true);
	Editor editor = PreferenceManager.getDefaultSharedPreferences(application).edit();
	editor.putInt(getString(R.string.wpt_sort), mSortMode);
	editor.commit();
	
	List<WaypointSet> sets = application.getWaypointSets();
	if (sets.size() > 1)
	{
		menu.setGroupVisible(R.id.group_sets, true);
		menu.removeGroup(R.id.group_sets);
		for (int i = 1; i < sets.size(); i++)
			menu.add(R.id.group_sets, i, Menu.NONE, sets.get(i).name).setChecked(true);
        menu.setGroupCheckable(R.id.group_sets, true, false);
	}
}
 
Example 6
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    menu.removeGroup(R.id.select_action_menu_default_items);
    menu.removeGroup(R.id.select_action_menu_assist_items);
    menu.removeGroup(R.id.select_action_menu_text_processing_menus);
    createActionMenu(mode, menu);
    return true;
}
 
Example 7
Source File: MainActivity.java    From openwebnet-android with MIT License 5 votes vote down vote up
private void reloadMenu() {
    Menu menu = navigationView.getMenu();
    menu.removeGroup(R.id.nav_group_environment);
    environmentService.findAll().subscribe(
        environments -> addEnvironmentMenu(menu, environments),
        throwable -> showSnackbar(errorLoadNavigationDrawer));
}
 
Example 8
Source File: GroupsViewFragment.java    From HomeGenie-Android with GNU General Public License v3.0 5 votes vote down vote up
public void UpdateJumpToGroupMenu(ArrayList<Group> groups) {
    StartActivity rootActivity = (StartActivity) getActivity();
    if (rootActivity != null) {
        Menu menu = rootActivity.getActionMenu();
        if (menu != null) {
            MenuItem jumpto = menu.findItem(R.id.action_jumpto);
            Menu submenu = jumpto.getSubMenu();
            if (submenu == null) return;
            //
            submenu.removeGroup(Menu.NONE);
            if (groups.size() > 0) {
                int gid = 0;
                for (Group group : groups) {
                    MenuItem grp = submenu.add(Menu.NONE, gid, gid, group.Name);
                    //prg.setIcon(R.drawable.ic_action_flash_on);
                    MenuCompat.setShowAsAction(grp, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                    grp.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            mIndicator.setCurrentItem(menuItem.getItemId());
                            return true;
                        }
                    });
                    gid++;
                }
            }
        }
    }
}
 
Example 9
Source File: Muazzin.java    From al-muazzin with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (!BuildConfig.DEBUG) {
        menu.removeGroup(R.id.menu_group_controller);
    }
    return super.onPrepareOptionsMenu(menu);
}
 
Example 10
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isFinishing()) {
        // otherwise we crash if we try to finish() in onCreate
        return false;
    }
    MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    // update the displayed login state
    if (settings.getBoolean(getString(R.string.pref_logintype_key), false)) {
        if (!isLoggingIn()) {
            if (authCookie.hasCookieBeenSet()) {
                replaceLoginButton(menu, R.id.logout_button, "Log out");
            } else {
                replaceLoginButton(menu, R.id.login_button, "Log in");
            }
        } else {
            replaceLoginButton(menu, R.id.cancel_button, "Cancel");
        }
    } else {
        if (authCookie.hasCookieBeenSet()) {
            replaceLoginButton(menu, R.id.logout_button, "Log out");
        } else {
            menu.removeGroup(R.id.login_menu_group);
        }
    }
    return true;
}
 
Example 11
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
/**
 * Replace current login button with another (typically "Log-in", "Cancel", or "Log out")
 * @param menu menu to add to
 * @param id id of button being added
 * @param text text of the button being added
 */
private void replaceLoginButton(Menu menu, int id, String text) {
    menu.removeGroup(R.id.login_menu_group);
    menu.add(R.id.login_menu_group, id, Menu.NONE, text);
    MenuItem item = menu.findItem(id);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
 
Example 12
Source File: MonthFragment.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    menu.findItem(R.id.action_show_month).setVisible(false);
    menu.removeGroup(R.id.week_type_group);
}
 
Example 13
Source File: ActivityMainDialog.java    From Clip-Stack with MIT License 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    boolean returnInt = super.onCreateOptionsMenu(menu);
    menu.removeGroup(R.id.menu_group);
    return returnInt;
}
 
Example 14
Source File: GroupsViewFragment.java    From HomeGenie-Android with GNU General Public License v3.0 4 votes vote down vote up
public void UpdateCurrentGroupMenu() {
        StartActivity rootActivity = (StartActivity) getActivity();
        if (rootActivity == null)
            return;
        Menu menu = rootActivity.getActionMenu();
        if (menu != null) {
            MenuItem automation = menu.findItem(R.id.menu_automation);
            if (automation != null) {
                automation.setEnabled(false);
                Menu submenu = automation.getSubMenu();
                if (submenu == null) return;
                //
                submenu.removeGroup(Menu.NONE);
                if (mGroupPrograms.size() > 0) {
                    for (Module program : mGroupPrograms) {
                        MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName());
                        prg.setIcon(R.drawable.ic_action_flash_on);
                        MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                        final String address = program.Address;
                        String groupName = "";
                        try {
                            groupName = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8");
                        } catch (Exception e) {
                        }
                        final String group = groupName;
                        prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuItem) {
                                String apiCall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" +
                                        address + "/" +
                                        group + "/" + new Date().getTime();
                                Control.apiRequest(apiCall, null);
                                return true;
                            }
                        });
                    }
                    automation.setEnabled(true);
                }
            }
            //
//            MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro");
//            recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
//                @Override
//                public boolean onMenuItemClick(MenuItem menuItem) {
//                    StartActivity sa = (StartActivity)getActivity();
//                    sa.openMacroRecordMenu();
//                    return true;
//                }
//            });
//            rootactivity.supportInvalidateOptionsMenu();
        }
    }