Example usage for android.view MenuItem hasSubMenu

List of usage examples for android.view MenuItem hasSubMenu

Introduction

In this page you can find the example usage for android.view MenuItem hasSubMenu.

Prototype

public boolean hasSubMenu();

Source Link

Document

Check whether this item has an associated sub-menu.

Usage

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapToolbarMenuIcon(@Nullable ActionMenuView view, int itemColor, int popupItemColor,
        int... excludeGroups) {
    if (view == null)
        return;//from w w w  .ja  v  a2 s. com
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int colorDark, int colorLight, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());/*from w  w w .  j a v  a 2 s . c o  m*/
    final int itemColor = TwidereColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = TwidereColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark,
            colorLight);
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}

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);
            }//w  w w .j a  va  2  s .c o  m
        }
    } else {
        throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu");
    }
}

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();/* w w w  .ja  v a  2 s. co m*/
        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);
            subItem.setIntent(intent);
        }
    }
    ThemeUtils.applyColorFilterToMenuIcon(getActivity(), menu);
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void resetCheatSheet(ActionMenuView menuView) {
    final OnLongClickListener listener = new OnLongClickListener() {
        @Override/*from w ww .  j  a va2 s  .c o  m*/
        public boolean onLongClick(View v) {
            if (((ActionMenuItemView) v).hasText())
                return false;
            final MenuItem menuItem = ((ActionMenuItemView) v).getItemData();
            Utils.showMenuItemToast(v, menuItem.getTitle(), true);
            return true;
        }
    };
    for (int i = 0, j = menuView.getChildCount(); i < j; i++) {
        final View child = menuView.getChildAt(i);
        if (!(child instanceof ActionMenuItemView))
            continue;
        final ActionMenuItemView itemView = (ActionMenuItemView) child;
        final MenuItem menuItem = itemView.getItemData();
        if (menuItem.hasSubMenu())
            continue;
        itemView.setOnLongClickListener(listener);
    }
}

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

void updateShareIntent() {
    final MenuItem item = mMenuBar.getMenu().findItem(MENU_SHARE);
    if (item == null || !item.hasSubMenu())
        return;//from  w  ww.  j  av  a2s .  c o  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);
}

From source file:hu.zelena.guide.MainActivity.java

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
        mDrawer.closeDrawers();// w  w w.  j a  v  a2 s .  c  o m
    } else {

        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        Fragment fragment = new AboutFragment();
        if (fragment != null) {
            firstFrag = true;
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
            setTitle("MOBILTUDS GUIDE");

            final Menu menu = nvDrawer.getMenu();
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                if (item.hasSubMenu()) {
                    SubMenu subMenu = item.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        subMenuItem.setChecked(false);
                    }
                } else {
                    item.setChecked(false);
                }
            }
        } else {
            Intent i = new Intent(this, ErrorActivity.class);
            i.putExtra("error", "Nem sikerlt a HOME-FRAGMENT betltse. [Null object]");
            startActivity(i);

            Log.e("MainActivity", "Error in creating fragment");
        }
        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this, "Nyomja meg mgegyszer a kilpshez", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor,
        final int highlightColor, final Mode mode, final int... excludedGroups) {
    for (int i = 0, j = menu.size(); i < j; i++) {
        final MenuItem item = menu.getItem(i);
        final Drawable icon = item.getIcon();
        final ContextMenuInfo info = item.getMenuInfo();
        if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) {
            icon.mutate();//from   w  w  w  .j a va 2s.c  o  m
            if (info instanceof TwidereMenuInfo) {
                final TwidereMenuInfo sInfo = (TwidereMenuInfo) info;
                icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color,
                        mode);
            } else {
                icon.setColorFilter(color, mode);
            }
        }
        if (item.hasSubMenu()) {
            // SubMenu item is always in popup
            applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode,
                    excludedGroups);
        }
    }
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

/**
 * Returns the menu item within the specified parent menu that owns
 * specified submenu./*from  w w w .ja v a  2  s  .  com*/
 *
 * @param parent the parent menu
 * @param submenu the submenu for which the index should be returned
 * @return the menu item that owns the submenu, or {@code null} if not
 *         present
 */
private MenuItem findMenuItemForSubmenu(@NonNull MenuBuilder parent, @NonNull MenuBuilder submenu) {
    for (int i = 0, count = parent.size(); i < count; i++) {
        final MenuItem item = parent.getItem(i);
        if (item.hasSubMenu() && submenu == item.getSubMenu()) {
            return item;
        }
    }

    return null;
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor,
        final int highlightColor, final Mode mode, final int... excludedGroups) {
    for (int i = 0, j = menu.size(); i < j; i++) {
        final MenuItem item = menu.getItem(i);
        final Drawable icon = item.getIcon();
        final ContextMenuInfo info = item.getMenuInfo();
        if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) {
            icon.mutate();//from w  w  w  .j a  v  a 2 s.  com
            if (info instanceof FiretweetMenuInfo) {
                final FiretweetMenuInfo sInfo = (FiretweetMenuInfo) info;
                icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color,
                        mode);
            } else {
                icon.setColorFilter(color, mode);
            }
        }
        if (item.hasSubMenu()) {
            // SubMenu item is always in popup
            applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode,
                    excludedGroups);
        }
    }
}