Example usage for android.view SubMenu add

List of usage examples for android.view SubMenu add

Introduction

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

Prototype

public MenuItem add(CharSequence title);

Source Link

Document

Add a new item to the menu.

Usage

From source file:com.cullaboration.userhookdemo.MainActivity.java

public void loadStaticPages() {
    UserHook.fetchPageNames(new UHOperation.UHArrayListener<UHPage>() {
        @Override//  www . ja  v  a  2s .  c  o m
        public void onSuccess(List<UHPage> items) {

            SubMenu staticMenu = navigationView.getMenu().addSubMenu("Static Pages");
            for (UHPage page : items) {
                // add page to menu
                staticMenu.add(page.getName());

                // store the page item for use in the click listener
                staticPages.put(page.getName(), page);
            }

            // hack to refresh menu
            MenuItem mi = navigationView.getMenu().getItem(navigationView.getMenu().size() - 1);
            mi.setTitle(mi.getTitle());
        }
    });
}

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

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    subMenu.clear();//from ww w .ja va 2s. com
    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);
        }
    } 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.bienvenidoainternet.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeManager tm = new ThemeManager(this);
    this.setTheme(tm.getThemeForMainActivity());

    if (savedInstanceState != null) {
        currentThemeId = savedInstanceState.getInt("currentThemeId");
        boardList = savedInstanceState.getParcelableArrayList("boardList");
    }/*from  w ww .j a v a 2 s . c  om*/
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    if (settings.getString("pref_password", "").isEmpty()) {
        SharedPreferences.Editor edit = settings.edit();
        edit.putString("pref_password", makePassword());
        edit.commit();
    }

    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Bievenido a internet");
    this.setSupportActionBar(toolbar);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (pager.getCurrentItem() == 0) {
                if (!mainFragment.getMode() && mainFragment.currentBoard != null) {
                    Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
                    Bundle b = new Bundle();
                    BoardItem temp = new BoardItem();
                    temp.setParentBoard(mainFragment.currentBoard);
                    b.putParcelable("theReply", temp);
                    b.putBoolean("quoting", false);
                    b.putBoolean("newthread", true);
                    in.putExtras(b);
                    startActivity(in);
                }
            } else {
                if (childFragment.currentBoard != null) {
                    if (!childFragment.boardItems.isEmpty()) {
                        try {
                            Intent in = new Intent(getApplicationContext(), ResponseActivity.class);
                            Bundle b = new Bundle();
                            BoardItem reply = childFragment.boardItems.get(0);
                            if (!reply.isLocked) {
                                b.putParcelable("theReply", reply);
                                b.putBoolean("quoting", false);
                                b.putBoolean("newthread", false);
                                in.putExtras(b);
                                startActivity(in);
                            } else {
                                Toast.makeText(getApplicationContext(), "Error: Este hilo est cerrado",
                                        Toast.LENGTH_LONG).show();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    });
    fab.setVisibility(View.GONE);

    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (savedInstanceState != null) {
        mainFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState,
                "mainFragment");
        childFragment = (FragmentBoardItemList) getSupportFragmentManager().getFragment(savedInstanceState,
                "childFragment");
    } else {
        mainFragment = FragmentBoardItemList.newInstance(true, null, null);
        childFragment = FragmentBoardItemList.newInstance(false, null, null);
    }

    this.pager = (ViewPager) findViewById(R.id.pager);
    this.pagerAdapter = new CustomFragmentPagerAdapter(getSupportFragmentManager());
    pagerAdapter.addFragment(mainFragment);
    pagerAdapter.addFragment(childFragment);
    this.pager.setAdapter(pagerAdapter);

    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                fab.setImageResource(R.drawable.ic_action_add);
                if (mainFragment.currentBoard != null) {
                    toolbar.setTitle("Catlogo");
                    toolbar.setSubtitle(mainFragment.currentBoard.getBoardName());
                }
                if (mainFragment.getMode()) {
                    toolbar.setTitle("Post recientes");
                    toolbar.setSubtitle("");
                }
                if (mainFragment.getMode()) {
                    fab.hide();
                } else {
                    fab.show();
                }
            } else if (position == 1) {
                fab.setImageResource(R.drawable.ic_edit);
                if (childFragment.currentBoard != null) {
                    toolbar.setTitle(childFragment.currentBoard.getBoardName());
                    if (!childFragment.boardItems.isEmpty()) {
                        toolbar.setSubtitle(childFragment.boardItems.get(0).getSubject());
                    }
                    fab.show();
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    if (boardList.isEmpty()) {
        getBoardList();
    } else {
        Menu menu = navigationView.getMenu();
        SubMenu sub = menu.addSubMenu("Lista de Boards");
        for (Board b : boardList) {
            sub.add(b.getBoardName());
        }
        refreshNavigator();
    }

    if (tm.isDarkTheme()) {
        navigationView.setBackgroundColor(0xFF888888);
    }
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPCompaniesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem searchBtn = menu.findItem(R.id.action_search);
    searchBtn.setVisible(true);/* ww  w  . ja va  2s. c  o m*/

    SubMenu selectionMenu = menu.addSubMenu(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_edit)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectionMenu.getItem().setTitle(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuItem selectAllItem = selectionMenu.add(getResources().getString(R.string.btn_select_all));
    selectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_check_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    selectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Selected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(true);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });

    MenuItem deselectAllItem = selectionMenu.add(getResources().getString(R.string.btn_deselect_all));
    deselectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    deselectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    deselectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Deselected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(false);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });
}

From source file:pw.dedominic.airc.App.java

public void recreateDrawerItems() {
    Menu menu = navView.getMenu();
    menu.clear();//from www. j  a  v  a2 s . co m
    SubMenu smenu = menu.addSubMenu("Servers");
    for (Server server : dao) {
        if (server.equals(selectedServer))
            smenu.add(server.getTitle()).setIcon(R.drawable.green_circle);
        else
            smenu.add(server.getTitle());
    }
    smenu = menu.addSubMenu("Actions");
    String[] actions = getResources().getStringArray(R.array.nav_items);
    if (actions.length != 5)
        throw new RuntimeException("LOLWUT?");
    smenu.add(actions[0]).setIcon(android.R.drawable.ic_input_add);
    smenu.add(actions[1]).setIcon(android.R.drawable.ic_menu_edit);
    smenu.add(actions[2]).setIcon(android.R.drawable.ic_menu_delete);
    smenu.add(actions[3]).setIcon(android.R.drawable.ic_menu_preferences);
    smenu.add(actions[4]);

}

From source file:com.googlecode.android_scripting.activity.ScriptManager.java

private void buildAddMenu(SubMenu subMenu) {
    subMenu.add(getString(R.string.s_Folder)).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*ww  w  .j  av  a 2s . co  m*/
        public boolean onMenuItemClick(MenuItem item) {
            menuItemClick(MenuId.FOLDER_ADD.getId());
            return false;
        }
    });
    for (final Entry<Integer, Interpreter> entry : mAddMenuIds.entrySet()) {
        subMenu.add(entry.getValue().getNiceName()).setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                menuItemClick(entry.getKey());
                return false;
            }
        });

    }
}

From source file:org.tigase.mobile.roster.RosterFragment.java

private boolean prepareResources(final SubMenu sm, final long id) {
    final RosterItem rosterItem = getJid(id);
    final Jaxmpp jaxmpp = getMulti().get(rosterItem.getSessionObject());
    Map<String, Presence> all = jaxmpp.getSessionObject().getPresence().getPresences(rosterItem.getJid());

    final CapabilitiesModule capabilitiesModule = jaxmpp.getModule(CapabilitiesModule.class);
    final String nodeName = jaxmpp.getSessionObject().getUserProperty(CapabilitiesModule.NODE_NAME_KEY);

    boolean added = false;

    try {/* w  ww .j  a  v a  2 s  . c  o m*/
        if (all != null)
            for (final Entry<String, Presence> entry : all.entrySet()) {
                if (entry.getValue().getType() != null)
                    continue;
                MenuItem i = sm.add(entry.getKey());

                added = true;
                i.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent();
                        intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
                        intent.putExtra("id", id);
                        intent.putExtra("resource", entry.getKey());

                        getActivity().getApplicationContext().sendBroadcast(intent);

                        return true;
                    }
                });
            }
    } catch (Exception e) {
        Log.e(TAG, "Problem on resources menu", e);
    }

    // if (!added) {
    // Intent intent = new Intent();
    // intent.setAction(TigaseMobileMessengerActivity.ROSTER_CLICK_MSG);
    // intent.putExtra("id", id);
    //
    // getActivity().getApplicationContext().sendBroadcast(intent);
    // }
    return added;
}

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();/*  ww  w  .  ja v a2s .c  o 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:org.bienvenidoainternet.app.MainActivity.java

private void getBoardList() {
    Menu menu = navigationView.getMenu();
    final SubMenu sub = menu.addSubMenu("Lista de Boards");
    Ion.with(getApplicationContext()).load("http://bienvenidoainternet.org/cgi/api/boards").asString()
            .setCallback(new FutureCallback<String>() {
                @Override/*from   ww w .j a  v  a2s.co  m*/
                public void onCompleted(Exception e, String result) {
                    if (e != null) {
                        e.printStackTrace();
                        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                    } else {
                        try {
                            JSONArray boards = new JSONObject(result).getJSONArray("boards");
                            for (int i = 0; i < boards.length(); i++) {
                                JSONObject board = boards.getJSONObject(i);
                                Board parsedBoard = new Board(board.getString("name"), board.getString("dir"),
                                        board.getInt("board_type"),
                                        board.getInt("allow_image_replies") == 1 ? true : false);
                                sub.add(parsedBoard.getBoardName());
                                boardList.add(parsedBoard);
                            }
                        } catch (JSONException e1) {
                            Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show();
                            e1.printStackTrace();
                        }
                    }
                }
            });
    refreshNavigator();
}

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

public static void addIntentToSubMenu(final Context context, final SubMenu menu, final Intent query_intent) {
    if (context == null || menu == null || query_intent == null)
        return;/*from  www  . j a v a2 s  . com*/
    final PackageManager pm = context.getPackageManager();
    final List<ResolveInfo> activities = pm.queryIntentActivities(query_intent, 0);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(query_intent);
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        menu.add(info.loadLabel(pm)).setIcon(info.loadIcon(pm)).setIntent(intent);
    }
}