Example usage for android.view SubMenu clear

List of usage examples for android.view SubMenu clear

Introduction

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

Prototype

public void clear();

Source Link

Document

Remove all existing items from the menu, leaving it empty as if it had just been created.

Usage

From source file:ca.rmen.android.scrumchatter.main.TeamNavigationMenu.java

void load() {
    Log.v(TAG, "load");
    mTeams.getAllTeams().subscribe(teamsData -> {
        // Update the navigation view.
        SubMenu teamsMenu = mNavigationMenu.findItem(R.id.teams_list).getSubMenu();
        teamsMenu.clear();
        for (Teams.Team team : teamsData.teams) {
            MenuItem teamMenuItem = teamsMenu.add(R.id.teams_list_items, Menu.NONE, Menu.NONE, team.teamName);
            if (team.teamName.equals(teamsData.currentTeam.teamName)) {
                teamMenuItem.setChecked(true);
            }/*  w w  w  .j  a v a  2 s.  co  m*/
        }
    });
}

From source file:com.marstemp.widgets.DynamicShareActionProvider.java

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();
    if (pm != null && list != null && list.size() > 0) {
        for (int i = 0; i < list.size(); i++) {
            ResolveInfo resolveInfo = list.get(i);
            OnMenuItemClickUpdateIntentListener itemListener = new OnMenuItemClickUpdateIntentListener();
            itemListener.setPosition(i);
            MenuItem item = subMenu.add(resolveInfo.loadLabel(pm)).setIcon(resolveInfo.loadIcon(pm))
                    .setOnMenuItemClickListener(itemListener);
        }/*w w  w  . j av  a 2s. c  o m*/
    } else {
        String msg;
        if (shareIntent == null || shareIntent.getType() == null || shareIntent.getType().equals("")) {
            msg = context.getString(R.string.no_share_type);
        } else if (list == null || list.size() <= 0) {
            String formatMsg = context.getString(R.string.no_app_to_share);
            msg = String.format(formatMsg, shareIntent.getType());
        } else {
            msg = context.getString(R.string.error_occurred);
        }

        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }
}

From source file:org.randoomz.learnit.ui.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    subscribe = db.createQuery(Language.TABLE, Language.ALL_QUERY).map(Language.MAP)
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<Language>>() {
                @Override/*  w ww.ja v a2 s  .c o  m*/
                public void call(List<Language> languages) {
                    MainActivity.this.languages = languages;
                    final MenuItem item = navigationView.getMenu().findItem(R.id.languages);
                    final SubMenu subMenuLanguages = item.getSubMenu();
                    subMenuLanguages.clear();
                    for (int i = 0; i < languages.size(); i++) {
                        subMenuLanguages.add(Menu.NONE, i, i, languages.get(i).language()).setCheckable(true);
                    }
                    onNavigationItemSelected(subMenuLanguages.getItem(currentPosition));
                }
            });
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.search.SearchFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();// w  w w  .j  a va  2 s .c o  m
    Log.i("MENU", "load gripmenu!!!!");
    getActivity().getMenuInflater().inflate(R.menu.gripmenu, menu);

    SubMenu submenu = menu.getItem(0).getSubMenu();
    submenu.clear();

    super.onPrepareOptionsMenu(menu);
}

From source file:eu.trentorise.smartcampus.trentinofamiglia.fragments.search.SearchFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from ww w. java  2 s. co m
    getActivity().getMenuInflater().inflate(R.menu.gripmenu, menu);

    SubMenu submenu = menu.getItem(0).getSubMenu();
    submenu.clear();

    super.onPrepareOptionsMenu(menu);
}

From source file:com.example.FilteredShareActionProvider.java

/**
 * {@inheritDoc}//from www.  j  av a 2 s .c om
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    FilteredActivityChooserModel dataModel = FilteredActivityChooserModel.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.abc_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);
        }
    }
}

From source file:android.support.v7.widget.ShareActionProvider.java

/**
 * {@inheritDoc}/*from   w  w w . j a  v  a2 s . co m*/
 */
@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.abc_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);
        }
    }
}

From source file:fr.rolandl.smartshareactionprovider.SmartShareActionProvider.java

/**
 * {@inheritDoc}/*from  w  ww  .ja v  a  2  s .c o  m*/
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    SmartActivityChooserModel dataModel = SmartActivityChooserModel.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.abc_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);
        }
    }
}

From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    final Resources res = getResources();
    final boolean hasOfficialKeyAccounts = Utils.hasAccountSignedWithOfficialKeys(getActivity());
    final boolean forcePrivateAPI = mPreferences.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false);
    final long[] accountIds = getAccountIds(getActivity());
    final MenuItem itemAdd = menu.findItem(R.id.add_submenu);
    if (itemAdd != null && itemAdd.hasSubMenu()) {
        final SubMenu subMenu = itemAdd.getSubMenu();
        subMenu.clear();
        final HashMap<String, CustomTabConfiguration> map = getConfiguraionMap();
        final List<Entry<String, CustomTabConfiguration>> tabs = new ArrayList<>(map.entrySet());
        Collections.sort(tabs, CustomTabConfigurationComparator.SINGLETON);
        for (final Entry<String, CustomTabConfiguration> entry : tabs) {
            final String type = entry.getKey();
            final CustomTabConfiguration conf = entry.getValue();

            final boolean isOfficiakKeyAccountRequired = TAB_TYPE_ACTIVITIES_ABOUT_ME.equals(type)
                    || TAB_TYPE_ACTIVITIES_BY_FRIENDS.equals(type);
            final boolean accountIdRequired = conf
                    .getAccountRequirement() == CustomTabConfiguration.ACCOUNT_REQUIRED;

            final Intent intent = new Intent(INTENT_ACTION_ADD_TAB);
            intent.setClass(getActivity(), CustomTabEditorActivity.class);
            intent.putExtra(EXTRA_TYPE, type);
            intent.putExtra(EXTRA_OFFICIAL_KEY_ONLY, isOfficiakKeyAccountRequired);

            final MenuItem subItem = subMenu.add(conf.getDefaultTitle());
            final boolean disabledByNoAccount = accountIdRequired && accountIds.length == 0;
            final boolean disabledByNoOfficialKey = !forcePrivateAPI && isOfficiakKeyAccountRequired
                    && !hasOfficialKeyAccounts;
            final boolean disabledByDuplicateTab = conf.isSingleTab() && isTabAdded(getActivity(), type);
            final boolean shouldDisable = disabledByDuplicateTab || disabledByNoOfficialKey
                    || disabledByNoAccount;
            subItem.setVisible(!shouldDisable);
            subItem.setEnabled(!shouldDisable);
            final Drawable icon = ResourcesCompat.getDrawable(res, conf.getDefaultIcon(), null);
            subItem.setIcon(icon);// ww  w.ja v a 2s.c  om
            subItem.setIntent(intent);
        }
    }
    ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu);
}

From source file:org.mariotaku.gallery3d.ImageViewerGLActivity.java

void updateShareIntent() {
    final MenuItem item = mMenuBar.getMenu().findItem(MENU_SHARE);
    if (item == null || !item.hasSubMenu())
        return;//  w  ww  .j  a v  a2 s  .co m
    final SubMenu subMenu = item.getSubMenu();
    subMenu.clear();
    final Intent intent = getIntent();
    final Uri uri = intent.getData();
    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
    if (mImageFile != null && mImageFile.exists()) {
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile));
    } else {
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, uri.toString());
    }
    Utils.addIntentToMenu(this, subMenu, shareIntent);
}